@git-stunts/git-cas 5.3.2 → 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.
Files changed (173) hide show
  1. package/ADVANCED_GUIDE.md +1027 -0
  2. package/ARCHITECTURE.md +514 -0
  3. package/CHANGELOG.md +449 -5
  4. package/CODE_OF_CONDUCT.md +33 -0
  5. package/GUIDE.md +926 -0
  6. package/README.md +106 -366
  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 +1255 -212
  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 +367 -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 +2254 -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 +273 -80
  60. package/index.js +220 -59
  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 +153 -53
  103. package/src/domain/services/CasService.js +322 -837
  104. package/src/domain/services/ChunkRepository.js +268 -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 +180 -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 +10 -6
  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/index.js CHANGED
@@ -12,11 +12,37 @@ import rotateVaultPassphrase from './src/domain/services/rotateVaultPassphrase.j
12
12
  import GitPersistenceAdapter from './src/infrastructure/adapters/GitPersistenceAdapter.js';
13
13
  import GitRefAdapter from './src/infrastructure/adapters/GitRefAdapter.js';
14
14
  import createCryptoAdapter from './src/infrastructure/adapters/createCryptoAdapter.js';
15
+ import { createGitPlumbing } from './src/infrastructure/createGitPlumbing.js';
15
16
  import { storeFile, restoreFile } from './src/infrastructure/adapters/FileIOHelper.js';
16
17
  import JsonCodec from './src/infrastructure/codecs/JsonCodec.js';
17
18
  import CborCodec from './src/infrastructure/codecs/CborCodec.js';
18
19
  import SilentObserver from './src/infrastructure/adapters/SilentObserver.js';
19
20
  import resolveChunker from './src/infrastructure/chunkers/resolveChunker.js';
21
+ import { CasError, createCasError, ErrorCodes } from './src/domain/errors/index.js';
22
+ import FixedChunker from './src/infrastructure/chunkers/FixedChunker.js';
23
+ import NodeCompressionAdapter from './src/infrastructure/adapters/NodeCompressionAdapter.js';
24
+ import { PACKAGE_VERSION } from './src/package-version.js';
25
+
26
+ /** @typedef {import('./src/domain/value-objects/Manifest.js').default} Manifest */
27
+
28
+ const PKG_VERSION = PACKAGE_VERSION;
29
+ const FIXED_CHUNKING_STRATEGY = 'fixed';
30
+ const RESTORE_FILE_DOCS_URL = `https://github.com/git-stunts/git-cas/blob/v${PKG_VERSION}/docs/API.md#restorefile`;
31
+
32
+ function withOperationChunker(options) {
33
+ const { chunking, ...rest } = options;
34
+ if (!chunking) {
35
+ return rest;
36
+ }
37
+ const chunker = resolveChunker({ chunking });
38
+ if (chunker) {
39
+ return { ...rest, chunker };
40
+ }
41
+ if (chunking.strategy === FIXED_CHUNKING_STRATEGY && chunking.chunkSize === undefined) {
42
+ return { ...rest, chunker: new FixedChunker() };
43
+ }
44
+ return rest;
45
+ }
20
46
 
21
47
  // ---------------------------------------------------------------------------
22
48
  // Re-exports — modules used in the class body
@@ -29,6 +55,7 @@ export {
29
55
  JsonCodec,
30
56
  CborCodec,
31
57
  SilentObserver,
58
+ CasError,
32
59
  };
33
60
 
34
61
  // ---------------------------------------------------------------------------
@@ -44,6 +71,10 @@ export { default as EventEmitterObserver } from './src/infrastructure/adapters/E
44
71
  export { default as StatsCollector } from './src/infrastructure/adapters/StatsCollector.js';
45
72
  export { default as FixedChunker } from './src/infrastructure/chunkers/FixedChunker.js';
46
73
  export { default as CdcChunker } from './src/infrastructure/chunkers/CdcChunker.js';
74
+ export { default as CompressionPort } from './src/ports/CompressionPort.js';
75
+ export { default as NodeCompressionAdapter } from './src/infrastructure/adapters/NodeCompressionAdapter.js';
76
+ export { default as diffManifests } from './src/domain/services/ManifestDiff.js';
77
+ export { SCHEME_WHOLE, SCHEME_FRAMED, SCHEME_CONVERGENT } from './src/domain/encryption/schemes.js';
47
78
 
