@@ -36,6 +36,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
3636
3737use core:: mem;
3838use core:: ops:: Deref ;
39+ use core:: time:: Duration ;
3940
4041/// A blinded path to be used for sending or receiving a message, hiding the identity of the
4142/// recipient.
@@ -343,6 +344,47 @@ pub enum OffersContext {
343344 /// [`Offer`]: crate::offers::offer::Offer
344345 nonce : Nonce ,
345346 } ,
347+ /// Context used by a [`BlindedMessagePath`] within the [`Offer`] of an async recipient.
348+ ///
349+ /// This variant is received by the static invoice server when handling an [`InvoiceRequest`] on
350+ /// behalf of said async recipient.
351+ ///
352+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
353+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
354+ StaticInvoiceRequested {
355+ /// An identifier for the async recipient for whom the static invoice server is serving
356+ /// [`StaticInvoice`]s. Used to look up a corresponding [`StaticInvoice`] to return to the payer
357+ /// if the recipient is offline.
358+ ///
359+ /// Also useful for the server to rate limit the number of [`InvoiceRequest`]s it will respond
360+ /// to on recipient's behalf.
361+ ///
362+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
363+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
364+ recipient_id_nonce : Nonce ,
365+
366+ /// A nonce used for authenticating that a received [`InvoiceRequest`] is valid for a preceding
367+ /// [`OfferPaths`] message sent by the static invoice server.
368+ ///
369+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
370+ /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
371+ nonce : Nonce ,
372+
373+ /// Authentication code for the [`InvoiceRequest`].
374+ ///
375+ /// Prevents nodes from creating their own blinded path to the static invoice server and causing
376+ /// them to unintentionally hit their database looking for a [`StaticInvoice`] to return.
377+ ///
378+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
379+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
380+ hmac : Hmac < Sha256 > ,
381+
382+ /// The time as duration since the Unix epoch at which this path expires and messages sent over
383+ /// it should be ignored.
384+ ///
385+ /// Useful to timeout async recipients that are no longer supported as clients.
386+ path_absolute_expiry : Duration ,
387+ } ,
346388 /// Context used by a [`BlindedMessagePath`] within a [`Refund`] or as a reply path for an
347389 /// [`InvoiceRequest`].
348390 ///
@@ -459,6 +501,43 @@ pub enum AsyncPaymentsContext {
459501 /// offer paths if we are no longer configured to accept paths from them.
460502 path_absolute_expiry : core:: time:: Duration ,
461503 } ,
504+ /// Context used by a reply path to an [`OfferPaths`] message, provided back to the static invoice
505+ /// server in corresponding [`ServeStaticInvoice`] messages.
506+ ///
507+ /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
508+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
509+ ServeStaticInvoice {
510+ /// An identifier for the async recipient that is requesting that a [`StaticInvoice`] be served
511+ /// on their behalf.
512+ ///
513+ /// Useful as a key to retrieve the invoice when payers send an [`InvoiceRequest`] to the static
514+ /// invoice server. Also useful to rate limit the invoices being persisted on behalf of a
515+ /// particular recipient.
516+ ///
517+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
518+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
519+ /// [`Offer::paths`]: crate::offers::offer::Offer::paths
520+ recipient_id_nonce : Nonce ,
521+ /// A nonce used for authenticating that a [`ServeStaticInvoice`] message is valid for a preceding
522+ /// [`OfferPaths`] message.
523+ ///
524+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
525+ /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
526+ nonce : Nonce ,
527+ /// Authentication code for the [`ServeStaticInvoice`] message.
528+ ///
529+ /// Prevents nodes from creating their own blinded path to the static invoice server and causing
530+ /// them to persist an unintended [`StaticInvoice`].
531+ ///
532+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
533+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
534+ hmac : Hmac < Sha256 > ,
535+ /// The time as duration since the Unix epoch at which this path expires and messages sent over
536+ /// it should be ignored.
537+ ///
538+ /// Useful to timeout async recipients that are no longer supported as clients.
539+ path_absolute_expiry : core:: time:: Duration ,
540+ } ,
462541 /// Context used by a reply path to a [`ServeStaticInvoice`] message, provided back to us in
463542 /// corresponding [`StaticInvoicePersisted`] messages.
464543 ///
@@ -580,6 +659,12 @@ impl_writeable_tlv_based_enum!(OffersContext,
580659 ( 1 , nonce, required) ,
581660 ( 2 , hmac, required)
582661 } ,
662+ ( 3 , StaticInvoiceRequested ) => {
663+ ( 0 , recipient_id_nonce, required) ,
664+ ( 2 , nonce, required) ,
665+ ( 4 , hmac, required) ,
666+ ( 6 , path_absolute_expiry, required) ,
667+ } ,
583668) ;
584669
585670impl_writeable_tlv_based_enum ! ( AsyncPaymentsContext ,
@@ -613,6 +698,12 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
613698 ( 2 , hmac, required) ,
614699 ( 4 , path_absolute_expiry, required) ,
615700 } ,
701+ ( 5 , ServeStaticInvoice ) => {
702+ ( 0 , recipient_id_nonce, required) ,
703+ ( 2 , nonce, required) ,
704+ ( 4 , hmac, required) ,
705+ ( 6 , path_absolute_expiry, required) ,
706+ } ,
616707) ;
617708
618709/// Contains a simple nonce for use in a blinded path's context.
0 commit comments