-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Peer Storage Feature – Part 2 #3623
base: main
Are you sure you want to change the base?
Changes from 1 commit
b133e80
3778b81
28d60ec
ebefcd1
65aee4d
35863ce
777f6b1
c3a3859
ef2b8a6
162b6c4
5a881a3
30d9068
5deb6ad
569caa4
58affb5
4730cdc
5ef58e9
f6d6204
57341a1
42af2ab
0fd40de
0c10bd5
4adeeee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -829,6 +829,30 @@ pub trait NodeSigner { | |
/// [phantom node payments]: PhantomKeysManager | ||
fn get_inbound_payment_key(&self) -> ExpandedKey; | ||
|
||
/// Defines a method to derive a 32-byte encryption key for peer storage. | ||
/// | ||
/// Implementations of this method must derive a secure encryption key using a | ||
/// cryptographically strong key derivation function (e.g., HKDF or a hardened | ||
/// child key derivation). The derived key is used to encrypt or decrypt peer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could link BIP32 here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, Thanks! |
||
/// storage data, ensuring confidentiality and integrity. | ||
/// | ||
/// # Implementation Details | ||
/// | ||
/// - The key must be derived from a node-specific secret to ensure uniqueness. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what a "node-specific secret" means. Honestly, I'm not sure any of the sections below the first paragraph are needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, on second thought, I agree it’s unnecessary. |
||
/// - The derived key must be exactly **32 bytes** and suitable for symmetric | ||
/// encryption algorithms. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is given by the return type, we don't have to specify it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I wrote it just as a note to implementations. But, yeah, the return type specifies it. Removing it. |
||
/// | ||
/// # Returns | ||
/// | ||
/// A **32-byte array** representing the encryption key for peer storage. | ||
/// | ||
/// # Usage | ||
/// | ||
/// This method is invoked when encrypting or decrypting peer storage data. | ||
/// It must return the same key every time it is called, ensuring consistency | ||
/// for encryption and decryption operations. | ||
fn get_peer_storage_key(&self) -> [u8; 32]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this return a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, fixing this... |
||
|
||
/// Get node id based on the provided [`Recipient`]. | ||
/// | ||
/// This method must return the same value each time it is called with a given [`Recipient`] | ||
|
@@ -1778,6 +1802,7 @@ pub struct KeysManager { | |
shutdown_pubkey: PublicKey, | ||
channel_master_key: Xpriv, | ||
channel_child_index: AtomicUsize, | ||
peer_storage_key: SecretKey, | ||
|
||
#[cfg(test)] | ||
pub(crate) entropy_source: RandomBytes, | ||
|
@@ -1846,6 +1871,10 @@ impl KeysManager { | |
.private_key; | ||
let mut inbound_pmt_key_bytes = [0; 32]; | ||
inbound_pmt_key_bytes.copy_from_slice(&inbound_payment_key[..]); | ||
let peer_storage_key: SecretKey = master_key | ||
.derive_priv(&secp_ctx, &ChildNumber::from_hardened_idx(6).unwrap()) | ||
.expect("Your RNG is busted") | ||
.private_key; | ||
|
||
let mut rand_bytes_engine = Sha256::engine(); | ||
rand_bytes_engine.input(&starting_time_secs.to_be_bytes()); | ||
|
@@ -1861,6 +1890,8 @@ impl KeysManager { | |
node_id, | ||
inbound_payment_key: ExpandedKey::new(inbound_pmt_key_bytes), | ||
|
||
peer_storage_key, | ||
|
||
destination_script, | ||
shutdown_pubkey, | ||
|
||
|
@@ -2086,6 +2117,10 @@ impl NodeSigner for KeysManager { | |
self.inbound_payment_key.clone() | ||
} | ||
|
||
fn get_peer_storage_key(&self) -> [u8; 32] { | ||
self.peer_storage_key.secret_bytes() | ||
} | ||
|
||
fn sign_invoice( | ||
&self, invoice: &RawBolt11Invoice, recipient: Recipient, | ||
) -> Result<RecoverableSignature, ()> { | ||
|
@@ -2247,6 +2282,10 @@ impl NodeSigner for PhantomKeysManager { | |
self.inbound_payment_key.clone() | ||
} | ||
|
||
fn get_peer_storage_key(&self) -> [u8; 32] { | ||
self.inner.peer_storage_key.secret_bytes() | ||
} | ||
|
||
fn sign_invoice( | ||
&self, invoice: &RawBolt11Invoice, recipient: Recipient, | ||
) -> Result<RecoverableSignature, ()> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure why this code move is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that we can use
keys_manager.get_peer_storage_key()
insideChainMonitor::new()
.