@@ -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.
@@ -331,6 +332,47 @@ pub enum OffersContext {
331332 /// [`Offer`]: crate::offers::offer::Offer
332333 nonce : Nonce ,
333334 } ,
335+ /// Context used by a [`BlindedMessagePath`] within the [`Offer`] of an async recipient on behalf
336+ /// of whom we are serving [`StaticInvoice`]s.
337+ ///
338+ /// This variant is intended to be received when handling an [`InvoiceRequest`] on behalf of said
339+ /// async recipient.
340+ ///
341+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
342+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
343+ StaticInvoiceRequested {
344+ /// An identifier for the async recipient for whom we are serving [`StaticInvoice`]s. Used to
345+ /// look up a corresponding [`StaticInvoice`] to return to the payer if the recipient is offline.
346+ ///
347+ /// Also useful to rate limit the number of [`InvoiceRequest`]s we will respond to on
348+ /// recipient's behalf.
349+ ///
350+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
351+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
352+ recipient_id_nonce : Nonce ,
353+
354+ /// A nonce used for authenticating that a received [`InvoiceRequest`] is valid for a preceding
355+ /// [`OfferPaths`] message that we sent.
356+ ///
357+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
358+ /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
359+ nonce : Nonce ,
360+
361+ /// Authentication code for the [`InvoiceRequest`].
362+ ///
363+ /// Prevents nodes from creating their own blinded path to us and causing us to unintentionally
364+ /// hit our database looking for a [`StaticInvoice`] to return.
365+ ///
366+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
367+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
368+ hmac : Hmac < Sha256 > ,
369+
370+ /// The time as duration since the Unix epoch at which this path expires and messages sent over
371+ /// it should be ignored.
372+ ///
373+ /// Useful to timeout async recipients that are no longer supported as clients.
374+ path_absolute_expiry : Duration ,
375+ } ,
334376 /// Context used by a [`BlindedMessagePath`] within a [`Refund`] or as a reply path for an
335377 /// [`InvoiceRequest`].
336378 ///
@@ -448,6 +490,43 @@ pub enum AsyncPaymentsContext {
448490 /// is no longer configured to accept paths from them.
449491 path_absolute_expiry : core:: time:: Duration ,
450492 } ,
493+ /// Context used by a reply path to an [`OfferPaths`] message, provided back to us in
494+ /// corresponding [`ServeStaticInvoice`] messages.
495+ ///
496+ /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
497+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
498+ ServeStaticInvoice {
499+ /// An identifier for the async recipient that is requesting that a [`StaticInvoice`] be served
500+ /// on their behalf.
501+ ///
502+ /// Useful as a key to retrieve the invoice when payers send an [`InvoiceRequest`] over the
503+ /// paths that we previously created for the recipient's [`Offer::paths`]. Also useful to rate
504+ /// limit the invoices being persisted on behalf of a particular recipient.
505+ ///
506+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
507+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
508+ /// [`Offer::paths`]: crate::offers::offer::Offer::paths
509+ recipient_id_nonce : Nonce ,
510+ /// A nonce used for authenticating that a [`ServeStaticInvoice`] message is valid for a preceding
511+ /// [`OfferPaths`] message.
512+ ///
513+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
514+ /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
515+ nonce : Nonce ,
516+ /// Authentication code for the [`ServeStaticInvoice`] message.
517+ ///
518+ /// Prevents nodes from creating their own blinded path to us and causing us to persist an
519+ /// unintended [`StaticInvoice`].
520+ ///
521+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
522+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
523+ hmac : Hmac < Sha256 > ,
524+ /// The time as duration since the Unix epoch at which this path expires and messages sent over
525+ /// it should be ignored.
526+ ///
527+ /// Useful to timeout async recipients that are no longer supported as clients.
528+ path_absolute_expiry : core:: time:: Duration ,
529+ } ,
451530 /// Context used by a reply path to a [`ServeStaticInvoice`] message, provided back to us in
452531 /// corresponding [`StaticInvoicePersisted`] messages.
453532 ///
@@ -549,6 +628,12 @@ impl_writeable_tlv_based_enum!(OffersContext,
549628 ( 1 , nonce, required) ,
550629 ( 2 , hmac, required)
551630 } ,
631+ ( 3 , StaticInvoiceRequested ) => {
632+ ( 0 , recipient_id_nonce, required) ,
633+ ( 2 , nonce, required) ,
634+ ( 4 , hmac, required) ,
635+ ( 6 , path_absolute_expiry, required) ,
636+ } ,
552637) ;
553638
554639impl_writeable_tlv_based_enum ! ( AsyncPaymentsContext ,
@@ -578,6 +663,12 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
578663 ( 2 , hmac, required) ,
579664 ( 4 , path_absolute_expiry, required) ,
580665 } ,
666+ ( 5 , ServeStaticInvoice ) => {
667+ ( 0 , recipient_id_nonce, required) ,
668+ ( 2 , nonce, required) ,
669+ ( 4 , hmac, required) ,
670+ ( 6 , path_absolute_expiry, required) ,
671+ } ,
581672) ;
582673
583674/// Contains a simple nonce for use in a blinded path's context.
0 commit comments