How to use the bip39.wordlists 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 LiskHQ / lisk-sdk / test / passphrase / validation.js View on Github external
describe('given a passphrase that uses a different wordlist for the passphrase', () => {
			const wordlist = Mnemonic.wordlists.spanish;
			const passphrase =
				'model actor shallow eight glue upper seat lobster reason label enlist bridge';
			const passphraseInvalidMnemonicError = [
				{
					code: 'INVALID_MNEMONIC',
					message:
						'Passphrase is not a valid mnemonic passphrase. Please check the passphrase.',
					expected: true,
					actual: false,
				},
			];

			it('should return the array with the error', () => {
				return expect(
					getPassphraseValidationErrors(passphrase, wordlist),
				).to.be.eql(passphraseInvalidMnemonicError);
github LiskHQ / lisk-sdk / test / passphrase / validation.js View on Github external
describe('given a passphrase that uses the correct wordlist for the passphrase', () => {
			const wordlist = Mnemonic.wordlists.english;
			const passphrase =
				'model actor shallow eight glue upper seat lobster reason label enlist bridge';

			it('should return an empty array', () => {
				return expect(
					getPassphraseValidationErrors(passphrase, wordlist),
				).to.be.eql(emptyErrorArray);
			});
		});
github MyEtherWallet / MyEtherWallet / src / dapps / ManageENS / ManageENS.vue View on Github external
generateKeyPhrase() {
      const wordsArray = [];
      const min = 0;
      const max = bip39.wordlists.EN.length;

      for (let i = 0; i < 3; i++) {
        wordsArray.push(
          bip39.wordlists.EN[Math.floor(Math.random() * (max - min + 1)) + min]
        );
      }

      this.secretPhrase = wordsArray.join(' ');
    }
  }
github LiskHQ / lisk-sdk / elements / lisk-passphrase / src / validation.ts View on Github external
actual: uppercaseCharacterInPassphrase,
		code: 'INVALID_AMOUNT_OF_UPPERCASE_CHARACTER',
		expected: expectedUppercaseCharacterCount,
		location: locateUppercaseCharacters(passphrase),
		message: `Passphrase contains ${uppercaseCharacterInPassphrase} uppercase character instead of expected ${expectedUppercaseCharacterCount}. Please check the passphrase.`,
	};
	const validationError: PassphraseError = {
		actual: false,
		code: 'INVALID_MNEMONIC',
		expected: true,
		message:
			'Passphrase is not a valid mnemonic passphrase. Please check the passphrase.',
	};

	const finalWordList =
		wordlists !== undefined ? [...wordlists] : Mnemonic.wordlists.english;

	return [
		passphraseWordError,
		whiteSpaceError,
		uppercaseCharacterError,
		validationError,
	].reduce(
		(errorArray: ReadonlyArray, error: PassphraseError) => {
			if (
				error.code === passphraseWordError.code &&
				wordsInPassphrase !== expectedWords
			) {
				return [...errorArray, error];
			}
			if (
				error.code === whiteSpaceError.code &&
github KeySplit / dapp / back / dist / index.es.js View on Github external
function entropyToMnemonic(entropy, wordlist) {
  if (!Buffer.isBuffer(entropy)) entropy = Buffer.from(entropy, 'hex');
  wordlist = wordlist || bip39.wordlists.EN;

  if (entropy.length % 4 !== 0) throw new TypeError(INVALID_ENTROPY);

  var entropyBits = bytesToBinary([].slice.call(entropy));
  var checksumBits = deriveChecksumBits(entropy);

  var bits = entropyBits + checksumBits;
  var chunks = bits.match(/(.{1,11})/g);
  var words = chunks.map(function (binary) {
    var index = binaryToByte(binary);
    return wordlist[index];
  });

  return wordlist === bip39.wordlists.JA ? words.join('\u3000') : words.join(' ');
}
github airgap-it / airgap-vault / src / app / components / verify-key / verify-key.component.ts View on Github external
public promptNextWord(): void {
    this.promptedWords = []

    const correctWord: SingleWord = this.splittedSecret[this.emptySpot(this.currentWords)]

    this.promptedWords.push(correctWord)

    const wordList: string[] = bip39.wordlists.EN

    for (let i: number = 0; i < ADDITIONAL_WORDS; i++) {
      const filteredList: string[] = wordList.filter(
        (originalWord: string) => !this.splittedSecret.find((word: SingleWord) => word === originalWord)
      )

      let hashedWord: string = sha3_256(correctWord)
      for (let hashRuns: number = 0; hashRuns <= i; hashRuns++) {
        hashedWord = sha3_256(hashedWord)
      }

      const additionalWord: SingleWord = filteredList[this.stringToIntHash(hashedWord, 0, filteredList.length)]

      this.promptedWords.push(additionalWord)
    }
github airgap-it / airgap-vault / src / app / models / BIP39Signer.ts View on Github external
public static wordLists(): any[] {
    return [
      bip39.wordlists.english
      /*
            bip39.wordlists.chinese_simplified,
            bip39.wordlists.chinese_traditional,
            bip39.wordlists.french,
            bip39.wordlists.italian,
            bip39.wordlists.japanese,
            bip39.wordlists.korean,
            bip39.wordlists.spanish
            */
    ]
  }
github vitelabs / vite.js / src / wallet / wallet.ts View on Github external
    constructor(mnemonics: string, wordlist: Array = bip39.wordlists.EN, passphrase: string = '') {
        if (!hdKey.validateMnemonics(mnemonics, wordlist)) {
            throw new Error('Illegal mnemonic');
        }

        this.rootPath = hdKey.ROOT_PATH;
        this.mnemonics = mnemonics;
        this.wordlist = wordlist;
        this.passphrase = passphrase;
        this.entropy = hdKey.getEntropyFromMnemonics(mnemonics, wordlist);

        const { seed, seedHex } = hdKey.getSeedFromMnemonics(mnemonics, passphrase, wordlist);
        this.seed = seed;
        this.seedHex = seedHex;
        this.addressList = {};
    }
github vitelabs / vite.js / src / wallet / index.ts View on Github external
function deriveAddress({ mnemonics, index = 0, wordlist = bip39.wordlists.EN, passphrase = '' }: {
    mnemonics: string;
    index: number;
    wordlist?: Array;
    passphrase?: string;
}): AddressObj {
    const { seedHex } = hdKey.getSeedFromMnemonics(mnemonics, passphrase, wordlist);
    const { privateKey } = hdKey.deriveKeyPairByIndex(seedHex, index);
    return addressLib.createAddressByPrivateKey(privateKey);
}