Documentation ¶
Index ¶
- Constants
- Variables
- func AddConditionWitness(inIndex int, ptx *psetv2.Pset, witness wire.TxWitness) error
- func BuildForfeitTxs(connectorTx *psetv2.Pset, vtxoInput psetv2.InputArgs, ...) (forfeitTxs []*psetv2.Pset, err error)
- func ExecuteBoolScript(script []byte, witness wire.TxWitness) (bool, error)
- func GetConditionWitness(in psetv2.Input) (wire.TxWitness, error)
- func ReadTxWitness(witnessSerialized []byte) (wire.TxWitness, error)
- func UnspendableKey() *secp256k1.PublicKey
- func ValidateVtxoTree(tree VtxoTree, roundTx string, serverPubkey *secp256k1.PublicKey, ...) error
- type CLTVMultisigClosure
- func (d *CLTVMultisigClosure) Decode(script []byte) (bool, error)
- func (d *CLTVMultisigClosure) Script() ([]byte, error)
- func (f *CLTVMultisigClosure) Witness(controlBlock []byte, signatures map[string][]byte) (wire.TxWitness, error)
- func (f *CLTVMultisigClosure) WitnessSize(extraWitnessSizes ...int) int
- type CSVMultisigClosure
- func (d *CSVMultisigClosure) Decode(script []byte) (bool, error)
- func (d *CSVMultisigClosure) Script() ([]byte, error)
- func (f *CSVMultisigClosure) Witness(controlBlock []byte, signatures map[string][]byte) (wire.TxWitness, error)
- func (f *CSVMultisigClosure) WitnessSize(extraWitnessSizes ...int) int
- type Closure
- type ConditionCSVMultisigClosure
- func (f *ConditionCSVMultisigClosure) Decode(script []byte) (bool, error)
- func (f *ConditionCSVMultisigClosure) Script() ([]byte, error)
- func (f *ConditionCSVMultisigClosure) Witness(controlBlock []byte, args map[string][]byte) (wire.TxWitness, error)
- func (f *ConditionCSVMultisigClosure) WitnessSize(conditionWitnessSizes ...int) int
- type ConditionMultisigClosure
- func (f *ConditionMultisigClosure) Decode(script []byte) (bool, error)
- func (f *ConditionMultisigClosure) Script() ([]byte, error)
- func (f *ConditionMultisigClosure) Witness(controlBlock []byte, args map[string][]byte) (wire.TxWitness, error)
- func (f *ConditionMultisigClosure) WitnessSize(conditionWitnessSizes ...int) int
- type MultisigClosure
- type MultisigType
- type Node
- type TapscriptsVtxoScript
- func (v *TapscriptsVtxoScript) Decode(scripts []string) error
- func (v *TapscriptsVtxoScript) Encode() ([]string, error)
- func (v *TapscriptsVtxoScript) ExitClosures() []Closure
- func (v *TapscriptsVtxoScript) ForfeitClosures() []Closure
- func (v *TapscriptsVtxoScript) SmallestExitDelay() (*common.RelativeLocktime, error)
- func (v *TapscriptsVtxoScript) TapTree() (*secp256k1.PublicKey, elementsTapTree, error)
- func (v *TapscriptsVtxoScript) Validate(server *secp256k1.PublicKey, minLocktime common.RelativeLocktime) error
- type TreeFactory
- type UnrollClosure
- type VtxoLeaf
- type VtxoScript
- type VtxoTree
Constants ¶
const ( OP_INSPECTOUTPUTSCRIPTPUBKEY = 0xd1 OP_INSPECTOUTPUTVALUE = 0xcf OP_PUSHCURRENTINPUTINDEX = 0xcd OP_INSPECTINPUTVALUE = 0xc9 OP_SUB64 = 0xd8 )
const ConditionWitnessKey = "condition"
Variables ¶
var ( ErrParentNotFound = errors.New("parent not found") ErrLeafNotFound = errors.New("leaf not found in vtxo tree") )
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") 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") ErrInvalidAsset = errors.New("invalid output asset") 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") ErrMissingBranchTapscript = errors.New("missing branch 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") )
var (
CONDITION_WITNESS_KEY_PREFIX = []byte(ConditionWitnessKey)
)
var (
ErrNoExitLeaf = fmt.Errorf("no exit leaf")
)
Functions ¶
func AddConditionWitness ¶
func BuildForfeitTxs ¶
func ExecuteBoolScript ¶
ExecuteBoolScript run the script with the provided witness as argument the result must be a boolean value accepted by OP_IF / OP_NOTIF opcodes
func UnspendableKey ¶
func UnspendableKey() *secp256k1.PublicKey
func ValidateVtxoTree ¶
func ValidateVtxoTree( 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 CLTVMultisigClosure ¶
type CLTVMultisigClosure struct { MultisigClosure Locktime common.AbsoluteLocktime }
CLTVMultisigClosure is a closure that contains a list of public keys and a CHECKLOCKTIMEVERIFY. The witness size is 64 bytes per key, admitting the sighash type is SIGHASH_DEFAULT.
func (*CLTVMultisigClosure) Decode ¶
func (d *CLTVMultisigClosure) Decode(script []byte) (bool, error)
func (*CLTVMultisigClosure) Script ¶
func (d *CLTVMultisigClosure) Script() ([]byte, error)
func (*CLTVMultisigClosure) WitnessSize ¶
func (f *CLTVMultisigClosure) WitnessSize(extraWitnessSizes ...int) int
type CSVMultisigClosure ¶
type CSVMultisigClosure struct { MultisigClosure Locktime common.RelativeLocktime }
CSVMultisigClosure is a closure that contains a list of public keys and a CHECKSEQUENCEVERIFY. The witness size is 64 bytes per key, admitting the sighash type is SIGHASH_DEFAULT.
func (*CSVMultisigClosure) Decode ¶
func (d *CSVMultisigClosure) Decode(script []byte) (bool, error)
func (*CSVMultisigClosure) Script ¶
func (d *CSVMultisigClosure) Script() ([]byte, error)
func (*CSVMultisigClosure) WitnessSize ¶
func (f *CSVMultisigClosure) WitnessSize(extraWitnessSizes ...int) int
type Closure ¶
type Closure interface { Script() ([]byte, error) Decode(script []byte) (bool, error) // WitnessSize returns the size of the witness excluding the script and control block // extraWitnessSize is here to count the condition witness size // or any other witness size that can't be computed from the script WitnessSize(extraWitnessSize ...int) int Witness(controlBlock []byte, signatures map[string][]byte) (wire.TxWitness, error) }
func DecodeClosure ¶
type ConditionCSVMultisigClosure ¶
type ConditionCSVMultisigClosure struct { CSVMultisigClosure Condition []byte }
ConditionCSVMultisigClosure is a closure that contains a condition and a CSV multisig closure. The condition is a boolean script that is executed with the multisig witness.
func (*ConditionCSVMultisigClosure) Decode ¶
func (f *ConditionCSVMultisigClosure) Decode(script []byte) (bool, error)
func (*ConditionCSVMultisigClosure) Script ¶
func (f *ConditionCSVMultisigClosure) Script() ([]byte, error)
func (*ConditionCSVMultisigClosure) WitnessSize ¶
func (f *ConditionCSVMultisigClosure) WitnessSize(conditionWitnessSizes ...int) int
type ConditionMultisigClosure ¶
type ConditionMultisigClosure struct { MultisigClosure Condition []byte }
ConditionMultisigClosure is a closure that contains a condition and a multisig closure. The condition is a boolean script that is executed with the multisig witness.
func (*ConditionMultisigClosure) Decode ¶
func (f *ConditionMultisigClosure) Decode(script []byte) (bool, error)
func (*ConditionMultisigClosure) Script ¶
func (f *ConditionMultisigClosure) Script() ([]byte, error)
func (*ConditionMultisigClosure) WitnessSize ¶
func (f *ConditionMultisigClosure) WitnessSize(conditionWitnessSizes ...int) int
type MultisigClosure ¶
type MultisigClosure struct { PubKeys []*secp256k1.PublicKey Type MultisigType }
MultisigClosure is a closure that contains a list of public keys and a CHECKSIG for each key. The witness size is 64 bytes per key, admitting the sighash type is SIGHASH_DEFAULT.
func (*MultisigClosure) Script ¶
func (f *MultisigClosure) Script() ([]byte, error)
func (*MultisigClosure) WitnessSize ¶
func (f *MultisigClosure) WitnessSize(_ ...int) int
type MultisigType ¶
type MultisigType int
const ( MultisigTypeChecksig MultisigType = iota MultisigTypeChecksigAdd )
type TapscriptsVtxoScript ¶
type TapscriptsVtxoScript struct {
Closures []Closure
}
TapscriptsVtxoScript represents a taproot script that contains a list of tapscript leaves the key-path is always unspendable
func NewDefaultVtxoScript ¶
func NewDefaultVtxoScript(owner, server *secp256k1.PublicKey, exitDelay common.RelativeLocktime) *TapscriptsVtxoScript
func (*TapscriptsVtxoScript) Decode ¶
func (v *TapscriptsVtxoScript) Decode(scripts []string) error
func (*TapscriptsVtxoScript) Encode ¶
func (v *TapscriptsVtxoScript) Encode() ([]string, error)
func (*TapscriptsVtxoScript) ExitClosures ¶
func (v *TapscriptsVtxoScript) ExitClosures() []Closure
func (*TapscriptsVtxoScript) ForfeitClosures ¶
func (v *TapscriptsVtxoScript) ForfeitClosures() []Closure
func (*TapscriptsVtxoScript) SmallestExitDelay ¶
func (v *TapscriptsVtxoScript) SmallestExitDelay() (*common.RelativeLocktime, error)
func (*TapscriptsVtxoScript) TapTree ¶
func (v *TapscriptsVtxoScript) TapTree() (*secp256k1.PublicKey, elementsTapTree, error)
func (*TapscriptsVtxoScript) Validate ¶
func (v *TapscriptsVtxoScript) Validate(server *secp256k1.PublicKey, minLocktime common.RelativeLocktime) error
type TreeFactory ¶
func BuildVtxoTree ¶
func BuildVtxoTree( asset string, serverPubkey *secp256k1.PublicKey, receivers []VtxoLeaf, feeSatsPerNode uint64, roundLifetime common.RelativeLocktime, ) ( factoryFn TreeFactory, sharedOutputScript []byte, sharedOutputAmount uint64, err error, )
type UnrollClosure ¶
type UnrollClosure struct {
LeftKey, RightKey *secp256k1.PublicKey
LeftAmount, RightAmount uint64
MinRelayFee uint64
}
UnrollClosure is liquid-only tapscript letting to enforce unrollable UTXO without musig.
func (*UnrollClosure) Decode ¶
func (c *UnrollClosure) Decode(script []byte) (valid bool, err error)
func (*UnrollClosure) Script ¶
func (c *UnrollClosure) Script() ([]byte, error)
func (*UnrollClosure) WitnessSize ¶
func (c *UnrollClosure) WitnessSize(_ ...int) int
type VtxoScript ¶
type VtxoScript common.VtxoScript[elementsTapTree, Closure]
func ParseVtxoScript ¶
func ParseVtxoScript(scripts []string) (VtxoScript, error)
type VtxoTree ¶
type VtxoTree [][]Node
VtxoTree is reprensented as a matrix of TreeNode struct the first level of the matrix is the root of the tree
func (VtxoTree) Branch ¶
Branch returns the branch of the given vtxo txid from root to leaf in the order of the vtxo tree
func (VtxoTree) NumberOfNodes ¶
NumberOfNodes returns the total number of pset in the vtxo tree