address

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: ISC Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChecksumMismatch describes an error where decoding failed due
	// to a bad checksum.
	ErrChecksumMismatch = errors.New("checksum mismatch")

	// ErrUnknownAddressType describes an error where an address can not
	// decoded as a specific address type due to the string encoding
	// beginning with an identifier byte unknown to any standard or
	// registered (via chaincfg.Register) network.
	ErrUnknownAddressType = errors.New("unknown address type")

	// ErrAddressCollision describes an error where an address can not
	// be uniquely determined as either a pay-to-pubkey-hash or
	// pay-to-script-hash address since the leading identifier is used for
	// describing both address kinds, but for different networks.  Rather
	// than assuming or defaulting to one or the other, this error is
	// returned and the caller must decide how to decode the address.
	ErrAddressCollision = errors.New("address collision")

	// ErrMissingDefaultNet describes an error in DecodeAddress that
	// attempts to decode an address without defining which network to decode
	// for.
	ErrMissingDefaultNet = errors.New("default net not defined")
)
View Source
var ErrInvalidPubKeyFormat = errors.New("invalid pubkey format")

ErrInvalidPubKeyFormat indicates that a serialized pubkey is unusable as it is neither in the uncompressed or compressed format.

Functions

func DecodeAddress

func DecodeAddress(addr string) (types.Address, error)

DecodeAddress decodes the string encoding of an address and returns the Address if addr is a valid encoding for a known address type

func IsForNetwork

func IsForNetwork(addr types.Address, p *params.Params) bool

IsForNetwork returns whether or not the address is associated with the passed network. TODO, other addr type and ec type check

func NewPubKeyAddress

func NewPubKeyAddress(decoded []byte, net *params.Params) (types.Address, error)

NewAddressPubKey returns a new Address. decoded must be 33 bytes.

Types

type ContractAddress

type ContractAddress struct {
	// contains filtered or unexported fields
}

type EdwardsPubKeyAddress

type EdwardsPubKeyAddress struct {
	// contains filtered or unexported fields
}

EdwardsPubKeyAddress is an Address for an Ed25519 pay-to-pubkey transaction.

func NewEdwardsPubKeyAddress

func NewEdwardsPubKeyAddress(serializedPubKey []byte,
	net *params.Params) (*EdwardsPubKeyAddress, error)

NewAddressEdwardsPubKey returns a new AddressEdwardsPubKey which represents a pay-to-pubkey address, using an Ed25519 pubkey. The serializedPubKey parameter must be a valid 32 byte serialized public key.

func (*EdwardsPubKeyAddress) EcType

func (a *EdwardsPubKeyAddress) EcType() ecc.EcType

func (*EdwardsPubKeyAddress) Encode

func (a *EdwardsPubKeyAddress) Encode() string

func (*EdwardsPubKeyAddress) Hash160

func (a *EdwardsPubKeyAddress) Hash160() *[ripemd160.Size]byte

Hash160 returns the underlying array of the pubkey hash. This can be useful when an array is more appropriate than a slice (for example, when used as map keys).

func (*EdwardsPubKeyAddress) PKHAddress

func (a *EdwardsPubKeyAddress) PKHAddress() *PubKeyHashAddress

func (*EdwardsPubKeyAddress) Script

func (a *EdwardsPubKeyAddress) Script() []byte

Script returns the bytes to be included in a txout script to pay to a public key. Setting the public key format will affect the output of this function accordingly. Part of the Address interface.

func (*EdwardsPubKeyAddress) String

func (a *EdwardsPubKeyAddress) String() string

String returns the hex-encoded human-readable string for the pay-to-pubkey address. This is not the same as calling EncodeAddress.

type PubKeyAddress

type PubKeyAddress struct {
	// contains filtered or unexported fields
}

type PubKeyFormat

type PubKeyFormat int

PubKeyFormat describes what format to use for a pay-to-pubkey address.

