commitment

package
v0.3.3-alpha.rc3 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AssetProofVersionType tlv.Type = 0
	AssetProofAssetIDType tlv.Type = 2
	AssetProofType        tlv.Type = 4

	TaprootAssetProofVersionType tlv.Type = 0
	TaprootAssetProofType        tlv.Type = 2

	ProofAssetProofType        tlv.Type = 1
	ProofTaprootAssetProofType tlv.Type = 2
)
View Source
const Subsystem = "CMMT"

Subsystem defines the logging code for this subsystem.

Variables

View Source
var (
	// ErrNoAssets is an error returned when we attempt to instantiate a new
	// AssetCommitment without any assets.
	ErrNoAssets = errors.New("asset commitment: no assets provided")

	// ErrAssetGenesisMismatch is an error returned when we attempt to
	// create a new asset commitment and two assets disagree on their
	// genesis.
	ErrAssetGenesisMismatch = errors.New(
		"asset commitment: genesis mismatch",
	)

	// ErrAssetTypeMismatch is an error returned when we attempt to insert
	// an asset into an asset commitment and the asset type does not match
	// the assets stored in the commitment.
	ErrAssetTypeMismatch = errors.New(
		"asset commitment: asset type mismatch",
	)

	// ErrAssetGroupKeyMismatch is an error returned when we attempt to
	// create a new asset commitment and two assets disagree on their
	// group key.
	ErrAssetGroupKeyMismatch = errors.New(
		"asset commitment: group key mismatch",
	)

	// ErrAssetDuplicateScriptKey is an error returned when we attempt to
	// create a new asset commitment that would include two assets with the
	// same script key.
	ErrAssetDuplicateScriptKey = errors.New(
		"asset commitment: duplicate script key",
	)
)
View Source
var (
	// ErrDuplicateSplitOutputIndex is an error returned when duplicate
	// split output indices are detected.
	ErrDuplicateSplitOutputIndex = errors.New(
		"found locator with duplicate output index",
	)

	// ErrInvalidSplitAmount is an error returned when a split amount is
	// invalid (e.g. splits do not fully consume input amount).
	ErrInvalidSplitAmount = errors.New("invalid split amounts")

	// ErrInvalidSplitLocator is returned if a new split is attempted to be
	// created w/o a valid external split locator.
	ErrInvalidSplitLocator = errors.New(
		"at least one locator should be specified",
	)

	// ErrInvalidSplitLocatorCount is returned if a collectible split is
	// attempted with a count of external split locators not equal to one.
	ErrInvalidSplitLocatorCount = errors.New(
		"exactly one locator should be specified",
	)

	// ErrInvalidScriptKey is an error returned when a root locator has zero
	// value but does not use the correct un-spendable script key.
	ErrInvalidScriptKey = errors.New(
		"invalid script key for zero-amount locator",
	)

	// ErrZeroSplitAmount is an error returned when a non-root split locator
	// has zero amount.
	ErrZeroSplitAmount = errors.New(
		"split locator has zero amount",
	)

	// ErrNonZeroSplitAmount is an error returned when a root locator uses
	// an un-spendable script key but has a non-zero amount.
	ErrNonZeroSplitAmount = errors.New(
		"un-spendable root locator has non-zero amount",
	)
)
View Source
var (
	// TaprootAssetsMarker is a static identifier included in the leaf
	// script of a Taproot Asset commitment to uniquely identify from any
	// other leaves in the tapscript tree.
	TaprootAssetsMarker = sha256.Sum256([]byte(taprootAssetsMarkerTag))

	// ErrMissingAssetCommitment is an error returned when we attempt to
	// update or delete a Taproot Asset commitment without an asset
	// commitment.
	ErrMissingAssetCommitment = errors.New(
		"tap commitment: missing asset commitment",
	)

	// TaprootAssetCommitmentScriptSize is the size of the Taproot Asset
	// commitment script:
	//
	//	- 1 byte for the version
	//	- 32 bytes for the TaprootAssetsMarker
	//	- 32 bytes for the root hash
	//	- 8 bytes for the root sum
	TaprootAssetCommitmentScriptSize = 1 + 32 + 32 + 8
)
View Source
var (
	// ErrInvalidTaprootProof is an error returned upon verifying an invalid
	// Taproot proof.
	ErrInvalidTaprootProof = errors.New("invalid taproot proof")

	// ErrInvalidTapscriptProof is an error returned upon attempting to
	// prove a malformed TapscriptProof.
	ErrInvalidTapscriptProof = errors.New("invalid tapscript proof")

	// ErrInvalidEmptyTapscriptPreimage is an error returned upon attempting
	// to generate the tap hash of an empty preimage.
	ErrInvalidEmptyTapscriptPreimage = errors.New(
		"invalid empty tapscript preimage",
	)

	// ErrInvalidTapscriptPreimageLen is an error returned upon attempting
	// to generate the tap hash of a branch preimage with invalid length.
	ErrInvalidTapscriptPreimageLen = errors.New(
		"invalid tapscript preimage length",
	)

	// ErrPreimageIsTapCommitment is an error returned when a tapscript
	// preimage is a valid Taproot Asset commitment.
	ErrPreimageIsTapCommitment = errors.New(
		"preimage is a Taproot Asset commitment",
	)
)
View Source
var (
	// ErrMissingAssetProof is an error returned when attempting to derive a
	// TapCommitment and an AssetProof is required but missing.
	ErrMissingAssetProof = errors.New("missing asset proof")
)

