trustwallet / wallet-core

Cross-platform, cross-blockchain wallet library.
https://developer.trustwallet.com/wallet-core
Apache License 2.0
2.89k stars 1.62k forks source link

Invalid signature for BNB through Walletconnect 2.0 #3433

Closed 0x-General closed 10 months ago

0x-General commented 1 year ago

Description When signing & broadcasting a send transaction for BNB through walletconnect, the BNB node responds with a message saying:

{
    "code": 401,
    "failed_tx_index": 0,
    "message": "signature verification failed",
    "success_tx_results": []
}

Looks like the signing process is incorrect. To Reproduce

Expected behavior The node should process the transaction with no error messages.

Additional context This is the message that is being broadcasted:

{
    "sequence": 1,
    "accountNumber": 7446375,
    "chainId": "Binance-Chain-Tigris",
    "msg": {
        "inputs": [
            {
                "address": {
                    "type": "Buffer",
                    "data": [
                        92,
                        12,
                        151,
                        228,
                        69,
                        248,
                        21,
                        153,
                        106,
                        172,
                        199,
                        153,
                        138,
                        210,
                        170,
                        200,
                        64,
                        182,
                        172,
                        235
                    ]
                },
                "coins": [
                    {
                        "denom": "BNB",
                        "amount": 10000
                    }
                ]
            }
        ],
        "outputs": [
            {
                "address": {
                    "type": "Buffer",
                    "data": [
                        92,
                        12,
                        151,
                        228,
                        69,
                        248,
                        21,
                        153,
                        106,
                        172,
                        199,
                        153,
                        138,
                        210,
                        170,
                        200,
                        64,
                        182,
                        172,
                        235
                    ]
                },
                "coins": [
                    {
                        "denom": "BNB",
                        "amount": 10000
                    }
                ]
            }
        ],
        "aminoPrefix": "2A2C87FA"
    },
    "memo": "",
    "source": 0,
    "signatures": [
        {
            "pub_key": {
                "type": "Buffer",
                "data": [
                    235,
                    90,
                    233,
                    135,
                    33,
                    2,
                    201,
                    141,
                    200,
                    60,
                    209,
                    67,
                    70,
                    142,
                    117,
                    45,
                    158,
                    247,
                    52,
                    74,
                    209,
                    0,
                    202,
                    92,
                    120,
                    6,
                    25,
                    166,
                    147,
                    180,
                    191,
                    8,
                    54,
                    217,
                    80,
                    191,
                    242,
                    186
                ]
            },
            "signature": {
                "type": "Buffer",
                "data": [
                    235,
                    204,
                    17,
                    136,
                    181,
                    5,
                    97,
                    1,
                    70,
                    136,
                    113,
                    199,
                    209,
                    96,
                    82,
                    20,
                    82,
                    206,
                    217,
                    56,
                    77,
                    46,
                    254,
                    179,
                    110,
                    251,
                    214,
                    198,
                    59,
                    165,
                    192,
                    114,
                    13,
                    42,
                    85,
                    74,
                    254,
                    152,
                    208,
                    66,
                    32,
                    233,
                    118,
                    241,
                    203,
                    112,
                    40,
                    121,
                    16,
                    10,
                    0,
                    21,
                    117,
                    69,
                    3,
                    62,
                    59,
                    45,
                    95,
                    129,
                    173,
                    166,
                    221,
                    139,
                    1
                ]
            },
            "account_number": 7446375,
            "sequence": 1
        }
    ]
}
satoshiotomakan commented 11 months ago

Hi @0x-General, could you please help to find out actual request and expected response payloads? I used https://thorswap.github.io/SwapKit/ to generate a send or swap requests with BNB chain, here's what I got:

These requests do not match the documentation:

  1. There is no request.signDoc.fee - probably, it supposes to be optional?
  2. request.signDoc.msgs do not have type and value fields.

Can we expect cosmos_signDirect request instead?

Could you please also advice, did you get this response from the TrustWallet Android app?

satoshiotomakan commented 11 months ago

One note - https://thorswap.github.io/SwapKit/ generates an expected payload on cosmos_signAmino for THORChain: https://gist.github.com/satoshiotomakan/e72631f61cbee10cc81dc0469e1e270e

satoshiotomakan commented 10 months ago

Hi @0x-General, we adopted WalletCore API to be able to parse and handle BNB signing requests through WalletConnect 2.0. The new Android/iOS releases coming soon