Documentation
¶
Index ¶
- Variables
- func AggregateKeys(pubkeys []*btcec.PublicKey, tweak []byte) (*musig2.AggregateKey, error)
- func BuildBatchOutput(receivers []Leaf, sweepTapTreeRoot []byte) ([]byte, int64, error)
- func BuildConnectorOutput(receivers []Leaf) ([]byte, int64, error)
- func BuildForfeitTx(inputs []*wire.OutPoint, sequences []uint32, prevouts []*wire.TxOut, ...) (*psbt.Packet, error)
- func BuildForfeitTxWithOutput(inputs []*wire.OutPoint, sequences []uint32, prevouts []*wire.TxOut, ...) (*psbt.Packet, error)
- func ValidateTreeSigs(batchOutSweepClosure []byte, batchOutAmount int64, vtxoTree *TxTree) error
- func ValidateVtxoTree(vtxoTree *TxTree, commitmentTx *psbt.Packet, signerPubkey *btcec.PublicKey, ...) error
- type CoordinatorSession
- type FlatTxTree
- type Leaf
- type Musig2Nonce
- type SignerSession
- type TreeNonces
- type TreePartialSigs
- type TxTree
- func (t *TxTree) Apply(fn func(tx *TxTree) (bool, error)) error
- func (t *TxTree) Find(txid string) *TxTree
- func (t *TxTree) Leaves() []*psbt.Packet
- func (t *TxTree) Serialize() (FlatTxTree, error)
- func (t *TxTree) SerializeNode() (*TxTreeNode, error)
- func (t *TxTree) SubTree(txids []string) (*TxTree, error)
- func (t *TxTree) Validate() error
- type TxTreeNode
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidBatchOutputsNum = fmt.Errorf( "invalid number of batch outputs in commitment transaction", ) ErrEmptyTree = fmt.Errorf("empty vtxo tree") ErrNoLeaves = fmt.Errorf("no leaves in the tree") ErrInvalidTaprootScript = fmt.Errorf("invalid taproot script") ErrMissingCosignersPublicKeys = fmt.Errorf("missing cosigners public keys") ErrInvalidAmount = fmt.Errorf("children amount is different from parent amount") ErrBatchOutputMismatch = fmt.Errorf( "invalid vtxo tree root, tx input does not match batch outpoint", ) )
var (
ErrMissingVtxoTree = errors.New("missing vtxo tree")
)
Functions ¶
func AggregateKeys ¶
AggregateKeys is a wrapper around musig2.AggregateKeys using the given tweak
func BuildBatchOutput ¶
BuildBatchOutput returns the taproot script and amount of a batch output of the commiment tx. The radix of the vtxo tree is hardcoded to 2.
func BuildConnectorOutput ¶
BuildConnectorOutput returns the taproot script and amount of a connector output of the commitment tx. The radix of the connector tree is hardcoded to 4.
func BuildForfeitTx ¶
func ValidateTreeSigs ¶
ValidateTreeSigs validates the signatures on the given vtxo tree.
It validates that each input in the tree has a valid signature, and that the signature was generated using the aggregated public key of all cosigners.
The function returns an error if any of the signatures are invalid, or if there are any issues with the aggregated public key.
func ValidateVtxoTree ¶
func ValidateVtxoTree( vtxoTree *TxTree, commitmentTx *psbt.Packet, signerPubkey *btcec.PublicKey, vtxoTreeExpiry arklib.RelativeLocktime, ) error
ValidateVtxoTree checks if the given vtxo tree is valid vtxoTree tx & commitmentTx are used to validate that the tree spends from the batch outpoint. signerPubkey & vtxoTreeExpiry are used to validate the sweep tapscript leaves. Along with that, the function validates: - the number of nodes - the number of leaves - children spend from parent - every control block and taproot output scripts - each tx matches input and output amounts
Types ¶
type CoordinatorSession ¶
type CoordinatorSession interface {
AddNonce(*btcec.PublicKey, TreeNonces)
AddSignatures(*btcec.PublicKey, TreePartialSigs)
AggregateNonces() (TreeNonces, error)
// SignTree combines the signatures and add them to the tree's psbts
SignTree() (*TxTree, error)
}
func NewTreeCoordinatorSession ¶
func NewTreeCoordinatorSession( batchOutSweepClosure []byte, batchOutAmount int64, vtxoTree *TxTree, ) (CoordinatorSession, error)
type FlatTxTree ¶
type FlatTxTree []TxTreeNode
FlatTxTree is the flat representation of a tx tree. The purpose of this struct is to facilitate the persistance of the tx tree in storage services.
func (FlatTxTree) Leaves ¶
func (c FlatTxTree) Leaves() []TxTreeNode
type Musig2Nonce ¶
type Musig2Nonce struct {
PubNonce [66]byte
}
type SignerSession ¶
type SignerSession interface {
Init(batchOutSweepClosure []byte, batchOutAmount int64, vtxoTree *TxTree) error
GetPublicKey() string
GetNonces() (TreeNonces, error) // generate tree nonces for this session
SetAggregatedNonces(TreeNonces) // set the aggregated nonces
Sign() (TreePartialSigs, error) // sign the tree
}
func NewTreeSignerSession ¶
func NewTreeSignerSession(signer *btcec.PrivateKey) SignerSession
type TreeNonces ¶
type TreeNonces map[string]*Musig2Nonce // txid -> public nonces only
TreeNonces is a map of txid to public nonces only it implements json.Marshaler and json.Unmarshaler
func (TreeNonces) MarshalJSON ¶
func (n TreeNonces) MarshalJSON() ([]byte, error)
func (*TreeNonces) UnmarshalJSON ¶
func (n *TreeNonces) UnmarshalJSON(data []byte) error
type TreePartialSigs ¶
type TreePartialSigs map[string]*musig2.PartialSignature // txid -> partial signature
TreePartialSigs is a map of txid to partial signature it implements json.Marshaler and json.Unmarshaler
func (TreePartialSigs) MarshalJSON ¶
func (s TreePartialSigs) MarshalJSON() ([]byte, error)
func (*TreePartialSigs) UnmarshalJSON ¶
func (s *TreePartialSigs) UnmarshalJSON(data []byte) error
type TxTree ¶
TxTree is the recursive reprensation of tree of transactions. It is used to represent the vtxo and connector trees.
func BuildConnectorTree ¶
BuildConnectorTree creates the connector tree, ie the tree of transactions from the one spending the connector output to those creating the connectors used to forfeit vtxos in the batch process. The radix of the tree is hardcoded to 4.
func BuildVtxoTree ¶
func BuildVtxoTree( rootInput *wire.OutPoint, receivers []Leaf, sweepTapTreeRoot []byte, vtxoTreeExpiry arklib.RelativeLocktime, ) (*TxTree, error)
BuildVtxoTree creates the vtxo tree, ie. the tree of transactions from the one spending the batch output to those creating the vtxos (the leaves of the tree). The radix of the tree is hardcoded to 2.
func NewTxTree ¶
func NewTxTree(flatTxTree FlatTxTree) (*TxTree, error)
NewTxTree converts a flat list of nodes to a tree of transactions.
func (*TxTree) Apply ¶
Apply executes the given function to all txs in the tx tree. The function returns a boolean to indicate whether it should continue applying to the children.
func (*TxTree) Leaves ¶
Leaves returns the leaves of the tx tree, ie. the nodes that don't have any children.
func (*TxTree) Serialize ¶
func (t *TxTree) Serialize() (FlatTxTree, error)
Serialize converts the tx tree into a flat list of nodes.
func (*TxTree) SerializeNode ¶
func (t *TxTree) SerializeNode() (*TxTreeNode, error)
SerializeNode converts the node of a tx tree into its flat representation.
func (*TxTree) SubTree ¶
SubTree returns the sub-tree that contains the given txs, ie all paths from root to the given txids, if they exist in the tree.
type TxTreeNode ¶
type TxTreeNode struct {
Txid string
// Tx is the base64 encoded root PSBT
Tx string
// Children maps root output index to child txid
Children map[uint32]string
}
TxTreeNode is a flat represenation of a node of tx tree. The purpose of this struct is to facilitate the persistance of the tx tree in storage services.