stdaddr

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: ISC Imports: 11 Imported by: 86

README

stdaddr

Build Status ISC License Doc

Decred Address Overview

An address is a human-readable representation of a possible destination for a payment. More specifically, it encodes information needed to create a smart contract via a transaction script that imposes constraints required to redeem funds.

Under the hood, an address typically consists of 4 primary components:

  • The network for which the address is valid
  • The data necessary to create a payment script with the appropriate constraints
  • The scripting language version of the aforementioned script
  • A checksum to prevent errors due to improper entry

It is also worth keeping in mind that the scripting language version may be implicit depending on the specific concrete encoding of the address.

Supported Version 0 Addresses

The following table lists the version 0 address types this package supports along with whether the type is supported by the staking system, whether it has a raw public key that can be obtained, whether it has an associated hash160, and some additional notes and recommendations:

Version 0 Address Type Staking? PubKey? Hash160? Notes / Recommendations
p2pk-ecdsa-secp256k1 N Y N Prefer p2pkh in on-chain txns [1]
p2pk-ed25519 N Y N Not recommended [2]
p2pk-schnorr-secp256k1 N Y N Prefer p2pkh, single party [1,3]
p2pkh-ecdsa-secp256k1 Y N Y Preferred v0 address
p2pkh-ed25519 N N Y Not recommended [2]
p2pkh-schnorr-secp256k1 N N Y Only use with single party [3]
p2sh Y N Y -

Abbreviations:

  • p2pk = Pay-to-public-key
  • p2pkh = Pay-to-public-key-hash
  • p2sh = Pay-to-script-hash

Notes:

  • [1] Pay to public key addresses are only recommended for use in sharing public keys via off-chain protocols such as multi-party signature creation. Pay to public key hash addresses should be used for on-chain transactions to avoid revealing the public key until the funds are redeemed.
  • [2] Version 0 addresses involving Ed25519 are not recommended due to lack of support for safe hierarchical derivation and the requirement for a legacy implementation of the curve that has known issues.
  • [3] Version 0 addresses involving Schnorr signatures are only recommended for use with single parties as extra care must be taken when used with multiple parties to avoid potential theft of funds by malicious counterparties.

Note about Standardness vs Consensus

This package is named stdaddr to clearly convey that addresses are a standardized construction built on top of the underlying scripting system that is enforced by the consensus rules. The specific scripts that the addresses represent are referred to as standard scripts since they are recognized forms that most software considers standard by policy. However, the consensus rules for regular transactions must support so called non-standard scripts as well (any script that is not one of the recognized forms).

This distinction between standardness and consensus is extremely important for developers working on the consensus rules, since consensus must NOT use addresses directly and instead must work with the actual underlying scripts. An address is a human-readable representation of an underlying script along with additional metadata to help prevent misuse and typographical errors. The underlying scripts are enforced by consensus, not the other way around!

Package Usage Primer

The overall design of this package is based on a few key interfaces to provide a generalized capabilities-based approach to working with the various types of addresses along with unique types for each supported address type that implement said interfaces.

Interacting with addresses typically falls into the following categories:

  • Instantiating addresses
    • Decoding existing addresses
    • Creating addresses of the types which correspond to desired encumbrances
  • Generating the payment script and associated version for use in regular transaction outputs
  • Determining additional capabilities of an address by type asserting supported interfaces
Address Versions

All software that works with sending funds to addresses must be able to produce payment scripts that correspond to the same scripting language version the original creator of the address (aka the recipient) supports as they might otherwise not be able to actually redeem the funds.

This requirement creates a one-to-one correspondence between a given address and the underlying scripting language version. Since the original base58-based address format does not encode a scripting language version and are implicitly expected to create version 0 scripts, they are referred to as version 0 addresses.

It is expected that new version addresses will be introduced in the future that change the address format to improve some of the shortcomings of base58 addresses as well as properly encode a scripting language version.

Instantiating Addresses

In order to provide a more ergonomic API depending on the specific needs of callers, this package offers two approaches to instantiating addresses:

  1. Methods that accept and instantiate addresses for any supported version. For example, DecodeAddress and NewAddressPubKeyHashEcdsaSecp256k1.
  2. Methods that accept and instantiate addresses for a specific version. For example, DecodeAddressV0 and NewAddressPubKeyHashEcdsaSecp256k1V0.

The first approach is likely suitable for most callers as it is intended to support all historical address types as well as allow easily specifying a script version from a dynamic variable. For example, applications involving historical data analytics, such as block explorers, should prefer this approach.

However, callers might wish to only support decoding and creating specific address versions in which case the second approach is more suitable. Further, when it comes to creating addresses, since not all adddress types will necessarily be supported by all scripting language versions, the second approach makes it clear from the API exactly which types of addresses are supported for a given version at compile time whereas the first approach requires the caller to check for errors at run time.

Generating Payment Scripts and Displaying a Human-Readable Address String

In order to generalize support for the various standard address types, this package provides an Address interface which is the primary interface implemented by all supported address types.

Use the PaymentScript method to obtain the scripting language version associated with the address along with a script to pay a transaction output to the address and the String method to get the human-readable string encoding of the address.

Address Use in the Staking System

A distinguishing aspect of the staking system in Decred is that it imposes additional constraints on the types of addresses that can be used versus those for regular transactions. This is because scripts in the staking system are tightly controlled by consensus to only permit very specific scripts, unlike regular transactions which allow scripts composed of any sequence of opcodes that evaluate to true.

In order to support this difference, this package provides the StakeAddress interface which is only implemented by the address types that are supported by the staking system. This allows callers to determine if an address can be used in the staking system by type asserting the interface and then making use of the relevant methods provided by the interface to interact with the staking system. Refer to the code examples to see this in action as well as the API documentation of the interface methods for further details.

Converting Public Key to Public Key Hash Addresses

It is often necessary to share public keys in interactive and manual off-chain protocols, such as multi-party signature creation. Since raw public keys are valid for any network, it is generally less error prone and more convenient to use human-readable public key addresses in this case because they ensure the correct network is involved as well as help prevent entry errors.

However, whenever dealing with on-chain transactions, public key hash addresses should typically be used instead to avoid revealing the public key until the funds are redeemed.

With the aim of supporting easy conversion of a public key address to a public key hash address for the cases when the caller already has the former available, this package provides the AddressPubKeyHasher interface which is only implemented by the public key address types. This allows callers to determine if an address can be converted to its public key hash variant by type asserting the interface and then convert it by making use of the AddressPubKeyHash method provided by the interface.