Functions

func AssetProofAssetIDRecord

func AssetProofAssetIDRecord(assetID *[32]byte) tlv.Record

func AssetProofDecoder

func AssetProofDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error

func AssetProofEncoder

func AssetProofEncoder(w io.Writer, val any, buf *[8]byte) error

func AssetProofRecord

func AssetProofRecord(proof *mssmt.Proof) tlv.Record

func AssetProofVersionRecord

func AssetProofVersionRecord(version *asset.Version) tlv.Record

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func HexTapscriptSibling added in v0.3.0

func HexTapscriptSibling(t testing.TB, ts *TapscriptPreimage) string

func IsTaprootAssetCommitmentScript

func IsTaprootAssetCommitmentScript(script []byte) bool

IsTaprootAssetCommitmentScript returns true if the passed script is a valid Taproot Asset commitment script.

func MaybeEncodeTapscriptPreimage

func MaybeEncodeTapscriptPreimage(t *TapscriptPreimage) ([]byte,
	*chainhash.Hash, error)

MaybeEncodeTapscriptPreimage returns the encoded preimage and hash of the Tapscript sibling or nil if the preimage is nil.

func NewTapBranchHash

func NewTapBranchHash(l, r chainhash.Hash) chainhash.Hash

NewTapBranchHash takes the raw tap hashes of the left and right nodes and hashes them into a branch.

func ProofAssetProofRecord

func ProofAssetProofRecord(proof **AssetProof) tlv.Record

func ProofTaprootAssetProofRecord

func ProofTaprootAssetProofRecord(proof *TaprootAssetProof) tlv.Record

func RandSplitCommit

func RandSplitCommit(t testing.TB, a asset.Asset) *asset.SplitCommitment

RandSplitCommit creates a random split commitment for testing.

func TapBranchHash

func TapBranchHash(preimage []byte) (*chainhash.Hash, error)

TapBranchHash computes the TapHash of a TapBranch node from its preimage if possible, otherwise an error is returned.

func TapLeafHash

func TapLeafHash(preimage []byte) (*chainhash.Hash, error)

TapLeafHash computes the TapHash of a TapLeaf node from its preimage if possible, otherwise an error is returned.

func TaprootAssetProofDecoder

func TaprootAssetProofDecoder(r io.Reader, val any, buf *[8]byte,
	l uint64) error

func TaprootAssetProofEncoder

func TaprootAssetProofEncoder(w io.Writer, val any, buf *[8]byte) error

func TaprootAssetProofRecord

func TaprootAssetProofRecord(proof *mssmt.Proof) tlv.Record

func TaprootAssetProofVersionRecord

func TaprootAssetProofVersionRecord(version *asset.Version) tlv.Record

func TapscriptPreimageDecoder

func TapscriptPreimageDecoder(r io.Reader, val any, buf *[8]byte,
	l uint64) error

