Cosmos Lib
JS implementation of Cosmos cryptography and addresses logic.
Features:
- Generate private/public key from mnemonic and path.
- Sign/verify bytes/JSON with private/public key.s
- Convert Cosmos bech32 address to bytes32 (solidity capability).
Installation
Install dependency:
yarn add cosmos-lib
And use in code:
const cosmos = require('cosmos-lib');
Usage
Generate private/public key from mnemonic:
const MNEMONIC = 'cluster unveil differ bright define prosper hunt warrior fetch rough host fringe worry mention gospel enlist elder laugh segment funny avoid regular market fortune'; const keys = cosmoscrypto;console;
Sign bytes/JSON:
const bytes = crypto;const json = data: crypto; let signature = cosmoscrypto;let verify = cosmoscrypto; if !verify throw 'Cant verify signature'; signature = cosmoscrypto;verify = cosmoscrypto; if !verify throw 'Cant verify signature';
Get address from public key:
const prefix = 'mywallet';const address = cosmosaddress; // prefix by default is 'cosmos'.console;
Get bytes32 from address:
bytes32 = cosmosaddress;console;
More examples could be found in tests.
Docs
To generate docs:
yarn global add jsdoc
yarn run docs
Then server them from out
directory.
Tests
To run tests:
git clone git@github.com:WingsDao/cosmos-lib.git
cd cosmos-lib/
yarn install
yarn test
LICENSE
MIT.