Obtaining Serialized Public Key From Public Key Addresses

When making use of public key addresses, callers often need to obtain the serialized public key associated with the address for further processing.

This package provides the SerializedPubKeyer interface, which is only implemented by the public key address types, for this purpose. Callers may determine if a serialized public key can be obtained from an address by type asserting the interface and then extract it by making use of the SerializedPubKey method provided by the interface.

However, it is also worth noting that merely obtaining the serialized public key via the generic interface is typically not sufficient on its own for a caller to be able to work with it since parsing a public key requires knowing what type of key it is as well. In that case, the caller will likely need to fall back to type asserting the specific concrete implementation to determine which type of public key it is dealing with.

Hash160 Use in Addresses

The term Hash160 is used as shorthand to refer to a hash that is created via a combination of RIPEMD-160 and BLAKE256. Specifically, it is the result of RIPEMD-160(BLAKE256(data)).

For address types that involve Hash160 hashes, such as version 0 public key hash and script hash addresses, it can be convenient for callers to extract the associated hash.

To enable the hash extraction, this package provides the Hash160er interface which is only implemented by the address types that involve Hash160. This allows callers to determine if an address involves a Hash160 by type asserting the interface and then extract it by making use of the Hash160 method provided by the interface.

Installation and Updating

This package is part of the github.com/decred/dcrd/txscript/v4 module. Use the standard go tooling for working with modules to incorporate it.

Examples

  • DecodeAddress

    Demonstrates decoding addresses, generating their payment scripts and associated scripting language versions, determining supported capabilities by checking if interfaces are implemented, obtaining the associated underlying hash160 for addresses that support it, converting public key addresses to their public key hash variant, and generating stake-related scripts for addresses that can be used in the staking system.

License

Package stdaddr is licensed under the copyfree ISC License.

Documentation

Overview

Package stdaddr provides facilities for working with human-readable Decred payment addresses.

Index

Examples

Constants

View Source
const (
	// ErrUnsupportedAddress indicates that an address successfully decoded, but
	// is not a supported/recognized type.
	ErrUnsupportedAddress = ErrorKind("ErrUnsupportedAddress")

	// ErrUnsupportedScriptVersion indicates that an address type does not
	// support a given script version.
	ErrUnsupportedScriptVersion = ErrorKind("ErrUnsupportedScriptVersion")

	// ErrMalformedAddress indicates an address failed to decode.
	ErrMalformedAddress = ErrorKind("ErrMalformedAddress")

	// ErrMalformedAddressData indicates an address successfully decoded and is
	// a recognized type, but the encoded data is not the expected length.
	ErrMalformedAddressData = ErrorKind("ErrMalformedAddressData")

	// ErrBadAddressChecksum indicates an address failed to decode due to an
	// invalid checksum.
	ErrBadAddressChecksum = ErrorKind("ErrBadAddressChecksum")

	// ErrInvalidPubKey indicates that a serialized public key failed to
	// parse.
	ErrInvalidPubKey = ErrorKind("ErrInvalidPubKey")

	// ErrInvalidPubKeyFormat indicates that a serialized public key parsed
	// successfully, but is not one of the allowed formats.
	ErrInvalidPubKeyFormat = ErrorKind("ErrInvalidPubKeyFormat")

	// ErrInvalidHashLen indicates that either a public key hash or a script
	// hash is not an allowed length.
	ErrInvalidHashLen = ErrorKind("ErrInvalidHashLen")
)

These constants are used to identify a specific ErrorKind.

Variables

This section is empty.

Functions

func Hash160

func Hash160(buf []byte) []byte

Hash160 calculates the hash ripemd160(blake256(b)).

Types

type Address

type Address interface {
	// String returns the string encoding of the payment address for the
	// associated script version and payment script.
	String() string

	// PaymentScript returns the script version associated with the address
	// along with a script to pay a transaction output to the address.
	PaymentScript() (uint16, []byte)
}

Address represents any type of destination a transaction output may spend to. Some examples include pay-to-pubkey (P2PK), pay-to-pubkey-hash (P2PKH), and pay-to-script-hash (P2SH). Address is designed to be generic enough that other kinds of addresses may be added in the future without changing the decoding and encoding API.

func DecodeAddress

func DecodeAddress(addr string, params AddressParams) (Address, error)

DecodeAddress decodes the string encoding of an address and returns the relevant Address if it is a valid encoding for a known address type and is for the provided network.

Example

This example demonstrates decoding addresses, generating their payment scripts and associated script versions, determining supported capabilities by checking if interfaces are implemented, obtaining the associated underlying hash160 for addresses that support it, converting public key addresses to their public key hash variant, and generating stake-related scripts for addresses that can be used in the staking system.

// Ordinarily addresses would be read from the user or the result of a
// derivation, but they are hard coded here for the purposes of this
// example.
simNetParams := chaincfg.SimNetParams()
addrsToDecode := []string{
	// v0 pay-to-pubkey ecdsa
	"SkLUJQxtYoVrewN6fwqsU6JQjxLs5a6xfcTsGfUYiLr2AUY6HuLMN",

	// v0 pay-to-pubkey-hash ecdsa
	"Sspzuh5xuvqxccYLWJDJjCtqp166NRxcaPB",

	// v0 pay-to-pubkey schnorr
	"SkLYBuKMSsCi1PdjqMf2i6D3wWB6K1QNMN39Qsxr68qLBFXMTwcpG",

	// v0 pay-to-pubkey-hash schnorr
	"SSt3WeMV3ufEHufh8nCey97y2yp7tNdPyES",

	// v0 pay-to-script-hash
	"ScrkZMau4jj7JUHUvU4YMMRRi4w1o3Wp1vY",
}
for idx, encodedAddr := range addrsToDecode {
	addr, err := stdaddr.DecodeAddress(encodedAddr, simNetParams)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Obtain the payment script and associated script version that would
	// ordinarily by used in a transaction output to send funds to the
	// address.
	scriptVer, script := addr.PaymentScript()
	fmt.Printf("addr%d: %s\n", idx, addr)
	fmt.Printf("  payment script version: %d\n", scriptVer)
	fmt.Printf("  payment script: %x\n", script)

	// Access the RIPEMD-160 hash from addresses that involve it.
	if h160er, ok := addr.(stdaddr.Hash160er); ok {
		fmt.Printf("  hash160: %x\n", *h160er.Hash160())
	}

	// Demonstrate converting public key addresses to the public key hash
	// variant when supported.  This is primarily provided for convenience
	// when the caller already happens to have the public key address handy
	// such as in cases where public keys are shared through some protocol.
	if pkHasher, ok := addr.(stdaddr.AddressPubKeyHasher); ok {
		fmt.Printf("  p2pkh addr: %s\n", pkHasher.AddressPubKeyHash())
	}

	// Obtain stake-related scripts and associated script versions that
	// would ordinarily be used in stake transactions such as ticket
	// purchases and votes for supported addresses.
	//
	// Note that only very specific addresses can be used as destinations in
	// the staking system and this approach provides a capabilities based
	// mechanism to determine support.
	if stakeAddr, ok := addr.(stdaddr.StakeAddress); ok {
		// Obtain the voting rights script and associated script version
		// that would ordinarily by used in a ticket purchase transaction to
		// give voting rights to the address.
		voteScriptVer, voteScript := stakeAddr.VotingRightsScript()
		fmt.Printf("  voting rights script version: %d\n", voteScriptVer)
		fmt.Printf("  voting rights script: %x\n", voteScript)

		// Obtain the rewards commitment script and associated script
		// version that would ordinarily by used in a ticket purchase
		// transaction to commit the original funds locked plus the reward
		// to the address.
		//
		// Ordinarily the reward amount and fee limits would need to be
		// calculated correctly, but they are hard coded here for the
		// purposes of this example.
		const rewardAmount = 1e8
		const voteFeeLimit = 0
		const revokeFeeLimit = 16777216
		rewardScriptVer, rewardScript := stakeAddr.RewardCommitmentScript(
			rewardAmount, voteFeeLimit, revokeFeeLimit)
		fmt.Printf("  reward script version: %d\n", rewardScriptVer)
		fmt.Printf("  reward script: %x\n", rewardScript)
	}
}
Output:

