UNPKG

@conflux-dev/hdwallet

Version:
31 lines (30 loc) 997 B
import HDNode from "hdkey"; import { generateMnemonic, mnemonicToSeedSync, validateMnemonic, mnemonicToSeed, } from "bip39"; export class HDWallet { static defaultBasePath = "m/44'/503'/0'/0"; // default Conflux path-503 mnemonic; password; seed; rootNode; static generateMnemonic() { return generateMnemonic(); } static validateMnemonic(mnemonic, wordlist) { return validateMnemonic(mnemonic, wordlist); } static mnemonicToSeed(mnemonic, password) { return mnemonicToSeed(mnemonic, password); } constructor(mnemonic, password) { this.mnemonic = mnemonic; this.password = password; this.seed = mnemonicToSeedSync(mnemonic, password); this.rootNode = HDNode.fromMasterSeed(this.seed); } getPrivateKey(path) { return this.rootNode.derive(path).privateKey; } getPrivateKeyByIndex(index) { return this.getPrivateKey(`${HDWallet.defaultBasePath}/${index}`); } }