package
1.9.25
Repository: https://github.com/p9c/pod.git
Documentation: pkg.go.dev

# README

txscript

ISC License GoDoc

Package txscript implements the bitcoin transaction script language. There is a comprehensive test suite.

This package has intentionally been designed so it can be used as a standalone package for any projects needing to use or validate bitcoin transaction scripts.

Bitcoin Scripts

Bitcoin provides a stack-based, FORTH-like language for the scripts in the bitcoin transactions. This language is not turing complete although it is still fairly powerful. A description of the language can be found at https://en.bitcoin.it/wiki/Script

Installation and Updating

$ go get -u github.com/p9c/pod/txscript

Examples

License

Package txscript is licensed under the copyfree ISC License.

# Functions

CalcMultiSigStats returns the number of public keys and signatures from a multi-signature transaction script.
CalcScriptInfo returns a structure providing data about the provided script pair.
CalcSignatureHash will given a script and hash type for the current script engine instance calculate the signature hash to be used for signing and verification.
CalcWitnessSigHash computes the sighash digest for the specified input of the target transaction observing the desired sig hash type.
DisasmString formats a disassembled script for one line printing.
ExtractAtomicSwapDataPushes returns the data pushes from an atomic swap contract.
ExtractPkScriptAddrs returns the type of script, addresses and required signatures associated with the passed PkScript.
GetPreciseSigOpCount returns the number of signature operations in scriptPubKey.
GetScriptClass returns the class of the script passed.
GetSigOpCount provides a quick count of the number of signature operations in a script.
IsErrorCode returns whether or not the provided error is a script error with the provided error code.
IsPayToScriptHash returns true if the script is in the standard pay -to-script-hash (P2SH) format, false otherwise.
IsPayToWitnessPubKeyHash returns true if the is in the standard pay -to-witness-pubkey-hash (P2WKH) format, false otherwise.
IsPayToWitnessScriptHash returns true if the is in the standard pay -to-witness-script-hash (P2WSH) format, false otherwise.
No description provided by the author
IsUnspendable returns whether the passed public key script is unspendable, or guaranteed to fail at execution.
IsWitnessProgram returns true if the passed script is a valid witness program which is encoded according to the passed witness program version.
MultiSigScript returns a valid script for a multisignature redemption where nrequired of the keys in pubkeys are required to have signed the transaction for success.
NewEngine returns a new script engine for the provided public key script, transaction, and input index.
NewHashCache returns a new instance of the HashCache given a maximum number of entries which may exist within it at anytime.
NewScriptBuilder returns a new instance of a script builder.
NewSigCache creates and initializes a new instance of SigCache.
NewTxSigHashes computes, and returns the cached sighashes of the given transaction.
NullDataScript creates a provably-prunable script containing OP_RETURN followed by the passed data.
ParseScriptTemplate is the same as parseScript but allows the passing of the template list for testing purposes.
PayToAddrScript creates a new script to pay a transaction output to a the specified address.
PushedData returns an array of byte slices containing any pushed data found in the passed script.
RawTxInSignature returns the serialized ECDSA signature for the input idx of the given transaction, with hashType appended to it.
RawTxInWitnessSignature returns the serialized ECDSA signature for the input idx of the given transaction, with the hashType appended to it.
SignatureScript creates an input signature script for tx to spend DUO sent from a previous output to the owner of privKey.
SignTxOutput signs output idx of the given tx to resolve the script given in pkScript with a signature type of hashType.
WitnessSignature creates an input witness stack for tx to spend DUO sent from a previous output to the owner of privKey using the p2wkh script template.

# Constants

