From 51d9218f678a2f0887b96a0190aa9d5e0553c0dd Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Thu, 15 Aug 2024 18:06:46 -0500 Subject: [PATCH] Add a construct_keys_callback for blinded paths When constructing a BlindedPath, an Option parameter to construct_keys_callback is never passed. Make a separate utility function that doesn't take this parameter. This allows for using the build_keys_helper macro with a Iterator yielding items other than PublicKey. --- lightning/src/blinded_path/utils.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lightning/src/blinded_path/utils.rs b/lightning/src/blinded_path/utils.rs index f96df7014..860d91cfc 100644 --- a/lightning/src/blinded_path/utils.rs +++ b/lightning/src/blinded_path/utils.rs @@ -114,6 +114,23 @@ where Ok(()) } +#[inline] +pub(super) fn construct_keys_callback_for_blinded_path<'a, T, I, F>( + secp_ctx: &Secp256k1, unblinded_path: I, session_priv: &SecretKey, mut callback: F, +) -> Result<(), secp256k1::Error> +where + T: secp256k1::Signing + secp256k1::Verification, + I: Iterator, + F: FnMut(PublicKey, SharedSecret, PublicKey, [u8; 32], Option, Option>), +{ + build_keys_helper!(session_priv, secp_ctx, callback); + + for pk in unblinded_path { + build_keys_in_loop!(pk, false, None); + } + Ok(()) +} + // Panics if `unblinded_tlvs` length is less than `unblinded_pks` length pub(crate) fn construct_blinded_hops<'a, T, I1, I2>( secp_ctx: &Secp256k1, unblinded_pks: I1, mut unblinded_tlvs: I2, session_priv: &SecretKey @@ -125,8 +142,8 @@ where I2::Item: Writeable { let mut blinded_hops = Vec::with_capacity(unblinded_pks.size_hint().0); - construct_keys_callback( - secp_ctx, unblinded_pks, None, session_priv, + construct_keys_callback_for_blinded_path( + secp_ctx, unblinded_pks, session_priv, |blinded_node_id, _, _, encrypted_payload_rho, _, _| { blinded_hops.push(BlindedHop { blinded_node_id, -- 2.39.5