@git-stunts/git-cas 5.3.2 → 6.0.0

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.
Files changed (173) hide show
  1. package/ADVANCED_GUIDE.md +1006 -0
  2. package/ARCHITECTURE.md +514 -0
  3. package/CHANGELOG.md +393 -5
  4. package/CODE_OF_CONDUCT.md +33 -0
  5. package/GUIDE.md +872 -0
  6. package/README.md +219 -325
  7. package/SECURITY.md +993 -0
  8. package/SUPPORT.md +54 -0
  9. package/UPGRADING.md +299 -0
  10. package/bin/actions.js +70 -21
  11. package/bin/agent/cli.js +51 -0
  12. package/bin/agent/commands/doctor.js +99 -0
  13. package/bin/agent/commands/index.js +1489 -0
  14. package/bin/agent/input.js +619 -0
  15. package/bin/agent/passphrase-source.js +123 -0
  16. package/bin/agent/protocol.js +193 -0
  17. package/bin/build-version.js +64 -0
  18. package/bin/credentials.js +425 -0
  19. package/bin/git-cas.js +595 -449
  20. package/bin/passphrase-source.js +266 -0
  21. package/bin/restore-output-target.js +28 -0
  22. package/bin/ui/blocks/asset-card.js +109 -0
  23. package/bin/ui/blocks/health-dashboard.js +149 -0
  24. package/bin/ui/blocks/heatmap-block.js +67 -0
  25. package/bin/ui/blocks/merkle-explorer.js +163 -0
  26. package/bin/ui/blocks/operation-feed.js +176 -0
  27. package/bin/ui/blocks/wizard-block.js +168 -0
  28. package/bin/ui/components/short-sha.js +36 -0
  29. package/bin/ui/context.js +56 -1
  30. package/bin/ui/dashboard-cmds.js +1578 -13
  31. package/bin/ui/dashboard-view.js +612 -145
  32. package/bin/ui/dashboard.js +998 -214
  33. package/bin/ui/encryption-card.js +69 -26
  34. package/bin/ui/heatmap.js +26 -54
  35. package/bin/ui/history-timeline.js +51 -19
  36. package/bin/ui/manifest-view.js +115 -60
  37. package/bin/ui/merkle-dag.js +83 -0
  38. package/bin/ui/progress.js +15 -9
  39. package/bin/ui/repo-treemap.js +328 -0
  40. package/bin/ui/shaders/bak-sneppen.js +180 -0
  41. package/bin/ui/shaders/fractal-zoom.js +99 -0
  42. package/bin/ui/shaders/merkle-tree.js +142 -0
  43. package/bin/ui/shaders/organic-flow.js +96 -0
  44. package/bin/ui/shaders/phase-portrait.js +93 -0
  45. package/bin/ui/store-wizard.js +296 -0
  46. package/bin/ui/theme.js +155 -0
  47. package/bin/ui/vault-report.js +495 -0
  48. package/build-info.json +4 -0
  49. package/docs/API.md +2224 -0
  50. package/docs/ENCRYPTION_MODES.md +33 -0
  51. package/docs/EXTENDING.md +174 -0
  52. package/docs/STORE_RESTORE_PIPELINE.md +199 -0
  53. package/docs/THREAT_MODEL.md +269 -0
  54. package/docs/VAULT_INTERNALS.md +251 -0
  55. package/docs/WALKTHROUGH.md +1868 -0
  56. package/docs/demo.gif +0 -0
  57. package/docs/releases/v6.0.0.md +104 -0
  58. package/examples/README.md +260 -0
  59. package/index.d.ts +208 -65
  60. package/index.js +163 -54
  61. package/package.json +35 -6
  62. package/scripts/migrate-encryption.js +680 -0
  63. package/src/domain/bytes/ByteLayout.js +96 -0
  64. package/src/domain/encoding/base64.js +91 -0
  65. package/src/domain/encoding/hex.js +14 -0
  66. package/src/domain/encoding/utf8.js +123 -0
  67. package/src/domain/encryption/schemes.js +132 -0
  68. package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
  69. package/src/domain/errors/CasError.d.ts +28 -0
  70. package/src/domain/errors/CasError.js +43 -6
  71. package/src/domain/errors/Codes.js +54 -0
  72. package/src/domain/errors/DekUnwrapFailedError.js +10 -0
  73. package/src/domain/errors/GitError.js +10 -0
  74. package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
  75. package/src/domain/errors/IntegrityError.js +10 -0
  76. package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
  77. package/src/domain/errors/InvalidOidError.js +10 -0
  78. package/src/domain/errors/InvalidOptionsError.js +10 -0
  79. package/src/domain/errors/ManifestIntegrityError.js +10 -0
  80. package/src/domain/errors/ManifestNotFoundError.js +10 -0
  81. package/src/domain/errors/NoMatchingRecipientError.js +10 -0
  82. package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
  83. package/src/domain/errors/PortNotImplementedError.js +10 -0
  84. package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
  85. package/src/domain/errors/RecipientNotFoundError.js +10 -0
  86. package/src/domain/errors/RestoreTooLargeError.js +10 -0
  87. package/src/domain/errors/RotationNotSupportedError.js +10 -0
  88. package/src/domain/errors/createCasError.js +68 -0
  89. package/src/domain/errors/index.js +20 -0
  90. package/src/domain/helpers/buildKdfMetadata.js +4 -2
  91. package/src/domain/helpers/codecBytes.js +34 -0
  92. package/src/domain/helpers/gitRefErrors.js +84 -0
  93. package/src/domain/helpers/scryptMaxmem.js +22 -0
  94. package/src/domain/outcomes/RestoreFailure.js +15 -0
  95. package/src/domain/outcomes/RestoreOutcome.js +11 -0
  96. package/src/domain/outcomes/RestoreSuccess.js +34 -0
  97. package/src/domain/outcomes/StoreFailure.js +15 -0
  98. package/src/domain/outcomes/StoreOutcome.js +11 -0
  99. package/src/domain/outcomes/StoreSuccess.js +17 -0
  100. package/src/domain/schemas/ManifestSchema.d.ts +40 -9
  101. package/src/domain/schemas/ManifestSchema.js +67 -13
  102. package/src/domain/services/CasService.d.ts +123 -38
  103. package/src/domain/services/CasService.js +298 -834
  104. package/src/domain/services/ChunkRepository.js +230 -0
  105. package/src/domain/services/CompressionStreams.js +72 -0
  106. package/src/domain/services/ConvergentEncryption.js +128 -0
  107. package/src/domain/services/GitTreeBuilder.js +86 -0
  108. package/src/domain/services/IntegrityVerifier.js +199 -0
  109. package/src/domain/services/KeyResolver.js +49 -42
  110. package/src/domain/services/ManifestDiff.js +56 -0
  111. package/src/domain/services/ManifestRepository.js +286 -0
  112. package/src/domain/services/PrefetchWindow.js +48 -0
  113. package/src/domain/services/RecipientService.js +157 -0
  114. package/src/domain/services/RedactingObservability.js +169 -0
  115. package/src/domain/services/RestorePipeline.js +68 -0
  116. package/src/domain/services/StorePipeline.js +201 -0
  117. package/src/domain/services/VaultKeyVerifier.js +101 -0
  118. package/src/domain/services/VaultMetadataCodec.js +206 -0
  119. package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
  120. package/src/domain/services/VaultPersistence.js +410 -0
  121. package/src/domain/services/VaultPrivacyIndex.js +191 -0
  122. package/src/domain/services/VaultService.js +749 -251
  123. package/src/domain/services/VaultStateCache.js +225 -0
  124. package/src/domain/services/VaultTreeCodec.js +121 -0
  125. package/src/domain/services/rotateVaultPassphrase.js +37 -20
  126. package/src/domain/strategies/Aad.js +39 -0
  127. package/src/domain/strategies/FramedRecordCodec.js +204 -0
  128. package/src/domain/strategies/RestoreCompressed.js +40 -0
  129. package/src/domain/strategies/RestoreConvergent.js +44 -0
  130. package/src/domain/strategies/RestoreFramed.js +55 -0
  131. package/src/domain/strategies/RestorePlain.js +37 -0
  132. package/src/domain/strategies/RestoreStrategy.js +35 -0
  133. package/src/domain/strategies/RestoreWhole.js +135 -0
  134. package/src/domain/strategies/StoreConvergent.js +28 -0
  135. package/src/domain/strategies/StoreFramed.js +39 -0
  136. package/src/domain/strategies/StorePlain.js +20 -0
  137. package/src/domain/strategies/StoreStrategy.js +61 -0
  138. package/src/domain/strategies/StoreWhole.js +34 -0
  139. package/src/domain/value-objects/Chunk.js +1 -2
  140. package/src/domain/value-objects/EncryptionMetadata.js +87 -0
  141. package/src/domain/value-objects/Manifest.d.ts +40 -4
  142. package/src/domain/value-objects/Manifest.js +61 -20
  143. package/src/domain/value-objects/Oid.js +45 -0
  144. package/src/domain/value-objects/Slug.js +124 -0
  145. package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
  146. package/src/helpers/aesGcmMeta.js +55 -0
  147. package/src/helpers/canonicalBase64.js +1 -0
  148. package/src/helpers/kdfPolicy.js +194 -0
  149. package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
  150. package/src/infrastructure/adapters/FileIOHelper.js +178 -13
  151. package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
  152. package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
  153. package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
  154. package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
  155. package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
  156. package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
  157. package/src/infrastructure/chunkers/CdcChunker.js +53 -19
  158. package/src/infrastructure/chunkers/FixedChunker.js +15 -7
  159. package/src/infrastructure/chunkers/resolveChunker.js +3 -1
  160. package/src/infrastructure/codecs/CborCodec.js +3 -3
  161. package/src/infrastructure/codecs/JsonCodec.js +5 -5
  162. package/src/infrastructure/createGitPlumbing.js +22 -0
  163. package/src/package-version.js +1 -0
  164. package/src/ports/ChunkingPort.js +3 -3
  165. package/src/ports/CodecPort.js +4 -4
  166. package/src/ports/CompressionPort.js +57 -0
  167. package/src/ports/CryptoPort.js +138 -50
  168. package/src/ports/GitPersistencePort.js +32 -2
  169. package/src/ports/GitPlumbingFactoryPort.js +16 -0
  170. package/src/ports/GitRefPort.js +1 -1
  171. package/src/types/ambient.d.ts +10 -5
  172. package/test/CONVENTIONS.md +94 -0
  173. package/test/cycles/README.md +13 -0
