How to use the bip39.generateMnemonic 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 / index.js View on Github external
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)
})
github blocktrail / wallet-recovery-tool / src / libs / blocktrail-sdk / lib / api_client.js View on Github external
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;
github oed / seedsplit / test / seedsplit.js View on Github external
    twentyfourWordSeeds = arr.map(e => bip39.generateMnemonic(256))
  })
github ArkEcosystem / mobile-wallet / src / app / pages / wallet / wallet-dashboard / modal / register-second-passphrase / register-second-passphrase.ts View on Github external
ngOnInit() {
    this.passphrase = bip39.generateMnemonic();
    this.currentNetwork = this.arkApiProvider.network;
    this.arkApiProvider.fees.subscribe((fees) => this.fees = fees);
  }
github N3TC4T / artunis-mobile / src / libs / crypto.js View on Github external
    generate: (strength: number = 256): string => bip39.generateMnemonic(strength),
github ArkEcosystem / core / packages / core-deployer / src / builder / genesis-block.ts View on Github external
public __createWallet() {
        const passphrase = bip39.generateMnemonic();
        const keys = crypto.getKeys(passphrase);

        return {
            address: crypto.getAddress(keys.publicKey, this.prefixHash),
            passphrase,
            keys,
        };
    }
github paritytech / fether / packages / fether-react / src / stores / createAccountStore.js View on Github external
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;
  };
github ArkEcosystem / rpc-server / lib / handlers / accounts.js View on Github external
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'
github Emurgo / yoroi-frontend / app / utils / crypto / BIP39.js View on Github external
export const generateMnemonicImpl = function () {
  return bip39.generateMnemonic(128);
};
github brave / ethereum-remote-client / app / scripts / keyrings / hd.js View on Github external
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)
  }