@@ -58,6 +58,7 @@ use crate::offers::invoice_request::InvoiceRequestBuilder;
58
58
use crate :: offers:: offer:: { Offer , OfferBuilder } ;
59
59
use crate :: offers:: parse:: SemanticError ;
60
60
use crate :: offers:: refund:: RefundBuilder ;
61
+ use crate :: onion_message:: BlindedPath ;
61
62
use crate :: util:: config:: { UserConfig , ChannelConfig } ;
62
63
use crate :: util:: events:: { Event , EventHandler , EventsProvider , MessageSendEvent , MessageSendEventsProvider , ClosureReason , HTLCDestination } ;
63
64
use crate :: util:: events;
@@ -5434,6 +5435,10 @@ where
5434
5435
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
5435
5436
/// [`OnionMessenger`] when handling [`InvoiceRequest`] messages for the offer.
5436
5437
///
5438
+ /// Uses [`Router::find_partial_paths`] to construct a [`BlindedPath`] for the offer. If one is
5439
+ /// found, also uses a derived signing pubkey for recipient privacy. Otherwise, uses the node id
5440
+ /// as the signing pubkey.
5441
+ ///
5437
5442
/// [`Offer`]: crate::offers::offer::Offer
5438
5443
/// [`OnionMessenger`]: crate::onion_message::OnionMessenger
5439
5444
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
@@ -5442,13 +5447,25 @@ where
5442
5447
let expanded_key = & self . inbound_payment_key ;
5443
5448
let nonce = inbound_payment:: Nonce :: from_entropy_source ( & * self . entropy_source ) ;
5444
5449
5445
- // TODO: Set blinded paths
5446
- OfferBuilder :: deriving_signing_pubkey ( description, node_id, expanded_key, nonce)
5450
+ match self . create_blinded_paths ( 1 ) {
5451
+ Ok ( paths) if !paths. is_empty ( ) => {
5452
+ OfferBuilder :: deriving_signing_pubkey ( description, node_id, expanded_key, nonce)
5453
+ . path ( paths. into_iter ( ) . next ( ) . unwrap ( ) )
5454
+ } ,
5455
+ // TODO: check if node is public?
5456
+ Ok ( _) | Err ( _) => {
5457
+ OfferBuilder :: deriving_signing_pubkey ( description, node_id, expanded_key, nonce)
5458
+ } ,
5459
+ }
5447
5460
}
5448
5461
5449
5462
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
5450
5463
/// [`OnionMessenger`] when handling [`Invoice`] messages for the refund.
5451
5464
///
5465
+ /// Uses [`Router::find_partial_paths`] to construct a [`BlindedPath`] for the refund. If one is
5466
+ /// found, also uses a derived payer id for sender privacy. Otherwise, uses the node id as the
5467
+ /// payer id.
5468
+ ///
5452
5469
/// [`Refund`]: crate::offers::refund::Refund
5453
5470
/// [`OnionMessenger`]: crate::onion_message::OnionMessenger
5454
5471
/// [`Invoice`]: crate::offers::invoice::Invoice
@@ -5459,8 +5476,21 @@ where
5459
5476
let expanded_key = & self . inbound_payment_key ;
5460
5477
let nonce = inbound_payment:: Nonce :: from_entropy_source ( & * self . entropy_source ) ;
5461
5478
5462
- // TODO: Set blinded paths
5463
- RefundBuilder :: deriving_payer_id ( description, node_id, expanded_key, nonce, amount_msats)
5479
+ let builder = match self . create_blinded_paths ( 1 ) {
5480
+ Ok ( paths) if !paths. is_empty ( ) => {
5481
+ RefundBuilder :: deriving_payer_id (
5482
+ description, node_id, expanded_key, nonce, amount_msats
5483
+ ) ?. path ( paths. into_iter ( ) . next ( ) . unwrap ( ) )
5484
+ } ,
5485
+ // TODO: check if node is public?
5486
+ Ok ( _) | Err ( _) => {
5487
+ RefundBuilder :: deriving_payer_id (
5488
+ description, node_id, expanded_key, nonce, amount_msats
5489
+ ) ?
5490
+ } ,
5491
+ } ;
5492
+
5493
+ Ok ( builder)
5464
5494
}
5465
5495
5466
5496
/// Creates an [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is
@@ -5608,6 +5638,23 @@ where
5608
5638
inbound_payment:: get_payment_preimage ( payment_hash, payment_secret, & self . inbound_payment_key )
5609
5639
}
5610
5640
5641
+ ///
5642
+ fn create_blinded_paths ( & self , count : usize ) -> Result < Vec < BlindedPath > , ( ) > {
5643
+ let last_hops = self . per_peer_state . read ( ) . unwrap ( ) . iter ( )
5644
+ . filter ( |( _, peer) | peer. lock ( ) . unwrap ( ) . latest_features . supports_route_blinding ( ) )
5645
+ . map ( |( node_id, _) | * node_id)
5646
+ . collect :: < Vec < _ > > ( ) ;
5647
+ let entropy_source = self . entropy_source . deref ( ) ;
5648
+ let secp_ctx = & self . secp_ctx ;
5649
+
5650
+ self . router
5651
+ . find_partial_paths ( self . get_our_node_id ( ) , last_hops. as_slice ( ) ) ?
5652
+ . into_iter ( )
5653
+ . map ( |node_pks| BlindedPath :: without_id ( & node_pks[ ..] , entropy_source, secp_ctx) )
5654
+ . take ( count)
5655
+ . collect ( )
5656
+ }
5657
+
5611
5658
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
5612
5659
/// are used when constructing the phantom invoice's route hints.
5613
5660
///
0 commit comments