Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors while signing transactions #74

Open
jacobtjackson opened this issue Jun 18, 2020 · 2 comments
Open

Errors while signing transactions #74

jacobtjackson opened this issue Jun 18, 2020 · 2 comments

Comments

@jacobtjackson
Copy link

Hi,

I'm developing a block explorer with the ability to delegate tokens for the secret network. We forked our code from hubble but the code they were using to connect with a Ledger wallet was not functional. I decided to use this library along with some code taken from the big dipper to connect with the ledger. I also tried using your cosmos-api/cosmos-js library but I had a lot of problems figuring out how to use those libraries with this one. The main error I've been getting comes from the ledger.sign(msg) method. I've tried passing a few different things to this method that seem to work in other codebases, but I can't figure out what the issue is here. From looking at the library briefly, it seems like it's saying that ledger.hdPath isn't a buffer, array, etc. but I know it is from the testing I've done. This is the message I'm currently passing to ledger.sign():

      "msg": [
        {
          "type": `cosmos-sdk/Send`,
          "value": {
            "inputs": [
              {
                "address": this.publicAddress,
                "coins": [{ "denom": `STAKE`, "amount": `1` }]
              }
            ],
            "outputs": [
              {
                "address": App.config.validatorOperatorAddress,
                "coins": [{ "denom": `STAKE`, "amount": `1` }]
              }
            ]
          }
        }
      ],
      "fee": { "amount": [{ "denom": ``, "amount": `0` }], "gas": `21906` },
      "signatures": null,
      "memo": ``
    }

const txSkeleton = {
      "type": 'auth/StdTx',
      "value": {
        "msg": msgs,
        "fee": '',
        "memo": txContext.value.memo || this.MEMO,
        "signatures": [{
          "signature": 'N/A',
          "account_number": txContext.value.account_number.toString(),
          "sequence": txContext.value.sequence.toString(),
          "pub_key": {
            "type": 'tendermint/PubKeySecp256k1',
            "value": txContext.pk || 'PK',
          },
        }],
      },
    };```

I've been passing this to `ledger.sign()` like this: `ledger.sign(txSkeleton)` and I get `cosmos-ledger.js:658 Uncaught (in promise) Error: Ledger Native Error: TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.` as an error. I decided to put the message in an array (`ledger.sign([txSkeleton])` and I get `cosmos-ledger.js:658 Uncaught (in promise) Error: Ledger Native Error: Data is invalid : JSON. Zero tokens`. I'm kind of at a loss as to what is happening here. Would very much appreciate any help that would put me on the right path
@faboweb
Copy link
Contributor

faboweb commented Jun 18, 2020

You need to pass in a string (the sign message).
We get our sign message like this: https://github.com/luniehq/lunie/blob/develop/app/src/signing/networkMessages/cosmos-transactions.js#L91
We pass it to the Ledger library like this:
https://github.com/luniehq/lunie/blob/develop/app/src/signing/signer.js#L84

@jacobtjackson
Copy link
Author

@faboweb That helped, thank you! I was able to get the ledger to sign the message. I'm now having trouble broadcasting it, though. The ledger.sign() method is returning an array of numbers, and I'm passing those to a function that POSTs to {url}/txs with a payload like this { tx: txPayload, mode: 'sync' }. I get a failure response from that endpoint that looks like this: {ok: false, height: "0", txhash: "2010346925C7B8DBBC79DDCD1633FA4BF6B4169063E38DB6F01328AD31BE174D", code: 18, raw_log: "invalid request: must contain at least one message"}. Am I passing the delegation message in the sign payload incorrectly?

This is the updated payload that I'm passing to ledger.sign():

{
  "account_number":196,
  "chain_id":"secret-1",
  "fee":{
    "amount":[{
      "amount":"3750",
      "denom":"uscrt"
    }],
    "gas":"150000"
  }, 
  "memo":"Delegate to your favorite validator with Puzzle - https://puzzle.secretnodes.org",
  "msgs":[{
    "type":"cosmos-sdk/MsgDelegate",
    "value": {
      "amount":{ "amount":"1000000","denom":"uscrt"},
      "delegator_address":"secret1g5ec3qgzgvt6g2xheaj9vrygugn2f80mww2v3z",
      "validator_address":"secretvaloper1hjd20hjvkx06y8p42xl0uzr3gr3ue3nkvd79jj"
    }
  }],
  "sequence":0
}```


Thanks again for your help and the prompt response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants