script

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2022 License: AGPL-3.0, ISC Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpDup        = 0x76
	OpHash       = 0xa8
	OpPushHash   = 0x4f
	OpPushPubKey = 0x55
	OpPushSig    = 0x54
	OpCheckSig   = 0xac
	OpEqual      = 0x87
	OpVerify     = 0x69
	OpPushBool   = 0x51
)
View Source
const (
	HashAlgSha256      = 0x01
	HashAlgSha512      = 0x02
	BoolFalse          = 0x00
	BoolTrue           = 0x01
	SigSchemeSecp256k1 = 0x01
)
View Source
const MaxScriptBytes = 65536
View Source
const StartByte = 0x53

Variables

View Source
var (
	ErrUnknownOpCode       = errors.New("unknown opcode")
	ErrInvalidScriptFormat = errors.New("invalid script format")
	ErrScriptResultFalse   = errors.New("script execution result yielded false or non-clean stack")
)

Functions

func PredicateAlwaysFalse

func PredicateAlwaysFalse() []byte

PredicateAlwaysFalse is a predicate that evaluates to false

func PredicateAlwaysTrue

func PredicateAlwaysTrue() []byte

PredicateAlwaysTrue is a predicate that evaluates to true with an empty argument.

func PredicateArgumentEmpty

func PredicateArgumentEmpty() []byte

PredicateArgumentEmpty predicate argument for PredicateAlwaysTrue

func PredicateArgumentPayToPublicKeyHash

func PredicateArgumentPayToPublicKeyHash(sig []byte, sigScheme byte, pubKey []byte) []byte

PredicateArgumentPayToPublicKeyHash creates argument for pay to public key hash predicate.

func PredicateArgumentPayToPublicKeyHashDefault

func PredicateArgumentPayToPublicKeyHashDefault(sig []byte, pubKey []byte) []byte

PredicateArgumentPayToPublicKeyHashDefault same as PredicateArgumentPayToPublicKeyHash(sig, secp256k1, pubkey)

func PredicatePayToPublicKeyHash

func PredicatePayToPublicKeyHash(hashAlg byte, pubKeyHash []byte, sigScheme byte) []byte

PredicatePayToPublicKeyHash is a predicate that evaluates true if a valid signature and public key is given as arguments

func PredicatePayToPublicKeyHashDefault

func PredicatePayToPublicKeyHashDefault(pubKeyHash []byte) []byte

PredicatePayToPublicKeyHashDefault same as PredicatePayToPublicKeyHash(sha256, pubkeyHash, secp256k1)

func RunScript

func RunScript(predicateArgument []byte, bearerPredicate []byte, sigData []byte) error

RunScript executes the given script. If the script contains OpCheckSig opCode then correct sigData must be supplied. The script is considered valid if after execution there's only one TRUE value on the stack, otherwise error is returned.

An example P2PKH script format: BearerPredicate: [Dup, Hash <SHA256>, PushHash <SHA256> <32 bytes>, Equal, Verify, CheckSig <secp256k1>] PredicateArgument: [PushSig <secp256k1> <65 bytes>, PushPubKey <secp256k1> <33 bytes>]

Same example with byte encoding BearerPredicate: [0x53, 0x76, 0xa8, 0x01, 0x4f, 0x01, <32 bytes>, 0x87, 0x69, 0xac, 0x01] PredicateArgument: [0x53, 0x54, 0x01, <65 bytes>, 0x55, 0x01, <33 bytes>]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL