From 0d5b7bd85dcabcfb3ee75b5ef8b5cc7d7fb0085d Mon Sep 17 00:00:00 2001 From: Rahul Patni Date: Thu, 7 Mar 2024 10:04:14 -0800 Subject: [PATCH] preserves order of identities when returning key packages (#4814) --- ironfish-rust-nodejs/src/frost.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ironfish-rust-nodejs/src/frost.rs b/ironfish-rust-nodejs/src/frost.rs index 08a7799e03..2b0019749a 100644 --- a/ironfish-rust-nodejs/src/frost.rs +++ b/ironfish-rust-nodejs/src/frost.rs @@ -203,13 +203,22 @@ pub fn generate_and_split_key( let identities = try_deserialize_identities(identities)?; let packages = - split_spender_key(&spending_key, min_signers, identities).map_err(to_napi_err)?; + split_spender_key(&spending_key, min_signers, identities.clone()).map_err(to_napi_err)?; let mut key_packages = Vec::with_capacity(packages.key_packages.len()); - for (identity, key_package) in packages.key_packages.iter() { + + // preserves the order of the identities + for identity in identities { + let key_package = packages + .key_packages + .get(&identity) + .ok_or_else(|| to_napi_err("Key package not found for identity"))? + .serialize() + .map_err(to_napi_err)?; + key_packages.push(ParticipantKeyPackage { identity: bytes_to_hex(&identity.serialize()), - key_package: bytes_to_hex(&key_package.serialize().map_err(to_napi_err)?), + key_package: bytes_to_hex(&key_package), }); }