@@ -294,6 +294,48 @@ impl ChannelSigner for TestChannelSigner {
294294 fn unsafe_sign_holder_commitment ( & self , commitment_tx : & HolderCommitmentTransaction , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> Result < Transaction , ( ) > {
295295 Ok ( self . inner . unsafe_sign_holder_commitment ( commitment_tx, secp_ctx) . unwrap ( ) )
296296 }
297+
298+ fn sign_holder_htlc_transaction (
299+ & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor ,
300+ secp_ctx : & Secp256k1 < secp256k1:: All >
301+ ) -> Result < Transaction , ( ) > {
302+ #[ cfg( test) ]
303+ if !self . is_signer_available ( SignerOp :: SignHolderHtlcTransaction ) {
304+ return Err ( ( ) ) ;
305+ }
306+ let state = self . state . lock ( ) . unwrap ( ) ;
307+ if state. last_holder_revoked_commitment - 1 != htlc_descriptor. per_commitment_number &&
308+ state. last_holder_revoked_commitment - 2 != htlc_descriptor. per_commitment_number
309+ {
310+ if !self . disable_revocation_policy_check {
311+ panic ! ( "can only sign the next two unrevoked commitment numbers, revoked={} vs requested={} for {}" ,
312+ state. last_holder_revoked_commitment, htlc_descriptor. per_commitment_number, self . inner. commitment_seed[ 0 ] )
313+ }
314+ }
315+ assert_eq ! ( htlc_tx. input[ input] , htlc_descriptor. unsigned_tx_input( ) ) ;
316+ let revokeable_spk = self . get_revokeable_spk ( true , htlc_descriptor. per_commitment_number , & htlc_descriptor. per_commitment_point , secp_ctx) ;
317+ assert_eq ! ( htlc_tx. output[ input] , htlc_descriptor. tx_output( revokeable_spk) ) ;
318+ {
319+ let witness_script = htlc_descriptor. witness_script ( secp_ctx) ;
320+ let sighash_type = if self . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
321+ EcdsaSighashType :: SinglePlusAnyoneCanPay
322+ } else {
323+ EcdsaSighashType :: All
324+ } ;
325+ let sighash = & sighash:: SighashCache :: new ( & * htlc_tx) . p2wsh_signature_hash (
326+ input, & witness_script, htlc_descriptor. htlc . to_bitcoin_amount ( ) , sighash_type
327+ ) . unwrap ( ) ;
328+ let countersignatory_htlc_key = HtlcKey :: from_basepoint (
329+ & secp_ctx, & self . inner . counterparty_pubkeys ( ) . unwrap ( ) . htlc_basepoint , & htlc_descriptor. per_commitment_point ,
330+ ) ;
331+
332+ secp_ctx. verify_ecdsa (
333+ & hash_to_message ! ( sighash. as_byte_array( ) ) , & htlc_descriptor. counterparty_sig , & countersignatory_htlc_key. to_public_key ( )
334+ ) . unwrap ( ) ;
335+ }
336+ Ok ( self . inner . sign_holder_htlc_transaction ( htlc_tx, input, htlc_descriptor, secp_ctx) . unwrap ( ) )
337+ }
338+
297339}
298340
299341impl EcdsaChannelSigner for TestChannelSigner {
@@ -336,47 +378,6 @@ impl EcdsaChannelSigner for TestChannelSigner {
336378 Ok ( EcdsaChannelSigner :: sign_justice_revoked_htlc ( & self . inner , justice_tx, input, amount, per_commitment_key, htlc, secp_ctx) . unwrap ( ) )
337379 }
338380
339- fn sign_holder_htlc_transaction (
340- & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor ,
341- secp_ctx : & Secp256k1 < secp256k1:: All >
342- ) -> Result < Signature , ( ) > {
343- #[ cfg( test) ]
344- if !self . is_signer_available ( SignerOp :: SignHolderHtlcTransaction ) {
345- return Err ( ( ) ) ;
346- }
347- let state = self . state . lock ( ) . unwrap ( ) ;
348- if state. last_holder_revoked_commitment - 1 != htlc_descriptor. per_commitment_number &&
349- state. last_holder_revoked_commitment - 2 != htlc_descriptor. per_commitment_number
350- {
351- if !self . disable_revocation_policy_check {
352- panic ! ( "can only sign the next two unrevoked commitment numbers, revoked={} vs requested={} for {}" ,
353- state. last_holder_revoked_commitment, htlc_descriptor. per_commitment_number, self . inner. commitment_seed[ 0 ] )
354- }
355- }
356- assert_eq ! ( htlc_tx. input[ input] , htlc_descriptor. unsigned_tx_input( ) ) ;
357- let revokeable_spk = self . get_revokeable_spk ( true , htlc_descriptor. per_commitment_number , & htlc_descriptor. per_commitment_point , secp_ctx) ;
358- assert_eq ! ( htlc_tx. output[ input] , htlc_descriptor. tx_output( revokeable_spk) ) ;
359- {
360- let witness_script = htlc_descriptor. witness_script ( secp_ctx) ;
361- let sighash_type = if self . channel_type_features ( ) . supports_anchors_zero_fee_htlc_tx ( ) {
362- EcdsaSighashType :: SinglePlusAnyoneCanPay
363- } else {
364- EcdsaSighashType :: All
365- } ;
366- let sighash = & sighash:: SighashCache :: new ( & * htlc_tx) . p2wsh_signature_hash (
367- input, & witness_script, htlc_descriptor. htlc . to_bitcoin_amount ( ) , sighash_type
368- ) . unwrap ( ) ;
369- let countersignatory_htlc_key = HtlcKey :: from_basepoint (
370- & secp_ctx, & self . inner . counterparty_pubkeys ( ) . unwrap ( ) . htlc_basepoint , & htlc_descriptor. per_commitment_point ,
371- ) ;
372-
373- secp_ctx. verify_ecdsa (
374- & hash_to_message ! ( sighash. as_byte_array( ) ) , & htlc_descriptor. counterparty_sig , & countersignatory_htlc_key. to_public_key ( )
375- ) . unwrap ( ) ;
376- }
377- Ok ( EcdsaChannelSigner :: sign_holder_htlc_transaction ( & self . inner , htlc_tx, input, htlc_descriptor, secp_ctx) . unwrap ( ) )
378- }
379-
380381 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 , ( ) > {
381382 #[ cfg( test) ]
382383 if !self . is_signer_available ( SignerOp :: SignCounterpartyHtlcTransaction ) {
@@ -446,10 +447,6 @@ impl TaprootChannelSigner for TestChannelSigner {
446447 todo ! ( )
447448 }
448449
449- fn sign_holder_htlc_transaction ( & self , htlc_tx : & Transaction , input : usize , htlc_descriptor : & HTLCDescriptor , secp_ctx : & Secp256k1 < All > ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
450- todo ! ( )
451- }
452-
453450 fn sign_counterparty_htlc_transaction ( & self , htlc_tx : & Transaction , input : usize , amount : u64 , per_commitment_point : & PublicKey , htlc : & HTLCOutputInCommitment , secp_ctx : & Secp256k1 < All > ) -> Result < secp256k1:: schnorr:: Signature , ( ) > {
454451 todo ! ( )
455452 }
0 commit comments