addr0: SkLUJQxtYoVrewN6fwqsU6JQjxLs5a6xfcTsGfUYiLr2AUY6HuLMN
  payment script version: 0
  payment script: 210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac
  p2pkh addr: Sspzuh5xuvqxccYLWJDJjCtqp166NRxcaPB
addr1: Sspzuh5xuvqxccYLWJDJjCtqp166NRxcaPB
  payment script version: 0
  payment script: 76a914e280cb6e66b96679aec288b1fbdbd4db08077a1b88ac
  hash160: e280cb6e66b96679aec288b1fbdbd4db08077a1b
  voting rights script version: 0
  voting rights script: ba76a914e280cb6e66b96679aec288b1fbdbd4db08077a1b88ac
  reward script version: 0
  reward script: 6a1ee280cb6e66b96679aec288b1fbdbd4db08077a1b00e1f505000000000058
addr2: SkLYBuKMSsCi1PdjqMf2i6D3wWB6K1QNMN39Qsxr68qLBFXMTwcpG
  payment script version: 0
  payment script: 210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179852be
  p2pkh addr: SSt3WeMV3ufEHufh8nCey97y2yp7tNdPyES
addr3: SSt3WeMV3ufEHufh8nCey97y2yp7tNdPyES
  payment script version: 0
  payment script: 76a914e280cb6e66b96679aec288b1fbdbd4db08077a1b8852be
  hash160: e280cb6e66b96679aec288b1fbdbd4db08077a1b
addr4: ScrkZMau4jj7JUHUvU4YMMRRi4w1o3Wp1vY
  payment script version: 0
  payment script: a914ae7cd0a69b915796aa9318e1ad74f3579bfcb36587
  hash160: ae7cd0a69b915796aa9318e1ad74f3579bfcb365
  voting rights script version: 0
  voting rights script: baa914ae7cd0a69b915796aa9318e1ad74f3579bfcb36587
  reward script version: 0
  reward script: 6a1eae7cd0a69b915796aa9318e1ad74f3579bfcb36500e1f505000000800058

func DecodeAddressV0

func DecodeAddressV0(addr string, params AddressParamsV0) (Address, error)

DecodeAddressV0 decodes the string encoding of an address and returns the relevant Address if it is a valid encoding for a known version 0 address type and is for the network identified by the provided parameters.

func NewAddressPubKeyEcdsaSecp256k1

func NewAddressPubKeyEcdsaSecp256k1(scriptVersion uint16,
	pubKey Secp256k1PublicKey,
	params AddressParams) (Address, error)

NewAddressPubKeyEcdsaSecp256k1 returns an address that represents a payment destination which imposes an encumbrance that requires a valid ECDSA signature for a specific secp256k1 public key.

See NewAddressPubKeyEcdsaSecp256k1Raw for a variant that accepts the public key already serialized in the _compressed_ format instead of a concrete type. It can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressPubKeyEcdsaSecp256k1Raw

func NewAddressPubKeyEcdsaSecp256k1Raw(scriptVersion uint16,
	serializedPubKey []byte,
	params AddressParams) (Address, error)

NewAddressPubKeyEcdsaSecp256k1Raw returns an address that represents a payment destination which imposes an encumbrance that requires a valid ECDSA signature for a specific secp256k1 public key.

The provided public key MUST be a valid secp256k1 public key serialized in the _compressed_ format or an error will be returned.

See NewAddressPubKeyEcdsaSecp256k1 for a variant that accepts the public key as a concrete type instance instead.

This function can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressPubKeyEd25519

func NewAddressPubKeyEd25519(scriptVersion uint16, pubKey Ed25519PublicKey,
	params AddressParams) (Address, error)

NewAddressPubKeyEd25519 returns an address that represents a payment destination which imposes an encumbrance that requires a valid Ed25519 signature for a specific Ed25519 public key.

See NewAddressPubKeyEd25519Raw for a variant that accepts the public key already serialized instead of a concrete type. It can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressPubKeyEd25519Raw

func NewAddressPubKeyEd25519Raw(scriptVersion uint16, serializedPubKey []byte,
	params AddressParams) (Address, error)

NewAddressPubKeyEd25519Raw returns an address that represents a payment destination which imposes an encumbrance that requires a valid Ed25519 signature for a specific Ed25519 public key.

See NewAddressPubKeyEd25519 for a variant that accepts the public key as a concrete type instance instead.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressPubKeyHashEcdsaSecp256k1

func NewAddressPubKeyHashEcdsaSecp256k1(scriptVersion uint16, pkHash []byte,
	params AddressParams) (Address, error)

NewAddressPubKeyHashEcdsaSecp256k1 returns an address that represents a payment destination which imposes an encumbrance that requires a secp256k1 public key that hashes to the provided public key hash along with a valid ECDSA signature for that public key.

