@@ -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
///
@@ -672,7 +683,6 @@ impl InMemorySigner {
672
683
witness. push ( witness_script. clone ( ) . into_bytes ( ) ) ;
673
684
Ok ( witness)
674
685
}
675
-
676
686
}
677
687
678
688
impl BaseSign for InMemorySigner {
@@ -769,6 +779,36 @@ impl BaseSign for InMemorySigner {
769
779
return Ok ( sign ( secp_ctx, & sighash, & revocation_key) )
770
780
}
771
781
782
+ #[ cfg( anchors) ]
783
+ fn sign_holder_htlc_transaction (
784
+ & self , htlc_tx : & Transaction , input : usize , per_commitment_number : u64 ,
785
+ htlc : & HTLCOutputInCommitment , counterparty_base_htlc_key : & PublicKey ,
786
+ counterparty_base_revocation_key : & PublicKey , secp_ctx : & Secp256k1 < secp256k1:: All >
787
+ ) -> Result < Signature , ( ) > {
788
+ let per_commitment_point = self . get_per_commitment_point ( per_commitment_number, & secp_ctx) ;
789
+ let witness_script = {
790
+ let our_htlc_key = chan_utils:: derive_public_key (
791
+ secp_ctx, & per_commitment_point, & self . pubkeys ( ) . htlc_basepoint
792
+ ) . map_err ( |_| ( ) ) ?;
793
+ let counterparty_htlc_key = chan_utils:: derive_public_revocation_key (
794
+ secp_ctx, & per_commitment_point, counterparty_base_htlc_key
795
+ ) . map_err ( |_| ( ) ) ?;
796
+ let revocation_key = chan_utils:: derive_public_revocation_key (
797
+ secp_ctx, & per_commitment_point, counterparty_base_revocation_key
798
+ ) . map_err ( |_| ( ) ) ?;
799
+ chan_utils:: get_htlc_redeemscript_with_explicit_keys (
800
+ & htlc, true /* opt_anchors */ , & our_htlc_key, & counterparty_htlc_key, & revocation_key,
801
+ )
802
+ } ;
803
+ let sighash = & sighash:: SighashCache :: new ( & * htlc_tx) . segwit_signature_hash (
804
+ input, & witness_script, htlc. amount_msat / 1000 , EcdsaSighashType :: All
805
+ ) . map_err ( |_| ( ) ) ?;
806
+ let our_htlc_private_key = chan_utils:: derive_private_key (
807
+ & secp_ctx, & per_commitment_point, & self . htlc_base_key
808
+ ) . map_err ( |_| ( ) ) ?;
809
+ Ok ( sign ( & secp_ctx, & hash_to_message ! ( sighash) , & our_htlc_private_key) )
810
+ }
811
+
772
812
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 , ( ) > {
773
813
if let Ok ( htlc_key) = chan_utils:: derive_private_key ( & secp_ctx, & per_commitment_point, & self . htlc_base_key ) {
774
814
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