Documentation ¶
Overview ¶
Package stdaddr provides facilities for working with human-readable Decred payment addresses.
Index ¶
- Constants
- func Hash160(buf []byte) []byte
- type Address
- func DecodeAddress(addr string, params AddressParams) (Address, error)
- func DecodeAddressV0(addr string, params AddressParamsV0) (Address, error)
- func NewAddressPubKeyEcdsaSecp256k1(scriptVersion uint16, pubKey Secp256k1PublicKey, params AddressParams) (Address, error)
- func NewAddressPubKeyEcdsaSecp256k1Raw(scriptVersion uint16, serializedPubKey []byte, params AddressParams) (Address, error)
- func NewAddressPubKeyEd25519(scriptVersion uint16, pubKey Ed25519PublicKey, params AddressParams) (Address, error)
- func NewAddressPubKeyEd25519Raw(scriptVersion uint16, serializedPubKey []byte, params AddressParams) (Address, error)
- func NewAddressPubKeyHashEcdsaSecp256k1(scriptVersion uint16, pkHash []byte, params AddressParams) (Address, error)
- func NewAddressPubKeyHashEd25519(scriptVersion uint16, pkHash []byte, params AddressParams) (Address, error)
- func NewAddressPubKeyHashSchnorrSecp256k1(scriptVersion uint16, pkHash []byte, params AddressParams) (Address, error)
- func NewAddressPubKeySchnorrSecp256k1(scriptVersion uint16, pubKey Secp256k1PublicKey, params AddressParams) (Address, error)
- func NewAddressPubKeySchnorrSecp256k1Raw(scriptVersion uint16, serializedPubKey []byte, params AddressParams) (Address, error)
- func NewAddressScriptHash(scriptVersion uint16, redeemScript []byte, params AddressParams) (Address, error)
- func NewAddressScriptHashFromHash(scriptVersion uint16, scriptHash []byte, params AddressParams) (Address, error)
- type AddressParams
- type AddressParamsV0
- type AddressPubKeyEcdsaSecp256k1V0
- type AddressPubKeyEd25519V0
- type AddressPubKeyHashEcdsaSecp256k1V0
- func (addr *AddressPubKeyHashEcdsaSecp256k1V0) Hash160() *[ripemd160.Size]byte
- func (addr *AddressPubKeyHashEcdsaSecp256k1V0) PayFromTreasuryScript() (uint16, []byte)
- func (addr *AddressPubKeyHashEcdsaSecp256k1V0) PayRevokeCommitmentScript() (uint16, []byte)
- func (addr *AddressPubKeyHashEcdsaSecp256k1V0) PayVoteCommitmentScript() (uint16, []byte)
- func (addr *AddressPubKeyHashEcdsaSecp256k1V0) PaymentScript() (uint16, []byte)
- func (addr *AddressPubKeyHashEcdsaSecp256k1V0) RewardCommitmentScript(amount, voteFeeLimit, revocationFeeLimit int64) (uint16, []byte)
- func (addr *AddressPubKeyHashEcdsaSecp256k1V0) StakeChangeScript() (uint16, []byte)
- func (addr *AddressPubKeyHashEcdsaSecp256k1V0) String() string
- func (addr *AddressPubKeyHashEcdsaSecp256k1V0) VotingRightsScript() (uint16, []byte)
- type AddressPubKeyHashEd25519V0
- type AddressPubKeyHashSchnorrSecp256k1V0
- type AddressPubKeyHasher
- type AddressPubKeySchnorrSecp256k1V0
- type AddressScriptHashV0
- func (addr *AddressScriptHashV0) Hash160() *[ripemd160.Size]byte
- func (addr *AddressScriptHashV0) PayFromTreasuryScript() (uint16, []byte)
- func (addr *AddressScriptHashV0) PayRevokeCommitmentScript() (uint16, []byte)
- func (addr *AddressScriptHashV0) PayVoteCommitmentScript() (uint16, []byte)
- func (addr *AddressScriptHashV0) PaymentScript() (uint16, []byte)
- func (addr *AddressScriptHashV0) RewardCommitmentScript(amount, voteFeeLimit, revocationFeeLimit int64) (uint16, []byte)
- func (addr *AddressScriptHashV0) StakeChangeScript() (uint16, []byte)
- func (addr *AddressScriptHashV0) String() string
- func (addr *AddressScriptHashV0) VotingRightsScript() (uint16, []byte)
- type Ed25519PublicKey
- type Error
- type ErrorKind
- type Hash160er
- type Secp256k1PublicKey
- type SerializedPubKeyer
- type StakeAddress
Examples ¶
Constants ¶
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 ¶
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 ¶
func (addr *AddressPubKeyHashEcdsaSecp256k1V0) 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 (*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 ¶
func (addr *AddressPubKeyHashEcdsaSecp256k1V0) 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 (*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 ¶
func (addr *AddressPubKeyHashSchnorrSecp256k1V0) 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 (*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 ¶
func (addr *AddressPubKeyHashSchnorrSecp256k1V0) 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 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 ¶
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.
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.