Package nxt.crypto
Class KeyDerivation
java.lang.Object
nxt.crypto.KeyDerivation
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a node in the Bip32 derivation tree. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic KeyDerivation.Bip32NodederiveChildPrivateKey(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.static KeyDerivation.Bip32NodederiveChildPublicKey(byte[] parentPublicKey, byte[] chainCode, int childIndex) static KeyDerivation.Bip32NodederiveChildPublicKey(KeyDerivation.Bip32Node node, int childIndex) static KeyDerivation.Bip32NodederiveChildPublicKey(PublicKeyDerivationInfo derivationInfo) static KeyDerivation.Bip32NodederiveChildPublicKey(SerializedMasterPublicKey serializedMasterPublicKey, int childIndex) static KeyDerivation.Bip32NodederiveMnemonic(String path, String mnemonic) static KeyDerivation.Bip32NodederiveSeed(String path, byte[] seed) static byte[]mnemonicToSeed(String mnemonic) static byte[]mnemonicToSeed(String mnemonic, String passphrase)
-
Constructor Details
-
KeyDerivation
public KeyDerivation()
-
-
Method Details
-
deriveMnemonic
- Parameters:
path- bip32 pathmnemonic- bip39 words- Returns:
- derived seed
-
mnemonicToSeed
-
mnemonicToSeed
-
deriveSeed
- 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
-
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)
- (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
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- nodechildIndex- child index- Returns:
- derived node
-