Documentation ¶
Index ¶
- Constants
- Variables
- func Bech32Bit5(data []byte) []byte
- func Bech32CRC(hrp string, data []byte) (crc []byte)
- func CheckVersion(version uint32) (int, uint32)
- func EntropyToWords(ent []byte) (words []string, err error)
- func GetAddrMode(label string) int
- func GetCoinInfo(symb string) (int, string)
- func GetXDVersion(coin, mode, network int, pub bool) uint32
- func MakeAddress(key *bitcoin.PublicKey, coin, version, network int) (string, error)
- func MakeAddressScript(scr *script.Script, coin, version, network int) (string, error)
- func WordsToEntropy(words []string) ([]byte, string)
- func WordsToSeed(words []string, password string) ([]byte, string)
- type AddrFormat
- type AddrSpec
- type AddrVersion
- type Addresser
- type CoinSpec
- type ExtendedData
- type ExtendedPrivateKey
- type ExtendedPublicKey
- type HD
- type HDPublic
Constants ¶
const ( // Mainnet/Testnet/Regnet NetwMain = 0 NetwTest = 1 NetwReg = 2 // Address usage AddrP2PKH = 0 AddrP2SH = 1 AddrP2WPKH = 2 AddrP2WSH = 3 AddrP2WPKHinP2SH = 4 AddrP2WSHinP2SH = 5 )
Address constants
Variables ¶
var ( ErrMkAddrPrefix = errors.New("unknown prefix") ErrMkAddrVersion = errors.New("unknown version") ErrMkAddrNotImplemented = errors.New("not implemented") )
Errors
var ( ErrHDVersion = errors.New("version mismatch") ErrHDPath = errors.New("invalid HD path") ErrHDKey = errors.New("invalid HD key") )
Error codes
var ( // AddrList for selected coins // (see page source for "https://iancoleman.io/bip39/") AddrList = []*AddrSpec{ {0, []*AddrFormat{ {"bc", 0x80, []*AddrVersion{ {0x00, 0x0488b21e, 0x0488ade4}, {0x05, 0x049d7cb2, 0x049d7878}, {0x00, 0x04b24746, 0x04b2430c}, {0x05, 0x02aa7ed3, 0x02aa7a99}, {0x05, 0x049d7cb2, 0x049d7878}, {0x05, 0x0295b43f, 0x0295b005}, }}, {"tb", 0xef, []*AddrVersion{ {0x6f, 0x043587cf, 0x04358394}, {0xc4, 0x043587cf, 0x04358394}, {0x6f, 0x045f1cf6, 0x045f18bc}, {0xc4, 0x02575483, 0x02575048}, {0xc4, 0x044a5262, 0x044a4e28}, {0xc4, 0x024289ef, 0x024285b5}, }}, {"bcrt", 0xef, []*AddrVersion{ {0x6f, 0x043587cf, 0x04358394}, {0xc4, 0x043587cf, 0x04358394}, {0x6f, 0x045f1cf6, 0x045f18bc}, {0xc4, 0x02575483, 0x02575048}, {0xc4, 0x044a5262, 0x044a4e28}, {0xc4, 0x024289ef, 0x024285b5}, }}, }, nil}, {2, []*AddrFormat{ {"ltc", 0xb0, []*AddrVersion{ {0x30, 0x0488b21e, 0x0488ade4}, {0x32, 0x0488b21e, 0x0488ade4}, {0x30, 0x04b24746, 0x04b2430c}, {0x32, 0x04b24746, 0x04b2430c}, {0x32, 0x01b26ef6, 0x01b26792}, {0x32, 0x01b26ef6, 0x01b26792}, }}, {"litecointestnet", 0xef, []*AddrVersion{ {0x6f, 0x043587cf, 0x04358394}, {0xc4, 0x043587cf, 0x04358394}, {0x6f, 0x043587cf, 0x04358394}, {0xc4, 0x043587cf, 0x04358394}, {0x6f, 0x043587cf, 0x04358394}, {0x6f, 0x043587cf, 0x04358394}, }}, nil, }, nil}, {3, []*AddrFormat{ {"", 0x9e, []*AddrVersion{ {0x1e, 0x02facafd, 0x02fac398}, {0x16, 0x02facafd, 0x02fac398}, nil, nil, {0x16, 0x02facafd, 0x02fac398}, nil, }}, {"dogecointestnet", 0xf1, []*AddrVersion{ {0x71, 0x043587cf, 0x04358394}, {0xc4, 0x043587cf, 0x04358394}, nil, nil, {0xc4, 0x043587cf, 0x04358394}, nil, }}, nil, }, nil}, {5, []*AddrFormat{ {"", 0xcc, []*AddrVersion{ {0x4c, 0x02fe52cc, 0x0488ade4}, {0x10, 0x02fe52cc, 0x0488ade4}, nil, nil, {0x10, 0x02fe52cc, 0x0488ade4}, nil, }}, {"", 0xef, []*AddrVersion{ {0x8c, 0x043587cf, 0x04358394}, {0x13, 0x043587cf, 0x04358394}, nil, nil, {0x13, 0x043587cf, 0x04358394}, nil, }}, nil, }, nil}, {7, []*AddrFormat{ {"", 0xb4, []*AddrVersion{ {0x34, 0x0488b21e, 0x0488ade4}, {0x0d, 0x0488b21e, 0x0488ade4}, nil, nil, {0x0d, 0x0488b21e, 0x0488ade4}, nil, }}, nil, nil, }, nil}, {20, []*AddrFormat{ {"dgb", 0x80, []*AddrVersion{ {0x1e, 0x0488b21e, 0x0488ade4}, {0x3f, 0x049d7cb2, 0x049d7878}, {0x1e, 0x04b24746, 0x049d7878}, nil, {0x3f, 0x049d7cb2, 0x049d7878}, nil, }}, nil, nil, }, nil}, {28, []*AddrFormat{ {"vtc", 0x80, []*AddrVersion{ {0x47, 0x0488b21e, 0x0488ade4}, {0x05, 0x049d7cb2, 0x049d7878}, {0x47, 0x0488b21e, 0x0488ade4}, nil, {0x05, 0x0488b21e, 0x0488ade4}, nil, }}, nil, nil, }, nil}, {60, []*AddrFormat{ nil, nil, nil, }, makeAddressETH}, {61, []*AddrFormat{ nil, nil, nil, }, makeAddressETH}, {133, []*AddrFormat{ {"", 0x80, []*AddrVersion{ {0x1cb8, 0x0488b21e, 0x0488ade4}, {0x1cbd, 0x0488b21e, 0x0488ade4}, nil, nil, {0x1cbd, 0x0488b21e, 0x0488ade4}, nil, }}, nil, nil, }, nil}, {145, []*AddrFormat{ {"", 0x80, []*AddrVersion{ {0x00, 0x0488b21e, 0x0488ade4}, {0x05, 0x0488b21e, 0x0488ade4}, {0x00, 0x04b24746, 0x04b2430c}, {0x05, 0x02aa7ed3, 0x02aa7a99}, {0x05, 0x049d7cb2, 0x049d7878}, {0x05, 0x0295b43f, 0x0295b005}, }}, {"", 0xef, []*AddrVersion{ {0x6f, 0x0488b21e, 0x0488ade4}, {0xc4, 0x0488b21e, 0x0488ade4}, {0x6f, 0x045f1cf6, 0x045f18bc}, {0xc4, 0x02575483, 0x02575048}, {0xc4, 0x044a5262, 0x044a4e28}, {0xc4, 0x024289ef, 0x024285b5}, }}, {"", 0xef, []*AddrVersion{ {0x6f, 0x043587cf, 0x04358394}, {0xc4, 0x043587cf, 0x04358394}, {0x6f, 0x045f1cf6, 0x045f18bc}, {0xc4, 0x02575483, 0x02575048}, {0xc4, 0x044a5262, 0x044a4e28}, {0xc4, 0x024289ef, 0x024285b5}, }}, }, makeAddressBCH}, {156, []*AddrFormat{ {"btg", 0x80, []*AddrVersion{ {0x26, 0x0488b21e, 0x0488ade4}, {0x17, 0x049d7cb2, 0x049d7878}, {0x26, 0x04b24746, 0x04b2430c}, nil, {0x17, 0x049d7cb2, 0x049d7878}, nil, }}, nil, nil, }, nil}, } )
var ( // CoinList of all all available BIP44 coin types CoinList = []*CoinSpec{}/* 815 elements not displayed */ )
var (
ErrInvalidEntropy = fmt.Errorf("invalid entropy data")
)
Error codes
Functions ¶
func Bech32Bit5 ¶ added in v1.2.25
Bech32Bit5 splits a byte array into 5-bit chunks
func CheckVersion ¶ added in v1.2.5
CheckVersion returns a status code and the "inverse" version (pub<->prv):
-1 if extended data refers to a public key 1 if extended data refers to a private key 0 if version is unknown
func EntropyToWords ¶
EntropyToWords converts an entropy into a sequence of words
func GetAddrMode ¶ added in v1.2.25
GetAddrMode returns the numeric value for mode (P2PKH, P2SH, ...)
func GetCoinInfo ¶ added in v1.2.7
GetCoinInfo returns information about a given coin by symbol.
func GetXDVersion ¶ added in v1.2.7
GetXDVersion returns the extended data version for a given coin mode
func MakeAddress ¶ added in v1.2.6
MakeAddress computes an address from a public key for given coin, version and network. All cryptocoins based on the Bitcoin curve (secp256k1) are supported.
func MakeAddressScript ¶ added in v1.2.25
MakeAddressScript creates an address for a P2SH script
func WordsToEntropy ¶
WordsToEntropy converts a sequence of words into an entropy. Returns the entropy OR the words where the conversion failed. If the number of words are incorrect, "#" is returned.
Types ¶
type AddrFormat ¶ added in v1.2.6
type AddrFormat struct { Bech32 string WifVersion byte Versions []*AddrVersion }
AddrFormat defines formatting information for addresses
type AddrSpec ¶ added in v1.2.6
type AddrSpec struct { CoinID int Formats []*AddrFormat Conv Addresser }
AddrSpec defines a coin address format.x
type AddrVersion ¶ added in v1.2.6
type AddrVersion struct { Version uint16 // version byte (address prefix) PubVersion uint32 // BIP32 key version (public) PrvVersion uint32 // BIP32 key version (private) }
AddrVersion defines address version constants
type CoinSpec ¶
CoinSpec defines a BIP44 registered coin. See: https://github.com/satoshilabs/slips/blob/master/slip-0044.md https://github.com/libbitcoin/libbitcoin-system/wiki/Altcoin-Version-Mappings
type ExtendedData ¶
type ExtendedData struct { Version uint32 `order:"big"` Depth uint8 ParentFP uint32 `order:"big"` Child uint32 `order:"big"` Chaincode []byte `size:"32"` Keydata []byte `size:"33"` }
ExtendedData is the data structure representing ExtendedKeys (both public and private) for exchange purposes.
func NewExtendedData ¶
func NewExtendedData() *ExtendedData
NewExtendedData allocates a new extended data object
func ParseExtended ¶
func ParseExtended(s string) (*ExtendedData, error)
ParseExtended returns a new data object for a given extended key string
func (*ExtendedData) String ¶
func (d *ExtendedData) String() string
String converts an extended data object into a human-readable representation.
type ExtendedPrivateKey ¶
type ExtendedPrivateKey struct { Data *ExtendedData Key *math.Int }
ExtendedPrivateKey represents a private key in a HD tree
func CKDprv ¶
func CKDprv(k *ExtendedPrivateKey, i uint32) (ki *ExtendedPrivateKey)
CKDprv is a key derivation function for private keys
func ParseExtendedPrivateKey ¶
func ParseExtendedPrivateKey(s string) (k *ExtendedPrivateKey, err error)
ParseExtendedPrivateKey converts a "?prv" string to a private key
func (*ExtendedPrivateKey) Public ¶
func (k *ExtendedPrivateKey) Public() *ExtendedPublicKey
Public returns the associated public key
func (*ExtendedPrivateKey) String ¶
func (k *ExtendedPrivateKey) String() string
String returns the string representation of an ExtendedPrivateKey
type ExtendedPublicKey ¶
type ExtendedPublicKey struct { Data *ExtendedData Key *bitcoin.Point }
ExtendedPublicKey represents a public key in a HD tree
func CKDpub ¶
func CKDpub(k *ExtendedPublicKey, i uint32) (ki *ExtendedPublicKey)
CKDpub is a key derivation function for public keys
func ParseExtendedPublicKey ¶
func ParseExtendedPublicKey(s string) (k *ExtendedPublicKey, err error)
ParseExtendedPublicKey converts a "?pub" string to a public key
func (*ExtendedPublicKey) Clone ¶
func (e *ExtendedPublicKey) Clone() *ExtendedPublicKey
Clone returns a deep copy of a public key
func (*ExtendedPublicKey) Fingerprint ¶
func (e *ExtendedPublicKey) Fingerprint() (i uint32)
Fingerprint returns the fingerprint of an ExtendedPublicKey
func (*ExtendedPublicKey) String ¶
func (e *ExtendedPublicKey) String() string
String returns the string representation of an ExtendedPublicKey
type HD ¶
type HD struct {
// contains filtered or unexported fields
}
HD represents a hierarchically deterministic key space.
func (*HD) MasterPrivate ¶ added in v1.2.5
func (hd *HD) MasterPrivate() *ExtendedPrivateKey
MasterPrivate returns the master private key.
func (*HD) MasterPublic ¶ added in v1.2.5
func (hd *HD) MasterPublic() *ExtendedPublicKey
MasterPublic returns the master public key.
type HDPublic ¶
type HDPublic struct {
// contains filtered or unexported fields
}
HDPublic represents a public branch in a hierarchically deterministic key space.
func NewHDPublic ¶
func NewHDPublic(key *ExtendedPublicKey, path string) *HDPublic
NewHDPublic initializes a new HDPublic from an extended public key with a given path.