How to use the bip39.mnemonicToEntropy function in bip39

To help you get started, we’ve selected a few bip39 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oed / seedsplit / lib / seedsplit.js View on Github external
function split(seed, numShards, threshold) {
  if (threshold > numShards) {
    throw new Error('Threshold can\'t be larger than the number of shards')
  }
  let ent = bip39.mnemonicToEntropy(seed)
  let shards = ssss.share(ent, numShards, threshold)

  let shardMnemonics = shards.map(shard => {
    let padding = '0'.repeat(numPaddingZeros)
    return bip39.entropyToMnemonic(padding + shard)
  })
  // due to padding first word is always the same
  return shardMnemonics.map(sm => sm.split(' ').slice(1).join(' '))
}
github brave / crypto / index.js View on Github external
toBytes32: function (passphrase/* : string */) {
    passphrase = passphrase.trim().replace(/\s+/gi, ' ')
    const words = passphrase.split(' ')
    if (words.length === module.exports.passphrase.NICEWARE_32_BYTE_WORD_COUNT) {
      return new Uint8Array(niceware.passphraseToBytes(words))
    } else if (words.length === module.exports.passphrase.BIP39_32_BYTE_WORD_COUNT) {
      return module.exports.hexToUint8(bip39.mnemonicToEntropy(passphrase))
    } else {
      throw new Error(`Input words length ${words.length} is not 24 or 16.`)
    }
  },
