@@ -34,7 +34,8 @@ use bitcoin::{PackedLockTime, secp256k1, Sequence, Witness};
3434use crate :: util:: { byte_utils, transaction_utils} ;
3535use crate :: util:: crypto:: { hkdf_extract_expand_twice, sign} ;
3636use crate :: util:: ser:: { Writeable , Writer , Readable , ReadableArgs } ;
37-
37+ #[ cfg( anchors) ]
38+ use crate :: util:: events:: HTLCDescriptor ;
3839use crate :: chain:: transaction:: OutPoint ;
3940use crate :: ln:: channel:: ANCHOR_OUTPUT_VALUE_SATOSHI ;
4041use crate :: ln:: { chan_utils, PaymentPreimage } ;
@@ -324,6 +325,16 @@ pub trait BaseSign {
324325 /// (which is committed to in the BIP 143 signatures).
325326 fn sign_justice_revoked_htlc ( & self , justice_tx : & Transaction , input : usize , amount : u64 , per_commitment_key : & SecretKey , htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> Result < Signature , ( ) > ;
326327
328+ #[ cfg( anchors) ]
329+ /// Computes the signature for a commitment transaction's HTLC output used as an input within
330+ /// `htlc_tx`, which spends the commitment transaction, at index `input`.
331+ /// Note that this should only be used to sign HTLC transactions from channels supporting anchor
332+ /// outputs after all additional inputs/outputs have been added to the transaction.
333+ fn sign_holder_htlc_transaction (
334+ & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor ,
335+ secp_ctx : & Secp256k1 < secp256k1:: All >
336+ ) -> Result < Signature , ( ) > ;
337+
327338 /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
328339 /// transaction, either offered or received.
329340 ///
@@ -671,7 +682,6 @@ impl InMemorySigner {
671682 witness. push ( witness_script. clone ( ) . into_bytes ( ) ) ;
672683 Ok ( witness)
673684 }
674-
675685}
676686
677687impl BaseSign for InMemorySigner {
@@ -768,6 +778,24 @@ impl BaseSign for InMemorySigner {
768778 return Ok ( sign ( secp_ctx, & sighash, & revocation_key) )
769779 }
770780
781+ #[ cfg( anchors) ]
782+ fn sign_holder_htlc_transaction (
783+ & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor ,
784+ secp_ctx : & Secp256k1 < secp256k1:: All >
785+ ) -> Result < Signature , ( ) > {
786+ let per_commitment_point = self . get_per_commitment_point (
787+ htlc_descriptor. per_commitment_number , & secp_ctx
788+ ) ;
789+ let witness_script = htlc_descriptor. witness_script ( & per_commitment_point, secp_ctx) ;
790+ let sighash = & sighash:: SighashCache :: new ( & * htlc_tx) . segwit_signature_hash (
791+ input, & witness_script, htlc_descriptor. htlc . amount_msat / 1000 , EcdsaSighashType :: All
792+ ) . map_err ( |_| ( ) ) ?;
793+ let our_htlc_private_key = chan_utils:: derive_private_key (
794+ & secp_ctx, & per_commitment_point, & self . htlc_base_key
795+ ) ;
796+ Ok ( sign ( & secp_ctx, & hash_to_message ! ( sighash) , & our_htlc_private_key) )
797+ }
798+
771799 fn sign_counterparty_htlc_transaction ( & self , htlc_tx : & Transaction , input : usize , amount : u64 , per_commitment_point : & PublicKey , htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> Result < Signature , ( ) > {
772800 let htlc_key = chan_utils:: derive_private_key ( & secp_ctx, & per_commitment_point, & self . htlc_base_key ) ;
773801 let revocation_pubkey = chan_utils:: derive_public_revocation_key ( & secp_ctx, & per_commitment_point, & self . pubkeys ( ) . revocation_basepoint ) ;
0 commit comments