From d4a5eaa6ad67a861faceb7dfa0c74c7c25bfad66 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 30 Jul 2017 20:23:24 -0700 Subject: [PATCH] lnwallet: modify CommitSpendNoDelay to directly craft witness This commit modifies the CommitSpendNoDelay script witness generation function. We must modify this function as all non-delayed outputs now also require a key derivation. The current default signer.ComputeInputScript implementation is unable to directly look up the public key required as it attempt to target the pub key using the pkScript. --- lnwallet/script_utils.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lnwallet/script_utils.go b/lnwallet/script_utils.go index c14200df..b7c9075b 100644 --- a/lnwallet/script_utils.go +++ b/lnwallet/script_utils.go @@ -941,12 +941,22 @@ func CommitSpendNoDelay(signer Signer, signDesc *SignDescriptor, // This is just a regular p2wkh spend which looks something like: // * witness: - inputScript, err := signer.ComputeInputScript(sweepTx, signDesc) + sweepSig, err := signer.SignOutputRaw(sweepTx, signDesc) if err != nil { return nil, err } - return wire.TxWitness(inputScript.Witness), nil + // Finally, we'll manually craft the witness. The witness here is the + // exact same as a regular p2wkh witness, but we'll need to ensure that + // we use the tweaked public key as the last item in the witness stack + // which was originally used to created the pkScript we're spending. + witness := make([][]byte, 2) + witness[0] = append(sweepSig, byte(txscript.SigHashAll)) + witness[1] = TweakPubKeyWithTweak( + signDesc.PubKey, signDesc.SingleTweak, + ).SerializeCompressed() + + return witness, nil } // SingleTweakBytes computes set of bytes we call the single tweak. The purpose