Skip to content
Library for creating keys and signing messages on Cosmos πŸ”‘
TypeScript JavaScript
Branch: develop
Clone or download
Latest commit a09de04 Jul 4, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci switched ci location of pending changelog files Jun 19, 2019
pending Merge pull request #9 from luniehq/fabo/node-compat Jun 20, 2019
src Replacing global type declarations with types file. Jun 21, 2019
test linted Jun 19, 2019
.editorconfig first commit Mar 7, 2019
.gitignore switched to webpack Jun 1, 2019
CHANGELOG.md release-0.0.10 Jun 19, 2019
README.md Update README Jun 27, 2019
package.json release-0.0.10 Jun 19, 2019
tsconfig.json switched to webpack Jun 1, 2019
tslint.json first commit Mar 7, 2019
webpack.config.js made node compatible Jun 19, 2019
yarn.lock linted Jun 19, 2019

README.md

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 { generateWalletFromSeed } from "@lunie/cosmos-keys"

const seed = ...24 seed words here

const { cosmosAddress, privateKey, publicKey } = generateWalletFromSeed(seed)
// 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()
You can’t perform that action at this time.