@@ -310,6 +310,29 @@ impl<MR: Deref> OffersMessageFlow<MR>
310310where
311311 MR :: Target : MessageRouter ,
312312{
313+ /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
314+ /// to pay us.
315+ ///
316+ /// See [`ChannelManager::create_inbound_payment`] for more details.
317+ ///
318+ /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
319+ pub fn create_inbound_payment < ES : Deref > (
320+ & self , entropy_source : ES , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 ,
321+ min_final_cltv_expiry_delta : Option < u16 > ,
322+ ) -> Result < ( PaymentHash , PaymentSecret ) , ( ) >
323+ where
324+ ES :: Target : EntropySource ,
325+ {
326+ inbound_payment:: create (
327+ & self . inbound_payment_key ,
328+ min_value_msat,
329+ invoice_expiry_delta_secs,
330+ & entropy_source,
331+ self . highest_seen_timestamp . load ( Ordering :: Acquire ) as u64 ,
332+ min_final_cltv_expiry_delta,
333+ )
334+ }
335+
313336 /// Verifies an [`InvoiceRequest`] using the provided [`OffersContext`] or the invoice request's own metadata.
314337 ///
315338 /// - If an [`OffersContext::InvoiceRequest`] with a `nonce` is provided, verification is performed using recipient context data.
@@ -726,8 +749,8 @@ where
726749 ///
727750 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
728751 pub fn create_invoice_builder_from_refund < ' a , ES : Deref , R : Deref > (
729- & ' a self , router : & R , entropy_source : ES , refund : & ' a Refund , payment_hash : PaymentHash ,
730- payment_secret : PaymentSecret , usable_channels : Vec < ChannelDetails > ,
752+ & ' a self , router : & R , entropy_source : ES , refund : & ' a Refund ,
753+ usable_channels : Vec < ChannelDetails > ,
731754 ) -> Result < InvoiceBuilder < ' a , DerivedSigningPubkey > , Bolt12SemanticError >
732755 where
733756 ES :: Target : EntropySource ,
@@ -743,6 +766,10 @@ where
743766 let amount_msats = refund. amount_msats ( ) ;
744767 let relative_expiry = DEFAULT_RELATIVE_EXPIRY . as_secs ( ) as u32 ;
745768
769+ let ( payment_hash, payment_secret) = self
770+ . create_inbound_payment ( entropy, Some ( amount_msats) , relative_expiry, None )
771+ . map_err ( |_| Bolt12SemanticError :: InvalidAmount ) ?;
772+
746773 let payment_context = PaymentContext :: Bolt12Refund ( Bolt12RefundContext { } ) ;
747774 let payment_paths = self
748775 . create_blinded_payment_paths (
@@ -788,19 +815,27 @@ where
788815 /// - We fail to generate a valid signed [`Bolt12Invoice`] for the [`InvoiceRequest`].
789816 pub fn create_response_for_invoice_request < ES : Deref , NS : Deref , R : Deref > (
790817 & self , signer : & NS , router : & R , entropy_source : ES ,
791- invoice_request : VerifiedInvoiceRequest , amount_msats : u64 , payment_hash : PaymentHash ,
792- payment_secret : PaymentSecret , usable_channels : Vec < ChannelDetails > ,
818+ invoice_request : VerifiedInvoiceRequest , amount_msats : u64 ,
819+ usable_channels : Vec < ChannelDetails > ,
793820 ) -> ( OffersMessage , Option < MessageContext > )
794821 where
795822 ES :: Target : EntropySource ,
796823 NS :: Target : NodeSigner ,
797824 R :: Target : Router ,
798825 {
799- let expanded_key = & self . inbound_payment_key ;
800826 let entropy = & * entropy_source;
827+ let expanded_key = & self . inbound_payment_key ;
801828 let secp_ctx = & self . secp_ctx ;
802829
803830 let relative_expiry = DEFAULT_RELATIVE_EXPIRY . as_secs ( ) as u32 ;
831+ let ( payment_hash, payment_secret) =
832+ match self . create_inbound_payment ( entropy, Some ( amount_msats) , relative_expiry, None ) {
833+ Ok ( ( payment_hash, payment_secret) ) => ( payment_hash, payment_secret) ,
834+ Err ( ( ) ) => {
835+ let error = Bolt12SemanticError :: InvalidAmount ;
836+ return ( OffersMessage :: InvoiceError ( error. into ( ) ) , None ) ;
837+ } ,
838+ } ;
804839
805840 let context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext {
806841 offer_id : invoice_request. offer_id ,
0 commit comments