Package org.bitcoinj.wallet
Class DeterministicSeed
- java.lang.Object
-
- org.bitcoinj.wallet.DeterministicSeed
-
- All Implemented Interfaces:
EncryptableItem
public class DeterministicSeed extends java.lang.Object implements EncryptableItem
Holds the seed bytes for the BIP32 deterministic wallet algorithm, inside aDeterministicKeyChain. The purpose of this wrapper is to simplify the encryption code.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_SEED_ENTROPY_BITSstatic intMAX_SEED_ENTROPY_BITS
-
Constructor Summary
Constructors Constructor Description DeterministicSeed(byte[] entropy, java.lang.String passphrase, long creationTimeSeconds)Constructs a seed from a BIP 39 mnemonic code.DeterministicSeed(byte[] seed, java.util.List<java.lang.String> mnemonic, long creationTimeSeconds)DeterministicSeed(java.lang.String mnemonicString, byte[] seed, java.lang.String passphrase, long creationTimeSeconds)DeterministicSeed(java.security.SecureRandom random, int bits, java.lang.String passphrase)Constructs a seed from a BIP 39 mnemonic code.DeterministicSeed(java.util.List<java.lang.String> mnemonicCode, byte[] seed, java.lang.String passphrase, long creationTimeSeconds)Constructs a seed from a BIP 39 mnemonic code.DeterministicSeed(EncryptedData encryptedMnemonic, EncryptedData encryptedSeed, long creationTimeSeconds)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheck()Check if our mnemonic is a valid mnemonic phrase for our word list.DeterministicSeeddecrypt(KeyCrypter crypter, java.lang.String passphrase, org.bouncycastle.crypto.params.KeyParameter aesKey)DeterministicSeedencrypt(KeyCrypter keyCrypter, org.bouncycastle.crypto.params.KeyParameter aesKey)booleanequals(java.lang.Object o)longgetCreationTimeSeconds()Returns the time in seconds since the UNIX epoch at which this encryptable item was first created/derived.EncryptedDatagetEncryptedData()Returns the initialization vector and encrypted secret bytes, or null if not encrypted.EncryptedDatagetEncryptedSeedData()Protos.Wallet.EncryptionTypegetEncryptionType()Returns an enum constant describing what algorithm was used to encrypt the key or UNENCRYPTED.java.util.List<java.lang.String>getMnemonicCode()Get the mnemonic code, or null if unknown.java.lang.StringgetMnemonicString()Get the mnemonic code as string, or null if unknown.byte[]getSecretBytes()Returns the raw bytes of the item, if not encrypted, or null if encrypted or the secret is missing.byte[]getSeedBytes()inthashCode()booleanisEncrypted()Returns whether the item is encrypted or not.voidsetCreationTimeSeconds(long creationTimeSeconds)java.lang.StringtoHexString()Returns the seed as hex or null if encrypted.java.lang.StringtoString()java.lang.StringtoString(boolean includePrivate)
-
-
-
Field Detail
-
DEFAULT_SEED_ENTROPY_BITS
public static final int DEFAULT_SEED_ENTROPY_BITS
- See Also:
- Constant Field Values
-
MAX_SEED_ENTROPY_BITS
public static final int MAX_SEED_ENTROPY_BITS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DeterministicSeed
public DeterministicSeed(java.lang.String mnemonicString, byte[] seed, java.lang.String passphrase, long creationTimeSeconds) throws UnreadableWalletException- Throws:
UnreadableWalletException
-
DeterministicSeed
public DeterministicSeed(byte[] seed, java.util.List<java.lang.String> mnemonic, long creationTimeSeconds)
-
DeterministicSeed
public DeterministicSeed(EncryptedData encryptedMnemonic, @Nullable EncryptedData encryptedSeed, long creationTimeSeconds)
-
DeterministicSeed
public DeterministicSeed(java.util.List<java.lang.String> mnemonicCode, @Nullable byte[] seed, java.lang.String passphrase, long creationTimeSeconds)Constructs a seed from a BIP 39 mnemonic code. SeeMnemonicCodefor more details on this scheme.- Parameters:
mnemonicCode- A list of words.seed- The derived seed, or pass null to derive it from mnemonicCode (slow)passphrase- A user supplied passphrase, or an empty string if there is no passphrasecreationTimeSeconds- When the seed was originally created, UNIX time.
-
DeterministicSeed
public DeterministicSeed(java.security.SecureRandom random, int bits, java.lang.String passphrase)Constructs a seed from a BIP 39 mnemonic code. SeeMnemonicCodefor more details on this scheme.- Parameters:
random- Entropy sourcebits- number of bits, must be divisible by 32passphrase- A user supplied passphrase, or an empty string if there is no passphrase
-
DeterministicSeed
public DeterministicSeed(byte[] entropy, java.lang.String passphrase, long creationTimeSeconds)Constructs a seed from a BIP 39 mnemonic code. SeeMnemonicCodefor more details on this scheme.- Parameters:
entropy- entropy bits, length must be divisible by 32passphrase- A user supplied passphrase, or an empty string if there is no passphrasecreationTimeSeconds- When the seed was originally created, UNIX time.
-
-
Method Detail
-
isEncrypted
public boolean isEncrypted()
Description copied from interface:EncryptableItemReturns whether the item is encrypted or not. If it is, thenEncryptableItem.getSecretBytes()will return null.- Specified by:
isEncryptedin interfaceEncryptableItem
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public java.lang.String toString(boolean includePrivate)
-
toHexString
@Nullable public java.lang.String toHexString()
Returns the seed as hex or null if encrypted.
-
getSecretBytes
@Nullable public byte[] getSecretBytes()
Description copied from interface:EncryptableItemReturns the raw bytes of the item, if not encrypted, or null if encrypted or the secret is missing.- Specified by:
getSecretBytesin interfaceEncryptableItem
-
getSeedBytes
@Nullable public byte[] getSeedBytes()
-
getEncryptedData
@Nullable public EncryptedData getEncryptedData()
Description copied from interface:EncryptableItemReturns the initialization vector and encrypted secret bytes, or null if not encrypted.- Specified by:
getEncryptedDatain interfaceEncryptableItem
-
getEncryptionType
public Protos.Wallet.EncryptionType getEncryptionType()
Description copied from interface:EncryptableItemReturns an enum constant describing what algorithm was used to encrypt the key or UNENCRYPTED.- Specified by:
getEncryptionTypein interfaceEncryptableItem
-
getEncryptedSeedData
@Nullable public EncryptedData getEncryptedSeedData()
-
getCreationTimeSeconds
public long getCreationTimeSeconds()
Description copied from interface:EncryptableItemReturns the time in seconds since the UNIX epoch at which this encryptable item was first created/derived.- Specified by:
getCreationTimeSecondsin interfaceEncryptableItem
-
setCreationTimeSeconds
public void setCreationTimeSeconds(long creationTimeSeconds)
-
encrypt
public DeterministicSeed encrypt(KeyCrypter keyCrypter, org.bouncycastle.crypto.params.KeyParameter aesKey)
-
decrypt
public DeterministicSeed decrypt(KeyCrypter crypter, java.lang.String passphrase, org.bouncycastle.crypto.params.KeyParameter aesKey)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
check
public void check() throws MnemonicExceptionCheck if our mnemonic is a valid mnemonic phrase for our word list. Does nothing if we are encrypted.- Throws:
MnemonicException- if check fails
-
getMnemonicCode
@Nullable public java.util.List<java.lang.String> getMnemonicCode()
Get the mnemonic code, or null if unknown.
-
getMnemonicString
@Nullable public java.lang.String getMnemonicString()
Get the mnemonic code as string, or null if unknown.
-
-