@@ -1129,56 +1129,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1129
1129
chan_utils:: build_htlc_transaction ( prev_hash, feerate_per_kw, if local { self . their_to_self_delay } else { self . our_to_self_delay } , htlc, & keys. a_delayed_payment_key , & keys. revocation_key )
1130
1130
}
1131
1131
1132
- fn create_htlc_tx_signature ( & self , tx : & Transaction , htlc : & HTLCOutputInCommitment , keys : & TxCreationKeys ) -> Result < ( Script , Signature , bool ) , ChannelError > {
1133
- if tx. input . len ( ) != 1 {
1134
- panic ! ( "Tried to sign HTLC transaction that had input count != 1!" ) ;
1135
- }
1136
-
1137
- let htlc_redeemscript = chan_utils:: get_htlc_redeemscript ( & htlc, & keys) ;
1138
-
1139
- let our_htlc_key = secp_check ! ( chan_utils:: derive_private_key( & self . secp_ctx, & keys. per_commitment_point, self . local_keys. htlc_base_key( ) ) , "Derived invalid key, peer is maliciously selecting parameters" ) ;
1140
- let sighash = hash_to_message ! ( & bip143:: SighashComponents :: new( & tx) . sighash_all( & tx. input[ 0 ] , & htlc_redeemscript, htlc. amount_msat / 1000 ) [ ..] ) ;
1141
- let is_local_tx = PublicKey :: from_secret_key ( & self . secp_ctx , & our_htlc_key) == keys. a_htlc_key ;
1142
- Ok ( ( htlc_redeemscript, self . secp_ctx . sign ( & sighash, & our_htlc_key) , is_local_tx) )
1143
- }
1144
-
1145
- #[ cfg( test) ]
1146
- /// Signs a transaction created by build_htlc_transaction. If the transaction is an
1147
- /// HTLC-Success transaction (ie htlc.offered is false), preimage must be set!
1148
- /// TODO: Make this a chan_utils, use it in channelmonitor and tests, cause its unused now
1149
- fn sign_htlc_transaction ( & self , tx : & mut Transaction , their_sig : & Signature , preimage : & Option < PaymentPreimage > , htlc : & HTLCOutputInCommitment , keys : & TxCreationKeys ) -> Result < Signature , ChannelError > {
1150
- if tx. input . len ( ) != 1 {
1151
- panic ! ( "Tried to sign HTLC transaction that had input count != 1!" ) ;
1152
- }
1153
- if tx. input [ 0 ] . witness . len ( ) != 0 {
1154
- panic ! ( "Tried to re-sign HTLC transaction" ) ;
1155
- }
1156
-
1157
- let ( htlc_redeemscript, our_sig, local_tx) = self . create_htlc_tx_signature ( tx, htlc, keys) ?;
1158
-
1159
- tx. input [ 0 ] . witness . push ( Vec :: new ( ) ) ; // First is the multisig dummy
1160
-
1161
- if local_tx { // b, then a
1162
- tx. input [ 0 ] . witness . push ( their_sig. serialize_der ( ) . to_vec ( ) ) ;
1163
- tx. input [ 0 ] . witness . push ( our_sig. serialize_der ( ) . to_vec ( ) ) ;
1164
- } else {
1165
- tx. input [ 0 ] . witness . push ( our_sig. serialize_der ( ) . to_vec ( ) ) ;
1166
- tx. input [ 0 ] . witness . push ( their_sig. serialize_der ( ) . to_vec ( ) ) ;
1167
- }
1168
- tx. input [ 0 ] . witness [ 1 ] . push ( SigHashType :: All as u8 ) ;
1169
- tx. input [ 0 ] . witness [ 2 ] . push ( SigHashType :: All as u8 ) ;
1170
-
1171
- if htlc. offered {
1172
- tx. input [ 0 ] . witness . push ( Vec :: new ( ) ) ;
1173
- } else {
1174
- tx. input [ 0 ] . witness . push ( preimage. unwrap ( ) . 0 . to_vec ( ) ) ;
1175
- }
1176
-
1177
- tx. input [ 0 ] . witness . push ( htlc_redeemscript. into_bytes ( ) ) ;
1178
-
1179
- Ok ( our_sig)
1180
- }
1181
-
1182
1132
/// Per HTLC, only one get_update_fail_htlc or get_update_fulfill_htlc call may be made.
1183
1133
/// In such cases we debug_assert!(false) and return an IgnoreError. Thus, will always return
1184
1134
/// Ok(_) if debug assertions are turned on and preconditions are met.
@@ -1822,8 +1772,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1822
1772
log_trace ! ( self , "Checking HTLC tx signature {} by key {} against tx {} with redeemscript {}" , log_bytes!( msg. htlc_signatures[ idx] . serialize_compact( ) [ ..] ) , log_bytes!( local_keys. b_htlc_key. serialize( ) ) , encode:: serialize_hex( & htlc_tx) , encode:: serialize_hex( & htlc_redeemscript) ) ;
1823
1773
let htlc_sighash = hash_to_message ! ( & bip143:: SighashComponents :: new( & htlc_tx) . sighash_all( & htlc_tx. input[ 0 ] , & htlc_redeemscript, htlc. amount_msat / 1000 ) [ ..] ) ;
1824
1774
secp_check ! ( self . secp_ctx. verify( & htlc_sighash, & msg. htlc_signatures[ idx] , & local_keys. b_htlc_key) , "Invalid HTLC tx signature from peer" ) ;
1825
- let htlc_sig = self . create_htlc_tx_signature ( & htlc_tx, & htlc, & local_keys) ?. 1 ;
1826
- htlcs_and_sigs. push ( ( htlc, Some ( ( msg. htlc_signatures [ idx] , htlc_sig) ) , source) ) ;
1775
+ htlcs_and_sigs. push ( ( htlc, Some ( msg. htlc_signatures [ idx] ) , source) ) ;
1827
1776
} else {
1828
1777
htlcs_and_sigs. push ( ( htlc, None , source) ) ;
1829
1778
}
@@ -4265,7 +4214,7 @@ mod tests {
4265
4214
assert!( preimage. is_some( ) ) ;
4266
4215
}
4267
4216
4268
- chan . sign_htlc_transaction( & mut htlc_tx, & remote_signature, & preimage, & htlc, & keys) . unwrap( ) ;
4217
+ chan_utils :: sign_htlc_transaction( & mut htlc_tx, & remote_signature, & preimage, & htlc, & keys. a_htlc_key , & keys . b_htlc_key , & keys . revocation_key , & keys . per_commitment_point , chan . local_keys . htlc_base_key ( ) , & chan . secp_ctx ) . unwrap( ) ;
4269
4218
assert_eq!( serialize( & htlc_tx) [ ..] ,
4270
4219
hex:: decode( $tx_hex) . unwrap( ) [ ..] ) ;
4271
4220
} ;
0 commit comments