multi: add p2tr keyspend wallet support

This commit is contained in:
Oliver Gugger committed 2022-03-24 18:02:38 +01:00
1 parent f130eddb92
commit c73cf03a55
24 files changed
+416 -163

No files matched your search

+34
View File
@@ -77,6 +77,18 @@ const (
// - pkscript (p2sh): 23 bytes
P2SHOutputSize = 8 + 1 + P2SHSize
// P2TRSize 34 bytes
// - OP_0: 1 byte
// - OP_DATA: 1 byte (x-only public key length)
// - x-only public key length: 32 bytes
P2TRSize = 34
// P2TROutputSize 43 bytes
// - value: 8 bytes
// - var_int: 1 byte (pkscript_length)
// - pkscript (p2tr): 34 bytes
P2TROutputSize = 8 + 1 + P2TRSize
// P2PKHScriptSigSize 108 bytes
// - OP_DATA: 1 byte (signature length)
// - signature
@@ -519,6 +531,19 @@ const (
// - witness_script_length: 1 byte
// - witness_script (anchor_script)
AnchorWitnessSize = 1 + 1 + 73 + 1 + AnchorScriptSize
// TaprootKeyPathWitnessSize 66 bytes
// - NumberOfWitnessElements: 1 byte
// - sigLength: 1 byte
// - sig: 64 bytes
TaprootKeyPathWitnessSize = 1 + 1 + 64
// TaprootKeyPathCustomSighashWitnessSize 67 bytes
// - NumberOfWitnessElements: 1 byte
// - sigLength: 1 byte
// - sig: 64 bytes
// - sighashFlag: 1 byte
TaprootKeyPathCustomSighashWitnessSize = TaprootKeyPathWitnessSize + 1
)
// EstimateCommitTxWeight estimate commitment transaction weight depending on
@@ -639,6 +664,15 @@ func (twe *TxWeightEstimator) AddP2WSHOutput() *TxWeightEstimator {
return twe
}
// AddP2TROutput updates the weight estimate to account for an additional native
// SegWit v1 P2TR output.
func (twe *TxWeightEstimator) AddP2TROutput() *TxWeightEstimator {
twe.outputSize += P2TROutputSize
twe.outputCount++
return twe
}
// AddP2SHOutput updates the weight estimate to account for an additional P2SH
// output.
func (twe *TxWeightEstimator) AddP2SHOutput() *TxWeightEstimator {
+13
View File
@@ -175,6 +175,11 @@ const (
// and CLTV locktime as part of the script enforced lease commitment
// type.
LeaseHtlcAcceptedSuccessSecondLevel StandardWitnessType = 20
// TaprootPubKeySpend is a witness type that allows us to spend a
// regular p2tr output that's sent to an output which is under complete
// control of the backing wallet.
TaprootPubKeySpend StandardWitnessType = 21
)
// String returns a human readable version of the target WitnessType.
@@ -245,6 +250,9 @@ func (wt StandardWitnessType) String() string {
case LeaseHtlcAcceptedSuccessSecondLevel:
return "LeaseHtlcAcceptedSuccessSecondLevel"
case TaprootPubKeySpend:
return "TaprootPubKeySpend"
default:
return fmt.Sprintf("Unknown WitnessType: %v", uint32(wt))
}
@@ -388,6 +396,8 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
case WitnessKeyHash:
fallthrough
case TaprootPubKeySpend:
fallthrough
case NestedWitnessKeyHash:
return signer.ComputeInputScript(tx, desc)
@@ -494,6 +504,9 @@ func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
// The revocation output of a second level output of an HTLC.
case HtlcSecondLevelRevoke:
return ToLocalPenaltyWitnessSize, false, nil
case TaprootPubKeySpend:
return TaprootKeyPathCustomSighashWitnessSize, false, nil
}
return 0, false, fmt.Errorf("unexpected witness type: %v", wt)