@@ -35,6 +35,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
35
35
36
36
use core:: mem;
37
37
use core:: ops:: Deref ;
38
+ use core:: time:: Duration ;
38
39
39
40
/// A blinded path to be used for sending or receiving a message, hiding the identity of the
40
41
/// recipient.
@@ -342,6 +343,43 @@ pub enum OffersContext {
342
343
/// [`Offer`]: crate::offers::offer::Offer
343
344
nonce : Nonce ,
344
345
} ,
346
+ /// Context used by a [`BlindedMessagePath`] within the [`Offer`] of an async recipient.
347
+ ///
348
+ /// This variant is received by the static invoice server when handling an [`InvoiceRequest`] on
349
+ /// behalf of said async recipient.
350
+ ///
351
+ /// [`Offer`]: crate::offers::offer::Offer
352
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
353
+ StaticInvoiceRequested {
354
+ /// An identifier for the async recipient for whom we as a static invoice server are serving
355
+ /// [`StaticInvoice`]s. Used paired with the
356
+ /// [`OffersContext::StaticInvoiceRequested::invoice_id`] when looking up a corresponding
357
+ /// [`StaticInvoice`] to return to the payer if the recipient is offline. This id was previously
358
+ /// provided via [`AsyncPaymentsContext::ServeStaticInvoice::recipient_id`].
359
+ ///
360
+ /// Also useful for rate limiting the number of [`InvoiceRequest`]s we will respond to on
361
+ /// recipient's behalf.
362
+ ///
363
+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
364
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
365
+ recipient_id : Vec < u8 > ,
366
+
367
+ /// A random unique identifier for a specific [`StaticInvoice`] that the recipient previously
368
+ /// requested be served on their behalf. Useful when paired with the
369
+ /// [`OffersContext::StaticInvoiceRequested::recipient_id`] to pull that specific invoice from
370
+ /// the database when payers send an [`InvoiceRequest`]. This id was previously
371
+ /// provided via [`AsyncPaymentsContext::ServeStaticInvoice::invoice_id`].
372
+ ///
373
+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
374
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
375
+ invoice_id : u128 ,
376
+
377
+ /// The time as duration since the Unix epoch at which this path expires and messages sent over
378
+ /// it should be ignored.
379
+ ///
380
+ /// Useful to timeout async recipients that are no longer supported as clients.
381
+ path_absolute_expiry : Duration ,
382
+ } ,
345
383
/// Context used by a [`BlindedMessagePath`] within a [`Refund`] or as a reply path for an
346
384
/// [`InvoiceRequest`].
347
385
///
@@ -405,6 +443,24 @@ pub enum OffersContext {
405
443
/// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage
406
444
#[ derive( Clone , Debug ) ]
407
445
pub enum AsyncPaymentsContext {
446
+ /// Context used by a [`BlindedMessagePath`] provided out-of-band to an async recipient, where the
447
+ /// context is provided back to the static invoice server in corresponding [`OfferPathsRequest`]s.
448
+ ///
449
+ /// [`OfferPathsRequest`]: crate::onion_message::async_payments::OfferPathsRequest
450
+ OfferPathsRequest {
451
+ /// An identifier for the async recipient that is requesting blinded paths to include in their
452
+ /// [`Offer::paths`]. This ID will be surfaced when the async recipient eventually sends a
453
+ /// corresponding [`ServeStaticInvoice`] message, and can be used to rate limit the recipient.
454
+ ///
455
+ /// [`Offer::paths`]: crate::offers::offer::Offer::paths
456
+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
457
+ recipient_id : Vec < u8 > ,
458
+ /// An optional field indicating the time as duration since the Unix epoch at which this path
459
+ /// expires and messages sent over it should be ignored.
460
+ ///
461
+ /// Useful to timeout async recipients that are no longer supported as clients.
462
+ path_absolute_expiry : Option < core:: time:: Duration > ,
463
+ } ,
408
464
/// Context used by a reply path to an [`OfferPathsRequest`], provided back to us as an async
409
465
/// recipient in corresponding [`OfferPaths`] messages from the static invoice server.
410
466
///
@@ -420,6 +476,41 @@ pub enum AsyncPaymentsContext {
420
476
/// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
421
477
path_absolute_expiry : core:: time:: Duration ,
422
478
} ,
479
+ /// Context used by a reply path to an [`OfferPaths`] message, provided back to us as the static
480
+ /// invoice server in corresponding [`ServeStaticInvoice`] messages.
481
+ ///
482
+ /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
483
+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
484
+ ServeStaticInvoice {
485
+ /// An identifier for the async recipient that is requesting that a [`StaticInvoice`] be served
486
+ /// on their behalf.
487
+ ///
488
+ /// Useful when surfaced alongside the below `invoice_id` when payers send an
489
+ /// [`InvoiceRequest`], to pull the specific static invoice from the database.
490
+ ///
491
+ /// Also useful to rate limit the invoices being persisted on behalf of a particular recipient.
492
+ ///
493
+ /// This id will be provided back to us as the static invoice server via
494
+ /// [`OffersContext::StaticInvoiceRequested::recipient_id`].
495
+ ///
496
+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
497
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
498
+ recipient_id : Vec < u8 > ,
499
+ /// A random identifier for the specific [`StaticInvoice`] that the recipient is requesting be
500
+ /// served on their behalf. Useful when surfaced alongside the above `recipient_id` when payers
501
+ /// send an [`InvoiceRequest`], to pull the specific static invoice from the database. This id
502
+ /// will be provided back to us as the static invoice server via
503
+ /// [`OffersContext::StaticInvoiceRequested::invoice_id`].
504
+ ///
505
+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
506
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
507
+ invoice_id : u128 ,
508
+ /// The time as duration since the Unix epoch at which this path expires and messages sent over
509
+ /// it should be ignored.
510
+ ///
511
+ /// Useful to timeout async recipients that are no longer supported as clients.
512
+ path_absolute_expiry : core:: time:: Duration ,
513
+ } ,
423
514
/// Context used by a reply path to a [`ServeStaticInvoice`] message, provided back to us in
424
515
/// corresponding [`StaticInvoicePersisted`] messages.
425
516
///
@@ -508,6 +599,11 @@ impl_writeable_tlv_based_enum!(OffersContext,
508
599
( 1 , nonce, required) ,
509
600
( 2 , hmac, required)
510
601
} ,
602
+ ( 3 , StaticInvoiceRequested ) => {
603
+ ( 0 , recipient_id, required) ,
604
+ ( 2 , invoice_id, required) ,
605
+ ( 4 , path_absolute_expiry, required) ,
606
+ } ,
511
607
) ;
512
608
513
609
impl_writeable_tlv_based_enum ! ( AsyncPaymentsContext ,
@@ -528,6 +624,15 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
528
624
( 0 , offer_id, required) ,
529
625
( 2 , path_absolute_expiry, required) ,
530
626
} ,
627
+ ( 4 , OfferPathsRequest ) => {
628
+ ( 0 , recipient_id, required) ,
629
+ ( 2 , path_absolute_expiry, option) ,
630
+ } ,
631
+ ( 5 , ServeStaticInvoice ) => {
632
+ ( 0 , recipient_id, required) ,
633
+ ( 2 , invoice_id, required) ,
634
+ ( 4 , path_absolute_expiry, required) ,
635
+ } ,
531
636
) ;
532
637
533
638
/// Contains a simple nonce for use in a blinded path's context.
0 commit comments