Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
importWalletFromMnemonic(words) {
let mnemonic = null;
if (typeof words == "string") {
mnemonic = words.split(" ");
} else {
mnemonic = words;
}
if (mnemonic == null) {
this.theWrapper.callbacks.error("AccountHelper:importWalletFromMnemonic", NimiqWrapper.ERROR_MESSAGES.BAD_PARAM_TYPE);
} else {
let entropy = null;
if (Nimiq.MnemonicUtils.getMnemonicType(mnemonic) == Nimiq.MnemonicUtils.MnemonicType.LEGACY) {
entropy = Nimiq.MnemonicUtils.legacyMnemonicToEntropy(mnemonic);
} else {
entropy = Nimiq.MnemonicUtils.mnemonicToEntropy(mnemonic);
}
let keypair = Nimiq.KeyPair.derive(entropy);
return new Nimiq.Wallet(keypair);
}
}exportWalletToMnemonic(wallet, legacy = false) {
let privateKey = wallet._keyPair.privateKey;
if (legacy) {
return Nimiq.MnemonicUtils.entropyToLegacyMnemonic(privateKey.serialize());
} else {
return Nimiq.MnemonicUtils.entropyToMnemonic(privateKey.serialize());
}
}