multi: introduce and use new TapTweak and SignMethod fields

In this commit, we add a new field `TapTweak` to be used for key path
spends. Before this commit, we'd overload the existing `WitnessScript`
field to pass this information to the signing context. This was
confusing as for tapscript spends, this was the leaf script, which
mirrors the other script based spending types.

With this new filed, users need to set this to the script root for
keypath spends where the output key commits to a real merkle root, and
nothing when bip 86 spending is being used.

To make the signing even more explicit, we also add a new field called
sign_method with an enum type that differentiates between the different
segwit v0 and v1 signing methods.

Fixes https://github.com/lightningnetwork/lnd/issues/6446.
This commit is contained in:
Olaoluwa Osuntokun authored and Oliver Gugger committed 2022-05-11 10:07:49 +02:00
1 parent 99cda74f6a
commit 630fc36dcf
7 files changed
+610 -358

No files matched your search

+17 -4
View File
@@ -56,16 +56,29 @@ type SignDescriptor struct {
// DoubleTweak, not both.
DoubleTweak *btcec.PrivateKey
// TapTweak is a 32-byte value that will be used to derive a taproot
// output public key (or the corresponding private key) from an
// internal key and this tweak. The transformation applied is:
// * outputKey = internalKey +
// tagged_hash("tapTweak", internalKey || tapTweak)
//
// When attempting to sign an output derived via BIP 86, then this
// field should be an empty byte array.
//
// When attempting to sign for the key spend path of an output key that
// commits to an actual script tree, the script root should be used.
TapTweak []byte
// WitnessScript is the full script required to properly redeem the
// output. This field should be set to the full script if a p2wsh
// output is being signed. For p2wkh it should be set to the hashed
// 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
// SignMethod specifies how the input should be signed. Depending on the
// selected method, either the TapTweak, WitnessScript or both need to
// be specified.
SignMethod SignMethod
// Output is the target output which should be signed. The PkScript and
// Value fields within the output should be properly populated,