Private and supply-chain hardened Ledger controller for TypeScript
npm i @hazae41/ledger
- 100% TypeScript and ESM
- No external dependencies
- Rust-like patterns
- No network code
- No tracking
/** Will open a popup using navigator.usb */
const device = Ledger.USB.getOrRequestDeviceOrThrow()
const connector = Ledger.USB.connectOrThrow(device)
import { Ledger } from "@hazae41/ledger"
const { address, uncompressedPublicKey } = await Ledger.Ethereum.getAddressOrThrow(connector, "44'/60'/0'/0/0")
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")
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)
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)
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)