Errors while signing transactions
jacobtjackson opened this issue · 2 comments
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
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
@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!