Package org.bitcoinj.crypto
Class MnemonicCode
- java.lang.Object
-
- org.bitcoinj.crypto.MnemonicCode
-
public class MnemonicCode extends java.lang.Object
A MnemonicCode object may be used to convert between binary seed values and lists of words per the BIP 39 specification
-
-
Field Summary
Fields Modifier and Type Field Description static java.time.Instant
BIP39_STANDARDISATION_TIME
UNIX time for when the BIP39 standard was finalised.static int
BIP39_STANDARDISATION_TIME_SECS
Deprecated.static MnemonicCode
INSTANCE
-
Constructor Summary
Constructors Constructor Description MnemonicCode()
Initialise from the included word list.MnemonicCode(java.io.InputStream wordstream, java.lang.String wordListDigest)
Creates an MnemonicCode object, initializing with words read from the supplied input stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
check(java.util.List<java.lang.String> words)
Check to see if a mnemonic word list is valid.java.util.List<java.lang.String>
getWordList()
Gets the word list this code uses.byte[]
toEntropy(java.util.List<java.lang.String> words)
Convert mnemonic word list to original entropy value.java.util.List<java.lang.String>
toMnemonic(byte[] entropy)
Convert entropy data to mnemonic word list.static byte[]
toSeed(java.util.List<java.lang.String> words, java.lang.String passphrase)
Convert mnemonic word list to seed.
-
-
-
Field Detail
-
BIP39_STANDARDISATION_TIME
public static final java.time.Instant BIP39_STANDARDISATION_TIME
UNIX time for when the BIP39 standard was finalised. This can be used as a default seed birthday.
-
BIP39_STANDARDISATION_TIME_SECS
@Deprecated public static final int BIP39_STANDARDISATION_TIME_SECS
Deprecated.
-
INSTANCE
public static MnemonicCode INSTANCE
-
-
Constructor Detail
-
MnemonicCode
public MnemonicCode() throws java.io.IOException
Initialise from the included word list. Won't work on Android.- Throws:
java.io.IOException
-
MnemonicCode
public MnemonicCode(java.io.InputStream wordstream, java.lang.String wordListDigest) throws java.io.IOException, java.lang.IllegalArgumentException
Creates an MnemonicCode object, initializing with words read from the supplied input stream. If a wordListDigest is supplied the digest of the words will be checked.- Parameters:
wordstream
- input stream of 2048 line-seperated wordswordListDigest
- hex-encoded Sha256 digest to check against- Throws:
java.io.IOException
- if there was a problem reading the steamjava.lang.IllegalArgumentException
- if list size is not 2048 or digest mismatch
-
-
Method Detail
-
getWordList
public java.util.List<java.lang.String> getWordList()
Gets the word list this code uses.- Returns:
- unmodifiable word list
-
toSeed
public static byte[] toSeed(java.util.List<java.lang.String> words, java.lang.String passphrase)
Convert mnemonic word list to seed.
-
toEntropy
public byte[] toEntropy(java.util.List<java.lang.String> words) throws MnemonicException.MnemonicLengthException, MnemonicException.MnemonicWordException, MnemonicException.MnemonicChecksumException
Convert mnemonic word list to original entropy value.
-
toMnemonic
public java.util.List<java.lang.String> toMnemonic(byte[] entropy)
Convert entropy data to mnemonic word list.- Parameters:
entropy
- entropy bits, length must be a multiple of 32 bits
-
check
public void check(java.util.List<java.lang.String> words) throws MnemonicException
Check to see if a mnemonic word list is valid.- Throws:
MnemonicException
-
-