48
79
  /**
49
80
  * High-level facade for the Content Addressable Store library.
@@ -62,17 +93,47 @@ export default class ContentAddressableStore {
62
93
  * @param {import('@git-stunts/alfred').Policy} [options.policy] - Resilience policy for Git I/O.
63
94
  * @param {number} [options.merkleThreshold=1000] - Chunk count threshold for Merkle manifests.
64
95
  * @param {number} [options.concurrency=1] - Maximum parallel chunk I/O operations.
65
- * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number }} [options.chunking] - Chunking strategy config.
96
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number, normalized?: boolean }} [options.chunking] - Chunking strategy config.
66
97
  * @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance (advanced).
67
98
  * @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes for encrypted/compressed restores (default 512 MiB).
99
+ * @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes (default 10 MiB).
100
+ * @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter (default NodeCompressionAdapter).
68
101
  */
69
- constructor({ plumbing, chunkSize, codec, policy, crypto, observability, merkleThreshold, concurrency, chunking, chunker, maxRestoreBufferSize }) {
70
- this.#config = { plumbing, chunkSize, codec, policy, crypto, observability, merkleThreshold, concurrency, chunking, chunker, maxRestoreBufferSize };
102
+ constructor({
103
+ plumbing,
104
+ chunkSize,
105
+ codec,
106
+ policy,
107
+ crypto,
108
+ observability,
109
+ merkleThreshold,
110
+ concurrency,
111
+ chunking,
112
+ chunker,
113
+ maxRestoreBufferSize,
114
+ maxBlobSize,
115
+ compressionAdapter,
116
+ }) {
117
+ this.#config = {
118
+ plumbing,
119
+ chunkSize,
120
+ codec,
121
+ policy,
122
+ crypto,
123
+ observability,
124
+ merkleThreshold,
125
+ concurrency,
126
+ chunking,
127
+ chunker,
128
+ maxRestoreBufferSize,
129
+ maxBlobSize,
130
+ compressionAdapter,
131
+ };
71
132
  this.service = null;
72
133
  this.#servicePromise = null;
73
134
  }
74
135
 
75
- /** @type {{ plumbing: *, chunkSize?: number, codec?: *, policy?: *, crypto?: *, observability?: *, merkleThreshold?: number, concurrency?: number, chunking?: *, chunker?: *, maxRestoreBufferSize?: number }} */
136
+ /** @type {{ plumbing: *, chunkSize?: number, codec?: *, policy?: *, crypto?: *, observability?: *, merkleThreshold?: number, concurrency?: number, chunking?: *, chunker?: *, maxRestoreBufferSize?: number, maxBlobSize?: number, compressionAdapter?: * }} */
76
137
  #config;
77
138
  /** @type {VaultService|null} */
78
139
  #vault = null;
@@ -101,11 +162,14 @@ export default class ContentAddressableStore {
101
162
  plumbing: cfg.plumbing,
102
163
  policy: cfg.policy,
103
164
  });
104
- const crypto = cfg.crypto || await createCryptoAdapter();
105
- const chunker = resolveChunker({ chunker: cfg.chunker, chunking: cfg.chunking });
165
+ const crypto = cfg.crypto || (await createCryptoAdapter());
166
+ const chunkSize = cfg.chunkSize || 256 * 1024;
167
+ const chunker =
168
+ resolveChunker({ chunker: cfg.chunker, chunking: cfg.chunking }) ||
169
+ new FixedChunker({ chunkSize });
106
170
  this.service = new CasService({
107
171
  persistence,
108
- chunkSize: cfg.chunkSize,
172
+ chunkSize,
109
173
  codec: cfg.codec || new JsonCodec(),
110
174
  crypto,
111
175
  observability: cfg.observability || new SilentObserver(),
@@ -113,13 +177,21 @@ export default class ContentAddressableStore {
113
177
  concurrency: cfg.concurrency,
114
178
  chunker,
115
179
  maxRestoreBufferSize: cfg.maxRestoreBufferSize,
180
+ maxBlobSize: cfg.maxBlobSize,
181
+ compressionAdapter: cfg.compressionAdapter || new NodeCompressionAdapter(),
182
+ formatVersion: PKG_VERSION,
116
183
  });
117
184
 
118
185
  const ref = new GitRefAdapter({
119
186
  plumbing: cfg.plumbing,
120
187
  policy: cfg.policy,
121
188
  });
122
- this.#vault = new VaultService({ persistence, ref, crypto, observability: this.service.observability });
189
+ this.#vault = new VaultService({
190
+ persistence,
191
+ ref,
192
+ crypto,
193
+ observability: this.service.observability,
194
+ });
123
195
 
