txscript

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: ISC Imports: 5 Imported by: 0

Documentation

Overview

Package txscript provides compat stubs for the removed Bitcoin script engine.

Index

Constants

View Source
const (
	SigHashAll            SigHashType   = 1
	SigHashDefault        SigHashType   = 0
	StandardVerifyFlags                 = 0
	NonStandardTy         ScriptClass   = 0
	PubKeyTy              ScriptClass   = 1
	PubKeyHashTy          ScriptClass   = 2
	WitnessV0PubKeyHashTy ScriptClass   = 3
	ScriptHashTy          ScriptClass   = 4
	WitnessV0ScriptHashTy ScriptClass   = 5
	MultiSigTy            ScriptClass   = 6
	NullDataTy            ScriptClass   = 7
	WitnessV1TaprootTy    ScriptClass   = 8
	TapscriptLeafVersion  uint8         = 0xc0
	TapscriptTypeFullTree TapscriptType = 0
)
View Source
const (
	OP_0                   = 0x00
	OP_FALSE               = 0x00
	OP_PUSHDATA1           = 0x4c
	OP_PUSHDATA2           = 0x4d
	OP_PUSHDATA4           = 0x4e
	OP_1                   = 0x51
	OP_TRUE                = 0x51
	OP_IF                  = 0x63
	OP_ELSE                = 0x67
	OP_ENDIF               = 0x68
	OP_RETURN              = 0x6a
	OP_DUP                 = 0x76
	OP_EQUAL               = 0x87
	OP_EQUALVERIFY         = 0x88
	OP_2DUP                = 0x6e
	OP_HASH160             = 0xa9
	OP_CHECKSIG            = 0xac
	OP_CHECKSIGVERIFY      = 0xad
	OP_CHECKMULTISIG       = 0xae
	OP_CHECKMULTISIGVERIFY = 0xaf
	OP_INVALIDOPCODE       = 0xff

	// SigHash types
	SigHashSingle       SigHashType = 3
	SigHashNone         SigHashType = 2
	SigHashAnyOneCanPay SigHashType = 0x80
)

--- OP codes ---

Variables

View Source
var ErrUnsupportedScriptType = fmt.Errorf("unsupported script type")

Functions

func CalcMultiSigStats

func CalcMultiSigStats(script []byte) (int, int, error)

func ComputeTaprootKeyNoScript

func ComputeTaprootKeyNoScript(internalKey *nogoec.PublicKey) *nogoec.PublicKey

func ComputeTaprootOutputKey

func ComputeTaprootOutputKey(internalKey *nogoec.PublicKey, scriptRoot []byte) *nogoec.PublicKey

func DisasmString

func DisasmString(script []byte) (string, error)

DisasmString returns a human-readable disassembly of the script. Compat stub — script validation is removed per NogoCore design.

func GetKey

func GetPreciseSigOpCount

func GetPreciseSigOpCount(a, b []byte, c bool) int

func GetSigOpCount

func GetSigOpCount(script []byte) int

GetSigOpCount returns the number of signature operations in a script. Compat stub.

func Hash160

func Hash160(data []byte) []byte

func IsCoinBaseTx

func IsCoinBaseTx(tx *wire.MsgTx) bool

func IsPayToAnchorScript

func IsPayToAnchorScript(script []byte) bool

func IsPayToScriptHash

func IsPayToScriptHash(script []byte) bool

func IsPayToTaproot

func IsPayToTaproot(script []byte) bool

func IsPayToWitnessPubKeyHash

func IsPayToWitnessPubKeyHash(script []byte) bool

func IsPushOnlyScript

func IsPushOnlyScript(script []byte) bool

func IsUnspendable

func IsUnspendable(script []byte) bool

func IsWitnessProgram

func IsWitnessProgram(script []byte) bool

func MultiSigScript

func MultiSigScript(pubKeys interface{}, nRequired int) ([]byte, error)

MultiSigScript creates a multisig script. Compat stub.

func PayToAddrScript

func PayToAddrScript(addr address.Address) ([]byte, error)

func PushedData

func PushedData(script []byte) ([][]byte, error)

PushedData extracts all data pushed in a script. Compat stub.

func RawTxInSignature

func RawTxInSignature(tx *wire.MsgTx, idx int, subScript []byte,
	hashType SigHashType, key *nogoec.PrivateKey) ([]byte, error)

RawTxInSignature generates a raw signature for the transaction input. Compat stub.

func SignTxOutput

func SignTxOutput(chainParams *chaincfg.Params, tx *wire.MsgTx, idx int, pkScript []byte, hashType SigHashType, kdb KeyDB, sdb ScriptDB, previousScript []byte) ([]byte, error)

func TaprootWitnessSignature

func TaprootWitnessSignature(tx *wire.MsgTx, sigHashes *TxSigHashes, idx int,
	amt int64, pkScript []byte, hashType SigHashType,
	privKey *nogoec.PrivateKey) ([][]byte, error)

TaprootWitnessSignature returns a valid witness stack that can be used to spend the key-spend path of a taproot output. Compat wrapper stub.

func ValidateTransactionScripts

func ValidateTransactionScripts(tx *wire.MsgTx, view *UtxoViewpoint, flags int, sigCache *SigCache, hashCache *HashCache) error

func WitnessSignature

