Skip to content

feat: DIS foundation — crypto core, modular SDK, threat model & migration plan#1

Merged
einmalmaik merged 10 commits into
mainfrom
devin/1780259862-dis-foundation
Jun 1, 2026
Merged

feat: DIS foundation — crypto core, modular SDK, threat model & migration plan#1
einmalmaik merged 10 commits into
mainfrom
devin/1780259862-dis-foundation

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Establishes DIS — Defensive Integration Shield as the central, framework-agnostic crypto layer that Singra Vault, Singra Premium, and future projects will depend on exclusively. This PR is Phase 0 (foundation): it implements and tests the portable primitives and ships all analysis deliverables. No application code is changed yet — the app cutover is gated on user approval and the compatibility proof described in docs/migration-plan.md.

DIS invents no cryptography. It composes audited primitives only: Argon2id (hash-wasm), AES-256-GCM / HKDF-SHA-256 / SHA-256 (WebCrypto), ML-KEM-768 hybrid (@noble/post-quantum, phase 2).

What's implemented (all tested: 42 tests, lint, typecheck, build green)

One package @dis/shield with tree-shakeable subpath exports per module:

  • core — typed error hierarchy (secret-free), encoding, constants, injectable CryptoProvider seam (only place a global is touched)
  • random — CSPRNG bytes/UUID, never Math.random
  • secure-memorySecureBuffer (wipe + FinalizationRegistry fallback, constant-time equals)
  • kdf — Argon2id with immutable versioned params (v1 64 MiB, v2 128 MiB, t=3, p=4, 32B) + optional HKDF strengthening for device-key binding
  • aead — AES-256-GCM, fresh 96-bit IV per call, 128-bit tag, AAD; all failures collapse to one opaque DisDecryptionError (no oracle)
  • format-versioning — prefix-tagged envelopes; unknown in-family versions fail closed
  • vault-encryptionsv-vault-v1: items with entryId as AAD (defeats row-swap); legacy no-AAD readable only via explicit migration API
  • key-management — content-key (usk-wrap-v2:) wrap/unwrap + rotateEncryptionKeys that re-wraps without re-encrypting vault data
  • file-encryption — chunked (4 MiB) attachment encryption, per-file random key, manifest root + per-chunk AAD binding owner/item/file/revision/root/index/count; storage-agnostic (caller supplies readChunk/writeChunk)
  • integrity — SHA-256, constant-time compare, verifyPayloadIntegrity
  • migrations — ordered, cycle-guarded MigrationRegistry

Stable SDK facade (@dis/shield) exposes the requested API names: encryptVaultEntry/decryptVaultEntry, encryptAttachment/decryptAttachment, deriveMasterKey, rotateEncryptionKeys, verifyPayloadIntegrity, plus DIS_BRANDING = "Powered by DIS — Defensive Integration Shield".

Format compatibility

All persisted-format constants (envelope prefixes, IV‖CT‖tag layout, AAD strings, HKDF info, KDF params) reproduce Singra's formats byte-for-byte, so apps can adopt DIS with no data re-encryption. Formats are append-only (new version, never edit).

Deliverables (in docs/)

architecture.md, crypto-dependency-map.md, trust-boundaries.md, threat-model.md (24 threats + accepted residual risks), risk-analysis.md (risk-ordered refactor plan), api-design.md (+ breaking-change policy), crypto-review.md, migration-plan.md, licensing.md. Plus LICENSE (PolyForm Noncommercial 1.0.0 — source-available, noncommercial, with dual-licensing path), CONTRIBUTING.md (CLA), SECURITY.md, and CI (lint/typecheck/test/build + npm audit + gitleaks secret scan).

License decision (see docs/licensing.md)

