Documentation ¶
Index ¶
Constants ¶
const ( // HardenedKeyStart is the index at which a hardended key starts. Each // extended key has 2^31 normal child keys and 2^31 hardned child keys. // Thus the range for normal child keys is [0, 2^31 - 1] and the range // for hardened child keys is [2^31, 2^32 - 1]. HardenedKeyStart = 0x80000000 // 2^31 // PublicKeyCompressedLength is the byte count of a compressed public key PublicKeyCompressedLength = 33 )
Formulas: pubkey1 = privkey1·G n = hash(nonce|i), i=2,3,4... pubkey2 = pubkey1 + n2·G = (privkey1 + n2)·G privkey2 = (privkey1 + n2) https://www.cs.cornell.edu/~iddo/detwal.pdf
BIP32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HDKey ¶
type HDKey struct {
// contains filtered or unexported fields
}
HDKey -- a BIP32 Hierarchically Derived key.
func NewHDKeyFromString ¶
NewHDKeyFromString -- import WIF string to HDKey.
func NewHDKeyRand ¶
NewHDKeyRand -- returns the HDKey with random seed.
func (*HDKey) Derive ¶
Derive -- returns a derived child extended key at the given index. When this extended key is a private extended key (as determined by the IsPrivate function), a private extended key will be derived. Otherwise, the derived extended key will be also be a public extended key.
When the index is greater to or equal than the HardenedKeyStart constant, the derived extended key will be a hardened extended key. It is only possible to derive a hardended extended key from a private extended key. Consequently, this function will return ErrDeriveHardFromPublic if a hardened child extended key is requested from a public extended key.
A hardened extended key is useful since, as previously mentioned, it requires a parent private extended key to derive. In other words, normal child extended public keys can be derived from a parent public extended key (no knowledge of the parent private key) whereas hardened extended keys may not be.
NOTE: There is an extremely small chance (< 1 in 2^127) the specific child index does not derive to a usable child. The ErrInvalidChild error will be returned if this should occur, and the caller is expected to ignore the invalid child and simply increment to the next index.
func (*HDKey) DeriveByPath ¶
DeriveByPath -- derive by path. m/1/2/3
func (*HDKey) PrivateKey ¶
PrivateKey -- ecdsa private key. If HDKey is public key, it will returns nil.