Class MnemonicUtils

    • Constructor Summary

      Constructors 
      Constructor Description
      MnemonicUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte calculateChecksum​(byte[] initialEntropy)  
      static byte[] generateEntropy​(java.lang.String mnemonic)
      Create entropy from the mnemonic.
      static java.lang.String generateMnemonic​(byte[] initialEntropy)
      The mnemonic must encode entropy in a multiple of 32 bits.
      static byte[] generateSeed​(java.lang.String mnemonic, java.lang.String passphrase)
      To create a binary seed from the mnemonic, we use the PBKDF2 function with a mnemonic sentence (in UTF-8 NFKD) used as the password and the string "mnemonic" + passphrase (again in UTF-8 NFKD) used as the salt.
      static java.util.List<java.lang.String> getWords()  
      static boolean validateMnemonic​(java.lang.String mnemonic)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MnemonicUtils

        public MnemonicUtils()
    • Method Detail

      • generateMnemonic

        public static java.lang.String generateMnemonic​(byte[] initialEntropy)
        The mnemonic must encode entropy in a multiple of 32 bits. With more entropy security is improved but the sentence length increases. We refer to the initial entropy length as ENT. The allowed size of ENT is 128-256 bits.

        Mnemonic generation algorithm

        Given a randomly generated initial entropy of size ENT, first a checksum is generated by taking the first ENT / 32 bits of its SHA256 hash. This checksum is appended to the end of the initial entropy. Next, these concatenated bits are split into groups of 11 bits, each encoding a number from 0-2047, serving as an index into a wordlist. Finally, we convert these numbers into words and use the joined words as a mnemonic sentence.
        Parameters:
        initialEntropy - The initial entropy to generate mnemonic from
        Returns:
        The generated mnemonic
        Throws:
        java.lang.IllegalArgumentException - If the given entropy is invalid
        java.lang.IllegalStateException - If the word list has not been loaded
      • generateEntropy

        public static byte[] generateEntropy​(java.lang.String mnemonic)
        Create entropy from the mnemonic.
        Parameters:
        mnemonic - The input mnemonic which should be 128-160 bits in length containing only valid words
        Returns:
        Byte array representation of the entropy
      • getWords

        public static java.util.List<java.lang.String> getWords()
      • generateSeed

        public static byte[] generateSeed​(java.lang.String mnemonic,
                                          java.lang.String passphrase)
        To create a binary seed from the mnemonic, we use the PBKDF2 function with a mnemonic sentence (in UTF-8 NFKD) used as the password and the string "mnemonic" + passphrase (again in UTF-8 NFKD) used as the salt. The iteration count is set to 2048 and HMAC-SHA512 is used as the pseudo-random function. The length of the derived key is 512 bits (= 64 bytes).
        Parameters:
        mnemonic - The input mnemonic which should be 128-160 bits in length containing only valid words
        passphrase - The passphrase which will be used as part of salt for PBKDF2 function
        Returns:
        Byte array representation of the generated seed
      • validateMnemonic

        public static boolean validateMnemonic​(java.lang.String mnemonic)
      • calculateChecksum

        public static byte calculateChecksum​(byte[] initialEntropy)