wallet

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Mainnet/Testnet/Regnet
	AddrMain = 0
	AddrTest = 1
	AddrReg  = 2

	// Address usage
	AddrP2PKH        = 0
	AddrP2SH         = 1
	AddrP2WPKH       = 2
	AddrP2WSH        = 3
	AddrP2WPKHinP2SH = 4
	AddrP2WSHinP2SH  = 5
)

Address constants

View Source
const (
	// Generic versions (P2PKH)
	XpubVersion = 0x0488b21e
	XprvVersion = 0x0488ade4

	// Testnet versions
	UpubVersion = 0x043587cf
	UprvVersion = 0x04358394

	// Generic versions (P2SH)
	YpubVersion = 0x049d7cb2
	YprvVersion = 0x049d7878

	// Dash
	DrkpVersion = 0x02fe52cc

	// Dogecoin
	DgubVersion = 0x02facafd
	DgpvVersion = 0x02fac398

	// Litecoin
	MtubVersion = 0x01b26ef6
	MtpvVersion = 0x01b26792
)

extended data version codes

Variables

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, 0x01b26ef6, 0x01b26792},
				{0x30, 0x04b24746, 0x04b2430c},
				nil,
				{0x32, 0x01b26ef6, 0x01b26792},
				nil,
			}},

			{"litecointestnet", 0xef, []*AddrVersion{
				{0x6f, 0x043587cf, 0x04358394},
				{0xc4, 0x043587cf, 0x04358394},
				{0x6f, 0x043587cf, 0x04358394},
				nil,
				{0xc4, 0x043587cf, 0x04358394},
				nil,
			}},

			nil,
		}, nil},

		{3, []*AddrFormat{

			{"", 0x9e, []*AddrVersion{
				{0x1e, 0x02facafd, 0x02fac398},
				{0x16, 0x02facafd, 0x02fac398},
				nil,
				nil,
				nil,
				nil,
			}},

			{"dogecointestnet", 0xf1, []*AddrVersion{
				{0x71, 0x043587cf, 0x04358394},
				{0xc4, 0x043587cf, 0x04358394},
				{0x71, 0x043587cf, 0x04358394},
				nil,
				{0xc4, 0x043587cf, 0x04358394},
				nil,
			}},

			nil,
		}, nil},

		{5, []*AddrFormat{

			{"", 0xcc, []*AddrVersion{
				{0x4c, 0x02fe52cc, 0x0488ade4},
				{0x10, 0x02fe52cc, 0x0488ade4},
				nil,
				nil,
				nil,
				nil,
			}},

			{"", 0xef, []*AddrVersion{
				{0x8c, 0x043587cf, 0x04358394},
				{0x13, 0x043587cf, 0x04358394},
				nil,
				nil,
				nil,
				nil,
			}},

			nil,
		}, nil},

		{7, []*AddrFormat{

			{"", 0xb4, []*AddrVersion{
				{0x34, 0x0488b21e, 0x0488ade4},
				{0x0d, 0x0488b21e, 0x0488ade4},
				nil,
				nil,
				nil,
				nil,
			}},

			nil,

			nil,
		}, nil},

		{20, []*AddrFormat{

			{"dgb", 0x80, []*AddrVersion{
				{0x1e, 0x0488b21e, 0x0488ade4},
				{0x3f, 0x049d7cb2, 0x049d7878},
				{0x1e, 0x04b24746, 0x04b2430c},
				nil,
				{0x3f, 0x049d7cb2, 0x049d7878},
				nil,
			}},

			nil,

			nil,
		}, nil},

		{28, []*AddrFormat{

			{"", 0x80, []*AddrVersion{
				{0x47, 0x0488b21e, 0x0488ade4},
				{0x05, 0x049d7cb2, 0x049d7878},
				{0x47, 0x0488b21e, 0x0488ade4},
				nil,
				{0x47, 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,
				nil,
				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 CheckVersion added in v1.2.5

func CheckVersion(version uint32) int

CheckVersion returns a status code:

-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 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(key *bitcoin.PublicKey, coin, version, network int) string

MakeAddress computes an address from public key for the "real" Bitcoin network

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.

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

Addresser is a function prototype for address conversion functions

type CoinSpec

type CoinSpec struct {
	ID     int
	Symbol string
	Name   string
}

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 xprv 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 xpub 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

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!

Jump to

Keyboard shortcuts

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