multi: add p2tr tapscript key path signing capabilities

This commit is contained in:
Oliver Gugger
2022-03-18 18:37:51 +01:00
parent 78db46be7e
commit ef98f2df8a
8 changed files with 330 additions and 104 deletions

View File

@@ -61,6 +61,11 @@ type SignDescriptor struct {
// script (PkScript).
WitnessScript []byte
// TaprootKeySpend indicates that instead of a witness script being
// spent by the signature that results from this signing request, a
// taproot key spend is performed instead.
TaprootKeySpend bool
// Output is the target output which should be signed. The PkScript and
// Value fields within the output should be properly populated,
// otherwise an invalid signature may be generated.

View File

@@ -2,6 +2,7 @@ package input
import (
"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcwallet/waddrmgr"
)
@@ -643,6 +644,27 @@ func (twe *TxWeightEstimator) AddTapscriptInput(leafWitnessSize int,
return twe
}
// AddTaprootKeySpendInput updates the weight estimate to account for an
// additional input spending a segwit v1 pay-to-taproot output using the key
// spend path. This accepts the sighash type being used since that has an
// influence on the total size of the signature.
func (twe *TxWeightEstimator) AddTaprootKeySpendInput(
hashType txscript.SigHashType) *TxWeightEstimator {
twe.inputSize += InputSize
if hashType == txscript.SigHashDefault {
twe.inputWitnessSize += TaprootKeyPathWitnessSize
} else {
twe.inputWitnessSize += TaprootKeyPathCustomSighashWitnessSize
}
twe.inputCount++
twe.hasWitness = true
return twe
}
// AddNestedP2WKHInput updates the weight estimate to account for an additional
// input spending a P2SH output with a nested P2WKH redeem script.
func (twe *TxWeightEstimator) AddNestedP2WKHInput() *TxWeightEstimator {