com.google.bitcoin.crypto
Class HDKeyDerivation

java.lang.Object
  extended by com.google.bitcoin.crypto.HDKeyDerivation

public final class HDKeyDerivation
extends Object

Implementation of the (public derivation version) deterministic wallet child key generation algorithm.


Method Summary
static DeterministicKey createMasterPrivateKey(byte[] seed)
          Generates a new deterministic key from the given seed, which can be any arbitrary byte array.
static DeterministicKey createMasterPrivKeyFromBytes(byte[] privKeyBytes, byte[] chainCode)
           
static DeterministicKey createMasterPubKeyFromBytes(byte[] pubKeyBytes, byte[] chainCode)
           
static DeterministicKey deriveChildKey(DeterministicKey parent, ChildNumber childNumber)
           
static DeterministicKey deriveChildKey(DeterministicKey parent, int childNumber)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createMasterPrivateKey

public static DeterministicKey createMasterPrivateKey(byte[] seed)
                                               throws HDDerivationException
Generates a new deterministic key from the given seed, which can be any arbitrary byte array. However resist the temptation to use a string as the seed - any key derived from a password is likely to be weak and easily broken by attackers (this is not theoretical, people have had money stolen that way). This method checks that the given seed is at least 64 bits long.

Throws:
HDDerivationException - if generated master key is invalid (private key 0 or >= n).
IllegalArgumentException - if the seed is less than 8 bytes and could be brute forced.

createMasterPrivKeyFromBytes

public static DeterministicKey createMasterPrivKeyFromBytes(byte[] privKeyBytes,
                                                            byte[] chainCode)
                                                     throws HDDerivationException
Throws:
HDDerivationException - if privKeyBytes is invalid (0 or >= n).

createMasterPubKeyFromBytes

public static DeterministicKey createMasterPubKeyFromBytes(byte[] pubKeyBytes,
                                                           byte[] chainCode)

deriveChildKey

public static DeterministicKey deriveChildKey(DeterministicKey parent,
                                              int childNumber)
Parameters:
childNumber - the "extended" child number, ie. with the 0x80000000 bit specifying private/public derivation.

deriveChildKey

public static DeterministicKey deriveChildKey(DeterministicKey parent,
                                              ChildNumber childNumber)
                                       throws HDDerivationException
Throws:
HDDerivationException - if private derivation is attempted for a public-only parent key, or if the resulting derived key is invalid (eg. private key == 0).


Copyright © 2014. All rights reserved.