@git-stunts/git-cas 5.3.1 → 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.
- package/ADVANCED_GUIDE.md +1006 -0
- package/ARCHITECTURE.md +514 -0
- package/CHANGELOG.md +401 -4
- package/CODE_OF_CONDUCT.md +33 -0
- package/GUIDE.md +872 -0
- package/README.md +219 -325
- package/SECURITY.md +993 -0
- package/SUPPORT.md +54 -0
- package/UPGRADING.md +299 -0
- package/bin/actions.js +72 -20
- package/bin/agent/cli.js +51 -0
- package/bin/agent/commands/doctor.js +99 -0
- package/bin/agent/commands/index.js +1489 -0
- package/bin/agent/input.js +619 -0
- package/bin/agent/passphrase-source.js +123 -0
- package/bin/agent/protocol.js +193 -0
- package/bin/build-version.js +64 -0
- package/bin/credentials.js +425 -0
- package/bin/git-cas.js +604 -450
- package/bin/io.js +86 -0
- package/bin/passphrase-source.js +266 -0
- package/bin/restore-output-target.js +28 -0
- package/bin/ui/blocks/asset-card.js +109 -0
- package/bin/ui/blocks/health-dashboard.js +149 -0
- package/bin/ui/blocks/heatmap-block.js +67 -0
- package/bin/ui/blocks/merkle-explorer.js +163 -0
- package/bin/ui/blocks/operation-feed.js +176 -0
- package/bin/ui/blocks/wizard-block.js +168 -0
- package/bin/ui/components/short-sha.js +36 -0
- package/bin/ui/context.js +56 -1
- package/bin/ui/dashboard-cmds.js +1578 -13
- package/bin/ui/dashboard-view.js +612 -145
- package/bin/ui/dashboard.js +998 -214
- package/bin/ui/encryption-card.js +69 -26
- package/bin/ui/heatmap.js +26 -54
- package/bin/ui/history-timeline.js +51 -19
- package/bin/ui/manifest-view.js +115 -60
- package/bin/ui/merkle-dag.js +83 -0
- package/bin/ui/progress.js +15 -9
- package/bin/ui/repo-treemap.js +328 -0
- package/bin/ui/shaders/bak-sneppen.js +180 -0
- package/bin/ui/shaders/fractal-zoom.js +99 -0
- package/bin/ui/shaders/merkle-tree.js +142 -0
- package/bin/ui/shaders/organic-flow.js +96 -0
- package/bin/ui/shaders/phase-portrait.js +93 -0
- package/bin/ui/store-wizard.js +296 -0
- package/bin/ui/theme.js +155 -0
- package/bin/ui/vault-report.js +495 -0
- package/build-info.json +4 -0
- package/docs/API.md +2224 -0
- package/docs/ENCRYPTION_MODES.md +33 -0
- package/docs/EXTENDING.md +174 -0
- package/docs/STORE_RESTORE_PIPELINE.md +199 -0
- package/docs/THREAT_MODEL.md +269 -0
- package/docs/VAULT_INTERNALS.md +251 -0
- package/docs/WALKTHROUGH.md +1868 -0
- package/docs/demo.gif +0 -0
- package/docs/releases/v6.0.0.md +104 -0
- package/examples/README.md +260 -0
- package/index.d.ts +208 -65
- package/index.js +163 -54
- package/package.json +35 -6
- package/scripts/migrate-encryption.js +680 -0
- package/src/domain/bytes/ByteLayout.js +96 -0
- package/src/domain/encoding/base64.js +91 -0
- package/src/domain/encoding/hex.js +14 -0
- package/src/domain/encoding/utf8.js +123 -0
- package/src/domain/encryption/schemes.js +132 -0
- package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
- package/src/domain/errors/CasError.d.ts +28 -0
- package/src/domain/errors/CasError.js +43 -6
- package/src/domain/errors/Codes.js +54 -0
- package/src/domain/errors/DekUnwrapFailedError.js +10 -0
- package/src/domain/errors/GitError.js +10 -0
- package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
- package/src/domain/errors/IntegrityError.js +10 -0
- package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
- package/src/domain/errors/InvalidOidError.js +10 -0
- package/src/domain/errors/InvalidOptionsError.js +10 -0
- package/src/domain/errors/ManifestIntegrityError.js +10 -0
- package/src/domain/errors/ManifestNotFoundError.js +10 -0
- package/src/domain/errors/NoMatchingRecipientError.js +10 -0
- package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
- package/src/domain/errors/PortNotImplementedError.js +10 -0
- package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
- package/src/domain/errors/RecipientNotFoundError.js +10 -0
- package/src/domain/errors/RestoreTooLargeError.js +10 -0
- package/src/domain/errors/RotationNotSupportedError.js +10 -0
- package/src/domain/errors/createCasError.js +68 -0
- package/src/domain/errors/index.js +20 -0
- package/src/domain/helpers/buildKdfMetadata.js +4 -2
- package/src/domain/helpers/codecBytes.js +34 -0
- package/src/domain/helpers/gitRefErrors.js +84 -0
- package/src/domain/helpers/scryptMaxmem.js +22 -0
- package/src/domain/outcomes/RestoreFailure.js +15 -0
- package/src/domain/outcomes/RestoreOutcome.js +11 -0
- package/src/domain/outcomes/RestoreSuccess.js +34 -0
- package/src/domain/outcomes/StoreFailure.js +15 -0
- package/src/domain/outcomes/StoreOutcome.js +11 -0
- package/src/domain/outcomes/StoreSuccess.js +17 -0
- package/src/domain/schemas/ManifestSchema.d.ts +40 -9
- package/src/domain/schemas/ManifestSchema.js +67 -13
- package/src/domain/services/CasService.d.ts +123 -38
- package/src/domain/services/CasService.js +298 -834
- package/src/domain/services/ChunkRepository.js +230 -0
- package/src/domain/services/CompressionStreams.js +72 -0
- package/src/domain/services/ConvergentEncryption.js +128 -0
- package/src/domain/services/GitTreeBuilder.js +86 -0
- package/src/domain/services/IntegrityVerifier.js +199 -0
- package/src/domain/services/KeyResolver.js +49 -42
- package/src/domain/services/ManifestDiff.js +56 -0
- package/src/domain/services/ManifestRepository.js +286 -0
- package/src/domain/services/PrefetchWindow.js +48 -0
- package/src/domain/services/RecipientService.js +157 -0
- package/src/domain/services/RedactingObservability.js +169 -0
- package/src/domain/services/RestorePipeline.js +68 -0
- package/src/domain/services/StorePipeline.js +201 -0
- package/src/domain/services/VaultKeyVerifier.js +101 -0
- package/src/domain/services/VaultMetadataCodec.js +206 -0
- package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
- package/src/domain/services/VaultPersistence.js +410 -0
- package/src/domain/services/VaultPrivacyIndex.js +191 -0
- package/src/domain/services/VaultService.js +749 -251
- package/src/domain/services/VaultStateCache.js +225 -0
- package/src/domain/services/VaultTreeCodec.js +121 -0
- package/src/domain/services/rotateVaultPassphrase.js +37 -20
- package/src/domain/strategies/Aad.js +39 -0
- package/src/domain/strategies/FramedRecordCodec.js +204 -0
- package/src/domain/strategies/RestoreCompressed.js +40 -0
- package/src/domain/strategies/RestoreConvergent.js +44 -0
- package/src/domain/strategies/RestoreFramed.js +55 -0
- package/src/domain/strategies/RestorePlain.js +37 -0
- package/src/domain/strategies/RestoreStrategy.js +35 -0
- package/src/domain/strategies/RestoreWhole.js +135 -0
- package/src/domain/strategies/StoreConvergent.js +28 -0
- package/src/domain/strategies/StoreFramed.js +39 -0
- package/src/domain/strategies/StorePlain.js +20 -0
- package/src/domain/strategies/StoreStrategy.js +61 -0
- package/src/domain/strategies/StoreWhole.js +34 -0
- package/src/domain/value-objects/Chunk.js +1 -2
- package/src/domain/value-objects/EncryptionMetadata.js +87 -0
- package/src/domain/value-objects/Manifest.d.ts +40 -4
- package/src/domain/value-objects/Manifest.js +61 -20
- package/src/domain/value-objects/Oid.js +45 -0
- package/src/domain/value-objects/Slug.js +124 -0
- package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
- package/src/helpers/aesGcmMeta.js +55 -0
- package/src/helpers/canonicalBase64.js +1 -0
- package/src/helpers/kdfPolicy.js +194 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
- package/src/infrastructure/adapters/FileIOHelper.js +178 -13
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
- package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
- package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
- package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
- package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
- package/src/infrastructure/chunkers/CdcChunker.js +53 -19
- package/src/infrastructure/chunkers/FixedChunker.js +15 -7
- package/src/infrastructure/chunkers/resolveChunker.js +3 -1
- package/src/infrastructure/codecs/CborCodec.js +3 -3
- package/src/infrastructure/codecs/JsonCodec.js +5 -5
- package/src/infrastructure/createGitPlumbing.js +22 -0
- package/src/package-version.js +1 -0
- package/src/ports/ChunkingPort.js +3 -3
- package/src/ports/CodecPort.js +4 -4
- package/src/ports/CompressionPort.js +57 -0
- package/src/ports/CryptoPort.js +138 -50
- package/src/ports/GitPersistencePort.js +32 -2
- package/src/ports/GitPlumbingFactoryPort.js +16 -0
- package/src/ports/GitRefPort.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/test/CONVENTIONS.md +94 -0
- package/test/cycles/README.md +13 -0
|
@@ -4,19 +4,42 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import z from 'zod';
|
|
7
|
+
import { isCanonicalBase64 } from '../../helpers/canonicalBase64.js';
|
|
8
|
+
import { base64DecodedLength } from '../encoding/base64.js';
|
|
9
|
+
|
|
10
|
+
function base64BytesSchema(field, byteLength) {
|
|
11
|
+
return z.string()
|
|
12
|
+
.min(1)
|
|
13
|
+
.refine((value) => isCanonicalBase64(value), {
|
|
14
|
+
message: `${field} must be canonical base64`,
|
|
15
|
+
})
|
|
16
|
+
.refine((value) => isCanonicalBase64(value) && base64DecodedLength(value) === byteLength, {
|
|
17
|
+
message: `${field} must decode to ${byteLength} bytes`,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Matches a lowercase hex Git OID — SHA-1 (40 chars) or SHA-256 (64 chars). */
|
|
22
|
+
const gitOidSchema = z.string().regex(
|
|
23
|
+
/^[0-9a-f]{40}([0-9a-f]{24})?$/,
|
|
24
|
+
'must be a 40- or 64-character lowercase hex Git OID',
|
|
25
|
+
);
|
|
7
26
|
|
|
8
27
|
/** Validates a single chunk entry within a manifest. */
|
|
9
28
|
export const ChunkSchema = z.object({
|
|
10
29
|
index: z.number().int().min(0),
|
|
11
30
|
size: z.number().int().positive(),
|
|
12
|
-
digest: z.string().
|
|
13
|
-
blob:
|
|
31
|
+
digest: z.string().regex(/^[0-9a-f]{64}$/, 'digest must be a 64-character lowercase hex string'),
|
|
32
|
+
blob: gitOidSchema,
|
|
14
33
|
});
|
|
15
34
|
|
|
16
35
|
/** Validates KDF parameters stored alongside encryption metadata. */
|
|
17
36
|
export const KdfSchema = z.object({
|
|
18
37
|
algorithm: z.enum(['pbkdf2', 'scrypt']),
|
|
19
|
-
salt: z.string()
|
|
38
|
+
salt: z.string()
|
|
39
|
+
.min(1)
|
|
40
|
+
.refine((value) => isCanonicalBase64(value), {
|
|
41
|
+
message: 'salt must be canonical base64',
|
|
42
|
+
}),
|
|
20
43
|
iterations: z.number().int().positive().optional(),
|
|
21
44
|
cost: z.number().int().positive().optional(),
|
|
22
45
|
blockSize: z.number().int().positive().optional(),
|
|
@@ -27,24 +50,52 @@ export const KdfSchema = z.object({
|
|
|
27
50
|
/** Validates a single recipient entry in an envelope-encrypted manifest. */
|
|
28
51
|
export const RecipientSchema = z.object({
|
|
29
52
|
label: z.string().min(1),
|
|
30
|
-
wrappedDek:
|
|
31
|
-
nonce:
|
|
32
|
-
tag:
|
|
53
|
+
wrappedDek: base64BytesSchema('wrappedDek', 32),
|
|
54
|
+
nonce: base64BytesSchema('nonce', 12),
|
|
55
|
+
tag: base64BytesSchema('tag', 16),
|
|
33
56
|
kekType: z.string().optional(),
|
|
34
57
|
keyVersion: z.number().int().min(0).optional(),
|
|
35
58
|
});
|
|
36
59
|
|
|
37
60
|
/** Validates the encryption metadata attached to an encrypted manifest. */
|
|
38
|
-
|
|
39
|
-
algorithm: z.
|
|
40
|
-
|
|
41
|
-
tag: z.string(),
|
|
42
|
-
encrypted: z.boolean().default(true),
|
|
61
|
+
const EncryptionBaseSchema = {
|
|
62
|
+
algorithm: z.literal('aes-256-gcm'),
|
|
63
|
+
encrypted: z.literal(true).default(true),
|
|
43
64
|
kdf: KdfSchema.optional(),
|
|
44
65
|
recipients: z.array(RecipientSchema).min(1).optional(),
|
|
45
66
|
keyVersion: z.number().int().min(0).optional(),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const WholeEncryptionSchema = z.object({
|
|
70
|
+
scheme: z.literal('whole'),
|
|
71
|
+
...EncryptionBaseSchema,
|
|
72
|
+
nonce: base64BytesSchema('nonce', 12),
|
|
73
|
+
tag: base64BytesSchema('tag', 16),
|
|
74
|
+
frameBytes: z.undefined().optional(),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const FramedEncryptionSchema = z.object({
|
|
78
|
+
scheme: z.literal('framed'),
|
|
79
|
+
...EncryptionBaseSchema,
|
|
80
|
+
frameBytes: z.number().int().positive(),
|
|
81
|
+
nonce: z.undefined().optional(),
|
|
82
|
+
tag: z.undefined().optional(),
|
|
46
83
|
});
|
|
47
84
|
|
|
85
|
+
const ConvergentEncryptionSchema = z.object({
|
|
86
|
+
scheme: z.literal('convergent'),
|
|
87
|
+
...EncryptionBaseSchema,
|
|
88
|
+
nonce: z.undefined().optional(),
|
|
89
|
+
tag: z.undefined().optional(),
|
|
90
|
+
frameBytes: z.undefined().optional(),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export const EncryptionSchema = z.union([
|
|
94
|
+
WholeEncryptionSchema,
|
|
95
|
+
FramedEncryptionSchema,
|
|
96
|
+
ConvergentEncryptionSchema,
|
|
97
|
+
]);
|
|
98
|
+
|
|
48
99
|
/** Validates compression metadata. */
|
|
49
100
|
export const CompressionSchema = z.object({
|
|
50
101
|
algorithm: z.enum(['gzip']),
|
|
@@ -65,6 +116,7 @@ export const CdcChunkingSchema = z.object({
|
|
|
65
116
|
target: z.number().int().positive(),
|
|
66
117
|
min: z.number().int().positive(),
|
|
67
118
|
max: z.number().int().positive(),
|
|
119
|
+
normalized: z.boolean().optional(),
|
|
68
120
|
}),
|
|
69
121
|
});
|
|
70
122
|
|
|
@@ -76,7 +128,7 @@ export const ChunkingSchema = z.discriminatedUnion('strategy', [
|
|
|
76
128
|
|
|
77
129
|
/** Validates a sub-manifest reference in a v2 Merkle manifest. */
|
|
78
130
|
export const SubManifestRefSchema = z.object({
|
|
79
|
-
oid:
|
|
131
|
+
oid: gitOidSchema,
|
|
80
132
|
chunkCount: z.number().int().positive(),
|
|
81
133
|
startIndex: z.number().int().min(0),
|
|
82
134
|
});
|
|
@@ -84,6 +136,8 @@ export const SubManifestRefSchema = z.object({
|
|
|
84
136
|
/** Validates a complete file manifest. */
|
|
85
137
|
export const ManifestSchema = z.object({
|
|
86
138
|
version: z.number().int().min(1).max(2).default(1),
|
|
139
|
+
formatVersion: z.string().regex(/^\d+\.\d+\.\d+$/).optional(),
|
|
140
|
+
manifestHash: z.string().regex(/^[0-9a-f]{64}$/, 'manifestHash must be a 64-char hex string').optional(),
|
|
87
141
|
slug: z.string().min(1),
|
|
88
142
|
filename: z.string().min(1),
|
|
89
143
|
size: z.number().int().min(0),
|
|
@@ -91,5 +145,5 @@ export const ManifestSchema = z.object({
|
|
|
91
145
|
encryption: EncryptionSchema.optional(),
|
|
92
146
|
compression: CompressionSchema.optional(),
|
|
93
147
|
chunking: ChunkingSchema.optional(),
|
|
94
|
-
subManifests: z.array(SubManifestRefSchema).optional(),
|
|
148
|
+
subManifests: z.array(SubManifestRefSchema).max(10_000).optional(),
|
|
95
149
|
});
|
|
@@ -3,40 +3,65 @@
|
|
|
3
3
|
* Domain service for Content Addressable Storage operations.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import Manifest from "../value-objects/Manifest.js";
|
|
7
|
-
import
|
|
6
|
+
import Manifest, { type EncryptionMeta, type CompressionMeta, type KdfParams, type EncryptionScheme } from "../value-objects/Manifest.js";
|
|
7
|
+
import Chunk from "../value-objects/Chunk.js";
|
|
8
8
|
|
|
9
9
|
/** Port interface for cryptographic operations (hashing, encryption, random bytes). */
|
|
10
10
|
export interface CryptoPort {
|
|
11
|
-
sha256(buf:
|
|
12
|
-
randomBytes(n: number):
|
|
11
|
+
sha256(buf: Uint8Array): Promise<string>;
|
|
12
|
+
randomBytes(n: number): Uint8Array;
|
|
13
13
|
encryptBuffer(
|
|
14
|
-
buffer:
|
|
15
|
-
key:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
buffer: Uint8Array,
|
|
15
|
+
key: Uint8Array,
|
|
16
|
+
aad?: Uint8Array,
|
|
17
|
+
): { buf: Uint8Array; meta: EncryptionMeta } | Promise<{ buf: Uint8Array; meta: EncryptionMeta }>;
|
|
18
|
+
decryptBuffer(buffer: Uint8Array, key: Uint8Array, meta: EncryptionMeta, aad?: Uint8Array): Uint8Array | Promise<Uint8Array>;
|
|
19
|
+
createEncryptionStream(key: Uint8Array, aad?: Uint8Array): {
|
|
20
|
+
encrypt: (source: AsyncIterable<Uint8Array>) => AsyncIterable<Uint8Array>;
|
|
20
21
|
finalize: () => EncryptionMeta;
|
|
21
22
|
};
|
|
23
|
+
createDecryptionStream(key: Uint8Array, meta: EncryptionMeta, aad?: Uint8Array): {
|
|
24
|
+
decrypt: (source: AsyncIterable<Uint8Array>) => AsyncIterable<Uint8Array>;
|
|
25
|
+
};
|
|
26
|
+
hmacSha256(key: Uint8Array, data: Uint8Array): Uint8Array | Promise<Uint8Array>;
|
|
27
|
+
encryptBufferWithNonce(
|
|
28
|
+
buffer: Uint8Array,
|
|
29
|
+
key: Uint8Array,
|
|
30
|
+
nonce: Uint8Array,
|
|
31
|
+
): { buf: Uint8Array; tag: Uint8Array } | Promise<{ buf: Uint8Array; tag: Uint8Array }>;
|
|
32
|
+
decryptBufferWithNonceTag(
|
|
33
|
+
buffer: Uint8Array,
|
|
34
|
+
key: Uint8Array,
|
|
35
|
+
nonce: Uint8Array,
|
|
36
|
+
tag: Uint8Array,
|
|
37
|
+
): Uint8Array | Promise<Uint8Array>;
|
|
22
38
|
deriveKey(options: DeriveKeyOptions): Promise<DeriveKeyResult>;
|
|
23
39
|
}
|
|
24
40
|
|
|
25
41
|
/** Port interface for encoding and decoding manifest data. */
|
|
26
42
|
export interface CodecPort {
|
|
27
|
-
encode(data: object):
|
|
28
|
-
decode(buffer:
|
|
43
|
+
encode(data: object): Uint8Array;
|
|
44
|
+
decode(buffer: Uint8Array): object;
|
|
29
45
|
get extension(): string;
|
|
30
46
|
}
|
|
31
47
|
|
|
32
48
|
/** Port interface for persisting data to Git's object database. */
|
|
33
49
|
export interface GitPersistencePort {
|
|
34
|
-
writeBlob(content:
|
|
50
|
+
writeBlob(content: Uint8Array): Promise<string>;
|
|
35
51
|
writeTree(entries: string[]): Promise<string>;
|
|
36
|
-
readBlob(oid: string): Promise<
|
|
52
|
+
readBlob(oid: string): Promise<Uint8Array>;
|
|
53
|
+
readBlobStream(oid: string): Promise<AsyncIterable<Uint8Array>>;
|
|
37
54
|
readTree(
|
|
38
55
|
treeOid: string,
|
|
39
56
|
): Promise<Array<{ mode: string; type: string; oid: string; name: string }>>;
|
|
57
|
+
readTreeEntry(
|
|
58
|
+
treeOid: string,
|
|
59
|
+
treePath: string,
|
|
60
|
+
): Promise<{ mode: string; type: string; oid: string; name: string } | null>;
|
|
61
|
+
iterateTree(
|
|
62
|
+
treeOid: string,
|
|
63
|
+
): AsyncIterable<{ mode: string; type: string; oid: string; name: string }>;
|
|
64
|
+
setMaxBlobSize?(maxBlobSize: number): void;
|
|
40
65
|
}
|
|
41
66
|
|
|
42
67
|
/** Port interface for observability (metrics, logging, tracing). */
|
|
@@ -48,11 +73,19 @@ export interface ObservabilityPort {
|
|
|
48
73
|
|
|
49
74
|
/** Port interface for chunking strategies (fixed, CDC, etc.). */
|
|
50
75
|
export interface ChunkingPort {
|
|
51
|
-
chunk(source: AsyncIterable<
|
|
76
|
+
chunk(source: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
|
|
52
77
|
readonly strategy: string;
|
|
53
78
|
readonly params: Record<string, unknown>;
|
|
54
79
|
}
|
|
55
80
|
|
|
81
|
+
/** Port interface for compression and decompression of buffers and streams. */
|
|
82
|
+
export interface CompressionPort {
|
|
83
|
+
compressBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
84
|
+
decompressBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
85
|
+
compressStream(source: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
|
|
86
|
+
decompressStream(source: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
|
|
87
|
+
}
|
|
88
|
+
|
|
56
89
|
/** Constructor options for {@link CasService}. */
|
|
57
90
|
export interface CasServiceOptions {
|
|
58
91
|
persistence: GitPersistencePort;
|
|
@@ -62,14 +95,19 @@ export interface CasServiceOptions {
|
|
|
62
95
|
chunkSize?: number;
|
|
63
96
|
merkleThreshold?: number;
|
|
64
97
|
concurrency?: number;
|
|
65
|
-
chunker
|
|
98
|
+
chunker: ChunkingPort;
|
|
66
99
|
maxRestoreBufferSize?: number;
|
|
100
|
+
maxBlobSize?: number;
|
|
101
|
+
compressionAdapter: CompressionPort;
|
|
102
|
+
formatVersion?: string;
|
|
103
|
+
/** When true, allows reading manifests with legacy encryption schemes (v1/v2). */
|
|
104
|
+
legacyMode?: boolean;
|
|
67
105
|
}
|
|
68
106
|
|
|
69
107
|
/** Options for key derivation. */
|
|
70
108
|
export interface DeriveKeyOptions {
|
|
71
109
|
passphrase: string;
|
|
72
|
-
salt?:
|
|
110
|
+
salt?: Uint8Array;
|
|
73
111
|
algorithm?: "pbkdf2" | "scrypt";
|
|
74
112
|
iterations?: number;
|
|
75
113
|
cost?: number;
|
|
@@ -80,11 +118,29 @@ export interface DeriveKeyOptions {
|
|
|
80
118
|
|
|
81
119
|
/** Result from key derivation. */
|
|
82
120
|
export interface DeriveKeyResult {
|
|
83
|
-
key:
|
|
84
|
-
salt:
|
|
121
|
+
key: Uint8Array;
|
|
122
|
+
salt: Uint8Array;
|
|
85
123
|
params: KdfParams;
|
|
86
124
|
}
|
|
87
125
|
|
|
126
|
+
export interface VerifyIntegrityOptions {
|
|
127
|
+
encryptionKey?: Uint8Array;
|
|
128
|
+
passphrase?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface StoreEncryptionOptions {
|
|
132
|
+
scheme?: EncryptionScheme;
|
|
133
|
+
frameBytes?: number;
|
|
134
|
+
/** Explicit convergent opt-in/opt-out; defaults on for CDC chunkers. */
|
|
135
|
+
convergent?: boolean;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface FileRestorePlan {
|
|
139
|
+
mode: "stream" | "bounded-file";
|
|
140
|
+
source: AsyncIterable<Uint8Array>;
|
|
141
|
+
encryptionMeta?: EncryptionMeta;
|
|
142
|
+
}
|
|
143
|
+
|
|
88
144
|
/**
|
|
89
145
|
* Domain service for Content Addressable Storage operations.
|
|
90
146
|
*
|
|
@@ -100,47 +156,59 @@ export default class CasService {
|
|
|
100
156
|
readonly merkleThreshold: number;
|
|
101
157
|
readonly concurrency: number;
|
|
102
158
|
readonly maxRestoreBufferSize: number;
|
|
159
|
+
readonly maxBlobSize: number;
|
|
103
160
|
|
|
104
161
|
constructor(options: CasServiceOptions);
|
|
105
162
|
|
|
106
163
|
encrypt(options: {
|
|
107
|
-
buffer:
|
|
108
|
-
key:
|
|
109
|
-
}): Promise<{ buf:
|
|
164
|
+
buffer: Uint8Array;
|
|
165
|
+
key: Uint8Array;
|
|
166
|
+
}): Promise<{ buf: Uint8Array; meta: EncryptionMeta }>;
|
|
110
167
|
|
|
111
168
|
decrypt(options: {
|
|
112
|
-
buffer:
|
|
113
|
-
key:
|
|
169
|
+
buffer: Uint8Array;
|
|
170
|
+
key: Uint8Array;
|
|
114
171
|
meta: EncryptionMeta;
|
|
115
|
-
}): Promise<
|
|
172
|
+
}): Promise<Uint8Array>;
|
|
116
173
|
|
|
117
174
|
store(options: {
|
|
118
|
-
source: AsyncIterable<
|
|
175
|
+
source: AsyncIterable<Uint8Array>;
|
|
119
176
|
slug: string;
|
|
120
177
|
filename: string;
|
|
121
|
-
encryptionKey?:
|
|
178
|
+
encryptionKey?: Uint8Array;
|
|
122
179
|
passphrase?: string;
|
|
180
|
+
encryption?: StoreEncryptionOptions;
|
|
123
181
|
kdfOptions?: Omit<DeriveKeyOptions, "passphrase">;
|
|
124
182
|
compression?: { algorithm: "gzip" };
|
|
125
|
-
recipients?: Array<{ label: string; key:
|
|
183
|
+
recipients?: Array<{ label: string; key: Uint8Array }>;
|
|
184
|
+
merkleThreshold?: number;
|
|
126
185
|
}): Promise<Manifest>;
|
|
127
186
|
|
|
128
|
-
createTree(options: { manifest: Manifest }): Promise<string>;
|
|
187
|
+
createTree(options: { manifest: Manifest; merkleThreshold?: number }): Promise<string>;
|
|
129
188
|
|
|
130
189
|
restore(options: {
|
|
131
190
|
manifest: Manifest;
|
|
132
|
-
encryptionKey?:
|
|
191
|
+
encryptionKey?: Uint8Array;
|
|
133
192
|
passphrase?: string;
|
|
134
|
-
}): Promise<{ buffer:
|
|
193
|
+
}): Promise<{ buffer: Uint8Array; bytesWritten: number }>;
|
|
135
194
|
|
|
136
195
|
restoreStream(options: {
|
|
137
196
|
manifest: Manifest;
|
|
138
|
-
encryptionKey?:
|
|
197
|
+
encryptionKey?: Uint8Array;
|
|
139
198
|
passphrase?: string;
|
|
140
|
-
}): AsyncIterable<
|
|
199
|
+
}): AsyncIterable<Uint8Array>;
|
|
200
|
+
|
|
201
|
+
createFileRestorePlan(options: {
|
|
202
|
+
manifest: Manifest;
|
|
203
|
+
encryptionKey?: Uint8Array;
|
|
204
|
+
passphrase?: string;
|
|
205
|
+
}): Promise<FileRestorePlan>;
|
|
141
206
|
|
|
142
207
|
readManifest(options: { treeOid: string }): Promise<Manifest>;
|
|
143
208
|
|
|
209
|
+
/** Reads a raw manifest without scheme assertion or Manifest construction. */
|
|
210
|
+
readManifestRaw(options: { treeOid: string }): Promise<Record<string, unknown>>;
|
|
211
|
+
|
|
144
212
|
inspectAsset(options: {
|
|
145
213
|
treeOid: string;
|
|
146
214
|
}): Promise<{ slug: string; chunksOrphaned: number }>;
|
|
@@ -161,8 +229,8 @@ export default class CasService {
|
|
|
161
229
|
|
|
162
230
|
addRecipient(options: {
|
|
163
231
|
manifest: Manifest;
|
|
164
|
-
existingKey:
|
|
165
|
-
newRecipientKey:
|
|
232
|
+
existingKey: Uint8Array;
|
|
233
|
+
newRecipientKey: Uint8Array;
|
|
166
234
|
label: string;
|
|
167
235
|
}): Promise<Manifest>;
|
|
168
236
|
|
|
@@ -175,12 +243,29 @@ export default class CasService {
|
|
|
175
243
|
|
|
176
244
|
rotateKey(options: {
|
|
177
245
|
manifest: Manifest;
|
|
178
|
-
oldKey:
|
|
179
|
-
newKey:
|
|
246
|
+
oldKey: Uint8Array;
|
|
247
|
+
newKey: Uint8Array;
|
|
180
248
|
label?: string;
|
|
181
249
|
}): Promise<Manifest>;
|
|
182
250
|
|
|
183
|
-
verifyIntegrity(manifest: Manifest): Promise<boolean>;
|
|
251
|
+
verifyIntegrity(manifest: Manifest, options?: VerifyIntegrityOptions): Promise<boolean>;
|
|
184
252
|
|
|
185
253
|
deriveKey(options: DeriveKeyOptions): Promise<DeriveKeyResult>;
|
|
254
|
+
|
|
255
|
+
static diffManifests(oldManifest: Manifest, newManifest: Manifest): ManifestDiffResult;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Result of comparing two manifests by chunk digest. */
|
|
259
|
+
export interface ManifestDiffResult {
|
|
260
|
+
added: Chunk[];
|
|
261
|
+
removed: Chunk[];
|
|
262
|
+
unchanged: Chunk[];
|
|
263
|
+
summary: {
|
|
264
|
+
addedCount: number;
|
|
265
|
+
removedCount: number;
|
|
266
|
+
unchangedCount: number;
|
|
267
|
+
addedBytes: number;
|
|
268
|
+
removedBytes: number;
|
|
269
|
+
unchangedBytes: number;
|
|
270
|
+
};
|
|
186
271
|
}
|