From de1063200ac890693c79e4426309af3cd2d3311a Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 6 Sep 2017 13:50:06 -0700 Subject: [PATCH] lnwallet/script_utils: adds public receiver+sender htlc revoke w/key derivation --- lnwallet/script_utils.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lnwallet/script_utils.go b/lnwallet/script_utils.go index 873961a4..509a69d1 100644 --- a/lnwallet/script_utils.go +++ b/lnwallet/script_utils.go @@ -297,6 +297,24 @@ func senderHtlcSpendRevoke(signer Signer, signDesc *SignDescriptor, return witnessStack, nil } +// SenderHtlcSpendRevoke constructs a valid witness allowing the receiver of an +// HTLC to claim the output with knowledge of the revocation private key in the +// scenario that the sender of the HTLC broadcasts a previously revoked +// commitment transaction. This method first derives the appropriate revocation +// key, and requires that the provided SignDescriptor has a local revocation +// basepoint and commitment secret in the PubKey and DoubleTweak fields, +// respectively. +func SenderHtlcSpendRevoke(signer Signer, signDesc *SignDescriptor, + sweepTx *wire.MsgTx) (wire.TxWitness, error) { + + // Derive the revocation key using the local revocation base point and + // commitment point. + revokeKey := DeriveRevocationPubkey(signDesc.PubKey, + signDesc.DoubleTweak.PubKey()) + + return senderHtlcSpendRevoke(signer, signDesc, revokeKey, sweepTx) +} + // senderHtlcSpendRedeem constructs a valid witness allowing the receiver of an // HTLC to redeem the pending output in the scenario that the sender broadcasts // their version of the commitment transaction. A valid spend requires @@ -528,6 +546,24 @@ func receiverHtlcSpendRevoke(signer Signer, signDesc *SignDescriptor, return witnessStack, nil } +// ReceiverHtlcSpendRevoke constructs a valid witness allowing the sender of an +// HTLC within a previously revoked commitment transaction to re-claim the +// pending funds in the case that the receiver broadcasts this revoked +// commitment transaction. This method first derives the appropriate revocation +// key, and requires that the provided SignDescriptor has a local revocation +// basepoint and commitment secret in the PubKey and DoubleTweak fields, +// respectively. +func ReceiverHtlcSpendRevoke(signer Signer, signDesc *SignDescriptor, + sweepTx *wire.MsgTx) (wire.TxWitness, error) { + + // Derive the revocation key using the local revocation base point and + // commitment point. + revokeKey := DeriveRevocationPubkey(signDesc.PubKey, + signDesc.DoubleTweak.PubKey()) + + return receiverHtlcSpendRevoke(signer, signDesc, revokeKey, sweepTx) +} + // receiverHtlcSpendTimeout constructs a valid witness allowing the sender of // an HTLC to recover the pending funds after an absolute timeout in the // scenario that the receiver of the HTLC broadcasts their version of the