For version 0 scripts, the provided public key hash must be 20 bytes and is expected to be the Hash160 of the associated secp256k1 public key serialized in the _compressed_ format.

It is important to note that while it is technically possible for legacy reasons to create this specific type of address based on the hash of a public key in the uncompressed format, so long as it is also redeemed with that same public key in uncompressed format, it is *HIGHLY* recommended to use the compressed format since it occupies less space on the chain and is more consistent with other address formats where uncompressed public keys are NOT supported.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressPubKeyHashEd25519

func NewAddressPubKeyHashEd25519(scriptVersion uint16, pkHash []byte,
	params AddressParams) (Address, error)

NewAddressPubKeyHashEd25519 returns an address that represents a a payment destination which imposes an encumbrance that requires an Ed25519 public key that hashes to the provided public key hash along with a valid Ed25519 signature for that public key.

For version 0 scripts, the provided public key hash must be 20 bytes and be the Hash160 of the correct public key or it will not be redeemable with the expected public key because it would hash to a different value than the payment script generated for the provided incorrect public key hash expects.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressPubKeyHashSchnorrSecp256k1

func NewAddressPubKeyHashSchnorrSecp256k1(scriptVersion uint16, pkHash []byte,
	params AddressParams) (Address, error)

NewAddressPubKeyHashSchnorrSecp256k1 returns an address that represents a payment destination which imposes an encumbrance that requires a secp256k1 public key in the _compressed_ format that hashes to the provided public key hash along with a valid EC-Schnorr-DCR signature for that public key.

For version 0 scripts, the provided public key hash must be 20 bytes and is expected to be the Hash160 of the associated secp256k1 public key serialized in the _compressed_ format.

WARNING: It is important to note that, unlike in the case of the ECDSA variant of this type of address, redemption via a public key in the uncompressed format is NOT supported by the consensus rules for this type, so it is *EXTREMELY* important to ensure the provided hash is of the serialized public key in the compressed format or the associated coins will NOT be redeemable.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressPubKeySchnorrSecp256k1

func NewAddressPubKeySchnorrSecp256k1(scriptVersion uint16,
	pubKey Secp256k1PublicKey,
	params AddressParams) (Address, error)

NewAddressPubKeySchnorrSecp256k1 returns an address that represents a payment destination which imposes an encumbrance that requires a valid EC-Schnorr-DCR signature for a specific secp256k1 public key.

See NewAddressPubKeySchnorrSecp256k1Raw for a variant that accepts the public key already serialized in the _compressed_ format instead of a concrete type. It can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressPubKeySchnorrSecp256k1Raw

func NewAddressPubKeySchnorrSecp256k1Raw(scriptVersion uint16,
	serializedPubKey []byte,
	params AddressParams) (Address, error)

NewAddressPubKeySchnorrSecp256k1Raw returns an address that represents a payment destination which imposes an encumbrance that requires a valid EC-Schnorr-DCR signature for a specific secp256k1 public key.

The provided public key MUST be a valid secp256k1 public key serialized in the _compressed_ format or an error will be returned.

See NewAddressPubKeySchnorrSecp256k1 for a variant that accepts the public key as a concrete type instance instead.

This function can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressScriptHash

func NewAddressScriptHash(scriptVersion uint16, redeemScript []byte,
	params AddressParams) (Address, error)

NewAddressScriptHash returns an address that represents a payment destination which imposes an encumbrance that requires a script that hashes to the same value as the provided script along with all of the encumbrances that script itself imposes. The script is commonly referred to as a redeem script.

See NewAddressScriptHashFromHash for a variant that accepts the hash of the script directly instead of the script. It can be useful to callers that either already have the script hash available or do not know the associated script.

NOTE: Version 0 scripts are the only currently supported version.

func NewAddressScriptHashFromHash

func NewAddressScriptHashFromHash(scriptVersion uint16, scriptHash []byte,
	params AddressParams) (Address, error)

NewAddressScriptHashFromHash returns an address that represents a payment destination which imposes an encumbrance that requires a script that hashes to the provided script hash along with all of the encumbrances that script itself imposes. The script is commonly referred to as a redeem script.

For version 0 scripts, the provided script hash must be 20 bytes and is expected to be the Hash160 of the associated redeem script.

See NewAddressScriptHash for a variant that accepts the redeem script instead of its hash. It can be used as a convenience for callers that have the redeem script available.

NOTE: Version 0 scripts are the only currently supported version.

type AddressParams

type AddressParams interface {
	AddressParamsV0
}

AddressParams defines an interface that is used to provide the parameters required when encoding and decoding addresses. These values are typically well-defined and unique per network.

type AddressParamsV0

type AddressParamsV0 interface {
	// AddrIDPubKeyV0 returns the magic prefix bytes for version 0 pay-to-pubkey
	// addresses.
	AddrIDPubKeyV0() [2]byte

	// AddrIDPubKeyHashECDSAV0 returns the magic prefix bytes for version 0
	// pay-to-pubkey-hash addresses where the underlying pubkey is secp256k1 and
	// the signature algorithm is ECDSA.
	AddrIDPubKeyHashECDSAV0() [2]byte

	// AddrIDPubKeyHashEd25519V0 returns the magic prefix bytes for version 0
	// pay-to-pubkey-hash addresses where the underlying pubkey and signature
	// algorithm are Ed25519.
	AddrIDPubKeyHashEd25519V0() [2]byte

	// AddrIDPubKeyHashSchnorrV0 returns the magic prefix bytes for version 0
	// pay-to-pubkey-hash addresses where the underlying pubkey is secp256k1 and
	// the signature algorithm is Schnorr.
	AddrIDPubKeyHashSchnorrV0() [2]byte

	// AddrIDScriptHashV0 returns the magic prefix bytes for version 0
	// pay-to-script-hash addresses.
	AddrIDScriptHashV0() [2]byte
}

AddressParamsV0 defines an interface that is used to provide the parameters required when encoding and decoding addresses for version 0 scripts. These values are typically well-defined and unique per network.

type AddressPubKeyEcdsaSecp256k1V0

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

AddressPubKeyEcdsaSecp256k1V0 specifies an address that represents a payment destination which imposes an encumbrance that requires a valid ECDSA signature for a specific secp256k1 public key.

This is commonly referred to as pay-to-pubkey (P2PK) for legacy reasons, however, since it is possible to support multiple algorithm and signature scheme combinations, it is technically more accurate to refer to it as pay-to-pubkey-ecdsa-secp256k1.

