Skip to content

Add HD1 v3: the same envelope over opaque bytes - #27

Merged
pablo-tech merged 1 commit into
mainfrom
feat/hd1-bytes
Sep 24, 2026
Merged

pablo-tech merged 1 commit into
mainfrom
feat/hd1-bytes

Conversation

@pablo-tech

Copy link
Copy Markdown
Contributor

Why

encryptVaultV2/decryptVaultV2 are JSON-only — JSON.stringify in, JSON.parse out. That is right for a vault blob and wrong for a payload that is already a file: base64-ing a PDF through JSON costs 33%, which is the difference between a 24 MB upload cap and a 32 MB one.

HD1 v3 is the same 32-byte header ("HD1" | version | vaultKeyId(16) | iv(12)) over an opaque byte payload. Every existing guard — the magic check, the minimum length — works unchanged, and the version byte is what says whether the plaintext is UTF-8 JSON or bytes.

What changed

  • encryptBytes(data, dek) / decryptBytes(blob, dek) — v3 seal/open.
  • isHD1(blob) — a cheap magic+length check, for a store that must read plaintext and sealed objects side by side while it migrates between them.
  • v2's codec now shares sealHD1/openHD1 with v3 rather than carrying its own copy of the header layout, so the format is stated once.
  • v1's decryptVault names a v3 blob instead of failing with a confusing version error.

Additive: no existing signature moved.

Tests

8 new cases in tests/crypto.test.ts — round-trip (including an empty payload), the exact header bytes and length (32 + len + 16), wrong key, tampered payload, truncated, non-HD1, and v2/v3 unconfusable in both directions. 93 tests green.

Consumer

tinytars/lexi — encrypting uploaded original documents at rest under per-file content keys held in the encrypted vault, so the operator holds no standing key that opens a patient's files.

🤖 Generated with Claude Code

…JSON

HD1 v2 is JSON-only, so a PDF has to be base64'd into it at a 33% cost — the
difference between a 24 MB upload cap and a 32 MB one. v3 is the same envelope
over opaque bytes; isHD1 lets a store read plaintext and sealed objects side by
side while it migrates between them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@pablo-tech
pablo-tech merged commit f160fc4 into main Sep 24, 2026
6 checks passed
@pablo-tech
pablo-tech deleted the feat/hd1-bytes branch September 24, 2026 17:07
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