bitcointree

package
v0.0.0-...-e2bdea5 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 17 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingVtxoTree     = errors.New("missing vtxo tree")
	ErrMissingAggregateKey = errors.New("missing aggregate key")
)
View Source
var (
	COSIGNER_PSBT_KEY_PREFIX     = []byte("cosigner")
	CONDITION_WITNESS_KEY_PREFIX = []byte(tree.ConditionWitnessKey)
)
View Source
var (
	ErrInvalidRoundTx           = fmt.Errorf("invalid round transaction")
	ErrInvalidRoundTxOutputs    = fmt.Errorf("invalid number of outputs in round transaction")
	ErrEmptyTree                = fmt.Errorf("empty vtxo tree")
	ErrInvalidRootLevel         = fmt.Errorf("root level must have only one node")
	ErrNoLeaves                 = fmt.Errorf("no leaves in the tree")
	ErrNodeTxEmpty              = fmt.Errorf("node transaction is empty")
	ErrNodeTxidEmpty            = fmt.Errorf("node txid is empty")
	ErrNodeParentTxidEmpty      = fmt.Errorf("node parent txid is empty")
	ErrNodeTxidDifferent        = fmt.Errorf("node txid differs from node transaction")
	ErrNumberOfInputs           = fmt.Errorf("node transaction should have only one input")
	ErrNumberOfOutputs          = fmt.Errorf("node transaction should have only three or two outputs")
	ErrParentTxidInput          = fmt.Errorf("parent txid should be the input of the node transaction")
	ErrNumberOfChildren         = fmt.Errorf("node branch transaction should have two children")
	ErrLeafChildren             = fmt.Errorf("leaf node should have max 1 child")
	ErrInvalidChildTxid         = fmt.Errorf("invalid child txid")
	ErrNumberOfTapscripts       = fmt.Errorf("input should have 1 tapscript leaf")
	ErrInternalKey              = fmt.Errorf("invalid taproot internal key")
	ErrInvalidTaprootScript     = fmt.Errorf("invalid taproot script")
	ErrInvalidControlBlock      = fmt.Errorf("invalid control block")
	ErrInvalidTaprootScriptLen  = fmt.Errorf("invalid taproot script length (expected 32 bytes)")
	ErrInvalidLeafTaprootScript = fmt.Errorf("invalid leaf taproot script")
	ErrInvalidAmount            = fmt.Errorf("children amount is different from parent amount")
	ErrInvalidSweepSequence     = fmt.Errorf("invalid sweep sequence")
	ErrInvalidServer            = fmt.Errorf("invalid server")
	ErrMissingFeeOutput         = fmt.Errorf("missing fee output")
	ErrInvalidLeftOutput        = fmt.Errorf("invalid left output")
	ErrInvalidRightOutput       = fmt.Errorf("invalid right output")
	ErrMissingSweepTapscript    = fmt.Errorf("missing sweep tapscript")
	ErrInvalidLeaf              = fmt.Errorf("leaf node shouldn't have children")
	ErrWrongRoundTxid           = fmt.Errorf("the input of the tree root is not the round tx's shared output")
)

Functions

func AddConditionWitness

func AddConditionWitness(inIndex int, ptx *psbt.Packet, witness wire.TxWitness) error

func AddCosignerKey

func AddCosignerKey(inIndex int, ptx *psbt.Packet, key *secp256k1.PublicKey) error

func AggregateKeys

func AggregateKeys(
	pubkeys []*btcec.PublicKey,
	scriptRoot []byte,
) (*musig2.AggregateKey, error)

func BuildForfeitTxs

func BuildForfeitTxs(
	connectorTx *psbt.Packet, vtxoInput *wire.OutPoint,
	vtxoAmount, connectorAmount, feeAmount uint64,
	vtxoScript, serverScript []byte,
	txLocktime uint32,
) (forfeitTxs []*psbt.Packet, err error)

func BuildRedeemTx

func BuildRedeemTx(
	vtxos []common.VtxoInput,
	outputs []*wire.TxOut,
) (string, error)

func BuildVtxoTree

func BuildVtxoTree(
	initialInput *wire.OutPoint, cosigners []*secp256k1.PublicKey, server *secp256k1.PublicKey, receivers []tree.VtxoLeaf,
	feeSatsPerNode uint64, roundLifetime common.RelativeLocktime,
) (tree.VtxoTree, error)

