hyperledger-archives / indy-sdk

indy-sdk
https://wiki.hyperledger.org/display/indy
Apache License 2.0
668 stars 735 forks source link

Nodejs: Invalid signatures when submitting a multi-signed transaction #2560

Closed Riff451 closed 9 months ago

Riff451 commented 2 years ago

Hello, I'm receiving the following error when calling the nodejs wrapper submitRequest function:

{
    "reqId": "<redacted>",
    "op": "REQNACK",
    "identifier": "<redacted_my_did>",
    "reason": "client request invalid: insufficient number of valid signatures, 2 is required but 0 valid and 2 invalid have been provided. The following signatures are invalid: did=<redacted_my_did>, signature=MP8493v2gTBFvrXbCVLQVFmWCKh3PwySaVfmSqE1ADYD6PE8awEu6T6r71YtukofYv7mcF4svJWQGmvsn4YtH8b; did=<redacted_endorser_did>, signature=2v45KTeydaSY4gT3tYBLmb4pNmwfgrshiDj5bV4Eq8i25JDcUMmxLXCDucSe6Qx9L7kwNRLAmGSrf4qEXTx6srPj"
}

If I try to use the indy-cli with the same configurations (DID/Verkey, etc.) I can manually multi-sign the transaction and submit successfully the request to the ledger.

In my app, which uses the nodejs wrapper, I've double checked the generated signatures and for the same txn I get the same signatures returned from the indy-cli.

The app code does something like this:

multiSignedRequest = await indy.multiSignRequest(ENDORSER_WALLET_HANDLE, this.ENDORSER_DID, request.transaction);
result = await indy.submitRequest(ENDORSER_POOL_HANDLE, multiSignedRequest);

where request.transaction is the txn json string already signed with my DID.

I don't understand what I'm doing wrong. :)

Here's my current environment:

Thanks in advance for any help.

Riff451 commented 2 years ago

It turned out that the nodejs wrapper does a JSON.parse:

https://github.com/hyperledger/indy-sdk/blob/ae9f8a252bb99e8b80c6d34c6c985fd95abfadef/wrappers/nodejs/src/index.js#L15-L23

And I think the reqId in the output of multiSignRequest was changed because it's a number too big to be contained in a js Number type. The workaround was to update manually the reqId of the multiSignRequest output with the original unchanged reqId. If the request is already of type string the wrapper doesn't do anything and passes the txn as is to libindy.

Should the wrapper take this issue with large numbers into considerations? Thanks.