Skip to content

Commit 953127a

Browse files
committed
Remove default implementations for node_id, ecdh, and sign_invoice.
1 parent 8527d4b commit 953127a

File tree

8 files changed

+187
-125
lines changed

8 files changed

+187
-125
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,26 @@ impl NodeSigner for KeyProvider {
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
}
177177

178+
fn get_node_id(&self, recipient: Recipient) -> Result<PublicKey, ()> {
179+
let secp_ctx = Secp256k1::signing_only();
180+
Ok(PublicKey::from_secret_key(&secp_ctx, &self.get_node_secret(recipient)?))
181+
}
182+
183+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
184+
let mut node_secret = self.get_node_secret(recipient)?;
185+
if let Some(tweak) = tweak {
186+
node_secret = node_secret.mul_tweak(tweak).unwrap();
187+
}
188+
Ok(SharedSecret::new(other_key, &node_secret))
189+
}
190+
178191
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
179192
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])
180193
}
194+
195+
fn sign_invoice(&self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient) -> Result<RecoverableSignature, ()> {
196+
unreachable!()
197+
}
181198
}
182199

183200
impl SignerProvider for KeyProvider {

fuzz/src/full_stack.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,26 @@ impl NodeSigner for KeyProvider {
279279
Ok(self.node_secret.clone())
280280
}
281281

282+
fn get_node_id(&self, recipient: Recipient) -> Result<PublicKey, ()> {
283+
let secp_ctx = Secp256k1::signing_only();
284+
Ok(PublicKey::from_secret_key(&secp_ctx, &self.get_node_secret(recipient)?))
285+
}
286+
287+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
288+
let mut node_secret = self.get_node_secret(recipient)?;
289+
if let Some(tweak) = tweak {
290+
node_secret = node_secret.mul_tweak(tweak).unwrap();
291+
}
292+
Ok(SharedSecret::new(other_key, &node_secret))
293+
}
294+
282295
fn get_inbound_payment_key_material(&self) -> KeyMaterial {
283296
self.inbound_payment_key.clone()
284297
}
298+
299+
fn sign_invoice(&self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient) -> Result<RecoverableSignature, ()> {
300+
unreachable!()
301+
}
285302
}
286303

287304
impl SignerProvider for KeyProvider {

fuzz/src/onion_message.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,24 @@ impl NodeSigner for KeyProvider {
104104
Ok(self.node_secret.clone())
105105
}
106106

107+
fn get_node_id(&self, recipient: Recipient) -> Result<PublicKey, ()> {
108+
let secp_ctx = Secp256k1::signing_only();
109+
Ok(PublicKey::from_secret_key(&secp_ctx, &self.get_node_secret(recipient)?))
110+
}
111+
112+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
113+
let mut node_secret = self.get_node_secret(recipient)?;
114+
if let Some(tweak) = tweak {
115+
node_secret = node_secret.mul_tweak(tweak).map_err(|_| ())?;
116+
}
117+
Ok(SharedSecret::new(other_key, &node_secret))
118+
}
119+
107120
fn get_inbound_payment_key_material(&self) -> KeyMaterial { unreachable!() }
121+
122+
fn sign_invoice(&self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient) -> Result<RecoverableSignature, ()> {
123+
unreachable!()
124+
}
108125
}
109126

110127
impl SignerProvider for KeyProvider {

lightning-invoice/src/payment.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,11 +2079,10 @@ mod tests {
20792079

20802080
let event_handler = |_: Event| { panic!(); };
20812081
let invoice_payer = InvoicePayer::new(nodes[0].node, router, nodes[0].logger, event_handler, Retry::Attempts(1));
2082-
let secp_context = Secp256k1::signing_only();
20832082

20842083
assert!(invoice_payer.pay_invoice(&create_invoice_from_channelmanager_and_duration_since_epoch(
20852084
&nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::Bitcoin,
2086-
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600, &secp_context).unwrap())
2085+
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600).unwrap())
20872086
.is_ok());
20882087
let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events();
20892088
assert_eq!(htlc_msgs.len(), 2);
@@ -2125,11 +2124,10 @@ mod tests {
21252124

21262125
let event_handler = |_: Event| { panic!(); };
21272126
let invoice_payer = InvoicePayer::new(nodes[0].node, router, nodes[0].logger, event_handler, Retry::Attempts(1));
2128-
let secp_context = Secp256k1::signing_only();
21292127

21302128
assert!(invoice_payer.pay_invoice(&create_invoice_from_channelmanager_and_duration_since_epoch(
21312129
&nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::Bitcoin,
2132-
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600, &secp_context).unwrap())
2130+
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600).unwrap())
21332131
.is_ok());
21342132
let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events();
21352133
assert_eq!(htlc_msgs.len(), 2);
@@ -2207,11 +2205,10 @@ mod tests {
22072205
event_checker(event);
22082206
};
22092207
let invoice_payer = InvoicePayer::new(nodes[0].node, router, nodes[0].logger, event_handler, Retry::Attempts(1));
2210-
let secp_context = Secp256k1::signing_only();
22112208

22122209
assert!(invoice_payer.pay_invoice(&create_invoice_from_channelmanager_and_duration_since_epoch(
22132210
&nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::Bitcoin,
2214-
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600, &secp_context).unwrap())
2211+
Some(100_010_000), "Invoice".to_string(), duration_since_epoch(), 3600).unwrap())
22152212
.is_ok());
22162213
let htlc_updates = SendEvent::from_node(&nodes[0]);
22172214
check_added_monitors!(nodes[0], 1);

0 commit comments

Comments
 (0)