@tearleads/client-sdk 0.1.41 → 0.1.43
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/client/Tearleads.js +3 -0
- package/client/Tearleads.js.map +1 -1
- package/data/blobs/transferPool.js +35 -8
- package/data/blobs/transferPool.js.map +1 -1
- package/data/containers/shared/projection.js +12 -0
- package/data/containers/shared/projection.js.map +1 -1
- package/data/documents/blob/shared/types.d.ts +2 -3
- package/data/documents/blob/shared/types.js.map +1 -1
- package/data/documents/shared/events.js +0 -1
- package/data/documents/shared/events.js.map +1 -1
- package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js +2 -0
- package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js.map +1 -1
- package/data/keyingProjectionVerification/checkpointContext.d.ts +12 -0
- package/data/keyingProjectionVerification/checkpointContext.js +16 -0
- package/data/keyingProjectionVerification/checkpointContext.js.map +1 -1
- package/data/keyingProjectionVerification/containerDestinationVerification.js +3 -1
- package/data/keyingProjectionVerification/containerDestinationVerification.js.map +1 -1
- package/data/keyingProjectionVerification/containerProjectionVerification.js +12 -6
- package/data/keyingProjectionVerification/containerProjectionVerification.js.map +1 -1
- package/data/keyingProjectionVerification/documentProjectionVerification.js +10 -4
- package/data/keyingProjectionVerification/documentProjectionVerification.js.map +1 -1
- package/data/persistence/container-contents/containerContentsPersistence.js +6 -22
- package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js +5 -15
- package/data/persistence/container-contents/containerMetadataMutationPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerPendingUpdatePersistence.js +6 -15
- package/data/persistence/container-contents/containerPendingUpdatePersistence.js.map +1 -1
- package/data/persistence/container-contents/containerRecoveryPersistence.js +3 -4
- package/data/persistence/container-contents/containerRecoveryPersistence.js.map +1 -1
- package/data/persistence/container-contents/containerRemovalWork.js +3 -5
- package/data/persistence/container-contents/containerRemovalWork.js.map +1 -1
- package/data/persistence/container-contents/dormantContainerMetadata.js +1 -5
- package/data/persistence/container-contents/dormantContainerMetadata.js.map +1 -1
- package/data/persistence/documents/documentsPersistence.js +4 -9
- package/data/persistence/documents/documentsPersistence.js.map +1 -1
- package/data/persistence/documents/internal/discardDocument.js +1 -2
- package/data/persistence/documents/internal/discardDocument.js.map +1 -1
- package/data/persistence/documents/internal/documentDeletionPersistence.js +1 -2
- package/data/persistence/documents/internal/documentDeletionPersistence.js.map +1 -1
- package/data/persistence/documents/internal/documentMutationPersistence.js +17 -25
- package/data/persistence/documents/internal/documentMutationPersistence.js.map +1 -1
- package/data/persistence/documents/internal/orphanSideRows.js +2 -14
- package/data/persistence/documents/internal/orphanSideRows.js.map +1 -1
- package/data/persistence/documents/internal/syncQueuePersistence.js +3 -3
- package/data/persistence/documents/internal/syncQueuePersistence.js.map +1 -1
- package/data/persistence/keyingCheckpointAdvancePersistence.js +27 -8
- package/data/persistence/keyingCheckpointAdvancePersistence.js.map +1 -1
- package/data/persistence/verifiedManifestBundlePersistence.d.ts +45 -0
- package/data/persistence/verifiedManifestBundlePersistence.js +282 -0
- package/data/persistence/verifiedManifestBundlePersistence.js.map +1 -0
- package/data/sqlite/documentHistoryPersistence.d.ts +9 -3
- package/data/sqlite/documentHistoryPersistence.js +31 -8
- package/data/sqlite/documentHistoryPersistence.js.map +1 -1
- package/data/sqlite/documentPendingUpdatePersistence.d.ts +58 -11
- package/data/sqlite/documentPendingUpdatePersistence.js +137 -63
- package/data/sqlite/documentPendingUpdatePersistence.js.map +1 -1
- package/data/sqlite/documentPersistence.d.ts +1 -1
- package/data/sqlite/documentPersistence.js +1 -1
- package/data/sqlite/documentPersistence.js.map +1 -1
- package/data/sqlite/documentPersistenceTypes.d.ts +2 -2
- package/data/sqlite/documentPersistenceTypes.js.map +1 -1
- package/data/sqlite/documentRecordPersistence.js +5 -4
- package/data/sqlite/documentRecordPersistence.js.map +1 -1
- package/data/sqlite/schema.d.ts +350 -443
- package/data/sqlite/schema.js +49 -47
- package/data/sqlite/schema.js.map +1 -1
- package/data/sqlite/verifiedManifestBundleSchema.d.ts +174 -0
- package/data/sqlite/verifiedManifestBundleSchema.js +36 -0
- package/data/sqlite/verifiedManifestBundleSchema.js.map +1 -0
- package/internal/api-client/ApiClient.d.ts +17 -19
- package/internal/api-client/ApiClient.js +10 -11
- package/internal/api-client/ApiClient.js.map +1 -1
- package/internal/api-client/binaryRequestOperationTransport.d.ts +18 -0
- package/internal/api-client/index.d.ts +2 -1
- package/internal/api-client/index.js +1 -1
- package/internal/api-client/index.js.map +1 -1
- package/internal/api-client/operationTransportFactory.d.ts +6 -0
- package/internal/api-client/principalHistoryRequest.js +8 -2
- package/internal/api-client/principalHistoryRequest.js.map +1 -1
- package/internal/api-client/principalHistoryRequestContext.js +15 -5
- package/internal/api-client/principalHistoryRequestContext.js.map +1 -1
- package/internal/api-client/routes/blobs/get.d.ts +7 -0
- package/internal/api-client/routes/blobs/get.js.map +1 -1
- package/internal/api-client/routes/blobs/multipart.js +1 -11
- package/internal/api-client/routes/blobs/multipart.js.map +1 -1
- package/internal/api-client/routes/blobs/multipartUpload.d.ts +14 -0
- package/internal/api-client/routes/blobs/multipartUpload.js +94 -43
- package/internal/api-client/routes/blobs/multipartUpload.js.map +1 -1
- package/internal/api-client/routes/writerProjections.js +6 -3
- package/internal/api-client/routes/writerProjections.js.map +1 -1
- package/internal/api-client/verifiedManifestCitations.d.ts +23 -0
- package/internal/api-client/verifiedManifestCitations.js +60 -0
- package/internal/api-client/verifiedManifestCitations.js.map +1 -0
- package/internal/api-client/writerProjectionRequests.js +75 -14
- package/internal/api-client/writerProjectionRequests.js.map +1 -1
- package/internal/crypto/index.d.ts +0 -1
- package/internal/crypto/index.js +0 -1
- package/internal/crypto/index.js.map +1 -1
- package/internal/validators/knownManifestsRefinements.js +5 -0
- package/internal/validators/knownManifestsRefinements.js.map +1 -0
- package/internal/validators/operation/attachments.d.ts +80 -160
- package/internal/validators/operation/auth.d.ts +760 -1664
- package/internal/validators/operation/blobDownloads.js +1 -1
- package/internal/validators/operation/blobDownloads.js.map +1 -1
- package/internal/validators/operation/containerMutations.d.ts +416 -856
- package/internal/validators/operation/documentMutations.d.ts +120 -264
- package/internal/validators/operation/documentSync.d.ts +40 -80
- package/internal/validators/operation/index.d.ts +1 -1
- package/internal/validators/operation/index.js +1 -1
- package/internal/validators/operation/index.js.map +1 -1
- package/internal/validators/operation/multipartBlobs.d.ts +70 -190
- package/internal/validators/operation/multipartBlobs.js +2 -24
- package/internal/validators/operation/multipartBlobs.js.map +1 -1
- package/internal/validators/operation/multipartPartUploads.d.ts +5 -5
- package/internal/validators/operation/multipartPartUploads.js +6 -20
- package/internal/validators/operation/multipartPartUploads.js.map +1 -1
- package/internal/validators/operation/organizations.d.ts +882 -1906
- package/internal/validators/operation/principals.d.ts +120 -240
- package/internal/validators/operation/registry.d.ts +1 -2
- package/internal/validators/operation/registry.js +1 -2
- package/internal/validators/operation/registry.js.map +1 -1
- package/internal/validators/operation/writerProjections.d.ts +85 -319
- package/internal/validators/operation/writerProjections.js +11 -11
- package/internal/validators/operation/writerProjections.js.map +1 -1
- package/internal/validators/request/blob.d.ts +100 -201
- package/internal/validators/request/blob.js +6 -13
- package/internal/validators/request/blob.js.map +1 -1
- package/internal/validators/request/container.d.ts +136 -272
- package/internal/validators/request/container.js +16 -10
- package/internal/validators/request/container.js.map +1 -1
- package/internal/validators/request/containerManifestRef.d.ts +54 -0
- package/internal/validators/request/containerManifestRef.js +28 -0
- package/internal/validators/request/containerManifestRef.js.map +1 -0
- package/internal/validators/request/containerMetadata.d.ts +160 -368
- package/internal/validators/request/document.d.ts +100 -245
- package/internal/validators/request/document.js +1 -2
- package/internal/validators/request/document.js.map +1 -1
- package/internal/validators/request/documentSyncSchema.d.ts +42 -109
- package/internal/validators/request/documentSyncSchema.js +8 -25
- package/internal/validators/request/documentSyncSchema.js.map +1 -1
- package/internal/validators/request/index.d.ts +1 -1
- package/internal/validators/request/index.js +1 -1
- package/internal/validators/request/index.js.map +1 -1
- package/internal/validators/request/organization.d.ts +160 -320
- package/internal/validators/request/organizationProvisioning.d.ts +2424 -5312
- package/internal/validators/request/principal.d.ts +160 -320
- package/internal/validators/request/registration.d.ts +760 -1664
- package/internal/validators/response/blob.d.ts +48 -27
- package/internal/validators/response/blob.js +3 -10
- package/internal/validators/response/blob.js.map +1 -1
- package/internal/validators/response/container.d.ts +429 -20
- package/internal/validators/response/container.js +40 -5
- package/internal/validators/response/container.js.map +1 -1
- package/internal/validators/response/documentMutation.d.ts +440 -20
- package/internal/validators/response/documentMutation.js +33 -3
- package/internal/validators/response/documentMutation.js.map +1 -1
- package/internal/validators/response/index.d.ts +4 -3
- package/internal/validators/response/index.js +4 -3
- package/internal/validators/response/index.js.map +1 -1
- package/internal/validators/response/manifestBundleReferences.js +79 -0
- package/internal/validators/response/manifestBundleReferences.js.map +1 -0
- package/internal/validators/response/writerProjectionWire.d.ts +19 -0
- package/internal/validators/response/writerProjectionWire.js +132 -0
- package/internal/validators/response/writerProjectionWire.js.map +1 -0
- package/internal/validators/schema.js +20 -0
- package/internal/validators/schema.js.map +1 -1
- package/internal/validators/util/blob.d.ts +7 -0
- package/internal/validators/util/blob.js +7 -0
- package/internal/validators/util/blob.js.map +1 -1
- package/internal/validators/util/blobTransferSchemas.d.ts +41 -0
- package/internal/validators/util/blobTransferSchemas.js +39 -0
- package/internal/validators/util/blobTransferSchemas.js.map +1 -0
- package/internal/validators/util/containerLimits.d.ts +7 -0
- package/internal/validators/util/containerLimits.js +7 -0
- package/internal/validators/util/containerLimits.js.map +1 -1
- package/internal/validators/util/index.d.ts +3 -2
- package/internal/validators/util/index.js +3 -2
- package/internal/validators/util/index.js.map +1 -1
- package/internal/validators/util/knownManifestWire.d.ts +11 -0
- package/internal/validators/util/knownManifestWire.js +28 -0
- package/internal/validators/util/knownManifestWire.js.map +1 -0
- package/internal/validators/writerProjectionRefinements.js +5 -0
- package/internal/validators/writerProjectionRefinements.js.map +1 -1
- package/package.json +1 -1
- package/workflows/blobs/multipartFirstParts.js +82 -0
- package/workflows/blobs/multipartFirstParts.js.map +1 -0
- package/workflows/blobs/multipartStageResolution.js +83 -0
- package/workflows/blobs/multipartStageResolution.js.map +1 -0
- package/workflows/blobs/multipartUpload.js +45 -89
- package/workflows/blobs/multipartUpload.js.map +1 -1
- package/workflows/container-contents/documentPriming.js +2 -1
- package/workflows/container-contents/documentPriming.js.map +1 -1
- package/workflows/container-contents/documentQueries/sql.js +4 -4
- package/workflows/container-contents/documentQueries/sql.js.map +1 -1
- package/workflows/container-contents/pendingWrites/deferredTails.js +6 -3
- package/workflows/container-contents/pendingWrites/deferredTails.js.map +1 -1
- package/workflows/container-contents/pendingWrites/sources.js +2 -1
- package/workflows/container-contents/pendingWrites/sources.js.map +1 -1
- package/workflows/container-contents/pendingWrites.js +2 -1
- package/workflows/container-contents/pendingWrites.js.map +1 -1
- package/workflows/containers/child/create.js +3 -3
- package/workflows/containers/child/create.js.map +1 -1
- package/workflows/containers/child/move.js +2 -2
- package/workflows/containers/child/move.js.map +1 -1
- package/workflows/containers/child/mutationRequestCore.js +5 -4
- package/workflows/containers/child/mutationRequestCore.js.map +1 -1
- package/workflows/containers/child/recitePlan.js +3 -2
- package/workflows/containers/child/recitePlan.js.map +1 -1
- package/workflows/containers/child/sharePlanCore.js +2 -2
- package/workflows/containers/child/sharePlanCore.js.map +1 -1
- package/workflows/containers/root/create.js +2 -2
- package/workflows/containers/root/create.js.map +1 -1
- package/workflows/registration/provisioningBootstrapBuilders.d.ts +20 -51
- package/workflows/sync/remoteReset.js +11 -9
- package/workflows/sync/remoteReset.js.map +1 -1
- package/workflows/sync/remoteResetPlans.js +6 -3
- package/workflows/sync/remoteResetPlans.js.map +1 -1
- package/internal/api-client/projectionHistoryTransport.js +0 -107
- package/internal/api-client/projectionHistoryTransport.js.map +0 -1
- package/internal/api-client/verifiedProjectionHistory.d.ts +0 -4
- package/internal/api-client/verifiedProjectionHistory.js +0 -12
- package/internal/api-client/verifiedProjectionHistory.js.map +0 -1
- package/internal/crypto/projectionHistory.d.ts +0 -14
- package/internal/crypto/projectionHistory.js +0 -90
- package/internal/crypto/projectionHistory.js.map +0 -1
- package/internal/crypto/projectionHistorySlots.d.ts +0 -13
- package/internal/crypto/projectionHistorySlots.js +0 -81
- package/internal/crypto/projectionHistorySlots.js.map +0 -1
- package/internal/validators/operation/blobTransferSchemas.js +0 -11
- package/internal/validators/operation/blobTransferSchemas.js.map +0 -1
- package/internal/validators/projectionHistoryRefinements.js +0 -5
- package/internal/validators/projectionHistoryRefinements.js.map +0 -1
- package/internal/validators/util/projectionHistoryWire.d.ts +0 -23
- package/internal/validators/util/projectionHistoryWire.js +0 -33
- package/internal/validators/util/projectionHistoryWire.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutationRequestCore.js","sourceRoot":"","sources":["mutationRequestCore.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mDAAmD,CAAC;AACjG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"mutationRequestCore.js","sourceRoot":"","sources":["mutationRequestCore.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mDAAmD,CAAC;AACjG,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EACL,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AAG3C,MAAM,UAAU,yBAAyB,CACvC,KAAc,EACd,KAAa;IAEb,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAC1C,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,gBAA0C,EAC1C,kBAAqD;IAKrD,OAAO;QACL,mBAAmB,EAAE,oBAAoB,CAAC,gBAAgB,CAAC;QAC3D,yBAAyB,EACvB,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC;KACpD,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B,CAC1C,SAAiB,EACjB,KASC;IAYD,MAAM,KAAK,GAAG,aAAa,SAAS,EAAE,CAAC;IACvC,OAAO;QACL,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,KAAK,QAAQ,CAAC;QACzD,IAAI,EAAE,mBAAmB,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC;QACtD,oBAAoB,EAAE,KAAK,CAAC,YAAY;QACxC,QAAQ,EAAE,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,KAAK,WAAW,CAAC;QAClE,iBAAiB,EAAE,oBAAoB,CACrC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACrC,4BAA4B,CAAC,MAAM,CAAC,CACrC,EACD,GAAG,KAAK,qBAAqB,CAC9B;QACD,QAAQ,EAAE,mBAAmB,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,KAAK,YAAY,CAAC;QACnE,KAAK,EAAE,oBAAoB,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,KAAK,QAAQ,CAAC;QAC1D,iBAAiB,EAAE,oBAAoB,CACrC,KAAK,CAAC,iBAAiB,EACvB,GAAG,KAAK,sBAAsB,CAC/B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n AccessEvent,\n AccessManifest,\n ContainerKeyEpoch,\n ContainerKeyWrap,\n ContainerUserRecipientKey,\n} from \"@tearleads/crypto\";\nimport type {\n AccessManifestBundleWire,\n ContainerMutationRequest,\n} from \"@tearleads/validators/request\";\nimport type { ContainerWriterProjectionResponse } from \"@tearleads/validators/response\";\nimport { principalPolicyRequestRecord } from \"../../../data/containers/shared/principalPolicies\";\nimport { containerManifestRef } from \"../../../data/containers/shared/projection\";\nimport {\n readCanonicalRecord,\n readCanonicalRecords,\n} from \"../../../data/keyingCanonicalJson\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../../data/principals/principalPolicyEvidence\";\n\nexport function readCanonicalRecordOrNull(\n value: unknown,\n label: string,\n): Record<string, unknown> | null {\n return value === null || value === undefined\n ? null\n : readCanonicalRecord(value, label);\n}\n\n/**\n * The previous-manifest identity every non-create mutation\n * (share/rekey/revoke/move) sends alongside the core request fields: the\n * previous head and the current path, cited by hash rather than echoed.\n */\nexport function previousPathRequestFields(\n previousManifest: AccessManifestBundleWire,\n previousProjection: ContainerWriterProjectionResponse,\n): Pick<\n ContainerMutationRequest,\n \"previousManifestRef\" | \"previousContainerPathRefs\"\n> {\n return {\n previousManifestRef: containerManifestRef(previousManifest),\n previousContainerPathRefs:\n previousProjection.path.map(containerManifestRef),\n };\n}\n\n/**\n * The eight ContainerMutationRequest fields every child-container mutation\n * (create/share/rekey/revoke/move) assembles identically, labeled by\n * operation. The identity fields — previous manifest/path, manifest history,\n * predecessor bridge, keyring, and the parent KEK — genuinely differ per\n * operation and stay with each builder.\n */\nexport function containerMutationRequestCore(\n operation: string,\n input: {\n body: unknown;\n event: AccessEvent;\n keyEpoch: ContainerKeyEpoch;\n manifest: AccessManifest;\n manifestHash: string;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n userRecipientKeys: readonly ContainerUserRecipientKey[];\n wraps: readonly ContainerKeyWrap[];\n },\n): Pick<\n ContainerMutationRequest,\n | \"event\"\n | \"body\"\n | \"expectedManifestHash\"\n | \"manifest\"\n | \"principalPolicies\"\n | \"keyEpoch\"\n | \"wraps\"\n | \"userRecipientKeys\"\n> {\n const label = `Container ${operation}`;\n return {\n event: readCanonicalRecord(input.event, `${label} event`),\n body: readCanonicalRecord(input.body, `${label} body`),\n expectedManifestHash: input.manifestHash,\n manifest: readCanonicalRecord(input.manifest, `${label} manifest`),\n principalPolicies: readCanonicalRecords(\n input.principalPolicies.map((policy) =>\n principalPolicyRequestRecord(policy),\n ),\n `${label} principal policies`,\n ),\n keyEpoch: readCanonicalRecord(input.keyEpoch, `${label} key epoch`),\n wraps: readCanonicalRecords(input.wraps, `${label} wraps`),\n userRecipientKeys: readCanonicalRecords(\n input.userRecipientKeys,\n `${label} user recipient keys`,\n ),\n };\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { computeAccessManifestHash, deriveContainerAccessManifest, KeyingVerificationError, MAX_CONTAINER_RECITATION_EPOCH, resolveContainerStatePathUserAccessLevel, } from "../../../internal/crypto/index.js";
|
|
2
2
|
import { signContainerMutationEvent } from "../../../data/containers/shared/events.js";
|
|
3
3
|
import { principalPolicyRequestRecord } from "../../../data/containers/shared/principalPolicies.js";
|
|
4
|
+
import { containerManifestRef } from "../../../data/containers/shared/projection.js";
|
|
4
5
|
import { canonicalKeyingJsonString, readCanonicalRecord, } from "../../../data/keyingCanonicalJson.js";
|
|
5
6
|
export function referencedRecitationPolicies(path, policies) {
|
|
6
7
|
const referencedIds = new Set(path.flatMap((head) => head.state.referencedPrincipalHeads.map((ref) => `${ref.principalType}:${ref.principalId}`)));
|
|
@@ -50,8 +51,8 @@ export async function buildContainerRecitePlan(input) {
|
|
|
50
51
|
event: readCanonicalRecord(event, "Recitation event"),
|
|
51
52
|
manifest: readCanonicalRecord(manifest, "Recitation manifest"),
|
|
52
53
|
expectedManifestHash: manifestHash,
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
previousManifestRef: containerManifestRef(previous.bundle),
|
|
55
|
+
previousContainerPathRefs: input.path.map((head) => containerManifestRef(head.bundle)),
|
|
55
56
|
principalPolicies: referencedRecitationPolicies(input.path, input.policies).map((policy) => principalPolicyRequestRecord(policy)),
|
|
56
57
|
};
|
|
57
58
|
return { body, event, eventHash, manifest, manifestHash, state, request };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recitePlan.js","sourceRoot":"","sources":["recitePlan.ts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Hash,\n deriveContainerAccessManifest,\n KeyingVerificationError,\n MAX_CONTAINER_RECITATION_EPOCH,\n resolveContainerStatePathUserAccessLevel,\n} from \"@tearleads/crypto\";\nimport type { ContainerReciteRequest } from \"@tearleads/validators/request\";\nimport type { ContainerReciteResponse } from \"@tearleads/validators/response\";\nimport { signContainerMutationEvent } from \"../../../data/containers/shared/events\";\nimport type { HeldContainerHead } from \"../../../data/containers/shared/heldContainerHeads\";\nimport { principalPolicyRequestRecord } from \"../../../data/containers/shared/principalPolicies\";\nimport { containerManifestRef } from \"../../../data/containers/shared/projection\";\nimport type { ContainerMutationAuthor } from \"../../../data/containers/shared/types\";\nimport {\n canonicalKeyingJsonString,\n readCanonicalRecord,\n} from \"../../../data/keyingCanonicalJson\";\nimport type { PrincipalPolicyCheckpointEvidence } from \"../../../data/principals/principalPolicyEvidence\";\n\nexport function referencedRecitationPolicies(\n path: readonly HeldContainerHead[],\n policies: readonly PrincipalPolicyCheckpointEvidence[],\n): readonly PrincipalPolicyCheckpointEvidence[] {\n const referencedIds = new Set(\n path.flatMap((head) =>\n head.state.referencedPrincipalHeads.map(\n (ref) => `${ref.principalType}:${ref.principalId}`,\n ),\n ),\n );\n return policies.filter((policy) =>\n referencedIds.has(`${policy.principalType}:${policy.principalId}`),\n );\n}\n\nexport async function buildContainerRecitePlan(input: {\n readonly author: ContainerMutationAuthor;\n readonly path: readonly HeldContainerHead[];\n readonly policies: readonly PrincipalPolicyCheckpointEvidence[];\n}) {\n const previous = input.path.at(-1);\n if (!previous) throw new Error(\"Recitation requires a held container path\");\n if (previous.state.epoch >= MAX_CONTAINER_RECITATION_EPOCH) {\n throw new Error(\"Container re-citation history budget is exhausted\");\n }\n if (\n input.path.some(\n (head) => head.state.organizationId !== input.author.organizationId,\n )\n ) {\n throw new Error(\"Recitation cannot cross organizations\");\n }\n if (\n resolveContainerStatePathUserAccessLevel({\n states: input.path.map((head) => head.state),\n principalPolicies: input.policies,\n userId: input.author.signerUserId,\n }) !== \"admin\"\n ) {\n throw new KeyingVerificationError(\n \"unauthorized\",\n \"Container re-citation signer lacks admin access on the held path\",\n );\n }\n const body = {\n eventType: \"container.recite\" as const,\n containerKeyEpochId: previous.state.containerKeyEpochId,\n containerKeyPublicKey: previous.state.containerKeyPublicKey,\n };\n const { event, eventHash } = await signContainerMutationEvent({\n author: input.author,\n body,\n containerId: previous.state.containerId,\n dependencyManifestHashes: input.path.map(\n (head) => head.bundle.manifestHash,\n ),\n eventId: crypto.randomUUID(),\n previousManifestHash: previous.bundle.manifestHash,\n signedAt: new Date().toISOString(),\n });\n const state = {\n ...previous.state,\n epoch: previous.state.epoch + 1,\n eventHash,\n previousManifestHash: previous.bundle.manifestHash,\n };\n const manifest = await deriveContainerAccessManifest(state);\n const manifestHash = await computeAccessManifestHash(manifest);\n const request: ContainerReciteRequest = {\n body,\n event: readCanonicalRecord(event, \"Recitation event\"),\n manifest: readCanonicalRecord(manifest, \"Recitation manifest\"),\n expectedManifestHash: manifestHash,\n previousManifestRef: containerManifestRef(previous.bundle),\n previousContainerPathRefs: input.path.map((head) =>\n containerManifestRef(head.bundle),\n ),\n principalPolicies: referencedRecitationPolicies(\n input.path,\n input.policies,\n ).map((policy) => principalPolicyRequestRecord(policy)),\n };\n return { body, event, eventHash, manifest, manifestHash, state, request };\n}\n\nexport function assertContainerReciteAcknowledgement(\n plan: Awaited<ReturnType<typeof buildContainerRecitePlan>>,\n response: ContainerReciteResponse,\n): void {\n const bundle = response.accessManifest;\n const signedFieldsMatch = [\n [bundle.event.event, plan.event],\n [bundle.event.body, plan.body],\n [bundle.manifest, plan.manifest],\n [bundle.state, plan.state],\n ].every(\n ([actual, expected]) =>\n canonicalKeyingJsonString(actual, \"Recitation response\") ===\n canonicalKeyingJsonString(expected, \"Recitation plan\"),\n );\n if (\n response.containerId !== plan.state.containerId ||\n response.organizationId !== plan.state.organizationId ||\n response.parentId !== plan.state.parentContainerId ||\n response.manifestHead.epoch !== plan.state.epoch ||\n response.manifestHead.manifestHash !== plan.manifestHash ||\n bundle.manifestHash !== plan.manifestHash ||\n bundle.event.eventHash !== plan.eventHash ||\n !signedFieldsMatch ||\n canonicalKeyingJsonString(\n response.referencedPrincipalHeads,\n \"Recitation references\",\n ) !==\n canonicalKeyingJsonString(\n plan.manifest.referencedPrincipalHeads,\n \"Recitation planned references\",\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Container recitation response does not match the signed plan\",\n );\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { computeAccessManifestHash, deriveContainerAccessManifest, } from "../../../internal/crypto/index.js";
|
|
2
2
|
import { uniquePrincipalPolicies } from "../../../data/containers/shared/principalPolicies.js";
|
|
3
|
-
import { asContainerManifestBundle, getParentKekForTarget, readContainerState, } from "../../../data/containers/shared/projection.js";
|
|
3
|
+
import { asContainerManifestBundle, containerManifestRef, getParentKekForTarget, readContainerState, } from "../../../data/containers/shared/projection.js";
|
|
4
4
|
import { readContainerKekRecipientTargets, readContainerKeyEpoch, } from "../../../data/containers/shared/readers.js";
|
|
5
5
|
import { collectContainerWriterProjectionPrincipalPolicies, } from "../../../data/keyingProjectionVerification.js";
|
|
6
6
|
import { containerMutationRequestCore, previousPathRequestFields, readCanonicalRecordOrNull, } from "./mutationRequestCore.js";
|
|
@@ -90,7 +90,7 @@ function buildContainerShareRequest(input) {
|
|
|
90
90
|
return {
|
|
91
91
|
...containerMutationRequestCore("share", input),
|
|
92
92
|
...previousPathRequestFields(input.previousManifest, input.previousProjection),
|
|
93
|
-
|
|
93
|
+
containerManifestHistoryRefs: input.containerManifestHistory.map(containerManifestRef),
|
|
94
94
|
predecessorBridge: null,
|
|
95
95
|
keyring: null,
|
|
96
96
|
parentKekState: readCanonicalRecordOrNull(input.parentKek, "Container share parent KEK state"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharePlanCore.js","sourceRoot":"","sources":["sharePlanCore.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,yBAAy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C,KAAK,CAAC,MAAM,CAAC,CACxC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sCAAsC,CAAC,KAS5D;IACC,MAAM,gBAAgB,GACpB,MAAM,iDAAiD,CAAC;QACtD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,8BAA8B,EAAE,KAAK,CAAC,8BAA8B;QACpE,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,UAAU,EAAE,KAAK,CAAC,kBAAkB;QACpC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,+BAA+B,EAAE,KAAK,CAAC,+BAA+B;KACvE,CAAC,CAAC;IACL,OAAO,0BAA0B,CAAC;QAChC,gBAAgB;QAChB,0BAA0B,EAAE,KAAK,CAAC,eAAe;KAClD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type AccessEvent,\n type AccessManifest,\n type ContainerAccessManifestState,\n type ContainerDirectGrant,\n type ContainerGrantAccessEventBody,\n type ContainerGrantPrincipalHead,\n type ContainerKekRecipientTarget,\n type ContainerKeyEpoch,\n type ContainerKeyWrap,\n type ContainerUserRecipientKey,\n computeAccessManifestHash,\n deriveContainerAccessManifest,\n} from \"@tearleads/crypto\";\nimport type {\n AccessManifestBundleWire,\n ContainerMutationRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerKekResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { uniquePrincipalPolicies } from \"../../../data/containers/shared/principalPolicies\";\nimport {\n asContainerManifestBundle,\n getParentKekForTarget,\n readContainerState,\n} from \"../../../data/containers/shared/projection\";\nimport {\n readContainerKekRecipientTargets,\n readContainerKeyEpoch,\n} from \"../../../data/containers/shared/readers\";\nimport type {\n ContainerSharePlan,\n MaterializedContainerSharePlan,\n} from \"../../../data/containers/shared/types\";\nimport {\n collectContainerWriterProjectionPrincipalPolicies,\n type PrincipalPolicyCache,\n type ProjectionUserKeyResolver,\n type ReferencedPrincipalPolicyWarmer,\n} from \"../../../data/keyingProjectionVerification\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../../data/principals/principalPolicyEvidence\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n containerMutationRequestCore,\n previousPathRequestFields,\n readCanonicalRecordOrNull,\n} from \"./mutationRequestCore\";\n\nexport type ContainerShareRecipient =\n | {\n readonly recipientEncapsulationPublicKey: Uint8Array;\n readonly subjectId: string;\n readonly subjectType: \"user\";\n }\n | {\n readonly principalPolicy: PrincipalPolicyCurrentEvidence;\n readonly subjectId: string;\n readonly subjectType: \"group\";\n };\n\nfunction grantKey(\n grant: Pick<ContainerDirectGrant, \"subjectId\" | \"subjectType\">,\n): string {\n return `${grant.subjectType}:${grant.subjectId}`;\n}\n\nfunction upsertContainerGrant(\n grants: readonly ContainerDirectGrant[],\n grant: ContainerDirectGrant,\n): ContainerDirectGrant[] {\n return [\n ...grants.filter(\n (existingGrant) => grantKey(existingGrant) !== grantKey(grant),\n ),\n grant,\n ].sort((left, right) => grantKey(left).localeCompare(grantKey(right)));\n}\n\nfunction referencedPrincipalKey(reference: {\n readonly principalId: string;\n readonly principalType: \"group\";\n}): string {\n return `${reference.principalType}:${reference.principalId}`;\n}\n\nexport function referencedPrincipalHeadFromPolicy(\n policy: PrincipalPolicyCurrentEvidence,\n): ContainerGrantPrincipalHead {\n if (policy.principalType !== \"group\") {\n throw new Error(\"Container grants can reference only group policies\");\n }\n return {\n principalType: \"group\",\n principalId: policy.principalId,\n version: policy.version,\n keyEpoch: policy.keyEpoch,\n stateHash: policy.stateHash,\n keyFingerprint: policy.state.keyFingerprint,\n };\n}\n\nfunction upsertReferencedPrincipalHead(\n references: readonly ContainerGrantPrincipalHead[],\n reference: ContainerGrantPrincipalHead,\n): ContainerGrantPrincipalHead[] {\n return [\n ...references.filter(\n (existingReference) =>\n referencedPrincipalKey(existingReference) !==\n referencedPrincipalKey(reference),\n ),\n reference,\n ].sort((left, right) =>\n referencedPrincipalKey(left).localeCompare(referencedPrincipalKey(right)),\n );\n}\n\n/**\n * The previous manifest's referenced principal heads with the replacement\n * policy's head upserted in place of any stale head for the same principal.\n * A rekey substitutes references and never adds one: a manifest may reference\n * only principals it grants, so a replacement for one it does not grant —\n * a carried rekey below the container the policy is granted on — is left out.\n */\nexport function refreshedPrincipalReferences(input: {\n readonly previousState: ContainerAccessManifestState;\n readonly replacementPrincipalPolicy?:\n | PrincipalPolicyCurrentEvidence\n | undefined;\n}): ContainerGrantPrincipalHead[] {\n const replacement = input.replacementPrincipalPolicy;\n if (\n !replacement ||\n !input.previousState.directGrants.some(\n (grant) =>\n grant.subjectType === replacement.principalType &&\n grant.subjectId === replacement.principalId,\n )\n ) {\n return [...input.previousState.referencedPrincipalHeads];\n }\n return upsertReferencedPrincipalHead(\n input.previousState.referencedPrincipalHeads,\n referencedPrincipalHeadFromPolicy(replacement),\n );\n}\n\n/**\n * The previous policies with the replacement policy substituted for any\n * existing policy of the same principal identity.\n */\nexport function refreshedPrincipalPolicies(input: {\n readonly previousPolicies: readonly PrincipalPolicyCurrentEvidence[];\n readonly replacementPrincipalPolicy?:\n | PrincipalPolicyCurrentEvidence\n | undefined;\n}): PrincipalPolicyCurrentEvidence[] {\n const replacement = input.replacementPrincipalPolicy;\n if (!replacement) {\n return uniquePrincipalPolicies(input.previousPolicies);\n }\n return uniquePrincipalPolicies([\n ...input.previousPolicies.filter(\n (policy) =>\n policy.principalType !== replacement.principalType ||\n policy.principalId !== replacement.principalId,\n ),\n replacement,\n ]);\n}\n\nexport async function deriveContainerShareManifest(input: {\n eventHash: string;\n grant: ContainerDirectGrant;\n previousManifest: ContainerWriterProjectionResponse[\"path\"][number];\n referencedPrincipalHead: ContainerGrantPrincipalHead | null;\n}): Promise<Pick<ContainerSharePlan, \"manifest\" | \"manifestHash\" | \"state\">> {\n const previousState = readContainerState(input.previousManifest);\n const state: ContainerAccessManifestState = {\n ...previousState,\n epoch: previousState.epoch + 1,\n previousManifestHash: input.previousManifest.manifestHash,\n eventHash: input.eventHash,\n directGrants: upsertContainerGrant(previousState.directGrants, input.grant),\n referencedPrincipalHeads: input.referencedPrincipalHead\n ? upsertReferencedPrincipalHead(\n previousState.referencedPrincipalHeads,\n input.referencedPrincipalHead,\n )\n : previousState.referencedPrincipalHeads,\n };\n const manifest = await deriveContainerAccessManifest(state);\n\n return {\n manifest,\n manifestHash: await computeAccessManifestHash(manifest),\n state,\n };\n}\n\nfunction buildContainerShareRequest(input: {\n body: ContainerGrantAccessEventBody;\n containerManifestHistory: readonly AccessManifestBundleWire[];\n event: AccessEvent;\n keyEpoch: ContainerKeyEpoch;\n manifest: AccessManifest;\n manifestHash: string;\n parentKek: ContainerKekResponse | null;\n previousManifest: AccessManifestBundleWire;\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n userRecipientKeys: readonly ContainerUserRecipientKey[];\n wraps: readonly ContainerKeyWrap[];\n}): ContainerMutationRequest {\n return {\n ...containerMutationRequestCore(\"share\", input),\n ...previousPathRequestFields(\n input.previousManifest,\n input.previousProjection,\n ),\n containerManifestHistory: [...input.containerManifestHistory],\n predecessorBridge: null,\n keyring: null,\n parentKekState: readCanonicalRecordOrNull(\n input.parentKek,\n \"Container share parent KEK state\",\n ),\n };\n}\n\nexport function replaceContainerWrap(\n wraps: readonly ContainerKeyWrap[],\n nextWrap: ContainerKeyWrap,\n): ContainerKeyWrap[] {\n return [\n ...wraps.filter(\n (wrap) =>\n !(\n wrap.recipientKind === nextWrap.recipientKind &&\n wrap.recipientId === nextWrap.recipientId\n ),\n ),\n nextWrap,\n ];\n}\n\nexport function shareManifestHistory(input: {\n readonly containerId: string;\n readonly targetKek: ContainerKekResponse;\n readonly targetManifest: ContainerWriterProjectionResponse[\"path\"][number];\n}): AccessManifestBundleWire[] {\n const byHash = new Map<string, AccessManifestBundleWire>();\n for (const bundle of [\n input.targetManifest,\n ...input.targetKek.containerManifestHistory,\n ]) {\n if (\n readContainerState(bundle).containerId === input.containerId &&\n !byHash.has(bundle.manifestHash)\n ) {\n byHash.set(bundle.manifestHash, asContainerManifestBundle(bundle));\n }\n }\n return [...byHash.values()];\n}\n\nexport function buildContainerSharePlanResult(input: {\n body: ContainerGrantAccessEventBody;\n containerManifestHistory: readonly AccessManifestBundleWire[];\n containerId: string;\n containerKey: Uint8Array;\n event: AccessEvent;\n eventHash: string;\n grant: ContainerDirectGrant;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n recipientTarget: ContainerKekRecipientTarget;\n state: ContainerAccessManifestState;\n targetKek: ContainerKekResponse;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}): MaterializedContainerSharePlan {\n const keyEpoch = readContainerKeyEpoch(\n input.targetKek.keyEpoch,\n \"Container share key epoch\",\n );\n const plan: ContainerSharePlan = {\n body: input.body,\n containerId: input.containerId,\n event: input.event,\n eventHash: input.eventHash,\n grant: input.grant,\n keyEpoch,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n previousKeyring: readCanonicalRecordOrNull(\n input.previousProjection.containerKeks.at(-1)?.keyring ?? null,\n \"Container share previous keyring\",\n ),\n previousManifest: input.previousManifest,\n recipientTarget: input.recipientTarget,\n request: buildContainerShareRequest({\n body: input.body,\n containerManifestHistory: input.containerManifestHistory,\n event: input.event,\n keyEpoch,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n parentKek: getParentKekForTarget(input.previousProjection),\n previousManifest: input.previousManifest,\n previousProjection: input.previousProjection,\n principalPolicies: input.principalPolicies,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n }),\n state: input.state,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n };\n\n return { containerKey: input.containerKey, plan };\n}\n\nexport function collectShareUserRecipientKeys(input: {\n newUserRecipientKey?: ContainerUserRecipientKey | undefined;\n state: ContainerAccessManifestState;\n targetKek: ContainerKekResponse;\n}): ContainerUserRecipientKey[] {\n const directUserIds = new Set(\n input.state.directGrants.flatMap((grant) =>\n grant.subjectType === \"user\" ? [grant.subjectId] : [],\n ),\n );\n const userRecipientKeyByUserId = new Map<string, ContainerUserRecipientKey>();\n\n for (const target of readContainerKekRecipientTargets(\n input.targetKek.recipientTargets,\n \"Container share target KEK recipient targets\",\n )) {\n if (\n target.recipientKind !== \"user\" ||\n !directUserIds.has(target.recipientId)\n ) {\n continue;\n }\n userRecipientKeyByUserId.set(target.recipientId, {\n userId: target.recipientId,\n recipientKeyEpochId: target.recipientKeyEpochId,\n recipientKeyFingerprint: target.recipientKeyFingerprint,\n });\n }\n\n if (input.newUserRecipientKey) {\n userRecipientKeyByUserId.set(\n input.newUserRecipientKey.userId,\n input.newUserRecipientKey,\n );\n }\n\n const missingUserId = [...directUserIds].find(\n (userId) => !userRecipientKeyByUserId.has(userId),\n );\n if (missingUserId) {\n throw new Error(\n `Container share recipient key is missing for direct user grant ${missingUserId}`,\n );\n }\n\n return [...userRecipientKeyByUserId.values()].sort((left, right) =>\n left.userId.localeCompare(right.userId),\n );\n}\n\nexport async function collectContainerSharePrincipalPolicies(input: {\n execSql: ExecSql;\n persistVerificationCheckpoints?: boolean | undefined;\n principalPolicyCache?: PrincipalPolicyCache | undefined;\n previousProjection: ContainerWriterProjectionResponse;\n recipientPolicy?: PrincipalPolicyCurrentEvidence | undefined;\n resolveUserKey: ProjectionUserKeyResolver;\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<PrincipalPolicyCurrentEvidence[]> {\n const previousPolicies =\n await collectContainerWriterProjectionPrincipalPolicies({\n execSql: input.execSql,\n persistVerificationCheckpoints: input.persistVerificationCheckpoints,\n principalPolicyCache: input.principalPolicyCache,\n projection: input.previousProjection,\n resolveUserKey: input.resolveUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n return refreshedPrincipalPolicies({\n previousPolicies,\n replacementPrincipalPolicy: input.recipientPolicy,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sharePlanCore.js","sourceRoot":"","sources":["sharePlanCore.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,mBAAmB,CAAC;AAS3B,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACL,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,yCAAyC,CAAC;AAKjD,OAAO,EACL,iDAAiD,GAIlD,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAc/B,SAAS,QAAQ,CACf,KAA8D;IAE9D,OAAO,GAAG,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;AACnD,CAAC;AAED,SAAS,oBAAoB,CAC3B,MAAuC,EACvC,KAA2B;IAE3B,OAAO;QACL,GAAG,MAAM,CAAC,MAAM,CACd,CAAC,aAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,QAAQ,CAAC,KAAK,CAAC,CAC/D;QACD,KAAK;KACN,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,sBAAsB,CAAC,SAG/B;IACC,OAAO,GAAG,SAAS,CAAC,aAAa,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;AAC/D,C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,CAAC,CAClD,CAAC;IACF,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,kEAAkE,aAAa,EAAE,CAClF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,GAAG,wBAAwB,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACjE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CACxC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sCAAsC,CAAC,KAS5D;IACC,MAAM,gBAAgB,GACpB,MAAM,iDAAiD,CAAC;QACtD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,8BAA8B,EAAE,KAAK,CAAC,8BAA8B;QACpE,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,UAAU,EAAE,KAAK,CAAC,kBAAkB;QACpC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,+BAA+B,EAAE,KAAK,CAAC,+BAA+B;KACvE,CAAC,CAAC;IACL,OAAO,0BAA0B,CAAC;QAChC,gBAAgB;QAChB,0BAA0B,EAAE,KAAK,CAAC,eAAe;KAClD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type AccessEvent,\n type AccessManifest,\n type ContainerAccessManifestState,\n type ContainerDirectGrant,\n type ContainerGrantAccessEventBody,\n type ContainerGrantPrincipalHead,\n type ContainerKekRecipientTarget,\n type ContainerKeyEpoch,\n type ContainerKeyWrap,\n type ContainerUserRecipientKey,\n computeAccessManifestHash,\n deriveContainerAccessManifest,\n} from \"@tearleads/crypto\";\nimport type {\n AccessManifestBundleWire,\n ContainerMutationRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerKekResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { uniquePrincipalPolicies } from \"../../../data/containers/shared/principalPolicies\";\nimport {\n asContainerManifestBundle,\n containerManifestRef,\n getParentKekForTarget,\n readContainerState,\n} from \"../../../data/containers/shared/projection\";\nimport {\n readContainerKekRecipientTargets,\n readContainerKeyEpoch,\n} from \"../../../data/containers/shared/readers\";\nimport type {\n ContainerSharePlan,\n MaterializedContainerSharePlan,\n} from \"../../../data/containers/shared/types\";\nimport {\n collectContainerWriterProjectionPrincipalPolicies,\n type PrincipalPolicyCache,\n type ProjectionUserKeyResolver,\n type ReferencedPrincipalPolicyWarmer,\n} from \"../../../data/keyingProjectionVerification\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../../data/principals/principalPolicyEvidence\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n containerMutationRequestCore,\n previousPathRequestFields,\n readCanonicalRecordOrNull,\n} from \"./mutationRequestCore\";\n\nexport type ContainerShareRecipient =\n | {\n readonly recipientEncapsulationPublicKey: Uint8Array;\n readonly subjectId: string;\n readonly subjectType: \"user\";\n }\n | {\n readonly principalPolicy: PrincipalPolicyCurrentEvidence;\n readonly subjectId: string;\n readonly subjectType: \"group\";\n };\n\nfunction grantKey(\n grant: Pick<ContainerDirectGrant, \"subjectId\" | \"subjectType\">,\n): string {\n return `${grant.subjectType}:${grant.subjectId}`;\n}\n\nfunction upsertContainerGrant(\n grants: readonly ContainerDirectGrant[],\n grant: ContainerDirectGrant,\n): ContainerDirectGrant[] {\n return [\n ...grants.filter(\n (existingGrant) => grantKey(existingGrant) !== grantKey(grant),\n ),\n grant,\n ].sort((left, right) => grantKey(left).localeCompare(grantKey(right)));\n}\n\nfunction referencedPrincipalKey(reference: {\n readonly principalId: string;\n readonly principalType: \"group\";\n}): string {\n return `${reference.principalType}:${reference.principalId}`;\n}\n\nexport function referencedPrincipalHeadFromPolicy(\n policy: PrincipalPolicyCurrentEvidence,\n): ContainerGrantPrincipalHead {\n if (policy.principalType !== \"group\") {\n throw new Error(\"Container grants can reference only group policies\");\n }\n return {\n principalType: \"group\",\n principalId: policy.principalId,\n version: policy.version,\n keyEpoch: policy.keyEpoch,\n stateHash: policy.stateHash,\n keyFingerprint: policy.state.keyFingerprint,\n };\n}\n\nfunction upsertReferencedPrincipalHead(\n references: readonly ContainerGrantPrincipalHead[],\n reference: ContainerGrantPrincipalHead,\n): ContainerGrantPrincipalHead[] {\n return [\n ...references.filter(\n (existingReference) =>\n referencedPrincipalKey(existingReference) !==\n referencedPrincipalKey(reference),\n ),\n reference,\n ].sort((left, right) =>\n referencedPrincipalKey(left).localeCompare(referencedPrincipalKey(right)),\n );\n}\n\n/**\n * The previous manifest's referenced principal heads with the replacement\n * policy's head upserted in place of any stale head for the same principal.\n * A rekey substitutes references and never adds one: a manifest may reference\n * only principals it grants, so a replacement for one it does not grant —\n * a carried rekey below the container the policy is granted on — is left out.\n */\nexport function refreshedPrincipalReferences(input: {\n readonly previousState: ContainerAccessManifestState;\n readonly replacementPrincipalPolicy?:\n | PrincipalPolicyCurrentEvidence\n | undefined;\n}): ContainerGrantPrincipalHead[] {\n const replacement = input.replacementPrincipalPolicy;\n if (\n !replacement ||\n !input.previousState.directGrants.some(\n (grant) =>\n grant.subjectType === replacement.principalType &&\n grant.subjectId === replacement.principalId,\n )\n ) {\n return [...input.previousState.referencedPrincipalHeads];\n }\n return upsertReferencedPrincipalHead(\n input.previousState.referencedPrincipalHeads,\n referencedPrincipalHeadFromPolicy(replacement),\n );\n}\n\n/**\n * The previous policies with the replacement policy substituted for any\n * existing policy of the same principal identity.\n */\nexport function refreshedPrincipalPolicies(input: {\n readonly previousPolicies: readonly PrincipalPolicyCurrentEvidence[];\n readonly replacementPrincipalPolicy?:\n | PrincipalPolicyCurrentEvidence\n | undefined;\n}): PrincipalPolicyCurrentEvidence[] {\n const replacement = input.replacementPrincipalPolicy;\n if (!replacement) {\n return uniquePrincipalPolicies(input.previousPolicies);\n }\n return uniquePrincipalPolicies([\n ...input.previousPolicies.filter(\n (policy) =>\n policy.principalType !== replacement.principalType ||\n policy.principalId !== replacement.principalId,\n ),\n replacement,\n ]);\n}\n\nexport async function deriveContainerShareManifest(input: {\n eventHash: string;\n grant: ContainerDirectGrant;\n previousManifest: ContainerWriterProjectionResponse[\"path\"][number];\n referencedPrincipalHead: ContainerGrantPrincipalHead | null;\n}): Promise<Pick<ContainerSharePlan, \"manifest\" | \"manifestHash\" | \"state\">> {\n const previousState = readContainerState(input.previousManifest);\n const state: ContainerAccessManifestState = {\n ...previousState,\n epoch: previousState.epoch + 1,\n previousManifestHash: input.previousManifest.manifestHash,\n eventHash: input.eventHash,\n directGrants: upsertContainerGrant(previousState.directGrants, input.grant),\n referencedPrincipalHeads: input.referencedPrincipalHead\n ? upsertReferencedPrincipalHead(\n previousState.referencedPrincipalHeads,\n input.referencedPrincipalHead,\n )\n : previousState.referencedPrincipalHeads,\n };\n const manifest = await deriveContainerAccessManifest(state);\n\n return {\n manifest,\n manifestHash: await computeAccessManifestHash(manifest),\n state,\n };\n}\n\nfunction buildContainerShareRequest(input: {\n body: ContainerGrantAccessEventBody;\n containerManifestHistory: readonly AccessManifestBundleWire[];\n event: AccessEvent;\n keyEpoch: ContainerKeyEpoch;\n manifest: AccessManifest;\n manifestHash: string;\n parentKek: ContainerKekResponse | null;\n previousManifest: AccessManifestBundleWire;\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n userRecipientKeys: readonly ContainerUserRecipientKey[];\n wraps: readonly ContainerKeyWrap[];\n}): ContainerMutationRequest {\n return {\n ...containerMutationRequestCore(\"share\", input),\n ...previousPathRequestFields(\n input.previousManifest,\n input.previousProjection,\n ),\n containerManifestHistoryRefs:\n input.containerManifestHistory.map(containerManifestRef),\n predecessorBridge: null,\n keyring: null,\n parentKekState: readCanonicalRecordOrNull(\n input.parentKek,\n \"Container share parent KEK state\",\n ),\n };\n}\n\nexport function replaceContainerWrap(\n wraps: readonly ContainerKeyWrap[],\n nextWrap: ContainerKeyWrap,\n): ContainerKeyWrap[] {\n return [\n ...wraps.filter(\n (wrap) =>\n !(\n wrap.recipientKind === nextWrap.recipientKind &&\n wrap.recipientId === nextWrap.recipientId\n ),\n ),\n nextWrap,\n ];\n}\n\nexport function shareManifestHistory(input: {\n readonly containerId: string;\n readonly targetKek: ContainerKekResponse;\n readonly targetManifest: ContainerWriterProjectionResponse[\"path\"][number];\n}): AccessManifestBundleWire[] {\n const byHash = new Map<string, AccessManifestBundleWire>();\n for (const bundle of [\n input.targetManifest,\n ...input.targetKek.containerManifestHistory,\n ]) {\n if (\n readContainerState(bundle).containerId === input.containerId &&\n !byHash.has(bundle.manifestHash)\n ) {\n byHash.set(bundle.manifestHash, asContainerManifestBundle(bundle));\n }\n }\n return [...byHash.values()];\n}\n\nexport function buildContainerSharePlanResult(input: {\n body: ContainerGrantAccessEventBody;\n containerManifestHistory: readonly AccessManifestBundleWire[];\n containerId: string;\n containerKey: Uint8Array;\n event: AccessEvent;\n eventHash: string;\n grant: ContainerDirectGrant;\n manifest: AccessManifest;\n manifestHash: string;\n previousManifest: AccessManifestBundleWire;\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n recipientTarget: ContainerKekRecipientTarget;\n state: ContainerAccessManifestState;\n targetKek: ContainerKekResponse;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}): MaterializedContainerSharePlan {\n const keyEpoch = readContainerKeyEpoch(\n input.targetKek.keyEpoch,\n \"Container share key epoch\",\n );\n const plan: ContainerSharePlan = {\n body: input.body,\n containerId: input.containerId,\n event: input.event,\n eventHash: input.eventHash,\n grant: input.grant,\n keyEpoch,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n previousKeyring: readCanonicalRecordOrNull(\n input.previousProjection.containerKeks.at(-1)?.keyring ?? null,\n \"Container share previous keyring\",\n ),\n previousManifest: input.previousManifest,\n recipientTarget: input.recipientTarget,\n request: buildContainerShareRequest({\n body: input.body,\n containerManifestHistory: input.containerManifestHistory,\n event: input.event,\n keyEpoch,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n parentKek: getParentKekForTarget(input.previousProjection),\n previousManifest: input.previousManifest,\n previousProjection: input.previousProjection,\n principalPolicies: input.principalPolicies,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n }),\n state: input.state,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n };\n\n return { containerKey: input.containerKey, plan };\n}\n\nexport function collectShareUserRecipientKeys(input: {\n newUserRecipientKey?: ContainerUserRecipientKey | undefined;\n state: ContainerAccessManifestState;\n targetKek: ContainerKekResponse;\n}): ContainerUserRecipientKey[] {\n const directUserIds = new Set(\n input.state.directGrants.flatMap((grant) =>\n grant.subjectType === \"user\" ? [grant.subjectId] : [],\n ),\n );\n const userRecipientKeyByUserId = new Map<string, ContainerUserRecipientKey>();\n\n for (const target of readContainerKekRecipientTargets(\n input.targetKek.recipientTargets,\n \"Container share target KEK recipient targets\",\n )) {\n if (\n target.recipientKind !== \"user\" ||\n !directUserIds.has(target.recipientId)\n ) {\n continue;\n }\n userRecipientKeyByUserId.set(target.recipientId, {\n userId: target.recipientId,\n recipientKeyEpochId: target.recipientKeyEpochId,\n recipientKeyFingerprint: target.recipientKeyFingerprint,\n });\n }\n\n if (input.newUserRecipientKey) {\n userRecipientKeyByUserId.set(\n input.newUserRecipientKey.userId,\n input.newUserRecipientKey,\n );\n }\n\n const missingUserId = [...directUserIds].find(\n (userId) => !userRecipientKeyByUserId.has(userId),\n );\n if (missingUserId) {\n throw new Error(\n `Container share recipient key is missing for direct user grant ${missingUserId}`,\n );\n }\n\n return [...userRecipientKeyByUserId.values()].sort((left, right) =>\n left.userId.localeCompare(right.userId),\n );\n}\n\nexport async function collectContainerSharePrincipalPolicies(input: {\n execSql: ExecSql;\n persistVerificationCheckpoints?: boolean | undefined;\n principalPolicyCache?: PrincipalPolicyCache | undefined;\n previousProjection: ContainerWriterProjectionResponse;\n recipientPolicy?: PrincipalPolicyCurrentEvidence | undefined;\n resolveUserKey: ProjectionUserKeyResolver;\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<PrincipalPolicyCurrentEvidence[]> {\n const previousPolicies =\n await collectContainerWriterProjectionPrincipalPolicies({\n execSql: input.execSql,\n persistVerificationCheckpoints: input.persistVerificationCheckpoints,\n principalPolicyCache: input.principalPolicyCache,\n projection: input.previousProjection,\n resolveUserKey: input.resolveUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n return refreshedPrincipalPolicies({\n previousPolicies,\n replacementPrincipalPolicy: input.recipientPolicy,\n });\n}\n"]}
|
|
@@ -54,8 +54,8 @@ function buildRootContainerCreateRequest(input) {
|
|
|
54
54
|
body: readCanonicalRecord(input.body, "Container root create body"),
|
|
55
55
|
expectedManifestHash: input.manifestHash,
|
|
56
56
|
manifest: readCanonicalRecord(input.manifest, "Container root create manifest"),
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
previousManifestRef: null,
|
|
58
|
+
parentContainerPathRefs: [],
|
|
59
59
|
principalPolicies: readCanonicalRecords(input.principalPolicies, "Container root create principal policies"),
|
|
60
60
|
keyEpoch: readCanonicalRecord(input.keyEpoch, "Container root create key epoch"),
|
|
61
61
|
predecessorBridge: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["create.ts"],"names":[],"mappings":"AASA,OAAO,EACL,sCAAsC,EACtC,4BAA4B,EAC5B,mCAAmC,EACnC,iCAAiC,GAClC,MAAM,mBAAmB,CAAC;AAO3B,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,6BAA6B,EAC7B,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,kCAAkC,EAClC,0BAA0B,GAC3B,MAAM,4CAA4C,CAAC;AAMpD,OAAO,EACL,iBAAiB,EACjB,mBAAm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BAC9D,IAAI,EAAE,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,qBAAqB,CAAC;oBAC3D,SAAS,EAAE,IAAI,CAAC,SAAS;iBAC1B;gBACD,QAAQ,EAAE,mBAAmB,CAAC,IAAI,CAAC,QAAQ,EAAE,yBAAyB,CAAC;gBACvE,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,KAAK,EAAE,mBAAmB,CAAC,IAAI,CAAC,KAAK,EAAE,sBAAsB,CAAC;aAC/D;SACF;QACD,aAAa,EAAE;YACb;gBACE,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,kBAAkB,EAAE,IAAI,CAAC,YAAY;gBACrC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;gBAC7C,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ;gBACzC,QAAQ,EAAE,mBAAmB,CAC3B,IAAI,CAAC,QAAQ,EACb,0BAA0B,CAC3B;gBACD,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,aAAa,EAAE,IAAI,CAAC,aAAa;gBACjC,wBAAwB,EAAE,EAAE;gBAC5B,yBAAyB,EAAE,IAAI;gBAC/B,OAAO,EAAE,IAAI;gBACb,gBAAgB,EAAE,oBAAoB,CACpC,IAAI,CAAC,gBAAgB,EACrB,kCAAkC,CACnC;gBACD,KAAK,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,sBAAsB,CAAC;aAChE;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n AccessEvent,\n AccessManifest,\n ContainerCreateAccessEventBody,\n ContainerGrantPrincipalHead,\n ContainerKeyEpoch,\n ContainerKeyWrap,\n ContainerUserRecipientKey,\n} from \"@tearleads/crypto\";\nimport {\n computeContainerKekRecipientTargetHash,\n computeContainerKeyEpochHash,\n deriveContainerKekWrappingPublicKey,\n normalizeContainerAccessEventBody,\n} from \"@tearleads/crypto\";\nimport type { ContainerSystemSlot } from \"@tearleads/validators/containerSystemSlot\";\nimport type {\n ContainerMutationRequest,\n CreateOrganizationGroupRequest,\n} from \"@tearleads/validators/request\";\nimport type { ContainerWriterProjectionResponse } from \"@tearleads/validators/response\";\nimport {\n buildContainerCreateBody,\n buildContainerCreateKeyEpoch,\n deriveContainerCreateManifest,\n resolveContainerKekEpochId,\n signContainerCreateEvent,\n} from \"../../../data/containers/shared/events\";\nimport {\n wrapContainerKeyToManagedPrincipal,\n wrapContainerKeyToRootUser,\n} from \"../../../data/containers/shared/projection\";\nimport type {\n ContainerCreatePlan,\n ContainerMutationAuthor,\n MaterializedContainerCreatePlan,\n} from \"../../../data/containers/shared/types\";\nimport {\n readCanonicalJson,\n readCanonicalRecord,\n readCanonicalRecords,\n} from \"../../../data/keyingCanonicalJson\";\n\nimport {\n principalHeadFromInitialGroupPolicy,\n principalPolicyRecordFromInitialGroupPolicy,\n} from \"./initialGroupPolicy\";\n\nfunction buildRootContainerCreateBody(input: {\n author: ContainerMutationAuthor;\n managedPrincipalHead: ContainerGrantPrincipalHead | null;\n containerKeyEpochId: string;\n containerKeyPublicKey: string;\n metadataDocumentId: string;\n memberHead: ContainerGrantPrincipalHead | null;\n systemSlot: ContainerSystemSlot | null;\n}): ContainerCreateAccessEventBody {\n const baseBody = buildContainerCreateBody({\n systemSlot: input.systemSlot,\n containerKeyEpochId: input.containerKeyEpochId,\n containerKeyPublicKey: input.containerKeyPublicKey,\n metadataDocumentId: input.metadataDocumentId,\n parentContainerId: null,\n parentManifestHash: null,\n });\n if (input.managedPrincipalHead) {\n return {\n ...baseBody,\n directGrants: [\n {\n accessLevel: \"admin\",\n subjectId: input.managedPrincipalHead.principalId,\n subjectType: input.managedPrincipalHead.principalType,\n },\n ...(input.memberHead\n ? [\n {\n accessLevel: \"read\" as const,\n subjectId: input.memberHead.principalId,\n subjectType: \"group\" as const,\n },\n ]\n : []),\n ],\n referencedPrincipalHeads: [\n input.managedPrincipalHead,\n ...(input.memberHead ? [input.memberHead] : []),\n ],\n };\n }\n\n return {\n ...baseBody,\n directGrants: [\n {\n accessLevel: \"admin\",\n subjectId: input.author.signerUserId,\n subjectType: \"user\",\n },\n ],\n };\n}\n\nfunction buildRootContainerCreateRequest(input: {\n body: ContainerCreateAccessEventBody;\n event: AccessEvent;\n keyEpoch: ContainerKeyEpoch;\n manifest: AccessManifest;\n manifestHash: string;\n principalPolicies: readonly Record<string, unknown>[];\n userRecipientKeys: readonly ContainerUserRecipientKey[];\n wraps: readonly ContainerKeyWrap[];\n}): ContainerMutationRequest {\n return {\n event: readCanonicalRecord(input.event, \"Container root create event\"),\n body: readCanonicalRecord(input.body, \"Container root create body\"),\n expectedManifestHash: input.manifestHash,\n manifest: readCanonicalRecord(\n input.manifest,\n \"Container root create manifest\",\n ),\n previousManifest: null,\n parentContainerPath: [],\n principalPolicies: readCanonicalRecords(\n input.principalPolicies,\n \"Container root create principal policies\",\n ),\n keyEpoch: readCanonicalRecord(\n input.keyEpoch,\n \"Container root create key epoch\",\n ),\n predecessorBridge: null,\n keyring: null,\n wraps: readCanonicalRecords(input.wraps, \"Container root create wraps\"),\n userRecipientKeys: readCanonicalRecords(\n input.userRecipientKeys,\n \"Container root create user recipient keys\",\n ),\n };\n}\n\nasync function buildRootManagedPrincipalContext(\n adminGroup: CreateOrganizationGroupRequest | null,\n): Promise<{\n managedPrincipalHead: ContainerGrantPrincipalHead | null;\n managedPrincipalPolicies: Record<string, unknown>[];\n}> {\n if (!adminGroup) {\n return {\n managedPrincipalHead: null,\n managedPrincipalPolicies: [],\n };\n }\n\n const managedPrincipalHead = await principalHeadFromInitialGroupPolicy({\n principalId: adminGroup.groupId,\n policy: adminGroup.initialGroupPolicy,\n });\n\n return {\n managedPrincipalHead,\n managedPrincipalPolicies: [\n principalPolicyRecordFromInitialGroupPolicy({\n head: managedPrincipalHead,\n policy: adminGroup.initialGroupPolicy,\n }),\n ],\n };\n}\n\nasync function deriveRootCreateArtifacts(input: {\n author: ContainerMutationAuthor;\n body: ContainerCreateAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n metadataDocumentId: string;\n signedAt: string | undefined;\n}) {\n if (!input.body.containerKeyPublicKey)\n throw new Error(\"Root container public key is missing\");\n const { event, eventHash } = await signContainerCreateEvent({\n author: input.author,\n body: input.body,\n containerId: input.containerId,\n eventId: crypto.randomUUID(),\n // A root container belongs to the creator's own organization.\n organizationId: input.author.organizationId,\n parentPath: [],\n signedAt: input.signedAt ?? new Date().toISOString(),\n });\n const { manifest, manifestHash, state } = await deriveContainerCreateManifest(\n {\n systemSlot: input.body.systemSlot,\n containerId: input.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n containerKeyPublicKey: input.body.containerKeyPublicKey,\n directGrants: input.body.directGrants,\n eventHash,\n metadataDocumentId: input.metadataDocumentId,\n // A root container belongs to the creator's own organization.\n organizationId: input.author.organizationId,\n parentContainerId: null,\n parentManifestHash: null,\n referencedPrincipalHeads: input.body.referencedPrincipalHeads,\n },\n );\n const keyEpoch = buildContainerCreateKeyEpoch({\n containerId: input.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n eventHash,\n manifestHash,\n parentContainerKeyEpochId: null,\n });\n return { event, eventHash, keyEpoch, manifest, manifestHash, state };\n}\n\nasync function wrapRootContainerKeyForPlan(input: {\n adminGroup: CreateOrganizationGroupRequest | null;\n containerKey: Uint8Array;\n containerKeyEpochId: string;\n manifestHash: string;\n managedPrincipalHead: ContainerGrantPrincipalHead | null;\n recipientEncapsulationPublicKey: Uint8Array;\n userId: string;\n}) {\n if (input.adminGroup && input.managedPrincipalHead) {\n return {\n ...(await wrapContainerKeyToManagedPrincipal({\n containerKey: input.containerKey,\n containerKeyEpochId: input.containerKeyEpochId,\n manifestHash: input.manifestHash,\n principalEncapsulationPublicKey:\n input.adminGroup.initialGroupPolicy.state.encapsulationPublicKey,\n principalHead: input.managedPrincipalHead,\n })),\n userRecipientKey: null,\n };\n }\n\n return wrapContainerKeyToRootUser({\n containerKey: input.containerKey,\n containerKeyEpochId: input.containerKeyEpochId,\n manifestHash: input.manifestHash,\n recipientEncapsulationPublicKey: input.recipientEncapsulationPublicKey,\n userId: input.userId,\n });\n}\n\nasync function wrapRootContainerRecipients(\n input: Parameters<typeof wrapRootContainerKeyForPlan>[0] & {\n memberGroup: CreateOrganizationGroupRequest | null;\n memberHead: ContainerGrantPrincipalHead | null;\n },\n) {\n const root = await wrapRootContainerKeyForPlan(input);\n const member =\n input.memberGroup && input.memberHead\n ? await wrapContainerKeyToManagedPrincipal({\n ...input,\n principalEncapsulationPublicKey:\n input.memberGroup.initialGroupPolicy.state.encapsulationPublicKey,\n principalHead: input.memberHead,\n })\n : null;\n return {\n recipientTargets: [\n root.recipientTarget,\n ...(member ? [member.recipientTarget] : []),\n ],\n wraps: [root.wrap, ...(member ? [member.wrap] : [])],\n userRecipientKeys: root.userRecipientKey ? [root.userRecipientKey] : [],\n };\n}\n\nfunction rootKeyMaterial(key?: Uint8Array): Uint8Array {\n const material = key ?? crypto.getRandomValues(new Uint8Array(32));\n if (material.byteLength !== 32)\n throw new Error(\"Container KEK material must be 32 bytes\");\n return material;\n}\n\nfunction normalizedRootCreateBody(\n input: Parameters<typeof buildRootContainerCreateBody>[0],\n): ContainerCreateAccessEventBody {\n const body = normalizeContainerAccessEventBody(\n readCanonicalJson(buildRootContainerCreateBody(input), \"Root create body\"),\n );\n if (body.eventType !== \"container.create\")\n throw new Error(\"Expected root creation body\");\n return body;\n}\n\nexport async function buildRootContainerCreatePlan(input: {\n adminGroup?: CreateOrganizationGroupRequest | undefined;\n memberGroup?: CreateOrganizationGroupRequest | undefined;\n systemSlot?: ContainerSystemSlot | undefined;\n author: ContainerMutationAuthor;\n containerId: string;\n containerKey?: Uint8Array | undefined;\n metadataDocumentId: string;\n recipientEncapsulationPublicKey: Uint8Array;\n signedAt?: string | undefined;\n}): Promise<MaterializedContainerCreatePlan> {\n const containerKey = rootKeyMaterial(input.containerKey);\n const adminGroup = input.adminGroup ?? null;\n const { managedPrincipalHead, managedPrincipalPolicies } =\n await buildRootManagedPrincipalContext(adminGroup);\n\n const member = await buildRootManagedPrincipalContext(\n input.memberGroup ?? null,\n );\n if (input.memberGroup && !adminGroup)\n throw new Error(\"Members root grant requires Admins authority\");\n managedPrincipalPolicies.push(...member.managedPrincipalPolicies);\n const containerKeyEpochId = await resolveContainerKekEpochId({\n containerId: input.containerId,\n keyEpoch: 1,\n keyMaterial: containerKey,\n });\n const body = normalizedRootCreateBody({\n containerKeyPublicKey: await deriveContainerKekWrappingPublicKey({\n containerId: input.containerId,\n keyMaterial: containerKey,\n }),\n memberHead: member.managedPrincipalHead,\n systemSlot: input.systemSlot ?? null,\n author: input.author,\n containerKeyEpochId,\n managedPrincipalHead,\n metadataDocumentId: input.metadataDocumentId,\n });\n const { event, eventHash, keyEpoch, manifest, manifestHash, state } =\n await deriveRootCreateArtifacts({\n author: input.author,\n body,\n containerId: input.containerId,\n containerKeyEpochId,\n metadataDocumentId: input.metadataDocumentId,\n signedAt: input.signedAt,\n });\n const { recipientTargets, wraps, userRecipientKeys } =\n await wrapRootContainerRecipients({\n memberGroup: input.memberGroup ?? null,\n memberHead: member.managedPrincipalHead,\n adminGroup,\n containerKey,\n containerKeyEpochId,\n manifestHash,\n managedPrincipalHead,\n recipientEncapsulationPublicKey: input.recipientEncapsulationPublicKey,\n userId: input.author.signerUserId,\n });\n const keyTargetHash =\n await computeContainerKekRecipientTargetHash(recipientTargets);\n const keyEpochHash = await computeContainerKeyEpochHash(keyEpoch);\n const plan: ContainerCreatePlan = {\n body,\n containerId: input.containerId,\n containerKeyEpochId,\n event,\n eventHash,\n keyEpoch,\n keyEpochHash,\n keyTargetHash,\n manifest,\n manifestHash,\n metadataDocumentId: input.metadataDocumentId,\n parentContainerId: null,\n parentManifestHash: null,\n recipientTargets,\n request: buildRootContainerCreateRequest({\n body,\n event,\n keyEpoch,\n manifest,\n manifestHash,\n principalPolicies: managedPrincipalPolicies,\n userRecipientKeys,\n wraps,\n }),\n state,\n wraps,\n };\n\n return { containerKey, plan };\n}\n\nexport function rootContainerWriterProjectionFromCreatePlan(\n plan: ContainerCreatePlan,\n): ContainerWriterProjectionResponse {\n return {\n policyEvidence: {\n organization: null,\n organizationPayloads: [],\n groups: [],\n },\n containerId: plan.containerId,\n organizationId: plan.state.organizationId,\n path: [\n {\n event: {\n event: readCanonicalRecord(plan.event, \"Container root event\"),\n body: readCanonicalRecord(plan.body, \"Container root body\"),\n eventHash: plan.eventHash,\n },\n manifest: readCanonicalRecord(plan.manifest, \"Container root manifest\"),\n manifestHash: plan.manifestHash,\n state: readCanonicalRecord(plan.state, \"Container root state\"),\n },\n ],\n containerKeks: [\n {\n containerId: plan.containerId,\n accessManifestHash: plan.manifestHash,\n containerKeyEpochId: plan.containerKeyEpochId,\n containerKeyEpoch: plan.keyEpoch.keyEpoch,\n keyEpoch: readCanonicalRecord(\n plan.keyEpoch,\n \"Container root key epoch\",\n ),\n keyEpochHash: plan.keyEpochHash,\n keyTargetHash: plan.keyTargetHash,\n containerManifestHistory: [],\n parentContainerKeyEpochId: null,\n keyring: null,\n recipientTargets: readCanonicalRecords(\n plan.recipientTargets,\n \"Container root recipient targets\",\n ),\n wraps: readCanonicalRecords(plan.wraps, \"Container root wraps\"),\n },\n ],\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["create.ts"],"names":[],"mappings":"AASA,OAAO,EACL,sCAAsC,EACtC,4BAA4B,EAC5B,mCAAmC,EACnC,iCAAiC,GAClC,MAAM,mBAAmB,CAAC;AAO3B,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,6BAA6B,EAC7B,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,kCAAkC,EAClC,0BAA0B,GAC3B,MAAM,4CAA4C,CAAC;AAMpD,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EACL,mCAAmC,EACnC,2CAA2C,GAC5C,MA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IAAI,CAAC,SAAS;iBAC1B;gBACD,QAAQ,EAAE,mBAAmB,CAAC,IAAI,CAAC,QAAQ,EAAE,yBAAyB,CAAC;gBACvE,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,KAAK,EAAE,mBAAmB,CAAC,IAAI,CAAC,KAAK,EAAE,sBAAsB,CAAC;aAC/D;SACF;QACD,aAAa,EAAE;YACb;gBACE,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,kBAAkB,EAAE,IAAI,CAAC,YAAY;gBACrC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;gBAC7C,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ;gBACzC,QAAQ,EAAE,mBAAmB,CAC3B,IAAI,CAAC,QAAQ,EACb,0BAA0B,CAC3B;gBACD,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,aAAa,EAAE,IAAI,CAAC,aAAa;gBACjC,wBAAwB,EAAE,EAAE;gBAC5B,yBAAyB,EAAE,IAAI;gBAC/B,OAAO,EAAE,IAAI;gBACb,gBAAgB,EAAE,oBAAoB,CACpC,IAAI,CAAC,gBAAgB,EACrB,kCAAkC,CACnC;gBACD,KAAK,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,sBAAsB,CAAC;aAChE;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n AccessEvent,\n AccessManifest,\n ContainerCreateAccessEventBody,\n ContainerGrantPrincipalHead,\n ContainerKeyEpoch,\n ContainerKeyWrap,\n ContainerUserRecipientKey,\n} from \"@tearleads/crypto\";\nimport {\n computeContainerKekRecipientTargetHash,\n computeContainerKeyEpochHash,\n deriveContainerKekWrappingPublicKey,\n normalizeContainerAccessEventBody,\n} from \"@tearleads/crypto\";\nimport type { ContainerSystemSlot } from \"@tearleads/validators/containerSystemSlot\";\nimport type {\n ContainerMutationRequest,\n CreateOrganizationGroupRequest,\n} from \"@tearleads/validators/request\";\nimport type { ContainerWriterProjectionResponse } from \"@tearleads/validators/response\";\nimport {\n buildContainerCreateBody,\n buildContainerCreateKeyEpoch,\n deriveContainerCreateManifest,\n resolveContainerKekEpochId,\n signContainerCreateEvent,\n} from \"../../../data/containers/shared/events\";\nimport {\n wrapContainerKeyToManagedPrincipal,\n wrapContainerKeyToRootUser,\n} from \"../../../data/containers/shared/projection\";\nimport type {\n ContainerCreatePlan,\n ContainerMutationAuthor,\n MaterializedContainerCreatePlan,\n} from \"../../../data/containers/shared/types\";\nimport {\n readCanonicalJson,\n readCanonicalRecord,\n readCanonicalRecords,\n} from \"../../../data/keyingCanonicalJson\";\n\nimport {\n principalHeadFromInitialGroupPolicy,\n principalPolicyRecordFromInitialGroupPolicy,\n} from \"./initialGroupPolicy\";\n\nfunction buildRootContainerCreateBody(input: {\n author: ContainerMutationAuthor;\n managedPrincipalHead: ContainerGrantPrincipalHead | null;\n containerKeyEpochId: string;\n containerKeyPublicKey: string;\n metadataDocumentId: string;\n memberHead: ContainerGrantPrincipalHead | null;\n systemSlot: ContainerSystemSlot | null;\n}): ContainerCreateAccessEventBody {\n const baseBody = buildContainerCreateBody({\n systemSlot: input.systemSlot,\n containerKeyEpochId: input.containerKeyEpochId,\n containerKeyPublicKey: input.containerKeyPublicKey,\n metadataDocumentId: input.metadataDocumentId,\n parentContainerId: null,\n parentManifestHash: null,\n });\n if (input.managedPrincipalHead) {\n return {\n ...baseBody,\n directGrants: [\n {\n accessLevel: \"admin\",\n subjectId: input.managedPrincipalHead.principalId,\n subjectType: input.managedPrincipalHead.principalType,\n },\n ...(input.memberHead\n ? [\n {\n accessLevel: \"read\" as const,\n subjectId: input.memberHead.principalId,\n subjectType: \"group\" as const,\n },\n ]\n : []),\n ],\n referencedPrincipalHeads: [\n input.managedPrincipalHead,\n ...(input.memberHead ? [input.memberHead] : []),\n ],\n };\n }\n\n return {\n ...baseBody,\n directGrants: [\n {\n accessLevel: \"admin\",\n subjectId: input.author.signerUserId,\n subjectType: \"user\",\n },\n ],\n };\n}\n\nfunction buildRootContainerCreateRequest(input: {\n body: ContainerCreateAccessEventBody;\n event: AccessEvent;\n keyEpoch: ContainerKeyEpoch;\n manifest: AccessManifest;\n manifestHash: string;\n principalPolicies: readonly Record<string, unknown>[];\n userRecipientKeys: readonly ContainerUserRecipientKey[];\n wraps: readonly ContainerKeyWrap[];\n}): ContainerMutationRequest {\n return {\n event: readCanonicalRecord(input.event, \"Container root create event\"),\n body: readCanonicalRecord(input.body, \"Container root create body\"),\n expectedManifestHash: input.manifestHash,\n manifest: readCanonicalRecord(\n input.manifest,\n \"Container root create manifest\",\n ),\n previousManifestRef: null,\n parentContainerPathRefs: [],\n principalPolicies: readCanonicalRecords(\n input.principalPolicies,\n \"Container root create principal policies\",\n ),\n keyEpoch: readCanonicalRecord(\n input.keyEpoch,\n \"Container root create key epoch\",\n ),\n predecessorBridge: null,\n keyring: null,\n wraps: readCanonicalRecords(input.wraps, \"Container root create wraps\"),\n userRecipientKeys: readCanonicalRecords(\n input.userRecipientKeys,\n \"Container root create user recipient keys\",\n ),\n };\n}\n\nasync function buildRootManagedPrincipalContext(\n adminGroup: CreateOrganizationGroupRequest | null,\n): Promise<{\n managedPrincipalHead: ContainerGrantPrincipalHead | null;\n managedPrincipalPolicies: Record<string, unknown>[];\n}> {\n if (!adminGroup) {\n return {\n managedPrincipalHead: null,\n managedPrincipalPolicies: [],\n };\n }\n\n const managedPrincipalHead = await principalHeadFromInitialGroupPolicy({\n principalId: adminGroup.groupId,\n policy: adminGroup.initialGroupPolicy,\n });\n\n return {\n managedPrincipalHead,\n managedPrincipalPolicies: [\n principalPolicyRecordFromInitialGroupPolicy({\n head: managedPrincipalHead,\n policy: adminGroup.initialGroupPolicy,\n }),\n ],\n };\n}\n\nasync function deriveRootCreateArtifacts(input: {\n author: ContainerMutationAuthor;\n body: ContainerCreateAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n metadataDocumentId: string;\n signedAt: string | undefined;\n}) {\n if (!input.body.containerKeyPublicKey)\n throw new Error(\"Root container public key is missing\");\n const { event, eventHash } = await signContainerCreateEvent({\n author: input.author,\n body: input.body,\n containerId: input.containerId,\n eventId: crypto.randomUUID(),\n // A root container belongs to the creator's own organization.\n organizationId: input.author.organizationId,\n parentPath: [],\n signedAt: input.signedAt ?? new Date().toISOString(),\n });\n const { manifest, manifestHash, state } = await deriveContainerCreateManifest(\n {\n systemSlot: input.body.systemSlot,\n containerId: input.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n containerKeyPublicKey: input.body.containerKeyPublicKey,\n directGrants: input.body.directGrants,\n eventHash,\n metadataDocumentId: input.metadataDocumentId,\n // A root container belongs to the creator's own organization.\n organizationId: input.author.organizationId,\n parentContainerId: null,\n parentManifestHash: null,\n referencedPrincipalHeads: input.body.referencedPrincipalHeads,\n },\n );\n const keyEpoch = buildContainerCreateKeyEpoch({\n containerId: input.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n eventHash,\n manifestHash,\n parentContainerKeyEpochId: null,\n });\n return { event, eventHash, keyEpoch, manifest, manifestHash, state };\n}\n\nasync function wrapRootContainerKeyForPlan(input: {\n adminGroup: CreateOrganizationGroupRequest | null;\n containerKey: Uint8Array;\n containerKeyEpochId: string;\n manifestHash: string;\n managedPrincipalHead: ContainerGrantPrincipalHead | null;\n recipientEncapsulationPublicKey: Uint8Array;\n userId: string;\n}) {\n if (input.adminGroup && input.managedPrincipalHead) {\n return {\n ...(await wrapContainerKeyToManagedPrincipal({\n containerKey: input.containerKey,\n containerKeyEpochId: input.containerKeyEpochId,\n manifestHash: input.manifestHash,\n principalEncapsulationPublicKey:\n input.adminGroup.initialGroupPolicy.state.encapsulationPublicKey,\n principalHead: input.managedPrincipalHead,\n })),\n userRecipientKey: null,\n };\n }\n\n return wrapContainerKeyToRootUser({\n containerKey: input.containerKey,\n containerKeyEpochId: input.containerKeyEpochId,\n manifestHash: input.manifestHash,\n recipientEncapsulationPublicKey: input.recipientEncapsulationPublicKey,\n userId: input.userId,\n });\n}\n\nasync function wrapRootContainerRecipients(\n input: Parameters<typeof wrapRootContainerKeyForPlan>[0] & {\n memberGroup: CreateOrganizationGroupRequest | null;\n memberHead: ContainerGrantPrincipalHead | null;\n },\n) {\n const root = await wrapRootContainerKeyForPlan(input);\n const member =\n input.memberGroup && input.memberHead\n ? await wrapContainerKeyToManagedPrincipal({\n ...input,\n principalEncapsulationPublicKey:\n input.memberGroup.initialGroupPolicy.state.encapsulationPublicKey,\n principalHead: input.memberHead,\n })\n : null;\n return {\n recipientTargets: [\n root.recipientTarget,\n ...(member ? [member.recipientTarget] : []),\n ],\n wraps: [root.wrap, ...(member ? [member.wrap] : [])],\n userRecipientKeys: root.userRecipientKey ? [root.userRecipientKey] : [],\n };\n}\n\nfunction rootKeyMaterial(key?: Uint8Array): Uint8Array {\n const material = key ?? crypto.getRandomValues(new Uint8Array(32));\n if (material.byteLength !== 32)\n throw new Error(\"Container KEK material must be 32 bytes\");\n return material;\n}\n\nfunction normalizedRootCreateBody(\n input: Parameters<typeof buildRootContainerCreateBody>[0],\n): ContainerCreateAccessEventBody {\n const body = normalizeContainerAccessEventBody(\n readCanonicalJson(buildRootContainerCreateBody(input), \"Root create body\"),\n );\n if (body.eventType !== \"container.create\")\n throw new Error(\"Expected root creation body\");\n return body;\n}\n\nexport async function buildRootContainerCreatePlan(input: {\n adminGroup?: CreateOrganizationGroupRequest | undefined;\n memberGroup?: CreateOrganizationGroupRequest | undefined;\n systemSlot?: ContainerSystemSlot | undefined;\n author: ContainerMutationAuthor;\n containerId: string;\n containerKey?: Uint8Array | undefined;\n metadataDocumentId: string;\n recipientEncapsulationPublicKey: Uint8Array;\n signedAt?: string | undefined;\n}): Promise<MaterializedContainerCreatePlan> {\n const containerKey = rootKeyMaterial(input.containerKey);\n const adminGroup = input.adminGroup ?? null;\n const { managedPrincipalHead, managedPrincipalPolicies } =\n await buildRootManagedPrincipalContext(adminGroup);\n\n const member = await buildRootManagedPrincipalContext(\n input.memberGroup ?? null,\n );\n if (input.memberGroup && !adminGroup)\n throw new Error(\"Members root grant requires Admins authority\");\n managedPrincipalPolicies.push(...member.managedPrincipalPolicies);\n const containerKeyEpochId = await resolveContainerKekEpochId({\n containerId: input.containerId,\n keyEpoch: 1,\n keyMaterial: containerKey,\n });\n const body = normalizedRootCreateBody({\n containerKeyPublicKey: await deriveContainerKekWrappingPublicKey({\n containerId: input.containerId,\n keyMaterial: containerKey,\n }),\n memberHead: member.managedPrincipalHead,\n systemSlot: input.systemSlot ?? null,\n author: input.author,\n containerKeyEpochId,\n managedPrincipalHead,\n metadataDocumentId: input.metadataDocumentId,\n });\n const { event, eventHash, keyEpoch, manifest, manifestHash, state } =\n await deriveRootCreateArtifacts({\n author: input.author,\n body,\n containerId: input.containerId,\n containerKeyEpochId,\n metadataDocumentId: input.metadataDocumentId,\n signedAt: input.signedAt,\n });\n const { recipientTargets, wraps, userRecipientKeys } =\n await wrapRootContainerRecipients({\n memberGroup: input.memberGroup ?? null,\n memberHead: member.managedPrincipalHead,\n adminGroup,\n containerKey,\n containerKeyEpochId,\n manifestHash,\n managedPrincipalHead,\n recipientEncapsulationPublicKey: input.recipientEncapsulationPublicKey,\n userId: input.author.signerUserId,\n });\n const keyTargetHash =\n await computeContainerKekRecipientTargetHash(recipientTargets);\n const keyEpochHash = await computeContainerKeyEpochHash(keyEpoch);\n const plan: ContainerCreatePlan = {\n body,\n containerId: input.containerId,\n containerKeyEpochId,\n event,\n eventHash,\n keyEpoch,\n keyEpochHash,\n keyTargetHash,\n manifest,\n manifestHash,\n metadataDocumentId: input.metadataDocumentId,\n parentContainerId: null,\n parentManifestHash: null,\n recipientTargets,\n request: buildRootContainerCreateRequest({\n body,\n event,\n keyEpoch,\n manifest,\n manifestHash,\n principalPolicies: managedPrincipalPolicies,\n userRecipientKeys,\n wraps,\n }),\n state,\n wraps,\n };\n\n return { containerKey, plan };\n}\n\nexport function rootContainerWriterProjectionFromCreatePlan(\n plan: ContainerCreatePlan,\n): ContainerWriterProjectionResponse {\n return {\n policyEvidence: {\n organization: null,\n organizationPayloads: [],\n groups: [],\n },\n containerId: plan.containerId,\n organizationId: plan.state.organizationId,\n path: [\n {\n event: {\n event: readCanonicalRecord(plan.event, \"Container root event\"),\n body: readCanonicalRecord(plan.body, \"Container root body\"),\n eventHash: plan.eventHash,\n },\n manifest: readCanonicalRecord(plan.manifest, \"Container root manifest\"),\n manifestHash: plan.manifestHash,\n state: readCanonicalRecord(plan.state, \"Container root state\"),\n },\n ],\n containerKeks: [\n {\n containerId: plan.containerId,\n accessManifestHash: plan.manifestHash,\n containerKeyEpochId: plan.containerKeyEpochId,\n containerKeyEpoch: plan.keyEpoch.keyEpoch,\n keyEpoch: readCanonicalRecord(\n plan.keyEpoch,\n \"Container root key epoch\",\n ),\n keyEpochHash: plan.keyEpochHash,\n keyTargetHash: plan.keyTargetHash,\n containerManifestHistory: [],\n parentContainerKeyEpochId: null,\n keyring: null,\n recipientTargets: readCanonicalRecords(\n plan.recipientTargets,\n \"Container root recipient targets\",\n ),\n wraps: readCanonicalRecords(plan.wraps, \"Container root wraps\"),\n },\n ],\n };\n}\n"]}
|
|
@@ -149,11 +149,6 @@ export declare function buildInitialRootProvisioning(input: {
|
|
|
149
149
|
manifestHash: string;
|
|
150
150
|
state: Record<string, unknown>;
|
|
151
151
|
}[];
|
|
152
|
-
historyPrefixes?: {
|
|
153
|
-
key: string;
|
|
154
|
-
count: number;
|
|
155
|
-
digest: string;
|
|
156
|
-
}[] | undefined;
|
|
157
152
|
};
|
|
158
153
|
rootMetadataDocument: import("../../data/documents/shared/types.js").MaterializedDocumentCreatePlan;
|
|
159
154
|
rootMetadataDocumentRequest: {
|
|
@@ -188,36 +183,26 @@ export declare function buildInitialRootProvisioning(input: {
|
|
|
188
183
|
predecessorBridge: Record<string, unknown> | null;
|
|
189
184
|
principalPolicies: Record<string, unknown>[];
|
|
190
185
|
wraps: Record<string, unknown>[];
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
manifest: Record<string, unknown>;
|
|
186
|
+
containerManifestHistoryRefs?: {
|
|
187
|
+
containerId: string;
|
|
194
188
|
manifestHash: string;
|
|
195
|
-
state: Record<string, unknown>;
|
|
196
189
|
}[] | undefined;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
manifest: Record<string, unknown>;
|
|
190
|
+
destinationParentContainerPathRefs?: {
|
|
191
|
+
containerId: string;
|
|
200
192
|
manifestHash: string;
|
|
201
|
-
state: Record<string, unknown>;
|
|
202
193
|
}[] | undefined;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
manifest: Record<string, unknown>;
|
|
194
|
+
parentContainerPathRefs?: {
|
|
195
|
+
containerId: string;
|
|
206
196
|
manifestHash: string;
|
|
207
|
-
state: Record<string, unknown>;
|
|
208
197
|
}[] | undefined;
|
|
209
198
|
parentKekState?: Record<string, unknown> | null | undefined;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
manifest: Record<string, unknown>;
|
|
199
|
+
previousContainerPathRefs?: {
|
|
200
|
+
containerId: string;
|
|
213
201
|
manifestHash: string;
|
|
214
|
-
state: Record<string, unknown>;
|
|
215
202
|
}[] | undefined;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
manifest: Record<string, unknown>;
|
|
203
|
+
previousManifestRef?: {
|
|
204
|
+
containerId: string;
|
|
219
205
|
manifestHash: string;
|
|
220
|
-
state: Record<string, unknown>;
|
|
221
206
|
} | null | undefined;
|
|
222
207
|
userRecipientKeys?: Record<string, unknown>[] | undefined;
|
|
223
208
|
}[] | undefined;
|
|
@@ -270,45 +255,29 @@ export declare function buildInitialRootProvisioning(input: {
|
|
|
270
255
|
predecessorBridge: Record<string, unknown> | null;
|
|
271
256
|
principalPolicies: Record<string, unknown>[];
|
|
272
257
|
wraps: Record<string, unknown>[];
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
manifest: Record<string, unknown>;
|
|
258
|
+
containerManifestHistoryRefs?: {
|
|
259
|
+
containerId: string;
|
|
276
260
|
manifestHash: string;
|
|
277
|
-
state: Record<string, unknown>;
|
|
278
261
|
}[] | undefined;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
manifest: Record<string, unknown>;
|
|
262
|
+
destinationParentContainerPathRefs?: {
|
|
263
|
+
containerId: string;
|
|
282
264
|
manifestHash: string;
|
|
283
|
-
state: Record<string, unknown>;
|
|
284
265
|
}[] | undefined;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
manifest: Record<string, unknown>;
|
|
266
|
+
parentContainerPathRefs?: {
|
|
267
|
+
containerId: string;
|
|
288
268
|
manifestHash: string;
|
|
289
|
-
state: Record<string, unknown>;
|
|
290
269
|
}[] | undefined;
|
|
291
270
|
parentKekState?: Record<string, unknown> | null | undefined;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
manifest: Record<string, unknown>;
|
|
271
|
+
previousContainerPathRefs?: {
|
|
272
|
+
containerId: string;
|
|
295
273
|
manifestHash: string;
|
|
296
|
-
state: Record<string, unknown>;
|
|
297
274
|
}[] | undefined;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
manifest: Record<string, unknown>;
|
|
275
|
+
previousManifestRef?: {
|
|
276
|
+
containerId: string;
|
|
301
277
|
manifestHash: string;
|
|
302
|
-
state: Record<string, unknown>;
|
|
303
278
|
} | null | undefined;
|
|
304
279
|
userRecipientKeys?: Record<string, unknown>[] | undefined;
|
|
305
280
|
}[] | undefined;
|
|
306
|
-
previousManifest?: {
|
|
307
|
-
event: Record<string, unknown>;
|
|
308
|
-
manifest: Record<string, unknown>;
|
|
309
|
-
manifestHash: string;
|
|
310
|
-
state: Record<string, unknown>;
|
|
311
|
-
} | null | undefined;
|
|
312
281
|
targetContainerPathRefs?: {
|
|
313
282
|
containerId: string;
|
|
314
283
|
manifestHash: string;
|
|
@@ -2,12 +2,14 @@ import { and, eq, inArray, or } from "drizzle-orm";
|
|
|
2
2
|
import { recordSupersededContainerBindingsInTransaction } from "../../data/persistence/container-contents/supersededContainerBindings.js";
|
|
3
3
|
import { deleteDocumentPlacementRowsByContainerIds, deleteDocumentPlacementRowsByDocumentIds, } from "../../data/persistence/containers/documentContainerProjectionPersistence.js";
|
|
4
4
|
import { clearDocumentDiscoveryEvidenceOnRemoteReset } from "../../data/persistence/documents/documentDiscoveryReset.js";
|
|
5
|
+
import { queuedUpdateRow, unqueueDocumentScopesInTransaction, } from "../../data/sqlite/documentPendingUpdatePersistence.js";
|
|
5
6
|
import { documentIntentLinkTargets } from "../../data/sqlite/documentPlacementIntentSchema.js";
|
|
6
7
|
import { organizationDataUsageCategories, organizationDataUsageSnapshots, } from "../../data/sqlite/organizationDataUsageSchema.js";
|
|
7
8
|
import { organizationPresentationDenials, organizationReadModelContainerGrants, organizationReadModelDirectoryUsers, organizationReadModelGroupMembers, organizationReadModelGroups, organizationReadModelRequesters, organizationReadModelState, } from "../../data/sqlite/organizationReadModelSchema.js";
|
|
8
|
-
import { clientSqlTables, containerCreateIntents, containerHydrationTombstones, containerMoveIntents, containers, documentAttachmentBlobProjection, documentMoveIntents, documentPendingAttachments,
|
|
9
|
+
import { clientSqlTables, containerCreateIntents, containerHydrationTombstones, containerMoveIntents, containers, documentAttachmentBlobProjection, documentHistoryUpdates, documentMoveIntents, documentPendingAttachments, documentProjection, documentSyncFailures, documents, dormantContainerMetadata, dormantMetadataSweepRequests, } from "../../data/sqlite/schema.js";
|
|
9
10
|
import { getClientSQLitePersistenceRuntime, } from "../../data/sqlite/sqlitePersistenceRuntime.js";
|
|
10
11
|
import { ensureSqlTables } from "../../data/sqlite/sqlTableSchema.js";
|
|
12
|
+
import { verifiedAccessManifestBundles } from "../../data/sqlite/verifiedManifestBundleSchema.js";
|
|
11
13
|
import { runOrganizationPresentationReset } from "../organizations/organizationPresentationAccessState.js";
|
|
12
14
|
import { clearResetPendingAttachments } from "./remoteResetAttachments.js";
|
|
13
15
|
import { remoteResetBatches } from "./remoteResetBatches.js";
|
|
@@ -75,10 +77,7 @@ async function clearScopedDocumentRows(input) {
|
|
|
75
77
|
.run();
|
|
76
78
|
}
|
|
77
79
|
for (const documentBatch of remoteResetBatches(snapshot.documentRows)) {
|
|
78
|
-
await tx
|
|
79
|
-
.delete(documentPendingUpdates)
|
|
80
|
-
.where(or(...documentBatch.map((row) => and(eq(documentPendingUpdates.appKind, row.appKind), eq(documentPendingUpdates.localId, row.localId)))))
|
|
81
|
-
.run();
|
|
80
|
+
await unqueueDocumentScopesInTransaction(tx, documentBatch);
|
|
82
81
|
await tx
|
|
83
82
|
.delete(documentSyncFailures)
|
|
84
83
|
.where(or(...documentBatch.map((row) => and(eq(documentSyncFailures.appKind, row.appKind), eq(documentSyncFailures.localId, row.localId)))))
|
|
@@ -91,6 +90,7 @@ async function clearScopedRemoteRows(input) {
|
|
|
91
90
|
for (const table of [
|
|
92
91
|
dormantContainerMetadata,
|
|
93
92
|
dormantMetadataSweepRequests,
|
|
93
|
+
verifiedAccessManifestBundles,
|
|
94
94
|
]) {
|
|
95
95
|
await tx
|
|
96
96
|
.delete(table)
|
|
@@ -171,11 +171,13 @@ async function resetRemoteColumns(input) {
|
|
|
171
171
|
async function queueResetDocumentUpdates(input) {
|
|
172
172
|
for (const updateBatch of remoteResetBatches(input.documentUpdates)) {
|
|
173
173
|
await input.tx
|
|
174
|
-
.insert(
|
|
175
|
-
.values(updateBatch.map((update) => ({
|
|
176
|
-
...update,
|
|
177
|
-
id: crypto.randomUUID(),
|
|
174
|
+
.insert(documentHistoryUpdates)
|
|
175
|
+
.values(updateBatch.map((update) => queuedUpdateRow({
|
|
178
176
|
createdAt: input.now,
|
|
177
|
+
origin: "outbox",
|
|
178
|
+
pendingUpdate: update,
|
|
179
|
+
scope: update,
|
|
180
|
+
updateId: crypto.randomUUID(),
|
|
179
181
|
})))
|
|
180
182
|
.run();
|
|
181
183
|
}
|