@@ -36,6 +36,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
36
36
37
37
use core:: mem;
38
38
use core:: ops:: Deref ;
39
+ use core:: time:: Duration ;
39
40
40
41
/// A blinded path to be used for sending or receiving a message, hiding the identity of the
41
42
/// recipient.
@@ -343,6 +344,47 @@ pub enum OffersContext {
343
344
/// [`Offer`]: crate::offers::offer::Offer
344
345
nonce : Nonce ,
345
346
} ,
347
+ /// Context used by a [`BlindedMessagePath`] within the [`Offer`] of an async recipient on behalf
348
+ /// of whom we are serving [`StaticInvoice`]s.
349
+ ///
350
+ /// This variant is intended to be received when handling an [`InvoiceRequest`] on behalf of said
351
+ /// async recipient.
352
+ ///
353
+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
354
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
355
+ StaticInvoiceRequested {
356
+ /// An identifier for the async recipient for whom we are serving [`StaticInvoice`]s. Used to
357
+ /// look up a corresponding [`StaticInvoice`] to return to the payer if the recipient is offline.
358
+ ///
359
+ /// Also useful to rate limit the number of [`InvoiceRequest`]s we will respond to on
360
+ /// 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 that we sent.
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 us and causing us to unintentionally
376
+ /// hit our 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
+ } ,
346
388
/// Context used by a [`BlindedMessagePath`] within a [`Refund`] or as a reply path for an
347
389
/// [`InvoiceRequest`].
348
390
///
@@ -460,6 +502,43 @@ pub enum AsyncPaymentsContext {
460
502
/// is no longer configured to accept paths from them.
461
503
path_absolute_expiry : core:: time:: Duration ,
462
504
} ,
505
+ /// Context used by a reply path to an [`OfferPaths`] message, provided back to us in
506
+ /// corresponding [`ServeStaticInvoice`] messages.
507
+ ///
508
+ /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
509
+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
510
+ ServeStaticInvoice {
511
+ /// An identifier for the async recipient that is requesting that a [`StaticInvoice`] be served
512
+ /// on their behalf.
513
+ ///
514
+ /// Useful as a key to retrieve the invoice when payers send an [`InvoiceRequest`] over the
515
+ /// paths that we previously created for the recipient's [`Offer::paths`]. Also useful to rate
516
+ /// limit the invoices being persisted on behalf of a particular recipient.
517
+ ///
518
+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
519
+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
520
+ /// [`Offer::paths`]: crate::offers::offer::Offer::paths
521
+ recipient_id_nonce : Nonce ,
522
+ /// A nonce used for authenticating that a [`ServeStaticInvoice`] message is valid for a preceding
523
+ /// [`OfferPaths`] message.
524
+ ///
525
+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
526
+ /// [`OfferPaths`]: crate::onion_message::async_payments::OfferPaths
527
+ nonce : Nonce ,
528
+ /// Authentication code for the [`ServeStaticInvoice`] message.
529
+ ///
530
+ /// Prevents nodes from creating their own blinded path to us and causing us to persist an
531
+ /// unintended [`StaticInvoice`].
532
+ ///
533
+ /// [`ServeStaticInvoice`]: crate::onion_message::async_payments::ServeStaticInvoice
534
+ /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
535
+ hmac : Hmac < Sha256 > ,
536
+ /// The time as duration since the Unix epoch at which this path expires and messages sent over
537
+ /// it should be ignored.
538
+ ///
539
+ /// Useful to timeout async recipients that are no longer supported as clients.
540
+ path_absolute_expiry : core:: time:: Duration ,
541
+ } ,
463
542
/// Context used by a reply path to a [`ServeStaticInvoice`] message, provided back to us in
464
543
/// corresponding [`StaticInvoicePersisted`] messages.
465
544
///
@@ -581,6 +660,12 @@ impl_writeable_tlv_based_enum!(OffersContext,
581
660
( 1 , nonce, required) ,
582
661
( 2 , hmac, required)
583
662
} ,
663
+ ( 3 , StaticInvoiceRequested ) => {
664
+ ( 0 , recipient_id_nonce, required) ,
665
+ ( 2 , nonce, required) ,
666
+ ( 4 , hmac, required) ,
667
+ ( 6 , path_absolute_expiry, required) ,
668
+ } ,
584
669
) ;
585
670
586
671
impl_writeable_tlv_based_enum ! ( AsyncPaymentsContext ,
@@ -614,6 +699,12 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
614
699
( 2 , hmac, required) ,
615
700
( 4 , path_absolute_expiry, required) ,
616
701
} ,
702
+ ( 5 , ServeStaticInvoice ) => {
703
+ ( 0 , recipient_id_nonce, required) ,
704
+ ( 2 , nonce, required) ,
705
+ ( 4 , hmac, required) ,
706
+ ( 6 , path_absolute_expiry, required) ,
707
+ } ,
617
708
) ;
618
709
619
710
/// Contains a simple nonce for use in a blinded path's context.
0 commit comments