Documentation ¶
Overview ¶
Package hdwallet implements heirarchical deterministic Bitcoin wallets, as defined in BIP 32.
BIP 32 - https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
This package provides utilities for generating hierarchical deterministic Bitcoin wallets.
Examples
// Generate a random 256 bit seed seed, err := hdwallet.GenSeed(256) // Create a master private key masterprv := hdwallet.MasterKey(seed) // Convert a private key to public key masterpub := masterprv.Pub() // Generate new child key based on private or public key childprv, err := masterprv.Child(0) childpub, err := masterpub.Child(0) // Create bitcoin address from public key address := childpub.Address() // Convenience string -> string Child and Address functions walletstring := childpub.String() childstring, err := hdwallet.StringChild(walletstring,0) childaddress, err := hdwallet.StringAddress(childstring)
Extended Keys ¶
Hierarchical deterministic wallets are simply deserialized extended keys. Extended Keys can be imported and exported as base58-encoded strings. Here are two examples:
public key: "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8" private key: "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi"
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( //MainNet Public []byte Private []byte //TestNet TestPublic []byte TestPrivate []byte )
Functions ¶
func GenSeed ¶
GenSeed returns a random seed with a length measured in bytes. The length must be at least 128.
func StringAddress ¶
StringToAddress returns the Bitcoin address of a base58-encoded extended key.
func StringCheck ¶
StringCheck is a validation check of a base58-encoded extended key.
Types ¶
type HDWallet ¶
type HDWallet struct { Vbytes []byte //4 bytes Depth uint16 //1 byte Fingerprint []byte //4 bytes I []byte //4 bytes Chaincode []byte //32 bytes Key []byte //33 bytes }
HDWallet defines the components of a hierarchical deterministic wallet
func StringWallet ¶
StringWallet returns a wallet given a base58-encoded extended key
func (*HDWallet) Child ¶
Child returns the ith child of wallet w. Values of i >= 2^31 signify private key derivation. Attempting private key derivation with a public key will throw an error.
func (*HDWallet) Pub ¶
Pub returns a new wallet which is the public key version of w. If w is a public key, Pub returns a copy of w