Skip to content

Commit beb9e7f

Browse files
keysinterface: add get_phantom_secret method
XXX elaborate
1 parent c41ae8d commit beb9e7f

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+
Ok(SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, self.node_id]).unwrap())
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+
/// XXX
414+
fn get_phantom_secret(&self, scid: u64) -> Result<SecretKey, ()>; // XXX better error?
411415
}
412416

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

11141123
// 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> {
@@ -530,6 +531,8 @@ impl keysinterface::KeysInterface for TestKeysInterface {
530531
fn sign_invoice(&self, invoice_preimage: Vec<u8>) -> Result<RecoverableSignature, ()> {
531532
self.backing.sign_invoice(invoice_preimage)
532533
}
534+
535+
fn get_phantom_secret(&self, scid: u64) -> Result<SecretKey, ()> { self.backing.get_phantom_secret(scid) }
533536
}
534537

535538
impl TestKeysInterface {

0 commit comments

Comments
 (0)