@@ -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,13 +160,26 @@ 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
163
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
170
+ }
171
+ }
172
+
173
+ impl NodeSigner for KeyProvider {
166
174
fn get_node_secret ( & self , _recipient : Recipient ) -> Result < SecretKey , ( ) > {
167
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 ( ) )
168
176
}
169
177
178
+ fn get_node_id ( & self , recipient : Recipient ) -> Result < PublicKey , ( ) > {
179
+ let secp_ctx = Secp256k1 :: signing_only ( ) ;
180
+ Ok ( PublicKey :: from_secret_key ( & secp_ctx, & self . get_node_secret ( recipient) ?) )
181
+ }
182
+
170
183
fn ecdh ( & self , recipient : Recipient , other_key : & PublicKey , tweak : Option < & Scalar > ) -> Result < SharedSecret , ( ) > {
171
184
let mut node_secret = self . get_node_secret ( recipient) ?;
172
185
if let Some ( tweak) = tweak {
@@ -179,19 +192,13 @@ impl KeysInterface for KeyProvider {
179
192
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 ] )
180
193
}
181
194
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 ( )
195
+ fn sign_invoice ( & self , _hrp_bytes : & [ u8 ] , _invoice_data : & [ u5 ] , _recipient : Recipient ) -> Result < RecoverableSignature , ( ) > {
196
+ unreachable ! ( )
187
197
}
198
+ }
188
199
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
- }
200
+ impl SignerProvider for KeyProvider {
201
+ type Signer = EnforcingSigner ;
195
202
196
203
fn generate_channel_keys_id ( & self , _inbound : bool , _channel_value_satoshis : u64 , _user_channel_id : u128 ) -> [ u8 ; 32 ] {
197
204
let id = self . rand_bytes_id . fetch_add ( 1 , atomic:: Ordering :: Relaxed ) as u8 ;
@@ -217,13 +224,6 @@ impl KeysInterface for KeyProvider {
217
224
EnforcingSigner :: new_with_revoked ( keys, revoked_commitment, false )
218
225
}
219
226
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
227
fn read_chan_signer ( & self , buffer : & [ u8 ] ) -> Result < Self :: Signer , DecodeError > {
228
228
let mut reader = std:: io:: Cursor :: new ( buffer) ;
229
229
@@ -237,11 +237,23 @@ impl KeysInterface for KeyProvider {
237
237
} )
238
238
}
239
239
240
- fn sign_invoice ( & self , _hrp_bytes : & [ u8 ] , _invoice_data : & [ u5 ] , _recipient : Recipient ) -> Result < RecoverableSignature , ( ) > {
241
- unreachable ! ( )
240
+ fn get_destination_script ( & self ) -> Script {
241
+ let secp_ctx = Secp256k1 :: signing_only ( ) ;
242
+ 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 ( ) ;
243
+ let our_channel_monitor_claim_key_hash = WPubkeyHash :: hash ( & PublicKey :: from_secret_key ( & secp_ctx, & channel_monitor_claim_key) . serialize ( ) ) ;
244
+ Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & our_channel_monitor_claim_key_hash[ ..] ) . into_script ( )
245
+ }
246
+
247
+ fn get_shutdown_scriptpubkey ( & self ) -> ShutdownScript {
248
+ let secp_ctx = Secp256k1 :: signing_only ( ) ;
249
+ 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 ( ) ;
250
+ let pubkey_hash = WPubkeyHash :: hash ( & PublicKey :: from_secret_key ( & secp_ctx, & secret_key) . serialize ( ) ) ;
251
+ ShutdownScript :: new_p2wpkh ( & pubkey_hash)
242
252
}
243
253
}
244
254
255
+ impl KeysInterface for KeyProvider { }
256
+
245
257
impl KeyProvider {
246
258
fn make_enforcement_state_cell ( & self , commitment_seed : [ u8 ; 32 ] ) -> Arc < Mutex < EnforcementState > > {
247
259
let mut revoked_commitments = self . enforcement_states . lock ( ) . unwrap ( ) ;
0 commit comments