Skip to content

feat(client): NaCl-box crypto primitives + pairing payload codec#27

Open
Codename-11 wants to merge 1 commit into
feature/v3-foundationfrom
feature/v3-crypto-primitives
Open

feat(client): NaCl-box crypto primitives + pairing payload codec#27
Codename-11 wants to merge 1 commit into
feature/v3-foundationfrom
feature/v3-crypto-primitives

Conversation

@Codename-11
Copy link
Copy Markdown
Owner

Summary

  • Adds packages/client/src/crypto.tsgenerateKeypair, box, unbox (null on auth failure), and URL-safe base64 helpers, wrapping tweetnacl (zero native build, Curve25519 + XSalsa20 + Poly1305).
  • Adds packages/client/src/pairing.ts — Zod schema + canonical encode/decode for the compact QR pairing payload (v, relayUrl, daemonPub, pairCode, optional label).
  • Adds tests/crypto-primitives.test.ts — 15 vitest cases: keypair shape & uniqueness, box/unbox roundtrip, tamper/wrong-nonce/wrong-key rejection, base64url safety, pairing payload roundtrip + malformed-input errors + schema-version rejection.

Context: Phase 10 of the ARC v3 daemon plan (E2E-encrypted relay). Primitives only — the relay server (Unit 10) and daemon pairing flow will consume these in follow-up batches.

Test plan

  • pnpm install
  • npx tsc --noEmit — passes
  • npx vitest run tests/crypto-primitives.test.ts — 15/15 pass
  • Node smoke: box/unbox round-trips "hello" across two fresh keypairs via the @axiom-labs/arc-client package export
  • Pairing smoke: encode → decode roundtrip preserves all fields, output is URL-safe (no +, /, =)
  • Only touched in-scope files (no dashboard chat.js / styles/*.css)

Adds pure crypto layer usable by both daemon and client for the ARC v3
E2E-encrypted relay flow (Phase 10 of the v3 daemon plan).

- `packages/client/src/crypto.ts`: `generateKeypair`, `box`, `unbox`
  (returns null on auth failure), and URL-safe base64 helpers. Wraps
  `tweetnacl` for zero-native-build crypto_box (Curve25519 + XSalsa20 +
  Poly1305).
- `packages/client/src/pairing.ts`: Zod schema + encode/decode for the
  compact QR pairing payload (v, relayUrl, daemonPub, pairCode, label).
  JSON is canonicalized before base64url so identical payloads always
  encode to the same string.
- `tests/crypto-primitives.test.ts`: 15 vitest cases covering keypair
  shape, box/unbox roundtrips, tamper/wrong-key/wrong-nonce rejection,
  base64url safety, and pairing payload encode/decode including
  malformed inputs and schema violations.

Primitives only — relay server and daemon pairing flow are follow-up
batches.
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