@@ -832,6 +832,15 @@ pub trait NodeSigner {
832832 /// [phantom node payments]: PhantomKeysManager
833833 fn get_inbound_payment_key ( & self ) -> ExpandedKey ;
834834
835+ /// Defines a method to derive a 32-byte encryption key for peer storage.
836+ ///
837+ /// Implementations of this method must derive a secure encryption key.
838+ /// The key is used to encrypt or decrypt backups of our state stored with our peers.
839+ ///
840+ /// Thus, if you wish to rely on recovery using this method, you should use a key which
841+ /// can be re-derived from data which would be available after state loss (eg the wallet seed)
842+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] ;
843+
835844 /// Get node id based on the provided [`Recipient`].
836845 ///
837846 /// This method must return the same value each time it is called with a given [`Recipient`]
@@ -1771,6 +1780,7 @@ pub struct KeysManager {
17711780 shutdown_pubkey : PublicKey ,
17721781 channel_master_key : Xpriv ,
17731782 channel_child_index : AtomicUsize ,
1783+ peer_storage_key : SecretKey ,
17741784
17751785 #[ cfg( test) ]
17761786 pub ( crate ) entropy_source : RandomBytes ,
@@ -1839,6 +1849,10 @@ impl KeysManager {
18391849 . private_key ;
18401850 let mut inbound_pmt_key_bytes = [ 0 ; 32 ] ;
18411851 inbound_pmt_key_bytes. copy_from_slice ( & inbound_payment_key[ ..] ) ;
1852+ let peer_storage_key: SecretKey = master_key
1853+ . derive_priv ( & secp_ctx, & ChildNumber :: from_hardened_idx ( 6 ) . unwrap ( ) )
1854+ . expect ( "Your RNG is busted" )
1855+ . private_key ;
18421856
18431857 let mut rand_bytes_engine = Sha256 :: engine ( ) ;
18441858 rand_bytes_engine. input ( & starting_time_secs. to_be_bytes ( ) ) ;
@@ -1854,6 +1868,8 @@ impl KeysManager {
18541868 node_id,
18551869 inbound_payment_key : ExpandedKey :: new ( inbound_pmt_key_bytes) ,
18561870
1871+ peer_storage_key,
1872+
18571873 destination_script,
18581874 shutdown_pubkey,
18591875
@@ -2079,6 +2095,10 @@ impl NodeSigner for KeysManager {
20792095 self . inbound_payment_key . clone ( )
20802096 }
20812097
2098+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] {
2099+ self . peer_storage_key . secret_bytes ( )
2100+ }
2101+
20822102 fn sign_invoice (
20832103 & self , invoice : & RawBolt11Invoice , recipient : Recipient ,
20842104 ) -> Result < RecoverableSignature , ( ) > {
@@ -2240,6 +2260,10 @@ impl NodeSigner for PhantomKeysManager {
22402260 self . inbound_payment_key . clone ( )
22412261 }
22422262
2263+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] {
2264+ self . inner . peer_storage_key . secret_bytes ( )
2265+ }
2266+
22432267 fn sign_invoice (
22442268 & self , invoice : & RawBolt11Invoice , recipient : Recipient ,
22452269 ) -> Result < RecoverableSignature , ( ) > {
0 commit comments