BuildVtxoTree creates all the tree's transactions

func CraftSharedOutput

func CraftSharedOutput(
	cosigners []*secp256k1.PublicKey, server *secp256k1.PublicKey, receivers []tree.VtxoLeaf,
	feeSatsPerNode uint64, roundLifetime common.RelativeLocktime,
) ([]byte, int64, error)

CraftSharedOutput returns the taproot script and the amount of the initial root output

func GetConditionWitness

func GetConditionWitness(in psbt.PInput) (wire.TxWitness, error)

func GetCosignerKeys

func GetCosignerKeys(in psbt.PInput) ([]*secp256k1.PublicKey, error)

func UnspendableKey

func UnspendableKey() *secp256k1.PublicKey

func ValidateTreeSigs

func ValidateTreeSigs(
	scriptRoot []byte,
	finalAggregatedKey *btcec.PublicKey,
	roundSharedOutputAmount int64,
	vtxoTree tree.VtxoTree,
) error

func ValidateVtxoTree

func ValidateVtxoTree(
	vtxoTree tree.VtxoTree, roundTx string, serverPubkey *secp256k1.PublicKey, roundLifetime common.RelativeLocktime,
) error

ValidateVtxoTree checks if the given vtxo tree is valid roundTxid & roundTxIndex & roundTxAmount are used to validate the root input outpoint serverPubkey & roundLifetime are used to validate the sweep tapscript leaves besides that, the function validates: - the number of nodes - the number of leaves - children coherence with parent - every control block and taproot output scripts - input and output amounts

Types

type CoordinatorSession

type CoordinatorSession interface {
	AddNonce(*btcec.PublicKey, TreeNonces) error
	AggregateNonces() (TreeNonces, error)
	AddSig(*btcec.PublicKey, TreePartialSigs) error
	// SignTree combines the signatures and add them to the tree's psbts
	SignTree() (tree.VtxoTree, error)
}

func NewTreeCoordinatorSession

func NewTreeCoordinatorSession(
	roundSharedOutputAmount int64,
	vtxoTree tree.VtxoTree,
	scriptRoot []byte,
	keys []*btcec.PublicKey,
) (CoordinatorSession, error)

type Musig2Nonce

type Musig2Nonce struct {
	PubNonce [66]byte
}

func (*Musig2Nonce) Decode

func (n *Musig2Nonce) Decode(r io.Reader) error

func (*Musig2Nonce) Encode

func (n *Musig2Nonce) Encode(w io.Writer) error

type SignerSession

type SignerSession interface {
	GetNonces() (TreeNonces, error)       // generate tree nonces for this session
	SetKeys([]*btcec.PublicKey) error     // set the cosigner public keys for this session
	SetAggregatedNonces(TreeNonces) error // set the aggregated nonces
	Sign() (TreePartialSigs, error)       // sign the tree
}

func NewTreeSignerSession

func NewTreeSignerSession(
	signer *btcec.PrivateKey,
	roundSharedOutputAmount int64,
	vtxoTree tree.VtxoTree,
	scriptRoot []byte,
) SignerSession

type TapscriptsVtxoScript

type TapscriptsVtxoScript struct {
	tree.TapscriptsVtxoScript
}

func (*TapscriptsVtxoScript) TapTree

func (v *TapscriptsVtxoScript) TapTree() (*secp256k1.PublicKey, bitcoinTapTree, error)

type TreeNonces

type TreeNonces [][]*Musig2Nonce // public nonces

func DecodeNonces

func DecodeNonces(r io.Reader) (TreeNonces, error)

func (TreeNonces) Encode

func (n TreeNonces) Encode(w io.Writer) error

type TreePartialSigs

type TreePartialSigs [][]*musig2.PartialSignature

func DecodeSignatures

func DecodeSignatures(r io.Reader) (TreePartialSigs, error)

func (TreePartialSigs) Encode

func (s TreePartialSigs) Encode(w io.Writer) error

type VtxoScript

type VtxoScript common.VtxoScript[bitcoinTapTree, tree.Closure]

func NewDefaultVtxoScript

func NewDefaultVtxoScript(owner, server *secp256k1.PublicKey, exitDelay common.RelativeLocktime) VtxoScript

func ParseVtxoScript

func ParseVtxoScript(scripts []string) (VtxoScript, error)

Jump to

Keyboard shortcuts

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