Keycard Pro Library based on @ledgerhq/hw-app-eth and @ledgerhq/hw-transport.
KProJS permits you to communicate with Keycard Pro through websites and through nodejs-based native applications.
Ethereum API
transport
Transport
import KProJS from "kprojs";
const eth = new KProJS.Eth(transport)
get Ethereum address for a given BIP 32 path.
const resp = await eth.getAddress("44'/60'/0'/0/0");
console.log(resp.address);
Returns Promise<{publicKey: string, address: string, chainCode: string?}> an object with a publicKey, address and (optionally) chainCode
sign a transaction and retrieve v, r, s given the raw transaction and the BIP 32 path of the account to sign.
path
string : the BIP32 path to sign the transaction onrawTxHex
string : the raw ethereum transaction in hexadecimal to sign
const tx = "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080"; // raw tx to sign
const resp = eth.signTransaction("44'/60'/0'/0/0", tx);
console.log(resp);
Returns Promise<{s: string, v: string, r: string}>
get firmware and ERC20 DB version installed on the Keycard Pro device.
const {fwVersion, erc20Version} = await eth.getAppConfiguration();
console.log(fwVersion);
console.log(erc20Version);
Returns Promise<{fwVersion: string, erc20Version: number}>
sign a personal message and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
const resp = await eth.signPersonalMessage("44'/60'/0'/0/0", "Hello world!");
let v = resp['v'] - 27;
v = v.toString(16);
if (v.length < 2) {
v = "0" + v;
}
console.log("Signature 0x" + resp['r'] + resp['s'] + v);
Returns Promise<{v: number, s: string, r: string}>
sign an EIP-712 formatted message
const resp = await eth.signEIP712Message("44'/60'/0'/0/0", {
domain: {
chainId: 69,
name: "Da Domain",
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
version: "1"
},
types: {
"EIP712Domain": [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
{ name: "verifyingContract", type: "address" }
],
"Test": [
{ name: "contents", type: "string" }
]
},
primaryType: "Test",
message: {contents: "Hello, Bob!"},
});
Returns Promise<{v: number, s: string, r: string}>
load Keycard Pro firmware
fw
ArrayBuffer firmware
const fs = require('fs'),
let f = fs.readFileSync('./firmware.bin');
let fw = new Uint8Array(f);
await eth.loadFirmware(fw);
load ERC20 & chain database
db
ArrayBuffer ERC20 & Chain DB
const fs = require('fs'),
let f = fs.readFileSync('./erc20db.bin');
let db = new Uint8Array(f);
await eth.loadERC20DB(db);
You can check a demo at KPro Web HID Example Page.