@@ -20,27 +20,21 @@ use crate::crypto::chacha20poly1305rfc::ChaCha20Poly1305RFC;
20
20
use crate :: prelude:: * ;
21
21
22
22
/// [`OurPeerStorage`] is used to store channel information that allows for the creation of a
23
- /// `peer_storage` backup. It includes versioning and timestamping for comparison between
24
- /// instances of [`OurPeerStorage`].
23
+ /// `peer_storage` backup.
25
24
///
26
25
/// This structure is designed to serialize channel data for backup and supports encryption
27
- /// and decryption to ensure data integrity and security during exchange or storage.
26
+ /// and decryption using `ChaCha20Poly1305RFC` to ensure data integrity and security during exchange or storage.
28
27
///
29
28
/// # Key Methods
30
- /// - `create_from_data`: Returns an encrypted [`OurPeerStorage`] instance created from the provided data.
31
- /// - `decrypt_our_peer_storage`: Decrypts the [`OurPeerStorage::encrypted_data`] using the key and returns decrypted data.
32
- ///
33
- /// # Usage
34
- /// This structure can be used for securely managing and exchanging peer storage backups. It
35
- /// includes methods for encryption and decryption using `ChaCha20Poly1305RFC`, making it
36
- /// suitable for on-the-wire transmission.
29
+ /// - [`OurPeerStorage::create_from_data`]: Returns an encrypted [`OurPeerStorage`] instance created from the provided data.
30
+ /// - [`OurPeerStorage::decrypt_our_peer_storage`]: Decrypts the [`OurPeerStorage::encrypted_data`] using the key and returns decrypted data.
37
31
///
38
32
/// ## Example
39
33
/// ```
40
34
/// use lightning::ln::our_peer_storage::OurPeerStorage;
41
35
/// use lightning::sign::PeerStorageKey;
42
36
/// let key = PeerStorageKey{inner: [0u8; 32]};
43
- /// let our_peer_storage = OurPeerStorage::create_from_data(key.clone(), vec![1, 2, 3]);
37
+ /// let our_peer_storage = OurPeerStorage::create_from_data(key.clone(), vec![1, 2, 3], [0u8; 32] );
44
38
/// let decrypted_data = our_peer_storage.decrypt_our_peer_storage(key).unwrap();
45
39
/// assert_eq!(decrypted_data, vec![1, 2, 3]);
46
40
/// ```
@@ -56,14 +50,15 @@ impl OurPeerStorage {
56
50
}
57
51
58
52
/// Get encrypted data stored inside [`OurPeerStorage`].
59
- pub fn encrypted_data ( & self ) -> Vec < u8 > {
60
- self . encrypted_data . clone ( )
53
+ pub fn into_vec ( self ) -> Vec < u8 > {
54
+ self . encrypted_data
61
55
}
62
56
63
57
/// Creates a serialised representation of [`OurPeerStorage`] from the given `ser_channels` data.
64
58
///
65
- /// This function takes a `key` (for encryption) and `ser_channels` data
66
- /// (serialised channel information), and returns a serialised [`OurPeerStorage`] as a `Vec<u8>`.
59
+ /// This function takes a `key` (for encryption), `ser_channels` data
60
+ /// (serialised channel information) and random_bytes (to derive nonce for encryption) and returns a serialised
61
+ /// [`OurPeerStorage`] as a `Vec<u8>`.
67
62
///
68
63
/// The resulting serialised data is intended to be directly used for transmission to the peers.
69
64
pub fn create_from_data (
0 commit comments