func NewAddressPubKeyEcdsaSecp256k1V0

func NewAddressPubKeyEcdsaSecp256k1V0(pubKey Secp256k1PublicKey,
	params AddressParamsV0) (*AddressPubKeyEcdsaSecp256k1V0, error)

NewAddressPubKeyEcdsaSecp256k1V0 returns an address that represents a payment destination which imposes an encumbrance that requires a valid ECDSA signature for a specific secp256k1 public key using version 0 scripts.

See NewAddressPubKeyEcdsaSecp256k1V0Raw for a variant that accepts the public key already serialized in the _compressed_ format instead of a concrete type. It can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

func NewAddressPubKeyEcdsaSecp256k1V0Raw

func NewAddressPubKeyEcdsaSecp256k1V0Raw(serializedPubKey []byte,
	params AddressParamsV0) (*AddressPubKeyEcdsaSecp256k1V0, error)

NewAddressPubKeyEcdsaSecp256k1V0Raw returns an address that represents a payment destination which imposes an encumbrance that requires a valid ECDSA signature for a specific secp256k1 public key using version 0 scripts.

The provided public key MUST be a valid secp256k1 public key serialized in the _compressed_ format or an error will be returned.

See NewAddressPubKeyEcdsaSecp256k1V0 for a variant that accepts the public key as a concrete type instance instead.

This function can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

func (*AddressPubKeyEcdsaSecp256k1V0) AddressPubKeyHash

func (addr *AddressPubKeyEcdsaSecp256k1V0) AddressPubKeyHash() Address

AddressPubKeyHash returns the address converted to a pay-to-pubkey-hash-ecdsa-secp256k1 address.

Note that the hash used in resulting address is the hash of the serialized public key and the address constructor intentionally only supports public keys in the compressed format. In other words, the resulting address will impose an encumbrance that requires the public key to be provided in the compressed format.

func (*AddressPubKeyEcdsaSecp256k1V0) PaymentScript

func (addr *AddressPubKeyEcdsaSecp256k1V0) PaymentScript() (uint16, []byte)

PaymentScript returns the script version associated with the address along with a script to pay a transaction output to the address.

This is part of the Address interface implementation.

func (*AddressPubKeyEcdsaSecp256k1V0) SerializedPubKey

func (addr *AddressPubKeyEcdsaSecp256k1V0) SerializedPubKey() []byte

SerializedPubKey returns the compressed serialization of the secp256k1 public key. The bytes must not be modified.

func (*AddressPubKeyEcdsaSecp256k1V0) String

func (addr *AddressPubKeyEcdsaSecp256k1V0) String() string

String returns the string encoding of the payment address for the associated script version and payment script.

This is part of the Address interface implementation.

type AddressPubKeyEd25519V0

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

AddressPubKeyEd25519V0 specifies an address that represents a payment destination which imposes an encumbrance that requires a valid Ed25519 signature for a specific Ed25519 public key.

This is commonly referred to as pay-to-pubkey-ed25519.

func NewAddressPubKeyEd25519V0

func NewAddressPubKeyEd25519V0(pubKey Ed25519PublicKey,
	params AddressParamsV0) (*AddressPubKeyEd25519V0, error)

NewAddressPubKeyEd25519V0 returns an address that represents a payment destination which imposes an encumbrance that requires a valid Ed25519 signature for a specific Ed25519 public key using version 0 scripts.

See NewAddressPubKeyEd25519Raw for a variant that accepts the public key already serialized instead of a concrete type. It can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

func NewAddressPubKeyEd25519V0Raw

func NewAddressPubKeyEd25519V0Raw(serializedPubKey []byte,
	params AddressParamsV0) (*AddressPubKeyEd25519V0, error)

NewAddressPubKeyEd25519V0Raw returns an address that represents a payment destination which imposes an encumbrance that requires a valid Ed25519 signature for a specific Ed25519 public key using version 0 scripts.

See NewAddressPubKeyEd25519V0 for a variant that accepts the public key as a concrete type instance instead.

func (*AddressPubKeyEd25519V0) AddressPubKeyHash

func (addr *AddressPubKeyEd25519V0) AddressPubKeyHash() Address

AddressPubKeyHash returns the address converted to a pay-to-pubkey-hash-ed25519 address.

func (*AddressPubKeyEd25519V0) PaymentScript

func (addr *AddressPubKeyEd25519V0) PaymentScript() (uint16, []byte)

PaymentScript returns the script version associated with the address along with a script to pay a transaction output to the address.

This is part of the Address interface implementation.

func (*AddressPubKeyEd25519V0) SerializedPubKey

func (addr *AddressPubKeyEd25519V0) SerializedPubKey() []byte

SerializedPubKey returns the serialization of the ed25519 public key. The bytes must not be modified.

func (*AddressPubKeyEd25519V0) String

func (addr *AddressPubKeyEd25519V0) String() string

String returns the string encoding of the payment address for the associated script version and payment script.

This is part of the Address interface implementation.

type AddressPubKeyHashEcdsaSecp256k1V0

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

AddressPubKeyHashEcdsaSecp256k1V0 specifies an address that represents a payment destination which imposes an encumbrance that requires a secp256k1 public key that hashes to the given public key hash along with a valid ECDSA signature for that public key.

This is commonly referred to as pay-to-pubkey-hash (P2PKH) for legacy reasons, however, since it is possible to support multiple algorithm and signature scheme combinations, it is technically more accurate to refer to it as pay-to-pubkey-hash-ecdsa-secp256k1.

func NewAddressPubKeyHashEcdsaSecp256k1V0

func NewAddressPubKeyHashEcdsaSecp256k1V0(pkHash []byte,
	params AddressParamsV0) (*AddressPubKeyHashEcdsaSecp256k1V0, error)

NewAddressPubKeyHashEcdsaSecp256k1V0 returns an address that represents a payment destination which imposes an encumbrance that requires a secp256k1 public key that hashes to the provided public key hash along with a valid ECDSA signature for that public key using version 0 scripts.

The provided public key hash must be 20 bytes and is expected to be the Hash160 of the associated secp256k1 public key serialized in the _compressed_ format.

It is important to note that while it is technically possible for legacy reasons to create this specific type of address based on the hash of a public key in the uncompressed format, so long as it is also redeemed with that same public key in uncompressed format, it is *HIGHLY* recommended to use the compressed format since it occupies less space on the chain and is more consistent with other address formats where uncompressed public keys are NOT supported.

