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
- func GenSeed(length int) ([]byte, error)
- type HDWallet
- type WalletGenPrefixes
- type WalletGenerator
- func (w *WalletGenerator) ByteCheck(dbin []byte) error
- func (w *WalletGenerator) MasterKey(seed []byte) (*HDWallet, error)
- func (w *WalletGenerator) StringAddress(data string) (string, error)
- func (w *WalletGenerator) StringCheck(key string) error
- func (w *WalletGenerator) StringChild(data string, i uint32) (string, error)
- func (w *WalletGenerator) StringWallet(data string) (*HDWallet, error)
Constants ¶
const ( // main net BtcPublicPrefix = "0488B21E" //same for Bch BtcPrivatePrefix = "0488ADE4" //same for Bch BtcPubkeyHash = "00" // test net TestBtcPublicPrefix = "043587CF" TestBtcPrivatePrefix = "04358394" TestBtcPubkeyHash = "6F" // main net LtcPublicPrefix = "019DA462" LtcPrivatePrefix = "019D9CFE" LtcPubkeyHash = "30" // test net TestLtcPublicPrefix = "0436F6E1" TestLtcPrivatePrefix = "0436EF7D" TestLtcPubkeyHash = "6F" DefaultBtcKey = "Bitcoin seed" DefaultLtcKey = "Litecoin seed" )
Variables ¶
This section is empty.
Functions ¶
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 // contains filtered or unexported fields }
HDWallet defines the components of a hierarchical deterministic wallet
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
type WalletGenPrefixes ¶
type WalletGenerator ¶
type WalletGenerator struct {
// contains filtered or unexported fields
}
func NewDefaultBchWalletGenerator ¶
func NewDefaultBchWalletGenerator(test bool) (*WalletGenerator, error)
func NewDefaultBtcWalletGenerator ¶
func NewDefaultBtcWalletGenerator(test bool) (*WalletGenerator, error)
func NewDefaultLtcWalletGenerator ¶
func NewDefaultLtcWalletGenerator(test bool) (*WalletGenerator, error)
func NewWalletGenerator ¶
func NewWalletGenerator(prefixes WalletGenPrefixes) (*WalletGenerator, error)
func (*WalletGenerator) ByteCheck ¶
func (w *WalletGenerator) ByteCheck(dbin []byte) error
func (*WalletGenerator) MasterKey ¶
func (w *WalletGenerator) MasterKey(seed []byte) (*HDWallet, error)
MasterKey returns a new wallet given a random seed.
func (*WalletGenerator) StringAddress ¶
func (w *WalletGenerator) StringAddress(data string) (string, error)
StringAddress returns the Bitcoin address of a base58-encoded extended key.
func (*WalletGenerator) StringCheck ¶
func (w *WalletGenerator) StringCheck(key string) error
StringCheck is a validation check of a base58-encoded extended key.
func (*WalletGenerator) StringChild ¶
func (w *WalletGenerator) StringChild(data string, i uint32) (string, error)
StringChild returns the ith base58-encoded extended key of a base58-encoded extended key.
func (*WalletGenerator) StringWallet ¶
func (w *WalletGenerator) StringWallet(data string) (*HDWallet, error)
StringWallet returns a wallet given a base58-encoded extended key