@@ -34,7 +34,8 @@ use bitcoin::{PackedLockTime, secp256k1, Sequence, Witness};
34
34
use crate :: util:: transaction_utils;
35
35
use crate :: util:: crypto:: { hkdf_extract_expand_twice, sign} ;
36
36
use crate :: util:: ser:: { Writeable , Writer , Readable , ReadableArgs } ;
37
-
37
+ #[ cfg( anchors) ]
38
+ use crate :: util:: events:: HTLCDescriptor ;
38
39
use crate :: chain:: transaction:: OutPoint ;
39
40
use crate :: ln:: channel:: ANCHOR_OUTPUT_VALUE_SATOSHI ;
40
41
use crate :: ln:: { chan_utils, PaymentPreimage } ;
@@ -325,6 +326,19 @@ pub trait BaseSign {
325
326
/// (which is committed to in the BIP 143 signatures).
326
327
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 , ( ) > ;
327
328
329
+ #[ cfg( anchors) ]
330
+ /// Computes the signature for a commitment transaction's HTLC output used as an input within
331
+ /// `htlc_tx`, which spends the commitment transaction, at index `input`. The signature returned
332
+ /// must be be computed using [`EcdsaSighashType::All`]. Note that this should only be used to
333
+ /// sign HTLC transactions from channels supporting anchor outputs after all additional
334
+ /// inputs/outputs have been added to the transaction.
335
+ ///
336
+ /// [`EcdsaSighashType::All`]: bitcoin::blockdata::transaction::EcdsaSighashType::All
337
+ fn sign_holder_htlc_transaction (
338
+ & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor ,
339
+ secp_ctx : & Secp256k1 < secp256k1:: All >
340
+ ) -> Result < Signature , ( ) > ;
341
+
328
342
/// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
329
343
/// transaction, either offered or received.
330
344
///
@@ -682,7 +696,6 @@ impl InMemorySigner {
682
696
witness. push ( witness_script. clone ( ) . into_bytes ( ) ) ;
683
697
Ok ( witness)
684
698
}
685
-
686
699
}
687
700
688
701
impl BaseSign for InMemorySigner {
@@ -779,6 +792,24 @@ impl BaseSign for InMemorySigner {
779
792
return Ok ( sign ( secp_ctx, & sighash, & revocation_key) )
780
793
}
781
794
795
+ #[ cfg( anchors) ]
796
+ fn sign_holder_htlc_transaction (
797
+ & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor ,
798
+ secp_ctx : & Secp256k1 < secp256k1:: All >
799
+ ) -> Result < Signature , ( ) > {
800
+ let per_commitment_point = self . get_per_commitment_point (
801
+ htlc_descriptor. per_commitment_number , & secp_ctx
802
+ ) ;
803
+ let witness_script = htlc_descriptor. witness_script ( & per_commitment_point, secp_ctx) ;
804
+ let sighash = & sighash:: SighashCache :: new ( & * htlc_tx) . segwit_signature_hash (
805
+ input, & witness_script, htlc_descriptor. htlc . amount_msat / 1000 , EcdsaSighashType :: All
806
+ ) . map_err ( |_| ( ) ) ?;
807
+ let our_htlc_private_key = chan_utils:: derive_private_key (
808
+ & secp_ctx, & per_commitment_point, & self . htlc_base_key
809
+ ) ;
810
+ Ok ( sign ( & secp_ctx, & hash_to_message ! ( sighash) , & our_htlc_private_key) )
811
+ }
812
+
782
813
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 , ( ) > {
783
814
let htlc_key = chan_utils:: derive_private_key ( & secp_ctx, & per_commitment_point, & self . htlc_base_key ) ;
784
815
let revocation_pubkey = chan_utils:: derive_public_revocation_key ( & secp_ctx, & per_commitment_point, & self . pubkeys ( ) . revocation_basepoint ) ;
0 commit comments