func (*AddressPubKeyHashEcdsaSecp256k1V0) Hash160

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 (*AddressPubKeyHashEcdsaSecp256k1V0) PayFromTreasuryScript

func (addr *AddressPubKeyHashEcdsaSecp256k1V0) PayFromTreasuryScript() (uint16, []byte)

PayFromTreasuryScript returns the script version associated with the address along with a script that pays funds from the treasury to the address. The script is only valid when used in treasury spend transactions.

This is part of the StakeAddress interface implementation.

func (*AddressPubKeyHashEcdsaSecp256k1V0) PayRevokeCommitmentScript

func (addr *AddressPubKeyHashEcdsaSecp256k1V0) PayRevokeCommitmentScript() (uint16, []byte)

PayRevokeCommitmentScript returns the script version associated with the address along with a script to revoke an expired or missed ticket which pays the original funds locked to purchase a ticket to the address. The address must have previously been committed to by the ticket purchase. The script is only valid when used in stake revocation transactions whose associated tickets have been missed or expired.

This is part of the StakeAddress interface implementation.

func (*AddressPubKeyHashEcdsaSecp256k1V0) PayVoteCommitmentScript

func (addr *AddressPubKeyHashEcdsaSecp256k1V0) PayVoteCommitmentScript() (uint16, []byte)

PayVoteCommitmentScript returns the script version associated with the address along with a script to pay the original funds locked to purchase a ticket plus the reward to the address. The address must have previously been committed to by the ticket purchase. The script is only valid when used in stake vote transactions whose associated tickets are eligible to vote.

This is part of the StakeAddress interface implementation.

func (*AddressPubKeyHashEcdsaSecp256k1V0) PaymentScript

func (addr *AddressPubKeyHashEcdsaSecp256k1V0) PaymentScript() (uint16, []byte)

PaymentScript returns the script version associated with the address along with a script to pay a transaction output to the address.

This is part of the Address interface implementation.

func (*AddressPubKeyHashEcdsaSecp256k1V0) RewardCommitmentScript

func (addr *AddressPubKeyHashEcdsaSecp256k1V0) RewardCommitmentScript(amount, voteFeeLimit, revocationFeeLimit int64) (uint16, []byte)

RewardCommitmentScript returns the script version associated with the address along with a script that commits the original funds locked to purchase a ticket plus the reward to the address along with limits to impose on any fees (in atoms).

Note that fee limits are encoded in the commitment script in terms of the closest base 2 exponent that results in a limit that is >= the provided limit. In other words, the limits are rounded up to the next power of 2 when they are not already an exact power of 2. For example, a revocation limit of 2^23 + 1 will result in allowing a revocation fee of up to 2^24 atoms.

This is part of the StakeAddress interface implementation.

func (*AddressPubKeyHashEcdsaSecp256k1V0) StakeChangeScript

func (addr *AddressPubKeyHashEcdsaSecp256k1V0) StakeChangeScript() (uint16, []byte)

StakeChangeScript returns the script version associated with the address along with a script to pay change to the address. It is only valid when used in stake ticket purchase and treasury add transactions.

This is part of the StakeAddress interface implementation.

func (*AddressPubKeyHashEcdsaSecp256k1V0) String

String returns the string encoding of the payment address for the associated script version and payment script.

This is part of the Address interface implementation.

func (*AddressPubKeyHashEcdsaSecp256k1V0) VotingRightsScript

func (addr *AddressPubKeyHashEcdsaSecp256k1V0) VotingRightsScript() (uint16, []byte)

VotingRightsScript returns the script version associated with the address along with a script to give voting rights to the address. It is only valid when used in stake ticket purchase transactions.

This is part of the StakeAddress interface implementation.

type AddressPubKeyHashEd25519V0

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

AddressPubKeyHashEd25519V0 specifies an address that represents a a payment destination which imposes an encumbrance that requires an Ed25519 public key that hashes to the given public key hash along with a valid Ed25519 signature for that public key.

This is commonly referred to as pay-to-pubkey-hash-ed25519.

func NewAddressPubKeyHashEd25519V0

func NewAddressPubKeyHashEd25519V0(pkHash []byte,
	params AddressParamsV0) (*AddressPubKeyHashEd25519V0, error)

NewAddressPubKeyHashEd25519V0 returns an address that represents a a payment destination which imposes an encumbrance that requires an Ed25519 public key that hashes to the provided public key hash along with a valid Ed25519 signature for that public key using version 0 scripts.

The provided public key hash must be 20 bytes and be the Hash160 of the correct public key or it will not be redeemable with the expected public key because it would hash to a different value than the payment script generated for the provided incorrect public key hash expects.

func (*AddressPubKeyHashEd25519V0) Hash160

func (addr *AddressPubKeyHashEd25519V0) 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 (*AddressPubKeyHashEd25519V0) PaymentScript

func (addr *AddressPubKeyHashEd25519V0) PaymentScript() (uint16, []byte)

PaymentScript returns the script version associated with the address along with a script to pay a transaction output to the address.

This is part of the Address interface implementation.

func (*AddressPubKeyHashEd25519V0) String

func (addr *AddressPubKeyHashEd25519V0) String() string

String returns the string encoding of the payment address for the associated script version and payment script.

This is part of the Address interface implementation.

type AddressPubKeyHashSchnorrSecp256k1V0

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

AddressPubKeyHashSchnorrSecp256k1V0 specifies address that represents a payment destination which imposes an encumbrance that requires a secp256k1 public key in the _compressed_ format that hashes to the given public key hash along with a valid EC-Schnorr-DCRv0 signature for that public key.

This is commonly referred to as pay-to-pubkey-hash-schnorr-secp256k1.

func NewAddressPubKeyHashSchnorrSecp256k1V0

func NewAddressPubKeyHashSchnorrSecp256k1V0(pkHash []byte,
	params AddressParamsV0) (*AddressPubKeyHashSchnorrSecp256k1V0, error)

NewAddressPubKeyHashSchnorrSecp256k1V0 returns an address that represents a payment destination which imposes an encumbrance that requires a secp256k1 public key in the _compressed_ format that hashes to the provided public key hash along with a valid EC-Schnorr-DCRv0 signature for that public key using version 0 scripts.

The provided public key hash must be 20 bytes and is expected to be the Hash160 of the associated secp256k1 public key serialized in the _compressed_ format.

WARNING: It is important to note that, unlike in the case of the ECDSA variant of this type of address, redemption via a public key in the uncompressed format is NOT supported by the consensus rules for this type, so it is *EXTREMELY* important to ensure the provided hash is of the serialized public key in the compressed format or the associated coins will NOT be redeemable.

