java.lang.Object
com.hedera.hashgraph.sdk.Mnemonic
BIP-39 24-word mnemonic phrases compatible with the Android and iOS mobile wallets.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic MnemonicfromString(String mnemonicString) Recover a mnemonic from a string, splitting on spaces.static MnemonicfromWords(List<? extends CharSequence> words) Construct a mnemonic from a 24-word list.static MnemonicReturns a new random 12-word mnemonic from the BIP-39 standard English word list.static MnemonicReturns a new random 24-word mnemonic from the BIP-39 standard English word list.Extract the private key.Deprecated.toPrivateKey(String passphrase) Deprecated.usetoStandardEd25519PrivateKey(String, int)()} ortoStandardECDSAsecp256k1PrivateKey(String, int)(String, int)} instead Recover a private key from this mnemonic phrase.(package private) byte[]Convert passphrase to a byte array.toStandardECDSAsecp256k1PrivateKey(String passphrase, int index) Recover an ECDSAsecp256k1 private key from this mnemonic phrase, with an optional passphrase.toStandardECDSAsecp256k1PrivateKeyCustomDerivationPath(String passphrase, String derivationPath) Recover an ECDSAsecp256k1 private key from this mnemonic phrase and derivation path, with an optional passphrase.toStandardEd25519PrivateKey(String passphrase, int index) Recover an Ed25519 private key from this mnemonic phrase, with an optional passphrase.toString()
-
Field Details
-
words
The list of words in this mnemonic.
-
-
Method Details
-
fromWords
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:
-
fromString
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
Returns a new random 24-word mnemonic from the BIP-39 standard English word list.- Returns:
this
-
generate12
Returns a new random 12-word mnemonic from the BIP-39 standard English word list.- Returns:
this
-
toPrivateKey
Deprecated.usetoStandardEd25519PrivateKey(String, int)()} ortoStandardECDSAsecp256k1PrivateKey(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
Extract the private key.- Returns:
- the private key
- Throws:
BadMnemonicException- when there are issues with the mnemonic
-
toPrivateKey
Deprecated.usetoStandardEd25519PrivateKey(String, int)()} ortoStandardECDSAsecp256k1PrivateKey(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
-
toSeed
Convert passphrase to a byte array.- Parameters:
passphrase- the passphrase- Returns:
- the byte array
-
toStandardEd25519PrivateKey
Recover an Ed25519 private key from this mnemonic phrase, with an optional passphrase.- Parameters:
passphrase- the passphrase used to protect the mnemonicindex- the derivation index- Returns:
- the private key
-
toStandardECDSAsecp256k1PrivateKey
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 noneindex- 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 nonederivationPath- the derivation path in BIP-44 format, e.g. "m/44'/60'/0'/0/0"- Returns:
- the private key
-
toStandardEd25519PrivateKey(String, int)()} ortoStandardECDSAsecp256k1PrivateKey(String, int)(String, int)} instead Recover a private key from this mnemonic phrase.