@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.
- package/ADVANCED_GUIDE.md +1027 -0
- package/ARCHITECTURE.md +514 -0
- package/CHANGELOG.md +449 -5
- package/CODE_OF_CONDUCT.md +33 -0
- package/GUIDE.md +926 -0
- package/README.md +106 -366
- package/SECURITY.md +993 -0
- package/SUPPORT.md +54 -0
- package/UPGRADING.md +299 -0
- package/bin/actions.js +70 -21
- 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 +595 -449
- 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 +1255 -212
- 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 +367 -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 +2254 -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 +273 -80
- package/index.js +220 -59
- 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 +153 -53
- package/src/domain/services/CasService.js +322 -837
- package/src/domain/services/ChunkRepository.js +268 -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 +180 -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 +10 -6
- 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,56 +3,110 @@
|
|
|
3
3
|
* Domain service for Content Addressable Storage operations.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import Manifest
|
|
7
|
-
|
|
6
|
+
import Manifest, {
|
|
7
|
+
type EncryptionMeta,
|
|
8
|
+
type CompressionMeta,
|
|
9
|
+
type KdfParams,
|
|
10
|
+
type EncryptionScheme,
|
|
11
|
+
} from '../value-objects/Manifest.js';
|
|
12
|
+
import Chunk from '../value-objects/Chunk.js';
|
|
8
13
|
|
|
9
14
|
/** Port interface for cryptographic operations (hashing, encryption, random bytes). */
|
|
10
15
|
export interface CryptoPort {
|
|
11
|
-
sha256(buf:
|
|
12
|
-
randomBytes(n: number):
|
|
16
|
+
sha256(buf: Uint8Array): Promise<string>;
|
|
17
|
+
randomBytes(n: number): Uint8Array;
|
|
13
18
|
encryptBuffer(
|
|
14
|
-
buffer:
|
|
15
|
-
key:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
buffer: Uint8Array,
|
|
20
|
+
key: Uint8Array,
|
|
21
|
+
aad?: Uint8Array
|
|
22
|
+
): { buf: Uint8Array; meta: EncryptionMeta } | Promise<{ buf: Uint8Array; meta: EncryptionMeta }>;
|
|
23
|
+
decryptBuffer(
|
|
24
|
+
buffer: Uint8Array,
|
|
25
|
+
key: Uint8Array,
|
|
26
|
+
meta: EncryptionMeta,
|
|
27
|
+
aad?: Uint8Array
|
|
28
|
+
): Uint8Array | Promise<Uint8Array>;
|
|
29
|
+
createEncryptionStream(
|
|
30
|
+
key: Uint8Array,
|
|
31
|
+
aad?: Uint8Array
|
|
32
|
+
): {
|
|
33
|
+
encrypt: (source: AsyncIterable<Uint8Array>) => AsyncIterable<Uint8Array>;
|
|
20
34
|
finalize: () => EncryptionMeta;
|
|
21
35
|
};
|
|
36
|
+
createDecryptionStream(
|
|
37
|
+
key: Uint8Array,
|
|
38
|
+
meta: EncryptionMeta,
|
|
39
|
+
aad?: Uint8Array
|
|
40
|
+
): {
|
|
41
|
+
decrypt: (source: AsyncIterable<Uint8Array>) => AsyncIterable<Uint8Array>;
|
|
42
|
+
};
|
|
43
|
+
hmacSha256(key: Uint8Array, data: Uint8Array): Uint8Array | Promise<Uint8Array>;
|
|
44
|
+
encryptBufferWithNonce(
|
|
45
|
+
buffer: Uint8Array,
|
|
46
|
+
key: Uint8Array,
|
|
47
|
+
nonce: Uint8Array
|
|
48
|
+
): { buf: Uint8Array; tag: Uint8Array } | Promise<{ buf: Uint8Array; tag: Uint8Array }>;
|
|
49
|
+
decryptBufferWithNonceTag(
|
|
50
|
+
buffer: Uint8Array,
|
|
51
|
+
key: Uint8Array,
|
|
52
|
+
nonce: Uint8Array,
|
|
53
|
+
tag: Uint8Array
|
|
54
|
+
): Uint8Array | Promise<Uint8Array>;
|
|
22
55
|
deriveKey(options: DeriveKeyOptions): Promise<DeriveKeyResult>;
|
|
23
56
|
}
|
|
24
57
|
|
|
25
58
|
/** Port interface for encoding and decoding manifest data. */
|
|
26
59
|
export interface CodecPort {
|
|
27
|
-
encode(data: object):
|
|
28
|
-
decode(buffer:
|
|
60
|
+
encode(data: object): Uint8Array;
|
|
61
|
+
decode(buffer: Uint8Array): object;
|
|
29
62
|
get extension(): string;
|
|
30
63
|
}
|
|
31
64
|
|
|
32
65
|
/** Port interface for persisting data to Git's object database. */
|
|
33
66
|
export interface GitPersistencePort {
|
|
34
|
-
writeBlob(content:
|
|
67
|
+
writeBlob(content: Uint8Array): Promise<string>;
|
|
35
68
|
writeTree(entries: string[]): Promise<string>;
|
|
36
|
-
readBlob(oid: string): Promise<
|
|
69
|
+
readBlob(oid: string): Promise<Uint8Array>;
|
|
70
|
+
readBlobStream(oid: string): Promise<AsyncIterable<Uint8Array>>;
|
|
37
71
|
readTree(
|
|
38
|
-
treeOid: string
|
|
72
|
+
treeOid: string
|
|
39
73
|
): Promise<Array<{ mode: string; type: string; oid: string; name: string }>>;
|
|
74
|
+
readTreeEntry(
|
|
75
|
+
treeOid: string,
|
|
76
|
+
treePath: string
|
|
77
|
+
): Promise<{ mode: string; type: string; oid: string; name: string } | null>;
|
|
78
|
+
iterateTree(
|
|
79
|
+
treeOid: string
|
|
80
|
+
): AsyncIterable<{ mode: string; type: string; oid: string; name: string }>;
|
|
81
|
+
setMaxBlobSize?(maxBlobSize: number): void;
|
|
40
82
|
}
|
|
41
83
|
|
|
42
84
|
/** Port interface for observability (metrics, logging, tracing). */
|
|
43
85
|
export interface ObservabilityPort {
|
|
44
86
|
metric(channel: string, data: Record<string, unknown>): void;
|
|
45
|
-
log(
|
|
87
|
+
log(
|
|
88
|
+
level: 'debug' | 'info' | 'warn' | 'error',
|
|
89
|
+
msg: string,
|
|
90
|
+
meta?: Record<string, unknown>
|
|
91
|
+
): void;
|
|
46
92
|
span(name: string): { end(meta?: Record<string, unknown>): void };
|
|
47
93
|
}
|
|
48
94
|
|
|
49
95
|
/** Port interface for chunking strategies (fixed, CDC, etc.). */
|
|
50
96
|
export interface ChunkingPort {
|
|
51
|
-
chunk(source: AsyncIterable<
|
|
97
|
+
chunk(source: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
|
|
52
98
|
readonly strategy: string;
|
|
53
99
|
readonly params: Record<string, unknown>;
|
|
54
100
|
}
|
|
55
101
|
|
|
102
|
+
/** Port interface for compression and decompression of buffers and streams. */
|
|
103
|
+
export interface CompressionPort {
|
|
104
|
+
compressBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
105
|
+
decompressBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
106
|
+
compressStream(source: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
|
|
107
|
+
decompressStream(source: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
|
|
108
|
+
}
|
|
109
|
+
|
|
56
110
|
/** Constructor options for {@link CasService}. */
|
|
57
111
|
export interface CasServiceOptions {
|
|
58
112
|
persistence: GitPersistencePort;
|
|
@@ -62,15 +116,20 @@ export interface CasServiceOptions {
|
|
|
62
116
|
chunkSize?: number;
|
|
63
117
|
merkleThreshold?: number;
|
|
64
118
|
concurrency?: number;
|
|
65
|
-
chunker
|
|
119
|
+
chunker: ChunkingPort;
|
|
66
120
|
maxRestoreBufferSize?: number;
|
|
121
|
+
maxBlobSize?: number;
|
|
122
|
+
compressionAdapter: CompressionPort;
|
|
123
|
+
formatVersion?: string;
|
|
124
|
+
/** When true, allows reading manifests with legacy encryption schemes (v1/v2). */
|
|
125
|
+
legacyMode?: boolean;
|
|
67
126
|
}
|
|
68
127
|
|
|
69
128
|
/** Options for key derivation. */
|
|
70
129
|
export interface DeriveKeyOptions {
|
|
71
130
|
passphrase: string;
|
|
72
|
-
salt?:
|
|
73
|
-
algorithm?:
|
|
131
|
+
salt?: Uint8Array;
|
|
132
|
+
algorithm?: 'pbkdf2' | 'scrypt';
|
|
74
133
|
iterations?: number;
|
|
75
134
|
cost?: number;
|
|
76
135
|
blockSize?: number;
|
|
@@ -80,11 +139,29 @@ export interface DeriveKeyOptions {
|
|
|
80
139
|
|
|
81
140
|
/** Result from key derivation. */
|
|
82
141
|
export interface DeriveKeyResult {
|
|
83
|
-
key:
|
|
84
|
-
salt:
|
|
142
|
+
key: Uint8Array;
|
|
143
|
+
salt: Uint8Array;
|
|
85
144
|
params: KdfParams;
|
|
86
145
|
}
|
|
87
146
|
|
|
147
|
+
export interface VerifyIntegrityOptions {
|
|
148
|
+
encryptionKey?: Uint8Array;
|
|
149
|
+
passphrase?: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface StoreEncryptionOptions {
|
|
153
|
+
scheme?: EncryptionScheme;
|
|
154
|
+
frameBytes?: number;
|
|
155
|
+
/** Explicit convergent opt-in/opt-out; defaults on for CDC chunkers. */
|
|
156
|
+
convergent?: boolean;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface FileRestorePlan {
|
|
160
|
+
mode: 'stream' | 'bounded-file';
|
|
161
|
+
source: AsyncIterable<Uint8Array>;
|
|
162
|
+
encryptionMeta?: EncryptionMeta;
|
|
163
|
+
}
|
|
164
|
+
|
|
88
165
|
/**
|
|
89
166
|
* Domain service for Content Addressable Storage operations.
|
|
90
167
|
*
|
|
@@ -100,55 +177,64 @@ export default class CasService {
|
|
|
100
177
|
readonly merkleThreshold: number;
|
|
101
178
|
readonly concurrency: number;
|
|
102
179
|
readonly maxRestoreBufferSize: number;
|
|
180
|
+
readonly maxBlobSize: number;
|
|
103
181
|
|
|
104
182
|
constructor(options: CasServiceOptions);
|
|
105
183
|
|
|
106
184
|
encrypt(options: {
|
|
107
|
-
buffer:
|
|
108
|
-
key:
|
|
109
|
-
}): Promise<{ buf:
|
|
185
|
+
buffer: Uint8Array;
|
|
186
|
+
key: Uint8Array;
|
|
187
|
+
}): Promise<{ buf: Uint8Array; meta: EncryptionMeta }>;
|
|
110
188
|
|
|
111
189
|
decrypt(options: {
|
|
112
|
-
buffer:
|
|
113
|
-
key:
|
|
190
|
+
buffer: Uint8Array;
|
|
191
|
+
key: Uint8Array;
|
|
114
192
|
meta: EncryptionMeta;
|
|
115
|
-
}): Promise<
|
|
193
|
+
}): Promise<Uint8Array>;
|
|
116
194
|
|
|
117
195
|
store(options: {
|
|
118
|
-
source: AsyncIterable<
|
|
196
|
+
source: AsyncIterable<Uint8Array>;
|
|
119
197
|
slug: string;
|
|
120
198
|
filename: string;
|
|
121
|
-
encryptionKey?:
|
|
199
|
+
encryptionKey?: Uint8Array;
|
|
122
200
|
passphrase?: string;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
201
|
+
encryption?: StoreEncryptionOptions;
|
|
202
|
+
kdfOptions?: Omit<DeriveKeyOptions, 'passphrase'>;
|
|
203
|
+
compression?: { algorithm: 'gzip' };
|
|
204
|
+
recipients?: Array<{ label: string; key: Uint8Array }>;
|
|
205
|
+
merkleThreshold?: number;
|
|
206
|
+
chunker?: ChunkingPort;
|
|
126
207
|
}): Promise<Manifest>;
|
|
127
208
|
|
|
128
|
-
createTree(options: { manifest: Manifest }): Promise<string>;
|
|
209
|
+
createTree(options: { manifest: Manifest; merkleThreshold?: number }): Promise<string>;
|
|
129
210
|
|
|
130
211
|
restore(options: {
|
|
131
212
|
manifest: Manifest;
|
|
132
|
-
encryptionKey?:
|
|
213
|
+
encryptionKey?: Uint8Array;
|
|
133
214
|
passphrase?: string;
|
|
134
|
-
}): Promise<{ buffer:
|
|
215
|
+
}): Promise<{ buffer: Uint8Array; bytesWritten: number }>;
|
|
135
216
|
|
|
136
217
|
restoreStream(options: {
|
|
137
218
|
manifest: Manifest;
|
|
138
|
-
encryptionKey?:
|
|
219
|
+
encryptionKey?: Uint8Array;
|
|
139
220
|
passphrase?: string;
|
|
140
|
-
}): AsyncIterable<
|
|
221
|
+
}): AsyncIterable<Uint8Array>;
|
|
222
|
+
|
|
223
|
+
createFileRestorePlan(options: {
|
|
224
|
+
manifest: Manifest;
|
|
225
|
+
encryptionKey?: Uint8Array;
|
|
226
|
+
passphrase?: string;
|
|
227
|
+
}): Promise<FileRestorePlan>;
|
|
141
228
|
|
|
142
229
|
readManifest(options: { treeOid: string }): Promise<Manifest>;
|
|
143
230
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
231
|
+
/** Reads a raw manifest without scheme assertion or Manifest construction. */
|
|
232
|
+
readManifestRaw(options: { treeOid: string }): Promise<Record<string, unknown>>;
|
|
233
|
+
|
|
234
|
+
inspectAsset(options: { treeOid: string }): Promise<{ slug: string; chunksOrphaned: number }>;
|
|
147
235
|
|
|
148
236
|
/** @deprecated Use {@link inspectAsset} instead. */
|
|
149
|
-
deleteAsset(options: {
|
|
150
|
-
treeOid: string;
|
|
151
|
-
}): Promise<{ slug: string; chunksOrphaned: number }>;
|
|
237
|
+
deleteAsset(options: { treeOid: string }): Promise<{ slug: string; chunksOrphaned: number }>;
|
|
152
238
|
|
|
153
239
|
collectReferencedChunks(options: {
|
|
154
240
|
treeOids: string[];
|
|
@@ -161,26 +247,40 @@ export default class CasService {
|
|
|
161
247
|
|
|
162
248
|
addRecipient(options: {
|
|
163
249
|
manifest: Manifest;
|
|
164
|
-
existingKey:
|
|
165
|
-
newRecipientKey:
|
|
250
|
+
existingKey: Uint8Array;
|
|
251
|
+
newRecipientKey: Uint8Array;
|
|
166
252
|
label: string;
|
|
167
253
|
}): Promise<Manifest>;
|
|
168
254
|
|
|
169
|
-
removeRecipient(options: {
|
|
170
|
-
manifest: Manifest;
|
|
171
|
-
label: string;
|
|
172
|
-
}): Promise<Manifest>;
|
|
255
|
+
removeRecipient(options: { manifest: Manifest; label: string }): Promise<Manifest>;
|
|
173
256
|
|
|
174
257
|
listRecipients(manifest: Manifest): string[];
|
|
175
258
|
|
|
176
259
|
rotateKey(options: {
|
|
177
260
|
manifest: Manifest;
|
|
178
|
-
oldKey:
|
|
179
|
-
newKey:
|
|
261
|
+
oldKey: Uint8Array;
|
|
262
|
+
newKey: Uint8Array;
|
|
180
263
|
label?: string;
|
|
181
264
|
}): Promise<Manifest>;
|
|
182
265
|
|
|
183
|
-
verifyIntegrity(manifest: Manifest): Promise<boolean>;
|
|
266
|
+
verifyIntegrity(manifest: Manifest, options?: VerifyIntegrityOptions): Promise<boolean>;
|
|
184
267
|
|
|
185
268
|
deriveKey(options: DeriveKeyOptions): Promise<DeriveKeyResult>;
|
|
269
|
+
|
|
270
|
+
static diffManifests(oldManifest: Manifest, newManifest: Manifest): ManifestDiffResult;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Result of comparing two manifests by chunk digest. */
|
|
274
|
+
export interface ManifestDiffResult {
|
|
275
|
+
added: Chunk[];
|
|
276
|
+
removed: Chunk[];
|
|
277
|
+
unchanged: Chunk[];
|
|
278
|
+
summary: {
|
|
279
|
+
addedCount: number;
|
|
280
|
+
removedCount: number;
|
|
281
|
+
unchangedCount: number;
|
|
282
|
+
addedBytes: number;
|
|
283
|
+
removedBytes: number;
|
|
284
|
+
unchangedBytes: number;
|
|
285
|
+
};
|
|
186
286
|
}
|