func (*AddressPubKeyHashSchnorrSecp256k1V0) Hash160

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 (*AddressPubKeyHashSchnorrSecp256k1V0) PaymentScript

func (addr *AddressPubKeyHashSchnorrSecp256k1V0) PaymentScript() (uint16, []byte)

PaymentScript returns the script version associated with the address along with a script to pay a transaction output to the address.

This is part of the Address interface implementation.

func (*AddressPubKeyHashSchnorrSecp256k1V0) String

String returns the string encoding of the payment address for the associated script version and payment script.

This is part of the Address interface implementation.

type AddressPubKeyHasher

type AddressPubKeyHasher interface {
	AddressPubKeyHash() Address
}

AddressPubKeyHasher is an interface for public key addresses that can be converted to an address that imposes an encumbrance that requires the public key that hashes to a given public key hash along with a valid signature for that public key.

The specific public key and signature types are dependent on the original address.

type AddressPubKeySchnorrSecp256k1V0

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

AddressPubKeySchnorrSecp256k1V0 specifies an address that represents a payment destination which imposes an encumbrance that requires a valid EC-Schnorr-DCRv0 signature for a specific secp256k1 public key.

This is commonly referred to as pay-to-pubkey-schnorr-secp256k1.

func NewAddressPubKeySchnorrSecp256k1V0

func NewAddressPubKeySchnorrSecp256k1V0(pubKey Secp256k1PublicKey,
	params AddressParamsV0) (*AddressPubKeySchnorrSecp256k1V0, error)

NewAddressPubKeySchnorrSecp256k1V0 returns an address that represents a payment destination which imposes an encumbrance that requires a valid EC-Schnorr-DCRv0 signature for a specific secp256k1 public key using version 0 scripts.

See NewAddressPubKeySchnorrSecp256k1V0Raw for a variant that accepts the public key already serialized in the _compressed_ format instead of a concrete type. It can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

func NewAddressPubKeySchnorrSecp256k1V0Raw

func NewAddressPubKeySchnorrSecp256k1V0Raw(serializedPubKey []byte,
	params AddressParamsV0) (*AddressPubKeySchnorrSecp256k1V0, error)

NewAddressPubKeySchnorrSecp256k1V0Raw returns an address that represents a payment destination which imposes an encumbrance that requires a valid EC-Schnorr-DCRv0 signature for a specific secp256k1 public key using version 0 scripts.

The provided public key MUST be a valid secp256k1 public key serialized in the _compressed_ format or an error will be returned.

See NewAddressPubKeySchnorrSecp256k1V0 for a variant that accepts the public key as a concrete type instance instead.

This function can be useful to callers who already need the serialized public key for other purposes to avoid the need to serialize it multiple times.

func (*AddressPubKeySchnorrSecp256k1V0) AddressPubKeyHash

func (addr *AddressPubKeySchnorrSecp256k1V0) AddressPubKeyHash() Address

AddressPubKeyHash returns the address converted to a pay-to-pubkey-hash-schnorr-secp256k1 address.

Note that the hash used in resulting address is the hash of the serialized public key and only public keys in the compressed format are supported. In other words, the resulting address will impose an encumbrance that requires the public key to be provided in the compressed format.

func (*AddressPubKeySchnorrSecp256k1V0) PaymentScript

func (addr *AddressPubKeySchnorrSecp256k1V0) PaymentScript() (uint16, []byte)

PaymentScript returns the script version associated with the address along with a script to pay a transaction output to the address.

This is part of the Address interface implementation.

func (*AddressPubKeySchnorrSecp256k1V0) SerializedPubKey

func (addr *AddressPubKeySchnorrSecp256k1V0) SerializedPubKey() []byte

SerializedPubKey returns the compressed serialization of the secp256k1 public key. The bytes must not be modified.

func (*AddressPubKeySchnorrSecp256k1V0) String

func (addr *AddressPubKeySchnorrSecp256k1V0) String() string

String returns the string encoding of the payment address for the associated script version and payment script.

This is part of the Address interface implementation.

type AddressScriptHashV0

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

AddressScriptHashV0 specifies an address that represents a payment destination which imposes an encumbrance that requires a script that hashes to the provided script hash along with all of the encumbrances that script itself imposes. The script is commonly referred to as a redeem script.

This is commonly referred to as pay-to-script-hash (P2SH).

func NewAddressScriptHashV0

func NewAddressScriptHashV0(redeemScript []byte,
	params AddressParamsV0) (*AddressScriptHashV0, error)

NewAddressScriptHashV0 returns an address that represents a payment destination which imposes an encumbrance that requires a script that hashes to the same value as the provided script along with all of the encumbrances that script itself imposes using version 0 scripts. The script is commonly referred to as a redeem script.

See NewAddressScriptHashV0FromHash for a variant that accepts the hash of the script directly instead of the script. It can be useful to callers that either already have the script hash available or do not know the associated script.

func NewAddressScriptHashV0FromHash

func NewAddressScriptHashV0FromHash(scriptHash []byte,
	params AddressParamsV0) (*AddressScriptHashV0, error)

NewAddressScriptHashV0FromHash returns an address that represents a payment destination which imposes an encumbrance that requires a script that hashes to the provided script hash along with all of the encumbrances that script itself imposes using version 0 scripts. The script is commonly referred to as a redeem script.

The provided script hash must be 20 bytes and is expected to be the Hash160 of the associated redeem script.

See NewAddressScriptHashV0 for a variant that accepts the redeem script instead of its hash. It can be used as a convenience for callers that have the redeem script available.

func (*AddressScriptHashV0) Hash160

func (addr *AddressScriptHashV0) Hash160() *[ripemd160.Size]byte

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

func (*AddressScriptHashV0) PayFromTreasuryScript

func (addr *AddressScriptHashV0) PayFromTreasuryScript() (uint16, []byte)

PayFromTreasuryScript returns the script version associated with the address along with a script that pays funds from the treasury to the address. The script is only valid when used in treasury spend transactions.

This is part of the StakeAddress interface implementation.

func (*AddressScriptHashV0) PayRevokeCommitmentScript

func (addr *AddressScriptHashV0) PayRevokeCommitmentScript() (uint16, []byte)

PayRevokeCommitmentScript returns the script version associated with the address along with a script to revoke an expired or missed ticket which pays the original funds locked to purchase a ticket to the address. The address must have previously been committed to by the ticket purchase. The script is only valid when used in stake revocation transactions whose associated tickets have been missed or expired.

