Zondax / ledger-icp

Apache License 2.0
16 stars 9 forks source link

Invalid Data Type in ChainDelgation creation #178

Closed alejo-acevedo-deel closed 1 year ago

alejo-acevedo-deel commented 1 year ago

I am trying to use ChainDelegation from the official Dfinity Library, agent-js to be able of making request calls without sign readState manually. So, I create a custom identity which has a method sign

  public async sign(blob: BinaryBlob): Promise<BinaryBlob> {
    return this._executeWithApp(async (app) => {
      console.log('Signing blob tryied 1', app, blob);
      const resp: ResponseSign = await app.sign(this.derivePath, Buffer.from(blob), 0);
      console.log('Signed blob', resp);
      const signatureRS = resp.signatureRS;
      if (!signatureRS) {
        throw new Error(
          `A ledger error happened during signature:\n` +
            `Code: ${resp.returnCode}\n` +
            `Message: ${JSON.stringify(resp.errorMessage)}\n`,
        );
      }

      if (signatureRS?.byteLength !== 64) {
        throw new Error(`Signature must be 64 bytes long (is ${signatureRS.length})`);
      }

      return blobFromBuffer(new BlobBuffer(signatureRS));
    })

  }

And for create delegation I do

      const pidTargets = targets?.map(target => Principal.fromText(target));
      const expiration = new Date(Date.now() + 15 * 60 * 1000);
      const delegation = new Delegation(to.toDer(), BigInt(+expiration) * BigInt(1000000), pidTargets);

      const signature = await this.ledgerIdentity.sign(delegation.toCBOR() as unknown as BinaryBlob);

When I tried to use it, it fails returning

Message: "Data is invalid : Unexpected data type"

The var signature is a ArrayBuffer type of byteLength 118

:link: zboto Link

ftheirs commented 1 year ago

Hi @0xAaCE! Could you share the blob that you are sending to the device? If you have also the returnCode would be great!

ftheirs commented 1 year ago

I'll close this issue. However, feel free to reopen and add more info about it!