import { bip32, payments, Network } from 'bitcoinjs-lib' import { mnemonicToSeedSync, validateMnemonic, generateMnemonic, wordlists } from 'bip39' import { getNetwork } from '../network/network' export const DEFAULT_PATH = '0' export class HDWallet { private network: Network private maxSearchDepth = 250 constructor(public rootNode: bip32.BIP32Interface, network: Network | string = 'mainnet') { this.network = getNetwork(network) this.rootNode.network = this.network } getNode(path: string) { return this.rootNode.derivePath(path) } getAddressPath(address: string, path = "m", searchDepth = this.maxSearchDepth) { for(let i=0; i Buffer): string { return generateMnemonic(strength, rng, wordlists[language]) } static validateMnemonic(mnemonic: string, throwOnError = false) { if (throwOnError && !validateMnemonic(mnemonic)) { throw Error('Invalid mnemonic') } return validateMnemonic(mnemonic) } }