@@ -36,7 +36,7 @@ use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, chainmonitor, chan
36
36
use lightning:: chain:: channelmonitor:: { ChannelMonitor , MonitorEvent } ;
37
37
use lightning:: chain:: transaction:: OutPoint ;
38
38
use lightning:: chain:: chaininterface:: { BroadcasterInterface , ConfirmationTarget , FeeEstimator } ;
39
- use lightning:: chain:: keysinterface:: { KeyMaterial , KeysInterface , InMemorySigner , Recipient } ;
39
+ use lightning:: chain:: keysinterface:: { KeyMaterial , KeysInterface , InMemorySigner , Recipient , EntropySource , NodeSigner , SignerProvider } ;
40
40
use lightning:: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
41
41
use lightning:: ln:: channelmanager:: { self , ChainParameters , ChannelManager , PaymentSendFailure , ChannelManagerReadArgs , PaymentId } ;
42
42
use lightning:: ln:: channel:: FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE ;
@@ -160,38 +160,24 @@ struct KeyProvider {
160
160
rand_bytes_id : atomic:: AtomicU32 ,
161
161
enforcement_states : Mutex < HashMap < [ u8 ; 32 ] , Arc < Mutex < EnforcementState > > > > ,
162
162
}
163
- impl KeysInterface for KeyProvider {
164
- type Signer = EnforcingSigner ;
165
-
166
- fn get_node_secret ( & self , _recipient : Recipient ) -> Result < SecretKey , ( ) > {
167
- Ok ( SecretKey :: from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , self . node_id ] ) . unwrap ( ) )
168
- }
169
163
170
- fn ecdh ( & self , recipient : Recipient , other_key : & PublicKey , tweak : Option < & Scalar > ) -> Result < SharedSecret , ( ) > {
171
- let mut node_secret = self . get_node_secret ( recipient) ?;
172
- if let Some ( tweak) = tweak {
173
- node_secret = node_secret. mul_tweak ( tweak) . unwrap ( ) ;
174
- }
175
- Ok ( SharedSecret :: new ( other_key, & node_secret) )
176
- }
177
-
178
- fn get_inbound_payment_key_material ( & self ) -> KeyMaterial {
179
- KeyMaterial ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , self . node_id ] )
164
+ impl EntropySource for KeyProvider {
165
+ fn get_secure_random_bytes ( & self ) -> [ u8 ; 32 ] {
166
+ let id = self . rand_bytes_id . fetch_add ( 1 , atomic:: Ordering :: Relaxed ) ;
167
+ let mut res = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 11 , self . node_id ] ;
168
+ res[ 30 -4 ..30 ] . copy_from_slice ( & id. to_le_bytes ( ) ) ;
169
+ res
180
170
}
171
+ }
181
172
182
- fn get_destination_script ( & self ) -> Script {
183
- let secp_ctx = Secp256k1 :: signing_only ( ) ;
184
- let channel_monitor_claim_key = SecretKey :: from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , self . node_id ] ) . unwrap ( ) ;
185
- let our_channel_monitor_claim_key_hash = WPubkeyHash :: hash ( & PublicKey :: from_secret_key ( & secp_ctx, & channel_monitor_claim_key) . serialize ( ) ) ;
186
- Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & our_channel_monitor_claim_key_hash[ ..] ) . into_script ( )
173
+ impl NodeSigner for KeyProvider {
174
+ fn get_node_secret ( & self , _recipient : Recipient ) -> Result < SecretKey , ( ) > {
175
+ Ok ( SecretKey :: from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , self . node_id ] ) . unwrap ( ) )
187
176
}
177
+ }
188
178
189
- fn get_shutdown_scriptpubkey ( & self ) -> ShutdownScript {
190
- let secp_ctx = Secp256k1 :: signing_only ( ) ;
191
- let secret_key = SecretKey :: from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 , self . node_id ] ) . unwrap ( ) ;
192
- let pubkey_hash = WPubkeyHash :: hash ( & PublicKey :: from_secret_key ( & secp_ctx, & secret_key) . serialize ( ) ) ;
193
- ShutdownScript :: new_p2wpkh ( & pubkey_hash)
194
- }
179
+ impl SignerProvider for KeyProvider {
180
+ type Signer = EnforcingSigner ;
195
181
196
182
fn generate_channel_keys_id ( & self , _inbound : bool , _channel_value_satoshis : u64 , _user_channel_id : u128 ) -> [ u8 ; 32 ] {
197
183
let id = self . rand_bytes_id . fetch_add ( 1 , atomic:: Ordering :: Relaxed ) as u8 ;
@@ -217,13 +203,6 @@ impl KeysInterface for KeyProvider {
217
203
EnforcingSigner :: new_with_revoked ( keys, revoked_commitment, false )
218
204
}
219
205
220
- fn get_secure_random_bytes ( & self ) -> [ u8 ; 32 ] {
221
- let id = self . rand_bytes_id . fetch_add ( 1 , atomic:: Ordering :: Relaxed ) ;
222
- let mut res = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 11 , self . node_id ] ;
223
- res[ 30 -4 ..30 ] . copy_from_slice ( & id. to_le_bytes ( ) ) ;
224
- res
225
- }
226
-
227
206
fn read_chan_signer ( & self , buffer : & [ u8 ] ) -> Result < Self :: Signer , DecodeError > {
228
207
let mut reader = std:: io:: Cursor :: new ( buffer) ;
229
208
@@ -236,9 +215,25 @@ impl KeysInterface for KeyProvider {
236
215
disable_revocation_policy_check : false ,
237
216
} )
238
217
}
218
+ }
219
+
220
+ impl KeysInterface for KeyProvider {
221
+ fn get_inbound_payment_key_material ( & self ) -> KeyMaterial {
222
+ KeyMaterial ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , self . node_id ] )
223
+ }
224
+
225
+ fn get_destination_script ( & self ) -> Script {
226
+ let secp_ctx = Secp256k1 :: signing_only ( ) ;
227
+ let channel_monitor_claim_key = SecretKey :: from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , self . node_id ] ) . unwrap ( ) ;
228
+ let our_channel_monitor_claim_key_hash = WPubkeyHash :: hash ( & PublicKey :: from_secret_key ( & secp_ctx, & channel_monitor_claim_key) . serialize ( ) ) ;
229
+ Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & our_channel_monitor_claim_key_hash[ ..] ) . into_script ( )
230
+ }
239
231
240
- fn sign_invoice ( & self , _hrp_bytes : & [ u8 ] , _invoice_data : & [ u5 ] , _recipient : Recipient ) -> Result < RecoverableSignature , ( ) > {
241
- unreachable ! ( )
232
+ fn get_shutdown_scriptpubkey ( & self ) -> ShutdownScript {
233
+ let secp_ctx = Secp256k1 :: signing_only ( ) ;
234
+ let secret_key = SecretKey :: from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 , self . node_id ] ) . unwrap ( ) ;
235
+ let pubkey_hash = WPubkeyHash :: hash ( & PublicKey :: from_secret_key ( & secp_ctx, & secret_key) . serialize ( ) ) ;
236
+ ShutdownScript :: new_p2wpkh ( & pubkey_hash)
242
237
}
243
238
}
244
239
0 commit comments