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