package/docs/demo.gif ADDED
Binary file
@@ -0,0 +1,104 @@
1
+ # git-cas v6.0.0 Release Notes
2
+
3
+ v6.0.0 is the security and storage-shape release for `git-cas`. It simplifies
4
+ the encryption scheme model, makes CDC-compatible encryption deduplicate again,
5
+ hardens restore and metadata boundaries, and publishes a clearer operator path
6
+ for upgrading existing vault entries.
7
+
8
+ ## What's New
9
+
10
+ - **Current encryption schemes only**: active manifests now use `whole`,
11
+ `framed`, or `convergent`.
12
+ - **Convergent encryption**: CDC plus encryption now preserves deduplication by
13
+ deriving per-chunk keys and nonces from plaintext chunk digests.
14
+ - **Framed authenticated streaming**: fixed-chunk encrypted stores default to
15
+ `framed`, giving bounded per-frame authenticated restore.
16
+ - **AAD always on**: `whole` and `framed` bind slug context into AES-GCM
17
+ authentication data.
18
+ - **Vault privacy mode**: encrypted vaults can HMAC slug names so repository
19
+ readers cannot enumerate stored asset names.
20
+ - **Vault passphrase verifier**: encrypted vault metadata can authenticate a
21
+ derived vault key before the first entry is added, and legacy encrypted vaults
22
+ gain the verifier on the next keyed vault write.
23
+ - **Manifest integrity hashes**: manifests can carry codec-level integrity
24
+ hashes that are verified on read.
25
+ - **Runtime-neutral byte contract**: public byte surfaces now use `Uint8Array`
26
+ instead of Node-only `Buffer` types.
27
+ - **Simpler library setup**: `await ContentAddressableStore.open({ cwd })`
28
+ creates the default Git-backed facade without requiring callers to wire
29
+ `@git-stunts/plumbing`.
30
+ - **Package docs surface cleanup**: the npm package ships public runtime and
31
+ user documentation without internal audits, planning logs, archives, or unused
32
+ media.
33
+
34
+ ## Core Library Compatibility
35
+
36
+ The v6.0.0 release uses npm registry state as the dependency source of truth:
37
+
38
+ | Package | npm latest checked during release prep | `git-cas` relationship |
39
+ | --- | --- | --- |
40
+ | `@git-stunts/plumbing` | `3.0.3` | Direct runtime dependency for async Git command execution. |
41
+ | `@git-stunts/vault` | `1.0.1` | Direct runtime dependency for OS-keychain passphrase lookup. |
42
+ | `@git-stunts/trailer-codec` | `2.1.1` | Ecosystem companion library; not a `git-cas` runtime dependency because v6 vault history is not trailer-backed. |
43
+
44
+ ## Breaking Changes
45
+
46
+ - Legacy encryption scheme identifiers (`whole-v1`, `whole-v2`, `framed-v1`,
47
+ `framed-v2`, `convergent-v1`) are rejected by normal reads with
48
+ `LEGACY_SCHEME`.
49
+ - v1 whole/framed manifests require full re-encryption because they did not bind
50
+ AAD.
51
+ - Direct `CasService` construction now requires explicit `chunker` and
52
+ `compressionAdapter` ports. The `ContentAddressableStore` facade still
53
+ supplies defaults.
54
+ - `ContentAddressableStore.open({ cwd })` is now async so the `@git-stunts/plumbing`
55
+ v3 working-directory validation and runtime selection happen behind the
56
+ infrastructure adapter before the facade is returned.
57
+ - Custom `CryptoPort` implementations must support HMAC and explicit
58
+ nonce/tag AES-GCM helpers used by convergent encryption and vault privacy.
59
+ - Web Crypto no longer falls back to Node for scrypt.
60
+ - JSR publication is deferred for this release line because the external
61
+ `jsr`/Deno dry-run toolchain panics before package validation. npm remains
62
+ the supported v6 publication path.
63
+
64
+ ## Upgrade Now
65
+
66
+ Existing v5 users with encrypted vault entries should dry-run the migration
67
+ before restoring old encrypted content:
68
+
69
+ ```bash
70
+ npm run upgrade
71
+ ```
72
+
73
+ If the dry-run reports entries that need a full migration, use a passphrase file
74
+ or stdin source:
75
+
76
+ ```bash
77
+ printf '%s\n' '<content-passphrase>' | npm run upgrade -- --execute --passphrase-file -
78
+ ```
79
+
80
+ Raw 32-byte key users can migrate with:
81
+
82
+ ```bash
83
+ npm run upgrade -- --execute --key-file ./asset.key
84
+ ```
85
+
86
+ Privacy-enabled vaults need vault credentials for listing and updates. Prefer a
87
+ vault passphrase file/stdin source when the vault passphrase differs from the
88
+ content passphrase:
89
+
90
+ ```bash
91
+ printf '%s\n' '<vault-passphrase>' \
92
+ | npm run upgrade -- --execute --key-file ./asset.key --vault-passphrase-file -
93
+ ```
94
+
95
+ Inline `--passphrase` and `--vault-passphrase` are still accepted for
96
+ compatibility, but they print warnings because command-line arguments can leak
97
+ through shell history, process listings, CI logs, and terminal transcripts.
98
+
99
+ ## Read Next
100
+
101
+ - [UPGRADING.md](../../UPGRADING.md): complete v5 to v6 migration guide.
102
+ - [CHANGELOG.md](../../CHANGELOG.md): full change history.
103
+ - [README.md](../../README.md): current product overview and quick start.
104
+ - [SECURITY.md](../../SECURITY.md): security model and vulnerability reporting.
@@ -0,0 +1,260 @@
1
+ # git-cas Examples
2
+
3
+ This directory contains runnable examples demonstrating the core features of `@git-stunts/git-cas`.
4
+
5
+ The maintained non-TUI examples are covered by
6
+ `test/unit/docs/release-truth.test.js` so the public examples stay aligned with
7
+ the current API contract.
8
+
9
+ Audit status:
10
+
11
+ | File | Demonstrates | Notes |
12
+ | --- | --- | --- |
13
+ | `examples/store-and-restore.js` | Basic store/tree/read/restore/verify workflow | First example to run. Uses the public `readManifest()` helper for tree-to-manifest reads. |
14
+ | `examples/encrypted-workflow.js` | Raw-key AES-256-GCM store/restore failure modes | Uses current `framed` default encryption metadata unless you select another scheme in code. |
15
+ | `examples/progress-tracking.js` | `EventEmitterObserver` progress and integrity events | Shows the backward-compatible event bridge over the `ObservabilityPort`. |
16
+ | `examples/v6-blocks/dashboard-v6.js` | Bijou TUI dashboard mock-up | Visual prototype for the v6 cockpit-style vault dashboard. |
17
+ | `examples/v6-blocks/health-v6.js` | Bijou TUI health panel mock-up | Visual prototype for doctor/health reporting blocks. |
18
+ | `examples/v6-blocks/merkle-v6.js` | Bijou TUI Merkle explorer mock-up | Visual prototype for table/tree/DAG Merkle manifest exploration. |
19
+
20
+ ## Prerequisites
21
+
22
+ - Node.js 22 or later
23
+ - Git installed and available in PATH
24
+ - `@git-stunts/git-cas` installed
25
+
26
+ ## Setup
27
+
28
+ Before running the examples, ensure you have a Git repository initialized. The examples will create a temporary bare repository for demonstration purposes.
29
+
30
+ ```bash
31
+ # Install dependencies (from the repository root)
32
+ npm install
33
+
34
+ # Navigate to the examples directory
35
+ cd examples
36
+ ```
37
+
38
+ ## Running the Examples
39
+
40
+ Each example is a standalone Node.js script that can be run directly:
41
+
42
+ ```bash
43
+ node store-and-restore.js
44
+ node encrypted-workflow.js
45
+ node progress-tracking.js
46
+ node v6-blocks/dashboard-v6.js
47
+ node v6-blocks/health-v6.js
48
+ node v6-blocks/merkle-v6.js
49
+ ```
50
+
51
+ ## Examples Overview
52
+
53
+ ### store-and-restore.js
54
+
55
+ **Demonstrates:** Basic CAS workflow with verification
56
+
57
+ This example shows the complete lifecycle of storing and restoring a file:
58
+
59
+ 1. Creates a temporary Git bare repository
60
+ 2. Stores a file in the content-addressable store
61
+ 3. Creates a Git tree to persist the manifest
62
+ 4. Reads the manifest back from the tree with the public `readManifest()` helper
63
+ 5. Restores the file to disk
64
+ 6. Verifies the restored content matches the original
65
+ 7. Runs integrity verification on the stored chunks
66
+
67
+ **Key concepts:**
68
+
69
+ - `await ContentAddressableStore.open({ cwd })` factory
70
+ - `storeFile()` to store files
71
+ - `createTree()` to persist manifests in Git
72
+ - `readManifest()` to reconstruct manifests from Git trees
73
+ - `restoreFile()` to write files back to disk
74
+ - `verifyIntegrity()` to check chunk digests
75
+
76
+ ### encrypted-workflow.js
77
+
78
+ **Demonstrates:** Encryption and decryption with AES-256-GCM
79
+
80
+ This example shows how to work with encrypted content:
81
+
82
+ 1. Generates a secure 32-byte encryption key
83
+ 2. Stores a file with encryption enabled
84
+ 3. Restores the file using the correct key
85
+ 4. Demonstrates that using the wrong key causes an integrity error
86
+ 5. Shows the encryption metadata stored in the manifest
87
+
88
+ **Key concepts:**
89
+
90
+ - Generating encryption keys with `crypto.randomBytes(32)`
91
+ - Storing encrypted files with `encryptionKey` parameter
92
+ - Encryption metadata in manifests
93
+ - Decryption during restore
94
+ - Handling wrong key errors (INTEGRITY_ERROR)
95
+
96
+ ### progress-tracking.js
97
+
98
+ **Demonstrates:** Event-driven progress monitoring
99
+
100
+ This example shows how to track storage and restore operations using `EventEmitterObserver`:
101
+
102
+ 1. Creates an `EventEmitterObserver`
103
+ 2. Passes it into `ContentAddressableStore` via the `observability` option
104
+ 3. Attaches event listeners to the observer
105
+ 4. Builds a progress logger that tracks:
106
+ - Chunk storage progress
107
+ - File storage completion
108
+ - Chunk restoration progress
109
+ - File restoration completion
110
+ - Integrity verification results
111
+
112
+ **Key concepts:**
113
+
114
+ - `EventEmitterObserver` as the backward-compatible event bridge
115
+ - Event types: `chunk:stored`, `file:stored`, `chunk:restored`, `file:restored`, `integrity:pass`, `integrity:fail`, `error`
116
+ - Building real-time progress indicators
117
+ - Calculating percentages based on chunk counts
118
+
119
+ ### v6-blocks/dashboard-v6.js
120
+
121
+ **Demonstrates:** Interactive TUI layout for the v6 vault cockpit
122
+
123
+ This mock-up shows a keyboard-driven asset ledger and manifest inspector using
124
+ the Bijou TUI stack. It is a visual example rather than a live vault reader.
125
+
126
+ **Key concepts:**
127
+
128
+ - Bijou surfaces and boxed panels
129
+ - Keyboard focus movement
130
+ - Asset metadata badges for scheme and manifest shape
131
+
132
+ ### v6-blocks/health-v6.js
133
+
134
+ **Demonstrates:** Interactive TUI health reporting block
135
+
136
+ This mock-up shows how vault health, reachability, encryption posture, and
137
+ history events can be rendered as a compact operator panel.
138
+
139
+ **Key concepts:**
140
+
141
+ - Timeline rendering
142
+ - Health and status badges
143
+ - Help overlay behavior
144
+
145
+ ### v6-blocks/merkle-v6.js
146
+
147
+ **Demonstrates:** Merkle manifest visualization concepts
148
+
149
+ This mock-up shows table, tree, and DAG views for a Merkle manifest. It is a
150
+ visual companion to the Merkle manifest docs, not a live Git object reader.
151
+
152
+ **Key concepts:**
153
+
154
+ - Segmented view modes
155
+ - Sub-manifest hierarchy
156
+ - DAG-style chunk reference display
157
+
158
+ ## API Reference
159
+
160
+ ### Factory Methods
161
+
162
+ ```javascript
163
+ // JSON codec (default)
164
+ const cas = await ContentAddressableStore.open({ cwd: '/path/to/repo' });
165
+
166
+ // CBOR codec (binary, with an explicit Git plumbing instance)
167
+ const cas = ContentAddressableStore.createCbor({ plumbing });
168
+ ```
169
+
170
+ ### Storage Operations
171
+
172
+ ```javascript
173
+ // Store a file
174
+ const manifest = await cas.storeFile({
175
+ filePath: '/path/to/file',
176
+ slug: 'unique-identifier',
177
+ filename: 'optional-name.txt',
178
+ encryptionKey: optionalKeyBytes, // 32-byte Uint8Array
179
+ });
180
+
181
+ // Create a Git tree
182
+ const treeOid = await cas.createTree({ manifest });
183
+ ```
184
+
185
+ ### Restore Operations
186
+
187
+ ```javascript
188
+ // Restore to disk
189
+ await cas.restoreFile({
190
+ manifest,
191
+ encryptionKey: optionalKeyBytes,
192
+ outputPath: '/path/to/output',
193
+ });
194
+
195
+ // Restore to memory (returns Uint8Array)
196
+ const { buffer, bytesWritten } = await cas.restore({
197
+ manifest,
198
+ encryptionKey: optionalKeyBytes,
199
+ });
200
+ ```
201
+
202
+ ### Verification
203
+
204
+ ```javascript
205
+ // Plaintext manifests: verify chunk integrity
206
+ const isValid = await cas.verifyIntegrity(manifest);
207
+
208
+ // Encrypted manifests: authenticate chunks with restore credentials
209
+ const encryptedIsValid = await cas.verifyIntegrity(manifest, { encryptionKey: optionalKeyBytes });
210
+ ```
211
+
212
+ Encrypted manifests require the same credentials used for restore; without
213
+ them, `verifyIntegrity()` returns `false` after authentication fails.
214
+
215
+ ### Reading Manifests from Trees
216
+
217
+ ```javascript
218
+ const manifest = await cas.readManifest({ treeOid });
219
+ ```
220
+
221
+ ## Encryption Keys
222
+
223
+ Encryption keys must be 32-byte `Uint8Array` values for AES-256-GCM. Node
224
+ `Buffer` values also work because `Buffer` extends `Uint8Array`.
225
+
226
+ ```javascript
227
+ import { randomBytes } from 'node:crypto';
228
+
229
+ // Generate a secure random key
230
+ const key = randomBytes(32);
231
+
232
+ // Or use a key derived from a password
233
+ // (use a proper KDF like PBKDF2 or scrypt in production)
234
+ ```
235
+
236
+ ## Notes
237
+
238
+ - All examples clean up temporary files and directories
239
+ - The examples use temporary Git bare repositories to avoid polluting your working directory
240
+ - Chunk size defaults to 256 KiB (262,144 bytes)
241
+ - Relative file paths are fine; these examples happen to use temporary absolute paths
242
+ - Progress events are exposed through `EventEmitterObserver`, not by subscribing directly to `CasService`
243
+
244
+ ## Troubleshooting
245
+
246
+ **Error: "Encryption key must be 32 bytes"**
247
+
248
+ - Ensure your encryption key is exactly 32 bytes
249
+ - Use `crypto.randomBytes(32)` or equivalent
250
+
251
+ **Error: "INTEGRITY_ERROR"**
252
+
253
+ - Using wrong decryption key
254
+ - Chunk corruption in Git object database
255
+ - Run `verifyIntegrity()` to identify corrupted chunks
256
+
257
+ **Error: "MISSING_KEY"**
258
+
259
+ - Attempting to restore encrypted content without providing the key
260
+ - Check if `manifest.encryption.encrypted === true`