Package nxt.crypto

Class KeyDerivation

java.lang.Object
nxt.crypto.KeyDerivation

public class KeyDerivation extends Object
  • Constructor Details

    • KeyDerivation

      public KeyDerivation()
  • Method Details

    • deriveMnemonic

      public static KeyDerivation.Bip32Node deriveMnemonic(String path, String mnemonic)
      Parameters:
      path - bip32 path
      mnemonic - bip39 words
      Returns:
      derived seed
    • mnemonicToSeed

      public static byte[] mnemonicToSeed(String mnemonic)
    • mnemonicToSeed

      public static byte[] mnemonicToSeed(String mnemonic, String passphrase)
    • deriveSeed

      public static KeyDerivation.Bip32Node deriveSeed(String path, byte[] seed)
      Parameters:
      path - bip32 string path to derive (eg 42'/1/2)
      seed - 512 bits seed
      Returns:
      bip32 node representing the public/private key pair and chain code
    • deriveChildPublicKey

      public static KeyDerivation.Bip32Node deriveChildPublicKey(PublicKeyDerivationInfo derivationInfo)
    • deriveChildPublicKey

      public static KeyDerivation.Bip32Node deriveChildPublicKey(KeyDerivation.Bip32Node node, int childIndex)
    • deriveChildPublicKey

      public static KeyDerivation.Bip32Node deriveChildPublicKey(SerializedMasterPublicKey serializedMasterPublicKey, int childIndex)
    • deriveChildPublicKey

      public static KeyDerivation.Bip32Node deriveChildPublicKey(byte[] parentPublicKey, byte[] chainCode, int childIndex)
    • deriveChildPrivateKey

      public static KeyDerivation.Bip32Node deriveChildPrivateKey(KeyDerivation.Bip32Node node, int childIndex)
      INPUT:
      • (kL,kR): 64 bytes private eddsa key
      • A: 32 bytes public key (y coordinate only), optional as A = kR.G (y coordinate only)
      • c: 32 bytes chain code
      • i: child index to compute (hardened if >= 0x80000000)
      OUTPUT:
      • (kL_i,kR_i): 64 bytes ith-child private eddsa key
      • A_i: 32 bytes ith-child public key, A_i = kR_i.G (y coordinatte only)
      • c_i: 32 bytes ith-child chain code
      PROCESS: 1. encode i 4-bytes little endian, il = encode_U32LE(i)
      2. if i is less than 2^31
      - compute Z = HMAC-SHA512(key=c, Data=0x02 | A | il )
      - compute c_ = HMAC-SHA512(key=c, Data=0x03 | A | il )
      else
      - compute Z = HMAC-SHA512(key=c, Data=0x00 | kL | kR | il )
      - compute c_ = HMAC-SHA512(key=c, Data=0x01 | kL | kR | il )
      3. ci = lowest_32bytes(c_)
      4. set ZL = highest_28bytes(Z)
      set ZR = lowest_32bytes(Z)
      5. compute kL_i:
      zl_ = LEBytes_to_int(ZL)
      kL_ = LEBytes_to_int(kL)
      kLi_ = zl_*8 + kL_
      if kLi_ % order == 0: child does not exist
      kL_i = int_to_LEBytes(kLi_)
      6. compute kR_i
      zr_ = LEBytes_to_int(ZR)
      kR_ = LEBytes_to_int(kR)
      kRi_ = (zr_ + kRn_) % 2^256
      kR_i = int_to_LEBytes(kRi_)
      7. compute A
      A = kLi_.G
      8. return (kL_i,kR_i), A_i, c
      Parameters:
      node - node
      childIndex - child index
      Returns:
      derived node