libnemo
Version:
Nano cryptocurrency wallet library.
106 lines (105 loc) • 4.4 kB
TypeScript
import { Block } from './block';
import { Rpc } from './rpc';
type LedgerStatus = 'UNSUPPORTED' | 'DISCONNECTED' | 'BUSY' | 'LOCKED' | 'CONNECTED';
interface LedgerResponse {
status: string;
}
interface LedgerAccountResponse extends LedgerResponse {
publicKey: string | null;
address: string | null;
}
/**
* Ledger hardware wallet created by communicating with a Ledger device via ADPU
* calls. This wallet does not feature any seed nor mnemonic phrase as all
* private keys are held in the secure chip of the device. As such, the user
* is responsible for using Ledger technology to back up these pieces of data.
*
* https://github.com/roosmaa/ledger-app-nano/blob/master/doc/nano.md
*/
export declare class Ledger {
#private;
static addEventListener: (type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean) => void;
static dispatchEvent: (event: Event) => boolean;
static removeEventListener: (type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean) => void;
/**
* Check which transport protocols are supported by the browser and return the
* transport type according to the following priorities: HID, Bluetooth, USB.
*/
static get isUnsupported(): boolean;
/**
* Vendor ID assigned to Ledger for HID and USB interfaces.
* https://github.com/LedgerHQ/ledger-live/blob/develop/libs/ledgerjs/packages/devices/src/index.ts#L164
*/
static get ledgerVendorId(): 0x2c97;
/**
* Status of the Ledger device connection.
*
* UNSUPPORTED | DISCONNECTED | BUSY | LOCKED | CONNECTED
*/
static get status(): LedgerStatus;
/**
* Request an account at a specific BIP-44 index.
*
* @returns Response object containing command status, public key, and address
*/
static account(index?: number, show?: boolean): Promise<LedgerAccountResponse>;
/**
* Check if the Nano app is currently open and set device status accordingly.
*
* @param {string} [api] Transport interface to use
* @returns Device status as follows:
* - UNSUPPORTED: Platform does not support any Ledger transport protocols
* - DISCONNECTED: Failed to communicate properly with the app
* - BUSY: Nano app is not currently open
* - LOCKED: Nano app is open but the device locked after a timeout
* - CONNECTED: Nano app is open and listening
*/
static connect(api?: 'hid' | 'ble' | 'usb'): Promise<LedgerStatus>;
/**
* Clears Ledger connections from HID and USB interfaces and stops polling for
* connection updates.
*/
static disconnect(): Promise<void>;
/**
* Sign a block with the Ledger device.
*
* @param {number} index - Account number
* @param {Block} block - Block data to sign
* @param {Block} [frontier] - Previous block data to cache in the device
*/
static sign(index: number, block: Block, frontier?: Block): Promise<string>;
/**
* Update cache from raw block data. Suitable for offline use.
*
* @param {number} index - Account number
* @param {object} block - JSON-formatted block data
*/
static updateCache(index: number, block: Block): Promise<LedgerResponse>;
/**
* Update cache from a block hash by calling out to a node. Suitable for online
* use only.
*
* @param {number} index - Account number
* @param {string} hash - Hexadecimal block hash
* @param {Rpc} rpc - Rpc class object with a node URL
*/
static updateCache(index: number, hash: string, rpc: Rpc): Promise<LedgerResponse>;
/**
* Checks whether a given seed matches the wallet seed. The wallet must be
* unlocked prior to verification.
*
* @param {string} seed - Hexadecimal seed to be matched against the wallet data
* @returns True if input matches wallet seed
*/
static verify(seed: string): Promise<boolean>;
/**
* Checks whether a given mnemonic phrase matches the wallet mnemonic. If a
* personal salt was used when generating the mnemonic, it cannot be verified.
* The wallet must be unlocked prior to verification.
*
* @param {string} mnemonic - Phrase to be matched against the wallet data
* @returns True if input matches wallet mnemonic
*/
static verify(mnemonic: string): Promise<boolean>;
}
export {};