Skip to content

test(crypto): add keys + primitives coverage with Argon2id parameter lock - #220

Merged
h4yfans merged 2 commits into
mainfrom
debt/1.4-keys-primitives-tests
Apr 15, 2026
Merged

test(crypto): add keys + primitives coverage with Argon2id parameter lock#220
h4yfans merged 2 commits into
mainfrom
debt/1.4-keys-primitives-tests

Conversation

@h4yfans

@h4yfans h4yfans commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Closes Phase 1 §1.4 of .claude/plans/tech-debt-remediation.md.

Summary

Dedicated coverage for keys.ts (205L) + primitives.ts (16L) with real libsodium, including an Argon2id regression lock via inline snapshot.

Key features

  • Argon2id parameter regression lock via toMatchInlineSnapshot() on a fixed (seed=64×0x42, salt=0x00..0xff) pair + a separate crypto_pwhash arg-spy asserting ARGON2_PARAMS.OPS_LIMIT/MEMORY_LIMIT/ALG_ARGON2ID13. Inline comment documents the parallelism=1 deviation from RFC 9106 spec=4 (per MEMORY.md).
  • Real libsodium end-to-end (no crypto mocks); keytar mocked only for keychain isolation.

Coverage

keys.test.ts (505L) — Argon2id lock, deriveKey context separation, deriveMasterKey snapshot + verifier-equality + memzero-on-failure, generateSalt uniqueness, generateDeviceSigningKeyPair (Ed25519 + BLAKE2b deviceId), generateKeyVerifier, X25519 ECDH roundtrip, deriveLinkingKeys, computeVerificationCode (deterministic, 6-digit, zero-padded), computeLinkingProof + computeKeyConfirm, getOrCreateSigningKeyPair, getOrDeriveVaultKey.

primitives.test.ts (118L) — generateFileKey uniqueness across 1000 calls + byte distribution, secureCleanup in-place zeroization.

Note to reviewer

The Argon2id inline snapshot is empty until first-run write. CI will need one -u pass to populate the hex — or the maintainer can run locally and commit the populated snapshot. Once populated, any parameter drift trips the test.

Test plan

  • Run pnpm --filter desktop test --project main src/main/crypto/keys.test.ts -u once to populate Argon2id snapshot; commit the update
  • pnpm --filter desktop test --project main src/main/crypto/keys.test.ts src/main/crypto/primitives.test.ts — 0 failures
  • per-file coverage on both ≥ 95%
  • pnpm typecheck:node && pnpm typecheck:web clean
  • pnpm lint clean

🤖 Generated with Claude Code

h4yfans added 2 commits April 16, 2026 00:41
Fills the empty toMatchInlineSnapshot() with the golden hex for the canonical (seed=64x0x42, salt=0x00..0xff, ops=3, mem=64MiB, parallelism=1 via libsodium) Argon2id derivation.
@h4yfans
h4yfans merged commit d8f4bb9 into main Apr 15, 2026
2 checks passed
@h4yfans
h4yfans deleted the debt/1.4-keys-primitives-tests branch April 15, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant