From: Jeffrey Czyz Date: Thu, 15 Aug 2024 23:06:46 +0000 (-0500) Subject: Add a construct_keys_callback for blinded paths X-Git-Tag: v0.0.124-rc1~9^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=51d9218f678a2f0887b96a0190aa9d5e0553c0dd;p=rust-lightning 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. --- 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,