@git-stunts/git-cas 6.0.0 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  >
5
5
  > `git-cas` addresses this by making artifact distribution inherit Git’s existing replication model, allowing binaries to be stored, verified, and transported anywhere Git can operate, including mirrored networks, constrained environments, or fully offline contexts.
6
6
 
7
- `git-cas` 6.0.0 is an industrial-grade Content-Addressable Storage (CAS) engine backed by Git’s object database. Its Security First posture makes explicit restore boundaries, bounded metadata reads, authenticated encryption, and legacy-scheme rejection the default. Stored content is chunked, deduplicated, and optionally encrypted — keeping high-fidelity assets and security-sensitive files directly within your repository history.
7
+ `git-cas` is an industrial-grade Content-Addressable Storage (CAS) engine backed by Git’s object database. Its Security First posture makes explicit restore boundaries, bounded metadata reads, authenticated encryption, and legacy-scheme rejection the default. Stored content is chunked, deduplicated, and optionally encrypted — keeping high-fidelity assets and security-sensitive files directly within your repository history.
8
8
 
9
9
  `git-cas` is designed for the architect who demands mathematical certainty and the operator who needs a stable foundation for artifact storage. It scales from simple binary blob management to multi-recipient envelope-encrypted vaults with key rotation, privacy-mode slug hashing, and Merkle-style manifests for assets of any size.
10
10
 
@@ -59,216 +59,61 @@ const cas = await ContentAddressableStore.open({ cwd: '.' });
59
59
  const manifest = await cas.storeFile({ filePath: './asset.bin', slug: 'app/asset' });
