/** * Calculate the seed given a mnemonic and corresponding passphrase. * The phrase is not checked for validity here, for that use a {@link MnemonicValidator}. * <p> * Due to normalization, these need to be {@link String}, and not {@link CharSequence}, this is an open issue: * https://github.com/NovaCrypto/BIP39/issues/7 * <p> * If you have a list of words selected from a word list, you can use {@link #withWordsFromWordList} then * {@link SeedCalculatorByWordListLookUp#calculateSeed} * * @param mnemonic The memorable list of words * @param passphrase An optional passphrase, use "" if not required * @return a seed for HD wallet generation */ public byte[] calculateSeed(final String mnemonic, final String passphrase) { final char[] chars = normalizeNFKD(mnemonic).toCharArray(); try { return calculateSeed(chars, passphrase); } finally { Arrays.fill(chars, '\0'); } }
/** * Calculate the seed given a mnemonic and corresponding passphrase. * The phrase is not checked for validity here, for that use a {@link MnemonicValidator}. * <p> * Due to normalization, these need to be {@link String}, and not {@link CharSequence}, this is an open issue: * https://github.com/NovaCrypto/BIP39/issues/7 * <p> * If you have a list of words selected from a word list, you can use {@link #withWordsFromWordList} then * {@link SeedCalculatorByWordListLookUp#calculateSeed} * * @param mnemonic The memorable list of words * @param passphrase An optional passphrase, use "" if not required * @return a seed for HD wallet generation */ public byte[] calculateSeed(final String mnemonic, final String passphrase) { final char[] chars = normalizeNFKD(mnemonic).toCharArray(); try { return calculateSeed(chars, passphrase); } finally { Arrays.fill(chars, '\0'); } }
return seedCalculator.calculateSeed(mnemonicChars, passphrase); } finally { Arrays.fill(mnemonicChars, '\0');
return seedCalculator.calculateSeed(mnemonicChars, passphrase); } finally { Arrays.fill(mnemonicChars, '\0');
private static String calculateSeed(String mnemonic, String passphrase, SeedCalculator seedCalculator) { return toHex(seedCalculator.calculateSeed(mnemonic, passphrase)); } }
@Test public void bip39_non_normalized_Japanese_word_not_found() { final String unNormalizedMnemonicWithBadWord = Normalizer.normalize("あおぞらAlan あいこくしん あいこくしん あいこくしん", Normalizer.Form.NFC); assertEquals(toHex(new SeedCalculator().calculateSeed(unNormalizedMnemonicWithBadWord, "")), calculateSeedHex(unNormalizedMnemonicWithBadWord, "", Japanese.INSTANCE, ValidateMode.EXPECTING_BAD_WORD)); }
@Test public void bip39_english_word_not_found() { final String mnemonicWithBadWord = "solar puppies hawk oxygen trip brief erase slot fossil mechanic filter voice"; assertEquals(toHex(new SeedCalculator().calculateSeed(mnemonicWithBadWord, "")), calculateSeedHex(mnemonicWithBadWord, "", English.INSTANCE, ValidateMode.EXPECTING_BAD_WORD)); }
private static void testSeedGeneration(TestVector testVector) { final byte[] seed = new SeedCalculator().calculateSeed(testVector.mnemonic, testVector.passphrase); assertEquals(testVector.seed, toHex(seed)); assertEquals(testVector.bip32Xprv, ExtendedPrivateKey.fromSeed(seed, Bitcoin.MAIN_NET).extendedBase58()); }