Skip to content

Commit 97cff63

Browse files
committed
lnwallet: support combined tweak to private key
Previously we'd define either a single or a double tweak for the sign descriptor. We introduce the option to apply both consecutively (double tweak first, single tweak second) if both tweak parameters are set. For callers who define only one of the two parameters we maintain the old behavior.
1 parent aeac338 commit 97cff63

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lnwallet/btcwallet/signer.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,32 @@ func (b *BtcWallet) fetchPrivKey(
238238

239239
// maybeTweakPrivKey examines the single and double tweak parameters on the
240240
// passed sign descriptor and may perform a mapping on the passed private key
241-
// in order to utilize the tweaks, if populated.
241+
// in order to utilize the tweaks, if populated. If both tweak parameters are
242+
// set, then both are applied in the following order:
243+
//
244+
// a) double tweak
245+
// b) single tweak
242246
func maybeTweakPrivKey(signDesc *input.SignDescriptor,
243247
privKey *btcec.PrivateKey) (*btcec.PrivateKey, error) {
244248

245249
var retPriv *btcec.PrivateKey
246-
switch {
247250

251+
// If both tweak parameters are set, then apply both.
252+
if signDesc.DoubleTweak != nil && signDesc.SingleTweak != nil {
253+
// First apply the double tweak.
254+
retPriv = input.DeriveRevocationPrivKey(privKey,
255+
signDesc.DoubleTweak)
256+
257+
// Then apply the single tweak.
258+
retPriv = input.TweakPrivKey(retPriv,
259+
signDesc.SingleTweak)
260+
261+
return retPriv, nil
262+
}
263+
264+
// If only one tweak parameter is set, apply it respectively over the
265+
// provided private key.
266+
switch {
248267
case signDesc.SingleTweak != nil:
249268
retPriv = input.TweakPrivKey(privKey,
250269
signDesc.SingleTweak)

0 commit comments

Comments
 (0)