Documentation ¶
Index ¶
- Constants
- Variables
- func AssetCommitmentKey(assetID ID, scriptKey *btcec.PublicKey, issuanceDisabled bool) [32]byte
- func BranchNodesRootHash(b TapBranchNodes) chainhash.Hash
- func CheckTapLeafSanity(leaf *txscript.TapLeaf) error
- func CheckTapLeavesSanity(leaves []txscript.TapLeaf) error
- func CompressedPubKeyDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func CompressedPubKeyEncoder(w io.Writer, val any, buf *[8]byte) error
- func ComputeTaprootScript(witnessProgram []byte) ([]byte, error)
- func DVarBytesWithLimit(limit uint64) tlv.Decoder
- func DecodeTapLeaf(leafData []byte) (*txscript.TapLeaf, error)
- func DeriveBurnKey(firstPrevID PrevID) *btcec.PublicKey
- func EncodeTapBranchNodes(branch TapBranchNodes) [][]byte
- func EncodeTapLeaf(leaf *txscript.TapLeaf) ([]byte, error)
- func EncodeTapLeafNodes(leaves TapLeafNodes) ([][]byte, error)
- func EqualKeyDescriptors(a, o keychain.KeyDescriptor) bool
- func GenesisDecoder(r io.Reader, val any, buf *[8]byte, _ uint64) error
- func GenesisEncoder(w io.Writer, val any, buf *[8]byte) error
- func GenesisPrevOutFetcher(prevAsset Asset) (*txscript.CannedPrevOutputFetcher, error)
- func GetBranch(ttn TapscriptTreeNodes) fn.Option[TapBranchNodes]
- func GetLeaves(ttn TapscriptTreeNodes) fn.Option[TapLeafNodes]
- func GroupKeyDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func GroupKeyEncoder(w io.Writer, val any, buf *[8]byte) error
- func GroupPubKey(rawKey *btcec.PublicKey, singleTweak, tapTweak []byte) (*btcec.PublicKey, error)
- func IDDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func IDEncoder(w io.Writer, val any, buf *[8]byte) error
- func InlineVarBytesDecoder(r io.Reader, val any, buf *[8]byte, maxLen uint64) error
- func InlineVarBytesEncoder(w io.Writer, val any, buf *[8]byte) error
- func InputGenesisAssetPrevOut(prevAsset Asset) (*wire.TxOut, error)
- func IsBurnKey(scriptKey *btcec.PublicKey, witness Witness) bool
- func IsGroupSig(witness wire.TxWitness) (*schnorr.Signature, bool)
- func IsSplitCommitWitness(witness Witness) bool
- func LeafDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func LeafEncoder(w io.Writer, val any, buf *[8]byte) error
- func LeafNodesRootHash(l TapLeafNodes) chainhash.Hash
- func NewLeafAmountRecord(amount *uint64) tlv.Record
- func NewLeafGenesisRecord(genesis *Genesis) tlv.Record
- func NewLeafGroupKeyRecord(groupKey **GroupKey) tlv.Record
- func NewLeafLockTimeRecord(lockTime *uint64) tlv.Record
- func NewLeafPrevWitnessRecord(prevWitnesses *[]Witness, encodeType EncodeType) tlv.Record
- func NewLeafRelativeLockTimeRecord(relativeLockTime *uint64) tlv.Record
- func NewLeafScriptKeyRecord(scriptKey **btcec.PublicKey) tlv.Record
- func NewLeafScriptVersionRecord(version *ScriptVersion) tlv.Record
- func NewLeafSplitCommitmentRootRecord(root *mssmt.Node) tlv.Record
- func NewLeafTypeRecord(assetType *Type) tlv.Record
- func NewLeafVersionRecord(version *Version) tlv.Record
- func NewTapBranchHash(l, r chainhash.Hash) chainhash.Hash
- func NewWitnessPrevIDRecord(prevID **PrevID) tlv.Record
- func NewWitnessSplitCommitmentRecord(commitment **SplitCommitment) tlv.Record
- func NewWitnessTxWitnessRecord(witness *wire.TxWitness) tlv.Record
- func OutPointDecoder(r io.Reader, val any, buf *[8]byte, _ uint64) error
- func OutPointEncoder(w io.Writer, val any, buf *[8]byte) error
- func ParseGroupSig(witness []byte) (*schnorr.Signature, error)
- func ParseGroupWitness(witness []byte) (wire.TxWitness, error)
- func PrevIDDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func PrevIDEncoder(w io.Writer, val any, buf *[8]byte) error
- func SchnorrSignatureDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func SchnorrSignatureEncoder(w io.Writer, val any, buf *[8]byte) error
- func ScriptVersionDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func ScriptVersionEncoder(w io.Writer, val any, buf *[8]byte) error
- func SerializeGroupWitness(witness wire.TxWitness) ([]byte, error)
- func SerializedKeyDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func SerializedKeyEncoder(w io.Writer, val any, buf *[8]byte) error
- func SignOutputRaw(priv *btcec.PrivateKey, tx *wire.MsgTx, signDesc *input.SignDescriptor) (*schnorr.Signature, error)
- func SignVirtualTx(priv *btcec.PrivateKey, signDesc *lndclient.SignDescriptor, tx *wire.MsgTx, ...) (*schnorr.Signature, error)
- func SplitCommitmentDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func SplitCommitmentEncoder(w io.Writer, val any, buf *[8]byte) error
- func SplitCommitmentRootDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func SplitCommitmentRootEncoder(w io.Writer, val any, buf *[8]byte) error
- func TapCommitmentKey(assetID ID, groupKey *btcec.PublicKey) [32]byte
- func ToBranch(b TapBranchNodes) [][]byte
- func ToLeaves(l TapLeafNodes) []txscript.TapLeaf
- func TxWitnessDecoder(r io.Reader, val any, buf *[8]byte, _ uint64) error
- func TxWitnessEncoder(w io.Writer, val any, buf *[8]byte) error
- func TypeDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func TypeEncoder(w io.Writer, val any, buf *[8]byte) error
- func ValidateAssetName(name string) error
- func VarIntDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func VarIntEncoder(w io.Writer, val any, buf *[8]byte) error
- func VersionDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
- func VersionEncoder(w io.Writer, val any, buf *[8]byte) error
- func VirtualGenesisTxIn(newAsset *Asset) (*wire.TxIn, mssmt.Tree, error)
- func VirtualTxInPrevOut(root mssmt.Node) *wire.OutPoint
- func VirtualTxWithInput(virtualTx *wire.MsgTx, lockTime, relativeLockTime uint64, idx uint32, ...) *wire.MsgTx
- func WitnessDecoder(r io.Reader, val any, buf *[8]byte, _ uint64) error
- func WitnessEncoder(w io.Writer, val any, buf *[8]byte) error
- func WitnessEncoderWithType(encodeType EncodeType) tlv.Encoder
- type Asset
- func AssetCustomGroupKey(t *testing.T, useHashLock, BIP86, keySpend, validScriptWitness bool, ...) *Asset
- func New(genesis Genesis, amount, locktime, relativeLocktime uint64, ...) (*Asset, error)
- func NewAssetNoErr(t testing.TB, gen Genesis, amt, locktime, relocktime uint64, ...) *Asset
- func RandAsset(t testing.TB, assetType Type) *Asset
- func RandAssetWithValues(t testing.TB, genesis Genesis, groupKey *GroupKey, scriptKey ScriptKey) *Asset
- func (a *Asset) AssetCommitmentKey() [32]byte
- func (a *Asset) Copy() *Asset
- func (a *Asset) Decode(r io.Reader) error
- func (a *Asset) DecodeRecords() []tlv.Record
- func (a *Asset) DeepEqual(o *Asset) bool
- func (a *Asset) DeepEqualAllowSegWitIgnoreTxWitness(o *Asset) bool
- func (a *Asset) Encode(w io.Writer) error
- func (a *Asset) EncodeNoWitness(w io.Writer) error
- func (a *Asset) EncodeRecords() []tlv.Record
- func (a *Asset) HasGenesisWitness() bool
- func (a *Asset) HasGenesisWitnessForGroup() bool
- func (a *Asset) HasSplitCommitmentWitness() bool
- func (a *Asset) IsBurn() bool
- func (a *Asset) IsGenesisAsset() bool
- func (a *Asset) IsUnSpendable() bool
- func (a *Asset) IsUnknownVersion() bool
- func (a *Asset) Leaf() (*mssmt.LeafNode, error)
- func (a *Asset) NeedsGenesisWitnessForGroup() bool
- func (a *Asset) PrimaryPrevID() (*PrevID, error)
- func (a *Asset) Record() tlv.Record
- func (a *Asset) TapCommitmentKey() [32]byte
- func (a *Asset) UpdateTxWitness(prevWitnessIndex int, witness wire.TxWitness) error
- func (a *Asset) Validate() error
- func (a *Asset) Witnesses() []Witness
- type AssetGroup
- type BurnTestVectors
- type ChainAsset
- type ChainLookup
- type EncodeType
- type ErrorTestCase
- type Genesis
- type GenesisSigner
- type GenesisTxBuilder
- type GroupKey
- func AssembleGroupKeyFromWitness(genTx GroupVirtualTx, req GroupKeyRequest, tapLeaf *psbt.TaprootTapLeafScript, ...) (*GroupKey, error)
- func DeriveGroupKey(genSigner GenesisSigner, genTx GroupVirtualTx, req GroupKeyRequest, ...) (*GroupKey, error)
- func RandGroupKey(t testing.TB, genesis Genesis, newAsset *Asset) *GroupKey
- func RandGroupKeyWithSigner(t testing.TB, genesis Genesis, newAsset *Asset) (*GroupKey, []byte)
- type GroupKeyRequest
- type GroupKeyReveal
- type GroupVirtualTx
- type ID
- type LeafTlvType
- type MockGenesisSigner
- type MockGroupTxBuilder
- type NewAssetOpt
- type PendingGroupWitness
- type PrevID
- type ScriptKey
- type ScriptVersion
- type SerializedKey
- type SplitCommitment
- type TapBranchNodes
- type TapLeafNodes
- type TapscriptTreeManager
- type TapscriptTreeNodes
- type TestAsset
- type TestGenesisReveal
- type TestGroupKey
- type TestGroupKeyReveal
- type TestPrevID
- type TestScriptKey
- type TestSplitCommitment
- type TestVectors
- type TestWitness
- type TweakedScriptKey
- type Type
- type ValidBurnTestCase
- type ValidTestCase
- type Version
- type Witness
- func (w *Witness) Decode(r io.Reader) error
- func (w *Witness) DecodeRecords() []tlv.Record
- func (w *Witness) DeepEqual(skipTxWitness bool, o *Witness) bool
- func (w *Witness) Encode(writer io.Writer) error
- func (w *Witness) EncodeNoWitness(writer io.Writer) error
- func (w *Witness) EncodeRecords() []tlv.Record
- type WitnessTlvType
Constants ¶
const ( // MaxAssetNameLength is the maximum byte length of an asset's name. // This byte length is equivalent to character count for single-byte // UTF-8 characters. MaxAssetNameLength = 64 // MaxAssetEncodeSizeBytes is the size we expect an asset to not exceed // in its encoded form. This is used to prevent OOMs when decoding // assets. The main contributing factor to this size are the previous // witnesses which we currently allow to number up to 65k witnesses. MaxAssetEncodeSizeBytes = blockchain.MaxBlockWeight )
const (
// MetaHashLen is the length of the metadata hash.
MetaHashLen = 32
)
const TapBranchNodesLen = 64
TapBranchNodesLen is the length of a TapBranch represented as a byte arrray.
const ( // TaprootAssetsKeyFamily is the key family used to generate internal // keys that tapd will use creating internal taproot keys and also any // other keys used for asset script keys. // This was derived via: sum(map(lambda y: ord(y), 'tapd')). // In order words: take the word tapd and return the integer // representation of each character and sum those. We get 425, then // divide that by 2, to allow us to fit this into just a 2-byte integer // and to ensure compatibility with the remote signer. TaprootAssetsKeyFamily = 212 )
Variables ¶
var ( // ZeroPrevID is the blank prev ID used for genesis assets and also // asset split leaves. ZeroPrevID PrevID // NUMSBytes is the NUMs point we'll use for un-spendable script keys. // It was generated via a try-and-increment approach using the phrase // "taproot-assets" with SHA2-256. The code for the try-and-increment // approach can be seen here: // https://github.com/lightninglabs/lightning-node-connect/tree/master/mailbox/numsgen NUMSBytes, _ = hex.DecodeString( "027c79b9b26e463895eef5679d8558942c86c4ad2233adef01bc3e6d540b" + "3653fe", ) NUMSPubKey, _ = btcec.ParsePubKey(NUMSBytes) NUMSCompressedKey = ToSerialized(NUMSPubKey) NUMSScriptKey = ScriptKey{ PubKey: NUMSPubKey, } // ErrUnknownVersion is returned when an asset with an unknown asset // version is being used. ErrUnknownVersion = errors.New("asset: unknown asset version") )
var ( // ErrTooManyInputs is returned when an asset TLV atempts to reference // too many inputs. ErrTooManyInputs = errors.New("witnesses: witness elements") // ErrByteSliceTooLarge is returned when an encoded byte slice is too // large. ErrByteSliceTooLarge = errors.New("bytes: too large") )
var ( // ErrTreeNotFound is returned when a TapscriptTreeManager attempts to // load a Tapscript tree, but found no tree nodes. ErrTreeNotFound = errors.New("tapscript tree not found") // ErrInvalidTapBranch is returned when decoding a slice of byte slices // to a TapBranch, and there are not exactly two slices. ErrInvalidTapBranch = errors.New( "tapscript tree branch must be 2 nodes", ) )
Functions ¶
func AssetCommitmentKey ¶
AssetCommitmentKey returns a key which can be used to locate an asset within an AssetCommitment that is specific to a particular owner (script key).
NOTE: This function is also used outside the asset package.
func BranchNodesRootHash ¶ added in v0.4.0
func BranchNodesRootHash(b TapBranchNodes) chainhash.Hash
BranchNodesRootHash returns the root hash of a Tapscript tree built from the tapHashes stored in a TapBranchNodes object.
func CheckTapLeafSanity ¶ added in v0.4.0
CheckTapLeafSanity asserts that a TapLeaf script is smaller than the maximum witness size, and that the TapLeaf version is Tapscript v0.
func CheckTapLeavesSanity ¶ added in v0.4.0
CheckTapLeavesSanity asserts that a slice of TapLeafs is below the maximum size, and that each leaf passes a sanity check for script version and size.
func CompressedPubKeyDecoder ¶
func CompressedPubKeyEncoder ¶
func ComputeTaprootScript ¶ added in v0.3.0
ComputeTaprootScript computes the on-chain SegWit v1 script, known as Taproot, based on the given `witnessProgram`.
func DVarBytesWithLimit ¶ added in v0.3.0
func DecodeTapLeaf ¶ added in v0.4.0
DecodeTapLeaf decodes a byte slice containing a TapLeaf TLV record prefixed with a varint indicating the length of the record.
func DeriveBurnKey ¶ added in v0.3.0
func DeriveBurnKey(firstPrevID PrevID) *btcec.PublicKey
DeriveBurnKey derives a provably un-spendable but unique key by tweaking the public NUMS key with a tap tweak:
burnTweak = h_tapTweak(NUMSKey || outPoint || assetID || scriptKey) burnKey = NUMSKey + burnTweak*G
The firstPrevID must be the PrevID from the first input that is being spent by the virtual transaction that contains the burn.
func EncodeTapBranchNodes ¶ added in v0.4.0
func EncodeTapBranchNodes(branch TapBranchNodes) [][]byte
func EncodeTapLeaf ¶ added in v0.4.0
EncodeTapLeaf encodes a TapLeaf into a byte slice containing a TapLeaf TLV record, prefixed with a varint indicating the length of the record.
func EncodeTapLeafNodes ¶ added in v0.4.0
func EncodeTapLeafNodes(leaves TapLeafNodes) ([][]byte, error)
func EqualKeyDescriptors ¶
func EqualKeyDescriptors(a, o keychain.KeyDescriptor) bool
EqualKeyDescriptors returns true if the two key descriptors are equal.
func GenesisPrevOutFetcher ¶ added in v0.3.0
func GenesisPrevOutFetcher(prevAsset Asset) (*txscript.CannedPrevOutputFetcher, error)
GenesisPrevOutFetcher returns a Taproot Asset input's `PrevOutFetcher` to be used throughout signing when the input asset is a genesis grouped asset.
func GetBranch ¶ added in v0.4.0
func GetBranch(ttn TapscriptTreeNodes) fn.Option[TapBranchNodes]
GetBranch returns an Option containing a copy of the internal TapBranchNodes, if it exists.
func GetLeaves ¶ added in v0.4.0
func GetLeaves(ttn TapscriptTreeNodes) fn.Option[TapLeafNodes]
GetLeaves returns an Option containing a copy of the internal TapLeafNodes, if it exists.
func GroupPubKey ¶ added in v0.3.0
GroupPubKey derives a tweaked group key from a public key and two tweaks; the single tweak is the asset ID of the group anchor asset, and the tapTweak is the root of a tapscript tree that commits to script-based conditions for reissuing assets as part of this asset group. The tweaked key is defined by:
internalKey = rawKey + singleTweak * G tweakedGroupKey = TapTweak(internalKey, tapTweak)
func InlineVarBytesDecoder ¶ added in v0.3.0
func InlineVarBytesEncoder ¶ added in v0.3.0
func InputGenesisAssetPrevOut ¶ added in v0.3.0
InputGenesisAssetPrevOut returns a TxOut that represents the input asset in a Taproot Asset virtual TX, but uses tweaked group key of the input asset to enable group witness validation.
func IsBurnKey ¶ added in v0.3.0
IsBurnKey returns true if the given script key is a valid burn key for the given witness.
func IsGroupSig ¶ added in v0.3.0
IsGroupSig checks if the given witness represents a key path spend of the tweaked group key. Such a witness must include one Schnorr signature, and can include an optional annex (matching the rules specified in BIP-341). If the signature is valid, IsGroupSig returns true and the parsed signature.
func IsSplitCommitWitness ¶ added in v0.3.0
IsSplitCommitWitness returns true if the witness is a split-commitment witness.
func LeafNodesRootHash ¶ added in v0.4.0
func LeafNodesRootHash(l TapLeafNodes) chainhash.Hash
LeafNodesRootHash returns the root hash of a Tapscript tree built from the TapLeaf nodes in a TapLeafNodes object.
func NewLeafAmountRecord ¶
func NewLeafGenesisRecord ¶
func NewLeafGroupKeyRecord ¶
func NewLeafLockTimeRecord ¶
func NewLeafPrevWitnessRecord ¶
func NewLeafPrevWitnessRecord(prevWitnesses *[]Witness, encodeType EncodeType) tlv.Record
func NewLeafScriptKeyRecord ¶
func NewLeafScriptVersionRecord ¶
func NewLeafScriptVersionRecord(version *ScriptVersion) tlv.Record
func NewLeafTypeRecord ¶
func NewLeafVersionRecord ¶
func NewTapBranchHash ¶ added in v0.4.0
NewTapBranchHash takes the raw tap hashes of the left and right nodes and hashes them into a branch.
func NewWitnessPrevIDRecord ¶
func NewWitnessSplitCommitmentRecord ¶
func NewWitnessSplitCommitmentRecord(commitment **SplitCommitment) tlv.Record
func ParseGroupSig ¶ added in v0.3.0
ParseGroupSig parses a group signature that was stored as a group witness in the DB. It returns an error if the witness is not a single Schnorr signature.
func ParseGroupWitness ¶ added in v0.3.0
ParseGroupWitness parses a group witness that was stored as a TLV stream in the DB.
func SchnorrSignatureDecoder ¶
func SchnorrSignatureEncoder ¶
func ScriptVersionDecoder ¶
func SerializeGroupWitness ¶ added in v0.3.0
SerializeGroupWitness serializes a group witness into a TLV stream suitable for storing in the DB.
func SerializedKeyDecoder ¶
func SignOutputRaw ¶ added in v0.3.0
func SignOutputRaw(priv *btcec.PrivateKey, tx *wire.MsgTx, signDesc *input.SignDescriptor) (*schnorr.Signature, error)
SignOutputRaw creates a signature for a single input. Taken from lnd/lnwallet/btcwallet/signer:L344, SignOutputRaw
func SignVirtualTx ¶ added in v0.3.0
func SplitCommitmentDecoder ¶
func TapCommitmentKey ¶
TapCommitmentKey is the key that maps to the root commitment for a specific asset group within a TapCommitment.
NOTE: This function is also used outside the asset package.
func ToBranch ¶ added in v0.4.0
func ToBranch(b TapBranchNodes) [][]byte
ToBranch returns an encoded TapBranchNodes object.
func ToLeaves ¶ added in v0.4.0
func ToLeaves(l TapLeafNodes) []txscript.TapLeaf
ToLeaves returns the TapLeaf slice inside a TapLeafNodes object.
func ValidateAssetName ¶ added in v0.3.0
ValidateAssetName validates an asset name (the asset's genesis tag).
func VirtualGenesisTxIn ¶ added in v0.3.0
VirtualGenesisTxIn computes the single input of a Taproot Asset virtual transaction that represents a grouped asset genesis. The input prevout's hash is the root of a MS-SMT committing to only the genesis asset.
func VirtualTxInPrevOut ¶ added in v0.3.0
VirtualTxInPrevOut returns the prevout of the Taproot Asset virtual transaction's single input as a hash of the root node's key concatenated by its sum.
func VirtualTxWithInput ¶ added in v0.3.0
func VirtualTxWithInput(virtualTx *wire.MsgTx, lockTime, relativeLockTime uint64, idx uint32, witness wire.TxWitness) *wire.MsgTx
VirtualTxWithInput returns a copy of the `virtualTx` amended to include all input-specific details.
This is used to further bind a given witness to the "true" input it spends. We'll use the index of the serialized input to bind the prev index, which represents the "leaf index" of the virtual input MS-SMT.
func WitnessEncoderWithType ¶ added in v0.3.0
func WitnessEncoderWithType(encodeType EncodeType) tlv.Encoder
WitnessEncoderWithType is a wrapper around WitnessEncoder that allows the caller to specify th witness type. It's a higher order function that returns an encoder function.
Types ¶
type Asset ¶
type Asset struct { // Version is the Taproot Asset version of the asset. Version Version // Genesis encodes an asset's genesis metadata which directly maps to // its unique ID within the Taproot Asset protocol. Genesis // Amount is the number of units represented by the asset. Amount uint64 // LockTime, if non-zero, restricts an asset from being moved prior to // the represented block height in the chain. This value needs to be set // on the asset that is spending from a script key with a CLTV script. LockTime uint64 // RelativeLockTime, if non-zero, restricts an asset from being moved // until a number of blocks after the confirmation height of the latest // transaction for the asset is reached. This value needs to be set // on the asset that is spending from a script key with a CSV script. RelativeLockTime uint64 // PrevWitnesses contains the witness(es) of an asset's previous // transfer. PrevWitnesses []Witness // SplitCommitmentRoot is the root node of the MS-SMT storing split // commitments. // // NOTE: This should only be set when the previous transfer of an asset // resulted in a value split. SplitCommitmentRoot mssmt.Node // ScriptVersion denotes how an asset's ScriptKey should be validated. ScriptVersion ScriptVersion // ScriptKey represents a tweaked Taproot output key encumbering the // different ways an asset can be spent. ScriptKey ScriptKey // GroupKey is the tweaked public key that is used to associate assets // together across distinct asset IDs, allowing further issuance of the // asset to be made possible. GroupKey *GroupKey }
Asset represents a Taproot asset.
func AssetCustomGroupKey ¶ added in v0.4.0
func AssetCustomGroupKey(t *testing.T, useHashLock, BIP86, keySpend, validScriptWitness bool, gen Genesis) *Asset
AssetCustomGroupKey constructs a new asset group key and anchor asset from a given asset genesis. The asset group key may also commit to a Tapscript tree root. The tree used in that case includes a hash lock and signature lock. The validity of that Tapscript tree is set by the caller.
The following group key derivation methods are supported:
BIP86: The group key commits to an empty tapscript tree. Assets can only be added to the group with a valid signature from the tweaked group key.
Key-spend: The group key commits to a tapscript tree root, but the witness for the group anchor will be a signature using the tweaked group key. Assets could later be added to the group with either a signature from the tweaked group key or a valid witness for a script in the committed tapscript tree.
Script-spend: The group key commits to a tapscript tree root, and the witness for the group anchor is a valid script witness for a script in the tapscript tree. Assets could later be added to the group with either a signature from the tweaked group key or a valid witness for a script in the committed tapscript tree.
func New ¶
func New(genesis Genesis, amount, locktime, relativeLocktime uint64, scriptKey ScriptKey, groupKey *GroupKey, opts ...NewAssetOpt) (*Asset, error)
New instantiates a new asset with a genesis asset witness.
func NewAssetNoErr ¶ added in v0.3.0
func NewAssetNoErr(t testing.TB, gen Genesis, amt, locktime, relocktime uint64, scriptKey ScriptKey, groupKey *GroupKey, opts ...NewAssetOpt) *Asset
NewAssetNoErr creates an asset and fails the test if asset creation fails.
func RandAssetWithValues ¶
func RandAssetWithValues(t testing.TB, genesis Genesis, groupKey *GroupKey, scriptKey ScriptKey) *Asset
RandAssetWithValues creates a random asset with the given genesis and keys for testing.
func (*Asset) AssetCommitmentKey ¶
AssetCommitmentKey is the key that maps to a specific owner of an asset within a Taproot AssetCommitment.
func (*Asset) DecodeRecords ¶
DecodeRecords provides all records known for an asset witness for proper decoding.
func (*Asset) DeepEqualAllowSegWitIgnoreTxWitness ¶ added in v0.4.0
DeepEqualAllowSegWitIgnoreTxWitness returns true if this asset is equal with the given asset, ignoring the TxWitness field of the Witness if the asset version is v1.
func (*Asset) Encode ¶
Encode encodes an asset into a TLV stream. This is used for encoding proof files and state transitions.
func (*Asset) EncodeNoWitness ¶ added in v0.3.0
EncodeNoWitness encodes the asset without the witness into a TLV stream. This is used for serializing on an asset as a leaf within a TAP MS-SMT tree. This only applies when the asset version is v1.
func (*Asset) EncodeRecords ¶
EncodeRecords determines the non-nil records to include when encoding an asset at runtime.
func (*Asset) HasGenesisWitness ¶
HasGenesisWitness determines whether an asset has a valid genesis witness, which should only have one input with a zero PrevID and empty witness and split commitment proof.
func (*Asset) HasGenesisWitnessForGroup ¶ added in v0.3.0
HasGenesisWitnessForGroup determines whether an asset has a witness for a genesis asset in an asset group. This asset must have a non-empty group key and a single prevWitness with a zero PrevID, empty split commitment proof, and non-empty witness.
func (*Asset) HasSplitCommitmentWitness ¶
HasSplitCommitmentWitness returns true if an asset has a split commitment witness.
func (*Asset) IsBurn ¶ added in v0.3.0
IsBurn returns true if an asset uses an un-spendable script key that was constructed using the proof-of-burn scheme.
func (*Asset) IsGenesisAsset ¶ added in v0.3.0
IsGenesisAsset returns true if an asset is a genesis asset.
func (*Asset) IsUnSpendable ¶
IsUnSpendable returns true if an asset uses the un-spendable script key and has zero value.
func (*Asset) IsUnknownVersion ¶ added in v0.3.0
IsUnknownVersion returns true if an asset has a version that is not recognized by this implementation of tap.
func (*Asset) NeedsGenesisWitnessForGroup ¶ added in v0.3.0
NeedsGenesisWitnessForGroup determines whether an asset is a genesis grouped asset, which does not yet have a group witness.
func (*Asset) PrimaryPrevID ¶ added in v0.3.0
PrimaryPrevID returns the primary prev ID of an asset. This is the prev ID of the first witness, unless the first witness is a split-commitment witness, in which case it is the prev ID of the first witness of the root asset. The first witness effectively corresponds to the asset's direct lineage.
func (*Asset) Record ¶ added in v0.4.0
Record returns a TLV record that can be used to encode/decode an Asset to/from a TLV stream.
NOTE: This is part of the tlv.RecordProducer interface.
func (*Asset) TapCommitmentKey ¶
TapCommitmentKey is the key that maps to the root commitment for a specific asset group within a TapCommitment.
func (*Asset) UpdateTxWitness ¶ added in v0.4.0
UpdateTxWitness updates the transaction witness at the given index with the provided witness stack. The previous witness index references the input that is spent.
type AssetGroup ¶
AssetGroup holds information about an asset group, including the genesis information needed re-tweak the raw key.
type BurnTestVectors ¶ added in v0.3.0
type BurnTestVectors struct {
ValidTestCases []*ValidBurnTestCase `json:"valid_test_cases"`
}
type ChainAsset ¶ added in v0.3.3
type ChainAsset struct { *Asset // IsSpent indicates whether the above asset was previously spent. IsSpent bool // AnchorTx is the transaction that anchors this chain asset. AnchorTx *wire.MsgTx // AnchorBlockHash is the blockhash that mined the anchor tx. AnchorBlockHash chainhash.Hash // AnchorBlockHeight is the height of the block that mined the anchor // tx. AnchorBlockHeight uint32 // AnchorOutpoint is the outpoint that commits to the asset. AnchorOutpoint wire.OutPoint // AnchorInternalKey is the raw internal key that was used to create the // anchor Taproot output key. AnchorInternalKey *btcec.PublicKey // AnchorMerkleRoot is the Taproot merkle root hash of the anchor output // the asset was committed to. If there is no Tapscript sibling, this is // equal to the Taproot Asset root commitment hash. AnchorMerkleRoot []byte // AnchorTapscriptSibling is the serialized preimage of a Tapscript // sibling, if there was one. If this is empty, then the // AnchorTapscriptSibling hash is equal to the Taproot root hash of the // anchor output. AnchorTapscriptSibling []byte // AnchorLeaseOwner is the identity of the application that currently // has a lease on this UTXO. If empty/nil, then the UTXO is not // currently leased. A lease means that the UTXO is being // reserved/locked to be spent in an upcoming transaction and that it // should not be available for coin selection through any of the wallet // RPCs. AnchorLeaseOwner [32]byte // AnchorLeaseExpiry is the expiry of the lease. If the expiry is nil or // the time is in the past, then the lease is not valid and the UTXO is // available for coin selection. AnchorLeaseExpiry *time.Time }
ChainAsset is a wrapper around the base asset struct that includes information detailing where in the chain the asset is currently anchored.
type ChainLookup ¶ added in v0.4.0
type ChainLookup interface { // TxBlockHeight returns the block height that the given transaction was // included in. TxBlockHeight(ctx context.Context, txid chainhash.Hash) (uint32, error) // MeanBlockTimestamp returns the timestamp of the block at the given // height as a Unix timestamp in seconds, taking into account the mean // time elapsed over the previous 10 blocks. MeanBlockTimestamp(ctx context.Context, blockHeight uint32) (time.Time, error) // CurrentHeight returns the current height of the main chain. CurrentHeight(context.Context) (uint32, error) }
ChainLookup is an interface that allows an asset validator to look up certain information about asset related transactions on the backing chain.
type EncodeType ¶ added in v0.3.0
type EncodeType uint8
EncodeType is used to denote the type of encoding used for an asset.
const ( // Encode normal is the normal encoding type for an asset. EncodeNormal EncodeType = iota // EncodeSegwit denotes that the witness vector field is not be be // encoded. EncodeSegwit )
type ErrorTestCase ¶ added in v0.3.0
type Genesis ¶
type Genesis struct { // FirstPrevOut represents the outpoint of the transaction's first // input that resulted in the creation of the asset. // // NOTE: This is immutable for the lifetime of the asset. FirstPrevOut wire.OutPoint // Tag is a human-readable identifier for the asset. This does not need // to be unique, but asset issuers should attempt for it to be unique if // possible. Users usually recognise this field as the asset's name. // // NOTE: This is immutable for the lifetime of the asset. Tag string // MetaHash is the hash of the set of encoded meta data. This value is // carried along for all assets transferred in the "light cone" of the // genesis asset. The preimage for this field may optionally be // revealed within the genesis asset proof for this asset. // // NOTE: This is immutable for the lifetime of the asset. MetaHash [MetaHashLen]byte // OutputIndex is the index of the output that carries the unique // Taproot Asset commitment in the genesis transaction. OutputIndex uint32 // Type uniquely identifies the type of Taproot asset. Type Type }
Genesis encodes an asset's genesis metadata which directly maps to its unique ID within the Taproot Asset protocol.
func DecodeGenesis ¶
DecodeGenesis decodes an asset genesis.
func RandGenesis ¶
RandGenesis creates a random genesis for testing.
func (Genesis) GroupKeyTweak ¶
GroupKeyTweak returns the tweak bytes that commit to the previous outpoint, output index and type of the genesis.
type GenesisSigner ¶
type GenesisSigner 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) }
GenesisSigner is used to sign the assetID using the group key public key for a given asset.
type GenesisTxBuilder ¶ added in v0.3.0
type GenesisTxBuilder interface { // 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. BuildGenesisTx(newAsset *Asset) (*wire.MsgTx, *wire.TxOut, error) }
GenesisTxBuilder is used to construct the virtual transaction that represents asset minting for grouped assets. This transaction is used to generate a group witness that authorizes the minting of an asset into the asset group.
type GroupKey ¶
type GroupKey struct { // RawKey is the raw group key before the tweak with the genesis point // has been applied. RawKey keychain.KeyDescriptor // GroupPubKey is the tweaked public key that is used to associate assets // together across distinct asset IDs, allowing further issuance of the // asset to be made possible. The tweaked public key is the result of: // // internalKey = rawKey + singleTweak * G // tweakedGroupKey = TapTweak(internalKey, tapTweak) GroupPubKey btcec.PublicKey // TapscriptRoot is the root of the Tapscript tree that commits to all // script spend conditions for the group key. Instead of spending an // asset, these scripts are used to define witnesses more complex than // a Schnorr signature for reissuing assets. A group key with an empty // Tapscript root can only authorize reissuance with a signature. TapscriptRoot []byte // Witness is a stack of witness elements that authorizes the membership // of an asset in a particular asset group. The witness can be a single // signature or a script from the tapscript tree committed to with the // TapscriptRoot, and follows the witness rules in BIP-341. Witness wire.TxWitness }
GroupKey is the tweaked public key that is used to associate assets together across distinct asset IDs, allowing further issuance of the asset to be made possible.
func AssembleGroupKeyFromWitness ¶ added in v0.4.0
func AssembleGroupKeyFromWitness(genTx GroupVirtualTx, req GroupKeyRequest, tapLeaf *psbt.TaprootTapLeafScript, scriptWitness []byte) (*GroupKey, error)
AssembleGroupKeyFromWitness constructs a group key given a group witness generated externally.
func DeriveGroupKey ¶
func DeriveGroupKey(genSigner GenesisSigner, genTx GroupVirtualTx, req GroupKeyRequest, tapLeaf *psbt.TaprootTapLeafScript) (*GroupKey, error)
DeriveGroupKey derives an asset's group key based on an internal public key descriptor, the original group asset genesis, and the asset's genesis.
func RandGroupKey ¶
RandGroupKey creates a random group key for testing.
func RandGroupKeyWithSigner ¶
RandGroupKeyWithSigner creates a random group key for testing, and provides the signer for reissuing assets into the same group.
func (*GroupKey) IsEqual ¶
IsEqual returns true if this group key and signature are exactly equivalent to the passed other group key.
func (*GroupKey) IsEqualGroup ¶
IsEqualGroup returns true if this group key describes the same asset group as the passed other group key.
type GroupKeyRequest ¶ added in v0.4.0
type GroupKeyRequest struct { // RawKey is the raw group key before the tweak with the genesis point // has been applied. RawKey keychain.KeyDescriptor // AnchorGen is the genesis of the group anchor, which is the asset used // to derive the single tweak for the group key. For a new group key, // this will be the genesis of the new asset. AnchorGen Genesis // TapscriptRoot is the root of a Tapscript tree that includes script // spend conditions for the group key. A group key with an empty // Tapscript root can only authorize reissuance with a signature. TapscriptRoot []byte // NewAsset is the asset which we are requesting group membership for. // A successful request will produce a witness that authorizes this // asset to be a member of this asset group. NewAsset *Asset }
GroupKeyRequest contains the essential fields used to derive a group key.
func NewGroupKeyRequest ¶ added in v0.4.0
func NewGroupKeyRequest(internalKey keychain.KeyDescriptor, anchorGen Genesis, newAsset *Asset, scriptRoot []byte) (*GroupKeyRequest, error)
NewGroupKeyRequest constructs and validates a group key request.
func NewGroupKeyRequestNoErr ¶ added in v0.4.0
func NewGroupKeyRequestNoErr(t testing.TB, internalKey keychain.KeyDescriptor, gen Genesis, newAsset *Asset, scriptRoot []byte) *GroupKeyRequest
func (*GroupKeyRequest) BuildGroupVirtualTx ¶ added in v0.4.0
func (req *GroupKeyRequest) BuildGroupVirtualTx(genBuilder GenesisTxBuilder) ( *GroupVirtualTx, error)
BuildGroupVirtualTx derives the tweaked group key for group key request, and constructs the group virtual TX needed to construct a sign descriptor and produce an asset group witness.
func (*GroupKeyRequest) Validate ¶ added in v0.4.0
func (req *GroupKeyRequest) Validate() error
Validate ensures that the asset intended to be a member of an asset group is well-formed.
type GroupKeyReveal ¶ added in v0.3.0
type GroupKeyReveal struct { // RawKey is the public key that is tweaked twice to derive the final // tweaked group key. The final tweaked key is the result of: // internalKey = rawKey + singleTweak * G // tweakedGroupKey = TapTweak(internalKey, tapTweak) RawKey SerializedKey // TapscriptRoot is the root of the Tapscript tree that commits to all // script spend conditions for the group key. Instead of spending an // asset, these scripts are used to define witnesses more complex than // a Schnorr signature for reissuing assets. This is either empty/nil or // a 32-byte hash. TapscriptRoot []byte }
GroupKeyReveal is a type for representing the data used to derive the tweaked key used to identify an asset group. The final tweaked key is the result of: TapTweak(groupInternalKey, tapscriptRoot)
func (*GroupKeyReveal) GroupPubKey ¶ added in v0.3.0
func (g *GroupKeyReveal) GroupPubKey(assetID ID) (*btcec.PublicKey, error)
GroupPubKey returns the group public key derived from the group key reveal.
type GroupVirtualTx ¶ added in v0.4.0
type GroupVirtualTx struct { // Tx is a virtual transaction that represents the genesis state // transition of a grouped asset. Tx wire.MsgTx // PrevOut is a transaction output that represents a grouped asset. // PrevOut uses the tweaked group key as its PkScript. This is used in // combination with GroupVirtualTx.Tx as input for a GenesisSigner. PrevOut wire.TxOut // GenID is the asset ID of the grouped asset in a GroupKeyRequest. This // ID is needed to construct a sign descriptor for a GenesisSigner, as // it is the single tweak for the group internal key. GenID ID // TweakedKey is the tweaked group key for the given GroupKeyRequest. // This is later used to construct a complete GroupKey, after a // GenesisSigner has produced an asset group witness. TweakedKey btcec.PublicKey }
GroupVirtualTx contains all the information needed to produce an asset group witness, except for the group internal key descriptor (or private key). A GroupVirtualTx is constructed from a GroupKeyRequest.
type ID ¶
ID serves as a unique identifier of an asset, resulting from:
sha256(genesisOutPoint || sha256(tag) || sha256(metadata) || outputIndex || assetType)
type LeafTlvType ¶
LeafTlvType represents the different TLV types for Asset Leaf TLV records.
const ( LeafVersion LeafTlvType = 0 LeafGenesis LeafTlvType = 2 LeafType LeafTlvType = 4 LeafAmount LeafTlvType = 6 LeafLockTime LeafTlvType = 7 LeafRelativeLockTime LeafTlvType = 9 LeafPrevWitness LeafTlvType = 11 LeafSplitCommitmentRoot LeafTlvType = 13 LeafScriptVersion LeafTlvType = 14 LeafScriptKey LeafTlvType = 16 LeafGroupKey LeafTlvType = 17 // Types for future asset format. LeafAssetID LeafTlvType = 11 )
type MockGenesisSigner ¶ added in v0.3.0
type MockGenesisSigner struct {
// contains filtered or unexported fields
}
MockGenesisSigner implements the GenesisSigner interface using a raw private key.
func NewMockGenesisSigner ¶ added in v0.3.0
func NewMockGenesisSigner(priv *btcec.PrivateKey) *MockGenesisSigner
NewMockGenesisSigner creates a new MockGenesisSigner instance given the passed public key.
func (*MockGenesisSigner) SignVirtualTx ¶ added in v0.3.0
func (r *MockGenesisSigner) SignVirtualTx(signDesc *lndclient.SignDescriptor, virtualTx *wire.MsgTx, prevOut *wire.TxOut) (*schnorr.Signature, error)
SignVirtualTx generates a signature according to the passed signing descriptor and virtual TX.
type MockGroupTxBuilder ¶ added in v0.3.0
type MockGroupTxBuilder struct{}
func (*MockGroupTxBuilder) BuildGenesisTx ¶ added in v0.3.0
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 NewAssetOpt ¶ added in v0.3.0
type NewAssetOpt func(*newAssetOptions)
NewAssetOpt is used to modify how a new asset is to be created.
func WithAssetVersion ¶ added in v0.3.0
func WithAssetVersion(v Version) NewAssetOpt
WithAssetVersion can be used to create an asset with a custom version.
type PendingGroupWitness ¶ added in v0.4.0
PendingGroupWitness specifies the asset group witness for an asset seedling in an unsealed minting batch.
type PrevID ¶
type PrevID struct { // OutPoint refers to the asset's previous output position within a // transaction. OutPoint wire.OutPoint // ID is the asset ID of the previous asset tree. ID ID // ScriptKey is the previously tweaked Taproot output key committing to // the possible spending conditions of the asset. PrevID is being used // as map keys, so we want to only use data types with fixed and // comparable content, which a btcec.PublicKey might not be. ScriptKey SerializedKey }
PrevID serves as a reference to an asset's previous input.
type ScriptKey ¶
type ScriptKey struct { // PubKey is the script key that'll be encoded in the final TLV format. // All signatures are checked against this script key. PubKey *btcec.PublicKey *TweakedScriptKey }
ScriptKey represents a tweaked Taproot output key encumbering the different ways an asset can be spent.
func NewScriptKey ¶
func NewScriptKey(key *btcec.PublicKey) ScriptKey
NewScriptKey constructs a ScriptKey with only the publicly available information. This resulting key may or may not have a tweak applied to it.
func NewScriptKeyBip86 ¶
func NewScriptKeyBip86(rawKey keychain.KeyDescriptor) ScriptKey
NewScriptKeyBip86 constructs a ScriptKey tweaked BIP-0086 style. The resulting script key will include the specified BIP-0086 tweak (no real tweak), and also apply that to the final external PubKey.
func RandScriptKey ¶
RandScriptKey creates a random script key for testing.
func (*ScriptKey) DeclaredAsKnown ¶ added in v0.4.0
DeclaredAsKnown returns true if this script key has either been derived by the local wallet or was explicitly declared to be known by using the DeclareScriptKey RPC. Knowing the key conceptually means the key belongs to the local wallet or is at least known by a software that operates on the local wallet. The DeclaredAsKnown flag is never serialized in proofs, so this is never explicitly set for keys foreign to the local wallet. Therefore, if this method returns true for a script key, it means the asset with the script key will be shown in the wallet balance.
func (*ScriptKey) HasScriptPath ¶ added in v0.4.0
HasScriptPath returns true if we know the internals of the script key and there is a tweak applied to it. This means that the script key is not a BIP-0086 key.
func (*ScriptKey) IsEqual ¶ added in v0.4.0
IsEqual returns true is this script key is exactly equivalent to the passed other script key.
func (*ScriptKey) IsUnSpendable ¶
IsUnSpendable returns true if this script key is equal to the un-spendable NUMS point.
type ScriptVersion ¶
type ScriptVersion uint16
ScriptVersion denotes the asset script versioning scheme.
const ( // ScriptV0 represents the initial asset script version of the Taproot // Asset protocol. In this version, assets commit to a tweaked Taproot // output key, allowing the ability for an asset to indirectly commit to // multiple spending conditions. ScriptV0 ScriptVersion = 0 )
type SerializedKey ¶
type SerializedKey [33]byte
SerializedKey is a type for representing a public key, serialized in the compressed, 33-byte form.
func RandSerializedKey ¶
func RandSerializedKey(t testing.TB) SerializedKey
RandSerializedKey creates a random serialized key for testing.
func ToSerialized ¶
func ToSerialized(pubKey *btcec.PublicKey) SerializedKey
ToSerialized serializes a public key in its 33-byte compressed form.
func (SerializedKey) CopyBytes ¶
func (s SerializedKey) CopyBytes() []byte
CopyBytes returns a copy of the underlying array as a byte slice.
func (SerializedKey) SchnorrSerialized ¶
func (s SerializedKey) SchnorrSerialized() []byte
SchnorrSerialized returns the Schnorr serialized, x-only 32-byte representation of the serialized key.
func (SerializedKey) ToPubKey ¶ added in v0.3.0
func (s SerializedKey) ToPubKey() (*btcec.PublicKey, error)
ToPubKey returns the public key parsed from the serialized key.
type SplitCommitment ¶
type SplitCommitment struct { // Proof is the proof for a particular asset split resulting from a // split commitment. Proof mssmt.Proof // RootAsset is the asset containing the root of the split commitment // tree from which the `Proof` above was computed from. RootAsset Asset }
SplitCommitment represents the asset witness for an asset split.
func (*SplitCommitment) DeepEqual ¶
func (s *SplitCommitment) DeepEqual(o *SplitCommitment) bool
DeepEqual returns true if this split commitment is equal with the given split commitment.
type TapBranchNodes ¶ added in v0.4.0
type TapBranchNodes struct {
// contains filtered or unexported fields
}
TapBranchNodes represents the tapHashes of the child nodes of a TapBranch. These tapHashes can be stored to and loaded from the DB.
func DecodeTapBranchNodes ¶ added in v0.4.0
func DecodeTapBranchNodes(branchData [][]byte) (*TapBranchNodes, error)
type TapLeafNodes ¶ added in v0.4.0
type TapLeafNodes struct {
// contains filtered or unexported fields
}
TapLeafNodes represents an ordered list of TapLeaf objects, that have been checked for their script version and size. These leaves can be stored to and loaded from the DB.
func DecodeTapLeafNodes ¶ added in v0.4.0
func DecodeTapLeafNodes(leafData [][]byte) (*TapLeafNodes, error)
type TapscriptTreeManager ¶ added in v0.4.0
type TapscriptTreeManager interface { // StoreTapscriptTree persists a Tapscript tree given a validated set of // TapLeafs or a TapBranch. If the store succeeds, the root hash of the // Tapscript tree is returned. StoreTapscriptTree(ctx context.Context, treeNodes TapscriptTreeNodes) (*chainhash.Hash, error) // LoadTapscriptTree loads the Tapscript tree with the given root hash, // and decodes the tree into a TapscriptTreeNodes object. LoadTapscriptTree(ctx context.Context, rootHash chainhash.Hash) (*TapscriptTreeNodes, error) // DeleteTapscriptTree deletes the Tapscript tree with the given root // hash. DeleteTapscriptTree(ctx context.Context, rootHash chainhash.Hash) error }
TapscriptTreeManager is used to persist a Tapscript tree, represented as either a slice of TapLeafs or a TapBranch. After a tree is stored, it can be referenced by its root hash. This root hash can be stored as a tweak for keys such as a batch internal key, group key, or asset script key.
type TapscriptTreeNodes ¶ added in v0.4.0
type TapscriptTreeNodes struct {
// contains filtered or unexported fields
}
TapscriptTreeNodes represents the two supported ways to define a tapscript tree to be used as a sibling for a Taproot Asset commitment, an asset group key, or an asset script key. This type is used for interfacing with the DB, not for supplying in a proof or key derivation. The inner fields are mutually exclusive.
func FromBranch ¶ added in v0.4.0
func FromBranch(tbn TapBranchNodes) TapscriptTreeNodes
FromBranch creates a TapscriptTreeNodes object from a TapBranchNodes object.
func FromLeaves ¶ added in v0.4.0
func FromLeaves(tln TapLeafNodes) TapscriptTreeNodes
FromLeaves creates a TapscriptTreeNodes object from a TapLeafNodes object.
func TapTreeNodesFromBranch ¶ added in v0.4.0
func TapTreeNodesFromBranch(branch txscript.TapBranch) TapscriptTreeNodes
TapTreeNodesFromBranch creates a TapscriptTreeNodes object from a TapBranch.
func TapTreeNodesFromLeaves ¶ added in v0.4.0
func TapTreeNodesFromLeaves(leaves []txscript.TapLeaf) (*TapscriptTreeNodes, error)
TapTreeNodesFromLeaves sanity checks an ordered list of TapLeaf objects and constructs a TapscriptTreeNodes object if all leaves are valid.
type TestAsset ¶ added in v0.3.0
type TestAsset struct { Version uint8 `json:"version"` GenesisFirstPrevOut string `json:"genesis_first_prev_out"` GenesisTag string `json:"genesis_tag"` GenesisMetaHash string `json:"genesis_meta_hash"` GenesisOutputIndex uint32 `json:"genesis_output_index"` GenesisType uint8 `json:"genesis_type"` Amount uint64 `json:"amount"` LockTime uint64 `json:"lock_time"` RelativeLockTime uint64 `json:"relative_lock_time"` PrevWitnesses []*TestWitness `json:"prev_witnesses"` SplitCommitmentRoot *mssmt.TestNode `json:"split_commitment_root"` ScriptVersion uint16 `json:"script_version"` ScriptKey string `json:"script_key"` GroupKey *TestGroupKey `json:"group_key"` }
type TestGenesisReveal ¶ added in v0.3.0
type TestGenesisReveal struct { FirstPrevOut string `json:"first_prev_out"` Tag string `json:"tag"` MetaHash string `json:"meta_hash"` OutputIndex uint32 `json:"output_index"` Type uint8 `json:"type"` }
func NewTestFromGenesisReveal ¶ added in v0.3.0
func NewTestFromGenesisReveal(t testing.TB, g *Genesis) *TestGenesisReveal
func (*TestGenesisReveal) ToGenesisReveal ¶ added in v0.3.0
func (tgr *TestGenesisReveal) ToGenesisReveal(t testing.TB) *Genesis
type TestGroupKey ¶ added in v0.3.0
type TestGroupKey struct {
GroupKey string `json:"group_key"`
}
func NewTestFromGroupKey ¶ added in v0.3.0
func NewTestFromGroupKey(t testing.TB, gk *GroupKey) *TestGroupKey
func (*TestGroupKey) ToGroupKey ¶ added in v0.3.0
func (tgk *TestGroupKey) ToGroupKey(t testing.TB) *GroupKey
type TestGroupKeyReveal ¶ added in v0.3.0
type TestGroupKeyReveal struct { RawKey string `json:"raw_key"` TapscriptRoot string `json:"tapscript_root"` }
func NewTestFromGroupKeyReveal ¶ added in v0.3.0
func NewTestFromGroupKeyReveal(t testing.TB, gkr *GroupKeyReveal) *TestGroupKeyReveal
func (*TestGroupKeyReveal) ToGroupKeyReveal ¶ added in v0.3.0
func (tgkr *TestGroupKeyReveal) ToGroupKeyReveal(t testing.TB) *GroupKeyReveal
type TestPrevID ¶ added in v0.3.0
type TestPrevID struct { OutPoint string `json:"out_point"` AssetID string `json:"asset_id"` ScriptKey string `json:"script_key"` }
func NewTestFromPrevID ¶ added in v0.3.0
func NewTestFromPrevID(prevID *PrevID) *TestPrevID
type TestScriptKey ¶ added in v0.3.0
type TestScriptKey struct { }
type TestSplitCommitment ¶ added in v0.3.0
type TestSplitCommitment struct { Proof string `json:"proof"` RootAsset *TestAsset `json:"root_asset"` }
func NewTestFromSplitCommitment ¶ added in v0.3.0
func NewTestFromSplitCommitment(t testing.TB, sc *SplitCommitment) *TestSplitCommitment
func (*TestSplitCommitment) ToSplitCommitment ¶ added in v0.3.0
func (tsc *TestSplitCommitment) ToSplitCommitment( t testing.TB) *SplitCommitment
type TestVectors ¶ added in v0.3.0
type TestVectors struct { ValidTestCases []*ValidTestCase `json:"valid_test_cases"` ErrorTestCases []*ErrorTestCase `json:"error_test_cases"` }
type TestWitness ¶ added in v0.3.0
type TestWitness struct { PrevID *TestPrevID `json:"prev_id"` TxWitness []string `json:"tx_witness"` SplitCommitment *TestSplitCommitment `json:"split_commitment"` }
func NewTestFromWitness ¶ added in v0.3.0
func NewTestFromWitness(t testing.TB, w Witness) *TestWitness
type TweakedScriptKey ¶
type TweakedScriptKey struct { // RawKey is the raw script key before the script key tweak is applied. // We store a full key descriptor here for wallet purposes, but will // only encode the pubkey above for the normal script leaf TLV // encoding. RawKey keychain.KeyDescriptor // Tweak is the tweak that is applied on the raw script key to get the // public key. If this is nil, then a BIP-0086 tweak is assumed. Tweak []byte // DeclaredKnown indicates that this script key has been explicitly // declared as being important to the local wallet, even if it might not // be fully known to the local wallet. This could perhaps also be named // "imported", though that might imply that the corresponding private // key was also somehow imported and available. The only relevance this // flag has is that assets with a declared key are shown in the asset // list/balance. DeclaredKnown bool }
TweakedScriptKey is an embedded struct which is primarily used by wallets to be able to keep track of the tweak of a script key alongside the raw key derivation information.
func (*TweakedScriptKey) IsEqual ¶ added in v0.4.0
func (ts *TweakedScriptKey) IsEqual(other *TweakedScriptKey) bool
IsEqual returns true is this tweaked script key is exactly equivalent to the passed other tweaked script key.
type Type ¶
type Type uint8
Type denotes the asset types supported by the Taproot Asset protocol.
func RandAssetType ¶ added in v0.4.0
RandAssetType creates a random asset type.
type ValidBurnTestCase ¶ added in v0.3.0
type ValidBurnTestCase struct { PrevID *TestPrevID `json:"prev_id"` Expected string `json:"expected"` Comment string `json:"comment"` }
type ValidTestCase ¶ added in v0.3.0
type Version ¶
type Version uint8
Version denotes the version of the Taproot Asset protocol in effect for an asset.
type Witness ¶
type Witness struct { // PrevID is a reference to an asset's previous input. // // NOTE: This should only be nil upon the creation of an asset. PrevID *PrevID // TxWitness is a witness that satisfies the asset's previous ScriptKey. // // NOTE: This field and `SplitCommitmentProof` are mutually exclusive, // except upon the creation of an asset, where both should be nil. TxWitness wire.TxWitness // SplitCommitmentProof is used to permit the spending of an asset UTXO // created as a result of an asset split. When an asset is split, the // non-change UTXO commits to the location of all other splits within an // MS-SMT tree. When spending a change UTXO resulting from a // `SplitCommitment`, a normal `Witness` isn't required, instead the // owner of the change asset UTXO must prove that it holds a valid split // which was authorized by the main transfer transaction. // // Outputs with the same `SplitCommitment` are said to share a single // `Witness` as such outputs are the result of a new asset split. // Therefore, we only need a single witness and the resulting merkle-sum // asset tree to verify a transfer. // // NOTE: This field and `TxWitness` are mutually exclusive, // except upon the creation of an asset, where both should be nil. // // TODO: This still needs to be specified further in the BIPs, see // https://github.com/lightninglabs/taproot-assets/issues/3. SplitCommitment *SplitCommitment }
Witness is a nested TLV stream within the main Asset TLV stream that contains the necessary data to verify the movement of an asset. All fields should be nil to represent the creation of an asset, `TxWitness` and `SplitCommitmentProof` are mutually exclusive otherwise.
func (*Witness) DecodeRecords ¶
DecodeRecords provides all records known for an asset witness for proper decoding.
func (*Witness) DeepEqual ¶
DeepEqual returns true if this witness is equal with the given witness. If the skipTxWitness boolean is set, the TxWitness field of the Witness is not compared.
func (*Witness) EncodeNoWitness ¶ added in v0.3.0
EncodeNoWitness encodes an asset witness into a TLV stream, but does not include the raw witness field. The prevID and the split commitment are still included.
func (*Witness) EncodeRecords ¶
EncodeRecords determines the non-nil records to include when encoding an asset witness at runtime.
type WitnessTlvType ¶
WitnessTlvType represents the different TLV types for Asset Witness TLV records.
const ( WitnessPrevID WitnessTlvType = 1 WitnessTxWitness WitnessTlvType = 3 WitnessSplitCommitment WitnessTlvType = 5 )