@@ -324,6 +324,17 @@ pub trait BaseSign {
324
324
/// (which is committed to in the BIP 143 signatures).
325
325
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 , ( ) > ;
326
326
327
+ #[ cfg( anchors) ]
328
+ /// Computes the signature for a commitment transaction's HTLC output used as an input within
329
+ /// `htlc_tx`, which spends the commitment transaction, at index `input`.
330
+ /// Note that this should only be used to sign HTLC transactions from channels supporting anchor
331
+ /// outputs after all additional inputs/outputs have been added to the transaction.
332
+ fn sign_holder_htlc_transaction (
333
+ & self , htlc_tx : & Transaction , input : usize , per_commitment_number : u64 ,
334
+ htlc : & HTLCOutputInCommitment , counterparty_base_htlc_key : & PublicKey ,
335
+ counterparty_base_revocation_key : & PublicKey , secp_ctx : & Secp256k1 < secp256k1:: All >
336
+ ) -> Result < Signature , ( ) > ;
337
+
327
338
/// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
328
339
/// transaction, either offered or received.
329
340
///
@@ -671,7 +682,6 @@ impl InMemorySigner {
671
682
witness. push ( witness_script. clone ( ) . into_bytes ( ) ) ;
672
683
Ok ( witness)
673
684
}
674
-
675
685
}
676
686
677
687
impl BaseSign for InMemorySigner {
@@ -767,6 +777,36 @@ impl BaseSign for InMemorySigner {
767
777
return Ok ( sign ( secp_ctx, & sighash, & revocation_key) )
768
778
}
769
779
780
+ #[ cfg( anchors) ]
781
+ fn sign_holder_htlc_transaction (
782
+ & self , htlc_tx : & Transaction , input : usize , per_commitment_number : u64 ,
783
+ htlc : & HTLCOutputInCommitment , counterparty_base_htlc_key : & PublicKey ,
784
+ counterparty_base_revocation_key : & PublicKey , secp_ctx : & Secp256k1 < secp256k1:: All >
785
+ ) -> Result < Signature , ( ) > {
786
+ let per_commitment_point = self . get_per_commitment_point ( per_commitment_number, & secp_ctx) ;
787
+ let witness_script = {
788
+ let our_htlc_key = chan_utils:: derive_public_key (
789
+ secp_ctx, & per_commitment_point, & self . pubkeys ( ) . htlc_basepoint
790
+ ) . map_err ( |_| ( ) ) ?;
791
+ let counterparty_htlc_key = chan_utils:: derive_public_revocation_key (
792
+ secp_ctx, & per_commitment_point, counterparty_base_htlc_key
793
+ ) . map_err ( |_| ( ) ) ?;
794
+ let revocation_key = chan_utils:: derive_public_revocation_key (
795
+ secp_ctx, & per_commitment_point, counterparty_base_revocation_key
796
+ ) . map_err ( |_| ( ) ) ?;
797
+ chan_utils:: get_htlc_redeemscript_with_explicit_keys (
798
+ & htlc, true /* opt_anchors */ , & our_htlc_key, & counterparty_htlc_key, & revocation_key,
799
+ )
800
+ } ;
801
+ let sighash = & sighash:: SighashCache :: new ( & * htlc_tx) . segwit_signature_hash (
802
+ input, & witness_script, htlc. amount_msat / 1000 , EcdsaSighashType :: All
803
+ ) . map_err ( |_| ( ) ) ?;
804
+ let our_htlc_private_key = chan_utils:: derive_private_key (
805
+ & secp_ctx, & per_commitment_point, & self . htlc_base_key
806
+ ) . map_err ( |_| ( ) ) ?;
807
+ Ok ( sign ( & secp_ctx, & hash_to_message ! ( sighash) , & our_htlc_private_key) )
808
+ }
809
+
770
810
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 , ( ) > {
771
811
if let Ok ( htlc_key) = chan_utils:: derive_private_key ( & secp_ctx, & per_commitment_point, & self . htlc_base_key ) {
772
812
let witness_script = if let Ok ( revocation_pubkey) = chan_utils:: derive_public_revocation_key ( & secp_ctx, & per_commitment_point, & self . pubkeys ( ) . revocation_basepoint ) {
0 commit comments