Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@lunie/cosmos-keys

luniehq3.6kApache-2.00.3.2TypeScript support: included

js version of cosmos wallet signer and address generation

cosmos, cosmos.network, cosmos wallet, cosmos signer, cosmos javascript, cosmos sdk, cosmos-sdk

readme

Cosmos Keys

Cosmos Keys is a library for creating keys and signing messages on Cosmos. You can use it to generate keypairs and addresses and to sign messages for the Cosmos Network.

This library deals with tasks that are considered security-critical and should be used very carefully.

Install

yarn add @lunie/cosmos-keys

Usage

Create a wallet

import { getNewWallet } from "@lunie/cosmos-keys"

const { cosmosAddress, privateKey, publicKey } = getNewWallet()
// Attention: protect the `privateKey` at all cost and never display it anywhere!!

Import a seed

import { getNewWalletFromSeed } from "@lunie/cosmos-keys"

const seed = ...24 seed words here


//bech32prefix   

const bech32prefix = 'cosmos';
const { cosmosAddress, privateKey, publicKey } = getNewWalletFromSeed(seed, bech32prefix)

// Attention: protect the `privateKey` at all cost and never display it anywhere!!

Sign a message

import { signWithPrivateKey } from "@lunie/cosmos-keys"

const privateKey = Buffer.from(...)
const signMessage = ... message to sign, generate messages with "@lunie/cosmos-js"
const signature = signWithPrivateKey(signMessage, privateKey)

Using with cosmos-js

import { signWithPrivateKey } from "@lunie/cosmos-keys"
import Cosmos from "@lunie/cosmos-js"

const privateKey = Buffer.from(...)
const publicKey = Buffer.from(...)

// init cosmos sender
const cosmos = Cosmos(STARGATE_URL, ADDRESS)

// create message
const msg = cosmos
  .MsgSend({toAddress: 'cosmos1abcd09876', amounts: [{ denom: 'stake', amount: 10 }]})

// create a signer from this local js signer library
const localSigner = (signMessage) => {
  const signature = signWithPrivateKey(signMessage, privateKey)

  return {
    signature,
    publicKey
  }
}

// send the transaction
const { included }= await msg.send({ gas: 200000 }, localSigner)

// await tx to be included in a block
await included()

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[0.3.2] - 2020-09-24

Changed

  • #125 Export the removeFromStorage function @Bitcoinera

[0.3.1] - 2020-07-31

Changed

  • #89 GetWalletIndex returns HDPath and curve when enriched @Bitcoinera

[0.3.0] - 2020-07-15

Changed

  • #86 Store accountType/algo in StoredWallet @Bitcoinera

[0.2.3] - 2020-06-24

Added

  • #73 Adds the dependabot config for the repo @Bitcoinera
  • #76 Adds a function to derive a Tendermint address from its private key @Bitcoinera
  • Store seed phrase @faboweb

Changed

  • #73 Changes the script name for changelog to changelog @Bitcoinera

[0.2.2] - 2020-05-10

Changed

  • #34 Switch to bcrypt for node compatibility @faustbrian

[0.2.1] - 2020-01-29

Changed

  • #31 Enrich wallets info with network value @iambeone

[0.2.0] - 2020-01-27

Added

  • #30 Storing network value in wallet @iambeone

[0.0.12] - 2019-12-17

Added

  • Use any bech32 prefix to create accounts @Bitcoinera

Repository

  • Remove all languages for bip39 wordlists but english to reduce the size of the bundle @colw

[0.0.11] - 2019-10-07

Added

  • Made library node compatible @AlexBHarley @faboweb

[0.0.10] - 2019-06-19

Added

  • Added a mechanism to store keys in local storage @faboweb

Fixed

  • Key creation would create sometimes keys of wrong length @faboweb

Repository

  • Made the repository CI ready @faboweb

[0.0.9] - 2019-06-02

Added

  • accept strings as signmessage @faboweb

[0.0.8] - 2019-06-02

Fixed

  • Typo in bundle name caused issues with integration @faboweb

[0.0.7] - 2019-06-02

Fixed

  • Release didn't include correct files @faboweb
  • Fixed publishing wrong files @faboweb

Repository

  • Changed license to Apache-2 @faboweb

[0.0.6] - 2019-06-01

Repository

  • Switched to webpack from rollup to simplify repository @faboweb

[0.0.5] - 2019-05-24

Deprecated

  • Removed some data structure relevant code from this library to make it signing only @faboweb

[0.0.4] - 2019-04-14

Added

  • Added changelog @faboweb

Changed

  • Slightly improved API (breaking) @faboweb
  • Slimmed repository architecture @faboweb

Fixed

  • Fixed tests @faboweb