Skip to content

Commit

Permalink
Include a one-hop blinded path in Offer and Refund
Browse files Browse the repository at this point in the history
While this doesn't add much privacy over not including any blinded
paths, it allows us to exercise code for receiving on blinded paths.
  • Loading branch information
jkczyz committed Oct 18, 2023
1 parent 1059231 commit 7bf0469
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lightning/src/blinded_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct BlindedHop {

impl BlindedPath {
/// Create a one-hop blinded path for a message.
pub fn one_hop_for_message<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
pub fn one_hop_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
recipient_node_id: PublicKey, entropy_source: &ES, secp_ctx: &Secp256k1<T>
) -> Result<Self, ()> {
Self::new_for_message(&[recipient_node_id], entropy_source, secp_ctx)
Expand All @@ -68,7 +68,7 @@ impl BlindedPath {
///
/// Errors if no hops are provided or if `node_pk`(s) are invalid.
// TODO: make all payloads the same size with padding + add dummy hops
pub fn new_for_message<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
pub fn new_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1<T>
) -> Result<Self, ()> {
if node_pks.is_empty() { return Err(()) }
Expand Down
27 changes: 24 additions & 3 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use bitcoin::secp256k1::{SecretKey,PublicKey};
use bitcoin::secp256k1::Secp256k1;
use bitcoin::{LockTime, secp256k1, Sequence};

use crate::blinded_path::BlindedPath;
use crate::chain;
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
Expand Down Expand Up @@ -7093,6 +7094,11 @@ where
/// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer. The offer will
/// not have an expiration unless otherwise set on the builder.
///
/// Uses a one-hop [`BlindedPath`] for the offer with [`ChannelManager::get_our_node_id`] as the
/// introduction node and a derived signing pubkey for recipient privacy. As such, currently,
/// the node must be announced. Otherwise, there is no way to find a path to the introduction
/// node in order to send the [`InvoiceRequest`].
///
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
Expand All @@ -7102,10 +7108,11 @@ where
let expanded_key = &self.inbound_payment_key;
let entropy = &*self.entropy_source;
let secp_ctx = &self.secp_ctx;
let path = self.create_one_hop_blinded_path();

// TODO: Set blinded paths
OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
.chain_hash(self.chain_hash)
.path(path)
}

/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
Expand All @@ -7115,6 +7122,11 @@ where
///
/// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
///
/// Uses a one-hop [`BlindedPath`] for the refund with [`ChannelManager::get_our_node_id`] as
/// the introduction node and a derived payer id for sender privacy. As such, currently, the
/// node must be announced. Otherwise, there is no way to find a path to the introduction node
/// in order to send the [`Bolt12Invoice`].
///
/// [`Refund`]: crate::offers::refund::Refund
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
pub fn create_refund_builder(
Expand All @@ -7125,13 +7137,14 @@ where
let expanded_key = &self.inbound_payment_key;
let entropy = &*self.entropy_source;
let secp_ctx = &self.secp_ctx;
let path = self.create_one_hop_blinded_path();

// TODO: Set blinded paths
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash(self.chain_hash)
.absolute_expiry(absolute_expiry);
.absolute_expiry(absolute_expiry)
.path(path);

self.pending_outbound_payments
.add_new_awaiting_invoice(
Expand Down Expand Up @@ -7242,6 +7255,14 @@ where
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
}

/// Creates a one-hop blinded path with [`ChannelManager::get_our_node_id`] as the introduction
/// node.
fn create_one_hop_blinded_path(&self) -> BlindedPath {
let entropy_source = self.entropy_source.deref();
let secp_ctx = &self.secp_ctx;
BlindedPath::one_hop_for_message(self.get_our_node_id(), entropy_source, secp_ctx).unwrap()
}

/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
/// are used when constructing the phantom invoice's route hints.
///
Expand Down
1 change: 1 addition & 0 deletions lightning/src/routing/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub trait Router {
&self, payer: &PublicKey, route_params: &RouteParameters,
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
) -> Result<Route, LightningError>;

/// Finds a [`Route`] for a payment between the given `payer` and a payee.
///
/// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
Expand Down

0 comments on commit 7bf0469

Please sign in to comment.