Skip to content

Instantly share code, notes, and snippets.

@zmanian
Last active March 22, 2019 21:12
Show Gist options
  • Select an option

  • Save zmanian/ede8bbde812bf6f8cf15530583d2d477 to your computer and use it in GitHub Desktop.

Select an option

Save zmanian/ede8bbde812bf6f8cf15530583d2d477 to your computer and use it in GitHub Desktop.

Cosmos signing

Cosmos transaction signing is a fairly simple process.

Every Cosmos transaction has a canonical json representation. The gaiacli and stargate rest interfaces provides canonical json representations of transactions and their broadcast function will provide compact amino(a protobuf like format) encoding translations.

Things to know when signing messages.

The format is

{ 
"account_number": XXX,
"chain_id":XXX,
"fee":XXX,
"sequence":XXX 
"memo":XXX,
"msgs":XXX
}

The signer must supply chain_id, account number and sequence number.

Fee, msg and memo will be supplied by the transaction composer interface.

account_number and sequence can be queried directly from the blockchain or cached locally. Getting these numbers wrong is a common cause of invalid signature errors. You can load the mempool of a full node or validator with a sequence of uncommitted transactions with incrementing sequence numbers and it will mostly do the correct thing.

Before signing, all keys are lexicographically sorted and all white space is removed from the JSON output before signing.

The Signature encoding is the 64-byte concatenation of ECDSArands(ie.r || s), where s is lexicographically less than it’s inverse, to prevent malleability. This is like Ethereum, but without the extra byte for pubkey recovery, since Tendermint assumes the pubkey is always provided anyway.

Singature and public

{
"pub_key":{
"type":"tendermint/PubKeySecp256k1",
"value":XXX
},
"signature":XXX
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment