How to use bip39

Comprehensive bip39 code examples:

How to use bip39.validateMnemonic:

490
491
492
493
494
495
496
497
498
499

(async () => {

    let mnemonic = options.word1.trim() + ' ' + options.word2.trim() + ' ' + options.word3.trim() + ' ' + options.word4.trim() + ' ' + options.word5.trim() + ' ' + options.word6.trim() + ' ' + options.word7.trim() + ' ' + options.word8.trim() + ' ' + options.word9.trim() + ' ' + options.word10.trim() + ' ' + options.word11.trim() + ' ' + options.word12.trim();

    let isValid = bip39.validateMnemonic(mnemonic);

    if (isValid == false) {

        resolve(false);

How to use bip39.mnemonicToEntropy:

8
9
10
11
12
13
14
15
16
17
18
}


export const checksumVaildateAction = (mnemonics) => {
  return mnemonics.filter(mnemonic => {
    try {
      bip39.mnemonicToEntropy(mnemonic);
      return true;
      // console.log(mnemonic, ':', 'valid')
    } catch (err) {
      // console.log(mnemonic, ':', 'invalid mnemonic');

How to use bip39.entropyToMnemonic:

38
39
40
41
42
43
44
45
46

async generateMnemonic(entropy) {
    var mnemonic;

    if(entropy) {
        mnemonic = bip39.entropyToMnemonic(entropy);
    } else {
        mnemonic = bip39.generateMnemonic();
    }

How to use bip39.mnemonicToSeedSync:

573
574
575
576
577
578
579
580
581
582

if (!bip39.validateMnemonic(mnemonic)) {
  throw new _errors.SdkError('wrong mnemonic format', _errors.CODES.InvalidMnemonic);
}

var seed = bip39.mnemonicToSeedSync(mnemonic, password);

if (derive) {
  var master = bip32.fromSeed(seed);
  var child = master.derivePath(Crypto.HDPATH + index);

How to use bip39.mnemonicToSeed:

47
48
49
50
51
52
53
54
55
56
entropyToMnemonic(entropy) {
    return bip39.entropyToMnemonic(entropy);
}

async mnemonicToSeed(mnemonic) {
    return bip39.mnemonicToSeed(mnemonic);
}

async registerWallet(mnemonic, index = 0) {
    const account = await this.walletFromMnemonic(mnemonic, index);

How to use bip39.generateMnemonic:

545
546
547
548
549
550
551
552
553
554
   */

}, {
  key: "generateMnemonic",
  value: function generateMnemonic() {
    return bip39.generateMnemonic(Crypto.MNEMONIC_LEN);
  }
  /**
   * Validates mnemonic phrase words.
   * @param mnemonic The mnemonic phrase words