@@ -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};
@@ -6591,6 +6592,10 @@ where
6591
6592
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
6592
6593
/// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer.
6593
6594
///
6595
+ /// Uses [`Router::find_partial_paths`] to construct a [`BlindedPath`] for the offer. If one is
6596
+ /// found, also uses a derived signing pubkey for recipient privacy. Otherwise, uses the node id
6597
+ /// as the signing pubkey.
6598
+ ///
6594
6599
/// [`Offer`]: crate::offers::offer::Offer
6595
6600
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
6596
6601
pub fn create_offer_builder(
@@ -6600,16 +6605,26 @@ where
6600
6605
let expanded_key = &self.inbound_payment_key;
6601
6606
let entropy = &*self.entropy_source;
6602
6607
let secp_ctx = &self.secp_ctx;
6608
+ let builder = OfferBuilder::deriving_signing_pubkey(
6609
+ description, node_id, expanded_key, entropy, secp_ctx
6610
+ );
6603
6611
6604
- // TODO: Set blinded paths
6605
- OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
6612
+ match self.create_blinded_paths(1) {
6613
+ Ok(paths) if !paths.is_empty() => builder.path(paths.into_iter().next().unwrap()),
6614
+ // TODO: check if node is public?
6615
+ Ok(_) | Err(_) => builder,
6616
+ }
6606
6617
}
6607
6618
6608
6619
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
6609
6620
/// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
6610
6621
///
6611
6622
/// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
6612
6623
///
6624
+ /// Uses [`Router::find_partial_paths`] to construct a [`BlindedPath`] for the refund. If one is
6625
+ /// found, also uses a derived payer id for sender privacy. Otherwise, uses the node id as the
6626
+ /// payer id.
6627
+ ///
6613
6628
/// [`Refund`]: crate::offers::refund::Refund
6614
6629
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
6615
6630
pub fn create_refund_builder(
@@ -6620,10 +6635,14 @@ where
6620
6635
let entropy = &*self.entropy_source;
6621
6636
let secp_ctx = &self.secp_ctx;
6622
6637
6623
- // TODO: Set blinded paths
6624
6638
let builder = RefundBuilder::deriving_payer_id(
6625
6639
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
6626
6640
)?;
6641
+ let builder = match self.create_blinded_paths(1) {
6642
+ Ok(paths) if !paths.is_empty() => builder.path(paths.into_iter().next().unwrap()),
6643
+ // TODO: check if node is public?
6644
+ Ok(_) | Err(_) => builder,
6645
+ };
6627
6646
self.pending_outbound_payments
6628
6647
.add_new_awaiting_invoice(payment_id, retry_strategy)
6629
6648
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
@@ -6756,6 +6775,23 @@ where
6756
6775
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
6757
6776
}
6758
6777
6778
+ ///
6779
+ fn create_blinded_paths(&self, count: usize) -> Result<Vec<BlindedPath>, ()> {
6780
+ let last_hops = self.per_peer_state.read().unwrap().iter()
6781
+ .filter(|(_, peer)| peer.lock().unwrap().latest_features.supports_route_blinding())
6782
+ .map(|(node_id, _)| *node_id)
6783
+ .collect::<Vec<_>>();
6784
+ let entropy_source = self.entropy_source.deref();
6785
+ let secp_ctx = &self.secp_ctx;
6786
+
6787
+ self.router
6788
+ .find_partial_paths(self.get_our_node_id(), last_hops.as_slice())?
6789
+ .into_iter()
6790
+ .map(|node_pks| BlindedPath::new_for_message(&node_pks[..], entropy_source, secp_ctx))
6791
+ .take(count)
6792
+ .collect()
6793
+ }
6794
+
6759
6795
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
6760
6796
/// are used when constructing the phantom invoice's route hints.
6761
6797
///
0 commit comments