doc.go raw

   1  /*Package hdkeychain provides an API for bitcoin hierarchical deterministic extended keys (BIP0032).
   2  
   3  Overview
   4  
   5  The ability to implement hierarchical deterministic wallets depends on the ability to create and derive hierarchical
   6  deterministic extended keys. At a high level, this package provides support for those hierarchical deterministic
   7  extended keys by providing an ExtendedKey type and supporting functions. Each extended key can either be a private or
   8  public extended key which itself is capable of deriving a child extended key.
   9  
  10  Determining the Extended Key Type
  11  
  12  Whether an extended key is a private or public extended key can be determined with the IsPrivate function. Transaction
  13  Signing Keys and Payment Addresses In order to create and sign transactions, or provide others with addresses to send
  14  funds to, the underlying key and address material must be accessible. This package provides the ECPubKey, ECPrivKey, and
  15  Address functions for this purpose.
  16  
  17  The Master Node
  18  
  19  As previously mentioned, the extended keys are hierarchical meaning they are used to form a tree. The root of that tree
  20  is called the master node and this package provides the NewMaster function to create it from a cryptographically random
  21  seed. The GenerateSeed function is provided as a convenient way to create a random seed for use with the NewMaster
  22  function.
  23  
  24  Deriving Children
  25  
  26  Once you have created a tree root (or have deserialized an extended key as discussed later), the child extended keys can
  27  be derived by using the Child function. The Child function supports deriving both normal (non-hardened) and hardened
  28  child extended keys. In order to derive a hardened extended key, use the HardenedKeyStart constant + the hardened key
  29  number as the index to the Child function. This provides the ability to cascade the keys into a tree and hence generate
  30  the hierarchical deterministic key chains.
  31  
  32  Normal vs Hardened Child Extended Keys
  33  
  34  A private extended key can be used to derive both hardened and non-hardened (normal) child private and public extended
  35  keys. A public extended key can only be used to derive non-hardened child public extended keys. As enumerated in BIP0032
  36  "knowledge of the extended public key plus any non-hardened private key descending from it is equivalent to knowing the
  37  extended private key (and thus every private and public key descending from it). This means that extended public keys
  38  must be treated more carefully than regular public keys. It is also the reason for the existence of hardened keys, and
  39  why they are used for the account level in the tree. This way, a leak of an account-specific (or below) private key
  40  never risks compromising the master or other accounts."
  41  
  42  Neutering a Private Extended Key
  43  
  44  A private extended key can be converted to a new instance of the corresponding public extended key with the Neuter
  45  function. The original extended key is not modified. A public extended key is still capable of deriving non-hardened
  46  child public extended keys.
  47  
  48  Serializing and Deserializing Extended Keys
  49  
  50  Extended keys are serialized and deserialized with the String and NewKeyFromString functions. The serialized key is a
  51  Base58-encoded string which looks like the following:
  52  
  53  	public key:   xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw
  54  	private key:  xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7
  55  
  56  Network
  57  
  58  Extended keys are much like normal Bitcoin addresses in that they have version bytes which tie them to a specific
  59  network. The SetNet and IsForNet functions are provided to set and determinine which network an extended key is
  60  associated with.
  61  */
  62  package hdkeychain
  63