60
60
  ```
61
61
 
62
- ## Feature Overview
63
-
64
- ### Content-Addressed Storage
65
-
66
- Every piece of stored content is broken into chunks and addressed by its SHA-256 digest. Identical content always produces the same address, giving you deduplication for free. Manifests record the ordered list of chunk digests so content can be reassembled faithfully, and every chunk is integrity-verified on read. New manifests are stamped with a `formatVersion` (semver from package.json) for forward-compatible schema evolution.
67
-
68
- ### Chunking
69
-
70
- Two chunking strategies are available, both with configurable size parameters:
71
-
72
- | Strategy | Algorithm | Default Target | Behavior |
73
- |---|---|---|---|
74
- | **Fixed-size** | Static split | 256 KiB | Deterministic, predictable chunk boundaries |
75
- | **Content-Defined (CDC)** | Buzhash rolling hash | Configurable target/min/max | Shift-resistant boundaries that survive insertions and deletions |
76
-
77
- CDC is the default for deduplication workloads. **FastCDC dual-mask normalization** is enabled by default, producing a tighter chunk-size distribution around the target size. Target, minimum, and maximum chunk sizes are all configurable.
78
-
79
- ### Encryption
80
-
81
- Encryption uses **AES-256-GCM** with 16-byte authentication tags. `whole` and
82
- `framed` use fresh random 96-bit nonces; `convergent` derives per-chunk keys
83
- and nonces deterministically from the plaintext content hash to preserve
84
- deduplication.
85
-
86
- Three encryption schemes are supported:
87
-
88
- | Scheme | Framing | AAD Binding | Notes |
89
- |---|---|---|---|
90
- | `whole` | Single ciphertext blob | Slug | AAD always bound to prevent cross-manifest blob swaps |
91
- | `framed` | Bounded frames | Slug + frame index | Default for fixed-chunk encrypted stores — streaming decrypt with per-frame AAD binding |
92
- | `convergent` | Per-chunk deterministic | Derived from content hash | **Default for CDC + encryption** — preserves deduplication across encrypted stores. Implemented as a standalone `ConvergentEncryption` service. |
93
-
94
- See [Encryption Modes](./docs/ENCRYPTION_MODES.md) for scheme selection guidance.
95
-
96
- Legacy schemes (`whole-v1`, `whole-v2`, `framed-v1`, `framed-v2`, `convergent-v1`) are no longer accepted and throw a `LEGACY_SCHEME` error. Run `npm run upgrade` (or `node scripts/migrate-encryption.js`) to migrate existing vault entries. The script auto-detects whether each entry needs a rename-only (fast) or full re-encryption (v1 schemes without AAD), accepts `--passphrase-file`, `--key-file`, or warning-emitting inline `--passphrase` for full migrations, supports privacy-vault key options, and defaults to dry-run mode.
97
-
98
- **Envelope encryption** wraps a random Data Encryption Key (DEK) with one or more Key Encryption Keys (KEKs). Each recipient is labeled, enabling multi-recipient access to the same encrypted content. Key rotation replaces the KEK wrapping without re-encrypting data blobs.
99
-
100
- ### Key Management
101
-
102
- Multiple key sources are supported:
103
-
104
- - **Raw keys**: 32-byte AES-256 key files read directly from disk.
105
- - **Passphrase-derived keys (PBKDF2)**: PBKDF2-SHA512 with a default of 600,000 iterations. Policy-enforced minimum and maximum iteration bounds.
106
- - **Passphrase-derived keys (scrypt)**: scrypt with default N=131072. Combined memory budget is capped at 1 GiB to prevent resource exhaustion.
107
- - **OS keychain**: Passphrase sourced from the operating system's native keychain (macOS Keychain, Linux Secret Service, Windows Credential Manager) via `@git-stunts/vault`.
108
-
109
- All KDF operations enforce a minimum 16-byte salt. Iteration counts and scrypt parameters are policy-bounded to prevent both weak derivation and denial-of-service.
110
-
111
- ### Compression
112
-
113
- Content can be gzip-compressed before storage through the `CompressionPort` abstraction. The shipped `NodeCompressionAdapter` handles Node.js; other runtimes can plug in their own adapter. Compression composes cleanly with encryption — content is compressed, then encrypted. Plaintext + gzip restores now stream instead of buffering.
114
-
115
- ### Manifests
116
-
117
- Two manifest versions handle assets of any size:
118
-
119
- - **Version 1**: A flat manifest blob listing all chunk digests. Suitable for most assets.
120
- - **Version 2**: A Merkle-style manifest that splits the chunk list into
121
- sub-manifests, each independently addressable and schema-validated.
122
- Automatically engaged when chunk count exceeds 1,000 by default, with
123
- per-operation `merkleThreshold` overrides available on store calls.
124
- Sub-manifest arrays are capped at 10,000 entries.
125
-
126
- Every manifest carries an **integrity hash** — the SHA-256 of the codec-encoded content — verified on every read to detect corruption or tampering. Two codecs are available: **JSON** (human-readable, default) and **CBOR** (binary, compact).
127
-
128
- Manifest diffing is available via `diffManifests()` for comparing two manifests and identifying changed, added, or removed chunks.
129
-
130
- ### Vault
131
-
132
- The vault is a GC-safe named asset index stored at `refs/cas/vault`. It is the control plane for managing stored content.
133
-
134
- - **CRUD**: Add, remove, list, and resolve named entries.
135
- - **Encryption**: Vault entries can be encrypted with a passphrase.
136
- - **Privacy mode**: HMAC-hashed slug names prevent metadata discovery — an observer cannot determine what assets are stored without the passphrase.
137
- - **Encryption count tracking**: The vault tracks how many times each entry has been encrypted under the current nonce context, issuing rotation warnings as limits approach.
138
- - **Passphrase verifier**: Encrypted vault metadata authenticates the derived
139
- vault key even before the first entry is added, so wrong passphrases fail
140
- before empty-vault writes are accepted.
141
- - **Passphrase rotation**: Rotate the vault passphrase across all entries in a single operation without re-encrypting data blobs.
142
- - **Optimistic concurrency**: Vault writes use compare-and-swap semantics with automatic retry on conflict, ensuring safe concurrent access.
143
-
144
- ### Restore Modes
145
-
146
- Three restore surfaces cover different memory and latency profiles:
147
-
148
- | Method | Behavior | Bounded? |
149
- |---|---|---|
150
- | `restore()` | Buffered reassembly to memory | Yes — capped by `maxRestoreBufferSize` |
151
- | `restoreFile()` | Atomic temp-file write with auth-then-rename | Yes — streams through disk for plaintext, framed, convergent, and uncompressed whole |
152
- | `restoreStream()` | Async iterable yielding chunks | Yes — frame-by-frame for framed scheme |
153
-
154
- `restoreFile()` writes tentative plaintext to a temporary file, verifies authentication, and renames into place only after verification succeeds. For `framed`, all three surfaces provide true streaming restore with per-frame authentication. Parallel chunk restore is supported via a prefetch window (`PrefetchWindow`) when concurrency is greater than 1, enabling ordered parallel reads for faster restores.
155
-
156
- ```js
157
- await cas.restoreFile({
158
- manifest,
159
- outputPath: './restored.bin',
160
- baseDirectory: process.cwd(),
161
- });
162
- ```
163
-
164
- ### CLI
165
-
166
- The `git-cas` command-line interface exposes the full feature set:
167
-
168
- | Command | Purpose |
169
- |---|---|
170
- | `git-cas store` | Store a file into the CAS |
171
- | `git-cas tree` | Create a Git tree from a manifest JSON file |
172
- | `git-cas inspect` | Inspect a stored manifest and optional chunk heatmap |
173
- | `git-cas restore` | Restore content by vault slug or tree OID |
174
- | `git-cas verify` | Verify chunk integrity for a stored asset |
175
- | `git-cas doctor` | Diagnose vault health and integrity |
176
- | `git-cas vault init` | Initialize a new vault |
177
- | `git-cas vault list` | List vault entries |
178
- | `git-cas vault stats` | Summarize vault size, dedupe, and encryption coverage |
179
- | `git-cas vault remove` | Remove a vault entry |
180
- | `git-cas vault info` | Show metadata for one vault entry |
181
- | `git-cas vault history` | Show vault commit history |
182
- | `git-cas vault rotate` | Rotate the vault passphrase |
183
- | `git-cas vault dashboard` | Interactive TUI for vault navigation |
184
- | `git-cas rotate` | Rotate an asset encryption key wrapper |
185
- | `git-cas recipient add/remove/list` | Manage envelope encryption recipients |
186
-
187
- `git-cas doctor` reports both chunk-reference dedupe and byte-level efficiency:
188
- logical manifest size versus unique chunk bytes. For privacy-enabled vaults,
189
- pass `--key-file`, `--vault-passphrase-file -`, or `--os-keychain-target` so the
190
- doctor can decrypt the privacy index before scanning entries.
191
-
192
- **Agent CLI**: `git-cas agent` exposes the same store/tree/restore/inspect/verify/doctor/rotate/recipient/vault surface through a newline-delimited protocol for CI/CD automation and programmatic integrations. Request payloads can be passed through `--request <json>` or stdin; responses stream back as JSON events on stdout.
193
-
194
- ### Security Hardening
195
-
196
- Beyond the core encryption primitives, `git-cas` enforces a set of defensive limits:
197
-
198
- - **Hex validation**: All OID and digest fields are schema-validated as strict hexadecimal strings.
199
- - **scrypt memory cap**: Combined scrypt memory budget is hard-capped at 1 GiB.
200
- - **Sub-manifest array limit**: Merkle sub-manifests are capped at 10,000 entries.
201
- - **Restore path boundary**: `restoreFile()` requires `baseDirectory` and refuses output paths that escape it.
202
- - **Metadata blob cap**: Manifest and sub-manifest blob reads default to a
203
- 10 MiB `maxBlobSize` safety limit. The default Git adapter honors the
204
- facade/service `maxBlobSize` option through its adapter-level read limit.
205
- - **Concurrency cap**: Parallel operations are bounded at 64.
206
- - **Frame size cap**: `frameBytes` is capped at 64 MiB.
207
- - **Timing oracle elimination**: Recipient trial decryption uses constant-time comparison to prevent timing-based key identification.
208
- - **Source validation**: Async iterables passed to `store()` are validated before processing begins.
209
- - **Salt enforcement**: KDF salts must be at least 16 bytes.
210
- - **Nonce rotation**: Encryption count tracking warns before nonce reuse becomes a concern.
211
- - **Legacy scheme rejection**: Attempting to use a legacy encryption scheme (`whole-v1`, `whole-v2`, `framed-v1`, `framed-v2`, `convergent-v1`) throws a `LEGACY_SCHEME` error with migration guidance (see [UPGRADING.md](./UPGRADING.md)).
212
-
213
- ## Streaming Surface
214
-
215
- | Surface | Streaming API? | Non-streaming API? | Notes |
216
- |---|---|---|---|
217
- | Write | `store({ source, ... })`, `storeFile(...)` | No dedicated non-streaming store facade | Write ingress is stream-based. CDC + encryption defaults to `convergent` (per-chunk deterministic encryption preserving dedup). Fixed + encryption defaults to `framed`. |
218
- | Read: plaintext | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | True chunk-by-chunk streaming restore. |
219
- | Read: encrypted `whole` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | `restoreStream()` is the buffered compatibility path. Uncompressed `restoreFile()` verifies chunks, streams tentative plaintext through whole-object AES-GCM decryption into a temp-file path, and renames into place only after auth succeeds. AAD (slug) is always bound. On Web Crypto runtimes this decrypt step is still one-shot internally, bounded by `maxDecryptionBufferSize`. |
220
- | Read: encrypted `framed` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | True authenticated streaming restore. Plaintext is yielded frame-by-frame after each frame is verified. Per-frame AAD is always bound. |
221
- | Read: compressed-only | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | Plaintext + gzip now streams end-to-end. `restoreFile()` streams gunzip output through a bounded temp-file path. |
222
- | Read: compressed + `whole` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | Auth must complete before gunzip. `restoreFile()` therefore preserves the auth-before-decompress boundary and may buffer the encrypted compressed payload; use `framed` or `convergent` for large compressed encrypted assets. |
223
- | Read: compressed + `framed` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | Streaming decrypt, then streaming gunzip. |
224
- | Read: encrypted `convergent` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | True per-chunk streaming restore. Each chunk is decrypted individually using a key derived from its content hash. Parallel chunk restore via prefetch window when concurrency > 1. |
225
- | Read: compressed + `convergent` | `restoreStream(...)`, `restoreFile(...)` | `restore(...)` | Per-chunk convergent decrypt, then streaming gunzip. |
226
- | Verify | No streaming verify surface | `verifyIntegrity(manifest, options?)` | Verifies chunk digests for all content. `whole` auth-checks the full ciphertext; `framed` parses and auth-checks every frame; `convergent` decrypts each chunk and verifies plaintext digests. |
227
-
228
- Runtime note: `framed` is the honest cross-runtime streaming answer. On Node and Bun, `whole restoreFile()` has the stronger low-memory path; on Web Crypto runtimes such as Deno, `whole` remains bounded-buffer rather than true streaming.
229
-
230
- ## Architecture
231
-
232
- `git-cas` follows a strict hexagonal (ports and adapters) architecture. The domain core has zero knowledge of runtime-specific APIs.
233
-
234
- ```
235
- ┌─────────────────────┐
236
- │ ContentAddressable │
237
- │ Store (Facade) │
238
- └──────────┬──────────┘
239
- │
240
- ┌──────────▼──────────┐
241
- │ CasService │
242
- │ (Domain Core) │
243
- └──┬──┬──┬──┬──┬──┬───┘
244
- │ │ │ │ │ │
245
- ┌──────────────┘ │ │ │ │ └──────────────┐
246
- │ ┌────────┘ │ │ └────────┐ │
247
- ▼ ▼ ▼ ▼ ▼ ▼
248
- ┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐
249
- │Persist.││ Crypto ││ Codec ││Compress││Chunking││Observe.│
250
- │ Port ││ Port ││ Port ││ Port ││ Port ││ Port │
251
- └───┬────┘└───┬────┘└───┬────┘└───┬────┘└───┬────┘└───┬────┘
252
- │ │ │ │ │ │
253
- ▼ ▼ ▼ ▼ ▼ ▼
254
- GitODB Node/Bun JSON or Node gzip Fixed or Event
255
- /Deno CBOR adapter CDC/ Emitter
256
- Crypto Buzhash
257
- ```
258
-
259
- **Ports** define the contracts. **Adapters** implement them for specific runtimes. Swap any adapter without touching domain logic.
260
-
261
- The core byte contract is `Uint8Array`. Node `Buffer` values still work at the
262
- Node boundary because `Buffer` extends `Uint8Array`, but the domain, ports,
263
- chunkers, codecs, and shared helpers do not depend on Node-specific byte APIs.
264
-
265
- ## Multi-Runtime Support
266
-
267
- | Runtime | Version | Crypto Backend | Status |
268
- |---|---|---|---|
269
- | **Node.js** | 22+ | `node:crypto` | Primary — full streaming support |
270
- | **Bun** | Latest | `node:crypto` compat | Tested via Docker |
271
- | **Deno** | Latest | Web Crypto API | Tested via Docker; `whole` decrypt is bounded-buffer |
62
+ ## Capability Map
63
+
64
+ The README is the front door. Detailed mechanics live in the guide set:
65
+
66
+ | Need | Start Here |
67
+ | ------------------------------------------------------- | ------------------------------------------------------------ |
68
+ | Productive library and CLI workflows | [Developer Guide](./GUIDE.md) |
69
+ | Restore memory behavior | [Streaming and restore matrix](./GUIDE.md#streaming-surface) |
70
+ | Encryption scheme selection | [Encryption Modes](./docs/ENCRYPTION_MODES.md) |
71
+ | CDC internals, Merkle manifests, KDF policy, and tuning | [Advanced Guide](./ADVANCED_GUIDE.md) |
72
+ | Ports, adapters, and collaborator boundaries | [Architecture](./ARCHITECTURE.md) |
73
+ | v5 to v6 migration | [Upgrading](./UPGRADING.md) |
74
+
75
+ Core capabilities:
76
+
77
+ - **Content-addressed storage**: chunks are addressed by SHA-256 digest and
78
+ integrity-verified on read.
79
+ - **Deduplication**: fixed chunking and content-defined chunking (CDC) support
80
+ predictable or shift-resistant chunk boundaries.
81
+ - **Encryption**: AES-256-GCM with authenticated metadata. `whole` and
82
+ `framed` use fresh random 96-bit nonces; `convergent` derives per-chunk keys
83
+ and nonces deterministically from the plaintext content hash to preserve
84
+ deduplication.
85
+ - **Vault indexing**: named assets live under `refs/cas/vault` so Git garbage
86
+ collection does not reclaim referenced blobs.
87
+ - **Envelope recipients**: multi-recipient key wrapping and recipient rotation
88
+ avoid re-encrypting data blobs.
89
+ - **Operational diagnostics**: `git-cas doctor` validates vault health and
90
+ reports deduplication efficiency.
91
+
92
+ ## Safety Snapshot
93
+
94
+ The v6 line is Security First by default:
95
+
96
+ - `restoreFile()` requires `baseDirectory` and refuses output paths that escape
97
+ it.
98
+ - Manifest and sub-manifest blob reads default to a 10 MiB `maxBlobSize` safety
99
+ limit.
100
+ - Legacy encryption scheme identifiers throw `LEGACY_SCHEME` with migration
101
+ guidance.
102
+ - KDF parameters, salts, frame sizes, restore buffers, and concurrency are
103
+ policy-bounded.
104
+ - Recipient trial decryption and vault verifier checks use constant-time
105
+ comparisons.
106
+
107
+ For the full hardening table, see
108
+ [Advanced Guide: Security Hardening Summary](./ADVANCED_GUIDE.md#security-hardening-summary).
109
+
110
+ ## Runtime Support
111
+
112
+ | Runtime | Version | Crypto Backend | Status |
113
+ | ----------- | ------- | -------------------- | ---------------------------------------------------- |
114
+ | **Node.js** | 22+ | `node:crypto` | Primary — full streaming support |
115
+ | **Bun** | Latest | `node:crypto` compat | Tested via Docker |
116
+ | **Deno** | Latest | Web Crypto API | Tested via Docker; `whole` decrypt is bounded-buffer |
272
117
 
273
118
  All three runtimes are tested in CI on every push. The hexagonal architecture isolates runtime differences behind the `CryptoPort` boundary, so the domain core is runtime-agnostic.
274
119
 
@@ -289,4 +134,5 @@ All three runtimes are tested in CI on every push. The hexagonal architecture is
289
134
  - **[Changelog](./CHANGELOG.md)**: Version history and migration notes.
290
135
 
291
136
  ---
137
+
292
138
  Built with terminal ambition by [FLYING ROBOTS](https://github.com/flyingrobots)