wallet

package
v1.2.28 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

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

View Source
var (
	ErrMkAddrPrefix         = errors.New("unknown address prefix")
	ErrMkAddrVersion        = errors.New("unknown address version")
	ErrMkAddrNotImplemented = errors.New("address not implemented")
)

Errors

View Source
var (
	ErrHDVersion = errors.New("version mismatch")
	ErrHDPath    = errors.New("invalid HD path")
	ErrHDKey     = errors.New("invalid HD key")
)

Error codes

View Source
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},
	}
)
View Source
var (
	// CoinList of all all available BIP44 coin types
	CoinList = []*CoinSpec{}/* 815 elements not displayed */

)
View Source
var (
	ErrInvalidEntropy = fmt.Errorf("invalid entropy data")
)

Error codes

Functions

func Bech32Bit5 added in v1.2.25

func Bech32Bit5(data []byte) []byte

Bech32Bit5 splits a byte array into 5-bit chunks

func Bech32CRC added in v1.2.25

func Bech32CRC(hrp string, data []byte) (crc []byte)

func CheckVersion added in v1.2.5

func CheckVersion(version uint32) (int, uint32)

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

func EntropyToWords(ent []byte) (words []string, err error)

EntropyToWords converts an entropy into a sequence of words

func GetAddrMode added in v1.2.25

func GetAddrMode(label string) int

GetAddrMode returns the numeric value for mode (P2PKH, P2SH, ...)

func GetCoinInfo added in v1.2.7

func GetCoinInfo(symb string) (int, string)

GetCoinInfo returns information about a given coin by symbol.

func GetXDVersion added in v1.2.7

func GetXDVersion(coin, mode, network int, pub bool) uint32

GetXDVersion returns the extended data version for a given coin mode

func MakeAddress added in v1.2.6

func MakeAddress(obj any, coin, version, network int) (string, error)

MakeAddress generates a new address based on the object it is based on. The object can be a public key for given coin, version and network or a Bitcoin script (classic). All cryptocoins based on the Bitcoin curve (secp256k1) are supported.

func WordsToEntropy

func WordsToEntropy(words []string) ([]byte, string)

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.

func WordsToSeed

func WordsToSeed(words []string, password string) ([]byte, string)

WordsToSeed computes a seed value for a given word list

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 Addresser added in v1.2.7

type Addresser func(pk *bitcoin.PublicKey, coin, version, network, prefix int) (string, error)

Addresser is a function prototype for address conversion functions

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

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

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 NewHD

func NewHD(seed []byte) (*HD, error)

NewHD initializes a new HD from a seed value.

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.

func (*HD) Private

func (hd *HD) Private(path string) (prv *ExtendedPrivateKey, err error)

Private returns an extended private key for a given path (BIP32,BIP44)

func (*HD) Public

func (hd *HD) Public(path string) (pub *ExtendedPublicKey, err error)

Public returns an extended public key for a given path (BIP32,BIP44)

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.

func (*HDPublic) Public

func (hd *HDPublic) Public(path string) (pub *ExtendedPublicKey, err error)

Public returns an extended public key for a given path. The path MUST NOT contain hardened elements and must start with the path of the public key in HDPublic!

type Serializable added in v1.2.27

type Serializable interface {
	Bytes() []byte
}

Jump to

Keyboard shortcuts

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