@@ -409,6 +409,38 @@ impl From<&ClaimableHTLC> for events::ClaimedHTLC {
409
409
}
410
410
}
411
411
412
+ /// A trait defining behavior for creating and verifing the HMAC for authenticating a given data.
413
+ pub trait Verification {
414
+ /// Constructs an HMAC to include in [`OffersContext`] for the data along with the given
415
+ /// [`Nonce`].
416
+ fn hmac_for_offer_payment(
417
+ &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
418
+ ) -> Hmac<Sha256>;
419
+
420
+ /// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`].
421
+ fn verify(
422
+ &self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
423
+ ) -> Result<(), ()>;
424
+ }
425
+
426
+ impl Verification for PaymentHash {
427
+ /// Constructs an HMAC to include in [`OffersContext::InboundPayment`] for the payment hash
428
+ /// along with the given [`Nonce`].
429
+ fn hmac_for_offer_payment(
430
+ &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
431
+ ) -> Hmac<Sha256> {
432
+ signer::hmac_for_payment_hash(*self, nonce, expanded_key)
433
+ }
434
+
435
+ /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
436
+ /// [`OffersContext::InboundPayment`].
437
+ fn verify(
438
+ &self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
439
+ ) -> Result<(), ()> {
440
+ signer::verify_payment_hash(*self, hmac, nonce, expanded_key)
441
+ }
442
+ }
443
+
412
444
/// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
413
445
/// a payment and ensure idempotency in LDK.
414
446
///
@@ -419,18 +451,20 @@ pub struct PaymentId(pub [u8; Self::LENGTH]);
419
451
impl PaymentId {
420
452
/// Number of bytes in the id.
421
453
pub const LENGTH: usize = 32;
454
+ }
422
455
456
+ impl Verification for PaymentId {
423
457
/// Constructs an HMAC to include in [`OffersContext::OutboundPayment`] for the payment id
424
458
/// along with the given [`Nonce`].
425
- pub fn hmac_for_offer_payment(
459
+ fn hmac_for_offer_payment(
426
460
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
427
461
) -> Hmac<Sha256> {
428
462
signer::hmac_for_payment_id(*self, nonce, expanded_key)
429
463
}
430
464
431
465
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
432
466
/// [`OffersContext::OutboundPayment`].
433
- pub fn verify(
467
+ fn verify(
434
468
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
435
469
) -> Result<(), ()> {
436
470
signer::verify_payment_id(*self, hmac, nonce, expanded_key)
0 commit comments