const (
	// PKFUncompressed indicates the pay-to-pubkey address format is an
	// uncompressed public key.
	PKFUncompressed PubKeyFormat = iota

	// PKFCompressed indicates the pay-to-pubkey address format is a
	// compressed public key.
	PKFCompressed
)

type PubKeyHashAddress

type PubKeyHashAddress struct {
	// contains filtered or unexported fields
}

PubKeyHashAddress is an Address for a pay-to-pubkey-hash (P2PKH) transaction.

func NewPubKeyHashAddress

func NewPubKeyHashAddress(pkHash []byte, net *params.Params, algo ecc.EcType) (*PubKeyHashAddress, error)

NewAddressPubKeyHash returns a new AddressPubKeyHash. pkHash must be 20 bytes.

func NewPubKeyHashAddressByNetId

func NewPubKeyHashAddressByNetId(pkHash []byte, netID [2]byte) (*PubKeyHashAddress,
	error)

NewPubKeyHashAddressByNetId returns a new PubKeyHashAddress from net id directly instead from params

func (*PubKeyHashAddress) EcType

func (a *PubKeyHashAddress) EcType() ecc.EcType

EcType returns the digital signature algorithm for the associated public key hash.

func (*PubKeyHashAddress) Encode

func (a *PubKeyHashAddress) Encode() string

func (*PubKeyHashAddress) Hash160

func (a *PubKeyHashAddress) Hash160() *[ripemd160.Size]byte

func (*PubKeyHashAddress) Script

func (a *PubKeyHashAddress) Script() []byte

Script returns the bytes to be included in a txout script to pay to a pubkey hash. Part of the Address interface.

func (*PubKeyHashAddress) String

func (a *PubKeyHashAddress) String() string

String returns a human-readable string for the pay-to-pubkey-hash address. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.

type ScriptHashAddress

type ScriptHashAddress struct {
	// contains filtered or unexported fields
}

ScriptHashAddress is an Address for a pay-to-script-hash (P2SH) transaction.

func NewScriptHashAddress

func NewScriptHashAddress(serializedScript []byte, net *params.Params) (*ScriptHashAddress, error)

NewAddressScriptHash returns a new AddressScriptHash.

func NewScriptHashAddressFromHash

func NewScriptHashAddressFromHash(scriptHash []byte, net *params.Params) (*ScriptHashAddress, error)

NewAddressScriptHashFromHash returns a new AddressScriptHash. scriptHash must be 20 bytes.

func (*ScriptHashAddress) EcType

func (a *ScriptHashAddress) EcType() ecc.EcType

func (*ScriptHashAddress) Encode

func (a *ScriptHashAddress) Encode() string

EncodeAddress returns the string encoding of a pay-to-script-hash address. Part of the Address interface.

func (*ScriptHashAddress) Hash160

func (a *ScriptHashAddress) Hash160() *[ripemd160.Size]byte

Hash160 returns the underlying array of the script hash. This can be useful when an array is more appropriate than a slice (for example, when used as map keys).

func (*ScriptHashAddress) Script

func (a *ScriptHashAddress) Script() []byte

Script returns the bytes to be included in a txout script to pay to a script hash. Part of the Address interface.

func (*ScriptHashAddress) String

func (a *ScriptHashAddress) String() string

type SecSchnorrPubKeyAddress

type SecSchnorrPubKeyAddress struct {
	// contains filtered or unexported fields
}

SecSchnorrPubKeyAddress is an Address for a secp256k1-schnorr pay-to-pubkey transaction.

func NewSecSchnorrPubKeyAddress

func NewSecSchnorrPubKeyAddress(serializedPubKey []byte,
	net *params.Params) (*SecSchnorrPubKeyAddress, error)

NewAddressSecSchnorrPubKey returns a new AddressSecpPubKey which represents a pay-to-pubkey address, using a secp256k1 pubkey. The serializedPubKey parameter must be a valid pubkey and must be compressed.