Honest framing: a strict OSI "open source" license cannot forbid commercial use. Chose PolyForm Noncommercial 1.0.0 (SPDX PolyForm-Noncommercial-1.0.0) — explicit noncommercial restriction, professionally drafted, clearer than Commons Clause; AGPL rejected (doesn't restrict commercial use). Commercial use via maintainer dual-licensing (CLA preserves this).

Not done in this PR (next phases, gated)

  • Capture production golden vectors + cross-impl decrypt tests (Phase 1 gate before any app change)
  • Port PQ hybrid (pqCryptoService) into key-management (Phase 2)
  • Vault + Premium cutover to consume DIS exclusively, replace Premium's ../singravault/src path alias, lint-ban raw crypto.subtle, make build fail without DIS (Phases 3–4)

Honest test status

npm run lint, npm run typecheck, npm test (42 passing), npm run build all run green locally. Cross-implementation golden-vector tests against live production payloads are not yet present (tracked as the Phase 1 gate) — byte-compatibility is currently asserted via format structure, not yet against captured production ciphertext.

Link to Devin session: https://app.devin.ai/sessions/24b35de4890f41edb8a0250d5f4aba7c

Implements the framework-agnostic crypto core (encoding, random, secure-memory,
kdf/Argon2id, aead/AES-256-GCM, vault-encryption, key-management, file-encryption,
integrity, format-versioning, migrations) with byte-compatible Singra formats.
42 tests (positive + negative + vectors), lint, typecheck, build all green.
Adds architecture/threat-model/crypto-review/migration/licensing docs,
PolyForm Noncommercial license, and CI with dependency + secret scanning.

Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

devin-ai-integration Bot and others added 9 commits May 31, 2026 20:39
Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
Hard-coded vectors produced by the legacy Singra cryptoService prove DIS
reads already-stored production ciphertext (KDF v1/v2, AEAD ±AAD,
sv-vault-v1 envelope, usk-wrap-v2 bundle). Phase 1 cutover gate.

Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
Faithful port of Singra pqCryptoService into @dis/shield/post-quantum.
Wire format preserved byte-for-byte (version bytes 0x01-0x04, HKDF v1/v2,
ver||pq_ct||rsa_ct||iv||aes_ct layout). Adds round-trip, fail-closed
(wrong AAD / tampered) and a legacy golden-vector test proving DIS
decrypts already-stored v0x04 hybrid ciphertext. Exposed via the SDK
facade and as an optional @noble/post-quantum peer.

Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
Gitleaks flagged the synthetic ML-KEM secret key in the PQ golden-vector
test as a generic secret (high entropy). Move the vector into a dedicated
__fixtures__ file documented as non-secret synthetic test material and
narrowly allowlist that path in .gitleaks.toml (default ruleset still
applies everywhere else).

Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
…module

Adds @dis/shield/vault-crypto — the stable, named API Singra Vault/Premium
consume so the apps need zero crypto code of their own. It composes the
audited DIS primitives (kdf, aead, vault-encryption, key-management,
asymmetric, post-quantum) and owns the application-specific versioned
formats (sv-vault-v1, usk-wrap-v2, usk-v1 private-key wrap, pq-v2 hybrid
keypair envelope, v3 verification hash, KDF auto-upgrade, re-encryption).

Adds @dis/shield/asymmetric (RSA-OAEP-4096) and key-management helpers
(createDeterministicWrappedUserKey, AES-GCM JWK shared keys).

16 profile tests prove byte-compat with legacy Singra golden vectors via
the profile API plus round-trips for every profile-only format. 66 DIS
tests green.

Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
…acy-migration logging

- isCurrentVaultItemEnvelope now fails closed (throws) on unknown in-family
  sv-vault-* versions instead of returning false, matching legacy behaviour
- decryptVaultItem/decryptVaultItemForMigration emit the legacy no-AAD marker
  via console.warn when the migration-only fallback is used
- add profile tests locking both behaviours

Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
npm audit flagged a critical advisory in vitest <4.1.0 (Vitest UI server
arbitrary file read/exec). Dev-only dependency; no production crypto impact.
All 68 tests pass on vitest 4.

Co-Authored-By: Gaming Gruppe <einmalmaik@gmail.com>
@einmalmaik
einmalmaik merged commit 5ab99e7 into main Jun 1, 2026
2 checks passed
@einmalmaik
einmalmaik deleted the devin/1780259862-dis-foundation branch June 12, 2026 23:26
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