Skip to content
/ ledger Public

Private and supply-chain hardened Ledger controller for TypeScript

Notifications You must be signed in to change notification settings

hazae41/ledger

Repository files navigation

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)

About

Private and supply-chain hardened Ledger controller for TypeScript

Resources

Stars

Watchers

Forks

Packages

No packages published