input: define new signing method constants
This commit is contained in:
1 file changed
+62
@@ -3,6 +3,7 @@ package input
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
@@ -89,6 +90,67 @@ type SignDescriptor struct {
|
|||||||
InputIndex int
|
InputIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SignMethod defines the different ways a signer can sign, given a specific
|
||||||
|
// input.
|
||||||
|
type SignMethod uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
// WitnessV0SignMethod denotes that a SegWit v0 (p2wkh, np2wkh, p2wsh)
|
||||||
|
// input script should be signed.
|
||||||
|
WitnessV0SignMethod SignMethod = 0
|
||||||
|
|
||||||
|
// TaprootKeySpendBIP0086SignMethod denotes that a SegWit v1 (p2tr)
|
||||||
|
// input should be signed by using the BIP0086 method (commit to
|
||||||
|
// internal key only).
|
||||||
|
TaprootKeySpendBIP0086SignMethod SignMethod = 1
|
||||||
|
|
||||||
|
// TaprootKeySpendSignMethod denotes that a SegWit v1 (p2tr)
|
||||||
|
// input should be signed by using a given taproot hash to commit to in
|
||||||
|
// addition to the internal key.
|
||||||
|
TaprootKeySpendSignMethod SignMethod = 2
|
||||||
|
|
||||||
|
// TaprootScriptSpendSignMethod denotes that a SegWit v1 (p2tr) input
|
||||||
|
// should be spent using the script path and that a specific leaf script
|
||||||
|
// should be signed for.
|
||||||
|
TaprootScriptSpendSignMethod SignMethod = 3
|
||||||
|
)
|
||||||
|
|
||||||
|
// String returns a human-readable representation of the signing method.
|
||||||
|
func (s SignMethod) String() string {
|
||||||
|
switch s {
|
||||||
|
case WitnessV0SignMethod:
|
||||||
|
return "witness_v0"
|
||||||
|
case TaprootKeySpendBIP0086SignMethod:
|
||||||
|
return "taproot_key_spend_bip86"
|
||||||
|
case TaprootKeySpendSignMethod:
|
||||||
|
return "taproot_key_spend"
|
||||||
|
case TaprootScriptSpendSignMethod:
|
||||||
|
return "taproot_script_spend"
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("unknown<%d>", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PkScriptCompatible returns true if the given public key script is compatible
|
||||||
|
// with the sign method.
|
||||||
|
func (s SignMethod) PkScriptCompatible(pkScript []byte) bool {
|
||||||
|
switch s {
|
||||||
|
// SegWit v0 can be p2wkh, np2wkh, p2wsh.
|
||||||
|
case WitnessV0SignMethod:
|
||||||
|
return txscript.IsPayToWitnessPubKeyHash(pkScript) ||
|
||||||
|
txscript.IsPayToWitnessScriptHash(pkScript) ||
|
||||||
|
txscript.IsPayToScriptHash(pkScript)
|
||||||
|
|
||||||
|
case TaprootKeySpendBIP0086SignMethod, TaprootKeySpendSignMethod,
|
||||||
|
TaprootScriptSpendSignMethod:
|
||||||
|
|
||||||
|
return txscript.IsPayToTaproot(pkScript)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WriteSignDescriptor serializes a SignDescriptor struct into the passed
|
// WriteSignDescriptor serializes a SignDescriptor struct into the passed
|
||||||
// io.Writer stream.
|
// io.Writer stream.
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in new issue
Block a user