@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/index.js CHANGED
@@ -12,11 +12,22 @@ 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 RESTORE_FILE_DOCS_URL =
30
+ `https://github.com/git-stunts/git-cas/blob/v${PKG_VERSION}/docs/API.md#restorefile`;
20
31
 
21
32
  // ---------------------------------------------------------------------------
22
33
  // Re-exports — modules used in the class body
@@ -29,6 +40,7 @@ export {
29
40
  JsonCodec,
30
41
  CborCodec,
31
42
  SilentObserver,
43
+ CasError,
32
44
  };
33
45
 
34
46
  // ---------------------------------------------------------------------------
@@ -44,6 +56,10 @@ export { default as EventEmitterObserver } from './src/infrastructure/adapters/E
44
56
  export { default as StatsCollector } from './src/infrastructure/adapters/StatsCollector.js';
45
57
  export { default as FixedChunker } from './src/infrastructure/chunkers/FixedChunker.js';
46
58
  export { default as CdcChunker } from './src/infrastructure/chunkers/CdcChunker.js';
59
+ export { default as CompressionPort } from './src/ports/CompressionPort.js';
60
+ export { default as NodeCompressionAdapter } from './src/infrastructure/adapters/NodeCompressionAdapter.js';
61
+ export { default as diffManifests } from './src/domain/services/ManifestDiff.js';
62
+ export { SCHEME_WHOLE, SCHEME_FRAMED, SCHEME_CONVERGENT } from './src/domain/encryption/schemes.js';
47
63
 
48
64
  /**
49
65
  * High-level facade for the Content Addressable Store library.
@@ -65,14 +81,16 @@ export default class ContentAddressableStore {
65
81
  * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number }} [options.chunking] - Chunking strategy config.
66
82
  * @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance (advanced).
67
83
  * @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes for encrypted/compressed restores (default 512 MiB).
84
+ * @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes (default 10 MiB).
85
+ * @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter (default NodeCompressionAdapter).
68
86
  */
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 };
87
+ constructor({ plumbing, chunkSize, codec, policy, crypto, observability, merkleThreshold, concurrency, chunking, chunker, maxRestoreBufferSize, maxBlobSize, compressionAdapter }) {
88
+ this.#config = { plumbing, chunkSize, codec, policy, crypto, observability, merkleThreshold, concurrency, chunking, chunker, maxRestoreBufferSize, maxBlobSize, compressionAdapter };
71
89
  this.service = null;
72
90
  this.#servicePromise = null;
73
91
  }
74
92
 
75
- /** @type {{ plumbing: *, chunkSize?: number, codec?: *, policy?: *, crypto?: *, observability?: *, merkleThreshold?: number, concurrency?: number, chunking?: *, chunker?: *, maxRestoreBufferSize?: number }} */
93
+ /** @type {{ plumbing: *, chunkSize?: number, codec?: *, policy?: *, crypto?: *, observability?: *, merkleThreshold?: number, concurrency?: number, chunking?: *, chunker?: *, maxRestoreBufferSize?: number, maxBlobSize?: number, compressionAdapter?: * }} */
76
94
  #config;
77
95
  /** @type {VaultService|null} */
78
96
  #vault = null;
@@ -102,10 +120,12 @@ export default class ContentAddressableStore {
102
120
  policy: cfg.policy,
103
121
  });
104
122
  const crypto = cfg.crypto || await createCryptoAdapter();
