@acryl/ledger
v3.3.3
Published
Acryl ladger lib for browser
Downloads
4
Readme
Acryl sign data by ledger in browser
Install
$ npm install --save @acryl/ledger
Usage
Create connection
const AcrylLedger = require('@acryl/ledger');
const ledger = new AcrylLedger();
AcrylLedger
can have optional arguments.
import TransportNodeHid from '@ledgerhq/hw-transport-node-u2f';
const options = {
debug: true, //boolean,
openTimeout: 3000, //number,
listenTimeout: 30000, //number,
exchangeTimeout: 30000, //number,
networkCode: 65, //number,
transport: TransportNodeHid
};
const ledger = new AcrylLedger(options);
Where:
debug
enable or not logs of the binary exchange.
openTimeout
is a delay number in ms for waiting connection.listenTimeout
is a delay number in ms for waiting listen request to U2F device.exchangeTimeout
is a timeout (in milliseconds) for the exchange call. Only some transport might implement it. (e.g. U2F).networkCode
is Acryl network code (65 - for mainet)transport
is U2F Transport implementation. (hw-transport-u2f by default)
- @ledgerhq/hw-transport-u2f
- @ledgerhq/hw-transport-webusb
- @ledgerhq/hw-transport-web-ble
- @ledgerhq/hw-transport-http
AcrylLedger API
probeDevice
probeDevice(): Promise. If device available and ready, Promise returned true.
const canIUse = async () => { return await ledger.probeDevice(); }
tryConnect
tryConnect(): Promise<>. reconnect to Transport and init ledger libs.
const isLedgerReady = async () => { try { return await ledger.tryConnect(); } catch (e) { ///...error handlers } };
getUserDataById
getUserDataById(id): Promise. Get user from ledger, where user is:
{ id: number, path: string, acrylAddress: string, publicKey: string }
id - is number from 0
path - is string in internal ledger format
acrylAddress - is string in base58 format
publicKey - is string in base58 formatledger.getUserDataById(id) .then( (user) => {...}, (err) => {...} );
signTransaction
Sign acryl transaction bytes (ledger show detailed transaction info)
ledger.signTransaction(userId, asset, data)
userId - number data - Array number form 0 to 255 asset - {precision: number, ...}
Result is Promise with signature string in base58 format
signSomeData
Sign any bytes (ledger can't show detail info)
ledger.signSomeData(userId, data)
userId - number data - Array number form 0 to 255
Result is Promise with signature string in base58 format
signRequest
Sign any bytes (ledger can't show detail info)
ledger.signRequest(userId, data)
userId - number data - Array number form 0 to 255
Result is Promise with signature string in base58 format
signMessage
Sign any string (ledger can't show detail info)
ledger.signMessage(userId, data)
userId - number data - string
Result is Promise with signature string in base58 format