@@ -31,7 +31,7 @@ use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
31
31
32
32
use bitcoin:: secp256k1:: { Secp256k1 , ecdsa:: Signature } ;
33
33
use bitcoin:: secp256k1:: { SecretKey , PublicKey } ;
34
- use bitcoin:: secp256k1;
34
+ use bitcoin:: { secp256k1, EcdsaSighashType } ;
35
35
36
36
use crate :: ln:: channel:: INITIAL_COMMITMENT_NUMBER ;
37
37
use crate :: ln:: { PaymentHash , PaymentPreimage } ;
@@ -1427,6 +1427,14 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1427
1427
self . inner . lock ( ) . unwrap ( ) . counterparty_commitment_txs_from_update ( update)
1428
1428
}
1429
1429
1430
+ /// Wrapper around [`crate::sign::EcdsaChannelSigner::sign_justice_revoked_output`] to make
1431
+ /// signing the justice transaction easier for implementors of
1432
+ /// [`chain::chainmonitor::Persist`]. On success this method returns a fully signed
1433
+ /// transaction that is ready to be broadcasted.
1434
+ pub fn sign_justice_tx ( & self , justice_tx : Transaction , input_idx : usize , value : u64 , commitment_number : u64 ) -> Result < Transaction , ( ) > {
1435
+ self . inner . lock ( ) . unwrap ( ) . sign_justice_tx ( justice_tx, input_idx, value, commitment_number)
1436
+ }
1437
+
1430
1438
pub ( crate ) fn get_min_seen_secret ( & self ) -> u64 {
1431
1439
self . inner . lock ( ) . unwrap ( ) . get_min_seen_secret ( )
1432
1440
}
@@ -2766,6 +2774,31 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2766
2774
} ) . collect ( )
2767
2775
}
2768
2776
2777
+ pub ( crate ) fn sign_justice_tx ( & self , mut justice_tx : Transaction , input_idx : usize , value : u64 , commitment_number : u64 ) -> Result < Transaction , ( ) > {
2778
+
2779
+ let secret = self . get_secret ( commitment_number) . ok_or ( ( ) ) ?;
2780
+ let per_commitment_key = SecretKey :: from_slice ( & secret) . map_err ( |_| ( ) ) ?;
2781
+ let their_per_commitment_point = PublicKey :: from_secret_key (
2782
+ & self . onchain_tx_handler . secp_ctx , & per_commitment_key) ;
2783
+
2784
+ let revocation_pubkey = chan_utils:: derive_public_revocation_key (
2785
+ & self . onchain_tx_handler . secp_ctx , & their_per_commitment_point,
2786
+ & self . holder_revocation_basepoint ) ;
2787
+ let delayed_key = chan_utils:: derive_public_key ( & self . onchain_tx_handler . secp_ctx ,
2788
+ & their_per_commitment_point,
2789
+ & self . counterparty_commitment_params . counterparty_delayed_payment_base_key ) ;
2790
+ let revokeable_redeemscript = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey,
2791
+ self . counterparty_commitment_params . on_counterparty_tx_csv , & delayed_key) ;
2792
+
2793
+ let sig = self . onchain_tx_handler . signer . sign_justice_revoked_output ( & justice_tx, input_idx, value, & per_commitment_key, & self . onchain_tx_handler . secp_ctx ) ?;
2794
+ let mut ser_sig = sig. serialize_der ( ) . to_vec ( ) ;
2795
+ ser_sig. push ( EcdsaSighashType :: All as u8 ) ;
2796
+ justice_tx. input [ input_idx] . witness . push ( ser_sig) ;
2797
+ justice_tx. input [ input_idx] . witness . push ( vec ! ( 1 ) ) ;
2798
+ justice_tx. input [ input_idx] . witness . push ( revokeable_redeemscript. clone ( ) . into_bytes ( ) ) ;
2799
+ Ok ( justice_tx)
2800
+ }
2801
+
2769
2802
/// Can only fail if idx is < get_min_seen_secret
2770
2803
fn get_secret ( & self , idx : u64 ) -> Option < [ u8 ; 32 ] > {
2771
2804
self . commitment_secrets . get_secret ( idx)
0 commit comments