Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async import() {
// This shouldn't happen, but a failsafe for if it does
if(this.hasInvalidWords())
return;
const words = this.state.words.join(' ');
const privateKey = bip39.mnemonicToSeedHex(words);
const publicKey = Utils.privateKeyToAddress(privateKey);
if(Object.keys(this.props.accounts).includes(publicKey)) {
return Swal({
type: 'error',
title: 'Account already exists',
text: 'The account you have tried to import already exists'
});
}
const { value: name } = await Swal({
title: this.translate({ id: 'accounts.import.title' }),
input: 'text',
inputPlaceholder: this.translate({ id: 'accounts.create.placeholder' }),
showCancelButton: true,
inputValidator: name => {
private generateAccountFromKeys() {
const pvKey = PrivateKey.fromSeed(this.keys.key, this.currentNetwork);
const pbKey = pvKey.getPublicKey();
pbKey.setNetwork(this.currentNetwork);
const wallet = this.userDataProvider.getWalletByAddress(pbKey.getAddress());
const account: AccountBackup = {};
account.address = wallet.address;
account.mnemonic = this.keys.key;
account.publicKey = pbKey.toHex();
account.seed = bip39.mnemonicToSeedHex(account.mnemonic);
if (pbKey.network.wif) {
account.wif = pvKey.toWIF();
}
if (this.keys.secondKey) {
account.secondMnemonic = this.keys.secondKey;
}
this.account = account;
}
fromMnemonic (mnemonic) {
if (isMnemonic(mnemonic)) {
this.mnemonic = mnemonic
this.entropy = bip39.mnemonicToEntropy(this.mnemonic)
this.seed = bip39.mnemonicToSeedHex(this.mnemonic)
return true
}
return false
}
/**
static async mnemonicToSeed(mnemonic){
return bip39.mnemonicToSeedHex(mnemonic);
}
_importFromWordList(wordList) {
logger.info('Importing account from word list');
if(!bip39.validateMnemonic(wordList))
throw new Error(`Invalid wordList ${wordList} provided`);
logger.info('Word list was valid');
this._type = ACCOUNT_TYPE.MNEMONIC;
this._seed = bip39.mnemonicToSeedHex(wordList);
this._wordList = wordList;
}
return this.secretsService.retrieveEntropyForSecret(secret).then((entropy: string) => {
const seed: string = bip39.mnemonicToSeedHex(bip39.entropyToMnemonic(entropy))
if (wallet.isExtendedPublicKey) {
const extendedPrivateKey: string = wallet.coinProtocol.getExtendedPrivateKeyFromHexSecret(seed, wallet.derivationPath)
return wallet.coinProtocol.signWithExtendedPrivateKey(extendedPrivateKey, transaction.transaction)
} else {
const privateKey: Buffer = wallet.coinProtocol.getPrivateKeyFromHexSecret(seed, wallet.derivationPath)
return wallet.coinProtocol.signWithPrivateKey(privateKey, transaction.transaction)
}
})
}
function newAddr(bits, lang, pwd) {
if (bits === void 0) { bits = 256; }
if (lang === void 0) { lang = type_1.LangList.english; }
if (pwd === void 0) { pwd = ''; }
var err = vitejs_utils_1.checkParams({ bits: bits }, ['bits']);
if (err) {
throw new Error(err.message);
}
var wordList = getWordList(lang);
var mnemonic = bip39.generateMnemonic(bits, null, wordList);
var entropy = bip39.mnemonicToEntropy(mnemonic, wordList);
var seed = bip39.mnemonicToSeedHex(mnemonic, pwd);
var path = getPath(0);
var addr = getAddrFromPath(path, seed);
var id = exports.getId(mnemonic, lang);
return { addr: addr, entropy: entropy, mnemonic: mnemonic, id: id };
}
exports.newAddr = newAddr;
APIClient.prototype.mnemonicToSeedHex = function(mnemonic, passphrase) {
var self = this;
if (useWebWorker) {
return webworkifier.workify(self.mnemonicToSeedHex, function() {
return require('./webworker');
}, {method: 'mnemonicToSeedHex', mnemonic: mnemonic, passphrase: passphrase})
.then(function(data) {
return data.seed;
});
} else {
try {
return q.when(bip39.mnemonicToSeedHex(mnemonic, passphrase));
} catch (e) {
return q.reject(e);
}
}
};
static fromMnemonic(mnemonic, password = undefined, language = "english") {
if (!StellarHDWallet.validateMnemonic(mnemonic, language)) {
throw new Error(INVALID_MNEMONIC);
}
return new StellarHDWallet(bip39.mnemonicToSeedHex(mnemonic, password));
}