@@ -30,6 +30,7 @@ use bitcoin::secp256k1::{SecretKey,PublicKey};
30
30
use bitcoin:: secp256k1:: Secp256k1 ;
31
31
use bitcoin:: { LockTime , secp256k1, Sequence } ;
32
32
33
+ use crate :: blinded_path:: BlindedPath ;
33
34
use crate :: chain;
34
35
use crate :: chain:: { Confirm , ChannelMonitorUpdateStatus , Watch , BestBlock } ;
35
36
use crate :: chain:: chaininterface:: { BroadcasterInterface , ConfirmationTarget , FeeEstimator , LowerBoundedFeeEstimator } ;
@@ -5741,6 +5742,10 @@ where
5741
5742
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
5742
5743
/// [`OnionMessenger`] when handling [`InvoiceRequest`] messages for the offer.
5743
5744
///
5745
+ /// Uses [`Router::find_partial_paths`] to construct a [`BlindedPath`] for the offer. If one is
5746
+ /// found, also uses a derived signing pubkey for recipient privacy. Otherwise, uses the node id
5747
+ /// as the signing pubkey.
5748
+ ///
5744
5749
/// [`Offer`]: crate::offers::offer::Offer
5745
5750
/// [`OnionMessenger`]: crate::onion_message::OnionMessenger
5746
5751
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
@@ -5751,14 +5756,24 @@ where
5751
5756
let expanded_key = & self . inbound_payment_key ;
5752
5757
let entropy = & * self . entropy_source ;
5753
5758
let secp_ctx = & self . secp_ctx ;
5759
+ let builder = OfferBuilder :: deriving_signing_pubkey (
5760
+ description, node_id, expanded_key, entropy, secp_ctx
5761
+ ) ;
5754
5762
5755
- // TODO: Set blinded paths
5756
- OfferBuilder :: deriving_signing_pubkey ( description, node_id, expanded_key, entropy, secp_ctx)
5763
+ match self . create_blinded_paths ( 1 ) {
5764
+ Ok ( paths) if !paths. is_empty ( ) => builder. path ( paths. into_iter ( ) . next ( ) . unwrap ( ) ) ,
5765
+ // TODO: check if node is public?
5766
+ Ok ( _) | Err ( _) => builder,
5767
+ }
5757
5768
}
5758
5769
5759
5770
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
5760
5771
/// [`OnionMessenger`] when handling [`Invoice`] messages for the refund.
5761
5772
///
5773
+ /// Uses [`Router::find_partial_paths`] to construct a [`BlindedPath`] for the refund. If one is
5774
+ /// found, also uses a derived payer id for sender privacy. Otherwise, uses the node id as the
5775
+ /// payer id.
5776
+ ///
5762
5777
/// [`Refund`]: crate::offers::refund::Refund
5763
5778
/// [`OnionMessenger`]: crate::onion_message::OnionMessenger
5764
5779
/// [`Invoice`]: crate::offers::invoice::Invoice
@@ -5769,11 +5784,15 @@ where
5769
5784
let expanded_key = & self . inbound_payment_key ;
5770
5785
let entropy = & * self . entropy_source ;
5771
5786
let secp_ctx = & self . secp_ctx ;
5772
-
5773
- // TODO: Set blinded paths
5774
- RefundBuilder :: deriving_payer_id (
5787
+ let builder = RefundBuilder :: deriving_payer_id (
5775
5788
description, node_id, expanded_key, entropy, secp_ctx, amount_msats
5776
- )
5789
+ ) ?;
5790
+
5791
+ match self . create_blinded_paths ( 1 ) {
5792
+ Ok ( paths) if !paths. is_empty ( ) => Ok ( builder. path ( paths. into_iter ( ) . next ( ) . unwrap ( ) ) ) ,
5793
+ // TODO: check if node is public?
5794
+ Ok ( _) | Err ( _) => Ok ( builder) ,
5795
+ }
5777
5796
}
5778
5797
5779
5798
/// Creates an [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is
@@ -5923,6 +5942,23 @@ where
5923
5942
inbound_payment:: get_payment_preimage ( payment_hash, payment_secret, & self . inbound_payment_key )
5924
5943
}
5925
5944
5945
+ ///
5946
+ fn create_blinded_paths ( & self , count : usize ) -> Result < Vec < BlindedPath > , ( ) > {
5947
+ let last_hops = self . per_peer_state . read ( ) . unwrap ( ) . iter ( )
5948
+ . filter ( |( _, peer) | peer. lock ( ) . unwrap ( ) . latest_features . supports_route_blinding ( ) )
5949
+ . map ( |( node_id, _) | * node_id)
5950
+ . collect :: < Vec < _ > > ( ) ;
5951
+ let entropy_source = self . entropy_source . deref ( ) ;
5952
+ let secp_ctx = & self . secp_ctx ;
5953
+
5954
+ self . router
5955
+ . find_partial_paths ( self . get_our_node_id ( ) , last_hops. as_slice ( ) ) ?
5956
+ . into_iter ( )
5957
+ . map ( |node_pks| BlindedPath :: new_for_message ( & node_pks[ ..] , entropy_source, secp_ctx) )
5958
+ . take ( count)
5959
+ . collect ( )
5960
+ }
5961
+
5926
5962
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
5927
5963
/// are used when constructing the phantom invoice's route hints.
5928
5964
///
0 commit comments