UNPKG

libnemo

Version:

Nano cryptocurrency wallet library.

91 lines (90 loc) 3.47 kB
/** * Represents a mnemonic phrase that identifies a wallet as defined by BIP-39. */ export declare class Bip39 { #private; encoder: TextEncoder; /** * SHA-256 hash of entropy that is appended to the entropy and subsequently * used to generate the mnemonic phrase. * * @param {Uint8Array<ArrayBuffer>} entropy - Cryptographically strong pseudorandom data of length N bits * @returns {Promise<bigint>} First N/32 bits of the hash as a bigint */ static checksum(entropy: Uint8Array<ArrayBuffer>): Promise<bigint>; /** * Derives a mnemonic phrase from source of entropy or seed. * * The entropy must be between 16-32 bytes (32-64 characters) to stay within * the limit of 128-256 bits defined in BIP-39. Typically, wallets use the * maximum entropy allowed. * * @param {(ArrayBuffer|Uint8Array<ArrayBuffer>)} entropy - Cryptographically secure random value * @returns {Promise<Bip39>} Mnemonic phrase created using the BIP-39 wordlist */ static fromEntropy(entropy: ArrayBuffer | Uint8Array<ArrayBuffer>): Promise<Bip39>; /** * 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 {Promise<Bip39>} Mnemonic phrase validated using the BIP-39 wordlist */ static fromPhrase(phrase: string): Promise<Bip39>; /** * Validates a mnemonic phrase meets the BIP-39 specification. * * @param {string} mnemonic - Mnemonic phrase to validate * @returns {Promise<boolean>} True if the mnemonic phrase is valid */ static validate(mnemonic: string): Promise<boolean>; private constructor(); /** * BIP-39 mnemonic phrase, normlized using Normalization Form Compatibility * Decomposition (NFKD). */ get phrase(): string | undefined; /** * Erases seed bytes and releases variable references. */ destroy(): void; /** * 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 {Promise<Uint8Array<ArrayBuffer>>} Promise for seed as bytes */ 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 {Promise<string>} Promise for seed as hexadecimal string */ toBip39Seed(passphrase: string, format: 'hex'): Promise<string>; /** * Converts the mnemonic phrase to a BLAKE2b seed. * * @returns {Uint8Array<ArrayBuffer>} Seed as bytes */ toBlake2bSeed(): Uint8Array<ArrayBuffer>; /** * Converts the mnemonic phrase to a BLAKE2b seed. * * @param {string} format * @returns {string} Seed as hexadecimal string */ toBlake2bSeed(format: 'hex'): string; /** * https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt */ static wordlist: readonly string[]; }