@@ -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.
@@ -290,8 +299,8 @@ func (h *Htlc) AddSuccessToEstimator(estimator *input.TxWeightEstimator) error {
290299 if ! ok {
291300 return ErrInvalidOutputSelected
292301 }
293- successLeaf := txscript .NewBaseTapLeaf (trHtlc .SuccessScript )
294- timeoutLeaf := txscript .NewBaseTapLeaf (trHtlc .TimeoutScript )
302+ successLeaf := txscript .NewBaseTapLeaf (trHtlc .SuccessScript () )
303+ timeoutLeaf := txscript .NewBaseTapLeaf (trHtlc .TimeoutScript () )
295304 timeoutLeafHash := timeoutLeaf .TapHash ()
296305
297306 tapscript := input .TapscriptPartialReveal (
@@ -321,8 +330,8 @@ func (h *Htlc) AddTimeoutToEstimator(estimator *input.TxWeightEstimator) error {
321330 if ! ok {
322331 return ErrInvalidOutputSelected
323332 }
324- successLeaf := txscript .NewBaseTapLeaf (trHtlc .SuccessScript )
325- timeoutLeaf := txscript .NewBaseTapLeaf (trHtlc .TimeoutScript )
333+ successLeaf := txscript .NewBaseTapLeaf (trHtlc .SuccessScript () )
334+ timeoutLeaf := txscript .NewBaseTapLeaf (trHtlc .TimeoutScript () )
326335 successLeafHash := successLeaf .TapHash ()
327336
328337 tapscript := input .TapscriptPartialReveal (
@@ -436,8 +445,19 @@ func (h *HtlcScriptV1) IsSuccessWitness(witness wire.TxWitness) bool {
436445 return ! isTimeoutTx
437446}
438447
439- // Script returns the htlc script.
440- func (h * HtlcScriptV1 ) Script () []byte {
448+ // TimeoutScript returns the redeem script required to unlock the htlc after
449+ // timeout.
450+ //
451+ // In the case of HtlcScriptV1, this is the full segwit v0 script.
452+ func (h * HtlcScriptV1 ) TimeoutScript () []byte {
453+ return h .script
454+ }
455+
456+ // SuccessScript returns the redeem script required to unlock the htlc using
457+ // the preimage.
458+ //
459+ // In the case of HtlcScriptV1, this is the full segwit v0 script.
460+ func (h * HtlcScriptV1 ) SuccessScript () []byte {
441461 return h .script
442462}
443463
@@ -474,6 +494,11 @@ func (h *HtlcScriptV1) SuccessSequence() uint32 {
474494 return 0
475495}
476496
497+ // Sighash is the signature hash to use for transactions spending from the htlc.
498+ func (h * HtlcScriptV1 ) SigHash () txscript.SigHashType {
499+ return txscript .SigHashAll
500+ }
501+
477502// lockingConditions return the address, pkScript and sigScript (if
478503// required) for a htlc script.
479504func (h * HtlcScriptV1 ) lockingConditions (htlcOutputType HtlcOutputType ,
@@ -577,8 +602,19 @@ func (h *HtlcScriptV2) GenTimeoutWitness(
577602 return witnessStack , nil
578603}
579604
580- // Script returns the htlc script.
581- func (h * HtlcScriptV2 ) Script () []byte {
605+ // TimeoutScript returns the redeem script required to unlock the htlc after
606+ // timeout.
607+ //
608+ // In the case of HtlcScriptV2, this is the full segwit v0 script.
609+ func (h * HtlcScriptV2 ) TimeoutScript () []byte {
610+ return h .script
611+ }
612+
613+ // SuccessScript returns the redeem script required to unlock the htlc using
614+ // the preimage.
615+ //
616+ // In the case of HtlcScriptV2, this is the full segwit v0 script.
617+ func (h * HtlcScriptV2 ) SuccessScript () []byte {
582618 return h .script
583619}
584620
@@ -616,6 +652,11 @@ func (h *HtlcScriptV2) SuccessSequence() uint32 {
616652 return 1
617653}
618654
655+ // Sighash is the signature hash to use for transactions spending from the htlc.
656+ func (h * HtlcScriptV2 ) SigHash () txscript.SigHashType {
657+ return txscript .SigHashAll
658+ }
659+
619660// lockingConditions return the address, pkScript and sigScript (if
620661// required) for a htlc script.
621662func (h * HtlcScriptV2 ) lockingConditions (htlcOutputType HtlcOutputType ,
@@ -626,13 +667,13 @@ func (h *HtlcScriptV2) lockingConditions(htlcOutputType HtlcOutputType,
626667
627668// HtlcScriptV3 encapsulates the htlc v3 script.
628669type HtlcScriptV3 struct {
629- // TimeoutScript is the final locking script for the timeout path which
670+ // timeoutScript is the final locking script for the timeout path which
630671 // is available to the sender after the set blockheight.
631- TimeoutScript []byte
672+ timeoutScript []byte
632673
633- // SuccessScript is the final locking script for the success path in
674+ // successScript is the final locking script for the success path in
634675 // which the receiver reveals the preimage.
635- SuccessScript []byte
676+ successScript []byte
636677
637678 // InternalPubKey is the public key for the keyspend path which bypasses
638679 // the above two locking scripts.
@@ -699,8 +740,8 @@ func newHTLCScriptV3(cltvExpiry int32, senderHtlcKey, receiverHtlcKey [33]byte,
699740 )
700741
701742 return & HtlcScriptV3 {
702- TimeoutScript : timeoutPathScript ,
703- SuccessScript : successPathScript ,
743+ timeoutScript : timeoutPathScript ,
744+ successScript : successPathScript ,
704745 InternalPubKey : aggregateKey .PreTweakedKey ,
705746 TaprootKey : taprootKey ,
706747 RootHash : rootHash ,
@@ -779,15 +820,15 @@ func (h *HtlcScriptV3) genControlBlock(leafScript []byte) ([]byte, error) {
779820func (h * HtlcScriptV3 ) genSuccessWitness (
780821 receiverSig []byte , preimage lntypes.Preimage ) (wire.TxWitness , error ) {
781822
782- controlBlockBytes , err := h .genControlBlock (h .TimeoutScript )
823+ controlBlockBytes , err := h .genControlBlock (h .timeoutScript )
783824 if err != nil {
784825 return nil , err
785826 }
786827
787828 return wire.TxWitness {
788829 preimage [:],
789830 receiverSig ,
790- h .SuccessScript ,
831+ h .successScript ,
791832 controlBlockBytes ,
792833 }, nil
793834}
@@ -797,14 +838,14 @@ func (h *HtlcScriptV3) genSuccessWitness(
797838func (h * HtlcScriptV3 ) GenTimeoutWitness (
798839 senderSig []byte ) (wire.TxWitness , error ) {
799840
800- controlBlockBytes , err := h .genControlBlock (h .SuccessScript )
841+ controlBlockBytes , err := h .genControlBlock (h .successScript )
801842 if err != nil {
802843 return nil , err
803844 }
804845
805846 return wire.TxWitness {
806847 senderSig ,
807- h .TimeoutScript ,
848+ h .timeoutScript ,
808849 controlBlockBytes ,
809850 }, nil
810851}
@@ -815,9 +856,20 @@ func (h *HtlcScriptV3) IsSuccessWitness(witness wire.TxWitness) bool {
815856 return len (witness ) == 4
816857}
817858
818- // Script is not implemented, but necessary to conform to interface.
819- func (h * HtlcScriptV3 ) Script () []byte {
820- return nil
859+ // TimeoutScript returns the redeem script required to unlock the htlc after
860+ // timeout.
861+ //
862+ // In the case of HtlcScriptV3, this is the timeout tapleaf.
863+ func (h * HtlcScriptV3 ) TimeoutScript () []byte {
864+ return h .timeoutScript
865+ }
866+
867+ // SuccessScript returns the redeem script required to unlock the htlc using
868+ // the preimage.
869+ //
870+ // In the case of HtlcScriptV3, this is the claim tapleaf.
871+ func (h * HtlcScriptV3 ) SuccessScript () []byte {
872+ return h .successScript
821873}
822874
823875// MaxSuccessWitnessSize returns the maximum witness size for the
@@ -864,6 +916,11 @@ func (h *HtlcScriptV3) SuccessSequence() uint32 {
864916 return 1
865917}
866918
919+ // Sighash is the signature hash to use for transactions spending from the htlc.
920+ func (h * HtlcScriptV3 ) SigHash () txscript.SigHashType {
921+ return txscript .SigHashDefault
922+ }
923+
867924// lockingConditions return the address, pkScript and sigScript (if required)
868925// for a htlc script.
869926func (h * HtlcScriptV3 ) lockingConditions (outputType HtlcOutputType ,
0 commit comments