@@ -308,6 +308,29 @@ impl<MR: Deref> OffersMessageFlow<MR>
308
308
where
309
309
MR :: Target : MessageRouter ,
310
310
{
311
+ /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
312
+ /// to pay us.
313
+ ///
314
+ /// See [`ChannelManager::create_inbound_payment`] for more details.
315
+ ///
316
+ /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
317
+ pub fn create_inbound_payment < ES : Deref > (
318
+ & self , entropy_source : ES , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ,
319
+ min_final_cltv_expiry_delta : Option < u16 > ,
320
+ ) -> Result < ( PaymentHash , PaymentSecret ) , ( ) >
321
+ where
322
+ ES :: Target : EntropySource ,
323
+ {
324
+ inbound_payment:: create (
325
+ & self . inbound_payment_key ,
326
+ min_value_msat,
327
+ invoice_expiry_delta_secs,
328
+ & entropy_source,
329
+ self . highest_seen_timestamp . load ( Ordering :: Acquire ) as u64 ,
330
+ min_final_cltv_expiry_delta,
331
+ )
332
+ }
333
+
311
334
/// Verifies an [`InvoiceRequest`] using the provided [`OffersContext`] or the invoice request's own metadata.
312
335
///
313
336
/// - If an [`OffersContext::InvoiceRequest`] with a `nonce` is provided, verification is performed using recipient context data.
@@ -708,8 +731,8 @@ where
708
731
///
709
732
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
710
733
pub fn create_invoice_builder_from_refund < ' a , ES : Deref , R : Deref > (
711
- & ' a self , router : & R , entropy_source : ES , refund : & ' a Refund , payment_hash : PaymentHash ,
712
- payment_secret : PaymentSecret , usable_channels : Vec < ChannelDetails > ,
734
+ & ' a self , router : & R , entropy_source : ES , refund : & ' a Refund ,
735
+ usable_channels : Vec < ChannelDetails > ,
713
736
) -> Result < InvoiceBuilder < ' a , DerivedSigningPubkey > , Bolt12SemanticError >
714
737
where
715
738
ES :: Target : EntropySource ,
@@ -721,6 +744,10 @@ where
721
744
let amount_msats = refund. amount_msats ( ) ;
722
745
let relative_expiry = DEFAULT_RELATIVE_EXPIRY . as_secs ( ) as u32 ;
723
746
747
+ let ( payment_hash, payment_secret) = self
748
+ . create_inbound_payment ( entropy, Some ( amount_msats) , relative_expiry, None )
749
+ . map_err ( |_| Bolt12SemanticError :: InvalidAmount ) ?;
750
+
724
751
let payment_context = PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ;
725
752
let payment_paths = self
726
753
. create_blinded_payment_paths (
@@ -766,19 +793,27 @@ where
766
793
/// - We fail to generate a valid signed [`Bolt12Invoice`] for the [`InvoiceRequest`].
767
794
pub fn create_response_for_invoice_request < ES : Deref , NS : Deref , R : Deref > (
768
795
& self , signer : & NS , router : & R , entropy_source : ES ,
769
- invoice_request : VerifiedInvoiceRequest , amount_msats : u64 , payment_hash : PaymentHash ,
770
- payment_secret : PaymentSecret , usable_channels : Vec < ChannelDetails > ,
796
+ invoice_request : VerifiedInvoiceRequest , amount_msats : u64 ,
797
+ usable_channels : Vec < ChannelDetails > ,
771
798
) -> ( OffersMessage , Option < MessageContext > )
772
799
where
773
800
ES :: Target : EntropySource ,
774
801
NS :: Target : NodeSigner ,
775
802
R :: Target : Router ,
776
803
{
777
- let expanded_key = & self . inbound_payment_key ;
778
804
let entropy = & * entropy_source;
805
+ let expanded_key = & self . inbound_payment_key ;
779
806
let secp_ctx = & self . secp_ctx ;
780
807
781
808
let relative_expiry = DEFAULT_RELATIVE_EXPIRY . as_secs ( ) as u32 ;
809
+ let ( payment_hash, payment_secret) =
810
+ match self . create_inbound_payment ( entropy, Some ( amount_msats) , relative_expiry, None ) {
811
+ Ok ( ( payment_hash, payment_secret) ) => ( payment_hash, payment_secret) ,
812
+ Err ( ( ) ) => {
813
+ let error = Bolt12SemanticError :: InvalidAmount ;
814
+ return ( OffersMessage :: InvoiceError ( error. into ( ) ) , None ) ;
815
+ } ,
816
+ } ;
782
817
783
818
let context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext {
784
819
offer_id : invoice_request. offer_id ,
0 commit comments