Skip to content

Commit d7e7a0b

Browse files
committed
Move get_inbound_payment_key_material from KeysInterface to NodeSigner
1 parent 84363be commit d7e7a0b

File tree

6 files changed

+40
-39
lines changed

6 files changed

+40
-39
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ impl NodeSigner for KeyProvider {
174174
fn get_node_secret(&self, _recipient: Recipient) -> Result<SecretKey, ()> {
175175
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())
176176
}
177+
178+
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
179+
KeyMaterial([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])
180+
}
177181
}
178182

179183
impl SignerProvider for KeyProvider {
@@ -218,10 +222,6 @@ impl SignerProvider for KeyProvider {
218222
}
219223

220224
impl KeysInterface for KeyProvider {
221-
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
222-
KeyMaterial([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])
223-
}
224-
225225
fn get_destination_script(&self) -> Script {
226226
let secp_ctx = Secp256k1::signing_only();
227227
let channel_monitor_claim_key = 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, 2, self.node_id]).unwrap();

fuzz/src/full_stack.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ impl NodeSigner for KeyProvider {
278278
fn get_node_secret(&self, _recipient: Recipient) -> Result<SecretKey, ()> {
279279
Ok(self.node_secret.clone())
280280
}
281+
282+
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
283+
self.inbound_payment_key.clone()
284+
}
281285
}
282286

