Sig
Sig is a signing library for Cosmos, supported in Node.js and browsers.
Sig provides JavaScript functions and TypeScript types for
- Deriving a wallet (private key, public key, and address) from a mnemonic
- Deriving an address from a public key
- Structuring a transaction
- Signing a transaction
- Verifying signatures for a transaction
- Preparing a transaction for broadcast
Sig does not provide functions for
- Generating a mnemonic
- Storing keys or other secrets
- Obtaining data from a chain
- Broadcasting transactions
Sig is designed to work well with other libraries like
Sig is experimental and not recommended for use in production yet. Please help us test and improve it!
As always, please be careful to protect any mnemonic phrases, passwords, and private keys.
Demo
Documentation
https://cosmos.github.io/sig/
Install
Please note that the NPM package name is @tendermint/sig
rather than @cosmos/sig
.
Yarn
yarn add @tendermint/sig
NPM
npm install --save @tendermint/sig
Usage
Derive a wallet (private key, public key, and address) from a mnemonic
import { createWalletFromMnemonic } from '@tendermint/sig';
const mnemonic = 'trouble salon husband push melody usage fine ensure blade deal miss twin';
const wallet = createWalletFromMnemonic(mnemonic);
Derive a Bech32 address from a public key
import { createAddress } from '@tendermint/sig';
const address = createAddress(publicKey);
Sign a transaction
import { signTx } from '@tendermint/sig';
const tx = {
fee: {
amount: [{ amount: '0', denom: '' }],
gas: '10000'
},
memo: '',
msg: [{
type: 'cosmos-sdk/MsgSend',
value: {
from_address: 'cosmos1qperwt9wrnkg5k9e5gzfgjppzpqhyav5j24d66',
to_address: 'cosmos1yeckxz7tapz34kjwnjxvmxzurerquhtrmxmuxt',
amount: [{ amount: '1', denom: 'STAKE' }]
}
}]
};
const signMeta = {
account_number: '1',
chain_id: 'cosmos',
sequence: '0'
};
const stdTx = signTx(tx, signMeta, wallet);
Verify a transaction
import { verifyTx } from '@tendermint/sig';
const valid = verifyTx(stdTx, signMeta);
Please see the documentation for the full API.
Building
git clone https://github.com/cosmos/sig.git
cd sig
yarn install
yarn setup
yarn test
Contributing
Sig is very new! Questions, feedback, use cases, issues, and code are all very, very welcome.
Thank you for helping us help you help us all. 🎁
Alternatives
A number of other projects exist that help with signing for Cosmos.
Please check them out and see if they are right for you!