Class 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 a DeterministicKeyChain. The purpose of this wrapper is to simplify the encryption code.
    • Method Detail

      • ofMnemonic

        public static DeterministicSeed ofMnemonic​(java.lang.String mnemonicCode,
                                                   java.lang.String passphrase,
                                                   java.time.Instant creationTime)
        Constructs a seed from a BIP 39 mnemonic code. See MnemonicCode for more details on this scheme.
        Parameters:
        mnemonicCode - list of words, space separated
        passphrase - user supplied passphrase, or empty string if there is no passphrase
        creationTime - when the seed was originally created
      • ofMnemonic

        public static DeterministicSeed ofMnemonic​(java.lang.String mnemonicCode,
                                                   java.lang.String passphrase)
        Constructs a seed from a BIP 39 mnemonic code. See MnemonicCode for more details on this scheme. Use this if you don't know the seed's creation time.
        Parameters:
        mnemonicCode - list of words, space separated
        passphrase - user supplied passphrase, or empty string if there is no passphrase
      • ofMnemonic

        public static DeterministicSeed ofMnemonic​(java.util.List<java.lang.String> mnemonicCode,
                                                   java.lang.String passphrase,
                                                   java.time.Instant creationTime)
        Constructs a seed from a BIP 39 mnemonic code. See MnemonicCode for more details on this scheme.
        Parameters:
        mnemonicCode - list of words
        passphrase - user supplied passphrase, or empty string if there is no passphrase
        creationTime - when the seed was originally created
      • ofMnemonic

        public static DeterministicSeed ofMnemonic​(java.util.List<java.lang.String> mnemonicCode,
                                                   java.lang.String passphrase)
        Constructs a seed from a BIP 39 mnemonic code. See MnemonicCode for more details on this scheme. Use this if you don't know the seed's creation time.
        Parameters:
        mnemonicCode - list of words
        passphrase - user supplied passphrase, or empty string if there is no passphrase
      • ofEntropy

        public static DeterministicSeed ofEntropy​(byte[] entropy,
                                                  java.lang.String passphrase,
                                                  java.time.Instant creationTime)
        Constructs a BIP 39 mnemonic code and a seed from a given entropy. See MnemonicCode for more details on this scheme.
        Parameters:
        entropy - entropy bits, length must be at least 128 bits and a multiple of 32 bits
        passphrase - user supplied passphrase, or empty string if there is no passphrase
        creationTime - when the seed was originally created
      • ofEntropy

        public static DeterministicSeed ofEntropy​(byte[] entropy,
                                                  java.lang.String passphrase)
        Constructs a BIP 39 mnemonic code and a seed from a given entropy. See MnemonicCode for more details on this scheme. Use this if you don't know the seed's creation time.
        Parameters:
        entropy - entropy bits, length must be at least 128 bits and a multiple of 32 bits
        passphrase - user supplied passphrase, or empty string if there is no passphrase
      • ofRandom

        public static DeterministicSeed ofRandom​(java.security.SecureRandom random,
                                                 int bits,
                                                 java.lang.String passphrase)
        Constructs a BIP 39 mnemonic code and a seed randomly. See MnemonicCode for more details on this scheme.
        Parameters:
        random - random source for the entropy
        bits - number of bits of entropy, must be at least 128 bits and a multiple of 32 bits
        passphrase - user supplied passphrase, or empty string if there is no passphrase
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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: EncryptableItem
        Returns the raw bytes of the item, if not encrypted, or null if encrypted or the secret is missing.
        Specified by:
        getSecretBytes in interface EncryptableItem
      • getSeedBytes

        @Nullable
        public byte[] getSeedBytes()
      • getEncryptedSeedData

        @Nullable
        public EncryptedData getEncryptedSeedData()
      • creationTime

        public java.util.Optional<java.time.Instant> creationTime()
        Description copied from interface: EncryptableItem
        Returns the time at which this encryptable item was first created/derived, or empty of unknown.
        Specified by:
        creationTime in interface EncryptableItem
      • setCreationTime

        public void setCreationTime​(java.time.Instant creationTime)
        Sets the creation time of this seed.
        Parameters:
        creationTime - creation time of this seed
      • clearCreationTime

        public void clearCreationTime()
        Clears the creation time of this seed. This is mainly used deserialization and cloning. Normally you should not need to use this, as keys should have proper creation times whenever possible.
      • setCreationTimeSeconds

        @Deprecated
        public void setCreationTimeSeconds​(long creationTimeSecs)
        Deprecated.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • check

        public void check()
                   throws MnemonicException
        Check 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.