bitcoins.txscript library

Classes

KeyClosure
KeyClosureResp
OpCode
An opcode defines the information related to a txscript opcode. opfunc, if present, is the function to call to perform the opcode on the script. The current script is passed in as a slice with the first member being the opcode itself.
ParsedOpcode
ScriptBuilder
ScriptClosure
TxSigHashes

Constants

DEFAULT_SCRIPT_VERSION → const int
DefaultScriptVersion is the default scripting language version representing extended Demos script.
0
MAX_DATA_CARRIER_SIZE → const int
256
MAX_SCRIPT_ELEMENT_SIZE → const int
Multisig can't have more sigs than this.
2048
MAX_SCRIPT_SIZE → const int
MaxScriptSize is the maximum allowed length of a raw script.
16384
MAX_STACK_SIZE → const int
MaxStackSize is the maximum combined height of stack and alt stack during execution.
1024
NON_STANDARD_TY → const int
0
NULL_DATA_TY → const int
Multi signature.
7
OP_0 → const int
0x00
OP_0NOTEQUAL → const int
0x92
OP_1 → const int
0x51
OP_1ADD → const int
0x8b
OP_1NEGATE → const int
0x4f
OP_1SUB → const int
0x8c
OP_2 → const int
0x52
OP_2DIV → const int
0x8e
OP_2DROP → const int
0x6d
OP_2DUP → const int
0x6e
OP_2MUL → const int
0x8d
OP_2OVER → const int
0x70
OP_2ROT → const int
0x71
OP_2SWAP → const int
0x72
OP_3 → const int
0x53
OP_3DUP → const int
0x6f
OP_4 → const int
0x54
OP_5 → const int
0x55
OP_6 → const int
0x56
OP_7 → const int
0x57
OP_8 → const int
0x58
OP_9 → const int
0x59
OP_10 → const int
0x5a
OP_11 → const int
0x5b
OP_12 → const int
0x5c
OP_13 → const int
0x5d
OP_14 → const int
0x5e
OP_15 → const int
0x5f
OP_16 → const int
0x60
OP_ABS → const int
0x90
OP_ADD → const int
0x93
OP_AND → const int
0x84
OP_BOOLAND → const int
0x9a
OP_BOOLOR → const int
0x9b
OP_CAT → const int
0x7e
OP_CHECKLOCKTIMEVERIFY → const int
0xb1
OP_CHECKMULTISIG → const int
0xae
OP_CHECKMULTISIGVERIFY → const int
0xaf
OP_CHECKSEQUENCEVERIFY → const int
0xb2
OP_CHECKSIG → const int
0xac
OP_CHECKSIGVERIFY → const int
0xad
OP_CODESEPARATOR → const int
0xab
OP_COND_FALSE → const int
Conditional execution constants.
0
OP_COND_SKIP → const int
2
OP_COND_TRUE → const int
1
OP_DATA_1 → const int
0x01
OP_DATA_2 → const int
0x02
OP_DATA_3 → const int
0x03
OP_DATA_4 → const int
0x04
OP_DATA_5 → const int
0x05
OP_DATA_6 → const int
0x06
OP_DATA_7 → const int
0x07
OP_DATA_8 → const int
0x08
OP_DATA_9 → const int
0x09
OP_DATA_10 → const int
0x0a
OP_DATA_11 → const int
0x0b
OP_DATA_12 → const int
0x0c
OP_DATA_13 → const int
0x0d
OP_DATA_14 → const int
0x0e
OP_DATA_15 → const int
0x0f
OP_DATA_16 → const int
0x10
OP_DATA_17 → const int
0x11
OP_DATA_18 → const int
0x12
OP_DATA_19 → const int
0x13
OP_DATA_20 → const int
0x14
OP_DATA_21 → const int
0x15
OP_DATA_22 → const int
0x16
OP_DATA_23 → const int
0x17
OP_DATA_24 → const int
0x18
OP_DATA_25 → const int
0x19
OP_DATA_26 → const int
0x1a
OP_DATA_27 → const int
0x1b
OP_DATA_28 → const int
0x1c
OP_DATA_29 → const int
0x1d
OP_DATA_30 → const int
0x1e
OP_DATA_31 → const int
0x1f
OP_DATA_32 → const int
0x20
OP_DATA_33 → const int
0x21
OP_DATA_34 → const int
0x22
OP_DATA_35 → const int
0x23
OP_DATA_36 → const int
0x24
OP_DATA_37 → const int
0x25
OP_DATA_38 → const int
0x26
OP_DATA_39 → const int
0x27
OP_DATA_40 → const int
0x28
OP_DATA_41 → const int
0x29
OP_DATA_42 → const int
0x2a
OP_DATA_43 → const int
0x2b
OP_DATA_44 → const int
0x2c
OP_DATA_45 → const int
0x2d
OP_DATA_46 → const int
0x2e
OP_DATA_47 → const int
0x2f
OP_DATA_48 → const int
0x30
OP_DATA_49 → const int
0x31
OP_DATA_50 → const int
0x32
OP_DATA_51 → const int
0x33
OP_DATA_52 → const int
0x34
OP_DATA_53 → const int
0x35
OP_DATA_54 → const int
0x36
OP_DATA_55 → const int
0x37
OP_DATA_56 → const int
0x38
OP_DATA_57 → const int
0x39
OP_DATA_58 → const int
0x3a
OP_DATA_59 → const int
0x3b
OP_DATA_60 → const int
0x3c
OP_DATA_61 → const int
0x3d
OP_DATA_62 → const int
0x3e
OP_DATA_63 → const int
0x3f
OP_DATA_64 → const int
0x40
OP_DATA_65 → const int
0x41
OP_DATA_66 → const int
0x42
OP_DATA_67 → const int
0x43
OP_DATA_68 → const int
0x44
OP_DATA_69 → const int
0x45
OP_DATA_70 → const int
0x46
OP_DATA_71 → const int
0x47
OP_DATA_72 → const int
0x48
OP_DATA_73 → const int
0x49
OP_DATA_74 → const int
0x4a
OP_DATA_75 → const int
0x4b
OP_DEPTH → const int
0x74
OP_DIV → const int
0x96
OP_DROP → const int
0x75
OP_DUP → const int
0x76
OP_ELSE → const int
0x67
OP_ENDIF → const int
0x68
OP_EQUAL → const int
0x87
OP_EQUALVERIFY → const int
0x88
OP_FALSE → const int
0x00
OP_FROMALTSTACK → const int
0x6c
OP_GREATERTHAN → const int
0xa0
OP_GREATERTHANOREQUAL → const int
0xa2
OP_HASH160 → const int
0xa9
OP_HASH256 → const int
0xaa
OP_IF → const int
0x63
OP_IFDUP → const int
0x73
OP_INVALIDOPCODE → const int
0xff
OP_INVERT → const int
0x83
OP_LEFT → const int
0x80
OP_LESSTHAN → const int
0x9f
OP_LESSTHANOREQUAL → const int
0xa1
OP_LSHIFT → const int
0x98
OP_MAX → const int
0xa4
OP_MIN → const int
0xa3
OP_MOD → const int
0x97
OP_MUL → const int
0x95
OP_NEGATE → const int
0x8f
OP_NIP → const int
0x77
OP_NOP → const int
0x61
OP_NOP1 → const int
0xb0
OP_NOP2 → const int
0xb1
OP_NOP3 → const int
0xb2
OP_NOP4 → const int
0xb3
OP_NOP5 → const int
0xb4
OP_NOP6 → const int
0xb5
OP_NOP7 → const int
0xb6
OP_NOP8 → const int
0xb7
OP_NOP9 → const int
0xb8
OP_NOP10 → const int
0xb9
OP_NOT → const int
0x91
OP_NOTIF → const int
0x64
OP_NUMEQUAL → const int
0x9c
OP_NUMEQUALVERIFY → const int
0x9d
OP_NUMNOTEQUAL → const int
0x9e
OP_OR → const int
0x85
OP_OVER → const int
0x78
OP_PICK → const int
0x79
OP_PUBKEY → const int
0xfe
OP_PUBKEYHASH → const int
0xfd
OP_PUBKEYS → const int
0xfb
OP_PUSHDATA1 → const int
0x4c
OP_PUSHDATA2 → const int
0x4d
OP_PUSHDATA4 → const int
0x4e
OP_RESERVED → const int
0x50
OP_RESERVED1 → const int
0x89
OP_RESERVED2 → const int
0x8a
OP_RETURN → const int
0x6a
OP_RIGHT → const int
0x81
OP_RIPEMD160 → const int
0xa6
OP_ROLL → const int
0x7a
OP_ROT → const int
0x7b
OP_RSHIFT → const int
0x99
OP_SHA1 → const int
0xa7
OP_SHA256 → const int
0xa8
OP_SIZE → const int
0x82
OP_SMALLINTEGER → const int
0xfa
OP_SUB → const int
0x94
OP_SUBSTR → const int
0x7f
OP_SWAP → const int
0x7c
OP_TOALTSTACK → const int
0x6b
OP_TRUE → const int
0x51
OP_TUCK → const int
0x7d
OP_UNKNOWN186 → const int
0xba
OP_UNKNOWN187 → const int
0xbb
OP_UNKNOWN188 → const int
0xbc
OP_UNKNOWN189 → const int
0xbd
OP_UNKNOWN190 → const int
0xbe
OP_UNKNOWN191 → const int
0xbf
OP_UNKNOWN192 → const int
0xc0
OP_UNKNOWN193 → const int
0xc1
OP_UNKNOWN194 → const int
0xc2
OP_UNKNOWN195 → const int
0xc3
OP_UNKNOWN196 → const int
0xc4
OP_UNKNOWN197 → const int
0xc5
OP_UNKNOWN198 → const int
0xc6
OP_UNKNOWN199 → const int
0xc7
OP_UNKNOWN200 → const int
0xc8
OP_UNKNOWN201 → const int
0xc9
OP_UNKNOWN202 → const int
0xca
OP_UNKNOWN203 → const int
0xcb
OP_UNKNOWN204 → const int
0xcc
OP_UNKNOWN205 → const int
0xcd
OP_UNKNOWN206 → const int
0xce
OP_UNKNOWN207 → const int
0xcf
OP_UNKNOWN208 → const int
0xd0
OP_UNKNOWN209 → const int
0xd1
OP_UNKNOWN210 → const int
0xd2
OP_UNKNOWN211 → const int
0xd3
OP_UNKNOWN212 → const int
0xd4
OP_UNKNOWN213 → const int
0xd5
OP_UNKNOWN214 → const int
0xd6
OP_UNKNOWN215 → const int
0xd7
OP_UNKNOWN216 → const int
0xd8
OP_UNKNOWN217 → const int
0xd9
OP_UNKNOWN218 → const int
0xda
OP_UNKNOWN219 → const int
0xdb
OP_UNKNOWN220 → const int
0xdc
OP_UNKNOWN221 → const int
0xdd
OP_UNKNOWN222 → const int
0xde
OP_UNKNOWN223 → const int
0xdf
OP_UNKNOWN224 → const int
0xe0
OP_UNKNOWN225 → const int
0xe1
OP_UNKNOWN226 → const int
0xe2
OP_UNKNOWN227 → const int
0xe3
OP_UNKNOWN228 → const int
0xe4
OP_UNKNOWN229 → const int
0xe5
OP_UNKNOWN230 → const int
0xe6
OP_UNKNOWN231 → const int
0xe7
OP_UNKNOWN232 → const int
0xe8
OP_UNKNOWN233 → const int
0xe9
OP_UNKNOWN234 → const int
0xea
OP_UNKNOWN235 → const int
0xeb
OP_UNKNOWN236 → const int
0xec
OP_UNKNOWN237 → const int
0xed
OP_UNKNOWN238 → const int
0xee
OP_UNKNOWN239 → const int
0xef
OP_UNKNOWN240 → const int
0xf0
OP_UNKNOWN241 → const int
0xf1
OP_UNKNOWN242 → const int
0xf2
OP_UNKNOWN243 → const int
0xf3
OP_UNKNOWN244 → const int
0xf4
OP_UNKNOWN245 → const int
0xf5
OP_UNKNOWN246 → const int
0xf6
OP_UNKNOWN247 → const int
0xf7
OP_UNKNOWN248 → const int
0xf8
OP_UNKNOWN249 → const int
0xf9
OP_UNKNOWN252 → const int
0xfc
OP_VER → const int
0x62
OP_VERIF → const int
0x65
OP_VERIFY → const int
0x69
OP_VERNOTIF → const int
0x66
OP_WITHIN → const int
0xa5
OP_XOR → const int
0x86
PUB_KEY_HASH_TY → const int
Pay pubkey.
2
PUB_KEY_TY → const int
None of the recognized forms.
1
SCRIPT_HASH_TY → const int
Pay pubkey hash.
4
SIG_HASH_ALL → const int
0x1
SIG_HASH_ANY_ONE_CAN_PAY → const int
0x80
SIG_HASH_MASK → const int
0x1f
SIG_HASH_NONE → const int
0x2
SIG_HASH_SINGLE → const int
0x3
WITNESS_V0_PUB_KEY_HASH_TY → const int
3
WITNESS_V0_SCRIPT_HASH_TY → const int
5

