Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async createNewWallet() {
// If a wallet already exists, confirm that the seed is saved
const confirmed = await this.confirmWalletOverwrite();
if (!confirmed) return;
const newSeed = this.walletService.createNewWallet();
this.newWalletSeed = newSeed;
this.newWalletMnemonic = bip.entropyToMnemonic(newSeed);
// Split the seed up so we can show 4 per line
const words = this.newWalletMnemonic.split(' ');
const lines = [
words.slice(0, 4),
words.slice(4, 8),
words.slice(8, 12),
words.slice(12, 16),
words.slice(16, 20),
words.slice(20, 24),
];
this.newWalletMnemonicLines = lines;
this.activePanel = 3;
this.notifications.sendSuccess(`Successfully created new wallet! Make sure to write down your seed!`);
}
generateKeySeed(masterSeed) {
if (this.isUnlock()) {
const root = hdkey.fromMasterSeed(masterSeed);
const pathRoot = "m/44'/60'/0'";
// Identity master generation
const nodeId = root.derive(pathRoot);
const privKey = nodeId._privateKey;
const keySeed = bip39.entropyToMnemonic(privKey);
const keySeedEncrypted = kcUtils.encrypt(this.encryptionKey, keySeed);
const pathKey = Buffer.alloc(4);
pathKey.writeUInt32BE(0);
const pathKeySeedEncrypted = kcUtils.encrypt(this.encryptionKey, utils.bytesToHex(pathKey));
this.db.insert(`${this.prefix}keySeed`, JSON.stringify({ keySeedEncrypted, pathKeySeedEncrypted }));
return true;
}
return false;
}
return crypto.randomBytes(32, (err, buf) => { // eslint-disable-line
if (err) throw err;
that.secret = bip39.entropyToMnemonic(buf.toString('hex'));
resolve();
});
}
const secretDigester: Hasher = sha3_256.create()
// TODO check if mnemoinc or secret
const seed: string = bip39.mnemonicToEntropy(secret)
secretDigester.update(seed)
const shares = secretJS.share(seed + secretDigester.hex().slice(0, this.checkSumLength), numberOfShares, threshold)
const calculatedShares = []
for (let i = 0; i < shares.length; i++) {
const paddedShare = shares[i].concat(
Array(29)
.fill(0)
.map(() => this.getRandomIntInclusive(0, 9))
.join('')
)
calculatedShares[i] = `${bip39.entropyToMnemonic(paddedShare.slice(0, 64))} ${bip39.entropyToMnemonic(paddedShare.slice(64, 128))}`
}
return calculatedShares
}
entropyToMnemonic(entropy: string): string {
return bip39.entropyToMnemonic(entropy)
}
const passwordToSeed = async password => {
const hash = await hashPassword(password);
let mnemonic = bip39.entropyToMnemonic(hash);
return bip39.mnemonicToSeedHex(mnemonic);
}
RNRandomBytes.randomBytes(32, (err, bytes) => {
if (err) throw new Error(err);
let b = Buffer.from(bytes, 'base64').toString('hex');
that.secret = bip39.entropyToMnemonic(b);
resolve();
});
});
function getMnemonicFromEntropy(entropy, lang) {
if (lang === void 0) { lang = type_1.LangList.english; }
var err = vitejs_utils_1.checkParams({ entropy: entropy }, ['entropy']);
if (err) {
throw new Error(err.message);
}
return bip39.entropyToMnemonic(entropy, getWordList(lang));
}
exports.getMnemonicFromEntropy = getMnemonicFromEntropy;
const input = Buffer.from(bip39.mnemonicToEntropy(mnemonic), 'hex')
const saltLength = 8
if (saltLength >= input.length) {
throw Error('unscrambleStrings: Input is too short')
}
const outputLength = input.length - saltLength
const output = await pbkdf2(passphrase, input.slice(0, saltLength), 10000, outputLength, 'sha512')
for (let i = 0; i < outputLength; i++) {
output[i] = output[i] ^ input[saltLength + i]
}
return bip39.entropyToMnemonic(output)
}
export function generateMnemonic(size: number = 16): string {
const random = ab2hexstring(generateRandomArray(size));
return bip39.entropyToMnemonic(random);
}