ErrCheckMultiSigVerify is returned when OP_CHECKMULTISIGVERIFY is encountered in a script and the top item on the data stack does not evaluate to true.
ErrCheckSigVerify is returned when OP_CHECKSIGVERIFY is encountered in a script and the top item on the data stack does not evaluate to true.
ErrCleanStack is returned when the ScriptVerifyCleanStack flag is set, and after evalution, the stack does not contain only a single element.
ErrDisabledOpcode is returned when a disabled opcode is encountered in a script.
ErrDiscourageUpgradableNOPs is returned when the ScriptDiscourageUpgradableNops flag is set and a NOP opcode is encountered in a script.
ErrDiscourageUpgradableWitnessProgram is returned if ScriptVerifyWitness is set and the versino of an executing witness program is outside the set of currently defined witness program vesions.
ErrEarlyReturn is returned when OP_RETURN is executed in the script.
ErrElementTooBig is returned if the size of an element to be pushed to the stack is over MaxScriptElementSize.
ErrEmptyStack is returned when the script evaluated without error, but terminated with an empty top stack element.
ErrEqualVerify is returned when OP_EQUALVERIFY is encountered in a script and the top item on the data stack does not evaluate to true.
ErrEvalFalse is returned when the script evaluated without error but terminated with a false top stack element.
ErrInternal is returned if internal consistency checks fail.
ErrInvalidFlags is returned when the passed flags to NewEngine contain an invalid combination.
ErrInvalidIndex is returned when an out-of-bounds index is passed to a function.
ErrInvalidProgramCounter is...
ErrInvalidPubKeyCount is returned when the number of public keys specified for a multsig is either negative or greater than MaxPubKeysPerMultiSig.
ErrInvalidSigHashType is returned when a signature hash type is not one of the supported types.
ErrInvalidSignatureCount is returned when the number of signatures specified for a multisig is either negative or greater than the number of public keys.
ErrInvalidStackOperation is returned when a stack operation is attempted with a number that is invalid for the current stack size.
ErrMalformedPush is returned when a data push opcode tries to push more bytes than are left in the script.
ErrMinimalData is returned when the ScriptVerifyMinimalData flag is set and the script contains push operations that do not use the minimal opcode required.
ErrMinimalIf is returned if ScriptVerifyWitness is set and the operand of an OP_IF/OP_NOF_IF are not either an empty vector or [0x01].
ErrNegativeLockTime is returned when a script contains an opcode that interprets a negative lock time.
ErrNotMultisigScript is returned from CalcMultiSigStats when the provided script is not a multisig script.
ErrNotPushOnly is returned when a script that is required to only push data to the stack performs other operations.
ErrNullFail is returned when the ScriptVerifyNullFail flag is set and signatures are not empty on failed checksig or checkmultisig operations.
ErrNumberTooBig is returned when the argument for an opcode that expects numeric input is larger than the expected maximum number of bytes.
ErrNumEqualVerify is returned when OP_NUMEQUALVERIFY is encountered in a script and the top item on the data stack does not evaluate to true.
ErrPubKeyType is returned when the ScriptVerifyStrictEncoding flag is set and the script contains invalid public keys.
ErrReservedOpcode is returned when an opcode marked as reserved is encountered in a script.
ErrScriptTooBig is returned if a script is larger than MaxScriptSize.
ErrScriptUnfinished is returned when CheckErrorCondition is called on a script that has not finished executing.
ErrSigHighS is returned when the ScriptVerifyLowS flag is set and the script contains any signatures whose S values are higher than the half order.
ErrSigInvalidDataLen is returned a signature that should be a canonically-encoded DER signature does not specify the correct number of remaining bytes for the R and S portions.
ErrSigInvalidRIntID is returned when a signature that should be a canonically-encoded DER signature does not have the expected ASN.1 integer ID for R.
ErrSigInvalidSeqID is returned when a signature that should be a canonically-encoded DER signature does not have the expected ASN.1 sequence ID.
ErrSigInvalidSIntID is returned when a signature that should be a canonically-encoded DER signature does not have the expected ASN.1 integer ID for S.
ErrSigInvalidSLen is returned a signature that should be a canonically-encoded DER signature does not specify the correct number of bytes for the S portion.
ErrSigMissingSLen is returned when a signature that should be a canonically-encoded DER signature does not provide the length of S.
ErrSigMissingSTypeID is returned a signature that should be a canonically-encoded DER signature does not provide the ASN.1 type ID for S.
ErrSigNegativeR is returned when a signature that should be a canonically-encoded DER signature has a negative value for R.
ErrSigNegativeS is returned when a signature that should be a canonically-encoded DER signature has a negative value for S.
ErrSigNullDummy is returned when the ScriptStrictMultiSig flag is set and a multisig script has anything other than 0 for the extra dummy argument.
ErrSigTooLong is returned when a signature that should be a canonically-encoded DER signature is too long.
ErrSigTooMuchRPadding is returned when a signature that should be a canonically-encoded DER signature has too much padding for R.
ErrSigTooMuchSPadding is returned when a signature that should be a canonically-encoded DER signature has too much padding for S.
ErrSigTooShort is returned when a signature that should be a canonically-encoded DER signature is too short.
ErrSigZeroRLen is returned when a signature that should be a canonically-encoded DER signature has an R length of zero.
ErrSigZeroSLen is returned when a signature that should be a canonically-encoded DER signature has an S length of zero.
ErrStackOverflow is returned when stack and altstack combined depth is over the limit.
ErrTooManyOperations is returned if a script has more than MaxOpsPerScript opcodes that do not push data.
ErrTooManyRequiredSigs is returned from MultiSigScript when the specified number of required signatures is larger than the number of provided public keys.
ErrTooMuchNullData is returned from NullDataScript when the length of the provided data exceeds MaxDataCarrierSize.
ErrUnbalancedConditional is returned when an OP_ELSE or OP_ENDIF is encountered in a script without first having an OP_IF or OP_NOTIF or the end of script is reached without encountering an OP_ENDIF when an OP_IF or OP_NOTIF was previously encountered.
ErrUnsatisfiedLockTime is returned when a script contains an opcode that involves a lock time and the required lock time has not been reached.
ErrUnsupportedAddress is returned when a concrete type that implements a util.Address is not a supported type.
ErrVerify is returned when OP_VERIFY is encountered in a script and the top item on the data stack does not evaluate to true.
ErrWitnessMalleated is returned if ScriptVerifyWitness is set and a native p2wsh program is encountered which has a non-empty sigScript.
ErrWitnessMalleatedP2SH is returned if ScriptVerifyWitness if set and the validation logic for nested p2sh encounters a sigScript which isn't *exactyl* a datapush of the witness program.
ErrWitnessProgramEmpty is returned if ScriptVerifyWitness is set and the witness stack itself is empty.
ErrWitnessProgramMismatch is returned if ScriptVerifyWitness is set and the witness itself for a p2wkh witness program isn't *exactly* 2 items or if the witness for a p2wsh isn't the sha255 of the witness script.
ErrWitnessProgramWrongLength is returned if ScriptVerifyWitness is set and the length of the witness program violates the length as dictated by the current witness version.
ErrWitnessPubKeyType is returned if ScriptVerifyWitness is set and the public key used in either a check-sig or check-multi-sig isn't serialized in a compressed format.
ErrWitnessUnexpected is returned if ScriptVerifyWitness is set and a transaction includes witness data but doesn't spend an which is a witness program (nested or native).
Tue Nov 5 00:53:20 1985 UTC.
MaxDataCarrierSize is the maximum number of bytes allowed in pushed data to be considered a nulldata transaction.
Max number of non-push operations.
Multisig can't have more sigs than this.
Max bytes pushable to the stack.
MaxScriptSize is the maximum allowed length of a raw script.
MaxStackSize is the maximum combined height of stack and alt stack during execution.
Multi signature.
None of the recognized forms.
Empty data-only (provably prunable).
0.
146.
81 - AKA OP_TRUE.
90.
91.
92.
93.
94.
95.
96.
139.
79.
140.
82.
142.
109.
110.
141.
112.
113.
114.
83.
111.
84.
85.
86.
87.
88.
89.
144.
147.
132.
154.
155.
126.
177 - AKA OP_NOP2.
174.
175.
178 - AKA OP_NOP3.
172.
173.
171.
1.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
2.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
3.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
4.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
5.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
6.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
7.
70.
71.
72.
73.
74.
75.
8.
9.
116.
150.
117.
118.
103.
104.
135.
136.
0 - AKA OP_0.
108.
160.
162.
169.
170.
99.
115.
255 - bitcoin core internal.
131.
128.
159.
161.
152.
164.
163.
151.
149.
143.
119.
97.
176.
185.
177.
178.
179.
180.
181.
182.
183.
184.
145.
100.
156.
157.
158.
133.
120.
121.
254 - bitcoin core internal.
253 - bitcoin core internal.
251 - bitcoin core internal.
76.
77.
78.
80.
137.
138.
106.
129.
166.
122.
123.
153.
167.
168.
130.
250 - bitcoin core internal.
148.
127.
124.
107.
81.
125.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
252.
98.
101.
105.
102.
165.
134.
No description provided by the author
No description provided by the author
No description provided by the author
Pay pubkey hash.
Pay pubkey.
ScriptBip16 defines whether the bip16 threshold has passed and thus pay-to-script hash transactions will be fully validated.
ScriptDiscourageUpgradableNops defines whether to verify that NOP1 through NOP10 are reserved for future soft-fork upgrades.
Pay to script hash.
ScriptStrictMultiSig defines whether to verify the stack item used by CHECKMULTISIG is zero length.
ScriptVerifyCheckLockTimeVerify defines whether to verify that a transaction output is spendable based on the locktime.
ScriptVerifyCheckSequenceVerify defines whether to allow execution pathways of a script to be restricted based on the age of the output being spent.
ScriptVerifyCleanStack defines that the stack must contain only one stack element after evaluation and that the element must be true if interpreted as a boolean.
ScriptVerifyDERSignatures defines that signatures are required to compily with the DER format.
ScriptVerifyDiscourageUpgradeableWitnessProgram makes witness program with versions 2-16 non-standard.
ScriptVerifyLowS defines that signtures are required to comply with the DER format and whose S value is <= order / 2.
ScriptVerifyMinimalData defines that signatures must use the smallest push operator.
ScriptVerifyMinimalIf makes a script with an OP_IF/OP_NOTIF whose operand is anything other than empty vector or [0x01] non-standard.
ScriptVerifyNullFail defines that signatures must be empty if a CHECKSIG or CHECKMULTISIG operation fails.
ScriptVerifySigPushOnly defines that signature scripts must contain only pushed data.
ScriptVerifyStrictEncoding defines that signature scripts and public keys must follow the strict encoding requirements.
ScriptVerifyWitness defines whether or not to verify a transaction output using a witness program template.
ScriptVerifyWitnessPubKeyType makes a script within a check-sig operation whose public key isn't serialized in a compressed format non-standard.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
StandardVerifyFlags are the script flags which are used when executing transaction scripts to enforce additional checks which are required for the script to be considered standard.

