mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
input: define new signing method constants
This commit is contained in:
parent
5395a0fe6b
commit
99cda74f6a
@ -3,6 +3,7 @@ package input
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
@ -89,6 +90,67 @@ type SignDescriptor struct {
|
||||
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
|
||||
// io.Writer stream.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user