@@ -35,6 +35,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
3535
3636use core:: mem;
3737use core:: ops:: Deref ;
38+ use core:: time:: Duration ;
3839
3940/// A blinded path to be used for sending or receiving a message, hiding the identity of the
4041/// recipient.
@@ -342,6 +343,43 @@ pub enum OffersContext {
342343 /// [`Offer`]: crate::offers::offer::Offer
343344 nonce : Nonce ,
344345 } ,
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+ } ,
345383 /// Context used by a [`BlindedMessagePath`] within a [`Refund`] or as a reply path for an
346384 /// [`InvoiceRequest`].
347385 ///
@@ -405,6 +443,24 @@ pub enum OffersContext {
405443/// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage
406444#[ derive( Clone , Debug ) ]
407445pub 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+ } ,
408464 /// Context used by a reply path to an [`OfferPathsRequest`], provided back to us as an async
409465 /// recipient in corresponding [`OfferPaths`] messages from the static invoice server.
410466 ///
@@ -420,6 +476,41 @@ pub enum AsyncPaymentsContext {
420476 /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
421477 path_absolute_expiry : core:: time:: Duration ,
422478 } ,
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+ } ,
423514 /// Context used by a reply path to a [`ServeStaticInvoice`] message, provided back to us in
424515 /// corresponding [`StaticInvoicePersisted`] messages.
425516 ///
@@ -508,6 +599,11 @@ impl_writeable_tlv_based_enum!(OffersContext,
508599 ( 1 , nonce, required) ,
509600 ( 2 , hmac, required)
510601 } ,
602+ ( 3 , StaticInvoiceRequested ) => {
603+ ( 0 , recipient_id, required) ,
604+ ( 2 , invoice_id, required) ,
605+ ( 4 , path_absolute_expiry, required) ,
606+ } ,
511607) ;
512608
513609impl_writeable_tlv_based_enum ! ( AsyncPaymentsContext ,
@@ -528,6 +624,15 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
528624 ( 0 , offer_id, required) ,
529625 ( 2 , path_absolute_expiry, required) ,
530626 } ,
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+ } ,
531636) ;
532637
533638/// Contains a simple nonce for use in a blinded path's context.
0 commit comments