func TapscriptPreimageEncoder

func TapscriptPreimageEncoder(w io.Writer, val any, buf *[8]byte) error

func TreeProofDecoder

func TreeProofDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error

func TreeProofEncoder

func TreeProofEncoder(w io.Writer, val any, buf *[8]byte) error

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type AssetCommitment

type AssetCommitment struct {
	// Version is the max version of the assets committed.
	Version asset.Version

	// TapKey is the common identifier for all assets found within the
	// AssetCommitment. This can either be an asset.ID, which every
	// committed asset must match, or the hash of an asset.GroupKey which
	// every committed asset must match if their asset.ID differs.
	TapKey [32]byte

	// AssetType is the type of asset(s) committed to within the tree.
	AssetType asset.Type

	// TreeRoot is the root node of the MS-SMT containing all of the
	// committed assets.
	TreeRoot *mssmt.BranchNode
	// contains filtered or unexported fields
}

AssetCommitment represents the inner MS-SMT within the Taproot Asset protocol committing to a set of assets under the same ID/group. Assets within this tree, which are leaves represented as the serialized asset TLV payload, are keyed by their `asset_script_key`.

func NewAssetCommitment

func NewAssetCommitment(assets ...*asset.Asset) (*AssetCommitment, error)

NewAssetCommitment constructs a new commitment for the given assets capable of computing merkle proofs. All assets provided should be related, i.e., their `ID` or `GroupKey` should match.

func (*AssetCommitment) Asset

func (c *AssetCommitment) Asset(key [32]byte) (*asset.Asset, bool)

Asset returns the committed asset specified by the given asset commitment key. If the asset is not present, the second result OK parameter is false.

func (*AssetCommitment) AssetProof

func (c *AssetCommitment) AssetProof(key [32]byte) (
	*asset.Asset, *mssmt.Proof, error)

AssetProof computes the AssetCommitment merkle proof for the asset leaf located at `key`. A `nil` asset is returned if the asset is not committed to.

func (*AssetCommitment) Assets

func (c *AssetCommitment) Assets() CommittedAssets

Assets returns the set of assets committed to in the asset commitment.

func (*AssetCommitment) Copy

func (c *AssetCommitment) Copy() (*AssetCommitment, error)

Copy returns a deep copy of tha target AssetCommitment.

func (*AssetCommitment) Delete

func (c *AssetCommitment) Delete(oldAsset *asset.Asset) error

Delete modifies one entry in the AssetCommitment by deleting it in the inner MS-SMT and deleting it in the internal asset map.

func (*AssetCommitment) Merge

func (c *AssetCommitment) Merge(other *AssetCommitment) error

Merge merges the other commitment into this commitment. If the other commitment is empty, then this is a no-op. If the other commitment was not constructed with NewAssetCommitment, then an error is returned.

func (*AssetCommitment) Root

func (c *AssetCommitment) Root() [sha256.Size]byte

Root computes the root identifier required to commit to this specific asset commitment within the outer commitment, also known as the Taproot Asset commitment.

func (*AssetCommitment) TapCommitmentKey

func (c *AssetCommitment) TapCommitmentKey() [32]byte

TapCommitmentKey computes the insertion key for this specific asset commitment to include in the Taproot Asset commitment MS-SMT.

func (*AssetCommitment) TapCommitmentLeaf

func (c *AssetCommitment) TapCommitmentLeaf() *mssmt.LeafNode

TapCommitmentLeaf computes the leaf node for this specific asset commitment to include in the Taproot Asset commitment MS-SMT.

func (*AssetCommitment) Upsert

func (c *AssetCommitment) Upsert(newAsset *asset.Asset) error

Upsert modifies one entry in the AssetCommitment by inserting (or updating) it in the inner MS-SMT and adding (or updating) it in the internal asset map.

type AssetCommitments

type AssetCommitments map[[32]byte]*AssetCommitment

AssetCommitments is the set of assetCommitments backing a TapCommitment. The map is keyed by the AssetCommitment's TapCommitmentKey.

type AssetDetails

