@@ -35,8 +35,8 @@ use bitcoin::{secp256k1, EcdsaSighashType};
3535use  crate :: ln:: channel:: INITIAL_COMMITMENT_NUMBER ; 
3636use  crate :: ln:: { PaymentHash ,  PaymentPreimage } ; 
3737use  crate :: ln:: msgs:: DecodeError ; 
38- use  crate :: ln:: chan_utils ; 
39- use  crate :: ln:: chan_utils:: { CommitmentTransaction ,  CounterpartyCommitmentSecrets ,  HTLCOutputInCommitment ,  HTLCClaim ,  ChannelTransactionParameters ,  HolderCommitmentTransaction ,  TxCreationKeys } ; 
38+ use  crate :: ln:: channel_keys :: { DelayedPaymentKey ,   DelayedPaymentBasepoint ,   HtlcBasepoint ,   HtlcKey ,   RevocationKey ,   RevocationBasepoint } ; 
39+ use  crate :: ln:: chan_utils:: { self , CommitmentTransaction ,  CounterpartyCommitmentSecrets ,  HTLCOutputInCommitment ,  HTLCClaim ,  ChannelTransactionParameters ,  HolderCommitmentTransaction ,  TxCreationKeys } ; 
4040use  crate :: ln:: channelmanager:: { HTLCSource ,  SentHTLCId } ; 
4141use  crate :: chain; 
4242use  crate :: chain:: { BestBlock ,  WatchedOutput } ; 
@@ -237,10 +237,10 @@ pub(crate) const HTLC_FAIL_BACK_BUFFER: u32 = CLTV_CLAIM_BUFFER + LATENCY_GRACE_
237237struct  HolderSignedTx  { 
238238	/// txid of the transaction in tx, just used to make comparison faster 
239239txid :  Txid , 
240- 	revocation_key :  PublicKey , 
241- 	a_htlc_key :  PublicKey , 
242- 	b_htlc_key :  PublicKey , 
243- 	delayed_payment_key :  PublicKey , 
240+ 	revocation_key :  RevocationKey , 
241+ 	a_htlc_key :  HtlcKey , 
242+ 	b_htlc_key :  HtlcKey , 
243+ 	delayed_payment_key :  DelayedPaymentKey , 
244244	per_commitment_point :  PublicKey , 
245245	htlc_outputs :  Vec < ( HTLCOutputInCommitment ,  Option < Signature > ,  Option < HTLCSource > ) > , 
246246	to_self_value_sat :  u64 , 
@@ -277,8 +277,8 @@ impl HolderSignedTx {
277277/// justice or 2nd-stage preimage/timeout transactions. 
278278#[ derive( Clone ,  PartialEq ,  Eq ) ]  
279279struct  CounterpartyCommitmentParameters  { 
280- 	counterparty_delayed_payment_base_key :  PublicKey , 
281- 	counterparty_htlc_base_key :  PublicKey , 
280+ 	counterparty_delayed_payment_base_key :  DelayedPaymentBasepoint , 
281+ 	counterparty_htlc_base_key :  HtlcBasepoint , 
282282	on_counterparty_tx_csv :  u16 , 
283283} 
284284
@@ -751,12 +751,12 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
751751	commitment_transaction_number_obscure_factor :  u64 , 
752752
753753	destination_script :  Script , 
754- 	broadcasted_holder_revokable_script :  Option < ( Script ,  PublicKey ,  PublicKey ) > , 
754+ 	broadcasted_holder_revokable_script :  Option < ( Script ,  PublicKey ,  RevocationKey ) > , 
755755	counterparty_payment_script :  Script , 
756756	shutdown_script :  Option < Script > , 
757757
758758	channel_keys_id :  [ u8 ;  32 ] , 
759- 	holder_revocation_basepoint :  PublicKey , 
759+ 	holder_revocation_basepoint :  RevocationBasepoint , 
760760	funding_info :  ( OutPoint ,  Script ) , 
761761	current_counterparty_commitment_txid :  Option < Txid > , 
762762	prev_counterparty_commitment_txid :  Option < Txid > , 
@@ -2923,12 +2923,13 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29232923		let  their_per_commitment_point = PublicKey :: from_secret_key ( 
29242924			& self . onchain_tx_handler . secp_ctx ,  & per_commitment_key) ; 
29252925
2926- 		let  revocation_pubkey = chan_utils:: derive_public_revocation_key ( 
2927- 			& self . onchain_tx_handler . secp_ctx ,  & their_per_commitment_point, 
2928- 			& self . holder_revocation_basepoint ) ; 
2929- 		let  delayed_key = chan_utils:: derive_public_key ( & self . onchain_tx_handler . secp_ctx , 
2930- 			& their_per_commitment_point, 
2931- 			& self . counterparty_commitment_params . counterparty_delayed_payment_base_key ) ; 
2926+ 		let  revocation_pubkey = RevocationKey :: from_basepoint ( & self . onchain_tx_handler . secp_ctx , 
2927+ 			& RevocationBasepoint :: from ( self . holder_revocation_basepoint ) , 
2928+ 			& their_per_commitment_point) ; 
2929+ 		let  delayed_payment_basepoint = DelayedPaymentBasepoint :: from ( self . counterparty_commitment_params . counterparty_delayed_payment_base_key ) ; 
2930+ 		let  delayed_key = DelayedPaymentKey :: from_basepoint ( & self . onchain_tx_handler . secp_ctx , 
2931+ 			& delayed_payment_basepoint, 
2932+ 			& their_per_commitment_point) ; 
29322933		let  revokeable_redeemscript = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey, 
29332934			self . counterparty_commitment_params . on_counterparty_tx_csv ,  & delayed_key) ; 
29342935
@@ -2991,8 +2992,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29912992			let  secret = self . get_secret ( commitment_number) . unwrap ( ) ; 
29922993			let  per_commitment_key = ignore_error ! ( SecretKey :: from_slice( & secret) ) ; 
29932994			let  per_commitment_point = PublicKey :: from_secret_key ( & self . onchain_tx_handler . secp_ctx ,  & per_commitment_key) ; 
2994- 			let  revocation_pubkey = chan_utils :: derive_public_revocation_key ( & self . onchain_tx_handler . secp_ctx ,  & per_commitment_point ,  & self . holder_revocation_basepoint ) ; 
2995- 			let  delayed_key = chan_utils :: derive_public_key ( & self . onchain_tx_handler . secp_ctx ,  & PublicKey :: from_secret_key ( & self . onchain_tx_handler . secp_ctx ,  & per_commitment_key) ,   & self . counterparty_commitment_params . counterparty_delayed_payment_base_key ) ; 
2995+ 			let  revocation_pubkey = RevocationKey :: from_basepoint ( & self . onchain_tx_handler . secp_ctx ,   & self . holder_revocation_basepoint ,   & per_commitment_point , ) ; 
2996+ 			let  delayed_key = DelayedPaymentKey :: from_basepoint ( & self . onchain_tx_handler . secp_ctx ,  & self . counterparty_commitment_params . counterparty_delayed_payment_base_key ,   & PublicKey :: from_secret_key ( & self . onchain_tx_handler . secp_ctx ,  & per_commitment_key) ) ; 
29962997
29972998			let  revokeable_redeemscript = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey,  self . counterparty_commitment_params . on_counterparty_tx_csv ,  & delayed_key) ; 
29982999			let  revokeable_p2wsh = revokeable_redeemscript. to_v0_p2wsh ( ) ; 
@@ -3104,11 +3105,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31043105			}  else  {  return  ( claimable_outpoints,  to_counterparty_output_info) ;  } ; 
31053106
31063107		if  let  Some ( transaction)  = tx { 
3107- 			let  revocation_pubkey = chan_utils :: derive_public_revocation_key ( 
3108- 				& self . onchain_tx_handler . secp_ctx ,  & per_commitment_point ,  & self . holder_revocation_basepoint ) ; 
3109- 			let  delayed_key = chan_utils :: derive_public_key ( & self . onchain_tx_handler . secp_ctx , 
3110- 				 & per_commitment_point , 
3111- 				 & self . counterparty_commitment_params . counterparty_delayed_payment_base_key ) ; 
3108+ 			let  revocation_pubkey = RevocationKey :: from_basepoint ( 
3109+ 				& self . onchain_tx_handler . secp_ctx ,   & self . holder_revocation_basepoint ,   & per_commitment_point ) ; 
3110+ 			
3111+ 			let  delayed_key =  DelayedPaymentKey :: from_basepoint ( & self . onchain_tx_handler . secp_ctx ,   & self . counterparty_commitment_params . counterparty_delayed_payment_base_key ,   & per_commitment_point ) ; 
3112+ 
31123113			let  revokeable_p2wsh = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey, 
31133114				self . counterparty_commitment_params . on_counterparty_tx_csv , 
31143115				& delayed_key) . to_v0_p2wsh ( ) ; 
@@ -3203,7 +3204,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32033204	// Returns (1) `PackageTemplate`s that can be given to the OnchainTxHandler, so that the handler can 
32043205	// broadcast transactions claiming holder HTLC commitment outputs and (2) a holder revokable 
32053206	// script so we can detect whether a holder transaction has been seen on-chain. 
3206- 	fn  get_broadcasted_holder_claims ( & self ,  holder_tx :  & HolderSignedTx ,  conf_height :  u32 )  -> ( Vec < PackageTemplate > ,  Option < ( Script ,  PublicKey ,  PublicKey ) > )  { 
3207+ 	fn  get_broadcasted_holder_claims ( & self ,  holder_tx :  & HolderSignedTx ,  conf_height :  u32 )  -> ( Vec < PackageTemplate > ,  Option < ( Script ,  PublicKey ,  RevocationKey ) > )  { 
32073208		let  mut  claim_requests = Vec :: with_capacity ( holder_tx. htlc_outputs . len ( ) ) ; 
32083209
32093210		let  redeemscript = chan_utils:: get_revokeable_redeemscript ( & holder_tx. revocation_key ,  self . on_holder_tx_csv ,  & holder_tx. delayed_payment_key ) ; 
@@ -4092,7 +4093,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40924093						per_commitment_point :  broadcasted_holder_revokable_script. 1 , 
40934094						to_self_delay :  self . on_holder_tx_csv , 
40944095						output :  outp. clone ( ) , 
4095- 						revocation_pubkey :  broadcasted_holder_revokable_script. 2 . clone ( ) , 
4096+ 						revocation_pubkey :  broadcasted_holder_revokable_script. 2 , 
40964097						channel_keys_id :  self . channel_keys_id , 
40974098						channel_value_satoshis :  self . channel_value_satoshis , 
40984099					} ) ) ; 
@@ -4504,8 +4505,8 @@ mod tests {
45044505	use  crate :: chain:: transaction:: OutPoint ; 
45054506	use  crate :: sign:: InMemorySigner ; 
45064507	use  crate :: ln:: { PaymentPreimage ,  PaymentHash } ; 
4507- 	use  crate :: ln:: chan_utils ; 
4508- 	use  crate :: ln:: chan_utils:: { HTLCOutputInCommitment ,  ChannelPublicKeys ,  ChannelTransactionParameters ,  HolderCommitmentTransaction ,  CounterpartyChannelTransactionParameters } ; 
4508+ 	use  crate :: ln:: channel_keys :: { DelayedPaymentBasepoint ,   DelayedPaymentKey ,   HtlcBasepoint ,   RevocationBasepoint ,   RevocationKey } ; 
4509+ 	use  crate :: ln:: chan_utils:: { self , HTLCOutputInCommitment ,  ChannelPublicKeys ,  ChannelTransactionParameters ,  HolderCommitmentTransaction ,  CounterpartyChannelTransactionParameters } ; 
45094510	use  crate :: ln:: channelmanager:: { PaymentSendFailure ,  PaymentId ,  RecipientOnionFields } ; 
45104511	use  crate :: ln:: functional_test_utils:: * ; 
45114512	use  crate :: ln:: script:: ShutdownScript ; 
@@ -4671,10 +4672,10 @@ mod tests {
46714672
46724673		let  counterparty_pubkeys = ChannelPublicKeys  { 
46734674			funding_pubkey :  PublicKey :: from_secret_key ( & secp_ctx,  & SecretKey :: from_slice ( & [ 44 ;  32 ] ) . unwrap ( ) ) , 
4674- 			revocation_basepoint :  PublicKey :: from_secret_key ( & secp_ctx,  & SecretKey :: from_slice ( & [ 45 ;  32 ] ) . unwrap ( ) ) , 
4675+ 			revocation_basepoint :  RevocationBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx,  & SecretKey :: from_slice ( & [ 45 ;  32 ] ) . unwrap ( ) ) ) , 
46754676			payment_point :  PublicKey :: from_secret_key ( & secp_ctx,  & SecretKey :: from_slice ( & [ 46 ;  32 ] ) . unwrap ( ) ) , 
4676- 			delayed_payment_basepoint :  PublicKey :: from_secret_key ( & secp_ctx,  & SecretKey :: from_slice ( & [ 47 ;  32 ] ) . unwrap ( ) ) , 
4677- 			htlc_basepoint :  PublicKey :: from_secret_key ( & secp_ctx,  & SecretKey :: from_slice ( & [ 48 ;  32 ] ) . unwrap ( ) ) 
4677+ 			delayed_payment_basepoint :  DelayedPaymentBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx,  & SecretKey :: from_slice ( & [ 47 ;  32 ] ) . unwrap ( ) ) ) , 
4678+ 			htlc_basepoint :  HtlcBasepoint :: from ( PublicKey :: from_secret_key ( & secp_ctx,  & SecretKey :: from_slice ( & [ 48 ;  32 ] ) . unwrap ( ) ) ) 
46784679		} ; 
46794680		let  funding_outpoint = OutPoint  {  txid :  Txid :: all_zeros ( ) ,  index :  u16:: max_value ( )  } ; 
46804681		let  channel_parameters = ChannelTransactionParameters  { 
@@ -4764,6 +4765,7 @@ mod tests {
47644765		let  privkey = SecretKey :: from_slice ( & hex:: decode ( "0101010101010101010101010101010101010101010101010101010101010101" ) . unwrap ( ) [ ..] ) . unwrap ( ) ; 
47654766		let  pubkey = PublicKey :: from_secret_key ( & secp_ctx,  & privkey) ; 
47664767
4768+ 		use  crate :: ln:: channel_keys:: { HtlcKey ,  HtlcBasepoint } ; 
47674769		macro_rules!  sign_input { 
47684770			( $sighash_parts:  expr,  $idx:  expr,  $amount:  expr,  $weight:  expr,  $sum_actual_sigs:  expr,  $opt_anchors:  expr)  => { 
47694771				let  htlc = HTLCOutputInCommitment  { 
@@ -4773,7 +4775,7 @@ mod tests {
47734775					payment_hash:  PaymentHash ( [ 1 ;  32 ] ) , 
47744776					transaction_output_index:  Some ( $idx as  u32 ) , 
47754777				} ; 
4776- 				let  redeem_script = if  * $weight == WEIGHT_REVOKED_OUTPUT  {  chan_utils:: get_revokeable_redeemscript( & pubkey,   256 ,  & pubkey)   }  else {  chan_utils:: get_htlc_redeemscript_with_explicit_keys( & htlc,  $opt_anchors,  & pubkey,  & pubkey,  & pubkey)  } ; 
4778+ 				let  redeem_script = if  * $weight == WEIGHT_REVOKED_OUTPUT  {  chan_utils:: get_revokeable_redeemscript( & RevocationKey :: from_basepoint ( & secp_ctx ,   & RevocationBasepoint :: from ( pubkey) ,   & pubkey ) ,   256 ,  & DelayedPaymentKey :: from_basepoint ( & secp_ctx ,   & DelayedPaymentBasepoint :: from ( pubkey) ,   & pubkey ) )   }  else {  chan_utils:: get_htlc_redeemscript_with_explicit_keys( & htlc,  $opt_anchors,  & HtlcKey :: from_basepoint ( & secp_ctx ,   & HtlcBasepoint :: from ( pubkey) ,  & pubkey) ,  & HtlcKey :: from_basepoint ( & secp_ctx ,   & HtlcBasepoint :: from ( pubkey) ,   & pubkey ) ,   & RevocationKey :: from_basepoint ( & secp_ctx ,   & RevocationBasepoint :: from ( pubkey ) ,   & pubkey ) )  } ; 
47774779				let  sighash = hash_to_message!( & $sighash_parts. segwit_signature_hash( $idx,  & redeem_script,  $amount,  EcdsaSighashType :: All ) . unwrap( ) [ ..] ) ; 
47784780				let  sig = secp_ctx. sign_ecdsa( & sighash,  & privkey) ; 
47794781				let  mut  ser_sig = sig. serialize_der( ) . to_vec( ) ; 
0 commit comments