private MnemonicValidator(final WordList wordList) { normalizer = new WordListMapNormalization(wordList); words = new WordAndIndex[1 << 11]; for (int i = 0; i < 1 << 11; i++) { words[i] = new WordAndIndex(i, wordList.getWord(i)); } charSequenceSplitter = new CharSequenceSplitter(wordList.getSpace(), normalizeNFKD(wordList.getSpace())); Arrays.sort(words, wordListSortOrder); }
byte[] calculateSeed(final char[] mnemonicChars, final String passphrase) { final String normalizedPassphrase = normalizeNFKD(passphrase); final byte[] salt2 = getUtf8Bytes(normalizedPassphrase); final byte[] salt = combine(fixedSalt, salt2); clear(salt2); final byte[] encoded = hash(mnemonicChars, salt); clear(salt); return encoded; }
@Override public int compare(final WordAndIndex o1, final WordAndIndex o2) { return CharSequenceComparators.ALPHABETICAL.compare(o1.normalized, o2.normalized); } };
SeedCalculatorByWordListLookUp(final SeedCalculator seedCalculator, final WordList wordList) { this.seedCalculator = seedCalculator; normalizer = new WordListMapNormalization(wordList); for (int i = 0; i < 1 << 11; i++) { final String word = normalizer.normalize(wordList.getWord(i)); map.put(word, word.toCharArray()); } }
/** * Check that the supplied mnemonic fits the BIP0039 spec. * * @param mnemonic The memorable list of words * @throws InvalidChecksumException If the last bytes don't match the expected last bytes * @throws InvalidWordCountException If the number of words is not a multiple of 3, 24 or fewer * @throws WordNotFoundException If a word in the mnemonic is not present in the word list * @throws UnexpectedWhiteSpaceException Occurs if one of the supplied words is empty, e.g. a double space */ public void validate(final CharSequence mnemonic) throws InvalidChecksumException, InvalidWordCountException, WordNotFoundException, UnexpectedWhiteSpaceException { validate(charSequenceSplitter.split(mnemonic)); }
@Override public char getSpace() { return wordList.getSpace(); } };
WordAndIndex(final int i, final CharSequence word) { this.word = word; normalized = normalizer.normalize(word); index = i; } }
/** * Get a Mnemonic validator for the given word list. * No normalization is currently performed, this is an open issue: https://github.com/NovaCrypto/BIP39/issues/13 * * @param wordList A WordList implementation * @return A validator */ public static MnemonicValidator ofWordList(final WordList wordList) { return new MnemonicValidator(wordList); }
private static void wordIndexesToEntropyWithCheckSum(final int[] wordIndexes, final byte[] entropyWithChecksum) { for (int i = 0, bi = 0; i < wordIndexes.length; i++, bi += 11) { ByteUtils.writeNext11(entropyWithChecksum, wordIndexes[i], bi); } }
private byte[] hash(final char[] chars, final byte[] salt) { return hashAlgorithm.hash(chars, salt); }
private MnemonicValidator(final WordList wordList) { normalizer = new WordListMapNormalization(wordList); words = new WordAndIndex[1 << 11]; for (int i = 0; i < 1 << 11; i++) { words[i] = new WordAndIndex(i, wordList.getWord(i)); } charSequenceSplitter = new CharSequenceSplitter(wordList.getSpace(), normalizeNFKD(wordList.getSpace())); Arrays.sort(words, wordListSortOrder); }
byte[] calculateSeed(final char[] mnemonicChars, final String passphrase) { final String normalizedPassphrase = normalizeNFKD(passphrase); final byte[] salt2 = getUtf8Bytes(normalizedPassphrase); final byte[] salt = combine(fixedSalt, salt2); clear(salt2); final byte[] encoded = hash(mnemonicChars, salt); clear(salt); return encoded; }
SeedCalculatorByWordListLookUp(final SeedCalculator seedCalculator, final WordList wordList) { this.seedCalculator = seedCalculator; normalizer = new WordListMapNormalization(wordList); for (int i = 0; i < 1 << 11; i++) { final String word = normalizer.normalize(wordList.getWord(i)); map.put(word, word.toCharArray()); } }
/** * Check that the supplied mnemonic fits the BIP0039 spec. * * @param mnemonic The memorable list of words * @throws InvalidChecksumException If the last bytes don't match the expected last bytes * @throws InvalidWordCountException If the number of words is not a multiple of 3, 24 or fewer * @throws WordNotFoundException If a word in the mnemonic is not present in the word list * @throws UnexpectedWhiteSpaceException Occurs if one of the supplied words is empty, e.g. a double space */ public void validate(final CharSequence mnemonic) throws InvalidChecksumException, InvalidWordCountException, WordNotFoundException, UnexpectedWhiteSpaceException { validate(charSequenceSplitter.split(mnemonic)); }
@Override public int compare(final WordAndIndex o1, final WordAndIndex o2) { return CharSequenceComparators.ALPHABETICAL.compare(o1.normalized, o2.normalized); } };
WordAndIndex(final int i, final CharSequence word) { this.word = word; normalized = normalizer.normalize(word); index = i; } }
/** * Get a Mnemonic validator for the given word list. * No normalization is currently performed, this is an open issue: https://github.com/NovaCrypto/BIP39/issues/13 * * @param wordList A WordList implementation * @return A validator */ public static MnemonicValidator ofWordList(final WordList wordList) { return new MnemonicValidator(wordList); }
private static void wordIndexesToEntropyWithCheckSum(final int[] wordIndexes, final byte[] entropyWithChecksum) { for (int i = 0, bi = 0; i < wordIndexes.length; i++, bi += 11) { ByteUtils.writeNext11(entropyWithChecksum, wordIndexes[i], bi); } }