@bajetech/digitalbits-hd-wallet
Version:
Key derivation for the DigitalBits blockchain (based on Stellar's SEP-0005)
105 lines (104 loc) • 3.5 kB
TypeScript
/// <reference types="node" />
import { Keypair } from "xdb-digitalbits-base";
/**
* Configurable options defining how to generate the mnemonic
*/
export interface GenerateMnemonicOptions {
/**
* Entropy bits
*
* @default 256
*/
entropyBits?: number;
/**
* Name of a language wordlist as defined in the 'bip39' npm module.
* See {@link https://github.com/bitcoinjs/bip39/tree/master/src/wordlists}
*
* @default 'english'
*/
language?: string;
/**
* RNG function (default is crypto.randomBytes)
*/
rngFn?: (size: number) => Buffer;
}
/**
* Class for SEP-0005 key derivation.
*
* This code is copied and adapted from:
* https://github.com/chatch/stellar-hd-wallet/blob/b529d5ad19e9cc31029fd9fbae724856adf4b953/src/stellar-hd-wallet.js
*
* to use with the DigitalBits blockchain network and ecosystem.
*
* @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md|SEP-0005}
*/
declare class DigitalBitsHDWallet {
private seedHex;
/**
* Instance from a BIP39 mnemonic string.
* @param mnemonic - A BIP39 mnemonic
* @param password - Optional mnemonic password.
* Defaults to undefined
* @param language - Optional language of mnemonic.
* Defaults to 'english'
* @throws {Error} Invalid Mnemonic
*/
static fromMnemonic(mnemonic: string, password?: string | undefined, language?: string): DigitalBitsHDWallet;
/**
* Instance from a seed
* @param seed - binary seed
* @throws {TypeError} Invalid seed
*/
static fromSeed(seed: string | Buffer): DigitalBitsHDWallet;
/**
* Generate a mnemonic using BIP39
* @param options - Options defining how to generate the mnemonic
* @throws {TypeError} Language not supported by bip39 module
* @throws {TypeError} Invalid entropy
*/
static generateMnemonic({ entropyBits, language, rngFn, }?: GenerateMnemonicOptions): string;
/**
* Validate a mnemonic using BIP39
* @param mnemonic - A BIP39 mnemonic
* @param language - name of a language wordlist as
* defined in the 'bip39' npm module. See module.exports.wordlists:
* here https://github.com/bitcoinjs/bip39/blob/master/index.js
*
* Defaults to 'english'
* @throws {TypeError} Language not supported by bip39 module
*/
static validateMnemonic(mnemonic: string, language?: string): boolean;
/**
* New instance from seed hex string
* @param seedHex - Hex string
*/
constructor(seedHex: string);
/**
* Derive key given a full BIP44 path
*
* @param path - BIP44 path string (eg. m/44'/148'/8')
* @return Key binary as Buffer
*/
derive(path: string): Buffer;
/**
* Get DigitalBits account keypair for child key at given index
*
* @param index - Account index into path m/44'/148'/{index}
* @return Keypair instance for the account
*/
getKeypair(index: number): Keypair;
/**
* Get public key for account at
*
* @param index - Account index into path m/44'/148'/{index}
* @return Public key
*/
getPublicKey(index: number): string;
/**
* Get secret for account at index
* @param index - Account index into path m/44'/148'/{index}
* @return Secret
*/
getSecret(index: number): string;
}
export default DigitalBitsHDWallet;