UNPKG

libnemo

Version:

Asynchronous, non-blocking Nano cryptocurrency integration toolkit.

1,060 lines (1,032 loc) 40.1 kB
//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev> //! SPDX-License-Identifier: GPL-3.0-or-later import { default as TransportBLE } from '@ledgerhq/hw-transport-web-ble' import { default as TransportUSB } from '@ledgerhq/hw-transport-webusb' import { default as TransportHID } from '@ledgerhq/hw-transport-webhid' /** * Represents a single Nano address and the associated public key. To include the * matching private key, it must be known at the time of object instantiation. * The frontier, balance, and representative for the account can also be set or * be fetched from the network. */ export declare class Account { #private get address (): string get index (): number | undefined get publicKey (): string get balance (): bigint | undefined get frontier (): string | undefined get receivable (): bigint | undefined get representative (): Account | undefined get weight (): bigint | undefined set balance (v: bigint | undefined) set frontier (v: string | undefined) set receivable (v: bigint | undefined) set representative (v: Account | undefined) set weight (v: bigint | undefined) private constructor () /** * Removes encrypted secrets in storage and releases variable references to * allow garbage collection. */ destroy (): Promise<void> /** * Instantiates an Account object from its Nano address. * * @param {string} address - Address of the account * @returns {Account} A new Account object */ static import (address: string): Account /** * Instantiates Account objects from their Nano addresses. * * @param {string[]} addresses - Addresses of the accounts * @returns {Account[]} Array of new Account objects */ static import (addresses: string[]): Account[] /** * Instantiates an Account object from its public key. It is unable to sign * blocks or messages since it has no private key. * * @param {Key} publicKey - Public key of the account * @returns {Account} A new Account object */ static import (publicKey: Key): Account /** * Instantiates Account objects from their public keys. They are unable to sign * blocks or messages since they have no private key. * * @param {Key[]} publicKeys - Public keys of the accounts * @returns {Account[]} Array of new Account objects */ static import (publicKeys: Key[]): Account[] /** * Instantiates an Account object from its public key. It is unable to sign * blocks or messages since it has no private key. * * @param {KeyPair} keypair - Index and keys of the account * @returns {Account} A new Account object */ static import (keypair: KeyPair): Account /** * Instantiates Account objects from their public keys. They are unable to sign * blocks or messages since they have no private key. * * @param {KeyPair[]} keypairs - Indexes and keys of the accounts * @returns {Account[]} Array of new Account objects */ static import (keypairs: KeyPair[]): Account[] /** * Instantiates an Account object from its private key which is then encrypted * and stored in IndexedDB. The corresponding public key will automatically be * derived and saved. * * @param {KeyPair} keypair - Index and keys of the account * @param {Key} password - Used to encrypt the private key * @returns {Promise<Account>} Promise for a new Account object */ static import (keypair: KeyPair, password: Key): Promise<Account> /** * Instantiates Account objects from their private keys which are then * encrypted and stored in IndexedDB. The corresponding public keys will * automatically be derived and saved. * * @param {KeyPair[]} keypairs - Indexes and keys of the accounts * @param {Key} password - Used to encrypt the private keys * @returns {Promise<Account[]>} Promise for array of new Account objects */ static import (keypairs: KeyPair[], password: Key): Promise<Account[]> /** * USING THIS METHOD IS DISCOURAGED. This library works in its entirety without * exposing the private keys of accounts. * * Retrieves and decrypts the private key of the Account. The same password * used to lock it must be used to unlock it. If derived from a wallet, the * password for the account is the wallet seed. * * @param {Key} password Used previously to lock the Account * @returns Private key bytes as a Uint8Array */ export (password: Key): Promise<Uint8Array<ArrayBuffer>> /** * USING THIS METHOD IS DISCOURAGED. This library works in its entirety without * exposing the private keys of accounts. * * Retrieves and decrypts the private key of the Account. The same password * used to lock it must be used to unlock it. If derived from a wallet, the * password for the account is the wallet seed. * * @param {Key} password Used previously to lock the Account * @returns Private key bytes as a hexadecimal string */ export (password: Key, format: 'hex'): Promise<string> /** * Refreshes the account from its current state on the network. * * A successful response sets the balance, frontier, and representative * properties. * * @param {Rpc|string|URL} rpc - RPC node information required to call `account_info` */ refresh (rpc: Rpc | string | URL): Promise<void> /** * Signs a block using the private key of the account. The signature is * appended to the signature field of the block before being returned. * * @param {(ChangeBlock|ReceiveBlock|SendBlock)} block - The block data to be hashed and signed * @param {Key} password - Required to decrypt the private key for signing * @returns {Promise<string>} Hexadecimal-formatted 64-byte signature */ sign (block: ChangeBlock | ReceiveBlock | SendBlock, password: Key): Promise<string> /** * Validates a Nano address with 'nano' and 'xrb' prefixes * Derived from https://github.com/alecrios/nano-address-validator * * @param {string} address - Nano address to validate * @throws Error if address is undefined, not a string, or an invalid format */ static validate (address: unknown): asserts address is string } export declare class AccountList extends Object { [index: number]: Account get length (): number; [Symbol.iterator] (): Iterator<Account> } /** * Represents a mnemonic phrase that identifies a wallet as defined by BIP-39. */ export declare class Bip39Mnemonic { #private get phrase (): string private constructor () /** * Imports and validates an existing mnemonic phrase. * * The phrase must be valid according to the BIP-39 specification. Typically * wallets use the maximum of 24 words. * * @param {string} phrase - String of 12, 15, 18, 21, or 24 words * @returns {string} Mnemonic phrase validated using the BIP-39 wordlist */ static fromPhrase (phrase: string): Promise<Bip39Mnemonic> /** * Derives a mnemonic phrase from source of entropy or seed. * * The entropy must be between 32-64 characters to stay within the defined * limit of 128-256 bits. Typically wallets use the maximum entropy allowed. * * @param {string} entropy - Hexadecimal string * @returns {string} Mnemonic phrase created using the BIP-39 wordlist */ static fromEntropy (entropy: string): Promise<Bip39Mnemonic> /** * SHA-256 hash of entropy that is appended to the entropy and subsequently * used to generate the mnemonic phrase. * * @param {Entropy} entropy - Cryptographically strong pseudorandom data of length N bits * @returns {Promise<string>} First N/32 bits of the hash as a hexadecimal string */ static checksum (entropy: Entropy): Promise<string> /** * Erases seed bytes and releases variable references to allow garbage * collection. */ destroy (): void /** * Validates a mnemonic phrase. * * @param {string} mnemonic - Mnemonic phrase to validate * @returns {boolean} True if the mnemonic phrase is valid */ static validate (mnemonic: string): Promise<boolean> toBip39Seed (passphrase: string): Promise<Uint8Array<ArrayBuffer>> /** * Converts the mnemonic phrase to a BIP-39 seed. * * A passphrase string can be specified. If the passphrase is undefined, null, * or not a string, the empty string ("") is used instead. * * @param {string} [passphrase=''] - Used as the PBKDF2 salt. Default: "" * @returns {string} Hexadecimal seed */ toBip39Seed (passphrase: string, format: 'hex'): Promise<string> toBlake2bSeed (): Promise<Uint8Array<ArrayBuffer>> /** * Converts the mnemonic phrase to a BLAKE2b seed. * * @returns {string} Hexadecimal seed */ toBlake2bSeed (format: 'hex'): Promise<string> } /** * Implementation derived from blake2b@2.1.4. Copyright 2017 Emil Bay * <github@tixz.dk> (https://github.com/emilbayes/blake2b). See LICENSES/ISC.txt * * Modified to use BigUint64 values, eliminate dependencies, port to TypeScript, * and embed in web workers. * * Original source commit: https://github.com/emilbayes/blake2b/blob/1f63e02e3f226642959506cdaa67c8819ff145cd/index.js */ export declare class Blake2b { #private static get OUTBYTES_MIN (): 1 static get OUTBYTES_MAX (): 64 static get KEYBYTES_MIN (): 1 static get KEYBYTES_MAX (): 64 static get SALTBYTES (): 16 static get PERSONALBYTES (): 16 static get IV (): bigint[] static get SIGMA (): number[][] /** * Creates a BLAKE2b hashing context. * * @param {number} length - Output length between 1-64 bytes * @param {Uint8Array} [key] - (_optional_) Used for keyed hashing (MAC and PRF) * @param {Uint8Array} [salt] - (_optional_) Used to simplify randomized hashing for digital signatures * @param {Uint8Array} [personal] - (_optional_) Arbitrary user-specified value */ constructor (length: UnknownNumber, key?: UnknownUint8Array, salt?: UnknownUint8Array, personal?: UnknownUint8Array) update (input: Uint8Array): Blake2b digest (): Uint8Array<ArrayBuffer> digest (out: 'hex'): string digest (out: 'binary' | Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer> } /** * Represents a block as defined by the Nano cryptocurrency protocol. The Block * class is abstract and cannot be directly instantiated. Every block must be one * of three derived classes: SendBlock, ReceiveBlock, ChangeBlock. */ declare abstract class Block { account: Account type: 'state' abstract subtype: 'send' | 'receive' | 'change' abstract previous: string abstract representative: Account abstract balance: bigint abstract link: string abstract signature?: string abstract work?: string constructor (account: Account | string) /** * Calculates the block hash using Blake2b. * * @returns {Promise<string>} Block data hashed to a byte array */ get hash (): string /** * Converts the block to JSON format as expected by the `process` RPC. * * @returns {string} JSON representation of the block */ toJSON (): { [key: string]: string } /** * Calculates proof-of-work using a pool of Web Workers. * * A successful response sets the `work` property. */ pow (): Promise<void> /** * Sends the block to a node for processing on the network. * * The block must already be signed (see `sign()` for more information). * The block must also have a `work` value. * * @param {Rpc|string|URL} rpc - RPC node information required to call `process` * @returns {Promise<string>} Hash of the processed block */ process (rpc: Rpc): Promise<string> /** * Signs the block using a private key. If successful, the result is stored in * the object's `signature` property. * * @param {string} [key] - Hexadecimal-formatted private key to use for signing */ sign (key?: string): Promise<void> /** * Signs the block using a Ledger hardware wallet. If that fails, an error is * thrown with the status code from the device. * * If successful, the result is stored in the object's `signature` * property. * * @param {number} index - Account index between 0x0 and 0x7fffffff * @param {object} [frontier] - JSON of frontier block for offline signing */ sign (index?: number, frontier?: ChangeBlock | ReceiveBlock | SendBlock): Promise<void> /** * Verifies the signature of the block. If a key is not provided, the public * key of the block's account will be used if it exists. * * @param {string} [key] - Hexadecimal-formatted public key to use for verification * @returns {boolean} True if block was signed by the matching private key */ verify (key?: string): Promise<boolean> } /** * Represents a block that sends funds from one address to another as defined by * the Nano cryptocurrency protocol. */ export declare class SendBlock extends Block { type: 'state' subtype: 'send' previous: string representative: Account balance: bigint link: string signature?: string work?: string constructor (sender: Account | string, balance: string, recipient: string, amount: string, representative: Account | string, frontier: string, work?: string) } /** * Represents a block that receives funds sent to one address from another as * defined by the Nano cryptocurrency protocol. */ export declare class ReceiveBlock extends Block { type: 'state' subtype: 'receive' previous: string representative: Account balance: bigint link: string signature?: string work?: string constructor (recipient: Account | string, balance: string, origin: string, amount: string, representative: Account | string, frontier?: string, work?: string) } /** * Represents a block that changes the representative account to which the user * account delegates their vote weight using the the Open Representative Voting * specification as defined by the Nano cryptocurrency protocol. */ export declare class ChangeBlock extends Block { type: 'state' subtype: 'change' previous: string representative: Account balance: bigint link: string signature?: string work?: string constructor (account: Account | string, balance: string, representative: Account | string, frontier: string, work?: string) } export type Data = boolean | number[] | string | ArrayBuffer /** * Represents a cryptographically strong source of entropy suitable for use in * BIP-39 mnemonic phrase generation and consequently BIP-44 key derivation. * * The constructor will accept one of several different data types under certain * constraints. If the constraints are not met, an error will be thrown. If no * value, or the equivalent of no value, is passed to the constructor, then a * brand new source of entropy will be generated at the maximum size of 256 bits. */ export declare class Entropy { #private static MIN: 16 static MAX: 32 static MOD: 4 get bits (): string get buffer (): ArrayBuffer get bytes (): Uint8Array get hex (): string private constructor () /** * Generate 256 bits of entropy. */ static create (): Promise<Entropy> /** * Generate between 16-32 bytes of entropy. * @param {number} size - Number of bytes to generate in multiples of 4 */ static create (size: number): Promise<Entropy> /** * Import existing entropy and validate it. * @param {string} hex - Hexadecimal string */ static import (hex: string): Promise<Entropy> /** * Import existing entropy and validate it. * @param {ArrayBuffer} buffer - Byte buffer */ static import (buffer: ArrayBuffer): Promise<Entropy> /** * Import existing entropy and validate it. * @param {Uint8Array} bytes - Byte array */ static import (bytes: Uint8Array<ArrayBuffer>): Promise<Entropy> /** * Randomizes the bytes, rendering the original values generally inaccessible. */ destroy (): boolean } export type NamedData<T extends Data = Data> = { [key: string]: T } export type Key = string | Uint8Array<ArrayBuffer> export type KeyPair = { index?: number privateKey?: Key publicKey?: Key } /** * Represents a basic address book of Nano accounts. Multiple addresses can be * saved under one nickname. */ export declare class Rolodex { /** * Adds an address to the rolodex under a specific nickname. * * If the name exists, add the address as a new association to that name. If * the account exists under a different name, update the name. If no matches * are found at all, add a new entry. * * @param {string} name - Contact alias for the address * @param {string} address - Nano account address * @returns {Promise<boolean>} Promise for true if name and address are added to the rolodex, else false */ static add (name: string, address: string): Promise<boolean> /** * Removes a Nano address from its related contact in the rolodex. * * @param {string} address - Nano account address * @returns {Promise<boolean>} Promise for true if address successfully removed, else false */ static deleteAddress (address: string): Promise<boolean> /** * Removes a contact and its related Nano addresses from the rolodex. * * @param {string} name - Contact name to delete * @returns {Promise<boolean>} Promise for true if name and related addresses successfully removed, else false */ static deleteName (name: string): Promise<boolean> /** * Gets all Nano account addresses associated with a name from the rolodex. * * @param {string} name - Alias to look up * @returns {Promise<string[]>} Promise for a list of Nano addresses associated with the name */ static getAddresses (name: string): Promise<string[]> /** * Gets all names stored in the rolodex. * * @returns {Promise<string[]>} Promise for a list of all names stored in the rolodex */ static getAllNames (): Promise<string[]> /** * Gets the name associated with a specific Nano address from the rolodex. * * @param {string} address - Nano account address * @returns {Promise<string|null>} Promise for the name associated with the address, or null if not found */ static getName (address: string): Promise<string | null> /** * Verifies whether the public key of any Nano address saved under a specific * name in the rolodex was used to sign a specific set of data. * * @param {string} name - Alias to look up * @param {string} signature - Signature to use for verification * @param {...string} data - Signed data to verify * @returns {Promise<boolean>} True if the signature was used to sign the data, else false */ static verify (name: string, signature: string, ...data: string[]): Promise<boolean> } /** * Represents a Nano network node. It primarily consists of a URL which will * accept RPC calls, and an optional API key header construction can be passed if * required by the node. Once instantiated, the Rpc object can be used to call * any action supported by the Nano protocol. The URL protocol must be HTTPS; any * other value will be changed automatically. */ export declare class Rpc { #private constructor (url: string | URL, apiKeyName?: string) /** * Sends a nano RPC call to a node endpoint. * * @param {string} action - Nano protocol RPC call to execute * @param {object} [data] - JSON to send to the node as defined by the action * @returns {Promise<any>} JSON-formatted RPC results from the node */ call (action: string, data?: { [key: string]: unknown }): Promise<any> } export type SafeRecord = { label: string iv: ArrayBuffer salt: ArrayBuffer encrypted: ArrayBuffer } type SweepResult = { status: "success" | "error" address: string message: string } /** * Converts a decimal amount of nano from one unit divider to another. * * @param {bigint|string} amount - Decimal amount to convert * @param {string} inputUnit - Current denomination * @param {string} outputUnit - Desired denomination */ export declare function convert (amount: bigint | string, inputUnit: string, outputUnit: string): Promise<string> declare function hash (data: string | string[], encoding?: 'hex'): Uint8Array<ArrayBuffer> /** * Signs arbitrary strings with a private key using the Ed25519 signature scheme. * * @param {Key} key - Hexadecimal-formatted private key to use for signing * @param {...string} input - Data to be signed * @returns {Promise<string>} Hexadecimal-formatted signature */ export declare function sign (key: Key, ...input: string[]): Promise<string> /** * Collects the funds from a specified range of accounts in a wallet and sends * them all to a single recipient address. Hardware wallets are unsupported. * * @param {Rpc|string|URL} rpc - RPC node information required to refresh accounts, calculate PoW, and process blocks * @param {Blake2bWallet|Bip44Wallet|LedgerWallet} wallet - Wallet from which to sweep funds * @param {string} recipient - Destination address for all swept funds * @param {number} from - Starting account index to sweep * @param {number} to - Ending account index to sweep * @returns An array of results including both successes and failures */ export declare function sweep (rpc: Rpc | string | URL, wallet: Blake2bWallet | Bip44Wallet | LedgerWallet, recipient: string, from?: number, to?: number): Promise<SweepResult[]> /** * Verifies the signature of arbitrary strings using a public key. * * @param {Key} key - Hexadecimal-formatted public key to use for verification * @param {string} signature - Hexadcimal-formatted signature * @param {...string} input - Data to be verified * @returns {Promise<boolean>} True if the data was signed by the public key's matching private key */ export declare function verify (key: Key, signature: string, ...input: string[]): Promise<boolean> export declare const Tools: { convert: typeof convert hash: typeof hash sign: typeof sign sweep: typeof sweep verify: typeof verify } /** * Represents a wallet containing numerous Nano accounts derived from a single * source, the form of which can vary based on the type of wallet. The Wallet * class itself is abstract and cannot be directly instantiated. Currently, three * types of wallets are supported, each as a derived class: Bip44Wallet, * Blake2bWallet, LedgerWallet. */ export declare abstract class Wallet { #private abstract ckd (index: number[]): Promise<KeyPair[]> get id (): string get isLocked (): boolean get isUnlocked (): boolean get mnemonic (): string get seed (): string constructor (id: Entropy, seed?: Uint8Array<ArrayBuffer>, mnemonic?: Bip39Mnemonic) /** * Retrieves an account from a wallet using its child key derivation function. * Defaults to the first account at index 0. * * ``` * console.log(await wallet.account(5)) * // outputs sixth account of the wallet * // { * // privateKey: <...>, * // index: 5 * // } * ``` * * @param {number} index - Wallet index of secret key. Default: 0 * @returns {Account} Account derived at the specified wallet index */ account (index?: number): Promise<Account> /** * Retrieves accounts from a wallet using its child key derivation function. * Defaults to the first account at index 0. * * The returned object will have keys corresponding with the requested range * of account indexes. The value of each key will be the Account derived for * that index in the wallet. * * ``` * console.log(await wallet.accounts(5)) * // outputs sixth account of the wallet * // { * // 5: { * // privateKey: <...>, * // index: 5 * // } * // } * ``` * * @param {number} from - Start index of secret keys. Default: 0 * @param {number} to - End index of secret keys. Default: `from` * @returns {AccountList} Object with keys of account indexes and values of the corresponding Accounts */ accounts (from?: number, to?: number): Promise<AccountList> /** * Removes encrypted secrets in storage and releases variable references to * allow garbage collection. */ destroy (): Promise<void> /** * Locks the wallet and all currently derived accounts with a password that * will be needed to unlock it later. * * @param {Key} password Used to lock the wallet * @returns True if successfully locked */ lock (password: Key): Promise<boolean> /** * Refreshes wallet account balances, frontiers, and representatives from the * current state on the network. * * A successful response will set these properties on each account. * * @param {Rpc|string|URL} rpc - RPC node information required to refresh accounts, calculate PoW, and process blocks * @returns {Promise<Account[]>} Accounts with updated balances, frontiers, and representatives */ refresh (rpc: Rpc | string | URL, from?: number, to?: number): Promise<AccountList> /** * Signs a block using the private key of the account at the wallet index * specified. The signature is appended to the signature field of the block * before being returned. The wallet must be unlocked prior to signing. * * @param {(ChangeBlock|ReceiveBlock|SendBlock)} block - Block data to be hashed and signed * @param {number} index - Account to use for signing * @returns {Promise<string>} Hexadecimal-formatted 64-byte signature */ sign (index: number, block: ChangeBlock | ReceiveBlock | SendBlock): Promise<string> /** * Unlocks the wallet using the same password as used prior to lock it. * * @param {Key} password Used previously to lock the wallet * @returns True if successfully unlocked */ unlock (password: Key): Promise<boolean> /** * Fetches the lowest-indexed unopened account from a wallet in sequential * order. An account is unopened if it has no frontier block. * * @param {Rpc|string|URL} rpc - RPC node information required to refresh accounts, calculate PoW, and process blocks * @param {number} batchSize - Number of accounts to fetch and check per RPC callout * @param {number} from - Account index from which to start the search * @returns {Promise<Account>} The lowest-indexed unopened account belonging to the wallet */ unopened (rpc: Rpc, batchSize?: number, from?: number): Promise<Account> } /** * Hierarchical deterministic (HD) wallet created by using a source of entropy to * derive a mnemonic phrase. The mnemonic phrase, in combination with an optional * salt, is used to generate a seed. A value can be provided as a parameter for * entropy, mnemonic + salt, or seed; if no argument is passed, a new entropy * value will be generated using a cryptographically strong pseudorandom number * generator. * * Importantly, the salt is not stored in the instantiated Wallet object. If a * salt is used, then losing it means losing the ability to regenerate the seed * from the mnemonic. * * Accounts are derived from the seed. Private keys are derived using a BIP-44 * derivation path. The public key is derived from the private key using the * Ed25519 key algorithm. Account addresses are derived as described in the nano * documentation (https://docs.nano.org) * * A password must be provided when creating or importing the wallet and is used * to lock and unlock the wallet. The wallet will be initialized as locked. When * the wallet is unlocked, a new password can be specified using the lock() * method. */ export declare class Bip44Wallet extends Wallet { #private private constructor () /** * Creates a new HD wallet by using an entropy value generated using a * cryptographically strong pseudorandom number generator. * * @param {string} password - Encrypts the wallet to lock and unlock it * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ static create (password: string, salt?: string): Promise<Bip44Wallet> /** * Creates a new HD wallet by using an entropy value generated using a * cryptographically strong pseudorandom number generator. * * @param {Uint8Array} key - Encrypts the wallet to lock and unlock it * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ static create (key: Uint8Array, salt?: string): Promise<Bip44Wallet> /** * Creates a new HD wallet by using a pregenerated entropy value. The user * must ensure that it is cryptographically strongly random. * * @param {string} password - Used to lock and unlock the wallet * @param {string} entropy - Used when generating the initial mnemonic phrase * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ static fromEntropy (password: string, entropy: string, salt?: string): Promise<Bip44Wallet> /** * Creates a new HD wallet by using a pregenerated entropy value. The user * must ensure that it is cryptographically strongly random. * * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} entropy - Used when generating the initial mnemonic phrase * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ static fromEntropy (key: Uint8Array<ArrayBuffer>, entropy: string, salt?: string): Promise<Bip44Wallet> /** * Creates a new HD wallet by using a pregenerated mnemonic phrase. * * @param {string} password - Used to lock and unlock the wallet * @param {string} mnemonic - Used when generating the final seed * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ static fromMnemonic (password: string, mnemonic: string, salt?: string): Promise<Bip44Wallet> /** * Creates a new HD wallet by using a pregenerated mnemonic phrase. * * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} mnemonic - Used when generating the final seed * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ static fromMnemonic (key: Uint8Array<ArrayBuffer>, mnemonic: string, salt?: string): Promise<Bip44Wallet> /** * Creates a new HD wallet by using a pregenerated seed value. This seed cannot * be used to regenerate any higher level randomness which includes entropy, * mnemonic phrase, and salt. * * @param {string} password - Used to lock and unlock the wallet * @param {string} seed - Hexadecimal 128-character string used to derive private-public key pairs * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ static fromSeed (password: string, seed: string): Promise<Bip44Wallet> /** * Creates a new HD wallet by using a pregenerated seed value. This seed cannot * be used to regenerate any higher level randomness which includes entropy, * mnemonic phrase, and salt. * * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} seed - Hexadecimal 128-character string used to derive private-public key pairs * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ static fromSeed (key: Uint8Array<ArrayBuffer>, seed: string): Promise<Bip44Wallet> /** * Retrieves an existing HD wallet from session storage using its ID. * * @param {string} id - Generated when the wallet was initially created * @returns {Bip44Wallet} Restored locked Bip44Wallet */ static restore (id: string): Promise<Bip44Wallet> /** * Derives BIP-44 Nano account private keys. * * @param {number[]} indexes - Indexes of the accounts * @returns {Promise<Account>} */ ckd (indexes: number[]): Promise<KeyPair[]> } /** * BLAKE2b wallet created by deriving a mnemonic phrase from a seed or vice * versa. If no value is provided for either, a new BIP-39 seed and mnemonic will * be generated using a cryptographically strong pseudorandom number generator. * * Account private keys are derived on an ad hoc basis using the Blake2b hashing * function. Account public key are derived from the private key using the * Ed25519 key algorithm. Account addresses are derived from the public key as * described in the Nano documentation. * https://docs.nano.org/integration-guides/the-basics/ * * A password must be provided when creating or importing the wallet and is used * to lock and unlock the wallet. The wallet will be initialized as locked. When * the wallet is unlocked, a new password can be specified using the lock() * method. */ export declare class Blake2bWallet extends Wallet { #private private constructor () /** * Creates a new BLAKE2b wallet by using a seed generated using a * cryptographically strong pseudorandom number generator. * * @param {string} password - Encrypts the wallet to lock and unlock it * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ static create (password: string): Promise<Blake2bWallet> /** * Creates a new BLAKE2b wallet by using a seed generated using a * cryptographically strong pseudorandom number generator. * * @param {Uint8Array} key - Encrypts the wallet to lock and unlock it * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ static create (key: Uint8Array): Promise<Blake2bWallet> /** * Creates a new BLAKE2b wallet by using a pregenerated seed. The user must * ensure that it is cryptographically strongly random. * * @param {string} password - Used to lock and unlock the wallet * @param {string} seed - Hexadecimal 64-character string used to derive private-public key pairs * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ static fromSeed (password: string, seed: string): Promise<Blake2bWallet> /** * Creates a new BLAKE2b wallet by using a pregenerated seed. The user must * ensure that it is cryptographically strongly random. * * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} seed - Hexadecimal 64-character string used to derive private-public key pairs * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ static fromSeed (key: Uint8Array<ArrayBuffer>, seed: string): Promise<Blake2bWallet> /** * Creates a new BLAKE2b wallet by using a pregenerated mnemonic phrase. * * @param {string} password - Used to lock and unlock the wallet * @param {string} mnemonic - Used when generating the final seed * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ static fromMnemonic (password: string, mnemonic: string): Promise<Blake2bWallet> /** * Creates a new BLAKE2b wallet by using a pregenerated mnemonic phrase. * * @param {Uint8Array} key - Used to lock and unlock the wallet * @param {string} mnemonic - Used when generating the final seed * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ static fromMnemonic (key: Uint8Array<ArrayBuffer>, mnemonic: string): Promise<Blake2bWallet> /** * Retrieves an existing BLAKE2b wallet from session storage using its ID. * * @param {string} id - Generated when the wallet was initially created * @returns {Blake2bWallet} Restored locked Blake2bWallet */ static restore (id: string): Promise<Blake2bWallet> /** * Derives BLAKE2b account private keys. * * @param {number[]} indexes - Indexes of the accounts * @returns {Promise<Account>} */ ckd (indexes: number[]): Promise<KeyPair[]> } type DeviceStatus = 'DISCONNECTED' | 'BUSY' | 'LOCKED' | 'CONNECTED' interface LedgerResponse { status: string } interface LedgerVersionResponse extends LedgerResponse { name: string | null, version: string | null } interface LedgerAccountResponse extends LedgerResponse { publicKey: string | null, address: string | null } interface LedgerSignResponse extends LedgerResponse { signature: string | null, hash?: string } /** * 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. * * Usage of this wallet is generally controlled by calling functions of the * `ledger` object. For example, the wallet interface should have a button to * initiate a device connection by calling `wallet.ledger.connect()`. For more * information, refer to the ledger.js service file. */ export declare class LedgerWallet extends Wallet { #private get listenTimeout (): 30000 get openTimeout (): 3000 get status (): DeviceStatus DynamicTransport: typeof TransportBLE | typeof TransportUSB | typeof TransportHID private constructor () /** * Check which transport protocols are supported by the browser and set the * transport type according to the following priorities: Bluetooth, USB, HID. */ checkBrowserSupport (): Promise<typeof TransportBLE | typeof TransportUSB | typeof TransportHID> /** * Check if the Nano app is currently open and set device status accordingly. * * @returns Device status as follows: * - 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 */ connect (): Promise<DeviceStatus> /** * Creates a new Ledger hardware wallet communication layer by dynamically * importing the ledger.js service. * * @returns {LedgerWallet} A wallet containing accounts and a Ledger device communication object */ static create (): Promise<LedgerWallet> /** * Removes encrypted secrets in storage and releases variable references to * allow garbage collection. */ destroy (): Promise<void> init (): Promise<void> /** * Revokes permission granted by the user to access the Ledger device. * * The 'quit app' ADPU command has not passed testing, so this is the only way * to ensure the connection is severed at this time. `setTimeout` is used to * expire any lingering transient user activation. * * Overrides the default wallet `lock()` method since as a hardware wallet it * does not need to be encrypted by software. * * @returns True if successfully locked */ lock (): Promise<boolean> onConnectUsb: (e: USBConnectionEvent) => Promise<void> onDisconnectUsb: (e: USBConnectionEvent) => Promise<void> /** * Retrieves an existing Ledger wallet from session storage using its ID. * * @param {string} id - Generated when the wallet was initially created * @returns {LedgerWallet} Restored LedgerWallet */ static restore (id: string): Promise<LedgerWallet> /** * Sign a block with the Ledger device. * * @param {number} index - Account number * @param {object} block - Block data to sign * @returns {Promise<string>} Signature */ sign (index: number, block: SendBlock | ReceiveBlock | ChangeBlock, frontier?: SendBlock | ReceiveBlock | ChangeBlock): Promise<string> /** * Attempts to connect to the Ledger device. * * Overrides the default wallet `unlock()` method since as a hardware wallet it * does not need to be encrypted by software. * * @returns True if successfully unlocked */ unlock (): Promise<boolean> /** * Update cache from raw block data. Suitable for offline use. * * @param {number} index - Account number * @param {object} block - JSON-formatted block data */ updateCache (index: number, block: ChangeBlock | ReceiveBlock | SendBlock): 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 */ updateCache (index: number, hash: string, rpc: Rpc): Promise<LedgerResponse> /** * Get the version of the current process. If a specific app is running, get * the app version. Otherwise, get the Ledger BOLOS version instead. * * https://developers.ledger.com/docs/connectivity/ledgerJS/open-close-info-on-apps#get-information * * @returns Status, process name, and version */ version (): Promise<LedgerVersionResponse> /** * Gets the public key for an account from the Ledger device. * * @param {number[]} indexes - Indexes of the accounts * @returns {Promise<Account>} */ ckd (indexes: number[]): Promise<KeyPair[]> } /** * Processes a queue of tasks using Web Workers. */ export declare class WorkerQueue { static get instances (): WorkerQueue[] /** * Creates a Web Worker from a stringified script. * * @param {string} worker - Stringified worker class body * @param {number} [count=1] - Integer between 1 and CPU thread count shared among all Pools */ constructor (worker: string) assign<T extends Data> (data: NamedData): Promise<NamedData<T>> prioritize<T extends Data> (data: NamedData): Promise<NamedData<T>> terminate (): void } export declare const Bip44CkdWorker: WorkerQueue export declare const NanoNaClWorker: WorkerQueue export declare const SafeWorker: WorkerQueue export type UnknownNumber = number | unknown export type UnknownUint8Array = Uint8Array | unknown