@@ -6,15 +6,14 @@ use bitcoin::blockdata::script::{Script,Builder};
6
6
use bitcoin:: blockdata:: opcodes;
7
7
use bitcoin:: blockdata:: transaction:: { TxIn , TxOut , OutPoint , Transaction , SigHashType } ;
8
8
use bitcoin:: consensus:: encode:: { self , Decodable , Encodable } ;
9
- use bitcoin:: util:: bip143;
10
9
11
10
use bitcoin_hashes:: { Hash , HashEngine } ;
12
11
use bitcoin_hashes:: sha256:: Hash as Sha256 ;
13
12
use bitcoin_hashes:: ripemd160:: Hash as Ripemd160 ;
14
13
use bitcoin_hashes:: hash160:: Hash as Hash160 ;
15
14
use bitcoin_hashes:: sha256d:: Hash as Sha256dHash ;
16
15
17
- use ln:: channelmanager:: { PaymentHash , PaymentPreimage } ;
16
+ use ln:: channelmanager:: PaymentHash ;
18
17
use ln:: msgs:: DecodeError ;
19
18
use util:: ser:: { Readable , Writeable , Writer , WriterWriteAdaptor } ;
20
19
use util:: byte_utils;
@@ -355,7 +354,7 @@ impl_writeable!(HTLCOutputInCommitment, 1 + 8 + 4 + 32 + 5, {
355
354
} ) ;
356
355
357
356
#[ inline]
358
- pub ( super ) fn get_htlc_redeemscript_with_explicit_keys ( htlc : & HTLCOutputInCommitment , a_htlc_key : & PublicKey , b_htlc_key : & PublicKey , revocation_key : & PublicKey ) -> Script {
357
+ pub ( crate ) fn get_htlc_redeemscript_with_explicit_keys ( htlc : & HTLCOutputInCommitment , a_htlc_key : & PublicKey , b_htlc_key : & PublicKey , revocation_key : & PublicKey ) -> Script {
359
358
let payment_hash160 = Ripemd160 :: hash ( & htlc. payment_hash . 0 [ ..] ) . into_inner ( ) ;
360
359
if htlc. offered {
361
360
Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_DUP )
@@ -475,43 +474,6 @@ pub fn build_htlc_transaction(prev_hash: &Sha256dHash, feerate_per_kw: u64, to_s
475
474
}
476
475
}
477
476
478
- /// Signs a transaction created by build_htlc_transaction. If the transaction is an
479
- /// HTLC-Success transaction (ie htlc.offered is false), preimage must be set!
480
- pub ( crate ) fn sign_htlc_transaction < T : secp256k1:: Signing > ( tx : & mut Transaction , their_sig : & Signature , preimage : & Option < PaymentPreimage > , htlc : & HTLCOutputInCommitment , a_htlc_key : & PublicKey , b_htlc_key : & PublicKey , revocation_key : & PublicKey , per_commitment_point : & PublicKey , htlc_base_key : & SecretKey , secp_ctx : & Secp256k1 < T > ) -> Result < ( Signature , Script ) , ( ) > {
481
- if tx. input . len ( ) != 1 { return Err ( ( ) ) ; }
482
- if tx. input [ 0 ] . witness . len ( ) != 0 { return Err ( ( ) ) ; }
483
-
484
- let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys ( & htlc, a_htlc_key, b_htlc_key, revocation_key) ;
485
-
486
- let our_htlc_key = derive_private_key ( secp_ctx, per_commitment_point, htlc_base_key) . map_err ( |_| ( ) ) ?;
487
- let sighash = hash_to_message ! ( & bip143:: SighashComponents :: new( & tx) . sighash_all( & tx. input[ 0 ] , & htlc_redeemscript, htlc. amount_msat / 1000 ) [ ..] ) ;
488
- let local_tx = PublicKey :: from_secret_key ( & secp_ctx, & our_htlc_key) == * a_htlc_key;
489
- let our_sig = secp_ctx. sign ( & sighash, & our_htlc_key) ;
490
-
491
- tx. input [ 0 ] . witness . push ( Vec :: new ( ) ) ; // First is the multisig dummy
492
-
493
- if local_tx { // b, then a
494
- tx. input [ 0 ] . witness . push ( their_sig. serialize_der ( ) . to_vec ( ) ) ;
495
- tx. input [ 0 ] . witness . push ( our_sig. serialize_der ( ) . to_vec ( ) ) ;
496
- } else {
497
- tx. input [ 0 ] . witness . push ( our_sig. serialize_der ( ) . to_vec ( ) ) ;
498
- tx. input [ 0 ] . witness . push ( their_sig. serialize_der ( ) . to_vec ( ) ) ;
499
- }
500
- tx. input [ 0 ] . witness [ 1 ] . push ( SigHashType :: All as u8 ) ;
501
- tx. input [ 0 ] . witness [ 2 ] . push ( SigHashType :: All as u8 ) ;
502
-
503
- if htlc. offered {
504
- tx. input [ 0 ] . witness . push ( Vec :: new ( ) ) ;
505
- assert ! ( preimage. is_none( ) ) ;
506
- } else {
507
- tx. input [ 0 ] . witness . push ( preimage. unwrap ( ) . 0 . to_vec ( ) ) ;
508
- }
509
-
510
- tx. input [ 0 ] . witness . push ( htlc_redeemscript. as_bytes ( ) . to_vec ( ) ) ;
511
-
512
- Ok ( ( our_sig, htlc_redeemscript) )
513
- }
514
-
515
477
#[ derive( Clone ) ]
516
478
/// We use this to track local commitment transactions and put off signing them until we are ready
517
479
/// to broadcast. Eventually this will require a signer which is possibly external, but for now we
0 commit comments