Class Mnemonic

java.lang.Object
com.hedera.hashgraph.sdk.Mnemonic

public final class Mnemonic extends Object
BIP-39 24-word mnemonic phrases compatible with the Android and iOS mobile wallets.
  • Field Details

    • words

      public final List<CharSequence> words
      The list of words in this mnemonic.
  • Method Details

    • fromWords

      public static Mnemonic fromWords(List<? extends CharSequence> words) throws BadMnemonicException
      Construct a mnemonic from a 24-word list. validate() is called before returning, and it will throw an exception if it does not pass validation. An invalid mnemonic can still create valid Ed25519 private keys, so the exception will contain the mnemonic in case the user wants to ignore the outcome of the validation.
      Parameters:
      words - the 24-word list that constitutes a mnemonic phrase.
      Returns:
      this
      Throws:
      BadMnemonicException - if the mnemonic does not pass validation.
      See Also:
      • the function that validates the mnemonic.
    • fromString

      public static Mnemonic fromString(String mnemonicString) throws BadMnemonicException
      Recover a mnemonic from a string, splitting on spaces.
      Parameters:
      mnemonicString - The string to recover the mnemonic from
      Returns:
      this
      Throws:
      BadMnemonicException - if the mnemonic does not pass validation.
    • generate24

      public static Mnemonic generate24()
      Returns a new random 24-word mnemonic from the BIP-39 standard English word list.
      Returns:
      this
    • generate12

      public static Mnemonic generate12()
      Returns a new random 12-word mnemonic from the BIP-39 standard English word list.
      Returns:
      this
    • toPrivateKey

      @Deprecated public PrivateKey toPrivateKey(String passphrase)
      Deprecated.
      use toStandardEd25519PrivateKey(String, int) ()} or toStandardECDSAsecp256k1PrivateKey(String, int) (String, int)} instead Recover a private key from this mnemonic phrase.

      This is not compatible with the phrases generated by the Android and iOS wallets; use the no-passphrase version instead.

      Parameters:
      passphrase - the passphrase used to protect the mnemonic
      Returns:
      the recovered key; use PrivateKey.derive(int) to get a key for an account index (0 for default account)
      See Also:
    • toLegacyPrivateKey

      public PrivateKey toLegacyPrivateKey() throws BadMnemonicException
      Extract the private key.
      Returns:
      the private key
      Throws:
      BadMnemonicException - when there are issues with the mnemonic
    • toPrivateKey

      @Deprecated public PrivateKey toPrivateKey()
      Deprecated.
      use toStandardEd25519PrivateKey(String, int) ()} or toStandardECDSAsecp256k1PrivateKey(String, int) (String, int)} instead Recover a private key from this mnemonic phrase.
      Returns:
      the recovered key; use PrivateKey.derive(int) to get a key for an account index (0 for default account)
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toSeed

      byte[] toSeed(String passphrase)
      Convert passphrase to a byte array.
      Parameters:
      passphrase - the passphrase
      Returns:
      the byte array
    • toStandardEd25519PrivateKey

      public PrivateKey toStandardEd25519PrivateKey(String passphrase, int index)
      Recover an Ed25519 private key from this mnemonic phrase, with an optional passphrase.
      Parameters:
      passphrase - the passphrase used to protect the mnemonic
      index - the derivation index
      Returns:
      the private key
    • toStandardECDSAsecp256k1PrivateKey

      public PrivateKey toStandardECDSAsecp256k1PrivateKey(String passphrase, int index)
      Recover an ECDSAsecp256k1 private key from this mnemonic phrase, with an optional passphrase. Uses the default derivation path of `m/44'/3030'/0'/0/${index}`.
      Parameters:
      passphrase - the passphrase used to protect the mnemonic, use "" for none
      index - the derivation index
      Returns:
      the private key
    • toStandardECDSAsecp256k1PrivateKeyCustomDerivationPath

      public PrivateKey toStandardECDSAsecp256k1PrivateKeyCustomDerivationPath(String passphrase, String derivationPath)
      Recover an ECDSAsecp256k1 private key from this mnemonic phrase and derivation path, with an optional passphrase.
      Parameters:
      passphrase - the passphrase used to protect the mnemonic, use "" for none
      derivationPath - the derivation path in BIP-44 format, e.g. "m/44'/60'/0'/0/0"
      Returns:
      the private key