@@ -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};
@@ -6708,6 +6709,10 @@ where
6708
6709
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
6709
6710
/// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer.
6710
6711
///
6712
+ /// Uses [`Router::find_partial_paths`] to construct a [`BlindedPath`] for the offer. If one is
6713
+ /// found, also uses a derived signing pubkey for recipient privacy. Otherwise, uses the node id
6714
+ /// as the signing pubkey.
6715
+ ///
6711
6716
/// [`Offer`]: crate::offers::offer::Offer
6712
6717
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6713
6718
pub fn create_offer_builder(
@@ -6717,16 +6722,26 @@ where
6717
6722
let expanded_key = &self.inbound_payment_key;
6718
6723
let entropy = &*self.entropy_source;
6719
6724
let secp_ctx = &self.secp_ctx;
6725
+ let builder = OfferBuilder::deriving_signing_pubkey(
6726
+ description, node_id, expanded_key, entropy, secp_ctx
6727
+ );
6720
6728
6721
- // TODO: Set blinded paths
6722
- OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
6729
+ match self.create_blinded_paths(1) {
6730
+ Ok(paths) if !paths.is_empty() => builder.path(paths.into_iter().next().unwrap()),
6731
+ // TODO: check if node is public?
6732
+ Ok(_) | Err(_) => builder,
6733
+ }
6723
6734
}
6724
6735
6725
6736
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
6726
6737
/// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
6727
6738
///
6728
6739
/// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
6729
6740
///
6741
+ /// Uses [`Router::find_partial_paths`] to construct a [`BlindedPath`] for the refund. If one is
6742
+ /// found, also uses a derived payer id for sender privacy. Otherwise, uses the node id as the
6743
+ /// payer id.
6744
+ ///
6730
6745
/// [`Refund`]: crate::offers::refund::Refund
6731
6746
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6732
6747
pub fn create_refund_builder(
@@ -6737,10 +6752,14 @@ where
6737
6752
let entropy = &*self.entropy_source;
6738
6753
let secp_ctx = &self.secp_ctx;
6739
6754
6740
- // TODO: Set blinded paths
6741
6755
let builder = RefundBuilder::deriving_payer_id(
6742
6756
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
6743
6757
)?;
6758
+ let builder = match self.create_blinded_paths(1) {
6759
+ Ok(paths) if !paths.is_empty() => builder.path(paths.into_iter().next().unwrap()),
6760
+ // TODO: check if node is public?
6761
+ Ok(_) | Err(_) => builder,
6762
+ };
6744
6763
self.pending_outbound_payments
6745
6764
.add_new_awaiting_invoice(payment_id, retry_strategy)
6746
6765
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
@@ -6873,6 +6892,23 @@ where
6873
6892
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
6874
6893
}
6875
6894
6895
+ ///
6896
+ fn create_blinded_paths(&self, count: usize) -> Result<Vec<BlindedPath>, ()> {
6897
+ let last_hops = self.per_peer_state.read().unwrap().iter()
6898
+ .filter(|(_, peer)| peer.lock().unwrap().latest_features.supports_route_blinding())
6899
+ .map(|(node_id, _)| *node_id)
6900
+ .collect::<Vec<_>>();
6901
+ let entropy_source = self.entropy_source.deref();
6902
+ let secp_ctx = &self.secp_ctx;
6903
+
6904
+ self.router
6905
+ .find_partial_paths(self.get_our_node_id(), last_hops.as_slice())?
6906
+ .into_iter()
6907
+ .map(|node_pks| BlindedPath::new_for_message(&node_pks[..], entropy_source, secp_ctx))
6908
+ .take(count)
6909
+ .collect()
6910
+ }
6911
+
6876
6912
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
6877
6913
/// are used when constructing the phantom invoice's route hints.
6878
6914
///
0 commit comments