@@ -766,15 +766,14 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
766
766
767
767
fn get_commitment_transaction_number_obscure_factor ( & self ) -> u64 {
768
768
let mut sha = Sha256 :: engine ( ) ;
769
- let our_payment_point = PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . payment_key ( ) ) ;
770
769
771
770
let their_payment_point = & self . their_pubkeys . as_ref ( ) . unwrap ( ) . payment_point . serialize ( ) ;
772
771
if self . channel_outbound {
773
- sha. input ( & our_payment_point . serialize ( ) ) ;
772
+ sha. input ( & self . local_keys . pubkeys ( ) . payment_point . serialize ( ) ) ;
774
773
sha. input ( their_payment_point) ;
775
774
} else {
776
775
sha. input ( their_payment_point) ;
777
- sha. input ( & our_payment_point . serialize ( ) ) ;
776
+ sha. input ( & self . local_keys . pubkeys ( ) . payment_point . serialize ( ) ) ;
778
777
}
779
778
let res = Sha256 :: from_engine ( sha) . into_inner ( ) ;
780
779
@@ -1095,11 +1094,11 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1095
1094
/// TODO Some magic rust shit to compile-time check this?
1096
1095
fn build_local_transaction_keys ( & self , commitment_number : u64 ) -> Result < TxCreationKeys , ChannelError > {
1097
1096
let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & self . build_local_commitment_secret ( commitment_number) ) ;
1098
- let delayed_payment_base = PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . delayed_payment_base_key ( ) ) ;
1099
- let htlc_basepoint = PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . htlc_base_key ( ) ) ;
1097
+ let delayed_payment_base = & self . local_keys . pubkeys ( ) . delayed_payment_basepoint ;
1098
+ let htlc_basepoint = & self . local_keys . pubkeys ( ) . htlc_basepoint ;
1100
1099
let their_pubkeys = self . their_pubkeys . as_ref ( ) . unwrap ( ) ;
1101
1100
1102
- Ok ( secp_check ! ( TxCreationKeys :: new( & self . secp_ctx, & per_commitment_point, & delayed_payment_base, & htlc_basepoint, & their_pubkeys. revocation_basepoint, & their_pubkeys. htlc_basepoint) , "Local tx keys generation got bogus keys" ) )
1101
+ Ok ( secp_check ! ( TxCreationKeys :: new( & self . secp_ctx, & per_commitment_point, delayed_payment_base, htlc_basepoint, & their_pubkeys. revocation_basepoint, & their_pubkeys. htlc_basepoint) , "Local tx keys generation got bogus keys" ) )
1103
1102
}
1104
1103
1105
1104
#[ inline]
@@ -1109,19 +1108,18 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1109
1108
fn build_remote_transaction_keys ( & self ) -> Result < TxCreationKeys , ChannelError > {
1110
1109
//TODO: Ensure that the payment_key derived here ends up in the library users' wallet as we
1111
1110
//may see payments to it!
1112
- let revocation_basepoint = PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . revocation_base_key ( ) ) ;
1113
- let htlc_basepoint = PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . htlc_base_key ( ) ) ;
1111
+ let revocation_basepoint = & self . local_keys . pubkeys ( ) . revocation_basepoint ;
1112
+ let htlc_basepoint = & self . local_keys . pubkeys ( ) . htlc_basepoint ;
1114
1113
let their_pubkeys = self . their_pubkeys . as_ref ( ) . unwrap ( ) ;
1115
1114
1116
- Ok ( secp_check ! ( TxCreationKeys :: new( & self . secp_ctx, & self . their_cur_commitment_point. unwrap( ) , & their_pubkeys. delayed_payment_basepoint, & their_pubkeys. htlc_basepoint, & revocation_basepoint, & htlc_basepoint) , "Remote tx keys generation got bogus keys" ) )
1115
+ Ok ( secp_check ! ( TxCreationKeys :: new( & self . secp_ctx, & self . their_cur_commitment_point. unwrap( ) , & their_pubkeys. delayed_payment_basepoint, & their_pubkeys. htlc_basepoint, revocation_basepoint, htlc_basepoint) , "Remote tx keys generation got bogus keys" ) )
1117
1116
}
1118
1117
1119
1118
/// Gets the redeemscript for the funding transaction output (ie the funding transaction output
1120
1119
/// pays to get_funding_redeemscript().to_v0_p2wsh()).
1121
1120
/// Panics if called before accept_channel/new_from_req
1122
1121
pub fn get_funding_redeemscript ( & self ) -> Script {
1123
- let our_funding_key = PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . funding_key ( ) ) ;
1124
- make_funding_redeemscript ( & our_funding_key, self . their_funding_pubkey ( ) )
1122
+ make_funding_redeemscript ( & self . local_keys . pubkeys ( ) . funding_pubkey , self . their_funding_pubkey ( ) )
1125
1123
}
1126
1124
1127
1125
/// Builds the htlc-success or htlc-timeout transaction which spends a given HTLC output
@@ -1455,7 +1453,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1455
1453
log_trace ! ( logger, "Checking funding_created tx signature {} by key {} against tx {} (sighash {}) with redeemscript {}" , log_bytes!( sig. serialize_compact( ) [ ..] ) , log_bytes!( self . their_funding_pubkey( ) . serialize( ) ) , encode:: serialize_hex( & local_initial_commitment_tx) , log_bytes!( local_sighash[ ..] ) , encode:: serialize_hex( & funding_script) ) ;
1456
1454
secp_check ! ( self . secp_ctx. verify( & local_sighash, & sig, self . their_funding_pubkey( ) ) , "Invalid funding_created signature from peer" ) ;
1457
1455
1458
- let localtx = LocalCommitmentTransaction :: new_missing_local_sig ( local_initial_commitment_tx, sig. clone ( ) , & PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . funding_key ( ) ) , self . their_funding_pubkey ( ) , local_keys, self . feerate_per_kw , Vec :: new ( ) ) ;
1456
+ let localtx = LocalCommitmentTransaction :: new_missing_local_sig ( local_initial_commitment_tx, sig. clone ( ) , & self . local_keys . pubkeys ( ) . funding_pubkey , self . their_funding_pubkey ( ) , local_keys, self . feerate_per_kw , Vec :: new ( ) ) ;
1459
1457
1460
1458
let remote_keys = self . build_remote_transaction_keys ( ) ?;
1461
1459
let remote_initial_commitment_tx = self . build_commitment_transaction ( self . cur_remote_commitment_transaction_number , & remote_keys, false , false , self . feerate_per_kw , logger) . 0 ;
@@ -1568,7 +1566,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1568
1566
let funding_txo_script = funding_redeemscript. to_v0_p2wsh ( ) ;
1569
1567
macro_rules! create_monitor {
1570
1568
( ) => { {
1571
- let local_commitment_tx = LocalCommitmentTransaction :: new_missing_local_sig( local_initial_commitment_tx. clone( ) , msg. signature. clone( ) , & PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys. funding_key ( ) ) , their_funding_pubkey, local_keys. clone( ) , self . feerate_per_kw, Vec :: new( ) ) ;
1569
+ let local_commitment_tx = LocalCommitmentTransaction :: new_missing_local_sig( local_initial_commitment_tx. clone( ) , msg. signature. clone( ) , & self . local_keys. pubkeys ( ) . funding_pubkey , their_funding_pubkey, local_keys. clone( ) , self . feerate_per_kw, Vec :: new( ) ) ;
1572
1570
let mut channel_monitor = ChannelMonitor :: new( self . local_keys. clone( ) ,
1573
1571
& self . shutdown_pubkey, self . our_to_self_delay,
1574
1572
& self . destination_script, ( funding_txo. clone( ) , funding_txo_script. clone( ) ) ,
@@ -1899,7 +1897,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1899
1897
let mut monitor_update = ChannelMonitorUpdate {
1900
1898
update_id : self . latest_monitor_update_id ,
1901
1899
updates : vec ! [ ChannelMonitorUpdateStep :: LatestLocalCommitmentTXInfo {
1902
- commitment_tx: LocalCommitmentTransaction :: new_missing_local_sig( local_commitment_tx. 0 , msg. signature. clone( ) , & PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys. funding_key ( ) ) , & their_funding_pubkey, local_keys, self . feerate_per_kw, htlcs_without_source) ,
1900
+ commitment_tx: LocalCommitmentTransaction :: new_missing_local_sig( local_commitment_tx. 0 , msg. signature. clone( ) , & self . local_keys. pubkeys ( ) . funding_pubkey , & their_funding_pubkey, local_keys, self . feerate_per_kw, htlcs_without_source) ,
1903
1901
htlc_outputs: htlcs_and_sigs
1904
1902
} ]
1905
1903
} ;
@@ -2825,7 +2823,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2825
2823
2826
2824
tx. input [ 0 ] . witness . push ( Vec :: new ( ) ) ; // First is the multisig dummy
2827
2825
2828
- let our_funding_key = PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . funding_key ( ) ) . serialize ( ) ;
2826
+ let our_funding_key = self . local_keys . pubkeys ( ) . funding_pubkey . serialize ( ) ;
2829
2827
let their_funding_key = self . their_funding_pubkey ( ) . serialize ( ) ;
2830
2828
if our_funding_key[ ..] < their_funding_key[ ..] {
2831
2829
tx. input [ 0 ] . witness . push ( our_sig. serialize_der ( ) . to_vec ( ) ) ;
@@ -3302,6 +3300,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3302
3300
}
3303
3301
3304
3302
let local_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
3303
+ let local_keys = self . local_keys . pubkeys ( ) ;
3305
3304
3306
3305
msgs:: OpenChannel {
3307
3306
chain_hash : chain_hash,
@@ -3315,11 +3314,11 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3315
3314
feerate_per_kw : fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) as u32 ,
3316
3315
to_self_delay : self . our_to_self_delay ,
3317
3316
max_accepted_htlcs : OUR_MAX_HTLCS ,
3318
- funding_pubkey : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . funding_key ( ) ) ,
3319
- revocation_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . revocation_base_key ( ) ) ,
3320
- payment_point : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . payment_key ( ) ) ,
3321
- delayed_payment_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . delayed_payment_base_key ( ) ) ,
3322
- htlc_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . htlc_base_key ( ) ) ,
3317
+ funding_pubkey : local_keys. funding_pubkey ,
3318
+ revocation_basepoint : local_keys. revocation_basepoint ,
3319
+ payment_point : local_keys. payment_point ,
3320
+ delayed_payment_basepoint : local_keys. delayed_payment_basepoint ,
3321
+ htlc_basepoint : local_keys. htlc_basepoint ,
3323
3322
first_per_commitment_point : PublicKey :: from_secret_key ( & self . secp_ctx , & local_commitment_secret) ,
3324
3323
channel_flags : if self . config . announced_channel { 1 } else { 0 } ,
3325
3324
shutdown_scriptpubkey : OptionalField :: Present ( if self . config . commit_upfront_shutdown_pubkey { self . get_closing_scriptpubkey ( ) } else { Builder :: new ( ) . into_script ( ) } )
@@ -3338,6 +3337,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3338
3337
}
3339
3338
3340
3339
let local_commitment_secret = self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number ) ;
3340
+ let local_keys = self . local_keys . pubkeys ( ) ;
3341
3341
3342
3342
msgs:: AcceptChannel {
3343
3343
temporary_channel_id : self . channel_id ,
@@ -3348,11 +3348,11 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3348
3348
minimum_depth : self . minimum_depth ,
3349
3349
to_self_delay : self . our_to_self_delay ,
3350
3350
max_accepted_htlcs : OUR_MAX_HTLCS ,
3351
- funding_pubkey : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . funding_key ( ) ) ,
3352
- revocation_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . revocation_base_key ( ) ) ,
3353
- payment_point : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . payment_key ( ) ) ,
3354
- delayed_payment_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . delayed_payment_base_key ( ) ) ,
3355
- htlc_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . htlc_base_key ( ) ) ,
3351
+ funding_pubkey : local_keys. funding_pubkey ,
3352
+ revocation_basepoint : local_keys. revocation_basepoint ,
3353
+ payment_point : local_keys. payment_point ,
3354
+ delayed_payment_basepoint : local_keys. delayed_payment_basepoint ,
3355
+ htlc_basepoint : local_keys. htlc_basepoint ,
3356
3356
first_per_commitment_point : PublicKey :: from_secret_key ( & self . secp_ctx , & local_commitment_secret) ,
3357
3357
shutdown_scriptpubkey : OptionalField :: Present ( if self . config . commit_upfront_shutdown_pubkey { self . get_closing_scriptpubkey ( ) } else { Builder :: new ( ) . into_script ( ) } )
3358
3358
}
@@ -3431,16 +3431,15 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
3431
3431
}
3432
3432
3433
3433
let were_node_one = our_node_id. serialize ( ) [ ..] < self . their_node_id . serialize ( ) [ ..] ;
3434
- let our_bitcoin_key = PublicKey :: from_secret_key ( & self . secp_ctx , self . local_keys . funding_key ( ) ) ;
3435
3434
3436
3435
let msg = msgs:: UnsignedChannelAnnouncement {
3437
3436
features : ChannelFeatures :: known ( ) ,
3438
3437
chain_hash : chain_hash,
3439
3438
short_channel_id : self . get_short_channel_id ( ) . unwrap ( ) ,
3440
3439
node_id_1 : if were_node_one { our_node_id } else { self . get_their_node_id ( ) } ,
3441
3440
node_id_2 : if were_node_one { self . get_their_node_id ( ) } else { our_node_id } ,
3442
- bitcoin_key_1 : if were_node_one { our_bitcoin_key } else { self . their_funding_pubkey ( ) . clone ( ) } ,
3443
- bitcoin_key_2 : if were_node_one { self . their_funding_pubkey ( ) . clone ( ) } else { our_bitcoin_key } ,
3441
+ bitcoin_key_1 : if were_node_one { self . local_keys . pubkeys ( ) . funding_pubkey } else { self . their_funding_pubkey ( ) . clone ( ) } ,
3442
+ bitcoin_key_2 : if were_node_one { self . their_funding_pubkey ( ) . clone ( ) } else { self . local_keys . pubkeys ( ) . funding_pubkey } ,
3444
3443
excess_data : Vec :: new ( ) ,
3445
3444
} ;
3446
3445
@@ -4442,7 +4441,7 @@ mod tests {
4442
4441
( 0 , 0 )
4443
4442
) ;
4444
4443
4445
- assert_eq ! ( PublicKey :: from_secret_key ( & secp_ctx , chan_keys. funding_key ( ) ) . serialize( ) [ ..] ,
4444
+ assert_eq ! ( chan_keys. pubkeys ( ) . funding_pubkey . serialize( ) [ ..] ,
4446
4445
hex:: decode( "023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb" ) . unwrap( ) [ ..] ) ;
4447
4446
let keys_provider = Keys { chan_keys : chan_keys. clone ( ) } ;
4448
4447
@@ -4477,11 +4476,11 @@ mod tests {
4477
4476
// We can't just use build_local_transaction_keys here as the per_commitment_secret is not
4478
4477
// derived from a commitment_seed, so instead we copy it here and call
4479
4478
// build_commitment_transaction.
4480
- let delayed_payment_base = PublicKey :: from_secret_key ( & secp_ctx , chan. local_keys . delayed_payment_base_key ( ) ) ;
4479
+ let delayed_payment_base = & chan. local_keys . pubkeys ( ) . delayed_payment_basepoint ;
4481
4480
let per_commitment_secret = SecretKey :: from_slice ( & hex:: decode ( "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100" ) . unwrap ( ) [ ..] ) . unwrap ( ) ;
4482
4481
let per_commitment_point = PublicKey :: from_secret_key ( & secp_ctx, & per_commitment_secret) ;
4483
- let htlc_basepoint = PublicKey :: from_secret_key ( & secp_ctx , chan. local_keys . htlc_base_key ( ) ) ;
4484
- let keys = TxCreationKeys :: new ( & secp_ctx, & per_commitment_point, & delayed_payment_base, & htlc_basepoint, & their_pubkeys. revocation_basepoint , & their_pubkeys. htlc_basepoint ) . unwrap ( ) ;
4482
+ let htlc_basepoint = & chan. local_keys . pubkeys ( ) . htlc_basepoint ;
4483
+ let keys = TxCreationKeys :: new ( & secp_ctx, & per_commitment_point, delayed_payment_base, htlc_basepoint, & their_pubkeys. revocation_basepoint , & their_pubkeys. htlc_basepoint ) . unwrap ( ) ;
4485
4484
4486
4485
chan. their_pubkeys = Some ( their_pubkeys) ;
4487
4486
@@ -4512,7 +4511,7 @@ mod tests {
4512
4511
} ) *
4513
4512
assert_eq!( unsigned_tx. 1 . len( ) , per_htlc. len( ) ) ;
4514
4513
4515
- localtx = LocalCommitmentTransaction :: new_missing_local_sig( unsigned_tx. 0 . clone( ) , their_signature. clone( ) , & PublicKey :: from_secret_key ( & secp_ctx , chan . local_keys . funding_key ( ) ) , chan. their_funding_pubkey( ) , keys. clone( ) , chan. feerate_per_kw, per_htlc) ;
4514
+ localtx = LocalCommitmentTransaction :: new_missing_local_sig( unsigned_tx. 0 . clone( ) , their_signature. clone( ) , & chan_keys . pubkeys ( ) . funding_pubkey , chan. their_funding_pubkey( ) , keys. clone( ) , chan. feerate_per_kw, per_htlc) ;
4516
4515
let local_sig = chan_keys. sign_local_commitment( & localtx, & chan. secp_ctx) . unwrap( ) ;
4517
4516
assert_eq!( Signature :: from_der( & hex:: decode( $our_sig_hex) . unwrap( ) [ ..] ) . unwrap( ) , local_sig) ;
4518
4517
0 commit comments