func (*SecSchnorrPubKeyAddress) EcType

func (a *SecSchnorrPubKeyAddress) EcType() ecc.EcType

func (*SecSchnorrPubKeyAddress) Encode

func (a *SecSchnorrPubKeyAddress) Encode() string

func (*SecSchnorrPubKeyAddress) Hash160

func (a *SecSchnorrPubKeyAddress) Hash160() *[ripemd160.Size]byte

Hash160 returns the underlying array of the pubkey hash. This can be useful when an array is more appropriate than a slice (for example, when used as map keys).

func (*SecSchnorrPubKeyAddress) PKHAddress

func (a *SecSchnorrPubKeyAddress) PKHAddress() *PubKeyHashAddress

func (*SecSchnorrPubKeyAddress) Script

func (a *SecSchnorrPubKeyAddress) Script() []byte

Script returns the bytes to be included in a txout script to pay to a public key. Setting the public key format will affect the output of this function accordingly. Part of the Address interface.

func (*SecSchnorrPubKeyAddress) String

func (a *SecSchnorrPubKeyAddress) String() string

String returns the hex-encoded human-readable string for the pay-to-pubkey address. This is not the same as calling EncodeAddress.

type SecpPubKeyAddress

type SecpPubKeyAddress struct {
	// contains filtered or unexported fields
}

SecpPubKeyAddress is an Address for a secp256k1 pay-to-pubkey transaction.

func NewSecpPubKeyAddress

func NewSecpPubKeyAddress(serializedPubKey []byte,
	net *params.Params) (*SecpPubKeyAddress, error)

NewAddressSecpPubKey returns a new AddressSecpPubKey which represents a pay-to-pubkey address, using a secp256k1 pubkey. The serializedPubKey parameter must be a valid pubkey and must be uncompressed or compressed.

func NewSecpPubKeyCompressedAddress

func NewSecpPubKeyCompressedAddress(pubkey ecc.PublicKey, params *params.Params) (*SecpPubKeyAddress, error)

NewSecpPubKeyCompressedAddress creates a new address using a compressed public key

func (*SecpPubKeyAddress) EcType

func (a *SecpPubKeyAddress) EcType() ecc.EcType

func (*SecpPubKeyAddress) Encode

func (a *SecpPubKeyAddress) Encode() string

EncodeAddress returns the string encoding of the public key as a pay-to-pubkey-hash. Note that the public key format (uncompressed, compressed, etc) will change the resulting address. This is expected since pay-to-pubkey-hash is a hash of the serialized public key which obviously differs with the format. Part of the Address interface.

func (*SecpPubKeyAddress) Hash160

func (a *SecpPubKeyAddress) Hash160() *[ripemd160.Size]byte

Hash160 returns the underlying array of the pubkey hash. This can be useful when an array is more appropriate than a slice (for example, when used as map keys).

func (*SecpPubKeyAddress) PKHAddress

func (a *SecpPubKeyAddress) PKHAddress() *PubKeyHashAddress

PKHAddress returns the pay-to-pubkey address converted to a pay-to-pubkey-hash address. Note that the public key format (uncompressed, compressed, etc) will change the resulting address. This is expected since pay-to-pubkey-hash is a hash of the serialized public key which obviously differs with the format.

func (*SecpPubKeyAddress) PubKey

func (a *SecpPubKeyAddress) PubKey() ecc.PublicKey

PubKey returns the underlying public key for the address.

func (*SecpPubKeyAddress) Script

func (a *SecpPubKeyAddress) Script() []byte

Script returns the bytes to be included in a txout script to pay to a public key. Setting the public key format will affect the output of this function accordingly. Part of the Address interface.

func (*SecpPubKeyAddress) String

func (a *SecpPubKeyAddress) String() string

String returns the hex-encoded human-readable string for the pay-to-pubkey address. This is not the same as calling EncodeAddress.

Jump to

Keyboard shortcuts

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