Skip to content

Commit 423e421

Browse files
keysinterface: add get_phantom_secret method
This method will be used to retrieve a phantom node's secret key to decrypt phantom node payments
1 parent 2f92dbf commit 423e421

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ impl KeysInterface for KeyProvider {
223223
fn sign_invoice(&self, _invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> {
224224
unreachable!()
225225
}
226+
227+
fn get_phantom_secret(&self, _scid: u64) -> Result<SecretKey, ()> {
228+
Err(())
229+
}
226230
}
227231

228232
impl KeyProvider {

fuzz/src/full_stack.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ impl KeysInterface for KeyProvider {
336336
fn sign_invoice(&self, _invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> {
337337
unreachable!()
338338
}
339+
340+
fn get_phantom_secret(&self, _scid: u64) -> Result<SecretKey, ()> {
341+
Err(())
342+
}
339343
}
340344

341345
#[inline]

lightning/src/chain/keysinterface.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use bitcoin::secp256k1::recovery::RecoverableSignature;
3030
use bitcoin::secp256k1;
3131

3232
use util::{byte_utils, transaction_utils};
33+
use util::crypto::hkdf_extract_expand;
3334
use util::ser::{Writeable, Writer, Readable};
3435

3536
use chain::transaction::OutPoint;
@@ -408,6 +409,9 @@ pub trait KeysInterface {
408409
///
409410
/// This method must return the same value each time it is called.
410411
fn get_inbound_payment_key_material(&self) -> KeyMaterial;
412+
413+
/// Get a secret key for use in receiving phantom node payments.
414+
fn get_phantom_secret(&self, scid: u64) -> Result<SecretKey, ()>;
411415
}
412416

413417
#[derive(Clone)]
@@ -1110,6 +1114,11 @@ impl KeysInterface for KeysManager {
11101114
fn sign_invoice(&self, invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> {
11111115
Ok(self.secp_ctx.sign_recoverable(&hash_to_message!(&Sha256::hash(&invoice_preimage)), &self.get_node_secret()))
11121116
}
1117+
1118+
fn get_phantom_secret(&self, _scid: u64) -> Result<SecretKey, ()> {
1119+
let hkdf = hkdf_extract_expand(b"LDK Phantom Node Secret Key Expansion", &self.inbound_payment_key.0, 1);
1120+
Ok(SecretKey::from_slice(&hkdf[0]).unwrap())
1121+
}
11131122
}
11141123

11151124
// Ensure that BaseSign can have a vtable

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5877,6 +5877,7 @@ mod tests {
58775877
fn get_secure_random_bytes(&self) -> [u8; 32] { [0; 32] }
58785878
fn read_chan_signer(&self, _data: &[u8]) -> Result<Self::Signer, DecodeError> { panic!(); }
58795879
fn sign_invoice(&self, _invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> { panic!(); }
5880+
fn get_phantom_secret(&self, _scid: u64) -> Result<SecretKey, ()> { panic!(); }
58805881
}
58815882

58825883
fn public_from_secret_hex(secp_ctx: &Secp256k1<All>, hex: &str) -> PublicKey {

lightning/src/util/test_utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl keysinterface::KeysInterface for OnlyReadsKeysInterface {
8888
))
8989
}
9090
fn sign_invoice(&self, _invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> { unreachable!(); }
91+
fn get_phantom_secret(&self, _scid: u64) -> Result<SecretKey, ()> { unreachable!(); }
9192
}
9293

9394
pub struct TestChainMonitor<'a> {
@@ -531,6 +532,8 @@ impl keysinterface::KeysInterface for TestKeysInterface {
531532
fn sign_invoice(&self, invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> {
532533
self.backing.sign_invoice(invoice_preimage)
533534
}
535+
536+
fn get_phantom_secret(&self, scid: u64) -> Result<SecretKey, ()> { self.backing.get_phantom_secret(scid) }
534537
}
535538

536539
impl TestKeysInterface {

0 commit comments

Comments
 (0)