@@ -33,7 +33,7 @@ use bitcoin::secp256k1::Secp256k1;
33
33
use bitcoin::{secp256k1, Sequence, Weight};
34
34
35
35
use crate::events::FundingInfo;
36
- use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, MessageForwardNode, OffersContext };
36
+ use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, MessageForwardNode};
37
37
use crate::blinded_path::NodeIdLookUp;
38
38
use crate::blinded_path::message::BlindedMessagePath;
39
39
use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, UnauthenticatedReceiveTlvs};
@@ -443,11 +443,15 @@ impl Ord for ClaimableHTLC {
443
443
pub trait Verification {
444
444
/// Constructs an HMAC to include in [`OffersContext`] for the data along with the given
445
445
/// [`Nonce`].
446
+ ///
447
+ /// [`OffersContext`]: crate::blinded_path::message::OffersContext
446
448
fn hmac_for_offer_payment(
447
449
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
448
450
) -> Hmac<Sha256>;
449
451
450
452
/// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`].
453
+ ///
454
+ /// [`OffersContext`]: crate::blinded_path::message::OffersContext
451
455
fn verify_for_offer_payment(
452
456
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
453
457
) -> Result<(), ()>;
@@ -456,6 +460,8 @@ pub trait Verification {
456
460
impl Verification for PaymentHash {
457
461
/// Constructs an HMAC to include in [`OffersContext::InboundPayment`] for the payment hash
458
462
/// along with the given [`Nonce`].
463
+ ///
464
+ /// [`OffersContext::InboundPayment`]: crate::blinded_path::message::OffersContext::InboundPayment
459
465
fn hmac_for_offer_payment(
460
466
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
461
467
) -> Hmac<Sha256> {
@@ -464,6 +470,8 @@ impl Verification for PaymentHash {
464
470
465
471
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
466
472
/// [`OffersContext::InboundPayment`].
473
+ ///
474
+ /// [`OffersContext::InboundPayment`]: crate::blinded_path::message::OffersContext::InboundPayment
467
475
fn verify_for_offer_payment(
468
476
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
469
477
) -> Result<(), ()> {
@@ -518,6 +526,8 @@ impl PaymentId {
518
526
impl Verification for PaymentId {
519
527
/// Constructs an HMAC to include in [`OffersContext::OutboundPayment`] for the payment id
520
528
/// along with the given [`Nonce`].
529
+ ///
530
+ /// [`OffersContext::OutboundPayment`]: crate::blinded_path::message::OffersContext::OutboundPayment
521
531
fn hmac_for_offer_payment(
522
532
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
523
533
) -> Hmac<Sha256> {
@@ -526,6 +536,8 @@ impl Verification for PaymentId {
526
536
527
537
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
528
538
/// [`OffersContext::OutboundPayment`].
539
+ ///
540
+ /// [`OffersContext::OutboundPayment`]: crate::blinded_path::message::OffersContext::OutboundPayment
529
541
fn verify_for_offer_payment(
530
542
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
531
543
) -> Result<(), ()> {
@@ -4486,35 +4498,6 @@ where
4486
4498
self.pending_outbound_payments.test_set_payment_metadata(payment_id, new_payment_metadata);
4487
4499
}
4488
4500
4489
- /// Pays the [`Bolt12Invoice`] associated with the `payment_id` encoded in its `payer_metadata`.
4490
- ///
4491
- /// The invoice's `payer_metadata` is used to authenticate that the invoice was indeed requested
4492
- /// before attempting a payment. [`Bolt12PaymentError::UnexpectedInvoice`] is returned if this
4493
- /// fails or if the encoded `payment_id` is not recognized. The latter may happen once the
4494
- /// payment is no longer tracked because the payment was attempted after:
4495
- /// - an invoice for the `payment_id` was already paid,
4496
- /// - one full [timer tick] has elapsed since initially requesting the invoice when paying an
4497
- /// offer, or
4498
- /// - the refund corresponding to the invoice has already expired.
4499
- ///
4500
- /// To retry the payment, request another invoice using a new `payment_id`.
4501
- ///
4502
- /// Attempting to pay the same invoice twice while the first payment is still pending will
4503
- /// result in a [`Bolt12PaymentError::DuplicateInvoice`].
4504
- ///
4505
- /// Otherwise, either [`Event::PaymentSent`] or [`Event::PaymentFailed`] are used to indicate
4506
- /// whether or not the payment was successful.
4507
- ///
4508
- /// [timer tick]: Self::timer_tick_occurred
4509
- pub fn send_payment_for_bolt12_invoice(
4510
- &self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
4511
- ) -> Result<(), Bolt12PaymentError> {
4512
- match self.verify_bolt12_invoice(invoice, context) {
4513
- Ok(payment_id) => self.send_payment_for_verified_bolt12_invoice(invoice, payment_id),
4514
- Err(()) => Err(Bolt12PaymentError::UnexpectedInvoice),
4515
- }
4516
- }
4517
-
4518
4501
#[cfg(async_payments)]
4519
4502
fn send_payment_for_static_invoice(
4520
4503
&self, payment_id: PaymentId
@@ -9601,27 +9584,11 @@ where
9601
9584
.collect::<Vec<_>>()
9602
9585
}
9603
9586
9604
- fn verify_bolt12_invoice(
9605
- &self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
9606
- ) -> Result<PaymentId, ()> {
9607
- let secp_ctx = &self.secp_ctx;
9608
- let expanded_key = &self.inbound_payment_key;
9609
-
9610
- match context {
9611
- None if invoice.is_for_refund_without_paths() => {
9612
- invoice.verify_using_metadata(expanded_key, secp_ctx)
9613
- },
9614
- Some(&OffersContext::OutboundPayment { payment_id, nonce, .. }) => {
9615
- invoice.verify_using_payer_data(payment_id, nonce, expanded_key, secp_ctx)
9616
- },
9617
- _ => Err(()),
9618
- }
9619
- }
9620
-
9621
9587
fn send_payment_for_verified_bolt12_invoice(&self, invoice: &Bolt12Invoice, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> {
9622
9588
let best_block_height = self.best_block.read().unwrap().height;
9623
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9624
9589
let features = self.bolt12_invoice_features();
9590
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9591
+
9625
9592
self.pending_outbound_payments
9626
9593
.send_payment_for_bolt12_invoice(
9627
9594
invoice, payment_id, &self.router, self.list_usable_channels(), features,
0 commit comments