Documentation ¶
Overview ¶
Package stdscript provides facilities for working with standard scripts.
Package stdscript provides facilities for working with standard scripts.
Index ¶
- Constants
- func DetermineRequiredSigs(scriptVersion uint16, script []byte) uint16
- func DetermineRequiredSigsV0(script []byte) uint16
- func ExtractCompressedPubKeyV0(script []byte) []byte
- func ExtractPubKeyAltDetailsV0(script []byte) ([]byte, dcrec.SignatureType)
- func ExtractPubKeyEd25519V0(script []byte) []byte
- func ExtractPubKeyHashAltDetailsV0(script []byte) ([]byte, dcrec.SignatureType)
- func ExtractPubKeyHashEd25519V0(script []byte) []byte
- func ExtractPubKeyHashSchnorrSecp256k1V0(script []byte) []byte
- func ExtractPubKeyHashV0(script []byte) []byte
- func ExtractPubKeySchnorrSecp256k1V0(script []byte) []byte
- func ExtractPubKeyV0(script []byte) []byte
- func ExtractScriptHashV0(script []byte) []byte
- func ExtractStakeChangePubKeyHashV0(script []byte) []byte
- func ExtractStakeChangeScriptHashV0(script []byte) []byte
- func ExtractStakeGenPubKeyHashV0(script []byte) []byte
- func ExtractStakeGenScriptHashV0(script []byte) []byte
- func ExtractStakePubKeyHashV0(script []byte) []byte
- func ExtractStakeRevocationPubKeyHashV0(script []byte) []byte
- func ExtractStakeRevocationScriptHashV0(script []byte) []byte
- func ExtractStakeScriptHashV0(script []byte) []byte
- func ExtractStakeSubmissionPubKeyHashV0(script []byte) []byte
- func ExtractStakeSubmissionScriptHashV0(script []byte) []byte
- func ExtractTreasuryGenPubKeyHashV0(script []byte) []byte
- func ExtractTreasuryGenScriptHashV0(script []byte) []byte
- func ExtractUncompressedPubKeyV0(script []byte) []byte
- func IsMultiSigScript(scriptVersion uint16, script []byte) bool
- func IsMultiSigScriptV0(script []byte) bool
- func IsMultiSigSigScript(scriptVersion uint16, script []byte) bool
- func IsMultiSigSigScriptV0(script []byte) bool
- func IsNullDataScript(scriptVersion uint16, script []byte) bool
- func IsNullDataScriptV0(script []byte) bool
- func IsPubKeyEd25519Script(scriptVersion uint16, script []byte) bool
- func IsPubKeyEd25519ScriptV0(script []byte) bool
- func IsPubKeyHashEd25519Script(scriptVersion uint16, script []byte) bool
- func IsPubKeyHashEd25519ScriptV0(script []byte) bool
- func IsPubKeyHashSchnorrSecp256k1Script(scriptVersion uint16, script []byte) bool
- func IsPubKeyHashSchnorrSecp256k1ScriptV0(script []byte) bool
- func IsPubKeyHashScript(scriptVersion uint16, script []byte) bool
- func IsPubKeyHashScriptV0(script []byte) bool
- func IsPubKeySchnorrSecp256k1Script(scriptVersion uint16, script []byte) bool
- func IsPubKeySchnorrSecp256k1ScriptV0(script []byte) bool
- func IsPubKeyScript(scriptVersion uint16, script []byte) bool
- func IsPubKeyScriptV0(script []byte) bool
- func IsScriptHashScript(scriptVersion uint16, script []byte) bool
- func IsScriptHashScriptV0(script []byte) bool
- func IsStakeChangePubKeyHashScript(scriptVersion uint16, script []byte) bool
- func IsStakeChangePubKeyHashScriptV0(script []byte) bool
- func IsStakeChangeScriptHashScript(scriptVersion uint16, script []byte) bool
- func IsStakeChangeScriptHashScriptV0(script []byte) bool
- func IsStakeGenPubKeyHashScript(scriptVersion uint16, script []byte) bool
- func IsStakeGenPubKeyHashScriptV0(script []byte) bool
- func IsStakeGenScriptHashScript(scriptVersion uint16, script []byte) bool
- func IsStakeGenScriptHashScriptV0(script []byte) bool
- func IsStakeRevocationPubKeyHashScript(scriptVersion uint16, script []byte) bool
- func IsStakeRevocationPubKeyHashScriptV0(script []byte) bool
- func IsStakeRevocationScriptHashScript(scriptVersion uint16, script []byte) bool
- func IsStakeRevocationScriptHashScriptV0(script []byte) bool
- func IsStakeSubmissionPubKeyHashScript(scriptVersion uint16, script []byte) bool
- func IsStakeSubmissionPubKeyHashScriptV0(script []byte) bool
- func IsStakeSubmissionScriptHashScript(scriptVersion uint16, script []byte) bool
- func IsStakeSubmissionScriptHashScriptV0(script []byte) bool
- func IsStandardAltSignatureTypeV0(op byte) bool
- func IsTreasuryAddScript(scriptVersion uint16, script []byte) bool
- func IsTreasuryAddScriptV0(script []byte) bool
- func IsTreasuryGenPubKeyHashScript(scriptVersion uint16, script []byte) bool
- func IsTreasuryGenPubKeyHashScriptV0(script []byte) bool
- func IsTreasuryGenScriptHashScript(scriptVersion uint16, script []byte) bool
- func IsTreasuryGenScriptHashScriptV0(script []byte) bool
- func MultiSigRedeemScriptFromScriptSigV0(script []byte) []byte
- func MultiSigScriptV0(threshold int, pubKeys ...[]byte) ([]byte, error)
- func ProvablyPruneableScriptV0(data []byte) ([]byte, error)
- type AtomicSwapDataPushesV0
- type Error
- type ErrorKind
- type MultiSigDetailsV0
- type ScriptType
- func DetermineScriptType(scriptVersion uint16, script []byte) ScriptType
- func DetermineScriptTypeV0(script []byte) ScriptType
- func ExtractAddrs(scriptVersion uint16, pkScript []byte, params stdaddr.AddressParamsV0) (ScriptType, []stdaddr.Address)
- func ExtractAddrsV0(pkScript []byte, params stdaddr.AddressParamsV0) (ScriptType, []stdaddr.Address)
Examples ¶
Constants ¶
const ( // ErrUnsupportedScriptVersion indicates that a given script version is not // supported. ErrUnsupportedScriptVersion = ErrorKind("ErrUnsupportedScriptVersion") // ErrTooManyRequiredSigs is returned from MultiSigScript when the // specified number of required signatures is larger than the number of // provided public keys. ErrTooManyRequiredSigs = ErrorKind("ErrTooManyRequiredSigs") // ErrPubKeyType is returned when a script contains invalid public keys. ErrPubKeyType = ErrorKind("ErrPubKeyType") // ErrTooMuchNullData is returned when attempting to generate a // provably-pruneable script with data that exceeds the maximum allowed // length. ErrTooMuchNullData = ErrorKind("ErrTooMuchNullData") )
These constants are used to identify a specific ErrorKind.
const ( // MaxDataCarrierSizeV0 is the maximum number of bytes allowed in pushed // data to be considered a standard version 0 provably pruneable nulldata // script. MaxDataCarrierSizeV0 = 256 )
Variables ¶
This section is empty.
Functions ¶
func DetermineRequiredSigs ¶
DetermineRequiredSigs attempts to identify the number of signatures required by the passed script for the known standard types.
NOTE: Version 0 scripts are the only currently supported version. It will always return 0 for other script versions.
Similarly, 0 is returned when the script does not parse or is not one of the known standard types.
func DetermineRequiredSigsV0 ¶
DetermineRequiredSigsV0 attempts to identify the number of signatures required by the passed version 0 script for the known standard types.
It will return 0 when the script does not parse or is not one of the known standard types.
func ExtractCompressedPubKeyV0 ¶
ExtractCompressedPubKeyV0 extracts a compressed public key from the passed script if it is a standard version 0 pay-to-compressed-secp256k1-pubkey script. It will return nil otherwise.
func ExtractPubKeyAltDetailsV0 ¶
ExtractPubKeyAltDetailsV0 extracts the public key and signature type from the passed script if it is a standard version 0 pay-to-alt-pubkey script. It will return nil otherwise.
func ExtractPubKeyEd25519V0 ¶
ExtractPubKeyEd25519V0 extracts a public key from the passed script if it is a standard version 0 pay-to-ed25519-pubkey script. It will return nil otherwise.
func ExtractPubKeyHashAltDetailsV0 ¶
ExtractPubKeyHashAltDetailsV0 extracts the public key hash and signature type from the passed script if it is a standard version 0 pay-to-alt-pubkey-hash script. It will return nil otherwise.
func ExtractPubKeyHashEd25519V0 ¶
ExtractPubKeyHashEd25519V0 extracts the public key hash from the passed script if it is a standard version 0 pay-to-pubkey-hash-ed25519 script. It will return nil otherwise.
func ExtractPubKeyHashSchnorrSecp256k1V0 ¶
ExtractPubKeyHashSchnorrSecp256k1V0 extracts the public key hash from the passed script if it is a standard version 0 pay-to-pubkey-hash-schnorr-secp256k1 script. It will return nil otherwise.
func ExtractPubKeyHashV0 ¶
ExtractPubKeyHashV0 extracts the public key hash from the passed script if it is a standard version 0 pay-to-pubkey-hash-ecdsa-secp256k1 script. It will return nil otherwise.
Example ¶
This example demonstrates extracting a public key hash from a standard pay-to-pubkey-hash script for scripting language version 0.
package main import ( "encoding/hex" "fmt" "github.com/Decred-Next/dcrnd/txscript/version4/v8/stdscript" ) // hexToBytes converts the passed hex string into bytes and will panic if there // is an error. This is only provided for the hard-coded constants so errors in // the source code can be detected. It will only (and must only) be called with // hard-coded values. func hexToBytes(s string) []byte { b, err := hex.DecodeString(s) if err != nil { panic("invalid hex in source file: " + s) } return b } func main() { // Ordinarily the script version and script would be obtained from the // output of a transaction, but the version is assumed to be zero and the // script is hard coded here for the purposes of this example. script := hexToBytes("76a914e280cb6e66b96679aec288b1fbdbd4db08077a1b88ac") pkHash := stdscript.ExtractPubKeyHashV0(script) fmt.Printf("public key hash: %x\n", pkHash) }
Output: public key hash: e280cb6e66b96679aec288b1fbdbd4db08077a1b
func ExtractPubKeySchnorrSecp256k1V0 ¶
ExtractPubKeySchnorrSecp256k1V0 extracts a public key from the passed script if it is a standard version 0 pay-to-schnorr-secp256k1-pubkey script. It will return nil otherwise.
func ExtractPubKeyV0 ¶
ExtractPubKeyV0 extracts either a compressed or uncompressed public key from the passed script if it is either a standard version 0 pay-to-compressed-secp256k1-pubkey or pay-to-uncompressed-secp256k1-pubkey script, respectively. It will return nil otherwise.
func ExtractScriptHashV0 ¶
ExtractScriptHashV0 extracts the script hash from the passed script if it is a standard version 0 pay-to-script-hash script. It will return nil otherwise.
Example ¶
This example demonstrates extracting a script hash from a standard pay-to-script-hash script for script language version 0.
package main import ( "encoding/hex" "fmt" "github.com/Decred-Next/dcrnd/txscript/version4/v8/stdscript" ) // hexToBytes converts the passed hex string into bytes and will panic if there // is an error. This is only provided for the hard-coded constants so errors in // the source code can be detected. It will only (and must only) be called with // hard-coded values. func hexToBytes(s string) []byte { b, err := hex.DecodeString(s) if err != nil { panic("invalid hex in source file: " + s) } return b } func main() { // Ordinarily the script version and script would be obtained from the // output of a transaction, but the version is assumed to be zero and the // script is hard coded here for the purposes of this example. script := hexToBytes("a914433ec2ac1ffa1b7b7d027f564529c57197f9ae8887") scriptHash := stdscript.ExtractScriptHashV0(script) fmt.Printf("script hash: %x\n", scriptHash) }
Output: script hash: 433ec2ac1ffa1b7b7d027f564529c57197f9ae88
func ExtractStakeChangePubKeyHashV0 ¶
ExtractStakeChangePubKeyHashV0 extracts the public key hash from the passed script if it is a standard version 0 stake change pay-to-pubkey-hash script. It will return nil otherwise.
func ExtractStakeChangeScriptHashV0 ¶
ExtractStakeChangeScriptHashV0 extracts the script hash from the passed script if it is a standard version 0 stake change pay-to-script-hash script. It will return nil otherwise.
func ExtractStakeGenPubKeyHashV0 ¶
ExtractStakeGenPubKeyHashV0 extracts the public key hash from the passed script if it is a standard version 0 stake generation pay-to-pubkey-hash script. It will return nil otherwise.
func ExtractStakeGenScriptHashV0 ¶
ExtractStakeGenScriptHashV0 extracts the script hash from the passed script if it is a standard version 0 stake generation pay-to-script-hash script. It will return nil otherwise.
func ExtractStakePubKeyHashV0 ¶
ExtractStakePubKeyHashV0 extracts the public key hash from the passed script if it is any one of the supported standard version 0 stake-tagged pay-to-pubkey-hash scripts. It will return nil otherwise.
func ExtractStakeRevocationPubKeyHashV0 ¶
ExtractStakeRevocationPubKeyHashV0 extracts the public key hash from the passed script if it is a standard version 0 stake revocation pay-to-pubkey-hash script. It will return nil otherwise.
func ExtractStakeRevocationScriptHashV0 ¶
ExtractStakeRevocationScriptHashV0 extracts the script hash from the passed script if it is a standard version 0 stake revocation pay-to-script-hash script. It will return nil otherwise.
func ExtractStakeScriptHashV0 ¶
ExtractStakeScriptHashV0 extracts the script hash from the passed script if it is any one of the supported standard version 0 stake-tagged pay-to-script-hash scripts. It will return nil otherwise.
func ExtractStakeSubmissionPubKeyHashV0 ¶
ExtractStakeSubmissionPubKeyHashV0 extracts the public key hash from the passed script if it is a standard version 0 stake submission pay-to-pubkey-hash script. It will return nil otherwise.
func ExtractStakeSubmissionScriptHashV0 ¶
ExtractStakeSubmissionScriptHashV0 extracts the script hash from the passed script if it is a standard version 0 stake submission pay-to-script-hash script. It will return nil otherwise.
func ExtractTreasuryGenPubKeyHashV0 ¶
ExtractTreasuryGenPubKeyHashV0 extracts the public key hash from the passed script if it is a standard version 0 treasury generation pay-to-pubkey-hash script. It will return nil otherwise.
func ExtractTreasuryGenScriptHashV0 ¶
ExtractTreasuryGenScriptHashV0 extracts the script hash from the passed script if it is a standard version 0 treasury generation pay-to-script-hash script. It will return nil otherwise.
func ExtractUncompressedPubKeyV0 ¶
ExtractUncompressedPubKeyV0 extracts an uncompressed public key from the passed script if it is a standard version 0 pay-to-uncompressed-secp256k1-pubkey script. It will return nil otherwise.
func IsMultiSigScript ¶
IsMultiSigScript returns whether or not the passed script is a standard ECDSA multisig script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsMultiSigScriptV0 ¶
IsMultiSigScriptV0 returns whether or not the passed script is a standard version 0 ECDSA multisig script.
NOTE: This function is only valid for version 0 scripts. It will always return false for other script versions.
func IsMultiSigSigScript ¶
IsMultiSigSigScript returns whether or not the passed script appears to be a signature script which consists of a pay-to-script-hash multi-signature redeem script. Determining if a signature script is actually a redemption of pay-to-script-hash requires the associated public key script which is often expensive to obtain. Therefore, this makes a fast best effort guess that has a high probability of being correct by checking if the signature script ends with a data push and treating that data push as if it were a p2sh redeem script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsMultiSigSigScriptV0 ¶
IsMultiSigSigScriptV0 returns whether or not the passed script appears to be a version 0 signature script which consists of a pay-to-script-hash multi-signature redeem script. Determining if a signature script is actually a redemption of pay-to-script-hash requires the associated public key script which is often expensive to obtain. Therefore, this makes a fast best effort guess that has a high probability of being correct by checking if the signature script ends with a data push and treating that data push as if it were a p2sh redeem script.
func IsNullDataScript ¶
IsNullDataScript returns whether or not the passed script is a standard null data script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsNullDataScriptV0 ¶
IsNullDataScriptV0 returns whether or not the passed script is a standard version 0 null data script.
func IsPubKeyEd25519Script ¶
IsPubKeyEd25519Script returns whether or not the passed script is a standard pay-to-ed25519-pubkey script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsPubKeyEd25519ScriptV0 ¶
IsPubKeyEd25519ScriptV0 returns whether or not the passed script is a standard version 0 pay-to-ed25519-pubkey script.
func IsPubKeyHashEd25519Script ¶
IsPubKeyHashEd25519Script returns whether or not the passed script is a standard pay-to-pubkey-hash-ed25519 script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsPubKeyHashEd25519ScriptV0 ¶
IsPubKeyHashEd25519ScriptV0 returns whether or not the passed script is a standard version 0 pay-to-pubkey-hash-ed25519 script.
func IsPubKeyHashSchnorrSecp256k1Script ¶
IsPubKeyHashSchnorrSecp256k1Script returns whether or not the passed script is a standard pay-to-pubkey-hash-schnorr-secp256k1 script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsPubKeyHashSchnorrSecp256k1ScriptV0 ¶
IsPubKeyHashSchnorrSecp256k1ScriptV0 returns whether or not the passed script is a standard version 0 pay-to-pubkey-hash-schnorr-secp256k1 script.
func IsPubKeyHashScript ¶
IsPubKeyHashScript returns whether or not the passed script is a standard pay-to-pubkey-hash-ecdsa-secp256k1 script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsPubKeyHashScriptV0 ¶
IsPubKeyHashScriptV0 returns whether or not the passed script is a standard version 0 pay-to-pubkey-hash-ecdsa-secp256k1 script.
func IsPubKeySchnorrSecp256k1Script ¶
IsPubKeySchnorrSecp256k1Script returns whether or not the passed script is a standard pay-to-schnorr-secp256k1-pubkey script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsPubKeySchnorrSecp256k1ScriptV0 ¶
IsPubKeySchnorrSecp256k1ScriptV0 returns whether or not the passed script is a standard version 0 pay-to-schnorr-secp256k1-pubkey script.
func IsPubKeyScript ¶
IsPubKeyScript returns whether or not the passed script is either a standard pay-to-compressed-secp256k1-pubkey or pay-to-uncompressed-secp256k1-pubkey script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsPubKeyScriptV0 ¶
IsPubKeyScriptV0 returns whether or not the passed script is either a standard version 0 pay-to-compressed-secp256k1-pubkey or pay-to-uncompressed-secp256k1-pubkey script.
func IsScriptHashScript ¶
IsScriptHashScript returns whether or not the passed script is a standard pay-to-script-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsScriptHashScriptV0 ¶
IsScriptHashScriptV0 returns whether or not the passed script is a standard version 0 pay-to-script-hash script.
func IsStakeChangePubKeyHashScript ¶
IsStakeChangePubKeyHashScript returns whether or not the passed script is a standard stake change pay-to-pubkey-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsStakeChangePubKeyHashScriptV0 ¶
IsStakeChangePubKeyHashScriptV0 returns whether or not the passed script is a standard version 0 stake change pay-to-pubkey-hash script.
func IsStakeChangeScriptHashScript ¶
IsStakeChangeScriptHashScript returns whether or not the passed script is a standard stake change pay-to-script-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsStakeChangeScriptHashScriptV0 ¶
IsStakeChangeScriptHashScriptV0 returns whether or not the passed script is a standard version 0 stake change pay-to-script-hash script.
func IsStakeGenPubKeyHashScript ¶
IsStakeGenPubKeyHashScript returns whether or not the passed script is a standard stake generation pay-to-pubkey-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsStakeGenPubKeyHashScriptV0 ¶
IsStakeGenPubKeyHashScriptV0 returns whether or not the passed script is a standard version 0 stake generation pay-to-pubkey-hash script.
func IsStakeGenScriptHashScript ¶
IsStakeGenScriptHashScript returns whether or not the passed script is a standard stake generation pay-to-script-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsStakeGenScriptHashScriptV0 ¶
IsStakeGenScriptHashScriptV0 returns whether or not the passed script is a standard version 0 stake generation pay-to-script-hash script.
func IsStakeRevocationPubKeyHashScript ¶
IsStakeRevocationPubKeyHashScript returns whether or not the passed script is a standard stake revocation pay-to-pubkey-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsStakeRevocationPubKeyHashScriptV0 ¶
IsStakeRevocationPubKeyHashScriptV0 returns whether or not the passed script is a standard version 0 stake revocation pay-to-pubkey-hash script.
func IsStakeRevocationScriptHashScript ¶
IsStakeRevocationScriptHashScript returns whether or not the passed script is a standard stake revocation pay-to-script-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsStakeRevocationScriptHashScriptV0 ¶
IsStakeRevocationScriptHashScriptV0 returns whether or not the passed script is a standard version 0 stake revocation pay-to-script-hash script.
func IsStakeSubmissionPubKeyHashScript ¶
IsStakeSubmissionPubKeyHashScript returns whether or not the passed script is a standard stake submission pay-to-pubkey-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsStakeSubmissionPubKeyHashScriptV0 ¶
IsStakeSubmissionPubKeyHashScriptV0 returns whether or not the passed script is a standard version 0 stake submission pay-to-pubkey-hash script.
func IsStakeSubmissionScriptHashScript ¶
IsStakeSubmissionScriptHashScript returns whether or not the passed script is a standard stake submission pay-to-script-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsStakeSubmissionScriptHashScriptV0 ¶
IsStakeSubmissionScriptHashScriptV0 returns whether or not the passed script is a standard version 0 stake submission pay-to-script-hash script.
func IsStandardAltSignatureTypeV0 ¶
IsStandardAltSignatureTypeV0 returns whether or not the provided version 0 script opcode represents a push of a standard alt signature type.
func IsTreasuryAddScript ¶
IsTreasuryAddScript returns whether or not the passed script is a supported treasury add script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsTreasuryAddScriptV0 ¶
IsTreasuryAddScriptV0 returns whether or not the passed script is a supported version 0 treasury add script.
func IsTreasuryGenPubKeyHashScript ¶
IsTreasuryGenPubKeyHashScript returns whether or not the passed script is a standard treasury generation pay-to-pubkey-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsTreasuryGenPubKeyHashScriptV0 ¶
IsTreasuryGenPubKeyHashScriptV0 returns whether or not the passed script is a standard version 0 treasury generation pay-to-pubkey-hash script.
func IsTreasuryGenScriptHashScript ¶
IsTreasuryGenScriptHashScript returns whether or not the passed script is a standard treasury generation pay-to-script-hash script.
NOTE: Version 0 scripts are the only currently supported version. It will always return false for other script versions.
func IsTreasuryGenScriptHashScriptV0 ¶
IsTreasuryGenScriptHashScriptV0 returns whether or not the passed script is a standard version 0 treasury generation pay-to-script-hash script.
func MultiSigRedeemScriptFromScriptSigV0 ¶
MultiSigRedeemScriptFromScriptSigV0 attempts to extract a multi-signature redeem script from a version 0 P2SH-redeeming input. The script is expected to already have been checked to be a version 0 multisignature script prior to calling this function. The results are undefined for other script types.
func MultiSigScriptV0 ¶
MultiSigScriptV0 returns a valid version 0 script for a multisignature redemption where the specified threshold number of the keys in the given public keys are required to have signed the transaction for success.
The provided public keys must be serialized in the compressed format or an error with kind ErrPubKeyType will be returned.
An Error with kind ErrTooManyRequiredSigs will be returned if the threshold is larger than the number of keys provided.
func ProvablyPruneableScriptV0 ¶
ProvablyPruneableScriptV0 returns a valid version 0 provably-pruneable script which consists of an OP_RETURN followed by the passed data. An Error with kind ErrTooMuchNullData will be returned if the length of the passed data exceeds MaxDataCarrierSizeV0.
Types ¶
type AtomicSwapDataPushesV0 ¶
type AtomicSwapDataPushesV0 struct { RecipientHash160 [20]byte RefundHash160 [20]byte SecretHash [32]byte SecretSize int64 LockTime int64 }
AtomicSwapDataPushesV0 houses the data pushes found in hash-based atomic swap contracts using version 0 scripts.
func ExtractAtomicSwapDataPushesV0 ¶
func ExtractAtomicSwapDataPushesV0(redeemScript []byte) *AtomicSwapDataPushesV0
ExtractAtomicSwapDataPushesV0 returns the data pushes from an atomic swap contract using version 0 scripts if it is one. It will return nil otherwise.
NOTE: Atomic swaps are not considered standard script types by the dcrd mempool policy and should be used with P2SH. The atomic swap format is also expected to change to use a more secure hash function in the future.
type Error ¶
Error identifies an script-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 MultiSigDetailsV0 ¶
MultiSigDetailsV0 houses details extracted from a standard version 0 ECDSA multisig script.
func ExtractMultiSigScriptDetailsV0 ¶
func ExtractMultiSigScriptDetailsV0(script []byte, extractPubKeys bool) MultiSigDetailsV0
ExtractMultiSigScriptDetailsV0 attempts to extract details from the passed version 0 script if it is a standard ECDSA multisig script. The returned details struct will have the valid flag set to false otherwise.
The extract pubkeys flag indicates whether or not the pubkeys themselves should also be extracted and is provided because extracting them results in an allocation that the caller might wish to avoid. The PubKeys member of the returned details struct will be nil when the flag is false.
type ScriptType ¶
type ScriptType byte
ScriptType identifies the type of known scripts in the blockchain that are typically considered standard by the default policy of most nodes. All other scripts are considered non-standard.
const ( // STNonStandard indicates a script is none of the recognized standard // forms. STNonStandard ScriptType = iota // STPubKeyEcdsaSecp256k1 identifies a standard script that imposes an // encumbrance that requires a valid ECDSA signature for a specific // secp256k1 public key. // // This is commonly referred to as either a pay-to-pubkey (P2PK) script or // the more specific pay-to-pubkey-ecdsa-secp256k1 script. STPubKeyEcdsaSecp256k1 // STPubKeyEd25519 identifies a standard script that imposes an encumbrance // that requires a valid Ed25519 signature for a specific Ed25519 public // key. // // This is commonly referred to as a pay-to-pubkey-ed25519 script. STPubKeyEd25519 // STPubKeySchnorrSecp256k1 identifies a standard script that imposes an // encumbrance that requires a valid EC-Schnorr-DCRv0 signature for a // specific secp256k1 public key. // // This is commonly referred to as a pay-to-pubkey-schnorr-secp256k1 script. STPubKeySchnorrSecp256k1 // STPubKeyHashEcdsaSecp256k1 identifies a standard script that imposes an // encumbrance that requires a secp256k1 public key that hashes to a // specific value along with a valid ECDSA signature for that public key. // // This is commonly referred to as either a pay-to-pubkey-hash (P2PKH) // script or the more specific pay-to-pubkey-hash-ecdsa-secp256k1 script. STPubKeyHashEcdsaSecp256k1 // STPubKeyHashEd25519 identifies a standard script that imposes an // encumbrance that requires an Ed25519 public key that hashes to a specific // value along with a valid Ed25519 signature for that public key. // // This is commonly referred to as a pay-to-pubkey-hash-ed25519 script. STPubKeyHashEd25519 // STPubKeyHashSchnorrSecp256k1 identifies a standard script that imposes an // encumbrance that requires a secp256k1 public key that hashes to a // specific value along with a valid EC-Schnorr-DCRv0 signature for that // public key. // // This is commonly referred to as a pay-to-pubkey-hash-schnorr-secp256k1 // script. STPubKeyHashSchnorrSecp256k1 // STScriptHash identifies a standard script that imposes an encumbrance // that requires a script that hashes to a specific value 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). STScriptHash // STMultiSig identifies a standard script that imposes an encumbrance that // requires a given number of valid ECDSA signatures which correspond to // given secp256k1 public keys. // // This is commonly referred to as a standard ECDSA n-of-m multi-signature // script. STMultiSig // STNullData identifies a standard null data script that is provably // prunable. STNullData // STStakeSubmissionPubKeyHash identifies a script that is only valid when // used as part of a ticket purchase transaction in the staking system and // is used for imposing voting rights. // // It imposes an encumbrance that requires a secp256k1 public key that // hashes to a specific value along with a valid ECDSA signature for that // public key. STStakeSubmissionPubKeyHash // STStakeSubmissionScriptHash identifies a script that is only valid when // used as part of a ticket purchase transaction in the staking system and // is used for imposing voting rights. // // It imposes an encumbrance that requires a script that hashes to a // specific value along with all of the encumbrances that script itself // imposes. The script is commonly referred to as a redeem script. STStakeSubmissionScriptHash // STStakeGenPubKeyHash identifies a script that is only valid when used as // part of a vote transaction in the staking system. // // It imposes an encumbrance that requires a secp256k1 public key that // hashes to a specific value along with a valid ECDSA signature for that // public key. STStakeGenPubKeyHash // STStakeGenScriptHash identifies a script that is only valid when used as // part of a vote transaction in the staking system. // // It imposes an encumbrance that requires a script that hashes to a // specific value along with all of the encumbrances that script itself // imposes. The script is commonly referred to as a redeem script. STStakeGenScriptHash // STStakeRevocationPubKeyHash identifies a script that is only valid when // used as part of a revocation transaction in the staking system. // // It imposes an encumbrance that requires a secp256k1 public key that // hashes to a specific value along with a valid ECDSA signature for that // public key. STStakeRevocationPubKeyHash // STStakeRevocationScriptHash identifies a script that is only valid when // used as part of a revocation transaction in the staking system. // // It imposes an encumbrance that requires a script that hashes to a // specific value along with all of the encumbrances that script itself // imposes. The script is commonly referred to as a redeem script. STStakeRevocationScriptHash // STStakeChangePubKeyHash identifies a script that is only valid when used // as part of supported transactions in the staking system. // // It imposes an encumbrance that requires a secp256k1 public key that // hashes to a specific value along with a valid ECDSA signature for that // public key. STStakeChangePubKeyHash // STStakeChangeScriptHash identifies a script that is only valid when used // as part of supported transactions in the staking system. // // It imposes an encumbrance that requires a script that hashes to a // specific value along with all of the encumbrances that script itself // imposes. The script is commonly referred to as a redeem script. STStakeChangeScriptHash // STTreasuryAdd identifies a script that is only valid when used as part // supported transactions in the staking system and adds value to the // treasury account. STTreasuryAdd // STTreasuryGenPubKeyHash identifies a script that is only valid when used // as part supported transactions in the staking system and generates utxos // from the treasury account. // // It imposes an encumbrance that requires a secp256k1 public key that // hashes to a specific value along with a valid ECDSA signature for that // public key. STTreasuryGenPubKeyHash // STTreasuryGenScriptHash identifies a script that is only valid when used // as part supported transactions in the staking system and generates utxos // from the treasury account. // // It imposes an encumbrance that requires a script that hashes to a // specific value along with all of the encumbrances that script itself // imposes. The script is commonly referred to as a redeem script. STTreasuryGenScriptHash )
func DetermineScriptType ¶
func DetermineScriptType(scriptVersion uint16, script []byte) ScriptType
DetermineScriptType returns the type of the script passed.
NOTE: Version 0 scripts are the only currently supported version. It will always return STNonStandard for other script versions.
Similarly, STNonStandard is returned when the script does not parse.
Example ¶
This example demonstrates determining the type of a script for a given scripting language version.
package main import ( "encoding/hex" "fmt" "github.com/Decred-Next/dcrnd/txscript/version4/v8/stdscript" ) // hexToBytes converts the passed hex string into bytes and will panic if there // is an error. This is only provided for the hard-coded constants so errors in // the source code can be detected. It will only (and must only) be called with // hard-coded values. func hexToBytes(s string) []byte { b, err := hex.DecodeString(s) if err != nil { panic("invalid hex in source file: " + s) } return b } func main() { // Ordinarily the script version and script would be obtained from the // output of a transaction, but they are hard coded here for the purposes of // this example. const scriptVersion = 0 script := hexToBytes("76a914e280cb6e66b96679aec288b1fbdbd4db08077a1b88ac") scriptType := stdscript.DetermineScriptType(scriptVersion, script) switch scriptType { case stdscript.STPubKeyHashEcdsaSecp256k1: fmt.Printf("standard version %d %v script\n", scriptVersion, scriptType) default: fmt.Printf("other script type: %v\n", scriptType) } }
Output: standard version 0 pubkeyhash script
func DetermineScriptTypeV0 ¶
func DetermineScriptTypeV0(script []byte) ScriptType
DetermineScriptTypeV0 returns the type of the passed version 0 script for the known standard types. This includes both types that are required by consensus as well as those which are not.
STNonStandard will be returned when the script does not parse.
func ExtractAddrs ¶
func ExtractAddrs(scriptVersion uint16, pkScript []byte, params stdaddr.AddressParamsV0) (ScriptType, []stdaddr.Address)
ExtractAddrs analyzes the passed public key script and returns the associated script type along with any addresses associated with it when possible.
This function only works for standard script types and any data that fails to produce a valid address is omitted from the results. This means callers must not blindly assume the slice will be of a particular length for a given returned script type and should always check the length prior to access in case the addresses were not able to be created.
NOTE: Version 0 scripts are the only currently supported version. It will always return a nonstandard script type and no addresses for other script versions.
func ExtractAddrsV0 ¶
func ExtractAddrsV0(pkScript []byte, params stdaddr.AddressParamsV0) (ScriptType, []stdaddr.Address)
ExtractAddrsV0 analyzes the passed version 0 public key script and returns the associated script type along with any addresses associated with it when possible.
This function only works for standard script types and any data that fails to produce a valid address is omitted from the results. This means callers must not blindly assume the slice will be of a particular length for a given returned script type and should always check the length prior to access in case the addresses were not able to be created.
func (ScriptType) String ¶
func (t ScriptType) String() string
String returns the ScriptType as a human-readable name.