124
196
  return this.service;
125
197
  }
@@ -150,16 +222,55 @@ export default class ContentAddressableStore {
150
222
  return await this.#getVault();
151
223
  }
152
224
 
225
+ /**
226
+ * Factory to create a default JSON CAS from a Git working directory.
227
+ *
228
+ * This is the shortest path for normal callers: the facade constructs the
229
+ * runtime-aware Git plumbing adapter and keeps all other options available.
230
+ *
231
+ * @param {Object} [options]
232
+ * @param {string} [options.cwd='.'] - Git working directory.
233
+ * @param {string} [options.env] - Shell runner environment override.
234
+ * @param {number} [options.chunkSize] - Chunk size in bytes.
235
+ * @param {import('./src/ports/CodecPort.js').default} [options.codec] - Manifest codec.
236
+ * @param {import('@git-stunts/alfred').Policy} [options.policy] - Resilience policy.
237
+ * @param {import('./src/ports/CryptoPort.js').default} [options.crypto] - Crypto adapter.
238
+ * @param {import('./src/ports/ObservabilityPort.js').default} [options.observability] - Observability adapter.
239
+ * @param {number} [options.merkleThreshold=1000] - Chunk count threshold for Merkle manifests.
240
+ * @param {number} [options.concurrency=1] - Maximum parallel chunk I/O operations.
241
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number, normalized?: boolean }} [options.chunking] - Chunking strategy config.
242
+ * @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance.
243
+ * @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes.
244
+ * @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes.
245
+ * @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter.
246
+ * @returns {Promise<ContentAddressableStore>}
247
+ */
248
+ static async open({ cwd = '.', env, ...options } = {}) {
249
+ return new ContentAddressableStore({
250
+ ...options,
251
+ plumbing: await createGitPlumbing({ cwd, env }),
252
+ });
253
+ }
254
+
153
255
  /**
154
256
  * Factory to create a CAS with JSON codec.
155
257
  * @param {Object} options
156
258
  * @param {import('@git-stunts/plumbing').default} options.plumbing - GitPlumbing instance.
157
259
  * @param {number} [options.chunkSize] - Chunk size in bytes.
158
260
  * @param {import('@git-stunts/alfred').Policy} [options.policy] - Resilience policy.
261
+ * @param {import('./src/ports/CryptoPort.js').default} [options.crypto] - Crypto adapter.
262
+ * @param {import('./src/ports/ObservabilityPort.js').default} [options.observability] - Observability adapter.
263
+ * @param {number} [options.merkleThreshold=1000] - Chunk count threshold for Merkle manifests.
264
+ * @param {number} [options.concurrency=1] - Maximum parallel chunk I/O operations.
265
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number, normalized?: boolean }} [options.chunking] - Chunking strategy config.
266
+ * @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance.
267
+ * @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes.
268
+ * @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes.
269
+ * @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter.
159
270
  * @returns {ContentAddressableStore}
160
271
  */