This is part of the StakeAddress interface implementation.

func (*AddressScriptHashV0) PayVoteCommitmentScript

func (addr *AddressScriptHashV0) PayVoteCommitmentScript() (uint16, []byte)

PayVoteCommitmentScript returns the script version associated with the address along with a script to pay the original funds locked to purchase a ticket plus the reward to the address. The address must have previously been committed to by the ticket purchase. The script is only valid when used in stake vote transactions whose associated tickets are eligible to vote.

This is part of the StakeAddress interface implementation.

func (*AddressScriptHashV0) PaymentScript

func (addr *AddressScriptHashV0) PaymentScript() (uint16, []byte)

PaymentScript returns the script version associated with the address along with a script to pay a transaction output to the address.

This is part of the Address interface implementation.

func (*AddressScriptHashV0) RewardCommitmentScript

func (addr *AddressScriptHashV0) RewardCommitmentScript(amount, voteFeeLimit, revocationFeeLimit int64) (uint16, []byte)

RewardCommitmentScript returns the script version associated with the address along with a script that commits the original funds locked to purchase a ticket plus the reward to the address along with limits to impose on any fees (in atoms).

Note that fee limits are encoded in the commitment script in terms of the closest base 2 exponent that results in a limit that is >= the provided limit. In other words, the limits are rounded up to the next power of 2 when they are not already an exact power of 2. For example, a revocation limit of 2^23 + 1 will result in allowing a revocation fee of up to 2^24 atoms.

This is part of the StakeAddress interface implementation.

func (*AddressScriptHashV0) StakeChangeScript

func (addr *AddressScriptHashV0) StakeChangeScript() (uint16, []byte)

StakeChangeScript returns the script version associated with the address along with a script to pay change to the address. It is only valid when used in stake ticket purchase and treasury add transactions.

This is part of the StakeAddress interface implementation.

func (*AddressScriptHashV0) String

func (addr *AddressScriptHashV0) String() string

String returns the string encoding of the payment address for the associated script version and payment script.

This is part of the Address interface implementation.

func (*AddressScriptHashV0) VotingRightsScript

func (addr *AddressScriptHashV0) VotingRightsScript() (uint16, []byte)

VotingRightsScript returns the script version associated with the address along with a script to give voting rights to the address. It is only valid when used in stake ticket purchase transactions.

This is part of the StakeAddress interface implementation.

type Ed25519PublicKey

type Ed25519PublicKey interface {
	// Serialize serializes the public key in a 32-byte compressed little endian
	// format.
	Serialize() []byte
}

Ed25519PublicKey is an interface type that represents an Ed25519 public key for use in creating pay-to-pubkey addresses that involve them.

type Error

type Error struct {
	Err         error
	Description string
}

Error identifies an address-related error.

It has full support for errors.Is and errors.As, so the caller can ascertain the specific reason for the error by checking the underlying error.

func (Error) Error

func (e Error) Error() string

Error satisfies the error interface and prints human-readable errors.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap returns the underlying wrapped error.

type ErrorKind

type ErrorKind string

ErrorKind identifies a kind of error.

func (ErrorKind) Error

func (e ErrorKind) Error() string

Error satisfies the error interface and prints human-readable errors.

type Hash160er

type Hash160er interface {
	Hash160() *[ripemd160.Size]byte
}

Hash160er is an interface that allows the RIPEMD-160 hash to be obtained from addresses that involve them.

type Secp256k1PublicKey

type Secp256k1PublicKey interface {
	// SerializeCompressed serializes a public key in the 33-byte compressed
	// format.
	SerializeCompressed() []byte
}

Secp256k1PublicKey is an interface that represents a secp256k1 public key for use in creating pay-to-pubkey addresses that involve them.

type SerializedPubKeyer

type SerializedPubKeyer interface {
	SerializedPubKey() []byte
}

SerializedPubKeyer is an interface for public key addresses that allows the serialized public key to be obtained from addresses that involve them.

type StakeAddress

type StakeAddress interface {
	Address

	// VotingRightsScript returns the script version associated with the address
	// along with a script to give voting rights to the address.  It is only
	// valid when used in stake ticket purchase transactions.
	VotingRightsScript() (uint16, []byte)

	// RewardCommitmentScript returns the script version associated with the
	// address along with a script that commits the original funds locked to
	// purchase a ticket plus the reward to the address along with limits to
	// impose on any fees (in atoms).
	//
	// Note that fee limits are encoded in the commitment script in terms of the
	// closest base 2 exponent that results in a limit that is >= the provided
	// limit.  In other words, the limits are rounded up to the next power of 2
	// when they are not already an exact power of 2.  For example, a revocation
	// limit of 2^23 + 1 will result in allowing a revocation fee of up to 2^24
	// atoms.
	RewardCommitmentScript(amount, voteFeeLimit, revocationFeeLimit int64) (uint16, []byte)

	// StakeChangeScript returns the script version associated with the address
	// along with a script to pay change to the address.  It is only valid when
	// used in stake ticket purchase and treasury add transactions.
	StakeChangeScript() (uint16, []byte)

	// PayVoteCommitmentScript returns the script version associated with the
	// address along with a script to pay the original funds locked to purchase
	// a ticket plus the reward to the address.  The address must have
	// previously been committed to by the ticket purchase.  The script is only
	// valid when used in stake vote transactions whose associated tickets are
	// eligible to vote.
	PayVoteCommitmentScript() (uint16, []byte)

	// PayRevokeCommitmentScript returns the script version associated with the
	// address along with a script to revoke an expired or missed ticket which
	// pays the original funds locked to purchase a ticket to the address.  The
	// address must have previously been committed to by the ticket purchase.
	// The script is only valid when used in stake revocation transactions whose
	// associated tickets have been missed or have expired.
	PayRevokeCommitmentScript() (uint16, []byte)

	// PayFromTreasuryScript returns the script version associated with the
	// address along with a script that pays funds from the treasury to the
	// address.  The script is only valid when used in treasury spend
	// transactions.
	PayFromTreasuryScript() (uint16, []byte)
}

StakeAddress is an interface for generating the specialized scripts that are used in the staking system. Only specific address types are supported by the staking system and therefore only those address types will implement this interface.

Version 1 and 3 staking transactions only support version 0 scripts and address types of AddressPubKeyHashEcdsaSecp256k1V0 and AddressScriptHashV0.

Callers can programmatically assert a specific address implements this interface to access the methods.

Jump to

Keyboard shortcuts

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