@@ -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, ReceiveTlvs};
@@ -438,11 +438,15 @@ impl Ord for ClaimableHTLC {
438
438
pub trait Verification {
439
439
/// Constructs an HMAC to include in [`OffersContext`] for the data along with the given
440
440
/// [`Nonce`].
441
+ ///
442
+ /// [`OffersContext`]: crate::blinded_path::message::OffersContext
441
443
fn hmac_for_offer_payment(
442
444
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
443
445
) -> Hmac<Sha256>;
444
446
445
447
/// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`].
448
+ ///
449
+ /// [`OffersContext`]: crate::blinded_path::message::OffersContext
446
450
fn verify_for_offer_payment(
447
451
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
448
452
) -> Result<(), ()>;
@@ -451,6 +455,8 @@ pub trait Verification {
451
455
impl Verification for PaymentHash {
452
456
/// Constructs an HMAC to include in [`OffersContext::InboundPayment`] for the payment hash
453
457
/// along with the given [`Nonce`].
458
+ ///
459
+ /// [`OffersContext::InboundPayment`]: crate::blinded_path::message::OffersContext::InboundPayment
454
460
fn hmac_for_offer_payment(
455
461
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
456
462
) -> Hmac<Sha256> {
@@ -459,6 +465,8 @@ impl Verification for PaymentHash {
459
465
460
466
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
461
467
/// [`OffersContext::InboundPayment`].
468
+ ///
469
+ /// [`OffersContext::InboundPayment`]: crate::blinded_path::message::OffersContext::InboundPayment
462
470
fn verify_for_offer_payment(
463
471
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
464
472
) -> Result<(), ()> {
@@ -499,6 +507,8 @@ impl PaymentId {
499
507
impl Verification for PaymentId {
500
508
/// Constructs an HMAC to include in [`OffersContext::OutboundPayment`] for the payment id
501
509
/// along with the given [`Nonce`].
510
+ ///
511
+ /// [`OffersContext::OutboundPayment`]: crate::blinded_path::message::OffersContext::OutboundPayment
502
512
fn hmac_for_offer_payment(
503
513
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
504
514
) -> Hmac<Sha256> {
@@ -507,6 +517,8 @@ impl Verification for PaymentId {
507
517
508
518
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
509
519
/// [`OffersContext::OutboundPayment`].
520
+ ///
521
+ /// [`OffersContext::OutboundPayment`]: crate::blinded_path::message::OffersContext::OutboundPayment
510
522
fn verify_for_offer_payment(
511
523
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
512
524
) -> Result<(), ()> {
@@ -4376,35 +4388,6 @@ where
4376
4388
self.pending_outbound_payments.test_set_payment_metadata(payment_id, new_payment_metadata);
4377
4389
}
4378
4390
4379
- /// Pays the [`Bolt12Invoice`] associated with the `payment_id` encoded in its `payer_metadata`.
4380
- ///
4381
- /// The invoice's `payer_metadata` is used to authenticate that the invoice was indeed requested
4382
- /// before attempting a payment. [`Bolt12PaymentError::UnexpectedInvoice`] is returned if this
4383
- /// fails or if the encoded `payment_id` is not recognized. The latter may happen once the
4384
- /// payment is no longer tracked because the payment was attempted after:
4385
- /// - an invoice for the `payment_id` was already paid,
4386
- /// - one full [timer tick] has elapsed since initially requesting the invoice when paying an
4387
- /// offer, or
4388
- /// - the refund corresponding to the invoice has already expired.
4389
- ///
4390
- /// To retry the payment, request another invoice using a new `payment_id`.
4391
- ///
4392
- /// Attempting to pay the same invoice twice while the first payment is still pending will
4393
- /// result in a [`Bolt12PaymentError::DuplicateInvoice`].
4394
- ///
4395
- /// Otherwise, either [`Event::PaymentSent`] or [`Event::PaymentFailed`] are used to indicate
4396
- /// whether or not the payment was successful.
4397
- ///
4398
- /// [timer tick]: Self::timer_tick_occurred
4399
- pub fn send_payment_for_bolt12_invoice(
4400
- &self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
4401
- ) -> Result<(), Bolt12PaymentError> {
4402
- match self.verify_bolt12_invoice(invoice, context) {
4403
- Ok(payment_id) => self.send_payment_for_verified_bolt12_invoice(invoice, payment_id),
4404
- Err(()) => Err(Bolt12PaymentError::UnexpectedInvoice),
4405
- }
4406
- }
4407
-
4408
4391
#[cfg(async_payments)]
4409
4392
fn initiate_async_payment(
4410
4393
&self, invoice: &StaticInvoice, payment_id: PaymentId
@@ -9528,15 +9511,10 @@ pub trait OffersMessageCommons {
9528
9511
/// Get the vector of peers that can be used for a blinded path
9529
9512
fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode>;
9530
9513
9531
- /// Verify bolt12 invoice
9532
- fn verify_bolt12_invoice(
9533
- &self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
9534
- ) -> Result<PaymentId, ()>;
9535
-
9536
9514
/// Gets the current configuration applied to all new channels.
9537
9515
fn get_current_default_configuration(&self) -> &UserConfig;
9538
9516
9539
- /// Send payment for verified bolt12 invoice
9517
+ /// Send Payment for verified BOLT12 Invoice
9540
9518
fn send_payment_for_verified_bolt12_invoice(&self, invoice: &Bolt12Invoice, payment_id: PaymentId) -> Result<(), Bolt12PaymentError>;
9541
9519
9542
9520
/// Add new pending event
@@ -9658,31 +9636,15 @@ where
9658
9636
.collect::<Vec<_>>()
9659
9637
}
9660
9638
9661
- fn verify_bolt12_invoice(
9662
- &self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
9663
- ) -> Result<PaymentId, ()> {
9664
- let secp_ctx = &self.secp_ctx;
9665
- let expanded_key = &self.inbound_payment_key;
9666
-
9667
- match context {
9668
- None if invoice.is_for_refund_without_paths() => {
9669
- invoice.verify_using_metadata(expanded_key, secp_ctx)
9670
- },
9671
- Some(&OffersContext::OutboundPayment { payment_id, nonce, .. }) => {
9672
- invoice.verify_using_payer_data(payment_id, nonce, expanded_key, secp_ctx)
9673
- },
9674
- _ => Err(()),
9675
- }
9676
- }
9677
-
9678
9639
fn get_current_default_configuration(&self) -> &UserConfig {
9679
9640
&self.default_configuration
9680
9641
}
9681
9642
9682
9643
fn send_payment_for_verified_bolt12_invoice(&self, invoice: &Bolt12Invoice, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> {
9683
9644
let best_block_height = self.best_block.read().unwrap().height;
9684
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9685
9645
let features = self.bolt12_invoice_features();
9646
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9647
+
9686
9648
self.pending_outbound_payments
9687
9649
.send_payment_for_bolt12_invoice(
9688
9650
invoice, payment_id, &self.router, self.list_usable_channels(), features,
0 commit comments