105
- const chunker = resolveChunker({ chunker: cfg.chunker, chunking: cfg.chunking });
123
+ const chunkSize = cfg.chunkSize || 256 * 1024;
124
+ const chunker = resolveChunker({ chunker: cfg.chunker, chunking: cfg.chunking })
125
+ || new FixedChunker({ chunkSize });
106
126
  this.service = new CasService({
107
127
  persistence,
108
- chunkSize: cfg.chunkSize,
128
+ chunkSize,
109
129
  codec: cfg.codec || new JsonCodec(),
110
130
  crypto,
111
131
  observability: cfg.observability || new SilentObserver(),
@@ -113,6 +133,9 @@ export default class ContentAddressableStore {
113
133
  concurrency: cfg.concurrency,
114
134
  chunker,
115
135
  maxRestoreBufferSize: cfg.maxRestoreBufferSize,
136
+ maxBlobSize: cfg.maxBlobSize,
137
+ compressionAdapter: cfg.compressionAdapter || new NodeCompressionAdapter(),
138
+ formatVersion: PKG_VERSION,
116
139
  });
117
140
 
118
141
  const ref = new GitRefAdapter({
@@ -150,16 +173,55 @@ export default class ContentAddressableStore {
150
173
  return await this.#getVault();
151
174
  }
152
175
 
176
+ /**
177
+ * Factory to create a default JSON CAS from a Git working directory.
178
+ *
179
+ * This is the shortest path for normal callers: the facade constructs the
180
+ * runtime-aware Git plumbing adapter and keeps all other options available.
181
+ *
182
+ * @param {Object} [options]
183
+ * @param {string} [options.cwd='.'] - Git working directory.
184
+ * @param {string} [options.env] - Shell runner environment override.
185
+ * @param {number} [options.chunkSize] - Chunk size in bytes.
186
+ * @param {import('./src/ports/CodecPort.js').default} [options.codec] - Manifest codec.
187
+ * @param {import('@git-stunts/alfred').Policy} [options.policy] - Resilience policy.
188
+ * @param {import('./src/ports/CryptoPort.js').default} [options.crypto] - Crypto adapter.
189
+ * @param {import('./src/ports/ObservabilityPort.js').default} [options.observability] - Observability adapter.
190
+ * @param {number} [options.merkleThreshold=1000] - Chunk count threshold for Merkle manifests.
191
+ * @param {number} [options.concurrency=1] - Maximum parallel chunk I/O operations.
192
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number }} [options.chunking] - Chunking strategy config.
193
+ * @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance.
194
+ * @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes.
195
+ * @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes.
196
+ * @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter.
197
+ * @returns {Promise<ContentAddressableStore>}
198
+ */
199
+ static async open({ cwd = '.', env, ...options } = {}) {
200
+ return new ContentAddressableStore({
201
+ ...options,
202
+ plumbing: await createGitPlumbing({ cwd, env }),
203
+ });
204
+ }
205
+
153
206
  /**
154
207
  * Factory to create a CAS with JSON codec.
155
208
  * @param {Object} options
156
209
  * @param {import('@git-stunts/plumbing').default} options.plumbing - GitPlumbing instance.
157
210
  * @param {number} [options.chunkSize] - Chunk size in bytes.
158
211
  * @param {import('@git-stunts/alfred').Policy} [options.policy] - Resilience policy.
212
+ * @param {import('./src/ports/CryptoPort.js').default} [options.crypto] - Crypto adapter.
213
+ * @param {import('./src/ports/ObservabilityPort.js').default} [options.observability] - Observability adapter.
214
+ * @param {number} [options.merkleThreshold=1000] - Chunk count threshold for Merkle manifests.
215
+ * @param {number} [options.concurrency=1] - Maximum parallel chunk I/O operations.
216
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number }} [options.chunking] - Chunking strategy config.
217
+ * @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance.
218
+ * @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes.
219
+ * @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes.
220
+ * @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter.
159
221
  * @returns {ContentAddressableStore}
160
222
  */
161
- static createJson({ plumbing, chunkSize, policy }) {
162
- return new ContentAddressableStore({ plumbing, chunkSize, codec: new JsonCodec(), policy });
223
+ static createJson({ plumbing, ...options }) {
224
+ return new ContentAddressableStore({ ...options, plumbing, codec: new JsonCodec() });
163
225
  }
164
226
 
165
227
  /**
@@ -168,10 +230,19 @@ export default class ContentAddressableStore {
168
230
  * @param {import('@git-stunts/plumbing').default} options.plumbing - GitPlumbing instance.
169
231
  * @param {number} [options.chunkSize] - Chunk size in bytes.
170
232
  * @param {import('@git-stunts/alfred').Policy} [options.policy] - Resilience policy.
233
+ * @param {import('./src/ports/CryptoPort.js').default} [options.crypto] - Crypto adapter.
234
+ * @param {import('./src/ports/ObservabilityPort.js').default} [options.observability] - Observability adapter.
235
+ * @param {number} [options.merkleThreshold=1000] - Chunk count threshold for Merkle manifests.
236
+ * @param {number} [options.concurrency=1] - Maximum parallel chunk I/O operations.
237
+ * @param {{ strategy: string, chunkSize?: number, targetChunkSize?: number, minChunkSize?: number, maxChunkSize?: number }} [options.chunking] - Chunking strategy config.
238
+ * @param {import('./src/ports/ChunkingPort.js').default} [options.chunker] - Pre-built ChunkingPort instance.
239
+ * @param {number} [options.maxRestoreBufferSize=536870912] - Max buffered restore size in bytes.
240
+ * @param {number} [options.maxBlobSize=10485760] - Safety limit for readBlob metadata in bytes.
241
+ * @param {import('./src/ports/CompressionPort.js').default} [options.compressionAdapter] - Compression adapter.
171
242
  * @returns {ContentAddressableStore}
172
243
  */
173
- static createCbor({ plumbing, chunkSize, policy }) {
174
- return new ContentAddressableStore({ plumbing, chunkSize, codec: new CborCodec(), policy });
244
+ static createCbor({ plumbing, ...options }) {
245
+ return new ContentAddressableStore({ ...options, plumbing, codec: new CborCodec() });
175
246
  }
176
247
 
177
248
  /**
@@ -183,11 +254,11 @@ export default class ContentAddressableStore {
183
254
  }
184
255
 
185
256
  /**
186
- * Encrypts a buffer using AES-256-GCM.
257
+ * Encrypts bytes using AES-256-GCM.
187
258
  * @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 } }>}
259
+ * @param {Uint8Array} options.buffer - Plaintext data to encrypt.
260
+ * @param {Uint8Array} options.key - 32-byte encryption key.
261
+ * @returns {Promise<{ buf: Uint8Array, meta: { algorithm: string, nonce: string, tag: string, encrypted: boolean } }>}
191
262
  */
192
263
  async encrypt(options) {
193
264
  const service = await this.#getService();
@@ -195,12 +266,12 @@ export default class ContentAddressableStore {
195
266
  }
196
267
 
197
268
  /**
198
- * Decrypts a buffer. Returns it unchanged if `meta.encrypted` is falsy.
269
+ * Decrypts bytes. Returns them unchanged if `meta.encrypted` is falsy.
199
270
  * @param {Object} options
200
- * @param {Buffer} options.buffer - Ciphertext to decrypt.
201
- * @param {Buffer} options.key - 32-byte encryption key.
271
+ * @param {Uint8Array} options.buffer - Ciphertext to decrypt.
272
+ * @param {Uint8Array} options.key - 32-byte encryption key.
202
273
  * @param {{ encrypted: boolean, algorithm: string, nonce: string, tag: string }} options.meta - Encryption metadata.
203
- * @returns {Promise<Buffer>}
274
+ * @returns {Promise<Uint8Array>}
204
275
  */
205
276
  async decrypt(options) {
206
277
  const service = await this.#getService();
@@ -213,12 +284,14 @@ export default class ContentAddressableStore {
213
284
  * @param {string} options.filePath - Absolute or relative path to the file.
214
285
  * @param {string} options.slug - Logical identifier for the stored asset.
215
286
  * @param {string} [options.filename] - Override filename (defaults to basename of filePath).
216
- * @param {Buffer} [options.encryptionKey] - 32-byte key for AES-256-GCM encryption.
287
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key for AES-256-GCM encryption.
217
288
  * @param {string} [options.passphrase] - Derive encryption key from passphrase.
289
+ * @param {{ scheme?: 'whole'|'framed'|'convergent', frameBytes?: number, convergent?: boolean }} [options.encryption] - Explicit encryption scheme selection.
218
290
  * @param {Object} [options.kdfOptions] - KDF options when using passphrase.
219
291
  * @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.
292
+ * @param {Array<{label: string, key: Uint8Array}>} [options.recipients] - Envelope recipients (mutually exclusive with encryptionKey/passphrase).
293
+ * @param {number} [options.merkleThreshold] - Per-operation chunk count threshold for Merkle tree publication.
294
+ * @returns {Promise<Manifest>} The resulting manifest.
222
295
  */
223
296
  async storeFile(options) {
224
297
  const service = await this.#getService();
@@ -228,15 +301,17 @@ export default class ContentAddressableStore {
228
301
  /**
229
302
  * Stores an async iterable source in Git as chunked blobs.
230
303
  * @param {Object} options
231
- * @param {AsyncIterable<Buffer>} options.source - Data to store.
304
+ * @param {AsyncIterable<Uint8Array>} options.source - Data to store.
232
305
  * @param {string} options.slug - Logical identifier for the stored asset.
233
306
  * @param {string} options.filename - Filename for the manifest.
234
- * @param {Buffer} [options.encryptionKey] - 32-byte key for AES-256-GCM encryption.
307
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key for AES-256-GCM encryption.
235
308
  * @param {string} [options.passphrase] - Derive encryption key from passphrase.
309
+ * @param {{ scheme?: 'whole'|'framed'|'convergent', frameBytes?: number, convergent?: boolean }} [options.encryption] - Explicit encryption scheme selection.
236
310
  * @param {Object} [options.kdfOptions] - KDF options when using passphrase.
237
311
  * @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.
312
+ * @param {Array<{label: string, key: Uint8Array}>} [options.recipients] - Envelope recipients (mutually exclusive with encryptionKey/passphrase).
313
+ * @param {number} [options.merkleThreshold] - Per-operation chunk count threshold for Merkle tree publication.
314
+ * @returns {Promise<Manifest>} The resulting manifest.
240
315
  */
241
316
  async store(options) {
242
317
  const service = await this.#getService();
@@ -246,24 +321,33 @@ export default class ContentAddressableStore {
246
321
  /**
247
322
  * Restores a file from its manifest and writes it to disk.
248
323
  * @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.
324
+ * @param {Manifest} options.manifest - The file manifest.
325
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key, required if manifest is encrypted.
251
326
  * @param {string} [options.passphrase] - Passphrase for KDF-based decryption.
252
327
  * @param {string} options.outputPath - Destination file path.
328
+ * @param {string} options.baseDirectory - Directory boundary that outputPath must stay inside.
253
329
  * @returns {Promise<{ bytesWritten: number }>}
254
330
  */
255
331
  async restoreFile(options) {
332
+ if (!options?.baseDirectory) {
333
+ throw createCasError({
334
+ message: 'baseDirectory is required for safe restoration. If you are restoring in a trusted local environment, pass baseDirectory: process.cwd().',
335
+ code: ErrorCodes.INVALID_OPTIONS,
336
+ meta: { option: 'baseDirectory' },
337
+ documentationUrl: RESTORE_FILE_DOCS_URL,
338
+ });
339
+ }
256
340
  const service = await this.#getService();
257
341
  return await restoreFile(service, options);
258
342
  }
259
343
 
260
344
  /**
261
- * Restores a file from its manifest, returning the buffer directly.
345
+ * Restores a file from its manifest, returning the bytes directly.
262
346
  * @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.
347
+ * @param {Manifest} options.manifest - The file manifest.
348
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key, required if manifest is encrypted.
265
349
  * @param {string} [options.passphrase] - Passphrase for KDF-based decryption.
266
- * @returns {Promise<{ buffer: Buffer, bytesWritten: number }>}
350
+ * @returns {Promise<{ buffer: Uint8Array, bytesWritten: number }>}
267
351
  */
268
352
  async restore(options) {
269
353
  const service = await this.#getService();
@@ -271,12 +355,12 @@ export default class ContentAddressableStore {
271
355
  }
272
356
 
273
357
  /**
274
- * Restores a file from its manifest as an async iterable of Buffer chunks.
358
+ * Restores a file from its manifest as an async iterable of byte chunks.
275
359
  * @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.
360
+ * @param {Manifest} options.manifest - The file manifest.
361
+ * @param {Uint8Array} [options.encryptionKey] - 32-byte key, required if manifest is encrypted.
278
362
  * @param {string} [options.passphrase] - Passphrase for KDF-based decryption.
279
- * @returns {AsyncIterable<Buffer>}
363
+ * @returns {AsyncIterable<Uint8Array>}
280
364
  */
281
365
  async *restoreStream(options) {
282
366
  const service = await this.#getService();
@@ -286,7 +370,8 @@ export default class ContentAddressableStore {
286
370
  /**
287
371
  * Creates a Git tree object from a manifest.
288
372
  * @param {Object} options
289
- * @param {import('./src/domain/value-objects/Manifest.js').default} options.manifest - The file manifest.
373
+ * @param {Manifest} options.manifest - The file manifest.
374
+ * @param {number} [options.merkleThreshold] - Override chunk count threshold for this tree publication.
290
375
  * @returns {Promise<string>} Git OID of the created tree.
291
376
  */
292
377
  async createTree(options) {
@@ -296,25 +381,37 @@ export default class ContentAddressableStore {
296
381
 
297
382
  /**
298
383
  * 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.
384
+ * @param {Manifest} manifest - The file manifest.
385
+ * @param {{ encryptionKey?: Uint8Array, passphrase?: string }} [options] - Optional decryption credentials for encrypted manifests.
300
386
  * @returns {Promise<boolean>} `true` if all chunks pass verification.
301
387
  */
302
- async verifyIntegrity(manifest) {
388
+ async verifyIntegrity(manifest, options) {
303
389
  const service = await this.#getService();
304
- return await service.verifyIntegrity(manifest);
390
+ return await service.verifyIntegrity(manifest, options);
305
391
  }
306
392
 
307
393
  /**
308
394
  * Reads a manifest from a Git tree OID.
309
395
  * @param {Object} options
310
396
  * @param {string} options.treeOid - Git tree OID to read the manifest from.
311
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>}
397
+ * @returns {Promise<Manifest>}
312
398
  */
313
399
  async readManifest(options) {
314
400
  const service = await this.#getService();
315
401
  return await service.readManifest(options);
316
402
  }
317
403
 
404
+ /**
405
+ * Compares two manifests by chunk digest.
406
+ * Pure function — no I/O needed. Does not require initialization.
407
+ * @param {Manifest} oldManifest
408
+ * @param {Manifest} newManifest
409
+ * @returns {import('./src/domain/services/ManifestDiff.js').ManifestDiffResult}
410
+ */
411
+ static diffManifests(oldManifest, newManifest) {
412
+ return CasService.diffManifests(oldManifest, newManifest);
413
+ }
414
+
318
415
  /**
319
416
  * Reads a manifest from a Git tree and returns inspection metadata.
320
417
  * @param {Object} options
@@ -363,14 +460,14 @@ export default class ContentAddressableStore {
363
460
  * Derives an encryption key from a passphrase using PBKDF2 or scrypt.
364
461
  * @param {Object} options
365
462
  * @param {string} options.passphrase - The passphrase.
366
- * @param {Buffer} [options.salt] - Salt (random if omitted).
463
+ * @param {Uint8Array} [options.salt] - Salt (random if omitted).
367
464
  * @param {'pbkdf2'|'scrypt'} [options.algorithm='pbkdf2'] - KDF algorithm.
368
465
  * @param {number} [options.iterations] - PBKDF2 iterations.
369
466
  * @param {number} [options.cost] - scrypt cost (N).
370
467
  * @param {number} [options.blockSize] - scrypt block size (r).
371
468
  * @param {number} [options.parallelization] - scrypt parallelization (p).
372
469
  * @param {number} [options.keyLength=32] - Derived key length.
373
- * @returns {Promise<{ key: Buffer, salt: Buffer, params: Object }>}
470
+ * @returns {Promise<{ key: Uint8Array, salt: Uint8Array, params: Object }>}
374
471
  */
375
472
  async deriveKey(options) {
376
473
  const service = await this.#getService();
@@ -384,11 +481,11 @@ export default class ContentAddressableStore {
384
481
  /**
385
482
  * Adds a recipient to an envelope-encrypted manifest.
386
483
  * @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.
484
+ * @param {Manifest} options.manifest
485
+ * @param {Uint8Array} options.existingKey - KEK of an existing recipient.
486
+ * @param {Uint8Array} options.newRecipientKey - KEK for the new recipient.
390
487
  * @param {string} options.label - Label for the new recipient.
391
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>}
488
+ * @returns {Promise<Manifest>}
392
489
  */
393
490
  async addRecipient(options) {
394
491
  const service = await this.#getService();
@@ -398,9 +495,9 @@ export default class ContentAddressableStore {
398
495
  /**
399
496
  * Removes a recipient from an envelope-encrypted manifest.
400
497
  * @param {Object} options
401
- * @param {import('./src/domain/value-objects/Manifest.js').default} options.manifest
498
+ * @param {Manifest} options.manifest
402
499
  * @param {string} options.label - Label to remove.
403
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>}
500
+ * @returns {Promise<Manifest>}
404
501
  */
405
502
  async removeRecipient(options) {
406
503
  const service = await this.#getService();
@@ -409,7 +506,7 @@ export default class ContentAddressableStore {
409
506
 
410
507
  /**
411
508
  * Lists recipient labels from an envelope-encrypted manifest.
412
- * @param {import('./src/domain/value-objects/Manifest.js').default} manifest
509
+ * @param {Manifest} manifest
413
510
  * @returns {Promise<string[]>}
414
511
  */
415
512
  async listRecipients(manifest) {
@@ -420,11 +517,11 @@ export default class ContentAddressableStore {
420
517
  /**
421
518
  * Rotates a recipient's key without re-encrypting data blobs.
422
519
  * @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.
520
+ * @param {Manifest} options.manifest
521
+ * @param {Uint8Array} options.oldKey - Current KEK of the recipient to rotate.
522
+ * @param {Uint8Array} options.newKey - New KEK to wrap the DEK with.
426
523
  * @param {string} [options.label] - If provided, only rotate the named recipient.
427
- * @returns {Promise<import('./src/domain/value-objects/Manifest.js').default>}
524
+ * @returns {Promise<Manifest>}
428
525
  */
429
526
  async rotateKey(options) {
430
527
  const service = await this.#getService();
@@ -450,9 +547,15 @@ export default class ContentAddressableStore {
450
547
  }
451
548
 
452
549
  /** @see VaultService#listVault */
453
- async listVault() {
550
+ async listVault(options) {
551
+ const vault = await this.#getVault();
552
+ return vault.listVault(options);
553
+ }
554
+
555
+ /** @see VaultService#iterateVault */
556
+ async *iterateVault(options) {
454
557
  const vault = await this.#getVault();
455
- return vault.listVault();
558
+ yield* vault.iterateVault(options);
456
559
  }
457
560
 
458
561
  /** @see VaultService#removeFromVault */
@@ -467,6 +570,12 @@ export default class ContentAddressableStore {
467
570
  return vault.resolveVaultEntry(options);
468
571
  }
469
572
 
573
+ /** @see VaultService#verifyVaultKey */
574
+ async verifyVaultKey(options) {
575
+ const vault = await this.#getVault();
576
+ return vault.verifyVaultKey(options);
577
+ }
578
+
470
579
  /** @see VaultService#getVaultMetadata */
471
580
  async getVaultMetadata() {
472
581
  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.0",
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"