@@ -543,24 +543,6 @@ pub trait Verification {
543543 ) -> Result<(), ()>;
544544}
545545
546- impl Verification for PaymentHash {
547- /// Constructs an HMAC to include in [`OffersContext::InboundPayment`] for the payment hash
548- /// along with the given [`Nonce`].
549- fn hmac_for_offer_payment(
550- &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
551- ) -> Hmac<Sha256> {
552- signer::hmac_for_payment_hash(*self, nonce, expanded_key)
553- }
554-
555- /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
556- /// [`OffersContext::InboundPayment`].
557- fn verify_for_offer_payment(
558- &self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
559- ) -> Result<(), ()> {
560- signer::verify_payment_hash(*self, hmac, nonce, expanded_key)
561- }
562- }
563-
564546impl Verification for UnauthenticatedReceiveTlvs {
565547 fn hmac_for_offer_payment(
566548 &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
@@ -585,42 +567,6 @@ pub struct PaymentId(pub [u8; Self::LENGTH]);
585567impl PaymentId {
586568 /// Number of bytes in the id.
587569 pub const LENGTH: usize = 32;
588-
589- /// Constructs an HMAC to include in [`AsyncPaymentsContext::OutboundPayment`] for the payment id
590- /// along with the given [`Nonce`].
591- #[cfg(async_payments)]
592- pub fn hmac_for_async_payment(
593- &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
594- ) -> Hmac<Sha256> {
595- signer::hmac_for_async_payment_id(*self, nonce, expanded_key)
596- }
597-
598- /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
599- /// [`AsyncPaymentsContext::OutboundPayment`].
600- #[cfg(async_payments)]
601- pub fn verify_for_async_payment(
602- &self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
603- ) -> Result<(), ()> {
604- signer::verify_async_payment_id(*self, hmac, nonce, expanded_key)
605- }
606- }
607-
608- impl Verification for PaymentId {
609- /// Constructs an HMAC to include in [`OffersContext::OutboundPayment`] for the payment id
610- /// along with the given [`Nonce`].
611- fn hmac_for_offer_payment(
612- &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
613- ) -> Hmac<Sha256> {
614- signer::hmac_for_offer_payment_id(*self, nonce, expanded_key)
615- }
616-
617- /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
618- /// [`OffersContext::OutboundPayment`].
619- fn verify_for_offer_payment(
620- &self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
621- ) -> Result<(), ()> {
622- signer::verify_offer_payment_id(*self, hmac, nonce, expanded_key)
623- }
624570}
625571
626572impl PaymentId {
@@ -5276,10 +5222,7 @@ where
52765222 },
52775223 };
52785224
5279- let entropy = &*self.entropy_source;
5280-
52815225 let enqueue_held_htlc_available_res = self.flow.enqueue_held_htlc_available(
5282- entropy,
52835226 invoice,
52845227 payment_id,
52855228 self.get_peers_for_blinded_path(),
@@ -11228,7 +11171,7 @@ where
1122811171
1122911172 let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
1123011173
11231- self.flow.enqueue_invoice(entropy, invoice.clone(), refund, self.get_peers_for_blinded_path())?;
11174+ self.flow.enqueue_invoice(invoice.clone(), refund, self.get_peers_for_blinded_path())?;
1123211175
1123311176 Ok(invoice)
1123411177 },
@@ -13199,8 +13142,6 @@ where
1319913142 fn handle_message(
1320013143 &self, message: OffersMessage, context: Option<OffersContext>, responder: Option<Responder>,
1320113144 ) -> Option<(OffersMessage, ResponseInstruction)> {
13202- let expanded_key = &self.inbound_payment_key;
13203-
1320413145 macro_rules! handle_pay_invoice_res {
1320513146 ($res: expr, $invoice: expr, $logger: expr) => {{
1320613147 let error = match $res {
@@ -13306,38 +13247,26 @@ where
1330613247 #[cfg(async_payments)]
1330713248 OffersMessage::StaticInvoice(invoice) => {
1330813249 let payment_id = match context {
13309- Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
13310- if payment_id.verify_for_offer_payment(hmac, nonce, expanded_key).is_err() {
13311- return None
13312- }
13313- payment_id
13314- },
13250+ Some(OffersContext::OutboundPayment { payment_id, .. }) => payment_id,
1331513251 _ => return None
1331613252 };
1331713253 let res = self.initiate_async_payment(&invoice, payment_id);
1331813254 handle_pay_invoice_res!(res, invoice, self.logger);
1331913255 },
1332013256 OffersMessage::InvoiceError(invoice_error) => {
1332113257 let payment_hash = match context {
13322- Some(OffersContext::InboundPayment { payment_hash, nonce, hmac }) => {
13323- match payment_hash.verify_for_offer_payment(hmac, nonce, expanded_key) {
13324- Ok(_) => Some(payment_hash),
13325- Err(_) => None,
13326- }
13327- },
13258+ Some(OffersContext::InboundPayment { payment_hash }) => Some(payment_hash),
1332813259 _ => None,
1332913260 };
1333013261
1333113262 let logger = WithContext::from(&self.logger, None, None, payment_hash);
1333213263 log_trace!(logger, "Received invoice_error: {}", invoice_error);
1333313264
1333413265 match context {
13335- Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
13336- if let Ok(()) = payment_id.verify_for_offer_payment(hmac, nonce, expanded_key) {
13337- self.abandon_payment_with_reason(
13338- payment_id, PaymentFailureReason::InvoiceRequestRejected,
13339- );
13340- }
13266+ Some(OffersContext::OutboundPayment { payment_id, .. }) => {
13267+ self.abandon_payment_with_reason(
13268+ payment_id, PaymentFailureReason::InvoiceRequestRejected,
13269+ );
1334113270 },
1334213271 _ => {},
1334313272 }
@@ -13390,15 +13319,18 @@ where
1339013319 fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {
1339113320 #[cfg(async_payments)]
1339213321 {
13393- if let Ok(payment_id) = self.flow.verify_outbound_async_payment_context(_context) {
13394- if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
13395- log_trace!(
13396- self.logger,
13397- "Failed to release held HTLC with payment id {}: {:?}",
13398- payment_id,
13399- e
13400- );
13401- }
13322+ let payment_id = match _context {
13323+ AsyncPaymentsContext::OutboundPayment { payment_id } => payment_id,
13324+ _ => return,
13325+ };
13326+
13327+ if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
13328+ log_trace!(
13329+ self.logger,
13330+ "Failed to release held HTLC with payment id {}: {:?}",
13331+ payment_id,
13332+ e
13333+ );
1340213334 }
1340313335 }
1340413336 }
0 commit comments