@lunie/cosmos-ledger
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

Cosmos Ledger

Cosmos Ledger is a library for interacting with the Cosmos Ledger Nano App. It provides a developer-friendly interface and user friendly error messages for an improved Ledger Nano development experience.

This library is based on ledger-cosmos-js by Juan Leni who also implemented the official Cosmos Ledger Nano App.

Thank you Juan! 🙌

Installation

yarn add @lunie/cosmos-ledger

Usage

Signing with the Ledger Nano

import Ledger from "@lunie/cosmos-ledger"

// generate messages with "@lunie/cosmos-api"
const signMessage = {} || ``
const ledger = await Ledger().connect()
const signature = await ledger.sign(signMessage)

Using with cosmos-api

import Ledger from "@lunie/cosmos-ledger"
import Cosmos from "@lunie/cosmos-api"

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

// init cosmos API object
const cosmos = Cosmos(API_URL, ADDRESS)

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

// create a signer
const ledgerSigner = async (signMessage) => {
  const ledger = new Ledger()
  await ledger.connect()
  const publicKey = await ledger.getPubKey()
  const signature = await ledger.sign(signMessage)

  return {
    signature,
    publicKey
  }
}

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

// wait for the transaction to be included in a block
await included()

Constructor options

Ledger(
  { testModeAllowed = false },
  hdPath = [44, 118, 0, 0, 0], // HDPATH
  hrp = 'cosmos', // BECH32PREFIX
);

Package Sidebar

Install

npm i @lunie/cosmos-ledger

Weekly Downloads

29

Version

0.1.8

License

MIT

Unpacked Size

35.2 kB

Total Files

8

Last publish

Collaborators

  • faboweb