Class Mnemonic
BIP-39 mnemonic sentences: the 12 to 24 English words a wallet shows as its backup, and
the 64-byte seed Bip32 and Slip10 derive every key from.
String words = Mnemonic.generate(128); // 12 words
byte[] seed = Mnemonic.toSeed(words, ""); // the empty passphrase
Bip32 account = Bip32.master(seed).derive("m/44'/60'/0'/0/0");
Only the English wordlist is built in, which is what every wallet exports by default.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringfromEntropy(byte[] entropy) The mnemonic that encodesentropy(16 to 32 bytes, a multiple of 4).static Stringgenerate(int strengthBits) A new mnemonic over fresh entropy from the platform CSPRNG.static intThe position of an English word in the BIP-39 list, or -1.static booleanTells whether the text is a mnemonic with known words and a correct checksum.static byte[]The entropy a mnemonic encodes, after checking every word and the checksum.static byte[]The 64-byte BIP-39 seed: PBKDF2-HMAC-SHA512 over the words, salted with"mnemonic" + passphrase, 2048 iterations.static Stringword(int index) The English word atindex(0 to 2047).
-
Method Details
-
generate
A new mnemonic over fresh entropy from the platform CSPRNG.
Parameters
strengthBits: 128, 160, 192, 224 or 256, for 12, 15, 18, 21 or 24 words
-
fromEntropy
The mnemonic that encodesentropy(16 to 32 bytes, a multiple of 4). -
toEntropy
The entropy a mnemonic encodes, after checking every word and the checksum.
Throws
IllegalArgumentException: for an unknown word, a word count other than 12, 15, 18, 21 or 24, or a checksum mismatch
-
isValid
Tells whether the text is a mnemonic with known words and a correct checksum. -
toSeed
The 64-byte BIP-39 seed: PBKDF2-HMAC-SHA512 over the words, salted with
"mnemonic" + passphrase, 2048 iterations. The words are not checked, as the specification asks; callisValid(String)first to reject a mistyped backup.BIP-39 normalizes both strings to Unicode NFKD before encoding them as UTF-8. The words always are ASCII and the device class library has no normalizer, so a passphrase outside ASCII must be given already in NFKD form -- a precomposed accent otherwise derives a different wallet than other software does.
Parameters
-
mnemonic: the words, separated by whitespace -
passphrase: the optional extra word ("25th word");nullor""for none
-
-
indexOf
The position of an English word in the BIP-39 list, or -1. -
word
The English word atindex(0 to 2047).
-