@@ -856,6 +856,35 @@ pub trait NodeSigner {
856856 /// [phantom node payments]: PhantomKeysManager
857857 fn get_inbound_payment_key ( & self ) -> ExpandedKey ;
858858
859+ /// Generates a 32-byte key used for peer storage encryption.
860+ ///
861+ /// This function derives an encryption key for peer storage by using the HKDF
862+ /// (HMAC-based Key Derivation Function) with a specific label and the node
863+ /// secret key. The derived key is used for encrypting or decrypting peer storage
864+ /// data.
865+ ///
866+ /// The process involves the following steps:
867+ /// 1. Retrieves the node secret key.
868+ /// 2. Uses the node secret key and the label `"Peer Storage Encryption Key"`
869+ /// to perform HKDF extraction and expansion.
870+ /// 3. Returns the first part of the derived key, which is a 32-byte array.
871+ ///
872+ /// # Returns
873+ ///
874+ /// Returns a 32-byte array that serves as the encryption key for peer storage.
875+ ///
876+ /// # Panics
877+ ///
878+ /// This function does not panic under normal circumstances, but failures in
879+ /// obtaining the node secret key or issues within the HKDF function may cause
880+ /// unexpected behavior.
881+ ///
882+ /// # Notes
883+ ///
884+ /// Ensure that the node secret key is securely managed, as it is crucial for
885+ /// the security of the derived encryption key.
886+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] ;
887+
859888 /// Get node id based on the provided [`Recipient`].
860889 ///
861890 /// This method must return the same value each time it is called with a given [`Recipient`]
@@ -2201,6 +2230,14 @@ impl NodeSigner for KeysManager {
22012230 self . inbound_payment_key . clone ( )
22022231 }
22032232
2233+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] {
2234+ let ( t1, _) = hkdf_extract_expand_twice (
2235+ b"Peer Storage Encryption Key" ,
2236+ & self . get_node_secret_key ( ) . secret_bytes ( ) ,
2237+ ) ;
2238+ t1
2239+ }
2240+
22042241 fn sign_invoice (
22052242 & self , invoice : & RawBolt11Invoice , recipient : Recipient ,
22062243 ) -> Result < RecoverableSignature , ( ) > {
@@ -2370,6 +2407,14 @@ impl NodeSigner for PhantomKeysManager {
23702407 self . inbound_payment_key . clone ( )
23712408 }
23722409
2410+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] {
2411+ let ( t1, _) = hkdf_extract_expand_twice (
2412+ b"Peer Storage Encryption Key" ,
2413+ & self . get_node_secret_key ( ) . secret_bytes ( ) ,
2414+ ) ;
2415+ t1
2416+ }
2417+
23732418 fn sign_invoice (
23742419 & self , invoice : & RawBolt11Invoice , recipient : Recipient ,
23752420 ) -> Result < RecoverableSignature , ( ) > {
0 commit comments