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), }); }