type AssetDetails struct {
	// Version is the type of the asset to mint.
	Version asset.Version

	// Type is the type of asset to mint.
	Type asset.Type

	// ScriptKey is the Taproot key with ownership of the asset.
	ScriptKey keychain.KeyDescriptor

	// Amount is the amount of assets that should be minted for `ScriptKey`.
	// NOTE: This should be nil when minting `Collectible` assets.
	Amount *uint64

	// LockTime is the earliest height in the blockchain at which the
	// asset(s) to mint can be spent from `ScriptKey`.
	LockTime uint64

	// RelativeLockTime is the number of blocks after the on-chain
	// confirmation height in the blockchain at which the asset(s) to mint
	// can be spent from `ScriptKey`.
	RelativeLockTime uint64
}

AssetDetails contains all of the configurable parameters of an Asset to specify upon mint.

type AssetProof

type AssetProof struct {
	mssmt.Proof

	// Version is the max version of the assets committed.
	Version asset.Version

	// TapKey is the common identifier for all assets found within the
	// AssetCommitment. This can either be an asset.ID, which every
	// committed asset must match, otherwise an asset.GroupKey which every
	// committed asset must match.
	TapKey [32]byte
}

AssetProof is the proof used along with an asset leaf to arrive at the root of the AssetCommitment MS-SMT.

type CommittedAssets

type CommittedAssets map[[32]byte]*asset.Asset

CommittedAssets is the set of Assets backing an AssetCommitment. The map is keyed by the Asset's AssetCommitmentKey.

type InputSet

type InputSet map[asset.PrevID]*asset.Asset

InputSet represents the set of inputs for a given asset indexed by their `PrevID`.

type Proof

type Proof struct {
	// AssetProof is the proof used along with the asset to arrive at the
	// root of the AssetCommitment MS-SMT.
	//
	// NOTE: This proof must be nil if the asset commitment for this
	// particular asset is not found within the Taproot Asset commitment. In
	// this case, the TaprootAssetProof below would be a non-inclusion proof
	// of the asset commitment.
	AssetProof *AssetProof

	// TaprootAssetProof is the proof used along with the asset commitment
	// to arrive at the root of the TapCommitment MS-SMT.
	TaprootAssetProof TaprootAssetProof
}

Proof represents a full commitment proof for a particular `Asset`. It proves that an asset does or does not exist within a Taproot Asset commitment.

func (*Proof) Decode

func (p *Proof) Decode(r io.Reader) error

Decode attempts to decode the CommitmentProof from the passed io.Reader.

func (*Proof) DecodeRecords

func (p *Proof) DecodeRecords() []tlv.Record

DecodeRecords returns the decoding records for the CommitmentProof.

func (Proof) DeriveByAssetCommitmentExclusion

func (p Proof) DeriveByAssetCommitmentExclusion(tapCommitmentKey [32]byte) (
	*TapCommitment, error)

DeriveByAssetCommitmentExclusion derives the Taproot Asset commitment excluding the given asset commitment identified by its key within a TapCommitment. This consists of proving with the TaprootAssetProof that an AssetCommitment does not exist within the outer MS-SMT, also known as the TapCommitment.

func (Proof) DeriveByAssetExclusion

func (p Proof) DeriveByAssetExclusion(assetCommitmentKey [32]byte) (
	*TapCommitment, error)

DeriveByAssetExclusion derives the Taproot Asset commitment excluding the given asset identified by its key within an AssetCommitment. This consists of proving with the AssetProof that an asset does not exist within the inner MS-SMT, also known as the AssetCommitment. With the AssetCommitment obtained, the TaprootAssetProof is used to prove that the AssetCommitment exists within the outer MS-SMT, also known as the TapCommitment.

func (Proof) DeriveByAssetInclusion

func (p Proof) DeriveByAssetInclusion(asset *asset.Asset) (*TapCommitment,
	error)

DeriveByAssetInclusion derives the Taproot Asset commitment containing the provided asset. This consists of proving that an asset exists within the inner MS-SMT with the AssetProof, also known as the AssetCommitment. With the AssetCommitment obtained, the TaprootAssetProof is used to prove that it exists or within the outer MS-SMT, also known as the TapCommitment.

func (Proof) Encode

func (p Proof) Encode(w io.Writer) error

Encode attempts to encode the CommitmentProof into the passed io.Writer.