161
- static createJson({ plumbing, chunkSize, policy }) {
162
- return new ContentAddressableStore({ plumbing, chunkSize, codec: new JsonCodec(), policy });
272
+ static createJson({ plumbing, ...options }) {
273
+ return new ContentAddressableStore({ ...options, plumbing, codec: new JsonCodec() });
163
274
  }
164
275
 
165
276
  /**
@@ -168,10 +279,19 @@ export default class ContentAddressableStore {
168
279
  * @param {import('@git-stunts/plumbing').default} options.plumbing - GitPlumbing instance.
169
280
  * @param {number} [options.chunkSize] - Chunk size in bytes.
170
281
  * @param {import('@git-stunts/alfred').Policy} [options.policy] - Resilience policy.
282
+ * @param {import('./src/ports/CryptoPort.js').default} [options.crypto] - Crypto adapter.
283
+ * @param {import('./src/ports/ObservabilityPort.js').default} [options.observability] - Observability adapter.
284
+ * @param {number} [options.merkleThreshold=1000] - Chunk count threshold for Merkle manifests.
285
+ * @param {number} [options.concurrency=1] - Maximum parallel chunk I/O operations.
286
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number, normalized?: boolean }} [options.chunking] - Chunking strategy config.
287
+ * @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance.
288
+ * @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes.
289
+ * @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes.
290
+ * @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter.
171
291
  * @returns {ContentAddressableStore}
172
292
  */
173
- static createCbor({ plumbing, chunkSize, policy }) {
174
- return new ContentAddressableStore({ plumbing, chunkSize, codec: new CborCodec(), policy });
293
+ static createCbor({ plumbing, ...options }) {
294
+ return new ContentAddressableStore({ ...options, plumbing, codec: new CborCodec() });
175
295
  }
176
296
 
177
297
  /**
@@ -183,11 +303,11 @@ export default class ContentAddressableStore {
183
303
  }
184
304
 
185
305
  /**
186
- * Encrypts a buffer using AES-256-GCM.
306
+ * Encrypts bytes using AES-256-GCM.
187
307
  * @param {Object} options
188
- * @param {Buffer} options.buffer - Plaintext data to encrypt.
189
- * @param {Buffer} options.key - 32-byte encryption key.
190
- * @returns {Promise<{ buf: Buffer, meta: { algorithm: string, nonce: string, tag: string, encrypted: boolean } }>}
308
+ * @param {Uint8Array} options.buffer - Plaintext data to encrypt.
309
+ * @param {Uint8Array} options.key - 32-byte encryption key.
310
+ * @returns {Promise<{ buf: Uint8Array, meta: { algorithm: string, nonce: string, tag: string, encrypted: boolean } }>}
191
311
  */
192
312
  async encrypt(options) {
193
313
  const service = await this.#getService();
@@ -195,12 +315,12 @@ export default class ContentAddressableStore {
195
315
  }
196
316
 
197
317
  /**
198
- * Decrypts a buffer. Returns it unchanged if `meta.encrypted` is falsy.
318
+ * Decrypts bytes. Returns them unchanged if `meta.encrypted` is falsy.
199
319
  * @param {Object} options
200
- * @param {Buffer} options.buffer - Ciphertext to decrypt.
201
- * @param {Buffer} options.key - 32-byte encryption key.
320
+ * @param {Uint8Array} options.buffer - Ciphertext to decrypt.
321
+ * @param {Uint8Array} options.key - 32-byte encryption key.
202
322
  * @param {{ encrypted: boolean, algorithm: string, nonce: string, tag: string }} options.meta - Encryption metadata.
203
- * @returns {Promise<Buffer>}
323
+ * @returns {Promise<Uint8Array>}
204
324
  */
205
325
  async decrypt(options) {
206
326
  const service = await this.#getService();
@@ -213,57 +333,73 @@ export default class ContentAddressableStore {
213
333
  * @param {string} options.filePath - Absolute or relative path to the file.
214
334
  * @param {string} options.slug - Logical identifier for the stored asset.
215
335
  * @param {string} [options.filename] - Override filename (defaults to basename of filePath).
216
- * @param {Buffer} [options.encryptionKey] - 32-byte key for AES-256-GCM encryption.
336
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key for AES-256-GCM encryption.
217
337
  * @param {string} [options.passphrase] - Derive encryption key from passphrase.
338
+ * @param {{ scheme?: 'whole'|'framed'|'convergent', frameBytes?: number, convergent?: boolean }} [options.encryption] - Explicit encryption scheme selection.
218
339
  * @param {Object} [options.kdfOptions] - KDF options when using passphrase.
219
340
  * @param {{ algorithm: 'gzip' }} [options.compression] - Enable compression.
220
- * @param {Array<{label: string, key: Buffer}>} [options.recipients] - Envelope recipients (mutually exclusive with encryptionKey/passphrase).
221
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>} The resulting manifest.
341
+ * @param {Array<{label: string, key: Uint8Array}>} [options.recipients] - Envelope recipients (mutually exclusive with encryptionKey/passphrase).
342
+ * @param {number} [options.merkleThreshold] - Per-operation chunk count threshold for Merkle tree publication.
343
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number, normalized?: boolean }} [options.chunking] - Per-operation chunking strategy config.
344
+ * @returns {Promise<Manifest>} The resulting manifest.
222
345
  */
223
346
  async storeFile(options) {
224
347
  const service = await this.#getService();
225
- return await storeFile(service, options);
348
+ return await storeFile(service, withOperationChunker(options));
226
349
  }
227
350
 
228
351
  /**
229
352
  * Stores an async iterable source in Git as chunked blobs.
230
353
  * @param {Object} options
231
- * @param {AsyncIterable<Buffer>} options.source - Data to store.
354
+ * @param {AsyncIterable<Uint8Array>} options.source - Data to store.
232
355
  * @param {string} options.slug - Logical identifier for the stored asset.
233
356
  * @param {string} options.filename - Filename for the manifest.
234
- * @param {Buffer} [options.encryptionKey] - 32-byte key for AES-256-GCM encryption.
357
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key for AES-256-GCM encryption.
235
358
  * @param {string} [options.passphrase] - Derive encryption key from passphrase.
359
+ * @param {{ scheme?: 'whole'|'framed'|'convergent', frameBytes?: number, convergent?: boolean }} [options.encryption] - Explicit encryption scheme selection.
236
360
  * @param {Object} [options.kdfOptions] - KDF options when using passphrase.
237
361
  * @param {{ algorithm: 'gzip' }} [options.compression] - Enable compression.
238
- * @param {Array<{label: string, key: Buffer}>} [options.recipients] - Envelope recipients (mutually exclusive with encryptionKey/passphrase).
239
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>} The resulting manifest.
362
+ * @param {Array<{label: string, key: Uint8Array}>} [options.recipients] - Envelope recipients (mutually exclusive with encryptionKey/passphrase).
363
+ * @param {number} [options.merkleThreshold] - Per-operation chunk count threshold for Merkle tree publication.
364
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number, normalized?: boolean }} [options.chunking] - Per-operation chunking strategy config.
365
+ * @returns {Promise<Manifest>} The resulting manifest.
240
366
  */
241
367
  async store(options) {
242
368
  const service = await this.#getService();
243
- return await service.store(options);
369
+ return await service.store(withOperationChunker(options));
244
370
  }
245
371
 
246
372
  /**
247
373
  * Restores a file from its manifest and writes it to disk.
248
374
  * @param {Object} options
249
- * @param {import('./src/domain/value-objects/Manifest.js').default} options.manifest - The file manifest.
250
- * @param {Buffer} [options.encryptionKey] - 32-byte key, required if manifest is encrypted.
375
+ * @param {Manifest} options.manifest - The file manifest.
376
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key, required if manifest is encrypted.
251
377
  * @param {string} [options.passphrase] - Passphrase for KDF-based decryption.
252
378
  * @param {string} options.outputPath - Destination file path.
379
+ * @param {string} options.baseDirectory - Directory boundary that outputPath must stay inside.
253
380
  * @returns {Promise<{ bytesWritten: number }>}
254
381
  */
255
382
  async restoreFile(options) {
383
+ if (!options?.baseDirectory) {
384
+ throw createCasError({
385
+ message:
386
+ 'baseDirectory is required for safe restoration. If you are restoring in a trusted local environment, pass baseDirectory: process.cwd().',
387
+ code: ErrorCodes.INVALID_OPTIONS,
388
+ meta: { option: 'baseDirectory' },
389
+ documentationUrl: RESTORE_FILE_DOCS_URL,
390
+ });
391
+ }
256
392
  const service = await this.#getService();
257
393
  return await restoreFile(service, options);
258
394
  }
259
395
 
260
396
  /**
261
- * Restores a file from its manifest, returning the buffer directly.
397
+ * Restores a file from its manifest, returning the bytes directly.
262
398
  * @param {Object} options
263
- * @param {import('./src/domain/value-objects/Manifest.js').default} options.manifest - The file manifest.
264
- * @param {Buffer} [options.encryptionKey] - 32-byte key, required if manifest is encrypted.
399
+ * @param {Manifest} options.manifest - The file manifest.
400
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key, required if manifest is encrypted.
265
401
  * @param {string} [options.passphrase] - Passphrase for KDF-based decryption.
266
- * @returns {Promise<{ buffer: Buffer, bytesWritten: number }>}
402
+ * @returns {Promise<{ buffer: Uint8Array, bytesWritten: number }>}
267
403
  */
268
404
  async restore(options) {
269
405
  const service = await this.#getService();
@@ -271,12 +407,12 @@ export default class ContentAddressableStore {
271
407
  }
272
408
 
273
409
  /**
274
- * Restores a file from its manifest as an async iterable of Buffer chunks.
410
+ * Restores a file from its manifest as an async iterable of byte chunks.
275
411
  * @param {Object} options
276
- * @param {import('./src/domain/value-objects/Manifest.js').default} options.manifest - The file manifest.
277
- * @param {Buffer} [options.encryptionKey] - 32-byte key, required if manifest is encrypted.
412
+ * @param {Manifest} options.manifest - The file manifest.
413
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key, required if manifest is encrypted.
278
414
  * @param {string} [options.passphrase] - Passphrase for KDF-based decryption.
279
- * @returns {AsyncIterable<Buffer>}
415
+ * @returns {AsyncIterable<Uint8Array>}
280
416
  */
281
417
  async *restoreStream(options) {
282
418
  const service = await this.#getService();
@@ -286,7 +422,8 @@ export default class ContentAddressableStore {
286
422
  /**
287
423
  * Creates a Git tree object from a manifest.
288
424
  * @param {Object} options
289
- * @param {import('./src/domain/value-objects/Manifest.js').default} options.manifest - The file manifest.
425
+ * @param {Manifest} options.manifest - The file manifest.
426
+ * @param {number} [options.merkleThreshold] - Override chunk count threshold for this tree publication.
290
427
  * @returns {Promise<string>} Git OID of the created tree.
291
428
  */
292
429
  async createTree(options) {
@@ -296,25 +433,37 @@ export default class ContentAddressableStore {
296
433
 
297
434
  /**
298
435
  * Verifies the integrity of a stored file by re-hashing its chunks.
299
- * @param {import('./src/domain/value-objects/Manifest.js').default} manifest - The file manifest.
436
+ * @param {Manifest} manifest - The file manifest.
437
+ * @param {{ encryptionKey?: Uint8Array, passphrase?: string }} [options] - Optional decryption credentials for encrypted manifests.
300
438
  * @returns {Promise<boolean>} `true` if all chunks pass verification.
301
439
  */
302
- async verifyIntegrity(manifest) {
440
+ async verifyIntegrity(manifest, options) {
303
441
  const service = await this.#getService();
304
- return await service.verifyIntegrity(manifest);
442
+ return await service.verifyIntegrity(manifest, options);
305
443
  }
306
444
 
307
445
  /**
308
446
  * Reads a manifest from a Git tree OID.
309
447
  * @param {Object} options
310
448
  * @param {string} options.treeOid - Git tree OID to read the manifest from.
311
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>}
449
+ * @returns {Promise<Manifest>}
312
450
  */
313
451
  async readManifest(options) {
314
452
  const service = await this.#getService();
315
453
  return await service.readManifest(options);
316
454
  }
317
455
 
456
+ /**
457
+ * Compares two manifests by chunk digest.
458
+ * Pure function — no I/O needed. Does not require initialization.
459
+ * @param {Manifest} oldManifest
460
+ * @param {Manifest} newManifest
461
+ * @returns {import('./src/domain/services/ManifestDiff.js').ManifestDiffResult}
462
+ */
463
+ static diffManifests(oldManifest, newManifest) {
464
+ return CasService.diffManifests(oldManifest, newManifest);
465
+ }
466
+
318
467
  /**
319
468
  * Reads a manifest from a Git tree and returns inspection metadata.
320
469
  * @param {Object} options
@@ -363,14 +512,14 @@ export default class ContentAddressableStore {
363
512
  * Derives an encryption key from a passphrase using PBKDF2 or scrypt.
364
513
  * @param {Object} options
365
514
  * @param {string} options.passphrase - The passphrase.
366
- * @param {Buffer} [options.salt] - Salt (random if omitted).
515
+ * @param {Uint8Array} [options.salt] - Salt (random if omitted).
367
516
  * @param {'pbkdf2'|'scrypt'} [options.algorithm='pbkdf2'] - KDF algorithm.
368
517
  * @param {number} [options.iterations] - PBKDF2 iterations.
369
518
  * @param {number} [options.cost] - scrypt cost (N).
370
519
  * @param {number} [options.blockSize] - scrypt block size (r).
371
520
  * @param {number} [options.parallelization] - scrypt parallelization (p).
372
521
  * @param {number} [options.keyLength=32] - Derived key length.
373
- * @returns {Promise<{ key: Buffer, salt: Buffer, params: Object }>}
522
+ * @returns {Promise<{ key: Uint8Array, salt: Uint8Array, params: Object }>}
374
523
  */
375
524
  async deriveKey(options) {
376
525
  const service = await this.#getService();
@@ -384,11 +533,11 @@ export default class ContentAddressableStore {
384
533
  /**
385
534
  * Adds a recipient to an envelope-encrypted manifest.
386
535
  * @param {Object} options
387
- * @param {import('./src/domain/value-objects/Manifest.js').default} options.manifest
388
- * @param {Buffer} options.existingKey - KEK of an existing recipient.
389
- * @param {Buffer} options.newRecipientKey - KEK for the new recipient.
536
+ * @param {Manifest} options.manifest
537
+ * @param {Uint8Array} options.existingKey - KEK of an existing recipient.
538
+ * @param {Uint8Array} options.newRecipientKey - KEK for the new recipient.
390
539
  * @param {string} options.label - Label for the new recipient.
391
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>}
540
+ * @returns {Promise<Manifest>}
392
541
  */
393
542
  async addRecipient(options) {
394
543
  const service = await this.#getService();
@@ -398,9 +547,9 @@ export default class ContentAddressableStore {
398
547
  /**
399
548
  * Removes a recipient from an envelope-encrypted manifest.
400
549
  * @param {Object} options
401
- * @param {import('./src/domain/value-objects/Manifest.js').default} options.manifest
550
+ * @param {Manifest} options.manifest
402
551
  * @param {string} options.label - Label to remove.
403
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>}
552
+ * @returns {Promise<Manifest>}
404
553
  */
405
554
  async removeRecipient(options) {
406
555
  const service = await this.#getService();
@@ -409,7 +558,7 @@ export default class ContentAddressableStore {
409
558
 
410
559
  /**
411
560
  * Lists recipient labels from an envelope-encrypted manifest.
412
- * @param {import('./src/domain/value-objects/Manifest.js').default} manifest
561
+ * @param {Manifest} manifest
413
562
  * @returns {Promise<string[]>}
414
563
  */
415
564
  async listRecipients(manifest) {
@@ -420,11 +569,11 @@ export default class ContentAddressableStore {
420
569
  /**
421
570
  * Rotates a recipient's key without re-encrypting data blobs.
422
571
  * @param {Object} options
423
- * @param {import('./src/domain/value-objects/Manifest.js').default} options.manifest
424
- * @param {Buffer} options.oldKey - Current KEK of the recipient to rotate.
425
- * @param {Buffer} options.newKey - New KEK to wrap the DEK with.
572
+ * @param {Manifest} options.manifest
573
+ * @param {Uint8Array} options.oldKey - Current KEK of the recipient to rotate.
574
+ * @param {Uint8Array} options.newKey - New KEK to wrap the DEK with.
426
575
  * @param {string} [options.label] - If provided, only rotate the named recipient.
427
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>}
576
+ * @returns {Promise<Manifest>}
428
577
  */
429
578
  async rotateKey(options) {
430
579
  const service = await this.#getService();
@@ -450,9 +599,15 @@ export default class ContentAddressableStore {
450
599
  }
451
600
 
452
601
  /** @see VaultService#listVault */
453
- async listVault() {
602
+ async listVault(options) {
454
603
  const vault = await this.#getVault();
455
- return vault.listVault();
604
+ return vault.listVault(options);
605
+ }
606
+
607
+ /** @see VaultService#iterateVault */
608
+ async *iterateVault(options) {
609
+ const vault = await this.#getVault();
610
+ yield* vault.iterateVault(options);
456
611
  }
457
612
 
458
613
  /** @see VaultService#removeFromVault */
@@ -467,6 +622,12 @@ export default class ContentAddressableStore {
467
622
  return vault.resolveVaultEntry(options);
468
623
  }
469
624
 
625
+ /** @see VaultService#verifyVaultKey */
626
+ async verifyVaultKey(options) {
627
+ const vault = await this.#getVault();
628
+ return vault.verifyVaultKey(options);
629
+ }
630
+
470
631
  /** @see VaultService#getVaultMetadata */
471
632
  async getVaultMetadata() {
472
633
  const vault = await this.#getVault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@git-stunts/git-cas",
3
- "version": "5.3.2",
3
+ "version": "6.0.1",
4
4
  "description": "Content-addressed storage backed by Git's object database, with optional encryption and pluggable codecs",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -15,9 +15,30 @@
15
15
  "files": [
16
16
  "index.js",
17
17
  "index.d.ts",
18
+ "build-info.json",
18
19
  "bin/",
19
20
  "src/",
21
+ "scripts/migrate-encryption.js",
20
22
  "README.md",
23
+ "CODE_OF_CONDUCT.md",
24
+ "GUIDE.md",
25
+ "ADVANCED_GUIDE.md",
26
+ "ARCHITECTURE.md",
27
+ "SECURITY.md",
28
+ "SUPPORT.md",
29
+ "UPGRADING.md",
30
+ "docs/API.md",
31
+ "docs/ENCRYPTION_MODES.md",
32
+ "docs/EXTENDING.md",
33
+ "docs/STORE_RESTORE_PIPELINE.md",
34
+ "docs/releases/v6.0.0.md",
35
+ "docs/THREAT_MODEL.md",
36
+ "docs/VAULT_INTERNALS.md",
37
+ "docs/WALKTHROUGH.md",
38
+ "docs/demo.gif",
39
+ "examples/README.md",
40
+ "test/CONVENTIONS.md",
41
+ "test/cycles/README.md",
21
42
  "LICENSE",
22
43
  "CHANGELOG.md"
23
44
  ],
@@ -62,17 +83,24 @@
62
83
  "test:platforms": "bats --jobs 3 test/platform/runtimes.bats",
63
84
  "benchmark": "vitest bench test/benchmark",
64
85
  "benchmark:local": "vitest bench test/benchmark",
86
+ "release:verify": "node scripts/release/verify.js",
87
+ "stamp": "node scripts/stamp-build.js",
88
+ "prepack": "node scripts/stamp-build.js --quiet",
89
+ "prepublishOnly": "node scripts/stamp-build.js",
90
+ "upgrade": "node scripts/migrate-encryption.js",
65
91
  "lint": "eslint .",
66
92
  "format": "prettier --write ."
67
93
  },
68
94
  "dependencies": {
69
- "@flyingrobots/bijou": "^0.2.0",
70
- "@flyingrobots/bijou-node": "^0.2.0",
71
- "@flyingrobots/bijou-tui": "^0.2.0",
95
+ "@flyingrobots/bijou": "^5.0.0",
96
+ "@flyingrobots/bijou-node": "^5.0.0",
97
+ "@flyingrobots/bijou-tui": "^5.0.0",
98
+ "@flyingrobots/bijou-tui-app": "^5.0.0",
72
99
  "@git-stunts/alfred": "^0.10.0",
73
- "@git-stunts/plumbing": "^2.8.0",
100
+ "@git-stunts/plumbing": "^3.0.3",
101
+ "@git-stunts/vault": "^1.0.1",
74
102
  "cbor-x": "^1.6.0",
75
- "commander": "^14.0.3",
103
+ "commander": "14.0.3",
76
104
  "zod": "^3.24.1"
77
105
  },
78
106
  "pnpm": {
@@ -85,6 +113,7 @@
85
113
  "@eslint/js": "^9.17.0",
86
114
  "@types/node": "^25.3.2",
87
115
  "eslint": "^9.17.0",
116
+ "fast-check": "^4.6.0",
88
117
  "jsr": "^0.14.2",
89
118
  "prettier": "^3.4.2",
90
119
  "vitest": "^2.1.8"