Properties

opcodeArray Map<int, OpCode>
read / write
opcodeOnelineRepls Map<String, String>
read / write

Functions

asSmallInt(OpCode op) int
asSmallInt returns the passed opcode, which must be true according to isSmallInt(), as an integer.
calcSignatureHash(List<ParsedOpcode> prevOutScript, int hashType, MsgTx tx, int idx) Uint8List
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.
calcWitnessSignatureHash(List<ParsedOpcode> subScript, TxSigHashes sigHashes, int hashType, MsgTx tx, int idx, Amount amt) Uint8List
calc Witness Signature Hash
ECSign(ECPrivateKey key, Uint8List hash) ECSignature
ECSign
extractPkScriptAddrs(Uint8List pkScript, Params net) List
ExtractPkScriptAddrs returns the type of script, addresses and required signatures associated with the passed PkScript. Note that it only works for 'standard' transaction script types. Any data such as public keys which are invalid are omitted from the results.
isNullData(List<ParsedOpcode> pops) bool
isNullData returns true if the passed script is a null data transaction, false otherwise.
isPayToScriptHash(Uint8List script) bool
isPayToScriptHash returns true if the script is in the standard pay-to-script-hash (P2SH) format, false otherwise.
isPayToWitnessPubKeyHash(Uint8List script) bool
isPayToWitnessPubKeyHash returns true if the is in the standard pay-to-witness-pubkey-hash (P2WKH) format, false otherwise.
isPayToWitnessScriptHash(Uint8List script) bool
isPayToWitnessScriptHash returns true if the is in the standard pay-to-witness-script-hash (P2WSH) format, false otherwise.
isPubkey(List<ParsedOpcode> pops) bool
isPubkey returns true if the script passed is a pay-to-pubkey transaction, false otherwise.
isPubkeyHash(List<ParsedOpcode> pops) bool
isPubkeyHash returns true if the script passed is a pay-to-pubkey-hash transaction, false otherwise.
isScriptHash(List<ParsedOpcode> pops) bool
isScriptHash returns true if the script passed is a pay-to-script-hash transaction, false otherwise.
isSmallInt(OpCode op) bool
isSmallInt returns whether or not the opcode is considered a small integer, which is an OP_0, or OP_1 through OP_16.
isWitnessPubKeyHash(List<ParsedOpcode> pops) bool
isWitnessPubKeyHash returns true if the passed script is a pay-to-witness-pubkey-hash, and false otherwise.
isWitnessScriptHash(List<ParsedOpcode> pops) bool
isWitnessScriptHash returns true if the passed script is a pay-to-witness-script-hash transaction, false otherwise.
mergeScripts(Params net, MsgTx tx, int idx, Uint8List pkScript, int cls, List<Address> addrs, int nRequired, Uint8List sigScript, Uint8List prevScript) Uint8List
merge scripts
parseScript(Uint8List script) List<ParsedOpcode>
parseScript preparses the script in bytes into a list of ParsedOpcodes while applying a number of sanity checks.
payToAddrScript(Address addr) Uint8List
payToAddrScript creates a new script to pay a transaction output to a the specified address.
payToWitnessScriptHashScript(Uint8List scriptHash) Uint8List
payToWitnessScriptHashScript creates a new script to pay to a version 0 script hash witness program. The passed hash is expected to be valid.
rawTxInSignature(MsgTx tx, int idx, Uint8List subScript, int hashType, ECPrivateKey key) Uint8List
raw TxIn signature
rawTxInWitnessSignature(MsgTx tx, TxSigHashes sigHashes, int idx, Amount amt, Uint8List subScript, int hashType, PrivateKey key) Uint8List
raw TxIn witness signature
removeOpcode(List<ParsedOpcode> pkscript, int val) List<ParsedOpcode>
sign(Params net, MsgTx tx, int idx, Uint8List subScript, int hashType, KeyClosure kdb, ScriptClosure sdb) List
sign
signatureScript(MsgTx tx, int idx, Uint8List subScript, int hashType, ECPrivateKey privKey, bool compress) Uint8List
signature script
signTxOutput(Params net, MsgTx tx, int idx, Uint8List pkScript, int hashType, KeyClosure kdb, ScriptClosure sdb, Uint8List previousScript) Uint8List
sign Tx Output
unparseScript(List<ParsedOpcode> pops) Uint8List
unparseScript reversed the action of parseScript and returns the ParsedOpcodes as a list of bytes
witnessSignature(MsgTx tx, TxSigHashes sigHashes, int idx, Amount amt, Uint8List subscript, int hashType, ECPrivateKey privKey, bool compress) List<Uint8List>
witness signature