hdkeys

package module
v0.0.0-...-ee76d77 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2015 License: MIT Imports: 14 Imported by: 5

README

Hierarchical Deterministic Keys

Hierarchical deterministic key derivation library, as described in BIP-0032. Supports BIP-0043 and BIP-0044 (Multi-Account hierarchy).

Generating a new master key:

seed := make([]byte, 32)
rand.Read(seed)
key := hdkeys.NewMasterKey(seed)

Serializing / exporting a key:

encoded := key.SerializeEncode()
fmt.Println(encoded) // eg. "xprv9s21ZrQH143K2PXAG98v5UhDdHawJG1DsV8DJrc76VTV7n2c8ZyN3VDkEAPBKcBL7BQssWqPFgVZN5rktZZSd8j37PtzLaGx7tVNWtF8i5S"

Deriving a child key:

child, err := k.Child(0)
hardenedChild, err := k.Child(0 + 1<<31)

Getting the public version of a private key:

pubKey := prvKey.Public()
fmt.Println(pubKey.IsPublic()) // "true"

Getting the address of a key:

addr := key.PublicKeyHashEncode()
fmt.Println(addr) // "1AvqrWZtrKgJEJh1PStbHLMQ1Bk7N22GyJ"

BIP-0044

Generating BIP-0044 style addresses at the format m / purpose' / coin_type' / account' / change / address_index

key, err := masterKey.Chain("m/44'/0'/0'/0/0")

Documentation

Index

Constants

View Source
const (
	BitcoinExtendedPublicKeyVersion         = 0x0488b21e
	BitcoinExtendedPrivateKeyVersion        = 0x0488ade4
	BitcoinTestnetExtendedPublicKeyVersion  = 0x043587cf
	BitcoinTestnetExtendedPrivateKeyVersion = 0x04358394
)

Variables

This section is empty.

Functions

func ParseCompact

func ParseCompact(b []byte) point

func ParseUncompressed

func ParseUncompressed(d []byte) (*big.Int, *big.Int, error)

ParseUncompressed parses a 65 bytes uncompressed public address into a (X,Y) point on the curve.

func RIPEMD160Hash

func RIPEMD160Hash(data []byte) []byte

func SerializeCompact

func SerializeCompact(p point) []byte

func SerializeUncompressed

func SerializeUncompressed(p point) []byte

SerializeUncompressed serializes a point on the curve into a 65 byte long byte array.

Types

type Key

type Key struct {
	// contains filtered or unexported fields
}

func NewMasterKey

func NewMasterKey(data []byte) *Key

func NewMasterKeyRawData

func NewMasterKeyRawData(I []byte) *Key

func Parse

func Parse(d []byte) (*Key, error)

func ParseEncoded

func ParseEncoded(s string) (*Key, error)

ParseEncoded parses a base58 encoded HD Key.

func (*Key) Chain

func (k *Key) Chain(chain string) (*Key, error)

Chain performs all the child derivations necessary to end up with the key described with BIP32 notations, eg. m/44'/0'/1'/0/3.

func (*Key) Child

func (k *Key) Child(i uint32) (*Key, error)

Child returns the child key with index i. Private keys will return private childs, public keys will return public childs.

func (*Key) ChildOrDie

func (k *Key) ChildOrDie(i uint32) *Key

func (*Key) ExportWIF

func (k *Key) ExportWIF() (string, error)

ExportWIF exports private key in the compressed Wallet Import Format.

func (*Key) Fingerprint

func (k *Key) Fingerprint() []byte

func (*Key) IsPublic

func (k *Key) IsPublic() bool

func (Key) Public

func (k Key) Public() *Key

Public returns the public version of the Key that can't be used to create signatures.

func (*Key) PublicKey

func (k *Key) PublicKey() []byte

PublicKey returns the compressed serialized public key corresponding to Key.

func (*Key) PublicKeyHash

func (k *Key) PublicKeyHash() []byte

func (*Key) PublicKeyHashEncode

func (k *Key) PublicKeyHashEncode() string

func (*Key) PublicKeyHashUncompressed

func (k *Key) PublicKeyHashUncompressed() string

func (*Key) Serialize

func (k *Key) Serialize() []byte

func (*Key) SerializeEncode

func (k *Key) SerializeEncode() string

SerializeEncode serializes and base58 encodes Key.

func (*Key) Sign

func (k *Key) Sign(data []byte) (*big.Int, *big.Int)

func (Key) String

func (k Key) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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