0
I am generating addresses for HDWallet while importing account using the
Mnemonic Phrase. So I am letting the user enter Mnemonic Phrase and derivePath both. Before generating addresses, I want to validate whether the user has entered these fields in the correct format or not. Mnemonic Phrase is validated using bip39.validateMnemonic(mnemonic) but I am not getting how can I validate derivePath. Any help will be appreciated. Below is my code:
$("#txt_seedphrase, #txt_importwalletderivepath").on('keyup', function() {
var mnemonic = $('#txt_seedphrase').val().trim();
var derivepath = $('#txt_importwalletderivepath').val().trim();
var isvalid = bip39.validateMnemonic(mnemonic);
if((isvalid == true) && (derivepath != "")){
var seed = bip39.mnemonicToSeedSync(mnemonic).toString('hex');
var hdkey = HDKey.fromMasterSeed(seed);
var HDkey = hdkey.privateExtendedKey
var node = bip32.fromBase58(HDkey);
var child = node.derivePath(derivepath);
bitcoinKey = child.toWIF();
var key = bitcoin.HDPrivateKey(HDkey);
var wallet = new EthereumBip44(key);
var ethereumKey = wallet.getPrivateKey(0).toString('hex');
}
});