bip32

package
v0.0.0-...-d2b8996 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2019 License: BSD-3-Clause Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
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 NewHDKey

func NewHDKey(seed []byte) *HDKey

NewHDKey -- creates a new master HDKey from a seed.

func NewHDKeyFromString

func NewHDKeyFromString(wif string) (*HDKey, error)

NewHDKeyFromString -- import WIF string to HDKey.

func NewHDKeyRand

func NewHDKeyRand() (*HDKey, error)

NewHDKeyRand -- returns the HDKey with random seed.

func (*HDKey) Derive

func (k *HDKey) Derive(childIdx uint32) (*HDKey, error)

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

func (k *HDKey) DeriveByPath(path string) (*HDKey, error)

DeriveByPath -- derive by path. m/1/2/3

func (*HDKey) HDPublicKey

func (k *HDKey) HDPublicKey() *HDKey

HDPublicKey -- the public HDkey.

func (*HDKey) PrivateKey

func (k *HDKey) PrivateKey() *xcrypto.PrvKey

PrivateKey -- ecdsa private key. If HDKey is public key, it will returns nil.

func (*HDKey) PublicKey

func (k *HDKey) PublicKey() *xcrypto.PubKey

PublicKey -- the ecdsa public key.

func (*HDKey) ToString

func (k *HDKey) ToString(net *network.Network) string

ToString -- the HDkey as a human-readable base58-encoded string, WIF, 78bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL