@Test(expected = MnemonicException.MnemonicLengthException.class) public void testBadEntropyLength() throws Exception { byte[] entropy = HEX.decode("7f7f7f7f7f7f7f7f7f7f7f7f7f7f"); mc.toMnemonic(entropy); }
public List<String> toMnemonic(byte[] entropy) throws MnemonicException.MnemonicLengthException { if (entropy.length % 4 > 0) throw new MnemonicException.MnemonicLengthException("Entropy length not multiple of 32 bits."); if (entropy.length == 0) throw new MnemonicException.MnemonicLengthException("Entropy is empty."); byte[] hash = Sha256Hash.hash(entropy); boolean[] hashBits = bytesToBits(hash); boolean[] entropyBits = bytesToBits(entropy); int checksumLengthBits = entropyBits.length / 32; boolean[] concatBits = new boolean[entropyBits.length + checksumLengthBits]; System.arraycopy(entropyBits, 0, concatBits, 0, entropyBits.length); System.arraycopy(hashBits, 0, concatBits, entropyBits.length, checksumLengthBits); ArrayList<String> words = new ArrayList<>(); int nwords = concatBits.length / 11; for (int i = 0; i < nwords; ++i) { int index = 0; for (int j = 0; j < 11; ++j) { index <<= 1; if (concatBits[(i * 11) + j]) index |= 0x1; } words.add(this.wordList.get(index)); } return words; }
MnemonicCode { public List<String> toMnemonic(byte[] entropy) throws MnemonicException.MnemonicLengthException { if (entropy.length % 4 > 0) throw new MnemonicException.MnemonicLengthException("Entropy length not multiple of 32 bits."); if (entropy.length == 0) throw new MnemonicException.MnemonicLengthException("Entropy is empty."); byte[] hash = Sha256Hash.hash(entropy); boolean[] hashBits = bytesToBits(hash); boolean[] entropyBits = bytesToBits(entropy); int checksumLengthBits = entropyBits.length / 32; boolean[] concatBits = new boolean[entropyBits.length + checksumLengthBits]; System.arraycopy(entropyBits, 0, concatBits, 0, entropyBits.length); System.arraycopy(hashBits, 0, concatBits, entropyBits.length, checksumLengthBits); ArrayList<String> words = new ArrayList<>(); int nwords = concatBits.length / 11; for (int i = 0; i < nwords; ++i) { int index = 0; for (int j = 0; j < 11; ++j) { index <<= 1; if (concatBits[(i * 11) + j]) index |= 0x1; } words.add(this.wordList.get(index)); } return words; } }
MnemonicCode { public List<String> toMnemonic(byte[] entropy) throws MnemonicException.MnemonicLengthException { if (entropy.length % 4 > 0) throw new MnemonicException.MnemonicLengthException("Entropy length not multiple of 32 bits."); if (entropy.length == 0) throw new MnemonicException.MnemonicLengthException("Entropy is empty."); byte[] hash = Sha256Hash.hash(entropy); boolean[] hashBits = bytesToBits(hash); boolean[] entropyBits = bytesToBits(entropy); int checksumLengthBits = entropyBits.length / 32; boolean[] concatBits = new boolean[entropyBits.length + checksumLengthBits]; System.arraycopy(entropyBits, 0, concatBits, 0, entropyBits.length); System.arraycopy(hashBits, 0, concatBits, entropyBits.length, checksumLengthBits); ArrayList<String> words = new ArrayList<>(); int nwords = concatBits.length / 11; for (int i = 0; i < nwords; ++i) { int index = 0; for (int j = 0; j < 11; ++j) { index <<= 1; if (concatBits[(i * 11) + j]) index |= 0x1; } words.add(this.wordList.get(index)); } return words; } MnemonicCode();  MnemonicCode(InputStream wordstream, String wordListDigest); }
MnemonicCode { public List<String> toMnemonic(byte[] entropy) throws MnemonicException.MnemonicLengthException { if (entropy.length % 4 > 0) throw new MnemonicException.MnemonicLengthException("Entropy length not multiple of 32 bits."); if (entropy.length == 0) throw new MnemonicException.MnemonicLengthException("Entropy is empty."); byte[] hash = Sha256Hash.hash(entropy); boolean[] hashBits = bytesToBits(hash); boolean[] entropyBits = bytesToBits(entropy); int checksumLengthBits = entropyBits.length / 32; boolean[] concatBits = new boolean[entropyBits.length + checksumLengthBits]; System.arraycopy(entropyBits, 0, concatBits, 0, entropyBits.length); System.arraycopy(hashBits, 0, concatBits, entropyBits.length, checksumLengthBits); ArrayList<String> words = new ArrayList<>(); int nwords = concatBits.length / 11; for (int i = 0; i < nwords; ++i) { int index = 0; for (int j = 0; j < 11; ++j) { index <<= 1; if (concatBits[(i * 11) + j]) index |= 0x1; } words.add(this.wordList.get(index)); } return words; } MnemonicCode();  MnemonicCode(InputStream wordstream, String wordListDigest); List<String> getWordList(); static byte[] toSeed(List<String> words, String passphrase); byte[] toEntropy(List<String> words); List<String> toMnemonic(byte[] entropy); void check(List<String> words); }
MnemonicCode { public List<String> toMnemonic(byte[] entropy) throws MnemonicException.MnemonicLengthException { if (entropy.length % 4 > 0) throw new MnemonicException.MnemonicLengthException("Entropy length not multiple of 32 bits."); if (entropy.length == 0) throw new MnemonicException.MnemonicLengthException("Entropy is empty."); byte[] hash = Sha256Hash.hash(entropy); boolean[] hashBits = bytesToBits(hash); boolean[] entropyBits = bytesToBits(entropy); int checksumLengthBits = entropyBits.length / 32; boolean[] concatBits = new boolean[entropyBits.length + checksumLengthBits]; System.arraycopy(entropyBits, 0, concatBits, 0, entropyBits.length); System.arraycopy(hashBits, 0, concatBits, entropyBits.length, checksumLengthBits); ArrayList<String> words = new ArrayList<>(); int nwords = concatBits.length / 11; for (int i = 0; i < nwords; ++i) { int index = 0; for (int j = 0; j < 11; ++j) { index <<= 1; if (concatBits[(i * 11) + j]) index |= 0x1; } words.add(this.wordList.get(index)); } return words; } MnemonicCode();  MnemonicCode(InputStream wordstream, String wordListDigest); List<String> getWordList(); static byte[] toSeed(List<String> words, String passphrase); byte[] toEntropy(List<String> words); List<String> toMnemonic(byte[] entropy); void check(List<String> words); static long BIP39_STANDARDISATION_TIME_SECS; static MnemonicCode INSTANCE; }