@@ -829,6 +829,30 @@ pub trait NodeSigner {
829829 /// [phantom node payments]: PhantomKeysManager
830830 fn get_inbound_payment_key ( & self ) -> ExpandedKey ;
831831
832+ /// Defines a method to derive a 32-byte encryption key for peer storage.
833+ ///
834+ /// Implementations of this method must derive a secure encryption key using a
835+ /// cryptographically strong key derivation function (e.g., HKDF or a hardened
836+ /// child key derivation). The derived key is used to encrypt or decrypt peer
837+ /// storage data, ensuring confidentiality and integrity.
838+ ///
839+ /// # Implementation Details
840+ ///
841+ /// - The key must be derived from a node-specific secret to ensure uniqueness.
842+ /// - The derived key must be exactly **32 bytes** and suitable for symmetric
843+ /// encryption algorithms.
844+ ///
845+ /// # Returns
846+ ///
847+ /// A **32-byte array** representing the encryption key for peer storage.
848+ ///
849+ /// # Usage
850+ ///
851+ /// This method is invoked when encrypting or decrypting peer storage data.
852+ /// It must return the same key every time it is called, ensuring consistency
853+ /// for encryption and decryption operations.
854+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] ;
855+
832856 /// Get node id based on the provided [`Recipient`].
833857 ///
834858 /// This method must return the same value each time it is called with a given [`Recipient`]
@@ -1778,6 +1802,7 @@ pub struct KeysManager {
17781802 shutdown_pubkey : PublicKey ,
17791803 channel_master_key : Xpriv ,
17801804 channel_child_index : AtomicUsize ,
1805+ peer_storage_key : SecretKey ,
17811806
17821807 #[ cfg( test) ]
17831808 pub ( crate ) entropy_source : RandomBytes ,
@@ -1846,6 +1871,10 @@ impl KeysManager {
18461871 . private_key ;
18471872 let mut inbound_pmt_key_bytes = [ 0 ; 32 ] ;
18481873 inbound_pmt_key_bytes. copy_from_slice ( & inbound_payment_key[ ..] ) ;
1874+ let peer_storage_key: SecretKey = master_key
1875+ . derive_priv ( & secp_ctx, & ChildNumber :: from_hardened_idx ( 6 ) . unwrap ( ) )
1876+ . expect ( "Your RNG is busted" )
1877+ . private_key ;
18491878
18501879 let mut rand_bytes_engine = Sha256 :: engine ( ) ;
18511880 rand_bytes_engine. input ( & starting_time_secs. to_be_bytes ( ) ) ;
@@ -1861,6 +1890,8 @@ impl KeysManager {
18611890 node_id,
18621891 inbound_payment_key : ExpandedKey :: new ( inbound_pmt_key_bytes) ,
18631892
1893+ peer_storage_key,
1894+
18641895 destination_script,
18651896 shutdown_pubkey,
18661897
@@ -2086,6 +2117,10 @@ impl NodeSigner for KeysManager {
20862117 self . inbound_payment_key . clone ( )
20872118 }
20882119
2120+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] {
2121+ self . peer_storage_key . secret_bytes ( )
2122+ }
2123+
20892124 fn sign_invoice (
20902125 & self , invoice : & RawBolt11Invoice , recipient : Recipient ,
20912126 ) -> Result < RecoverableSignature , ( ) > {
@@ -2247,6 +2282,10 @@ impl NodeSigner for PhantomKeysManager {
22472282 self . inbound_payment_key . clone ( )
22482283 }
22492284
2285+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] {
2286+ self . inner . peer_storage_key . secret_bytes ( )
2287+ }
2288+
22502289 fn sign_invoice (
22512290 & self , invoice : & RawBolt11Invoice , recipient : Recipient ,
22522291 ) -> Result < RecoverableSignature , ( ) > {
0 commit comments