@@ -19,6 +19,7 @@ use util::sha2::Sha256;
19
19
use util:: logger:: Logger ;
20
20
21
21
use std:: sync:: Arc ;
22
+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
22
23
23
24
/// When on-chain outputs are created by rust-lightning an event is generated which informs the
24
25
/// user thereof. This enum describes the format of the output and provides the OutPoint.
@@ -39,7 +40,7 @@ pub enum SpendableOutputDescriptor {
39
40
DynamicOutput {
40
41
/// Outpoint spendable by user wallet
41
42
outpoint : OutPoint ,
42
- /// local_delayedkey = delayed_payment_basepoint_secret + SHA256(per_commitment_point || delayed_payment_basepoint
43
+ /// local_delayedkey = delayed_payment_basepoint_secret + SHA256(per_commitment_point || delayed_payment_basepoint)
43
44
local_delayedkey : SecretKey ,
44
45
/// witness redeemScript encumbering output
45
46
witness_script : Script ,
@@ -137,6 +138,7 @@ pub struct KeysManager {
137
138
destination_script : Script ,
138
139
shutdown_pubkey : PublicKey ,
139
140
channel_master_key : ExtendedPrivKey ,
141
+ channel_child_index : AtomicUsize ,
140
142
141
143
logger : Arc < Logger > ,
142
144
}
@@ -169,6 +171,7 @@ impl KeysManager {
169
171
destination_script,
170
172
shutdown_pubkey,
171
173
channel_master_key,
174
+ channel_child_index : AtomicUsize :: new ( 0 ) ,
172
175
173
176
logger,
174
177
}
@@ -192,11 +195,11 @@ impl KeysInterface for KeysManager {
192
195
}
193
196
194
197
fn get_channel_keys ( & self , _inbound : bool ) -> ChannelKeys {
195
- let channel_pubkey = ExtendedPubKey :: from_private ( & self . secp_ctx , & self . channel_master_key ) ;
196
- let mut seed = [ 0 ; 32 ] ;
197
- for ( arr , slice ) in seed . iter_mut ( ) . zip ( ( & channel_pubkey . public_key . serialize ( ) [ 0 .. 32 ] ) . iter ( ) ) {
198
- * arr = * slice ;
199
- }
198
+ let child_ix = self . channel_child_index . fetch_add ( 1 , Ordering :: SeqCst ) ;
199
+ let child_privkey = self . channel_master_key . ckd_priv ( & self . secp_ctx , ChildNumber :: from_hardened_idx ( child_ix as u32 ) ) . expect ( "Your RNG is busted" ) ;
200
+ let child_pubkey = ExtendedPubKey :: from_private ( & self . secp_ctx , & child_privkey ) ;
201
+ let mut seed = [ 0u8 ; 32 ] ;
202
+ seed . copy_from_slice ( & child_pubkey . public_key . serialize ( ) [ 1 .. 33 ] ) ;
200
203
ChannelKeys :: new_from_seed ( & seed)
201
204
}
202
205
}
0 commit comments