func (Proof) EncodeRecords

func (p Proof) EncodeRecords() []tlv.Record

EncodeRecords returns the encoding records for the Proof.

type SplitAsset

type SplitAsset struct {
	asset.Asset

	// OutputIndex is the index of the on-chain transaction that held the
	// split asset at the time of its creation.
	OutputIndex uint32
}

SplitAsset is an asset resulting from a split. This is the same as the underlying asset, except it also encodes its `OutputIndex`.

type SplitCommitment

type SplitCommitment struct {
	// PrevAssets is the set of asset inputs being split.
	PrevAssets InputSet

	// RootAsset is the root asset resulting after the creation of split
	// assets containing the SplitCommitmentRoot.
	RootAsset *asset.Asset

	// SplitAssets is the set of asset splits within the on-chain
	// transaction committed to within the split commitment MS-SMT.
	SplitAssets SplitSet
	// contains filtered or unexported fields
}

SplitCommitment encodes all of the data necessary to generate and validate a set of asset splits from its root.

func NewSplitCommitment

func NewSplitCommitment(ctx context.Context, inputs []SplitCommitmentInput,
	rootLocator *SplitLocator,
	externalLocators ...*SplitLocator) (*SplitCommitment, error)

NewSplitCommitment computes a new SplitCommitment based on the given input assets. It creates a set of asset splits uniquely identified by their `locators`. The resulting asset splits are committed to a MS-SMT and its root is placed within the root asset, which should have a signature over the split state transition to authenticate the transfer. This signature on the root asset needs to be provided after the fact. The rootLocator field is considered to be the "change" output in the transfer: this is the location where all the other splits (elsewhere in the transaction are committed to).

type SplitCommitmentInput

type SplitCommitmentInput struct {
	// Asset is the input asset.
	Asset *asset.Asset

	// OutPoint is the input asset's on-chain outpoint.
	OutPoint wire.OutPoint
}

SplitCommitmentInput holds input asset specific data used in constructing a new split commitment.

type SplitLocator

type SplitLocator struct {
	// OutputIndex is the output index of the on-chain transaction which
	// the asset split was sent to.
	OutputIndex uint32

	// AssetID is the unique ID of the asset.
	AssetID asset.ID

	// ScriptKey is the Taproot tweaked key encoding the different spend
	// conditions possible for the asset split.
	ScriptKey asset.SerializedKey

	// Amount is the amount of units for the asset split.
	Amount uint64

	// AssetVersion is the version that the asset split should use.
	AssetVersion asset.Version
}

SplitLocator encodes the data that uniquely identifies an asset split within a split commitment tree.

func (SplitLocator) Hash

func (l SplitLocator) Hash() [sha256.Size]byte

Hash computes the hash of a SplitLocator, encumbering its `OutputIndex`, `AssetID` and `ScriptKey`. This hash is used as the key for the asset split within a split commitment tree.

type SplitSet

type SplitSet map[SplitLocator]*SplitAsset

SplitSet is a type to represent a set of asset splits.

type TapCommitment

type TapCommitment struct {
	// Version is the maximum Taproot Asset version found within all of the
	// assets committed.
	Version asset.Version

	// TreeRoot is the root node of the MS-SMT containing all of the asset
	// commitments.
	TreeRoot *mssmt.BranchNode
	// contains filtered or unexported fields
}

TapCommitment represents the outer MS-SMT within the Taproot Asset protocol committing to a set of asset commitments. Asset commitments, which are leaves represented as `asset_version || asset_tree_root || asset_sum`, are keyed by their `asset_group_key` or `asset_id` otherwise.

func FromAssets

func FromAssets(assets ...*asset.Asset) (*TapCommitment, error)

FromAssets creates a new Taproot Asset commitment for the given assets, creating the appropriate asset commitments internally.

func Mint

func Mint(genesis asset.Genesis, groupKey *asset.GroupKey,
	details ...*AssetDetails) (*TapCommitment, []*asset.Asset, error)

Mint mints a series of assets within a new Taproot Asset commitment. The distribution and other parameters of these assets can be specified through `AssetDetails`.

func NewTapCommitment

func NewTapCommitment(newCommitments ...*AssetCommitment) (*TapCommitment,
	error)

