Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const bip39 = require('bip39')
const seedsplit = require('./lib/seedsplit')
//let m1 = bip39.generateMnemonic(256) // 24 words
let m1 = bip39.generateMnemonic() // 12 words
console.log(m1)
let sm = seedsplit.split(m1, 3, 2)
sm.then((x) => console.log(x))
let m2 = sm.then((x) => seedsplit.combine(x.slice(1)))
m2.then((x) => {
console.log(x)
console.log('Is correct:', m1 === x)
})
q.nextTick(function() {
if (!options.primaryMnemonic && !options.primarySeed) {
if (!options.passphrase && !options.password) {
deferred.reject(new blocktrail.WalletCreateError("Can't generate Primary Mnemonic without a passphrase"));
return deferred.promise;
} else {
options.primaryMnemonic = bip39.generateMnemonic(Wallet.WALLET_ENTROPY_BITS);
if (options.storePrimaryMnemonic !== false) {
options.storePrimaryMnemonic = true;
}
}
}
if (!options.backupMnemonic && !options.backupPublicKey) {
options.backupMnemonic = bip39.generateMnemonic(Wallet.WALLET_ENTROPY_BITS);
}
deferred.notify(APIClient.CREATE_WALLET_PROGRESS_PRIMARY);
self.resolvePrimaryPrivateKeyFromOptions(options)
.then(function(options) {
deferred.notify(APIClient.CREATE_WALLET_PROGRESS_BACKUP);
return self.resolveBackupPublicKeyFromOptions(options)
.then(function(options) {
deferred.notify(APIClient.CREATE_WALLET_PROGRESS_SUBMIT);
// create a checksum of our private key which we'll later use to verify we used the right password
var pubKeyHash = bitcoin.crypto.hash160(options.primaryPrivateKey.getPublicKeyBuffer());
var checksum = bitcoin.address.toBase58Check(pubKeyHash, self.network.pubKeyHash);
var keyIndex = options.keyIndex;
twentyfourWordSeeds = arr.map(e => bip39.generateMnemonic(256))
})
ngOnInit() {
this.passphrase = bip39.generateMnemonic();
this.currentNetwork = this.arkApiProvider.network;
this.arkApiProvider.fees.subscribe((fees) => this.fees = fees);
}
generate: (strength: number = 256): string => bip39.generateMnemonic(strength),
public __createWallet() {
const passphrase = bip39.generateMnemonic();
const keys = crypto.getKeys(passphrase);
return {
address: crypto.getAddress(keys.publicKey, this.prefixHash),
passphrase,
keys,
};
}
generateNewAccount = async () => {
debug('Generating new account.');
const mnemonic = bip39.generateMnemonic();
const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic));
const wallet = hdwallet.derivePath(DERIVATION_PATH).getWallet();
const address = `0x${wallet.getAddress().toString('hex')}`;
this.bip39Phrase = mnemonic;
this.address = address;
};
handler: async (request, h) => {
if (request.payload.bip38 && request.payload.userId) {
try {
const account = await getBip38Keys(request.payload.userId, request.payload.bip38)
return {
success: true,
publicKey: account.keys.getPublicKeyBuffer().toString('hex'),
address: account.keys.getAddress(),
wif: account.wif
}
} catch (err) {
const keys = arkjs.crypto.getKeys(bip39.generateMnemonic())
const encryptedWif = bip38.encrypt(keys.d.toBuffer(32), true, request.payload.bip38 + request.payload.userId)
database.setUTF8(arkjs.crypto.sha256(Buffer.from(request.payload.userId)).toString('hex'), encryptedWif)
return {
success: true,
publicKey: keys.getPublicKeyBuffer().toString('hex'),
address: keys.getAddress(),
wif: encryptedWif
}
}
}
return {
success: false,
err: 'Wrong parameters'
export const generateMnemonicImpl = function () {
return bip39.generateMnemonic(128);
};
addAccounts (numberOfAccounts = 1) {
if (!this.root) {
this._initFromMnemonic(bip39.generateMnemonic())
}
const oldLen = this.wallets.length
const newWallets = []
for (let i = oldLen; i < numberOfAccounts + oldLen; i++) {
const child = this.root.deriveChild(i)
const wallet = child.getWallet()
newWallets.push(wallet)
this.wallets.push(wallet)
}
const hexWallets = newWallets.map(w => w.getAddress().toString('hex'))
return Promise.resolve(hexWallets)
}