Skip to content

Commit d309b1a

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 af57d6d commit d309b1a

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ pub trait KeysInterface {
409409
///
410410
/// This method must return the same value each time it is called.
411411
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, ()>;
412415
}
413416

414417
#[derive(Clone)]
@@ -1131,6 +1134,13 @@ impl KeysInterface for KeysManager {
11311134
fn sign_invoice(&self, invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> {
11321135
Ok(self.secp_ctx.sign_recoverable(&hash_to_message!(&Sha256::hash(&invoice_preimage)), &self.get_node_secret()))
11331136
}
1137+
1138+
fn get_phantom_secret(&self, _scid: u64) -> Result<SecretKey, ()> {
1139+
match self.phantom_secret {
1140+
Some(key) => Ok(key.clone()),
1141+
None => Err(())
1142+
}
1143+
}
11341144
}
11351145

11361146
// 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
@@ -5885,6 +5885,7 @@ mod tests {
58855885
fn get_secure_random_bytes(&self) -> [u8; 32] { [0; 32] }
58865886
fn read_chan_signer(&self, _data: &[u8]) -> Result<Self::Signer, DecodeError> { panic!(); }
58875887
fn sign_invoice(&self, _invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> { panic!(); }
5888+
fn get_phantom_secret(&self, _scid: u64) -> Result<SecretKey, ()> { panic!(); }
58885889
}
58895890

58905891
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)