NewTapCommitment creates a new Taproot Asset commitment for the given asset commitments capable of computing merkle proofs.

func NewTapCommitmentWithRoot

func NewTapCommitmentWithRoot(version asset.Version,
	root *mssmt.BranchNode) *TapCommitment

NewTapCommitmentWithRoot creates a new Taproot Asset commitment backed by the root node. The resulting commitment will not be able to compute merkle proofs as it only knows of the tree's root node, and not the tree itself.

func (*TapCommitment) Commitment

func (c *TapCommitment) Commitment(a *asset.Asset) (*AssetCommitment, bool)

Commitment returns the asset commitment for the given asset. If the asset commitment is not found, the second returned value is false.

func (*TapCommitment) Commitments

func (c *TapCommitment) Commitments() AssetCommitments

Commitments returns the set of assetCommitments committed to in the Taproot Asset commitment.

func (*TapCommitment) CommittedAssets

func (c *TapCommitment) CommittedAssets() []*asset.Asset

CommittedAssets returns the set of assets committed to in the Taproot Asset commitment.

func (*TapCommitment) Copy

func (c *TapCommitment) Copy() (*TapCommitment, error)

Copy performs a deep copy of the passed Taproot Asset commitment.

func (*TapCommitment) Delete

func (c *TapCommitment) Delete(assetCommitment *AssetCommitment) error

Delete modifies one entry in the TapCommitment by deleting it in the inner MS-SMT and in the internal AssetCommitment map.

func (*TapCommitment) Merge

func (c *TapCommitment) Merge(other *TapCommitment) error

Merge merges the other commitment into this commitment. If the other commitment is empty, then this is a no-op. If the other commitment was constructed with NewTapCommitmentWithRoot, then an error is returned.

func (*TapCommitment) Proof

func (c *TapCommitment) Proof(tapCommitmentKey,
	assetCommitmentKey [32]byte) (*asset.Asset, *Proof, error)

Proof computes the full TapCommitment merkle proof for the asset leaf located at `assetCommitmentKey` within the AssetCommitment located at `tapCommitmentKey`.

func (*TapCommitment) TapLeaf

func (c *TapCommitment) TapLeaf() txscript.TapLeaf

TapLeaf constructs a new `TapLeaf` for this `TapCommitment`.

func (*TapCommitment) TapscriptRoot

func (c *TapCommitment) TapscriptRoot(sibling *chainhash.Hash) chainhash.Hash

TapscriptRoot returns the tapscript root for this TapCommitment. If `sibling` is not nil, we assume it is a valid sibling (e.g., not a duplicate Taproot Asset commitment), and hash it with the Taproot Asset commitment leaf to arrive at the tapscript root, otherwise the Taproot Asset commitment leaf itself becomes the tapscript root.

func (*TapCommitment) Upsert

func (c *TapCommitment) Upsert(assetCommitment *AssetCommitment) error

Upsert modifies one entry in the TapCommitment by inserting (or updating) it in the inner MS-SMT and in the internal AssetCommitment map. If the asset commitment passed in is empty, it is instead pruned from the Taproot Asset tree.

type TaprootAssetProof

type TaprootAssetProof struct {
	mssmt.Proof

	// Version is the max version committed of the AssetCommitment's
	// included in the TapCommitment.
	Version asset.Version
}

TaprootAssetProof is the proof used along with an asset commitment leaf to arrive at the root of the TapCommitment MS-SMT.

type TapscriptPreimage

type TapscriptPreimage struct {
	// SiblingPreimage is the pre-image itself. This will be either 32 or
	// 64 bytes.
	SiblingPreimage []byte

	// SiblingType is the type of the pre-image.
	SiblingType TapscriptPreimageType
}

TapscriptPreimage wraps a pre-image byte slice with a type byte that self identifies what type of pre-image it is.

func MaybeDecodeTapscriptPreimage

func MaybeDecodeTapscriptPreimage(encoded []byte) (*TapscriptPreimage,
	*chainhash.Hash, error)

MaybeDecodeTapscriptPreimage returns the decoded preimage and hash of the Tapscript sibling or nil if the encoded content is empty.

