Skip to content

Commit 998c40e

Browse files
fixup: Refactor LSPS5 webhook notification handling: return notification on success, remove event emission
- Change parse_webhook_notification to return the verified WebhookNotification directly, instead of emitting an event. - Remove LSPS5ClientEvent::WebhookNotificationReceived and related event logic. - Now, invalid signatures result in an error and notification data is not exposed to the user. - Follows feedback to avoid requiring users to manually check a boolean for signature validity and prevents leaking invalid notifications.
1 parent 5eeae38 commit 998c40e

File tree

2 files changed

+9
-59
lines changed

2 files changed

+9
-59
lines changed

lightning-liquidity/src/lsps5/client.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ where
451451
fn verify_notification_signature(
452452
&self, counterparty_node_id: PublicKey, signature_timestamp: &LSPSDateTime,
453453
signature: &str, notification: &WebhookNotification,
454-
) -> Result<bool, LSPS5ClientError> {
454+
) -> Result<(), LSPS5ClientError> {
455455
let now =
456456
LSPSDateTime::new_from_duration_since_epoch(self.time_provider.duration_since_epoch());
457457
let diff = signature_timestamp.abs_diff(now);
@@ -467,7 +467,7 @@ where
467467
);
468468

469469
if message_signing::verify(message.as_bytes(), signature, &counterparty_node_id) {
470-
Ok(true)
470+
Ok(())
471471
} else {
472472
Err(LSPS5ClientError::InvalidSignature)
473473
}
@@ -516,7 +516,7 @@ where
516516
/// - `signature`: the zbase32-encoded LN signature over timestamp+body.
517517
/// - `notification`: the [`WebhookNotification`] received from the LSP.
518518
///
519-
/// On success, emits [`LSPS5ClientEvent::WebhookNotificationReceived`].
519+
/// On success, returns the received [`WebhookNotification`].
520520
///
521521
/// Failure reasons include:
522522
/// - Timestamp too old (drift > 10 minutes)
@@ -527,36 +527,24 @@ where
527527
/// event, before taking action on the notification. This guarantees that only authentic,
528528
/// non-replayed notifications reach your application.
529529
///
530-
/// [`LSPS5ClientEvent::WebhookNotificationReceived`]: super::event::LSPS5ClientEvent::WebhookNotificationReceived
531530
/// [`LSPS5ServiceEvent::SendWebhookNotification`]: super::event::LSPS5ServiceEvent::SendWebhookNotification
532531
/// [`WebhookNotification`]: super::msgs::WebhookNotification
533532
pub fn parse_webhook_notification(
534533
&self, counterparty_node_id: PublicKey, timestamp: &LSPSDateTime, signature: &str,
535534
notification: &WebhookNotification,
536-
) -> Result<(), LSPS5ClientError> {
537-
match self.verify_notification_signature(
535+
) -> Result<WebhookNotification, LSPS5ClientError> {
536+
self.verify_notification_signature(
538537
counterparty_node_id,
539538
timestamp,
540539
signature,
541540
&notification,
542-
) {
543-
Ok(signature_valid) => {
544-
let event_queue_notifier = self.pending_events.notifier();
541+
)?;
545542

546-
self.check_signature_exists(signature)?;
543+
self.check_signature_exists(signature)?;
547544

548-
self.store_signature(signature.to_string());
545+
self.store_signature(signature.to_string());
549546

550-
event_queue_notifier.enqueue(LSPS5ClientEvent::WebhookNotificationReceived {
551-
counterparty_node_id,
552-
notification: notification.clone(),
553-
timestamp: timestamp.clone(),
554-
signature_valid,
555-
});
556-
Ok(())
557-
},
558-
Err(e) => Err(e),
559-
}
547+
Ok(notification.clone())
560548
}
561549
}
562550

lightning-liquidity/src/lsps5/event.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -392,42 +392,4 @@ pub enum LSPS5ClientEvent {
392392
/// This can be used to track which request this event corresponds to.
393393
request_id: LSPSRequestId,
394394
},
395-
396-
/// A webhook notification was received from the LSP.
397-
///
398-
/// This event is triggered when the client receives and successfully
399-
/// verifies a webhook notification from the LSP. This represents an
400-
/// asynchronous event that the LSP is notifying the client about.
401-
///
402-
/// When this event occurs, the client should:
403-
/// 1. Check `signature_valid` to confirm the notification is authentic
404-
/// 2. Examine the `notification.method` to determine the type of notification
405-
/// 3. Process the notification according to its method and parameters
406-
/// 4. Update any UI or take actions based on the notification type
407-
///
408-
/// Common notification methods include:
409-
/// - [`LSPS5WebhookRegistered`] - Initial test notification after registration
410-
/// - [`LSPS5PaymentIncoming`] - Client has pending incoming payments
411-
/// - [`LSPS5ExpirySoon`] - An HTLC or contract will expire soon
412-
/// - [`LSPS5LiquidityManagementRequest`] - LSP needs to manage liquidity
413-
/// - [`LSPS5OnionMessageIncoming`] - Client has pending onion messages
414-
///
415-
/// The client should reject notifications with invalid signatures or timestamps
416-
/// more than 10 minutes from the current time.
417-
///
418-
/// [`LSPS5WebhookRegistered`]: super::msgs::WebhookNotificationMethod::LSPS5WebhookRegistered
419-
/// [`LSPS5PaymentIncoming`]: super::msgs::WebhookNotificationMethod::LSPS5PaymentIncoming
420-
/// [`LSPS5ExpirySoon`]: super::msgs::WebhookNotificationMethod::LSPS5ExpirySoon
421-
/// [`LSPS5LiquidityManagementRequest`]: super::msgs::WebhookNotificationMethod::LSPS5LiquidityManagementRequest
422-
/// [`LSPS5OnionMessageIncoming`]: super::msgs::WebhookNotificationMethod::LSPS5OnionMessageIncoming
423-
WebhookNotificationReceived {
424-
/// LSP node ID that sent the notification.
425-
counterparty_node_id: PublicKey,
426-
/// The notification with its method and parameters.
427-
notification: WebhookNotification,
428-
/// Timestamp of the notification.
429-
timestamp: LSPSDateTime,
430-
/// Whether the LSP's signature was successfully verified.
431-
signature_valid: bool,
432-
},
433395
}

0 commit comments

Comments
 (0)