cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
645 stars 330 forks source link

Problem with amino signing FeeGrant and SendAuthorization #1599

Open wojciechowskip opened 2 months ago

wojciechowskip commented 2 months ago

Hi guys, I have a huge problem broadcasting transactions on Cosmos using cosmjs and Ledger connected via Keplr wallet.

My code is working as expected for direct Keplr signing but when it comes to Ledger - some messages works and some not. Usually authz ones are the ones that are not working and return enigmatic cosmos error:

BroadcastTxError: Broadcasting transaction failed with code 4 (codespace: sdk).
Log: signature verification failed; please verify account number (1525623),
sequence (0) and chain-id (cosmoshub-4): unauthorized

I've realized that this error is returned when I am trying to brodcast:

Isnt that cosmjs & ledger issue?

EDIT #1

Looks like for both I may have wrong amino converters OR this is not supported by sdk, anyone can point me to how such amino converters should look like or examples for SendAuthorization and MsgGrantAllowance with BasicAllowance (Fee grant)?|

These are messages I want to convert using amino (they are working with direct signing):

1 Fee grant

{
    typeUrl: COSMOS_MESSAGE_TYPE_URL.GRANT_ALLOWANCE,
    value: MsgGrantAllowance.fromPartial({
      granter: granterAddress,
      grantee: granteeAddress,
      allowance: {
        typeUrl: COSMOS_MESSAGE_TYPE_URL.BASIC_ALLOWANCE,
        value: BasicAllowance.encode(
          BasicAllowance.fromPartial({
            spendLimit: [givenGrantsAmount],
            expiration: {
              seconds: expiredDateInS,
            },
          })
        ).finish(),
      },
    }),
  };

2 Send Grant

{
    typeUrl: COSMOS_MESSAGE_TYPE_URL.GRANT,
    value: MsgGrant.fromPartial({
      granter: granterAddress,
      grantee: granteeAddress,
      grant: Grant.fromPartial({
        expiration: {
          seconds: expiredDateInS,
        },
        authorization: {
          typeUrl: COSMOS_MESSAGE_TYPE_URL.SEND_AUTHORIZATION,
          value: SendAuthorization.encode(
            SendAuthorization.fromPartial({
              allowList: [granteeAddress],
              spendLimit: [
                formatCompoundSpendLimit(
                  calculateTransferGrantLimit(delegationAmount)
                ),
              ],
            })
          ).finish(),
        },
      }),
    }),
  }

PS: MsgGrant converter I was able to create based on restake-ui but with the rest - no luck, any tips and tricks appreciated

Wgil commented 1 month ago

Hi @wojciechowskip did you find a solution?

avkr003 commented 1 month ago

@Wgil @wojciechowskip This might be related to issue 1092