func NewPreimageFromBranch

func NewPreimageFromBranch(branch txscript.TapBranch) *TapscriptPreimage

NewPreimageFromBranch creates a new TapscriptPreimage from a tap branch.

func NewPreimageFromLeaf

func NewPreimageFromLeaf(leaf txscript.TapLeaf) *TapscriptPreimage

NewPreimageFromLeaf creates a new TapscriptPreimage from a single tap leaf.

func ParseTapscriptSibling added in v0.3.0

func ParseTapscriptSibling(t testing.TB, ts string) *TapscriptPreimage

func (*TapscriptPreimage) IsEmpty

func (t *TapscriptPreimage) IsEmpty() bool

IsEmpty returns true if the sibling pre-image is empty.

func (*TapscriptPreimage) TapHash

func (t *TapscriptPreimage) TapHash() (*chainhash.Hash, error)

TapHash returns the tap hash of this preimage according to its type.

func (*TapscriptPreimage) VerifyNoCommitment

func (t *TapscriptPreimage) VerifyNoCommitment() error

VerifyNoCommitment verifies that the preimage is not a Taproot Asset commitment.

type TapscriptPreimageType

type TapscriptPreimageType uint8

TapscriptPreimageType denotes the type of tapscript sibling preimage.

const (
	// LeafPreimage is a pre-image that's a leaf script.
	LeafPreimage TapscriptPreimageType = 0

	// BranchPreimage is a pre-image that's a branch, so it's actually
	// 64-bytes of two child pre-images.
	BranchPreimage TapscriptPreimageType = 1
)

func (TapscriptPreimageType) String

func (t TapscriptPreimageType) String() string

String returns a human-readable string for the TapscriptPreimageType.

type TestAssetProof added in v0.3.0

type TestAssetProof struct {
	Proof   string `json:"proof"`
	Version uint8  `json:"version"`
	TapKey  string `json:"tap_key"`
}

type TestInputEntry added in v0.3.0

type TestInputEntry struct {
	PrevID *asset.TestPrevID `json:"prev_id"`
	Asset  *asset.TestAsset  `json:"asset"`
}

type TestInputSet added in v0.3.0

type TestInputSet []*TestInputEntry

func NewTestFromInputSet added in v0.3.0

func NewTestFromInputSet(t testing.TB, i InputSet) TestInputSet

func (TestInputSet) ToInputSet added in v0.3.0

func (ts TestInputSet) ToInputSet(t testing.TB) InputSet

type TestProof added in v0.3.0

type TestProof struct {
	AssetProof        *TestAssetProof        `json:"asset_proof"`
	TaprootAssetProof *TestTaprootAssetProof `json:"taproot_asset_proof"`
}

func NewTestFromProof added in v0.3.0

func NewTestFromProof(t testing.TB, p *Proof) *TestProof

func (*TestProof) ToProof added in v0.3.0

func (tp *TestProof) ToProof(t testing.TB) *Proof

type TestSplitAsset added in v0.3.0

type TestSplitAsset struct {
	Asset       *asset.TestAsset `json:"asset"`
	OutputIndex uint32           `json:"output_index"`
}

type TestSplitEntry added in v0.3.0

type TestSplitEntry struct {
	Locator *TestSplitLocator `json:"key"`
	Asset   *TestSplitAsset   `json:"value"`
}

type TestSplitLocator added in v0.3.0

type TestSplitLocator struct {
	OutputIndex uint32 `json:"output_index"`
	AssetID     string `json:"asset_id"`
	ScriptKey   string `json:"script_key"`
	Amount      uint64 `json:"amount"`
}

type TestSplitSet added in v0.3.0

type TestSplitSet []*TestSplitEntry

func NewTestFromSplitSet added in v0.3.0

func NewTestFromSplitSet(t testing.TB, s SplitSet) TestSplitSet

func (TestSplitSet) ToSplitSet added in v0.3.0

func (ts TestSplitSet) ToSplitSet(t testing.TB) SplitSet

type TestTaprootAssetProof added in v0.3.0

type TestTaprootAssetProof struct {
	Proof   string `json:"proof"`
	Version uint8  `json:"version"`
}

Jump to

Keyboard shortcuts

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