Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class Mnemonic
- Object
- 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.
Methods
public static String generate(int strengthBits) | A new mnemonic over fresh entropy from the platform CSPRNG. |
public static String fromEntropy(byte[] entropy) | The mnemonic that encodes entropy (16 to 32 bytes, a multiple of 4). |
public static byte[] toEntropy(String mnemonic) | The entropy a mnemonic encodes, after checking every word and the checksum. |
public static boolean isValid(String mnemonic) | Tells whether the text is a mnemonic with known words and a correct checksum. |
public static byte[] toSeed(String mnemonic, String passphrase) | The 64-byte BIP-39 seed: PBKDF2-HMAC-SHA512 over the words, salted with "mnemonic" + passphrase, 2048 iterations. |
public static int indexOf(String word) | The position of an English word in the BIP-39 list, or -1. |
public static String word(int index) | The English word at index (0 to 2047). |
Inherited methods
Method details
generate
public static String generate(int strengthBits)Parameters
strengthBitsint- 128, 160, 192, 224 or 256, for 12, 15, 18, 21 or 24 words
fromEntropy
public static String fromEntropy(byte[] entropy)entropy (16 to 32 bytes, a multiple of 4).toEntropy
public static byte[] toEntropy(String mnemonic)Throws
IllegalArgumentException- for an unknown word, a word count other than 12, 15, 18, 21 or 24, or a checksum mismatch
isValid
public static boolean isValid(String mnemonic)toSeed
public static byte[] toSeed(String mnemonic, String passphrase)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; call isValid 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
mnemonicString- the words, separated by whitespace
passphraseString- the optional extra word (“25th word”);
nullor""for none
indexOf
public static int indexOf(String word)word
public static String word(int index)index (0 to 2047).