Ledger Hardware Wallet JavaScript bindings for Avalanche, based on LedgerJS.
Here is a sample app for Node:
const Transport = require("@ledgerhq/hw-transport-node-hid").default;
const Avalanche = require("@obsidiansystems/hw-app-avalanche").default;
const getWalletId = async () => {
const avalanche = new Avalanche(await Transport.create());
return await avalanche.getWalletId();
};
const signHash = async () => {
const transport = await Transport.create();
const avalanche = new Avalanche(await Transport.create());
return await avalanche.signHash(
"44'/9000'/0'/0/0",
"0000000000000000000000000000000000000000000000000000000000000000"
);
};
const getVersion = async () => {
const avalanche = new Avalanche(await Transport.create());
return await avalanche.getAppConfiguration();
};
const getAddress = async () => {
const avalanche = new Avalanche(await Transport.create());
return await avalanche.getWalletPublicKey("44'/9000'/0'/1/0");
};
const doAll = async () => {
console.log(await getWalletId());
console.log(await getVersion());
console.log(await getAddress());
console.log(await signHash());
};
doAll().catch(err => console.log(err));
Avalanche API for Ledger
transport
Transport<any>
scrambleKey
string (optional, default"Avalanche"
)
import Avalanche from "@obsidiansystems/hw-app-avalanche";
const avalanche = new Avalanche(transport);
Get Avalanche address for a given BIP-32 path.
path
string a path in BIP-32 format
const publicKey = await avalanche.getWalletPublicKey("44'/9000'/0'/0/0");
Returns Promise<string> an object with a public key.
Sign a 32-byte hash of transaction with a given BIP-32 path
const signature = await avalanche.signHash("44'/9000'/0'/0/0", "0000000000000000000000000000000000000000000000000000000000000000");
Returns Promise<string> a signature as hex string.
Get the version of the application installed on the hardware device.
console.log(await avalanche.getAppConfiguration());
produces something like
{
"version": "1.0.3",
"commit": "1234567",
"name": "Avax"
}
Returns Promise<{version: string, commit: string, name: string}> an object with a version.
Get the wallet identifier for the Ledger wallet. This value distinguishes different Ledger hardware devices which have different seeds.
console.log(await avalanche.getWalletId());
produces something like
abcdefgh