commitment

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 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",
	)

	// ErrInvalidTapCommitmentVersion is an error returned when we attempt
	// to create a TapCommitment with an invalid TapCommitmentVersion.
	ErrInvalidTapCommitmentVersion = errors.New(
		"tap commitment: invalid version",
	)

	// 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",
	)

	// ErrInvalidTapscriptPreimageType is an error returned when a tapscript
	// preimage has an unknown type that is not leaf nor branch.
	ErrInvalidTapscriptPreimageType = errors.New(
		"unknown tapscript preimage type",
	)

	// 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")
)

KnownAssetProofTypes is a set of all known asset proof TLV types. This set is asserted to be complete by a check in the BIP test vector unit tests.

KnownProofTypes is a set of all known proof TLV types. This set is asserted to be complete by a check in the BIP test vector unit tests.

KnownTaprootAssetProofTypes is a set of all known taproot asset proof TLV types. This set is asserted to be complete by a check in the BIP test vector unit tests.

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 IsSimilarTapCommitmentVersion added in v0.4.0

func IsSimilarTapCommitmentVersion(a, b *TapCommitmentVersion) bool

IsSimilarTapCommitmentVersion returns true if both TapCommitmentVersions are nil, equal, or would map to the same TapCommitmentVersion.

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 NewLeafFromPreimage added in v0.4.0

func NewLeafFromPreimage(preimage TapscriptPreimage) (*txscript.TapLeaf,
	error)

NewLeafFromPreimage sanity checks a TapscriptPreimage and decodes it into a TapLeaf.

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 TapCommitmentVersionDecoder added in v0.4.0

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

func TapCommitmentVersionEncoder added in v0.4.0

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

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 *TapCommitmentVersion) 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

	// UnknownOddTypes is a map of unknown odd types that were encountered
	// during decoding. This map is used to preserve unknown types that we
	// don't know of yet, so we can still encode them back when serializing.
	// This enables forward compatibility with future versions of the
	// protocol as it allows new odd (optional) types to be added without
	// breaking old clients that don't yet fully understand them.
	UnknownOddTypes tlv.TypeMap
}

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

func (*AssetProof) Records added in v0.5.0

func (a *AssetProof) Records() []tlv.Record

Records returns the encoding/decoding records for the AssetProof.

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

	// UnknownOddTypes is a map of unknown odd types that were encountered
	// during decoding. This map is used to preserve unknown types that we
	// don't know of yet, so we can still encode them back when serializing.
	// This enables forward compatibility with future versions of the
	// protocol as it allows new odd (optional) types to be added without
	// breaking old clients that don't yet fully understand them.
	UnknownOddTypes tlv.TypeMap
}

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 version of the Taproot Asset commitment.
	Version TapCommitmentVersion

	// 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(version *TapCommitmentVersion,
	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(version *TapCommitmentVersion, 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(version *TapCommitmentVersion,
	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 TapCommitmentVersion,
	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 TrimAltLeaves added in v0.5.0

func TrimAltLeaves(c *TapCommitment) (*TapCommitment, []*asset.Asset, error)

TrimAltLeaves creates a new TapCommitment with any AltLeaves removed, if present. The removed AltLeaves are returned separately.

func TrimSplitWitnesses added in v0.4.0

func TrimSplitWitnesses(version *TapCommitmentVersion,
	c *TapCommitment) (*TapCommitment, error)

TrimSplitWitnesses returns a copy of the commitment in which all assets with a split commitment witness have their SplitCommitment field set to nil.

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) Downgrade added in v0.4.0

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

Downgrade returns a taproot asset commitment with the same root, but with the asset commitment version downgraded to V0. This is useful for unit tests.

func (*TapCommitment) FetchAltLeaves added in v0.5.0

func (c *TapCommitment) FetchAltLeaves() ([]*asset.Asset, error)

FetchAltLeaves returns a copy of any AltLeaves present in the TapCommitment.

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) MergeAltLeaves added in v0.5.0

func (c *TapCommitment) MergeAltLeaves(
	altLeaves []asset.AltLeaf[asset.Asset]) error

MergeAltLeaves adds a set of AltLeaves to an existing TapCommitment. Merging fails if the new AltLeaves collide with any existing AltLeaves.

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 TapCommitmentVersion added in v0.4.0

type TapCommitmentVersion uint8

TapCommitmentVersion denotes the structure of the Taproot Asset commitment MS-SMT and the procedure for building a TapLeaf from a Taproot Asset commitment.

const (
	// TapCommitmentV0 is the initial Taproot Asset Commitment version. A
	// V0 commitment uses the legacy TapLeaf format, and ONLY commits to V0
	// assets.
	TapCommitmentV0 TapCommitmentVersion = 0

	// TapCommitmentV1 is used by Taproot Asset Commitments that commit to
	// V0 or V1 assets. A V1 commitment uses the legacy TapLeaf format.
	TapCommitmentV1 TapCommitmentVersion = 1

	// TapCommitmentV2 is used by Taproot Asset Commitments that commit to
	// V0 or V1 assets. A V2 commitment uses the V1 TapLeaf format.
	TapCommitmentV2 TapCommitmentVersion = 2
)

func RandTapCommitVersion added in v0.4.0

func RandTapCommitVersion() *TapCommitmentVersion

type TaprootAssetProof

type TaprootAssetProof struct {
	mssmt.Proof

	// Version is the version of the TapCommitment used to create the proof.
	Version TapCommitmentVersion

	// UnknownOddTypes is a map of unknown odd types that were encountered
	// during decoding. This map is used to preserve unknown types that we
	// don't know of yet, so we can still encode them back when serializing.
	// This enables forward compatibility with future versions of the
	// protocol as it allows new odd (optional) types to be added without
	// breaking old clients that don't yet fully understand them.
	UnknownOddTypes tlv.TypeMap
}

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

func (*TaprootAssetProof) Records added in v0.5.0

func (t *TaprootAssetProof) Records() []tlv.Record

Records returns the encoding/decoding records for the TaprootAssetProof.

type TapscriptPreimage

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

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, error)

NewPreimageFromLeaf creates a new TapscriptPreimage from a single tap leaf.

func NewPreimageFromTapscriptTreeNodes added in v0.4.0

func NewPreimageFromTapscriptTreeNodes(
	tn asset.TapscriptTreeNodes) (*TapscriptPreimage, error)

NewPreimageFromTapscriptTreeNodes constructs a taproot sibling hash from Tapscript tree nodes, to be used with a TapCommitment tree root to derive a tapscript root. This could be multiple TapLeaf objects, or a representation of a TapBranch.

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) Type added in v0.4.0

Type returns the preimage type.

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"`
	UnknownOddTypes tlv.TypeMap `json:"unknown_odd_types"`
}

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"`
	UnknownOddTypes   tlv.TypeMap            `json:"unknown_odd_types"`
}

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"`
	UnknownOddTypes tlv.TypeMap `json:"unknown_odd_types"`
}

Jump to

Keyboard shortcuts

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