From 97cff63728c90ea3eebc01a861a890e816e3d3dc Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 18 Nov 2025 16:49:56 +0100 Subject: [PATCH] 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. --- lnwallet/btcwallet/signer.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lnwallet/btcwallet/signer.go b/lnwallet/btcwallet/signer.go index 69f7ab60912..b3a6de8782c 100644 --- a/lnwallet/btcwallet/signer.go +++ b/lnwallet/btcwallet/signer.go @@ -238,13 +238,32 @@ func (b *BtcWallet) fetchPrivKey( // maybeTweakPrivKey examines the single and double tweak parameters on the // passed sign descriptor and may perform a mapping on the passed private key -// in order to utilize the tweaks, if populated. +// in order to utilize the tweaks, if populated. If both tweak parameters are +// set, then both are applied in the following order: +// +// a) double tweak +// b) single tweak func maybeTweakPrivKey(signDesc *input.SignDescriptor, privKey *btcec.PrivateKey) (*btcec.PrivateKey, error) { var retPriv *btcec.PrivateKey - switch { + // If both tweak parameters are set, then apply both. + if signDesc.DoubleTweak != nil && signDesc.SingleTweak != nil { + // First apply the double tweak. + retPriv = input.DeriveRevocationPrivKey(privKey, + signDesc.DoubleTweak) + + // Then apply the single tweak. + retPriv = input.TweakPrivKey(retPriv, + signDesc.SingleTweak) + + return retPriv, nil + } + + // If only one tweak parameter is set, apply it respectively over the + // provided private key. + switch { case signDesc.SingleTweak != nil: retPriv = input.TweakPrivKey(privKey, signDesc.SingleTweak)