@@ -409,6 +409,38 @@ impl From<&ClaimableHTLC> for events::ClaimedHTLC {
409409 }
410410}
411411
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+
412444/// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
413445/// a payment and ensure idempotency in LDK.
414446///
@@ -419,18 +451,20 @@ pub struct PaymentId(pub [u8; Self::LENGTH]);
419451impl PaymentId {
420452 /// Number of bytes in the id.
421453 pub const LENGTH: usize = 32;
454+ }
422455
456+ impl Verification for PaymentId {
423457 /// Constructs an HMAC to include in [`OffersContext::OutboundPayment`] for the payment id
424458 /// along with the given [`Nonce`].
425- pub fn hmac_for_offer_payment(
459+ fn hmac_for_offer_payment(
426460 &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
427461 ) -> Hmac<Sha256> {
428462 signer::hmac_for_payment_id(*self, nonce, expanded_key)
429463 }
430464
431465 /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
432466 /// [`OffersContext::OutboundPayment`].
433- pub fn verify(
467+ fn verify(
434468 &self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
435469 ) -> Result<(), ()> {
436470 signer::verify_payment_id(*self, hmac, nonce, expanded_key)
0 commit comments