@@ -835,6 +835,35 @@ pub trait NodeSigner {
835
835
/// [phantom node payments]: PhantomKeysManager
836
836
fn get_inbound_payment_key_material ( & self ) -> KeyMaterial ;
837
837
838
+ /// Generates a 32-byte key used for peer storage encryption.
839
+ ///
840
+ /// This function derives an encryption key for peer storage by using the HKDF
841
+ /// (HMAC-based Key Derivation Function) with a specific label and the node
842
+ /// secret key. The derived key is used for encrypting or decrypting peer storage
843
+ /// data.
844
+ ///
845
+ /// The process involves the following steps:
846
+ /// 1. Retrieves the node secret key.
847
+ /// 2. Uses the node secret key and the label `"Peer Storage Encryption Key"`
848
+ /// to perform HKDF extraction and expansion.
849
+ /// 3. Returns the first part of the derived key, which is a 32-byte array.
850
+ ///
851
+ /// # Returns
852
+ ///
853
+ /// Returns a 32-byte array that serves as the encryption key for peer storage.
854
+ ///
855
+ /// # Panics
856
+ ///
857
+ /// This function does not panic under normal circumstances, but failures in
858
+ /// obtaining the node secret key or issues within the HKDF function may cause
859
+ /// unexpected behavior.
860
+ ///
861
+ /// # Notes
862
+ ///
863
+ /// Ensure that the node secret key is securely managed, as it is crucial for
864
+ /// the security of the derived encryption key.
865
+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] ;
866
+
838
867
/// Get node id based on the provided [`Recipient`].
839
868
///
840
869
/// This method must return the same value each time it is called with a given [`Recipient`]
@@ -2174,6 +2203,14 @@ impl NodeSigner for KeysManager {
2174
2203
self . inbound_payment_key . clone ( )
2175
2204
}
2176
2205
2206
+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] {
2207
+ let ( t1, _) = hkdf_extract_expand_twice (
2208
+ b"Peer Storage Encryption Key" ,
2209
+ & self . get_node_secret_key ( ) . secret_bytes ( ) ,
2210
+ ) ;
2211
+ t1
2212
+ }
2213
+
2177
2214
fn sign_invoice (
2178
2215
& self , invoice : & RawBolt11Invoice , recipient : Recipient ,
2179
2216
) -> Result < RecoverableSignature , ( ) > {
@@ -2352,6 +2389,14 @@ impl NodeSigner for PhantomKeysManager {
2352
2389
self . inbound_payment_key . clone ( )
2353
2390
}
2354
2391
2392
+ fn get_peer_storage_key ( & self ) -> [ u8 ; 32 ] {
2393
+ let ( t1, _) = hkdf_extract_expand_twice (
2394
+ b"Peer Storage Encryption Key" ,
2395
+ & self . get_node_secret_key ( ) . secret_bytes ( ) ,
2396
+ ) ;
2397
+ t1
2398
+ }
2399
+
2355
2400
fn sign_invoice (
2356
2401
& self , invoice : & RawBolt11Invoice , recipient : Recipient ,
2357
2402
) -> Result < RecoverableSignature , ( ) > {
0 commit comments