@@ -10623,36 +10623,41 @@ where
1062310623				}
1062410624			},
1062510625			OffersMessage::Invoice(invoice) => {
10626- 				let expected_payment_id  = match context {
10626+ 				let payer_data  = match context {
1062710627					OffersContext::Unknown {} if invoice.is_for_refund_without_paths() => None,
10628- 					OffersContext::OutboundPayment { payment_id, ..  } => Some(payment_id),
10628+ 					OffersContext::OutboundPayment { payment_id, nonce  } => Some(( payment_id, nonce) ),
1062910629					_ => return ResponseInstruction::NoResponse,
1063010630				};
1063110631
10632- 				let result = match invoice.verify(expanded_key, secp_ctx) {
10633- 					Ok(payment_id) => {
10634- 						if let Some(expected_payment_id) = expected_payment_id {
10635- 							if payment_id != expected_payment_id {
10636- 								return ResponseInstruction::NoResponse;
10637- 							}
10638- 						}
10639- 
10640- 						let features = self.bolt12_invoice_features();
10641- 						if invoice.invoice_features().requires_unknown_bits_from(&features) {
10642- 							Err(InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures))
10643- 						} else if self.default_configuration.manually_handle_bolt12_invoices {
10644- 							let event = Event::InvoiceReceived { payment_id, invoice, responder };
10645- 							self.pending_events.lock().unwrap().push_back((event, None));
10646- 							return ResponseInstruction::NoResponse;
10632+ 				let (invoice, payment_id) = match payer_data {
10633+ 					Some((payment_id, nonce)) => {
10634+ 						if invoice.verify_using_payer_data(payment_id, nonce, expanded_key, secp_ctx) {
10635+ 							(invoice, payment_id)
1064710636						} else {
10648- 							self.send_payment_for_verified_bolt12_invoice(&invoice, payment_id)
10649- 								.map_err(|e| {
10650- 									log_trace!(self.logger, "Failed paying invoice: {:?}", e);
10651- 									InvoiceError::from_string(format!("{:?}", e))
10652- 								})
10637+ 							return ResponseInstruction::NoResponse;
1065310638						}
1065410639					},
10655- 					Err(()) => return ResponseInstruction::NoResponse,
10640+ 					None => match invoice.verify(expanded_key, secp_ctx) {
10641+ 						Ok(payment_id) => (invoice, payment_id),
10642+ 						Err(()) => return ResponseInstruction::NoResponse,
10643+ 					},
10644+ 				};
10645+ 
10646+ 				let result = {
10647+ 					let features = self.bolt12_invoice_features();
10648+ 					if invoice.invoice_features().requires_unknown_bits_from(&features) {
10649+ 						Err(InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures))
10650+ 					} else if self.default_configuration.manually_handle_bolt12_invoices {
10651+ 						let event = Event::InvoiceReceived { payment_id, invoice, responder };
10652+ 						self.pending_events.lock().unwrap().push_back((event, None));
10653+ 						return ResponseInstruction::NoResponse;
10654+ 					} else {
10655+ 						self.send_payment_for_verified_bolt12_invoice(&invoice, payment_id)
10656+ 							.map_err(|e| {
10657+ 								log_trace!(self.logger, "Failed paying invoice: {:?}", e);
10658+ 								InvoiceError::from_string(format!("{:?}", e))
10659+ 							})
10660+ 					}
1065610661				};
1065710662
1065810663				match result {
0 commit comments