@@ -36,7 +36,7 @@ use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, chainmonitor, chan
3636use lightning:: chain:: channelmonitor:: { ChannelMonitor , MonitorEvent } ;
3737use lightning:: chain:: transaction:: OutPoint ;
3838use 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 } ;
4040use lightning:: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
4141use lightning:: ln:: channelmanager:: { self , ChainParameters , ChannelManager , PaymentSendFailure , ChannelManagerReadArgs , PaymentId } ;
4242use lightning:: ln:: channel:: FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE ;
@@ -160,13 +160,26 @@ struct KeyProvider {
160160 rand_bytes_id : atomic:: AtomicU32 ,
161161 enforcement_states : Mutex < HashMap < [ u8 ; 32 ] , Arc < Mutex < EnforcementState > > > > ,
162162}
163- impl KeysInterface for KeyProvider {
164- type Signer = EnforcingSigner ;
165163
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 {
166174 fn get_node_secret ( & self , _recipient : Recipient ) -> Result < SecretKey , ( ) > {
167175 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 ( ) )
168176 }
169177
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+
170183 fn ecdh ( & self , recipient : Recipient , other_key : & PublicKey , tweak : Option < & Scalar > ) -> Result < SharedSecret , ( ) > {
171184 let mut node_secret = self . get_node_secret ( recipient) ?;
172185 if let Some ( tweak) = tweak {
@@ -179,19 +192,13 @@ impl KeysInterface for KeyProvider {
179192 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 ] )
180193 }
181194
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 ! ( )
187197 }
198+ }
188199
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 ;
195202
196203 fn generate_channel_keys_id ( & self , _inbound : bool , _channel_value_satoshis : u64 , _user_channel_id : u128 ) -> [ u8 ; 32 ] {
197204 let id = self . rand_bytes_id . fetch_add ( 1 , atomic:: Ordering :: Relaxed ) as u8 ;
@@ -217,13 +224,6 @@ impl KeysInterface for KeyProvider {
217224 EnforcingSigner :: new_with_revoked ( keys, revoked_commitment, false )
218225 }
219226
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-
227227 fn read_chan_signer ( & self , buffer : & [ u8 ] ) -> Result < Self :: Signer , DecodeError > {
228228 let mut reader = std:: io:: Cursor :: new ( buffer) ;
229229
@@ -237,11 +237,23 @@ impl KeysInterface for KeyProvider {
237237 } )
238238 }
239239
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)
242252 }
243253}
244254
255+ impl KeysInterface for KeyProvider { }
256+
245257impl KeyProvider {
246258 fn make_enforcement_state_cell ( & self , commitment_seed : [ u8 ; 32 ] ) -> Arc < Mutex < EnforcementState > > {
247259 let mut revoked_commitments = self . enforcement_states . lock ( ) . unwrap ( ) ;
0 commit comments