@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
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class InvalidOptionsError extends CasError {
|
|
5
|
+
static code = ErrorCodes.INVALID_OPTIONS;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, InvalidOptionsError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class ManifestIntegrityError extends CasError {
|
|
5
|
+
static code = ErrorCodes.MANIFEST_INTEGRITY_ERROR;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, ManifestIntegrityError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class ManifestNotFoundError extends CasError {
|
|
5
|
+
static code = ErrorCodes.MANIFEST_NOT_FOUND;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, ManifestNotFoundError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class NoMatchingRecipientError extends CasError {
|
|
5
|
+
static code = ErrorCodes.NO_MATCHING_RECIPIENT;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, NoMatchingRecipientError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class PersistenceCapabilityRequiredError extends CasError {
|
|
5
|
+
static code = ErrorCodes.PERSISTENCE_CAPABILITY_REQUIRED;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, PersistenceCapabilityRequiredError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class PortNotImplementedError extends CasError {
|
|
5
|
+
static code = ErrorCodes.PORT_NOT_IMPLEMENTED;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, PortNotImplementedError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class RecipientAlreadyExistsError extends CasError {
|
|
5
|
+
static code = ErrorCodes.RECIPIENT_ALREADY_EXISTS;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, RecipientAlreadyExistsError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class RecipientNotFoundError extends CasError {
|
|
5
|
+
static code = ErrorCodes.RECIPIENT_NOT_FOUND;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, RecipientNotFoundError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class RestoreTooLargeError extends CasError {
|
|
5
|
+
static code = ErrorCodes.RESTORE_TOO_LARGE;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, RestoreTooLargeError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import { ErrorCodes } from './Codes.js';
|
|
3
|
+
|
|
4
|
+
export default class RotationNotSupportedError extends CasError {
|
|
5
|
+
static code = ErrorCodes.ROTATION_NOT_SUPPORTED;
|
|
6
|
+
|
|
7
|
+
constructor(message, meta = {}) {
|
|
8
|
+
super(message, RotationNotSupportedError.code, meta);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import CasError from './CasError.js';
|
|
2
|
+
import CannotRemoveLastRecipientError from './CannotRemoveLastRecipientError.js';
|
|
3
|
+
import DekUnwrapFailedError from './DekUnwrapFailedError.js';
|
|
4
|
+
import GitError from './GitError.js';
|
|
5
|
+
import IntegrityError from './IntegrityError.js';
|
|
6
|
+
import InvalidChunkingStrategyError from './InvalidChunkingStrategyError.js';
|
|
7
|
+
import InvalidOidError from './InvalidOidError.js';
|
|
8
|
+
import InvalidOptionsError from './InvalidOptionsError.js';
|
|
9
|
+
import ManifestIntegrityError from './ManifestIntegrityError.js';
|
|
10
|
+
import ManifestNotFoundError from './ManifestNotFoundError.js';
|
|
11
|
+
import NoMatchingRecipientError from './NoMatchingRecipientError.js';
|
|
12
|
+
import PersistenceCapabilityRequiredError from './PersistenceCapabilityRequiredError.js';
|
|
13
|
+
import PortNotImplementedError from './PortNotImplementedError.js';
|
|
14
|
+
import RecipientAlreadyExistsError from './RecipientAlreadyExistsError.js';
|
|
15
|
+
import RecipientNotFoundError from './RecipientNotFoundError.js';
|
|
16
|
+
import RestoreTooLargeError from './RestoreTooLargeError.js';
|
|
17
|
+
import RotationNotSupportedError from './RotationNotSupportedError.js';
|
|
18
|
+
import GitPlumbingInitializationError from './GitPlumbingInitializationError.js';
|
|
19
|
+
|
|
20
|
+
const ERROR_BY_CODE = Object.freeze({
|
|
21
|
+
[CannotRemoveLastRecipientError.code]: CannotRemoveLastRecipientError,
|
|
22
|
+
[DekUnwrapFailedError.code]: DekUnwrapFailedError,
|
|
23
|
+
[GitError.code]: GitError,
|
|
24
|
+
[GitPlumbingInitializationError.code]: GitPlumbingInitializationError,
|
|
25
|
+
[IntegrityError.code]: IntegrityError,
|
|
26
|
+
[InvalidChunkingStrategyError.code]: InvalidChunkingStrategyError,
|
|
27
|
+
[InvalidOidError.code]: InvalidOidError,
|
|
28
|
+
[InvalidOptionsError.code]: InvalidOptionsError,
|
|
29
|
+
[ManifestIntegrityError.code]: ManifestIntegrityError,
|
|
30
|
+
[ManifestNotFoundError.code]: ManifestNotFoundError,
|
|
31
|
+
[NoMatchingRecipientError.code]: NoMatchingRecipientError,
|
|
32
|
+
[PersistenceCapabilityRequiredError.code]: PersistenceCapabilityRequiredError,
|
|
33
|
+
[PortNotImplementedError.code]: PortNotImplementedError,
|
|
34
|
+
[RecipientAlreadyExistsError.code]: RecipientAlreadyExistsError,
|
|
35
|
+
[RecipientNotFoundError.code]: RecipientNotFoundError,
|
|
36
|
+
[RestoreTooLargeError.code]: RestoreTooLargeError,
|
|
37
|
+
[RotationNotSupportedError.code]: RotationNotSupportedError,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export default function createCasError(messageOrOptions, code, meta = {}) {
|
|
41
|
+
const normalized = normalizeCreateCasErrorArgs(messageOrOptions, code, meta);
|
|
42
|
+
const ErrorClass = ERROR_BY_CODE[normalized.code];
|
|
43
|
+
const error = ErrorClass
|
|
44
|
+
? new ErrorClass(normalized.message, normalized.meta)
|
|
45
|
+
: new CasError(normalized);
|
|
46
|
+
if (normalized.documentationUrl) {
|
|
47
|
+
error.documentationUrl = normalized.documentationUrl;
|
|
48
|
+
}
|
|
49
|
+
return error;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {string|{ message: string, code: string, meta?: Object, documentationUrl?: string }} messageOrOptions
|
|
54
|
+
* @param {string|undefined} code
|
|
55
|
+
* @param {Object} meta
|
|
56
|
+
* @returns {{ message: string, code: string, meta: Object, documentationUrl?: string }}
|
|
57
|
+
*/
|
|
58
|
+
function normalizeCreateCasErrorArgs(messageOrOptions, code, meta) {
|
|
59
|
+
if (typeof messageOrOptions === 'object' && messageOrOptions !== null) {
|
|
60
|
+
return {
|
|
61
|
+
message: messageOrOptions.message,
|
|
62
|
+
code: messageOrOptions.code,
|
|
63
|
+
meta: messageOrOptions.meta ?? {},
|
|
64
|
+
documentationUrl: messageOrOptions.documentationUrl,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return { message: messageOrOptions, code, meta };
|
|
68
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { ErrorCodes } from './Codes.js';
|
|
2
|
+
export { default as CasError } from './CasError.js';
|
|
3
|
+
export { default as CannotRemoveLastRecipientError } from './CannotRemoveLastRecipientError.js';
|
|
4
|
+
export { default as DekUnwrapFailedError } from './DekUnwrapFailedError.js';
|
|
5
|
+
export { default as GitError } from './GitError.js';
|
|
6
|
+
export { default as GitPlumbingInitializationError } from './GitPlumbingInitializationError.js';
|
|
7
|
+
export { default as IntegrityError } from './IntegrityError.js';
|
|
8
|
+
export { default as InvalidChunkingStrategyError } from './InvalidChunkingStrategyError.js';
|
|
9
|
+
export { default as InvalidOidError } from './InvalidOidError.js';
|
|
10
|
+
export { default as InvalidOptionsError } from './InvalidOptionsError.js';
|
|
11
|
+
export { default as ManifestIntegrityError } from './ManifestIntegrityError.js';
|
|
12
|
+
export { default as ManifestNotFoundError } from './ManifestNotFoundError.js';
|
|
13
|
+
export { default as NoMatchingRecipientError } from './NoMatchingRecipientError.js';
|
|
14
|
+
export { default as PersistenceCapabilityRequiredError } from './PersistenceCapabilityRequiredError.js';
|
|
15
|
+
export { default as PortNotImplementedError } from './PortNotImplementedError.js';
|
|
16
|
+
export { default as RecipientAlreadyExistsError } from './RecipientAlreadyExistsError.js';
|
|
17
|
+
export { default as RecipientNotFoundError } from './RecipientNotFoundError.js';
|
|
18
|
+
export { default as RestoreTooLargeError } from './RestoreTooLargeError.js';
|
|
19
|
+
export { default as RotationNotSupportedError } from './RotationNotSupportedError.js';
|
|
20
|
+
export { default as createCasError } from './createCasError.js';
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { encodeBase64 } from '../encoding/base64.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Builds the KDF metadata object for vault/manifest encryption metadata.
|
|
3
5
|
*
|
|
4
|
-
* @param {
|
|
6
|
+
* @param {Uint8Array} salt - KDF salt.
|
|
5
7
|
* @param {{ algorithm: string, keyLength: number, iterations?: number, cost?: number, blockSize?: number, parallelization?: number }} params - KDF parameters.
|
|
6
8
|
* @returns {{ algorithm: string, salt: string, keyLength: number, iterations?: number, cost?: number, blockSize?: number, parallelization?: number }}
|
|
7
9
|
*/
|
|
8
10
|
export default function buildKdfMetadata(salt, params) {
|
|
9
11
|
return {
|
|
10
12
|
algorithm: params.algorithm,
|
|
11
|
-
salt: salt
|
|
13
|
+
salt: encodeBase64(salt),
|
|
12
14
|
...('iterations' in params && { iterations: params.iterations }),
|
|
13
15
|
...('cost' in params && { cost: params.cost }),
|
|
14
16
|
...('blockSize' in params && { blockSize: params.blockSize }),
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import createCasError from '../errors/createCasError.js';
|
|
2
|
+
import { utf8Encode } from '../encoding/utf8.js';
|
|
3
|
+
import { ErrorCodes } from '../errors/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {unknown} value
|
|
7
|
+
* @returns {Uint8Array}
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeCodecBytes(value) {
|
|
10
|
+
if (value instanceof Uint8Array) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
return utf8Encode(value);
|
|
15
|
+
}
|
|
16
|
+
throw createCasError('Codec output must be Uint8Array', ErrorCodes.INVALID_OPTIONS);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Strips `manifestHash` and `undefined` values, then returns codec-encoded bytes.
|
|
21
|
+
* @param {Record<string, unknown>} data
|
|
22
|
+
* @param {{ encode: (value: object) => Uint8Array|string }} codec
|
|
23
|
+
* @returns {Uint8Array}
|
|
24
|
+
*/
|
|
25
|
+
export function encodeForHash(data, codec) {
|
|
26
|
+
const copy = { ...data };
|
|
27
|
+
delete copy.manifestHash;
|
|
28
|
+
for (const key of Object.keys(copy)) {
|
|
29
|
+
if (copy[key] === undefined) {
|
|
30
|
+
delete copy[key];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return normalizeCodecBytes(codec.encode(copy));
|
|
34
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const GIT_REV_PARSE = 'rev-parse';
|
|
2
|
+
const GIT_REF_NOT_FOUND_STATUS = 128;
|
|
3
|
+
|
|
4
|
+
const MISSING_REF_MARKERS = Object.freeze({
|
|
5
|
+
ambiguousArgument: 'ambiguous argument',
|
|
6
|
+
neededSingleRevision: 'needed a single revision',
|
|
7
|
+
unknownRevision: 'unknown revision',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {unknown} err
|
|
12
|
+
* @param {string} ref
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
*/
|
|
15
|
+
export function isGitMissingRefError(err, ref) {
|
|
16
|
+
return isStdoutOnlyRevParseMiss(errorDetails(err), ref) ||
|
|
17
|
+
isGitMissingRefMessage(errorDetailsText(err), ref);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {unknown} err
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
export function errorDetailsText(err) {
|
|
25
|
+
if (!(err instanceof Error)) {
|
|
26
|
+
return String(err);
|
|
27
|
+
}
|
|
28
|
+
const details = errorDetails(err);
|
|
29
|
+
return [
|
|
30
|
+
err.message,
|
|
31
|
+
typeof details.stderr === 'string' ? details.stderr : '',
|
|
32
|
+
typeof details.stdout === 'string' ? details.stdout : '',
|
|
33
|
+
].join('\n');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {unknown} err
|
|
38
|
+
* @returns {Record<string, unknown>}
|
|
39
|
+
*/
|
|
40
|
+
function errorDetails(err) {
|
|
41
|
+
return err instanceof Error && typeof err.details === 'object' && err.details
|
|
42
|
+
? err.details
|
|
43
|
+
: {};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {Record<string, unknown>} details
|
|
48
|
+
* @param {string} ref
|
|
49
|
+
* @returns {boolean}
|
|
50
|
+
*/
|
|
51
|
+
function isStdoutOnlyRevParseMiss(details, ref) {
|
|
52
|
+
// Some plumbing runners surface a stdout-only `rev-parse <ref>` miss: Git
|
|
53
|
+
// exits 128 and echoes the unresolved ref without emitting locale text.
|
|
54
|
+
return details.code === GIT_REF_NOT_FOUND_STATUS &&
|
|
55
|
+
Array.isArray(details.args) &&
|
|
56
|
+
details.args[0] === GIT_REV_PARSE &&
|
|
57
|
+
details.args.at(-1) === ref &&
|
|
58
|
+
typeof details.stdout === 'string' &&
|
|
59
|
+
details.stdout.trim() === ref &&
|
|
60
|
+
`${details.stderr ?? ''}`.trim() === '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} message
|
|
65
|
+
* @param {string} ref
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
*/
|
|
68
|
+
function isGitMissingRefMessage(message, ref) {
|
|
69
|
+
const normalized = message.toLowerCase();
|
|
70
|
+
const normalizedRef = ref.toLowerCase();
|
|
71
|
+
if (!normalized.includes(normalizedRef)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
// C/English-locale missing-ref fallback: normal adapters should return
|
|
75
|
+
// GIT_REF_NOT_FOUND. This best-effort fallback is only for third-party ports
|
|
76
|
+
// that expose Git stderr without a structured code.
|
|
77
|
+
return (
|
|
78
|
+
normalized.includes(MISSING_REF_MARKERS.neededSingleRevision) ||
|
|
79
|
+
(
|
|
80
|
+
normalized.includes(MISSING_REF_MARKERS.ambiguousArgument) &&
|
|
81
|
+
normalized.includes(MISSING_REF_MARKERS.unknownRevision)
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute a conservative `maxmem` budget for Node-compatible scrypt calls.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the runtime formula currently required by the Node, Bun, and Web
|
|
5
|
+
* Crypto fallback derive paths.
|
|
6
|
+
*
|
|
7
|
+
* @param {{
|
|
8
|
+
* cost: number,
|
|
9
|
+
* blockSize: number,
|
|
10
|
+
* parallelization: number,
|
|
11
|
+
* keyLength: number,
|
|
12
|
+
* }} options
|
|
13
|
+
* @returns {number}
|
|
14
|
+
*/
|
|
15
|
+
export default function scryptMaxmem({ cost, blockSize, parallelization, keyLength }) {
|
|
16
|
+
return (
|
|
17
|
+
(128 * cost * blockSize) +
|
|
18
|
+
(256 * blockSize * parallelization) +
|
|
19
|
+
keyLength +
|
|
20
|
+
(1024 * 1024)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import RestoreOutcome from './RestoreOutcome.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Immutable failed restore result.
|
|
5
|
+
*/
|
|
6
|
+
export default class RestoreFailure extends RestoreOutcome {
|
|
7
|
+
/**
|
|
8
|
+
* @param {{ error: Error }} options
|
|
9
|
+
*/
|
|
10
|
+
constructor({ error }) {
|
|
11
|
+
super({ ok: false });
|
|
12
|
+
this.error = error;
|
|
13
|
+
Object.freeze(this);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { concatBytes } from '../bytes/ByteLayout.js';
|
|
2
|
+
import RestoreOutcome from './RestoreOutcome.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Immutable successful restore result.
|
|
6
|
+
*/
|
|
7
|
+
export default class RestoreSuccess extends RestoreOutcome {
|
|
8
|
+
#buffer;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {{ buffer: Uint8Array }} options
|
|
12
|
+
*/
|
|
13
|
+
constructor({ buffer }) {
|
|
14
|
+
super({ ok: true });
|
|
15
|
+
this.#buffer = new Uint8Array(buffer);
|
|
16
|
+
this.bytesWritten = this.#buffer.length;
|
|
17
|
+
Object.freeze(this);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @returns {Uint8Array}
|
|
22
|
+
*/
|
|
23
|
+
get buffer() {
|
|
24
|
+
return new Uint8Array(this.#buffer);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {Uint8Array[]} chunks
|
|
29
|
+
* @returns {RestoreSuccess}
|
|
30
|
+
*/
|
|
31
|
+
static fromChunks(chunks) {
|
|
32
|
+
return new RestoreSuccess({ buffer: concatBytes(chunks) });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import StoreOutcome from './StoreOutcome.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Immutable failed store result.
|
|
5
|
+
*/
|
|
6
|
+
export default class StoreFailure extends StoreOutcome {
|
|
7
|
+
/**
|
|
8
|
+
* @param {{ error: Error }} options
|
|
9
|
+
*/
|
|
10
|
+
constructor({ error }) {
|
|
11
|
+
super({ ok: false });
|
|
12
|
+
this.error = error;
|
|
13
|
+
Object.freeze(this);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import StoreOutcome from './StoreOutcome.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Immutable successful store result.
|
|
5
|
+
*
|
|
6
|
+
* @typedef {import('../value-objects/Manifest.js').default} Manifest
|
|
7
|
+
*/
|
|
8
|
+
export default class StoreSuccess extends StoreOutcome {
|
|
9
|
+
/**
|
|
10
|
+
* @param {{ manifest: Manifest }} options
|
|
11
|
+
*/
|
|
12
|
+
constructor({ manifest }) {
|
|
13
|
+
super({ ok: true });
|
|
14
|
+
this.manifest = manifest;
|
|
15
|
+
Object.freeze(this);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -35,15 +35,43 @@ export declare const RecipientSchema: z.ZodObject<{
|
|
|
35
35
|
}>;
|
|
36
36
|
|
|
37
37
|
/** Validates the encryption metadata attached to an encrypted manifest. */
|
|
38
|
-
export declare const EncryptionSchema: z.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
export declare const EncryptionSchema: z.ZodUnion<
|
|
39
|
+
[
|
|
40
|
+
z.ZodObject<{
|
|
41
|
+
scheme: z.ZodLiteral<"whole">;
|
|
42
|
+
algorithm: z.ZodLiteral<"aes-256-gcm">;
|
|
43
|
+
encrypted: z.ZodDefault<z.ZodLiteral<true>>;
|
|
44
|
+
kdf: z.ZodOptional<typeof KdfSchema>;
|
|
45
|
+
recipients: z.ZodOptional<z.ZodArray<typeof RecipientSchema>>;
|
|
46
|
+
keyVersion: z.ZodOptional<z.ZodNumber>;
|
|
47
|
+
nonce: z.ZodString;
|
|
48
|
+
tag: z.ZodString;
|
|
49
|
+
frameBytes: z.ZodOptional<z.ZodUndefined>;
|
|
50
|
+
}>,
|
|
51
|
+
z.ZodObject<{
|
|
52
|
+
scheme: z.ZodLiteral<"framed">;
|
|
53
|
+
algorithm: z.ZodLiteral<"aes-256-gcm">;
|
|
54
|
+
encrypted: z.ZodDefault<z.ZodLiteral<true>>;
|
|
55
|
+
kdf: z.ZodOptional<typeof KdfSchema>;
|
|
56
|
+
recipients: z.ZodOptional<z.ZodArray<typeof RecipientSchema>>;
|
|
57
|
+
keyVersion: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
frameBytes: z.ZodNumber;
|
|
59
|
+
nonce: z.ZodOptional<z.ZodUndefined>;
|
|
60
|
+
tag: z.ZodOptional<z.ZodUndefined>;
|
|
61
|
+
}>,
|
|
62
|
+
z.ZodObject<{
|
|
63
|
+
scheme: z.ZodLiteral<"convergent">;
|
|
64
|
+
algorithm: z.ZodLiteral<"aes-256-gcm">;
|
|
65
|
+
encrypted: z.ZodDefault<z.ZodLiteral<true>>;
|
|
66
|
+
kdf: z.ZodOptional<typeof KdfSchema>;
|
|
67
|
+
recipients: z.ZodOptional<z.ZodArray<typeof RecipientSchema>>;
|
|
68
|
+
keyVersion: z.ZodOptional<z.ZodNumber>;
|
|
69
|
+
nonce: z.ZodOptional<z.ZodUndefined>;
|
|
70
|
+
tag: z.ZodOptional<z.ZodUndefined>;
|
|
71
|
+
frameBytes: z.ZodOptional<z.ZodUndefined>;
|
|
72
|
+
}>
|
|
73
|
+
]
|
|
74
|
+
>;
|
|
47
75
|
|
|
48
76
|
/** Validates compression metadata. */
|
|
49
77
|
export declare const CompressionSchema: z.ZodObject<{
|
|
@@ -65,6 +93,7 @@ export declare const CdcChunkingSchema: z.ZodObject<{
|
|
|
65
93
|
target: z.ZodNumber;
|
|
66
94
|
min: z.ZodNumber;
|
|
67
95
|
max: z.ZodNumber;
|
|
96
|
+
normalized: z.ZodOptional<z.ZodBoolean>;
|
|
68
97
|
}>;
|
|
69
98
|
}>;
|
|
70
99
|
|
|
@@ -84,6 +113,8 @@ export declare const SubManifestRefSchema: z.ZodObject<{
|
|
|
84
113
|
/** Validates a complete file manifest. */
|
|
85
114
|
export declare const ManifestSchema: z.ZodObject<{
|
|
86
115
|
version: z.ZodDefault<z.ZodNumber>;
|
|
116
|
+
formatVersion: z.ZodOptional<z.ZodString>;
|
|
117
|
+
manifestHash: z.ZodOptional<z.ZodString>;
|
|
87
118
|
slug: z.ZodString;
|
|
88
119
|
filename: z.ZodString;
|
|
89
120
|
size: z.ZodNumber;
|