Skip to content

Commit

Permalink
Test async receive
Browse files Browse the repository at this point in the history
In the previous commit we completed support for async receive from an
always-online sender to an often-offline receiver, minus support for acting as
the async receiver's always-online channel counterparty.
  • Loading branch information
valentinewallace committed Jan 9, 2025
1 parent d19ebae commit 6f7fcba
Show file tree
Hide file tree
Showing 5 changed files with 733 additions and 84 deletions.
26 changes: 17 additions & 9 deletions lightning/src/blinded_path/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use bitcoin::hashes::hmac::Hmac;
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
use bitcoin::secp256k1::ecdh::SharedSecret;

use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NodeIdLookUp};
use crate::blinded_path::utils;
Expand Down Expand Up @@ -170,15 +171,8 @@ impl BlindedPaymentPath {
NL::Target: NodeIdLookUp,
T: secp256k1::Signing + secp256k1::Verification,
{
let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &self.inner_path.blinding_point, None)?;
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
let encrypted_control_tlvs = &self.inner_path.blinded_hops.get(0).ok_or(())?.encrypted_payload;
let mut s = Cursor::new(encrypted_control_tlvs);
let mut reader = FixedLengthReader::new(&mut s, encrypted_control_tlvs.len() as u64);
match ChaChaPolyReadAdapter::read(&mut reader, rho) {
Ok(ChaChaPolyReadAdapter {
readable: BlindedPaymentTlvs::Forward(ForwardTlvs { short_channel_id, .. })
}) => {
match self.decrypt_intro_payload::<NS>(node_signer) {
Ok((BlindedPaymentTlvs::Forward(ForwardTlvs { short_channel_id, .. }), control_tlvs_ss)) => {
let next_node_id = match node_id_lookup.next_node_id(short_channel_id) {
Some(node_id) => node_id,
None => return Err(()),
Expand All @@ -195,6 +189,20 @@ impl BlindedPaymentPath {
}
}

pub(crate) fn decrypt_intro_payload<NS: Deref>(
&self, node_signer: &NS
) -> Result<(BlindedPaymentTlvs, SharedSecret), ()> where NS::Target: NodeSigner {
let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &self.inner_path.blinding_point, None)?;
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
let encrypted_control_tlvs = &self.inner_path.blinded_hops.get(0).ok_or(())?.encrypted_payload;
let mut s = Cursor::new(encrypted_control_tlvs);
let mut reader = FixedLengthReader::new(&mut s, encrypted_control_tlvs.len() as u64);
match ChaChaPolyReadAdapter::read(&mut reader, rho) {
Ok(ChaChaPolyReadAdapter { readable, .. }) => Ok((readable, control_tlvs_ss)),
_ => Err(())
}
}

pub(crate) fn inner_blinded_path(&self) -> &BlindedPath {
&self.inner_path
}
Expand Down
Loading

0 comments on commit 6f7fcba

Please sign in to comment.