# Variables

Bip16Activation is the timestamp where BIP0016 is valid to use in the blockchain.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OpcodeArray holds details about all possible opcodes such as how many bytes the opcode and any associated data should take, its human-readable name, and the handler function.
OpcodeByName is a map that can be used to lookup an opcode by its human-readable name (OP_CHECKMULTISIG, OP_CHECKSIG, etc).
No description provided by the author
No description provided by the author

# Structs

AtomicSwapDataPushes houses the data pushes found in atomic swap contracts.
Engine is the virtual machine that executes scripts.
HashCache houses a set of partial sighashes keyed by txid.
ScriptBuilder provides a facility for building custom scripts.
ScriptError identifies a script-related error.
ScriptInfo houses information about a script pair that is determined by CalcScriptInfo.
SigCache implements an ECDSA signature verification cache with a randomized entry eviction policy.
TxSigHashes houses the partial set of sighashes introduced within BIP0143.

# Interfaces

KeyDB is an interface type provided to SignTxOutput, it encapsulates any user state required to get the private keys for an address.
ScriptDB is an interface type provided to SignTxOutput, it encapsulates any user state required to get the scripts for an pay-to-script-hash address.

# Type aliases

ErrorCode identifies a kind of script error.
ErrScriptNotCanonical identifies a non-canonical script.
KeyClosure implements KeyDB with a closure.
ScriptClass is an enumeration for the list of standard types of script.
ScriptClosure implements ScriptDB with a closure.
ScriptFlags is a bitmask defining additional operations or tests that will be done when executing a script pair.
No description provided by the author