X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fonion_message%2Futils.rs;fp=lightning%2Fsrc%2Fonion_message%2Futils.rs;h=9b95183e74bb8bc549ca0a6f252522ae80e050f7;hb=9051c38ebe42e171fd0fcfa22d2b9ff6a1607b3b;hp=785a373caa4c80d7783dc062208af9da28e087b3;hpb=4c8dc2c2a0b9589298d937bf16061ae0ac99b31e;p=rust-lightning diff --git a/lightning/src/onion_message/utils.rs b/lightning/src/onion_message/utils.rs index 785a373c..9b95183e 100644 --- a/lightning/src/onion_message/utils.rs +++ b/lightning/src/onion_message/utils.rs @@ -16,14 +16,16 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey}; use bitcoin::secp256k1::ecdh::SharedSecret; use ln::onion_utils; +use super::blinded_route::BlindedRoute; +use super::messenger::Destination; use prelude::*; // TODO: DRY with onion_utils::construct_onion_keys_callback #[inline] pub(super) fn construct_keys_callback)>( - secp_ctx: &Secp256k1, unblinded_path: &[PublicKey], + FType: FnMut(PublicKey, SharedSecret, PublicKey, [u8; 32], Option, Option>)>( + secp_ctx: &Secp256k1, unblinded_path: &[PublicKey], destination: Option, session_priv: &SecretKey, mut callback: FType ) -> Result<(), secp256k1::Error> { let mut msg_blinding_point_priv = session_priv.clone(); @@ -32,7 +34,7 @@ pub(super) fn construct_keys_callback { + ($pk: expr, $blinded: expr, $encrypted_payload: expr) => {{ let encrypted_data_ss = SharedSecret::new(&$pk, &msg_blinding_point_priv); let blinded_hop_pk = if $blinded { $pk } else { @@ -49,7 +51,14 @@ pub(super) fn construct_keys_callback { + let (encrypted_data_ss, onion_packet_ss) = build_keys!($pk, $blinded, $encrypted_payload); let msg_blinding_point_blinding_factor = { let mut sha = Sha256::engine(); @@ -73,7 +82,19 @@ pub(super) fn construct_keys_callback { + build_keys!(pk, false, None); + }, + Destination::BlindedRoute(BlindedRoute { blinded_hops, .. }) => { + for hop in blinded_hops { + build_keys_in_loop!(hop.blinded_node_id, true, Some(hop.encrypted_payload)); + } + }, + } } Ok(()) }