Skip to content

Commit a0e779d

Browse files
committed
amino, proto-signing: add explicit scream test to KDF code
This should make the deserialize 'can restore multiple accounts' unit test take about 12s, approximating pure JS performance on node 22.
1 parent 7b65103 commit a0e779d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/amino/src/wallet.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ export async function executeKdf(password: string, configuration: KdfConfigurati
2828
case "argon2id": {
2929
const options = configuration.params;
3030
if (!isArgon2idOptions(options)) throw new Error("Invalid format of argon2id params");
31-
return Argon2id.execute(password, cosmjsSalt, options);
31+
32+
// Emulate a slower implementation. The fast WASM code may get removed.
33+
// This approximates the speed of using a pure JS implementation (@noble/hashes) in Node 22.
34+
const screamTest = new Promise((resolve) => setTimeout(resolve, options.opsLimit * 250));
35+
const result = await Argon2id.execute(password, cosmjsSalt, options);
36+
await screamTest;
37+
return result;
3238
}
3339
default:
3440
throw new Error("Unsupported KDF algorithm");

packages/proto-signing/src/wallet.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ export async function executeKdf(password: string, configuration: KdfConfigurati
2828
case "argon2id": {
2929
const options = configuration.params;
3030
if (!isArgon2idOptions(options)) throw new Error("Invalid format of argon2id params");
31-
return Argon2id.execute(password, cosmjsSalt, options);
31+
32+
// Emulate a slower implementation. The fast WASM code may get removed.
33+
// This approximates the speed of using a pure JS implementation (@noble/hashes) in Node 22.
34+
const screamTest = new Promise((resolve) => setTimeout(resolve, options.opsLimit * 250));
35+
const result = await Argon2id.execute(password, cosmjsSalt, options);
36+
await screamTest;
37+
return result;
3238
}
3339
default:
3440
throw new Error("Unsupported KDF algorithm");

0 commit comments

Comments
 (0)