github blocktrail / wallet-recovery-tool / src / libs / blocktrail-sdk / lib / wallet_sweeper.js View on Github external
this.blocktrailPublicKeys = {};
    _.each(backupData.blocktrailKeys, function(blocktrailKey) {
        self.blocktrailPublicKeys[blocktrailKey['keyIndex']] = bitcoin.HDNode.fromBase58(blocktrailKey['pubkey'], self.network);
    });

    // convert the primary and backup mnemonics to seeds (using BIP39)
    var primarySeed, backupSeed, secret;
    switch (backupData.walletVersion) {
        case 1:
            primarySeed = bip39.mnemonicToSeed(backupData.primaryMnemonic, backupData.primaryPassphrase);
            backupSeed = bip39.mnemonicToSeed(backupData.backupMnemonic, "");
        break;

        case 2:
            // convert mnemonics to hex (bip39) and then base64 for decryption
            backupData.encryptedPrimaryMnemonic = blocktrail.convert(bip39.mnemonicToEntropy(backupData.encryptedPrimaryMnemonic), 'hex', 'base64');
            if (usePassword) {
                backupData.passwordEncryptedSecretMnemonic = blocktrail.convert(
                    bip39.mnemonicToEntropy(backupData.passwordEncryptedSecretMnemonic), 'hex', 'base64');
            } else {
                backupData.encryptedRecoverySecretMnemonic = blocktrail.convert(
                    bip39.mnemonicToEntropy(backupData.encryptedRecoverySecretMnemonic), 'hex', 'base64');
            }

            // decrypt encryption secret
            if (usePassword) {
                secret = CryptoJS.AES.decrypt(backupData.passwordEncryptedSecretMnemonic, backupData.password).toString(CryptoJS.enc.Utf8);
            } else {
                secret = CryptoJS.AES.decrypt(backupData.encryptedRecoverySecretMnemonic, backupData.recoverySecretDecryptionKey).toString(CryptoJS.enc.Utf8);
            }

            if (!secret) {
github blocktrail / wallet-recovery-tool / src / libs / blocktrail-sdk / examples / wallet_v2_recovery_example.js View on Github external
.then(function(wallet) {
        if (typeof recoveryEncryptedSecretMnemonic !== "undefined") {
            var encryptedSecret = blocktrail.convert(bip39.mnemonicToEntropy(recoveryEncryptedSecretMnemonic), 'hex', 'base64');
            var secret = CryptoJS.AES.decrypt(encryptedSecret, wallet.recoverySecret).toString(CryptoJS.enc.Utf8);

            var encryptedPrimarySeed = blocktrail.convert(bip39.mnemonicToEntropy(encryptedPrimarySeedMnemonic), 'hex', 'base64');
            var primarySeedBuffer = new Buffer(CryptoJS.AES.decrypt(encryptedPrimarySeed, secret).toString(CryptoJS.enc.Utf8), 'base64');

            wallet.primaryPrivateKey = bitcoin.HDNode.fromSeedBuffer(primarySeedBuffer, client.network);
        } else if (typeof backupSeedMnemonic !== "undefined") {
            var backupSeedHex = bip39.mnemonicToEntropy(backupSeedMnemonic);
            wallet.backupPrivateKey = bitcoin.HDNode.fromSeedHex(backupSeedHex, client.network);
        }
        wallet.locked = false;

        return wallet.maxSpendable({allowZeroConf: true, outputs: sendTo.length}).then(function(maxSpendable) {
            console.log(maxSpendable);

            var pay = {};
github blockstack-packages / blockstack-keychains-js / src / unitTests.es6 View on Github external
let childPublicKeychain = childPrivateKeychain.publicKeychain()
    t.ok(childPublicKeychain, 'Child public keychain should have been created from the child private keychain')
    let childPublicKeychain2 = publicKeychain.child(entropy)
    t.ok(childPublicKeychain2, 'Child public keychain should have been created from the parent public keychain')
    t.equal(childPublicKeychain.publicKey('hex'), childPublicKeychain2.publicKey('hex'), 'Child public keychains should be equal')

    let firstChildPrivateKeychain = privateKeychain.privatelyEnumeratedChild(0)
    t.ok(firstChildPrivateKeychain, 'Privately-enumerated child keychain should have been created')

    let namedChildPrivateKeychain = privateKeychain.privatelyNamedChild('home-laptop-1')
    t.ok(namedChildPrivateKeychain, 'Privately-named child keychain should have been created')

    let mnemonic = privateKeychain.mnemonic()
    t.ok(mnemonic, 'Mnemonic should have been created')

    let recoveredPrivateKey = bip39.mnemonicToEntropy(mnemonic)
    t.ok(recoveredPrivateKey, 'Private key should have been recovered from mnemonic')
    t.equal(privateKeychain.privateKey('hex'), recoveredPrivateKey, 'Private key recovered from mnemonic should match the original')
})
github vacuumlabs / cardano-crypto.js / index.js View on Github external
function mnemonicToSeedV1(mnemonic) {
  validateMnemonic(mnemonic)
  const entropy = Buffer.from(bip39.mnemonicToEntropy(mnemonic), 'hex')
  
  return cborEncodeBuffer(blake2b(cborEncodeBuffer(entropy), 32))
}
github blocktrail / wallet-recovery-tool / src / libs / blocktrail-sdk / lib / blocktrail.js View on Github external
var aesDecryptMnemonic = function(mnemonic, passphrase) {
    var hex = bip39.mnemonicToEntropy(mnemonic);
    var base64 = convert(hex, 'hex', 'base64');
    var decrypted = CryptoJS.AES.decrypt(base64, passphrase).toString(CryptoJS.enc.Utf8);

    if (!decrypted.length) {
        throw new blocktrail.WalletDecryptError();
    }

    return decrypted;
};
github ontio / ontology-ts-sdk / src / utils.ts View on Github external
export function parseMnemonic(str: string) {
    return bip39.mnemonicToEntropy(str);
}
github vitelabs / vite.js / src / hdAddr / index.ts View on Github external
export function getEntropyFromMnemonic(mnemonic: string, wordlist: Array): string {
    wordlist = wordlist || bip39.wordlists.EN;
    const err = checkParams({ mnemonic }, ['mnemonic'], [{
        name: 'mnemonic',
        func: _m => validateMnemonic(_m, wordlist)
    }]);
    if (err) {
        throw new Error(err.message);
    }

    return bip39.mnemonicToEntropy(mnemonic, wordlist);
}
github ontio / ontology-ts-sdk / src / core.ts View on Github external
export function parseMnemonic(str: string) {
    return bip39.mnemonicToEntropy(str);
}