func WitnessSignature(tx *wire.MsgTx, sigHashes *TxSigHashes, idx int, amt int64,
	subscript []byte, hashType SigHashType, privKey *nogoec.PrivateKey,
	compress bool) ([][]byte, error)

WitnessSignature creates an input witness stack for tx to spend BTC sent to a P2WPKH / P2WSH output. Compat wrapper stub.

Types

type ComputedPkScript

type ComputedPkScript struct {
	// contains filtered or unexported fields
}

ComputedPkScript wraps the result of ComputePkScript, providing an Address() method compatible with newer btcd API.

func ComputePkScript

func ComputePkScript(sigScript []byte, witness wire.TxWitness) (*ComputedPkScript, error)

ComputePkScript reconstructs the pkScript from a signature script and optional witness data. Compat stub.

func (*ComputedPkScript) Address

func (c *ComputedPkScript) Address(params *chaincfg.Params) (address.Address, error)

Address returns the address derived from the computed pkScript.

type ControlBlock

type ControlBlock struct {
	InternalKey *nogoec.PublicKey
	RootNode    *TapLeaf
}

func AssembleTaprootScriptTree

func AssembleTaprootScriptTree(leaves ...TapLeaf) *ControlBlock

func ParseControlBlock

func ParseControlBlock(b []byte) (*ControlBlock, error)

func (*ControlBlock) RootHash

func (c *ControlBlock) RootHash(script []byte) []byte

func (*ControlBlock) ToBytes

func (c *ControlBlock) ToBytes() ([]byte, error)

type Engine

type Engine struct{}

Engine represents a virtual machine that executes scripts. Compat stub.

func NewEngine

func NewEngine(scriptPubKey []byte, tx *wire.MsgTx, txIdx int, flags ScriptFlags,
	sigCache *SigCache, hashCache *TxSigHashes, inputAmount int64,
	prevOutFetcher PrevOutputFetcher) (*Engine, error)

NewEngine returns a new script engine. Compat stub.

func (*Engine) Execute

func (e *Engine) Execute() error

Execute executes the scripts in the engine. Compat stub.

type HashCache

type HashCache struct{}

type KeyClosure

type KeyClosure func(address.Address) (*nogoec.PrivateKey, bool, error)

KeyClosure is a closure function type that provides keys.

type KeyDB

type KeyDB interface{}

type MultiPrevOutFetcher

type MultiPrevOutFetcher struct {
	// contains filtered or unexported fields
}

func NewMultiPrevOutFetcher

func NewMultiPrevOutFetcher(tx *wire.MsgTx) *MultiPrevOutFetcher

func (*MultiPrevOutFetcher) AddPrevOut

func (f *MultiPrevOutFetcher) AddPrevOut(op wire.OutPoint, txOut *wire.TxOut)

func (*MultiPrevOutFetcher) FetchPrevOutput

func (f *MultiPrevOutFetcher) FetchPrevOutput(op wire.OutPoint) *wire.TxOut

type PrevOutputFetcher

type PrevOutputFetcher interface {
	FetchPrevOutput(wire.OutPoint) *wire.TxOut
}

PrevOutputFetcher defines an interface for fetching previous output info.

type ScriptBuilder

type ScriptBuilder []byte

func NewScriptBuilder

func NewScriptBuilder() *ScriptBuilder

NewScriptBuilder returns a new ScriptBuilder.

func (*ScriptBuilder) AddData

func (b *ScriptBuilder) AddData(data []byte) *ScriptBuilder

AddData adds the passed data as a data push to the script builder.

func (*ScriptBuilder) AddOp

func (b *ScriptBuilder) AddOp(op byte) *ScriptBuilder

AddOp adds the passed opcode to the script builder.

func (*ScriptBuilder) Script

func (b *ScriptBuilder) Script() ([]byte, error)

Script returns the built script. Compat stub.

type ScriptClass

type ScriptClass int

func ExtractPkScriptAddrs

func ExtractPkScriptAddrs(script []byte, params *chaincfg.Params) (ScriptClass, []address.Address, int, error)

func GetScriptClass

func GetScriptClass(script []byte) (ScriptClass, error)

GetScriptClass returns the class of the script. Compat stub.

func (ScriptClass) String

func (s ScriptClass) String() string

String returns the string representation of the ScriptClass.

type ScriptClosure

type ScriptClosure func(address.Address) ([]byte, error)

ScriptClosure is a closure function type that provides scripts.

type ScriptDB

type ScriptDB interface{}

type ScriptFlags

type ScriptFlags = int

ScriptFlags defines flags for script execution.

type SecretsSource

type SecretsSource interface {
	ChainParams() *chaincfg.Params
	GetKey(addr address.Address) (*nogoec.PrivateKey, bool, error)
}

type SigCache

type SigCache struct{}

type SigHashType

type SigHashType uint32

type TapLeaf

type TapLeaf struct {
	LeafVersion uint8
	Script      []byte
}

func (*TapLeaf) TapHash

func (t *TapLeaf) TapHash() []byte

type TapscriptType

type TapscriptType uint8

type TxSigHashes

type TxSigHashes struct{}

func NewTxSigHashes

func NewTxSigHashes(tx *wire.MsgTx, fetcher PrevOutputFetcher) *TxSigHashes

type UtxoViewpoint

type UtxoViewpoint struct{}

Jump to

Keyboard shortcuts

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