@@ -64,9 +64,6 @@ type HtlcScript interface {
6464 // redeeming the htlc.
6565 IsSuccessWitness (witness wire.TxWitness ) bool
6666
67- // Script returns the htlc script.
68- Script () []byte
69-
7067 // lockingConditions return the address, pkScript and sigScript (if
7168 // required) for a htlc script.
7269 lockingConditions (HtlcOutputType , * chaincfg.Params ) (btcutil.Address ,
@@ -80,9 +77,21 @@ type HtlcScript interface {
8077 // timeout case witness.
8178 MaxTimeoutWitnessSize () int
8279
80+ // TimeoutScript returns the redeem script required to unlock the htlc
81+ // after timeout.
82+ TimeoutScript () []byte
83+
84+ // SuccessScript returns the redeem script required to unlock the htlc
85+ // using the preimage.
86+ SuccessScript () []byte
87+
8388 // SuccessSequence returns the sequence to spend this htlc in the
8489 // success case.
8590 SuccessSequence () uint32
91+
92+ // SigHash is the signature hash to use for transactions spending from
93+ // the htlc.
94+ SigHash () txscript.SigHashType
8695}
8796
8897// Htlc contains relevant htlc information from the receiver perspective.
@@ -291,8 +300,8 @@ func (h *Htlc) AddSuccessToEstimator(estimator *input.TxWeightEstimator) error {
291300 return ErrInvalidOutputSelected
292301 }
293302
294- successLeaf := txscript .NewBaseTapLeaf (trHtlc .SuccessScript )
295- timeoutLeaf := txscript .NewBaseTapLeaf (trHtlc .TimeoutScript )
303+ successLeaf := txscript .NewBaseTapLeaf (trHtlc .SuccessScript () )
304+ timeoutLeaf := txscript .NewBaseTapLeaf (trHtlc .TimeoutScript () )
296305 timeoutLeafHash := timeoutLeaf .TapHash ()
297306
298307 tapscript := input .TapscriptPartialReveal (
@@ -324,8 +333,8 @@ func (h *Htlc) AddTimeoutToEstimator(estimator *input.TxWeightEstimator) error {
324333 return ErrInvalidOutputSelected
325334 }
326335
327- successLeaf := txscript .NewBaseTapLeaf (trHtlc .SuccessScript )
328- timeoutLeaf := txscript .NewBaseTapLeaf (trHtlc .TimeoutScript )
336+ successLeaf := txscript .NewBaseTapLeaf (trHtlc .SuccessScript () )
337+ timeoutLeaf := txscript .NewBaseTapLeaf (trHtlc .TimeoutScript () )
329338 successLeafHash := successLeaf .TapHash ()
330339
331340 tapscript := input .TapscriptPartialReveal (
@@ -440,8 +449,19 @@ func (h *HtlcScriptV1) IsSuccessWitness(witness wire.TxWitness) bool {
440449 return ! isTimeoutTx
441450}
442451
443- // Script returns the htlc script.
444- func (h * HtlcScriptV1 ) Script () []byte {
452+ // TimeoutScript returns the redeem script required to unlock the htlc after
453+ // timeout.
454+ //
455+ // In the case of HtlcScriptV1, this is the full segwit v0 script.
456+ func (h * HtlcScriptV1 ) TimeoutScript () []byte {
457+ return h .script
458+ }
459+
460+ // SuccessScript returns the redeem script required to unlock the htlc using
461+ // the preimage.
462+ //
463+ // In the case of HtlcScriptV1, this is the full segwit v0 script.
464+ func (h * HtlcScriptV1 ) SuccessScript () []byte {
445465 return h .script
446466}
447467
@@ -478,6 +498,11 @@ func (h *HtlcScriptV1) SuccessSequence() uint32 {
478498 return 0
479499}
480500
501+ // Sighash is the signature hash to use for transactions spending from the htlc.
502+ func (h * HtlcScriptV1 ) SigHash () txscript.SigHashType {
503+ return txscript .SigHashAll
504+ }
505+
481506// lockingConditions return the address, pkScript and sigScript (if
482507// required) for a htlc script.
483508func (h * HtlcScriptV1 ) lockingConditions (htlcOutputType HtlcOutputType ,
@@ -581,8 +606,19 @@ func (h *HtlcScriptV2) GenTimeoutWitness(
581606 return witnessStack , nil
582607}
583608
584- // Script returns the htlc script.
585- func (h * HtlcScriptV2 ) Script () []byte {
609+ // TimeoutScript returns the redeem script required to unlock the htlc after
610+ // timeout.
611+ //
612+ // In the case of HtlcScriptV2, this is the full segwit v0 script.
613+ func (h * HtlcScriptV2 ) TimeoutScript () []byte {
614+ return h .script
615+ }
616+
617+ // SuccessScript returns the redeem script required to unlock the htlc using
618+ // the preimage.
619+ //
620+ // In the case of HtlcScriptV2, this is the full segwit v0 script.
621+ func (h * HtlcScriptV2 ) SuccessScript () []byte {
586622 return h .script
587623}
588624
@@ -620,6 +656,11 @@ func (h *HtlcScriptV2) SuccessSequence() uint32 {
620656 return 1
621657}
622658
659+ // Sighash is the signature hash to use for transactions spending from the htlc.
660+ func (h * HtlcScriptV2 ) SigHash () txscript.SigHashType {
661+ return txscript .SigHashAll
662+ }
663+
623664// lockingConditions return the address, pkScript and sigScript (if
624665// required) for a htlc script.
625666func (h * HtlcScriptV2 ) lockingConditions (htlcOutputType HtlcOutputType ,
@@ -630,13 +671,13 @@ func (h *HtlcScriptV2) lockingConditions(htlcOutputType HtlcOutputType,
630671
631672// HtlcScriptV3 encapsulates the htlc v3 script.
632673type HtlcScriptV3 struct {
633- // TimeoutScript is the final locking script for the timeout path which
674+ // timeoutScript is the final locking script for the timeout path which
634675 // is available to the sender after the set blockheight.
635- TimeoutScript []byte
676+ timeoutScript []byte
636677
637- // SuccessScript is the final locking script for the success path in
678+ // successScript is the final locking script for the success path in
638679 // which the receiver reveals the preimage.
639- SuccessScript []byte
680+ successScript []byte
640681
641682 // InternalPubKey is the public key for the keyspend path which bypasses
642683 // the above two locking scripts.
@@ -707,8 +748,8 @@ func newHTLCScriptV3(cltvExpiry int32, senderHtlcKey, receiverHtlcKey [33]byte,
707748 )
708749
709750 return & HtlcScriptV3 {
710- TimeoutScript : timeoutPathScript ,
711- SuccessScript : successPathScript ,
751+ timeoutScript : timeoutPathScript ,
752+ successScript : successPathScript ,
712753 InternalPubKey : aggregateKey .PreTweakedKey ,
713754 TaprootKey : taprootKey ,
714755 RootHash : rootHash ,
@@ -787,15 +828,15 @@ func (h *HtlcScriptV3) genControlBlock(leafScript []byte) ([]byte, error) {
787828func (h * HtlcScriptV3 ) genSuccessWitness (
788829 receiverSig []byte , preimage lntypes.Preimage ) (wire.TxWitness , error ) {
789830
790- controlBlockBytes , err := h .genControlBlock (h .TimeoutScript )
831+ controlBlockBytes , err := h .genControlBlock (h .timeoutScript )
791832 if err != nil {
792833 return nil , err
793834 }
794835
795836 return wire.TxWitness {
796837 preimage [:],
797838 receiverSig ,
798- h .SuccessScript ,
839+ h .successScript ,
799840 controlBlockBytes ,
800841 }, nil
801842}
@@ -805,14 +846,14 @@ func (h *HtlcScriptV3) genSuccessWitness(
805846func (h * HtlcScriptV3 ) GenTimeoutWitness (
806847 senderSig []byte ) (wire.TxWitness , error ) {
807848
808- controlBlockBytes , err := h .genControlBlock (h .SuccessScript )
849+ controlBlockBytes , err := h .genControlBlock (h .successScript )
809850 if err != nil {
810851 return nil , err
811852 }
812853
813854 return wire.TxWitness {
814855 senderSig ,
815- h .TimeoutScript ,
856+ h .timeoutScript ,
816857 controlBlockBytes ,
817858 }, nil
818859}
@@ -823,9 +864,20 @@ func (h *HtlcScriptV3) IsSuccessWitness(witness wire.TxWitness) bool {
823864 return len (witness ) == 4
824865}
825866
826- // Script is not implemented, but necessary to conform to interface.
827- func (h * HtlcScriptV3 ) Script () []byte {
828- return nil
867+ // TimeoutScript returns the redeem script required to unlock the htlc after
868+ // timeout.
869+ //
870+ // In the case of HtlcScriptV3, this is the timeout tapleaf.
871+ func (h * HtlcScriptV3 ) TimeoutScript () []byte {
872+ return h .timeoutScript
873+ }
874+
875+ // SuccessScript returns the redeem script required to unlock the htlc using
876+ // the preimage.
877+ //
878+ // In the case of HtlcScriptV3, this is the claim tapleaf.
879+ func (h * HtlcScriptV3 ) SuccessScript () []byte {
880+ return h .successScript
829881}
830882
831883// MaxSuccessWitnessSize returns the maximum witness size for the
@@ -872,6 +924,11 @@ func (h *HtlcScriptV3) SuccessSequence() uint32 {
872924 return 1
873925}
874926
927+ // Sighash is the signature hash to use for transactions spending from the htlc.
928+ func (h * HtlcScriptV3 ) SigHash () txscript.SigHashType {
929+ return txscript .SigHashDefault
930+ }
931+
875932// lockingConditions return the address, pkScript and sigScript (if required)
876933// for a htlc script.
877934func (h * HtlcScriptV3 ) lockingConditions (outputType HtlcOutputType ,
0 commit comments