@@ -2,15 +2,72 @@ package bip32
2
2
3
3
import "github.com/btcsuite/btcd/btcec"
4
4
5
+ // References:
6
+ // [BIP32]: BIP0032 - Hierarchical Deterministic Wallets
7
+ // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
8
+
9
+ // ExtendedKey specifies the basic api for a extended private or public key.
10
+ // TODO: add the Zero method manually clears all fields and bytes in the
11
+ // extended key. This can be used to explicitly clear key material from memory
12
+ // for enhanced security against memory scraping. This function only clears
13
+ // this particular key and not any children that have already been derived.
5
14
type ExtendedKey interface {
15
+ // AddressPubKeyHash returns the public key hash (20 bytes) derived from the
16
+ // key, which would be itself for public keys and the extended public key
17
+ // bound to it for private keys
6
18
AddressPubKeyHash () []byte
19
+ // Child returns a derived child extended key at the given index. When this
20
+ // extended key is a private extended key (as determined by the IsPrivate
21
+ // function), a private extended key will be derived. Otherwise, the derived
22
+ // extended key will be also be a public extended key.
23
+ //
24
+ // When the index is greater to or equal than the HardenedKeyStart constant,
25
+ // the derived extended key will be a hardened extended key. It is only
26
+ // possible to derive a hardended extended key from a private extended key.
27
+ // Consequently, this function will return ErrDeriveHardFromPublic if a
28
+ // hardened child extended key is requested from a public extended key.
29
+ //
30
+ // A hardened extended key is useful since, as previously mentioned, it
31
+ // requires a parent private extended key to derive. In other words, normal
32
+ // child extended public keys can be derived from a parent public extended
33
+ // key (no knowledge of the parent private key) whereas hardened extended
34
+ // keys may not be.
35
+ //
36
+ // NOTE: There is an extremely small chance (< 1 in 2^127) the specific child
37
+ // index does not derive to a usable child. The ErrInvalidChild error should
38
+ // be returned if this should occur, and the caller is expected to ignore the
39
+ // invalid child and simply increment to the next index.
7
40
Child (i uint32 ) (ExtendedKey , error )
41
+ // Depth returns the current derivation level with respect to the root.
42
+ //
43
+ // The root key has depth zero, and the field has a maximum of 255 due to
44
+ // how depth is serialized.
8
45
Depth () uint8
46
+ // Hardened tells if the key of interest is hardened, whose index is greater
47
+ // than HardenedKeyStart.
9
48
Hardened () bool
49
+ // Index returns the index of the key seen from its parent.
10
50
Index () uint32
51
+ // IsForNet checks if this key is in use for a given net specified by keyID
11
52
IsForNet (keyID Magic ) bool
53
+
54
+ // Neuter returns a new extended public key from a extended private key. The
55
+ // same extended key will be returned unaltered if it is already an extended
56
+ // public key.
57
+ //
58
+ // As the name implies, an extended public key does not have access to the
59
+ // private key, so it is not capable of signing transactions or deriving
60
+ // child extended private keys. However, it is capable of deriving further
61
+ // child extended public keys.
62
+ Neuter () (* PublicKey , error )
63
+ // ParentFingerprint returns a fingerprint of the parent extended key from
64
+ // which this one was derived.
12
65
ParentFingerprint () uint32
66
+ // Public converts the extended key to a btcec public key and returns it.
13
67
Public () (* btcec.PublicKey , error )
68
+ // SetNet associates the extended key, and any child keys yet to be derived
69
+ // from it, with the passed network.
14
70
SetNet (keyID Magic )
71
+ // String returns the extended key as a human-readable base58-encoded string.
15
72
String () string
16
73
}
0 commit comments