@@ -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 ///
@@ -438,6 +476,41 @@ pub enum AsyncPaymentsContext {
438476 /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
439477 path_absolute_expiry : core:: time:: Duration ,
440478 } ,
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+ } ,
441514 /// Context used by a reply path to a [`ServeStaticInvoice`] message, provided back to us in
442515 /// corresponding [`StaticInvoicePersisted`] messages.
443516 ///
@@ -526,6 +599,11 @@ impl_writeable_tlv_based_enum!(OffersContext,
526599 ( 1 , nonce, required) ,
527600 ( 2 , hmac, required)
528601 } ,
602+ ( 3 , StaticInvoiceRequested ) => {
603+ ( 0 , recipient_id, required) ,
604+ ( 2 , invoice_id, required) ,
605+ ( 4 , path_absolute_expiry, required) ,
606+ } ,
529607) ;
530608
531609impl_writeable_tlv_based_enum ! ( AsyncPaymentsContext ,
@@ -550,6 +628,11 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
550628 ( 0 , recipient_id, required) ,
551629 ( 2 , path_absolute_expiry, option) ,
552630 } ,
631+ ( 5 , ServeStaticInvoice ) => {
632+ ( 0 , recipient_id, required) ,
633+ ( 2 , invoice_id, required) ,
634+ ( 4 , path_absolute_expiry, required) ,
635+ } ,
553636) ;
554637
555638/// Contains a simple nonce for use in a blinded path's context.
0 commit comments