]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add a construct_keys_callback for blinded paths
authorJeffrey Czyz <jkczyz@gmail.com>
Thu, 15 Aug 2024 23:06:46 +0000 (18:06 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 20 Aug 2024 21:35:43 +0000 (16:35 -0500)
When constructing a BlindedPath, an Option<Destination> 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

index f96df7014b2511fe5bae2088120a5a7dfa72e7c5..860d91cfcf923536bd2a33dce0cfb006f2de5117 100644 (file)
@@ -114,6 +114,23 @@ where
        Ok(())
 }
 
+#[inline]
+pub(super) fn construct_keys_callback_for_blinded_path<'a, T, I, F>(
+       secp_ctx: &Secp256k1<T>, unblinded_path: I, session_priv: &SecretKey, mut callback: F,
+) -> Result<(), secp256k1::Error>
+where
+       T: secp256k1::Signing + secp256k1::Verification,
+       I: Iterator<Item=PublicKey>,
+       F: FnMut(PublicKey, SharedSecret, PublicKey, [u8; 32], Option<PublicKey>, Option<Vec<u8>>),
+{
+       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<T>, 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,