JSPM

@hazae41/ledger

0.1.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 237
  • Score
    100M100P100Q71065F
  • License MIT

Private and supply-chain hardened Ledger controller for TypeScript

Package Exports

  • @hazae41/ledger

Readme

Ledger

Private and supply-chain hardened Ledger controller for TypeScript

npm i @hazae41/ledger

Node Package 📦

Features

Current features

  • 100% TypeScript and ESM
  • No external dependencies
  • Rust-like patterns
  • No network code
  • No tracking

Usage

Get USB connector

/** Will open a popup using navigator.usb */
const device = Ledger.USB.getOrRequestDeviceOrThrow()
const connector = Ledger.USB.connectOrThrow(device)

Get address and/or uncompressed public key at path

import { Ledger } from "@hazae41/ledger"

const { address, uncompressedPublicKey } = await Ledger.Ethereum.getAddressOrThrow(connector, "44'/60'/0'/0/0")

Verify and get address and/or uncompressed public key at path

Ask the user to verify the address and get it

import { Ledger } from "@hazae41/ledger"

const { address, uncompressedPublicKey } = await Ledger.Ethereum.verifyAndGetAddressOrThrow(connector, "44'/60'/0'/0/0")

Sign a personal message at path

import { Ledger } from "@hazae41/ledger"
import { ZeroHexSignature } from "@hazae41/cubane"

const message = new TextEncoder().encode("Hello World")

const rsvSignature = await Ledger.Ethereum.signPersonalMessageOrThrow(connector, "44'/60'/0'/0/0", message)
const zeroHexSignature = ZeroHexSignature.fromOrThrow(rsvSignature)

Sign a transaction at path

import { Ledger } from "@hazae41/ledger"
import { ZeroHexSignature } from "@hazae41/cubane"

const transaction = ethers.utils.arrayify(ethers.Transaction.from({
  chainId,
  nonce,
  to,
  value,
  data
  gasLimit,
  gasPrice,
}).unsignedSerialized)

const rsvSignature = await Ledger.Ethereum.signTransactionOrThrow(connector, "44'/60'/0'/0/0", transaction)
const zeroHexSignature = ZeroHexSignature.fromOrThrow(rsvSignature)

Sign EIP712 typed message at path

import { Ledger } from "@hazae41/ledger"
import { ZeroHexSignature } from "@hazae41/cubane"

const rsvSignature = await Ledger.Ethereum.signEIP712HashedMessageOrThrow(connector, "44'/60'/0'/0/0", domain, message)
const zeroHexSignature = ZeroHexSignature.fromOrThrow(rsvSignature)