283287
impl SignerProvider for KeyProvider {
@@ -335,10 +339,6 @@ impl SignerProvider for KeyProvider {
335339
}
336340

337341
impl KeysInterface for KeyProvider {
338-
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
339-
self.inbound_payment_key.clone()
340-
}
341-
342342
fn get_destination_script(&self) -> Script {
343343
let secp_ctx = Secp256k1::signing_only();
344344
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();

fuzz/src/onion_message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ impl NodeSigner for KeyProvider {
103103
fn get_node_secret(&self, _recipient: Recipient) -> Result<SecretKey, ()> {
104104
Ok(self.node_secret.clone())
105105
}
106+
107+
fn get_inbound_payment_key_material(&self) -> KeyMaterial { unreachable!() }
106108
}
107109

108110
impl SignerProvider for KeyProvider {
@@ -118,8 +120,6 @@ impl SignerProvider for KeyProvider {
118120
}
119121

120122
impl KeysInterface for KeyProvider {
121-
fn get_inbound_payment_key_material(&self) -> KeyMaterial { unreachable!() }
122-
123123
fn get_destination_script(&self) -> Script { unreachable!() }
124124

125125
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!() }

lightning/src/chain/keysinterface.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,20 @@ pub trait NodeSigner {
448448
/// Errors if the [`Recipient`] variant is not supported by the implementation.
449449
fn get_node_secret(&self, recipient: Recipient) -> Result<SecretKey, ()>;
450450

451+
/// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
452+
///
453+
/// If the implementor of this trait supports [phantom node payments], then every node that is
454+
/// intended to be included in the phantom invoice route hints must return the same value from
455+
/// this method.
456+
// This is because LDK avoids storing inbound payment data by encrypting payment data in the
457+
// payment hash and/or payment secret, therefore for a payment to be receivable by multiple
458+
// nodes, they must share the key that encrypts this payment data.
459+
///
460+
/// This method must return the same value each time it is called.
461+
///
462+
/// [phantom node payments]: PhantomKeysManager
463+
fn get_inbound_payment_key_material(&self) -> KeyMaterial;
464+
451465
/// Get node id based on the provided [`Recipient`]. This public key corresponds to the secret in
452466
/// [`get_node_secret`].
453467
///
@@ -533,20 +547,6 @@ pub trait SignerProvider {
533547

534548
/// A trait to describe an object which can get user secrets and key material.
535549
pub trait KeysInterface: EntropySource + NodeSigner + SignerProvider {
536-
/// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
537-
///
538-
/// If the implementor of this trait supports [phantom node payments], then every node that is
539-
/// intended to be included in the phantom invoice route hints must return the same value from
540-
/// this method.
541-
// This is because LDK avoids storing inbound payment data by encrypting payment data in the
542-
// payment hash and/or payment secret, therefore for a payment to be receivable by multiple
543-
// nodes, they must share the key that encrypts this payment data.
544-
///
545-
/// This method must return the same value each time it is called.
546-
///
547-
/// [phantom node payments]: PhantomKeysManager
548-
fn get_inbound_payment_key_material(&self) -> KeyMaterial;
549-
550550
/// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
551551
///
552552
/// This method should return a different value each time it is called, to avoid linking
@@ -1273,6 +1273,10 @@ impl NodeSigner for KeysManager {
12731273
Recipient::PhantomNode => Err(())
12741274
}
12751275
}
1276+
1277+
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
1278+
self.inbound_payment_key.clone()
1279+
}
12761280
}
12771281

12781282
impl SignerProvider for KeysManager {
@@ -1299,10 +1303,6 @@ impl SignerProvider for KeysManager {
12991303
}
13001304

13011305
impl KeysInterface for KeysManager {
1302-
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
1303-
self.inbound_payment_key.clone()
1304-
}
1305-
13061306
fn get_destination_script(&self) -> Script {
13071307
self.destination_script.clone()
13081308
}
@@ -1353,6 +1353,10 @@ impl NodeSigner for PhantomKeysManager {
13531353
}
13541354
}
13551355

1356+
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
1357+
self.inbound_payment_key.clone()
1358+
}
1359+
13561360
// We need to override the invoice signing implementation for phantom keys managers
13571361
fn sign_invoice<C: Signing>(&self, hrp_bytes: &[u8], invoice_data: &[u5], recipient: Recipient, _secp_context: &Secp256k1<C>) -> Result<RecoverableSignature, ()> {
13581362
let preimage = construct_invoice_preimage(&hrp_bytes, &invoice_data);
@@ -1378,10 +1382,6 @@ impl SignerProvider for PhantomKeysManager {
13781382
}
13791383

13801384
impl KeysInterface for PhantomKeysManager {
1381-
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
1382-
self.inbound_payment_key.clone()
1383-
}
1384-
13851385
fn get_destination_script(&self) -> Script {
13861386
self.inner.get_destination_script()
13871387
}

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6858,6 +6858,8 @@ mod tests {
68586858

68596859
impl NodeSigner for Keys {
68606860
fn get_node_secret(&self, _recipient: Recipient) -> Result<SecretKey, ()> { panic!(); }
6861+
6862+
fn get_inbound_payment_key_material(&self) -> KeyMaterial { panic!(); }
68616863
}
68626864

68636865
impl SignerProvider for Keys {
@@ -6875,8 +6877,6 @@ mod tests {
68756877
}
68766878

68776879
impl KeysInterface for Keys {
6878-
fn get_inbound_payment_key_material(&self) -> KeyMaterial { panic!(); }
6879-
68806880
fn get_destination_script(&self) -> Script {
68816881
let secp_ctx = Secp256k1::signing_only();
68826882
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();

lightning/src/util/test_utils.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ impl EntropySource for OnlyReadsKeysInterface {
7777

7878
impl NodeSigner for OnlyReadsKeysInterface {
7979
fn get_node_secret(&self, _recipient: Recipient) -> Result<SecretKey, ()> { unreachable!(); }
80+
81+
fn get_inbound_payment_key_material(&self) -> KeyMaterial { unreachable!(); }
8082
}
8183

8284
impl SignerProvider for OnlyReadsKeysInterface {
@@ -100,7 +102,6 @@ impl SignerProvider for OnlyReadsKeysInterface {
100102
}
101103

102104
impl keysinterface::KeysInterface for OnlyReadsKeysInterface {
103-
fn get_inbound_payment_key_material(&self) -> KeyMaterial { unreachable!(); }
104105
fn get_destination_script(&self) -> Script { unreachable!(); }
105106
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript { unreachable!(); }
106107
}
@@ -625,6 +626,10 @@ impl NodeSigner for TestKeysInterface {
625626
self.backing.get_node_secret(recipient)
626627
}
627628

629+
fn get_inbound_payment_key_material(&self) -> keysinterface::KeyMaterial {
630+
self.backing.get_inbound_payment_key_material()
631+
}
632+
628633
fn sign_invoice<C: Signing>(&self, hrp_bytes: &[u8], invoice_data: &[u5], recipient: Recipient, secp_context: &Secp256k1<C>) -> Result<RecoverableSignature, ()> {
629634
self.backing.sign_invoice(hrp_bytes, invoice_data, recipient, secp_context)
630635
}
@@ -658,10 +663,6 @@ impl SignerProvider for TestKeysInterface {
658663
}
659664

660665
impl keysinterface::KeysInterface for TestKeysInterface {
661-
fn get_inbound_payment_key_material(&self) -> keysinterface::KeyMaterial {
662-
self.backing.get_inbound_payment_key_material()
663-
}
664-
665666
fn get_destination_script(&self) -> Script { self.backing.get_destination_script() }
666667

667668
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript {

0 commit comments

Comments
 (0)