Skip to content

Commit ae2d248

Browse files
committed
WIP: Include blinded paths
1 parent 0198e49 commit ae2d248

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub(crate) mod utils;
1515

1616
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1717

18+
use core::ops::Deref;
1819
use crate::ln::msgs::DecodeError;
1920
use crate::offers::invoice::BlindedPayInfo;
2021
use crate::sign::EntropySource;
@@ -61,10 +62,9 @@ impl BlindedPath {
6162
///
6263
/// Errors if less than one hop is provided or if `node_pk`(s) are invalid.
6364
// TODO: make all payloads the same size with padding + add dummy hops
64-
pub fn new_for_message<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>
65-
(node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1<T>) -> Result<Self, ()>
66-
{
67-
if node_pks.is_empty() { return Err(()) }
65+
pub fn new_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
66+
node_pks: &[PublicKey], entropy_source: ES, secp_ctx: &Secp256k1<T>
67+
) -> Result<Self, ()> where ES::Target: EntropySource {
6868
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
6969
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
7070
let introduction_node_id = node_pks[0];

lightning/src/ln/channelmanager.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use bitcoin::secp256k1::{SecretKey,PublicKey};
3030
use bitcoin::secp256k1::Secp256k1;
3131
use bitcoin::{LockTime, secp256k1, Sequence};
3232

33+
use crate::blinded_path::BlindedPath;
3334
use crate::chain;
3435
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
3536
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
@@ -6708,6 +6709,9 @@ where
67086709
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
67096710
/// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer.
67106711
///
6712+
/// Uses a one-hop [`BlindedPath`] for the offer with [`ChannelManager::get_our_node_id`] as the
6713+
/// introduction node and a derived signing pubkey for recipient privacy.
6714+
///
67116715
/// [`Offer`]: crate::offers::offer::Offer
67126716
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
67136717
pub fn create_offer_builder(
@@ -6717,16 +6721,25 @@ where
67176721
let expanded_key = &self.inbound_payment_key;
67186722
let entropy = &*self.entropy_source;
67196723
let secp_ctx = &self.secp_ctx;
6724+
let builder = OfferBuilder::deriving_signing_pubkey(
6725+
description, node_id, expanded_key, entropy, secp_ctx
6726+
);
67206727

6721-
// TODO: Set blinded paths
6722-
OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
6728+
match self.create_one_hop_blinded_path() {
6729+
Ok(path) => builder.path(path),
6730+
// TODO: check if node is public?
6731+
Err(_) => builder,
6732+
}
67236733
}
67246734

67256735
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
67266736
/// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
67276737
///
67286738
/// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
67296739
///
6740+
/// Uses a one-hop [`BlindedPath`] for the refund with [`ChannelManager::get_our_node_id`] as
6741+
/// the introduction node and a derived payer id for sender privacy.
6742+
///
67306743
/// [`Refund`]: crate::offers::refund::Refund
67316744
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
67326745
pub fn create_refund_builder(
@@ -6737,10 +6750,14 @@ where
67376750
let entropy = &*self.entropy_source;
67386751
let secp_ctx = &self.secp_ctx;
67396752

6740-
// TODO: Set blinded paths
67416753
let builder = RefundBuilder::deriving_payer_id(
67426754
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
67436755
)?;
6756+
let builder = match self.create_one_hop_blinded_path() {
6757+
Ok(path) => builder.path(path),
6758+
// TODO: check if node is public?
6759+
Err(_) => builder,
6760+
};
67446761
self.pending_outbound_payments
67456762
.add_new_awaiting_invoice(payment_id, retry_strategy)
67466763
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
@@ -6873,6 +6890,15 @@ where
68736890
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
68746891
}
68756892

6893+
/// Creates a one-hop blinded path with [`ChannelManager::get_our_node_id`] as the introduction
6894+
/// node.
6895+
fn create_one_hop_blinded_path(&self) -> Result<BlindedPath, ()> {
6896+
let entropy_source = self.entropy_source.deref();
6897+
let secp_ctx = &self.secp_ctx;
6898+
BlindedPath::new_for_message(&[self.get_our_node_id()], entropy_source, secp_ctx)
6899+
6900+
}
6901+
68766902
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
68776903
/// are used when constructing the phantom invoice's route hints.
68786904
///

lightning/src/routing/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub trait Router {
9090
&self, payer: &PublicKey, route_params: &RouteParameters,
9191
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
9292
) -> Result<Route, LightningError>;
93+
9394
/// Finds a [`Route`] for a payment between the given `payer` and a payee.
9495
///
9596
/// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]

0 commit comments

Comments
 (0)