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)