@@ -856,6 +856,35 @@ pub trait NodeSigner {
856
856
/// [phantom node payments]: PhantomKeysManager
857
857
fn get_inbound_payment_key ( & self ) -> ExpandedKey ;
858
858
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
+
859
888
/// Get node id based on the provided [`Recipient`].
860
889
///
861
890
/// This method must return the same value each time it is called with a given [`Recipient`]
@@ -2201,6 +2230,14 @@ impl NodeSigner for KeysManager {
2201
2230
self . inbound_payment_key . clone ( )
2202
2231
}
2203
2232
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
+
2204
2241
fn sign_invoice (
2205
2242
& self , invoice : & RawBolt11Invoice , recipient : Recipient ,
2206
2243
) -> Result < RecoverableSignature , ( ) > {
@@ -2370,6 +2407,14 @@ impl NodeSigner for PhantomKeysManager {
2370
2407
self . inbound_payment_key . clone ( )
2371
2408
}
2372
2409
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
+
2373
2418
fn sign_invoice (
2374
2419
& self , invoice : & RawBolt11Invoice , recipient : Recipient ,
2375
2420
) -> Result < RecoverableSignature , ( ) > {
0 commit comments