tapscript

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoInputs represents an error case where an asset undergoing a
	// state transition does not have any or a specific input required.
	ErrNoInputs = errors.New("missing asset input(s)")

	// ErrInputMismatch represents an error case where an asset's set of
	// inputs mismatch the set provided to the virtual machine.
	ErrInputMismatch = errors.New("asset input(s) mismatch")

	// ErrInvalidScriptVersion represents an error case where an asset input
	// commits to an invalid script version.
	ErrInvalidScriptVersion = errors.New("invalid script version")
)

Functions

func BuildGenesisTx added in v0.3.0

func BuildGenesisTx(newAsset *asset.Asset) (*wire.MsgTx,
	*wire.TxOut, error)

BuildGenesisTx constructs a virtual transaction and prevOut that represent the genesis state transition for a grouped asset. This output is used to create a group witness for the grouped asset.

func EstimateFee added in v0.4.0

func EstimateFee(inputScripts [][]byte, outputs []*wire.TxOut,
	feeRate chainfee.SatPerKWeight) (int, btcutil.Amount)

EstimateFee provides a worst-case fee and vsize estimate for a transaction built from the given inputs and outputs. This mirrors the fee estimation implemented in btcwallet/wallet/txauthor/author.go:NewUnsignedTransaction() EstimateFee assumes that a change output (or a dummy output for change) is included in the set of given outputs.

func FlipParity added in v0.4.0

func FlipParity(pubKey *btcec.PublicKey) *btcec.PublicKey

FlipParity turns the given public key from even to odd parity or vice versa.

func InputAssetPrevOut

func InputAssetPrevOut(prevAsset asset.Asset) (*wire.TxOut, error)

InputAssetPrevOut returns a TxOut that represents the input asset in a Taproot Asset virtual TX.

func InputKeySpendSigHash

func InputKeySpendSigHash(virtualTx *wire.MsgTx, input, newAsset *asset.Asset,
	idx uint32, sigHashType txscript.SigHashType) ([]byte, error)

InputKeySpendSigHash returns the signature hash of a virtual transaction for a specific Taproot Asset input that can be spent through the key path. This is the message over which signatures are generated over.

func InputPrevOutFetcher

func InputPrevOutFetcher(prevAsset asset.Asset) (*txscript.CannedPrevOutputFetcher,
	error)

InputPrevOutFetcher returns a Taproot Asset input's `PrevOutFetcher` to be used throughout signing.

func InputScriptSpendSigHash

func InputScriptSpendSigHash(virtualTx *wire.MsgTx, input,
	newAsset *asset.Asset, idx uint32, sigHashType txscript.SigHashType,
	tapLeaf *txscript.TapLeaf) ([]byte, error)

InputScriptSpendSigHash returns the signature hash of a virtual transaction for a specific Taproot Asset input that can be spent through the script path. This is the message over which signatures are generated over.

func PayToAddrScript

func PayToAddrScript(internalKey btcec.PublicKey, sibling *chainhash.Hash,
	commitment commitment.TapCommitment) ([]byte, error)

PayToAddrScript constructs a P2TR script that embeds a Taproot Asset commitment by tweaking the receiver key by a Tapscript tree that contains the Taproot Asset commitment root. The Taproot Asset commitment must be reconstructed by the receiver, and they also need to Tapscript sibling hash used here if present.

func PayToTaprootScript

func PayToTaprootScript(taprootKey *btcec.PublicKey) ([]byte, error)

PayToTaprootScript creates a pk script for a pay-to-taproot output key.

func VirtualTx

func VirtualTx(newAsset *asset.Asset, prevAssets commitment.InputSet) (
	*wire.MsgTx, mssmt.Tree, error)

VirtualTx constructs the virtual transaction that enables the movement of an asset representing an asset state transition.

Types

type GroupTxBuilder added in v0.3.0

type GroupTxBuilder struct{}

GroupTxBuilder is an implementation of the asset.GenesisTxBuilder interface that constructs virtual transactions for grouped asset genesis.

func (*GroupTxBuilder) BuildGenesisTx added in v0.3.0

func (m *GroupTxBuilder) BuildGenesisTx(newAsset *asset.Asset) (*wire.MsgTx,
	*wire.TxOut, error)

BuildGenesisTx constructs a virtual transaction and prevOut that represent the genesis state transition for a grouped asset. This output is used to create a group witness for the grouped asset.

type MockSigner

type MockSigner struct {
	PrivKey *btcec.PrivateKey
}

func NewMockSigner

func NewMockSigner(privKey *btcec.PrivateKey) *MockSigner

func (*MockSigner) SignVirtualTx

func (m *MockSigner) SignVirtualTx(signDesc *lndclient.SignDescriptor,
	tx *wire.MsgTx, prevOut *wire.TxOut) (*schnorr.Signature, error)

type Signer

type Signer interface {
	// SignVirtualTx generates a signature according to the passed signing
	// descriptor and TX.
	SignVirtualTx(signDesc *lndclient.SignDescriptor, tx *wire.MsgTx,
		prevOut *wire.TxOut) (*schnorr.Signature, error)
}

Signer is the interface used to compute the witness for a Taproot Asset virtual TX.

type TxValidator

type TxValidator interface {
	// Execute creates an instance of the Taproot Asset VM and validates
	// an asset transfer, including the attached witnesses.
	Execute(newAsset *asset.Asset, splitAssets []*commitment.SplitAsset,
		prevAssets commitment.InputSet,
		chainLookup asset.ChainLookup) error
}

TxValidator is the interface used to validate an asset transfer with the Taproot Asset VM.

type WitnessValidator added in v0.4.0

type WitnessValidator interface {
	// ValidateWitnesses validates the generated witnesses of an asset
	// transfer.
	ValidateWitnesses(newAsset *asset.Asset,
		splitAssets []*commitment.SplitAsset,
		prevAssets commitment.InputSet) error
}

WitnessValidator is the interface used to validate the witnesses of an asset transfer. This method may be used in partially constructed asset transfers to only check signature validity.

Jump to

Keyboard shortcuts

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