Documentation ¶
Index ¶
- Constants
- Variables
- func Base58EncodeMissingChecksum(input []byte) string
- func DecodeParts(b []byte) ([][]byte, error)
- func DecodeStringParts(s string) ([][]byte, error)
- func EncodeBIP276(script BIP276) string
- func EncodeParts(parts [][]byte) ([]byte, error)
- func PushDataPrefix(data []byte) ([]byte, error)
- func ValidateAddress(address string) (bool, error)
- type Address
- func NewAddressFromPublicKey(pubKey *bec.PublicKey, mainnet bool) (*Address, error)
- func NewAddressFromPublicKeyHash(hash []byte, mainnet bool) (*Address, error)
- func NewAddressFromPublicKeyString(pubKey string, mainnet bool) (*Address, error)
- func NewAddressFromString(addr string) (*Address, error)
- type BIP276
- type Script
- func NewFromASM(str string) (*Script, error)
- func NewFromBytes(b []byte) *Script
- func NewFromHexString(s string) (*Script, error)
- func NewP2PKHFromAddress(addr string) (*Script, error)
- func NewP2PKHFromPubKeyBytes(pubKeyBytes []byte) (*Script, error)
- func NewP2PKHFromPubKeyEC(pubKey *bec.PublicKey) (*Script, error)
- func NewP2PKHFromPubKeyHash(pubKeyHash []byte) (*Script, error)
- func NewP2PKHFromPubKeyHashStr(pubKeyHash string) (*Script, error)
- func NewP2PKHFromPubKeyStr(pubKey string) (*Script, error)
- func NewP2PKHUnlockingScript(pubKey []byte, sig []byte, sigHashFlag sighash.Flag) (*Script, error)
- func (s *Script) Addresses() ([]string, error)
- func (s *Script) AppendOpCode(o uint8) *Script
- func (s *Script) AppendPushData(d []byte) error
- func (s *Script) AppendPushDataArray(d [][]byte) error
- func (s *Script) AppendPushDataHexString(str string) error
- func (s *Script) AppendPushDataString(str string) error
- func (s *Script) AppendPushDataStrings(strs []string) error
- func (s *Script) Equals(b *Script) bool
- func (s *Script) EqualsBytes(b []byte) bool
- func (s *Script) EqualsHex(h string) bool
- func (s *Script) IsData() bool
- func (s *Script) IsMultiSigOut() bool
- func (s *Script) IsP2PK() bool
- func (s *Script) IsP2PKH() bool
- func (s *Script) IsP2SH() bool
- func (s *Script) PublicKeyHash() ([]byte, error)
- func (s *Script) ScriptType() string
- func (s *Script) String() string
- func (s *Script) ToASM() (string, error)
Constants ¶
const ( Op0 byte = 0x00 // 0 OpZERO byte = 0x00 // 0 OpFALSE byte = 0x00 // 0 OpDATA1 byte = 0x01 // 1 OpDATA2 byte = 0x02 // 2 OpDATA3 byte = 0x03 // 3 OpDATA4 byte = 0x04 // 4 OpDATA5 byte = 0x05 // 5 OpDATA6 byte = 0x06 // 6 OpDATA7 byte = 0x07 // 7 OpDATA8 byte = 0x08 // 8 OpDATA9 byte = 0x09 // 9 OpDATA10 byte = 0x0a // 10 OpDATA11 byte = 0x0b // 11 OpDATA12 byte = 0x0c // 12 OpDATA13 byte = 0x0d // 13 OpDATA14 byte = 0x0e // 14 OpDATA15 byte = 0x0f // 15 OpDATA16 byte = 0x10 // 16 OpDATA17 byte = 0x11 // 17 OpDATA18 byte = 0x12 // 18 OpDATA19 byte = 0x13 // 19 OpDATA20 byte = 0x14 // 20 OpDATA21 byte = 0x15 // 21 OpDATA22 byte = 0x16 // 22 OpDATA23 byte = 0x17 // 23 OpDATA24 byte = 0x18 // 24 OpDATA25 byte = 0x19 // 25 OpDATA26 byte = 0x1a // 26 OpDATA27 byte = 0x1b // 27 OpDATA28 byte = 0x1c // 28 OpDATA29 byte = 0x1d // 29 OpDATA30 byte = 0x1e // 30 OpDATA31 byte = 0x1f // 31 OpDATA32 byte = 0x20 // 32 OpDATA33 byte = 0x21 // 33 OpDATA34 byte = 0x22 // 34 OpDATA35 byte = 0x23 // 35 OpDATA36 byte = 0x24 // 36 OpDATA37 byte = 0x25 // 37 OpDATA38 byte = 0x26 // 38 OpDATA39 byte = 0x27 // 39 OpDATA40 byte = 0x28 // 40 OpDATA41 byte = 0x29 // 41 OpDATA42 byte = 0x2a // 42 OpDATA43 byte = 0x2b // 43 OpDATA44 byte = 0x2c // 44 OpDATA45 byte = 0x2d // 45 OpDATA46 byte = 0x2e // 46 OpDATA47 byte = 0x2f // 47 OpDATA48 byte = 0x30 // 48 OpDATA49 byte = 0x31 // 49 OpDATA50 byte = 0x32 // 50 OpDATA51 byte = 0x33 // 51 OpDATA52 byte = 0x34 // 52 OpDATA53 byte = 0x35 // 53 OpDATA54 byte = 0x36 // 54 OpDATA55 byte = 0x37 // 55 OpDATA56 byte = 0x38 // 56 OpDATA57 byte = 0x39 // 57 OpDATA58 byte = 0x3a // 58 OpDATA59 byte = 0x3b // 59 OpDATA60 byte = 0x3c // 60 OpDATA61 byte = 0x3d // 61 OpDATA62 byte = 0x3e // 62 OpDATA63 byte = 0x3f // 63 OpDATA64 byte = 0x40 // 64 OpDATA65 byte = 0x41 // 65 OpDATA66 byte = 0x42 // 66 OpDATA67 byte = 0x43 // 67 OpDATA68 byte = 0x44 // 68 OpDATA69 byte = 0x45 // 69 OpDATA70 byte = 0x46 // 70 OpDATA71 byte = 0x47 // 71 OpDATA72 byte = 0x48 // 72 OpDATA73 byte = 0x49 // 73 OpDATA74 byte = 0x4a // 74 OpDATA75 byte = 0x4b // 75 OpPUSHDATA1 byte = 0x4c // 76 OpPUSHDATA2 byte = 0x4d // 77 OpPUSHDATA4 byte = 0x4e // 78 Op1NEGATE byte = 0x4f // 79 OpRESERVED byte = 0x50 // 80 OpBASE byte = 0x50 // 80 Op1 byte = 0x51 // 81 OpONE byte = 0x51 // 81 OpTRUE byte = 0x51 // 81 Op2 byte = 0x52 // 82 Op3 byte = 0x53 // 83 Op4 byte = 0x54 // 84 Op5 byte = 0x55 // 85 Op6 byte = 0x56 // 86 Op7 byte = 0x57 // 87 Op8 byte = 0x58 // 88 Op9 byte = 0x59 // 89 Op10 byte = 0x5a // 90 Op11 byte = 0x5b // 91 Op12 byte = 0x5c // 92 Op13 byte = 0x5d // 93 Op14 byte = 0x5e // 94 Op15 byte = 0x5f // 95 Op16 byte = 0x60 // 96 OpNOP byte = 0x61 // 97 OpVER byte = 0x62 // 98 OpIF byte = 0x63 // 99 OpNOTIF byte = 0x64 // 100 OpVERIF byte = 0x65 // 101 OpVERNOTIF byte = 0x66 // 102 OpELSE byte = 0x67 // 103 OpENDIF byte = 0x68 // 104 OpVERIFY byte = 0x69 // 105 OpRETURN byte = 0x6a // 106 OpTOALTSTACK byte = 0x6b // 107 OpFROMALTSTACK byte = 0x6c // 108 Op2DROP byte = 0x6d // 109 Op2DUP byte = 0x6e // 110 Op3DUP byte = 0x6f // 111 Op2OVER byte = 0x70 // 112 Op2ROT byte = 0x71 // 113 Op2SWAP byte = 0x72 // 114 OpIFDUP byte = 0x73 // 115 OpDEPTH byte = 0x74 // 116 OpDROP byte = 0x75 // 117 OpDUP byte = 0x76 // 118 OpNIP byte = 0x77 // 119 OpOVER byte = 0x78 // 120 OpPICK byte = 0x79 // 121 OpROLL byte = 0x7a // 122 OpROT byte = 0x7b // 123 OpSWAP byte = 0x7c // 124 OpTUCK byte = 0x7d // 125 OpCAT byte = 0x7e // 126 OpSPLIT byte = 0x7f // 127 OpNUM2BIN byte = 0x80 // 128 OpBIN2NUM byte = 0x81 // 129 OpSIZE byte = 0x82 // 130 OpINVERT byte = 0x83 // 131 OpAND byte = 0x84 // 132 OpOR byte = 0x85 // 133 OpXOR byte = 0x86 // 134 OpEQUAL byte = 0x87 // 135 OpEQUALVERIFY byte = 0x88 // 136 OpRESERVED1 byte = 0x89 // 137 OpRESERVED2 byte = 0x8a // 138 Op1ADD byte = 0x8b // 139 Op1SUB byte = 0x8c // 140 Op2MUL byte = 0x8d // 141 Op2DIV byte = 0x8e // 142 OpNEGATE byte = 0x8f // 143 OpABS byte = 0x90 // 144 OpNOT byte = 0x91 // 145 Op0NOTEQUAL byte = 0x92 // 146 OpADD byte = 0x93 // 147 OpSUB byte = 0x94 // 148 OpMUL byte = 0x95 // 149 OpDIV byte = 0x96 // 150 OpMOD byte = 0x97 // 151 OpLSHIFT byte = 0x98 // 152 OpRSHIFT byte = 0x99 // 153 OpBOOLAND byte = 0x9a // 154 OpBOOLOR byte = 0x9b // 155 OpNUMEQUAL byte = 0x9c // 156 OpNUMEQUALVERIFY byte = 0x9d // 157 OpNUMNOTEQUAL byte = 0x9e // 158 OpLESSTHAN byte = 0x9f // 159 OpGREATERTHAN byte = 0xa0 // 160 OpLESSTHANOREQUAL byte = 0xa1 // 161 OpGREATERTHANOREQUAL byte = 0xa2 // 162 OpMIN byte = 0xa3 // 163 OpMAX byte = 0xa4 // 164 OpWITHIN byte = 0xa5 // 165 OpRIPEMD160 byte = 0xa6 // 166 OpSHA1 byte = 0xa7 // 167 OpSHA256 byte = 0xa8 // 168 OpHASH160 byte = 0xa9 // 169 OpHASH256 byte = 0xaa // 170 OpCODESEPARATOR byte = 0xab // 171 OpCHECKSIG byte = 0xac // 172 OpCHECKSIGVERIFY byte = 0xad // 173 OpCHECKMULTISIG byte = 0xae // 174 OpCHECKMULTISIGVERIFY byte = 0xaf // 175 OpNOP1 byte = 0xb0 // 176 OpNOP2 byte = 0xb1 // 177 OpCHECKLOCKTIMEVERIFY byte = 0xb1 // 177 OpNOP3 byte = 0xb2 // 178 OpCHECKSEQUENCEVERIFY byte = 0xb2 // 178 OpNOP4 byte = 0xb3 // 179 OpNOP5 byte = 0xb4 // 180 OpNOP6 byte = 0xb5 // 181 OpNOP7 byte = 0xb6 // 182 OpNOP8 byte = 0xb7 // 183 OpNOP9 byte = 0xb8 // 184 OpNOP10 byte = 0xb9 // 185 OpUNKNOWN186 byte = 0xba // 186 OpUNKNOWN187 byte = 0xbb // 187 OpUNKNOWN188 byte = 0xbc // 188 OpUNKNOWN189 byte = 0xbd // 189 OpUNKNOWN190 byte = 0xbe // 190 OpUNKNOWN191 byte = 0xbf // 191 OpUNKNOWN192 byte = 0xc0 // 192 OpUNKNOWN193 byte = 0xc1 // 193 OpUNKNOWN194 byte = 0xc2 // 194 OpUNKNOWN195 byte = 0xc3 // 195 OpUNKNOWN196 byte = 0xc4 // 196 OpUNKNOWN197 byte = 0xc5 // 197 OpUNKNOWN198 byte = 0xc6 // 198 OpUNKNOWN199 byte = 0xc7 // 199 OpUNKNOWN200 byte = 0xc8 // 200 OpUNKNOWN201 byte = 0xc9 // 201 OpUNKNOWN202 byte = 0xca // 202 OpUNKNOWN203 byte = 0xcb // 203 OpUNKNOWN204 byte = 0xcc // 204 OpUNKNOWN205 byte = 0xcd // 205 OpUNKNOWN206 byte = 0xce // 206 OpUNKNOWN207 byte = 0xcf // 207 OpUNKNOWN208 byte = 0xd0 // 208 OpUNKNOWN209 byte = 0xd1 // 209 OpUNKNOWN210 byte = 0xd2 // 210 OpUNKNOWN211 byte = 0xd3 // 211 OpUNKNOWN212 byte = 0xd4 // 212 OpUNKNOWN213 byte = 0xd5 // 213 OpUNKNOWN214 byte = 0xd6 // 214 OpUNKNOWN215 byte = 0xd7 // 215 OpUNKNOWN216 byte = 0xd8 // 216 OpUNKNOWN217 byte = 0xd9 // 217 OpUNKNOWN218 byte = 0xda // 218 OpUNKNOWN219 byte = 0xdb // 219 OpUNKNOWN220 byte = 0xdc // 220 OpUNKNOWN221 byte = 0xdd // 221 OpUNKNOWN222 byte = 0xde // 222 OpUNKNOWN223 byte = 0xdf // 223 OpUNKNOWN224 byte = 0xe0 // 224 OpUNKNOWN225 byte = 0xe1 // 225 OpUNKNOWN226 byte = 0xe2 // 226 OpUNKNOWN227 byte = 0xe3 // 227 OpUNKNOWN228 byte = 0xe4 // 228 OpUNKNOWN229 byte = 0xe5 // 229 OpUNKNOWN230 byte = 0xe6 // 230 OpUNKNOWN231 byte = 0xe7 // 231 OpUNKNOWN232 byte = 0xe8 // 232 OpUNKNOWN233 byte = 0xe9 // 233 OpUNKNOWN234 byte = 0xea // 234 OpUNKNOWN235 byte = 0xeb // 235 OpUNKNOWN236 byte = 0xec // 236 OpUNKNOWN237 byte = 0xed // 237 OpUNKNOWN238 byte = 0xee // 238 OpUNKNOWN239 byte = 0xef // 239 OpUNKNOWN240 byte = 0xf0 // 240 OpUNKNOWN241 byte = 0xf1 // 241 OpUNKNOWN242 byte = 0xf2 // 242 OpUNKNOWN243 byte = 0xf3 // 243 OpUNKNOWN244 byte = 0xf4 // 244 OpUNKNOWN245 byte = 0xf5 // 245 OpUNKNOWN246 byte = 0xf6 // 246 OpUNKNOWN247 byte = 0xf7 // 247 OpUNKNOWN248 byte = 0xf8 // 248 OpUNKNOWN249 byte = 0xf9 // 249 OpSMALLINTEGER byte = 0xfa // 250 - bitcoin core internal OpPUBKEYS byte = 0xfb // 251 - bitcoin core internal OpUNKNOWN252 byte = 0xfc // 252 OpPUBKEYHASH byte = 0xfd // 253 - bitcoin core internal OpPUBKEY byte = 0xfe // 254 - bitcoin core internal OpINVALIDOPCODE byte = 0xff // 255 - bitcoin core )
BitCoin Script constants. See https://wiki.bitcoinsv.io/index.php/Opcodes_used_in_Bitcoin_Script
const ( ScriptTypePubKey = "pubkey" ScriptTypePubKeyHash = "pubkeyhash" ScriptTypeNonStandard = "nonstandard" ScriptTypeMultiSig = "multisig" ScriptTypeNullData = "nulldata" )
ScriptKey types.
const CurrentVersion = 1
CurrentVersion provides the ability to update the structure of the data that follows it.
const NetworkMainnet = 1
NetworkMainnet specifies that the data is only valid for use on the main network.
const NetworkTestnet = 2
NetworkTestnet specifies that the data is only valid for use on the test network.
const PrefixScript = "bitcoin-script"
PrefixScript is the prefix in the BIP276 standard which specifies if it is a script or template.
const PrefixTemplate = "bitcoin-template"
PrefixTemplate is the prefix in the BIP276 standard which specifies if it is a script or template.
Variables ¶
var ( ErrInvalidPKLen = errors.New("invalid public key length") ErrInvalidOpCode = errors.New("invalid opcode data") ErrEmptyScript = errors.New("script is empty") ErrNotP2PKH = errors.New("not a P2PKH") )
Sentinel errors raised by the package.
Functions ¶
func Base58EncodeMissingChecksum ¶
Base58EncodeMissingChecksum appends a checksum to a byte sequence then encodes into base58 encoding.
func DecodeParts ¶
DecodeParts takes bytes and decodes the opcodes in it returning an array of opcode parts (which could be opcodes or data pushed to the stack).
func DecodeStringParts ¶
DecodeStringParts takes a hex string and decodes the opcodes in it returning an array of opcode parts (which could be opcodes or data pushed to the stack).
func EncodeBIP276 ¶
EncodeBIP276 is used to encode specific (non-standard) scripts in BIP276 format. See https://github.com/moneybutton/bips/blob/master/bip-0276.mediawiki
func EncodeParts ¶
EncodeParts takes an array of byte slices and returns a single byte slice with the appropriate OP_PUSH commands embedded. The output can be encoded to a hex string and viewed as a BitCoin script hex string.
For example '76a9140d6cf2ef7bc915d109f77357a71b64fc25e2e11488ac' is the hex string of a P2PKH output script.
func PushDataPrefix ¶
PushDataPrefix takes a single byte slice of data and returns its OP_PUSHDATA BitCoin encoding prefix based on its length.
For example, the data byte slice '022a8c1a18378885db9054676f17a27f4219045e' would be encoded as '14022a8c1a18378885db9054676f17a27f4219045e' in BitCoin. The OP_PUSHDATA prefix is '14' since the length of the data is 20 bytes (0x14 in decimal is 20).
func ValidateAddress ¶
ValidateAddress checks if an address string is a valid BitCoin address (ex. P2PKH, BIP276). Checks both mainnet and testnet.
Types ¶
type Address ¶
An Address struct contains the address string as well as the hash160 hexstring of the public key. The address string will be human readable and specific to the network type, but the public key hash is useful because it stays the same regardless of the network type (mainnet, testnet).
func NewAddressFromPublicKey ¶
NewAddressFromPublicKey takes a bec public key and returns an Address struct pointer. If mainnet parameter is true it will return a mainnet address (starting with a 1). Otherwise (mainnet is false) it will return a testnet address (starting with an m or n).
func NewAddressFromPublicKeyHash ¶
NewAddressFromPublicKeyHash takes a public key hash in bytes and returns an Address struct pointer. If mainnet parameter is true it will return a mainnet address (starting with a 1). Otherwise (mainnet is false) it will return a testnet address (starting with an m or n).
func NewAddressFromPublicKeyString ¶
NewAddressFromPublicKeyString takes a public key string and returns an Address struct pointer. If mainnet parameter is true it will return a mainnet address (starting with a 1). Otherwise (mainnet is false) it will return a testnet address (starting with an m or n).
func NewAddressFromString ¶
NewAddressFromString takes a string address (P2PKH) and returns a pointer to an Address which contains the address string as well as the public key hash string.
type BIP276 ¶
BIP276 proposes a scheme for encoding typed bitcoin related data in a user friendly way see https://github.com/moneybutton/bips/blob/master/bip-0276.mediawiki
func DecodeBIP276 ¶
DecodeBIP276 is used to decode BIP276 formatted data into specific (non-standard) scripts. See https://github.com/moneybutton/bips/blob/master/bip-0276.mediawiki
type Script ¶
type Script []byte
Script type
func NewFromASM ¶
NewFromASM creates a new script from a BitCoin ASM formatted string.
func NewFromBytes ¶
NewFromBytes wraps a byte slice with the Script type.
func NewFromHexString ¶
NewFromHexString creates a new script from a hex encoded string.
func NewP2PKHFromAddress ¶
NewP2PKHFromAddress takes an address and creates a P2PKH script from it.
func NewP2PKHFromPubKeyBytes ¶
NewP2PKHFromPubKeyBytes takes public key bytes (in compressed format) and creates a P2PKH script from it.
func NewP2PKHFromPubKeyEC ¶
NewP2PKHFromPubKeyEC takes a public key hex string (in compressed format) and creates a P2PKH script from it.
func NewP2PKHFromPubKeyHash ¶
NewP2PKHFromPubKeyHash takes a public key hex string (in compressed format) and creates a P2PKH script from it.
func NewP2PKHFromPubKeyHashStr ¶
NewP2PKHFromPubKeyHashStr takes a public key hex string (in compressed format) and creates a P2PKH script from it.
func NewP2PKHFromPubKeyStr ¶
NewP2PKHFromPubKeyStr takes a public key hex string (in compressed format) and creates a P2PKH script from it.
func NewP2PKHUnlockingScript ¶
NewP2PKHUnlockingScript creates a new unlocking script which spends a P2PKH locking script from a public key, a signature, and a SIGHASH flag.
func (*Script) AppendOpCode ¶
AppendOpCode appends an opcode type to the script
func (*Script) AppendPushData ¶
AppendPushData takes data bytes and appends them to the script with proper PUSHDATA prefixes
func (*Script) AppendPushDataArray ¶
AppendPushDataArray takes an array of data bytes and appends them to the script with proper PUSHDATA prefixes
func (*Script) AppendPushDataHexString ¶
AppendPushDataHexString takes a hex string and appends them to the script with proper PUSHDATA prefixes
func (*Script) AppendPushDataString ¶
AppendPushDataString takes a string and appends its UTF-8 encoding to the script with proper PUSHDATA prefixes
func (*Script) AppendPushDataStrings ¶
AppendPushDataStrings takes an array of strings and appends their UTF-8 encoding to the script with proper PUSHDATA prefixes
func (*Script) EqualsBytes ¶
EqualsBytes will compare the script to a byte representation of a script, b, and return true if they match.
func (*Script) EqualsHex ¶
EqualsHex will compare the script to a hex string h, if they match then true is returned otherwise false.
func (*Script) IsData ¶
IsData returns true if this is a data output script. This means the script starts with OP_RETURN or OP_FALSE OP_RETURN.
func (*Script) IsMultiSigOut ¶
IsMultiSigOut returns true if this is a multisig output script.
func (*Script) IsP2SH ¶
IsP2SH returns true if this is a p2sh output script. TODO: remove all p2sh stuff from repo
func (*Script) PublicKeyHash ¶
PublicKeyHash returns a public key hash byte array if the script is a P2PKH script.
func (*Script) ScriptType ¶
ScriptType returns the type of script this is as a string.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package interpreter implements the bitcoin transaction script language.
|
Package interpreter implements the bitcoin transaction script language. |