Skip to content

Commit acc4c87

Browse files
committed
perf: make tests faster
1 parent 8dcf567 commit acc4c87

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

new-deepnotes/packages/e2ee/src/derive-group-password.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { argon2id } from "@noble/hashes/argon2.js";
22

33
import { wrapSymmetricKey } from "./symmetric-key.js";
44

5+
/** Fast Argon2 params in test environments; production hardness unchanged. */
6+
const isTestEnv =
7+
typeof process !== "undefined" && process.env?.VITEST === "true";
8+
59
/** Legacy nanoid alphabet (must match `@stdlib/misc` / client). */
610
const alphabet =
711
"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
@@ -54,8 +58,8 @@ export function deriveGroupPasswordValues(
5458
const salt = nanoidToBytes(groupId);
5559

5660
const derivedKey = argon2id(new TextEncoder().encode(password), salt, {
57-
t: 8, // iterations
58-
m: 32 * 1024, // memory in KB (32MB)
61+
t: isTestEnv ? 1 : 8, // iterations
62+
m: isTestEnv ? 64 * 1024 : 32 * 1024, // memory in KB
5963
p: 1, // parallelism
6064
dkLen: 32 + 64, // output length
6165
});

new-deepnotes/packages/e2ee/src/derive-password.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { argon2id } from "@noble/hashes/argon2.js";
22

33
import { wrapSymmetricKey } from "./symmetric-key.js";
44

5+
/** Fast Argon2 params in test environments; production hardness unchanged. */
6+
const isTestEnv =
7+
typeof process !== "undefined" && process.env?.VITEST === "true";
8+
59
const SALT_SIZE = 16;
610

711
function getRandomBytes(length: number): Uint8Array {
@@ -24,8 +28,8 @@ export function derivePasswordValues(input: {
2428
input.salt ??= getRandomBytes(SALT_SIZE);
2529

2630
const derivedKey = argon2id(input.password, input.salt, {
27-
t: 2, // iterations
28-
m: 32 * 1024, // memory in KB (32MB)
31+
t: isTestEnv ? 1 : 2, // iterations
32+
m: isTestEnv ? 64 * 1024 : 32 * 1024, // memory in KB
2933
p: 1, // parallelism
3034
dkLen: 32 + 64, // output length
3135
});

0 commit comments

Comments
 (0)