@tearleads/client-sdk 0.1.239 → 0.1.241
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/data/documents/shared/sync/syncResponseAuthorization.js +12 -1
- package/data/documents/shared/sync/syncResponseAuthorization.js.map +1 -1
- package/data/documents/shared/sync/syncResponses.js +2 -2
- package/data/documents/shared/sync/syncResponses.js.map +1 -1
- package/data/documents/shared/types.d.ts +5 -1
- package/data/documents/shared/types.js.map +1 -1
- package/data/persistence/documents/documentAttachmentPresence.js +44 -0
- package/data/persistence/documents/documentAttachmentPresence.js.map +1 -0
- package/internal/api-client/ApiClient.d.ts +7 -7
- package/internal/api-client/client/apiClientContext.d.ts +1 -1
- package/internal/api-client/client/blobs.d.ts +1 -1
- package/internal/api-client/client/documents.d.ts +6 -6
- package/internal/validators/operation/attachments.d.ts +2 -2
- package/internal/validators/operation/containerMutations.d.ts +16 -16
- package/internal/validators/operation/documentMutations.d.ts +20 -20
- package/internal/validators/operation/documentSync.d.ts +24 -24
- package/internal/validators/response/blob.d.ts +6 -6
- package/internal/validators/response/blob.js +12 -2
- package/internal/validators/response/blob.js.map +1 -1
- package/internal/validators/response/containerMutationError.d.ts +2 -2
- package/internal/validators/response/documentMutationError.d.ts +3 -2
- package/internal/validators/response/documentMutationError.js +5 -0
- package/internal/validators/response/documentMutationError.js.map +1 -1
- package/internal/validators/response/documentSyncSchema.d.ts +48 -48
- package/internal/validators/response/documentSyncSchema.js +1 -1
- package/internal/validators/response/documentSyncSchema.js.map +1 -1
- package/package.json +1 -1
- package/workflows/blobs/hydration/decrypt.js +17 -1
- package/workflows/blobs/hydration/decrypt.js.map +1 -1
- package/workflows/documents/linkSet/linkSetBlobRewraps.d.ts +10 -4
- package/workflows/documents/linkSet/linkSetBlobRewraps.js +23 -11
- package/workflows/documents/linkSet/linkSetBlobRewraps.js.map +1 -1
- package/workflows/documents/linkSet/linkSetLegMachine.js +74 -0
- package/workflows/documents/linkSet/linkSetLegMachine.js.map +1 -0
- package/workflows/documents/linkSet/linkSetRemote.d.ts +4 -4
- package/workflows/documents/linkSet/linkSetRemote.js +96 -52
- package/workflows/documents/linkSet/linkSetRemote.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.js","sourceRoot":"","sources":["blob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAEtE,MAAM,CAAC,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;IAC3D,UAAU,EAAE,qBAAqB;IACjC,IAAI,EAAE,oBAAoB;IAC1B,UAAU,EAAE,qBAAqB;CAClC,CAAC,CAAC;AAMH,MAAM,CAAC,MAAM,wCAAwC,GAAG,gBAAgB,CAAC;IACvE,cAAc,EAAE,oBAAoB;IACpC,UAAU,EAAE,qBAAqB;IACjC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,gEAAgE;IAChE,WAAW,EAAE,WAAW,CAAC,6BAA6B,CAAC;IACvD,MAAM,EAAE,oBAAoB;IAC5B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,aAAa,EAAE,WAAW,CAAC,4BAA4B,CAAC;IACxD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CAAC;AAMH,MAAM,CAAC,MAAM,sCAAsC,GAAG,gBAAgB,CAAC;IACrE,cAAc,EAAE,oBAAoB;IACpC,UAAU,EAAE,qBAAqB;IACjC,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;IACtB,SAAS,EA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E,CAAC,CAAC,MAAM,EAAE;IACtB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAMH,MAAM,UAAU,oCAAoC,CAClD,KAAc;IAEd,OAAO,wCAAwC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,kCAAkC,CAChD,KAAc;IAEd,OAAO,sCAAsC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,KAAc;IAEd,OAAO,gCAAgC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,KAAc;IAEd,OAAO,kCAAkC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACrE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport { AccessEventBundleWireResponseSchema } from \"../util\";\nimport { MultipartBlobPartUploadSchema } from \"../util/blobTransferSchemas\";\nimport { DocumentCreateSeedResponseSchema } from \"./documentMutation\";\n\nexport const MultipartBlobStagePartSchema = loosePlainObject({\n byteLength: positiveIntegerSchema,\n etag: nonEmptyStringSchema,\n partNumber: positiveIntegerSchema,\n});\n\nexport type MultipartBlobStagePart = z.infer<\n typeof MultipartBlobStagePartSchema\n>;\n\nexport const InitiateMultipartBlobStageResponseSchema = loosePlainObject({\n organizationId: nonEmptyStringSchema,\n byteLength: positiveIntegerSchema,\n expiresAt: z.string(),\n // One upload source per requested first part, in request order.\n partUploads: arraySchema(MultipartBlobPartUploadSchema),\n sha256: nonEmptyStringSchema,\n stageId: z.string(),\n uploadedParts: arraySchema(MultipartBlobStagePartSchema),\n uploadId: z.string(),\n});\n\nexport type InitiateMultipartBlobStageResponse = z.infer<\n typeof InitiateMultipartBlobStageResponseSchema\n>;\n\nexport const MultipartBlobStageStatusResponseSchema = loosePlainObject({\n organizationId: nonEmptyStringSchema,\n byteLength: positiveIntegerSchema,\n completed: z.boolean(),\n expiresAt: z.string(),\n sha256: nonEmptyStringSchema,\n stageId: z.string(),\n uploadedParts: arraySchema(MultipartBlobStagePartSchema),\n uploadId: z.string(),\n});\n\nexport type MultipartBlobStageStatusResponse = z.infer<\n typeof MultipartBlobStageStatusResponseSchema\n>;\n\nexport const UploadMultipartBlobPartResponseSchema = loosePlainObject({\n part: MultipartBlobStagePartSchema,\n stageId: z.string(),\n uploadId: z.string(),\n});\n\nexport type UploadMultipartBlobPartResponse = z.infer<\n typeof UploadMultipartBlobPartResponseSchema\n>;\n\nexport const BlobContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n bindingId: z.string(),\n containerId: z.string(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: z.string(),\n containerManifestHash: z.string(),\n documentId: z.string(),\n wrappedKey: z.string(),\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type BlobContentKeyTargetEnvelopeResponse = z.infer<\n typeof BlobContentKeyTargetEnvelopeResponseSchema\n>;\n\nexport const BlobContentKeyBundleResponseSchema = loosePlainObject({\n blobId: z.string(),\n contentKeyEpoch: positiveIntegerSchema,\n targetHash: z.string(),\n targets: arraySchema(BlobContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type BlobContentKeyBundleResponse = z.infer<\n typeof BlobContentKeyBundleResponseSchema\n>;\n\nexport const BlobKekTargetsResponseSchema = loosePlainObject({\n activeBindingIds: arraySchema(z.string()),\n blobAccessManifestHash: z.string(),\n blobId: z.string(),\n blobKeyTargetHash: z.string(),\n documentManifestHashes: arraySchema(z.string()),\n linkedContainerKeyEpochIds: arraySchema(z.string()),\n linkedContainerManifestHashes: arraySchema(z.string()),\n organizationId: z.string(),\n targets: arraySchema(plainObjectSchema),\n});\n\nexport type BlobKekTargetsResponse = z.infer<\n typeof BlobKekTargetsResponseSchema\n>;\n\nexport const BlobAttachmentSummarySchema = loosePlainObject({\n bindingEvent: AccessEventBundleWireResponseSchema,\n bindingId: z.string(),\n blobId: z.string(),\n blobKekTargets: BlobKekTargetsResponseSchema,\n contentKeyBundle: BlobContentKeyBundleResponseSchema,\n documentManifestHash: z.string(),\n previousBindingId: z.string().nullable(),\n slotId: z.string(),\n writeAuthorization: BlobKekTargetsResponseSchema,\n writeHeader: plainObjectSchema,\n});\n\nexport type BlobAttachmentSummary = z.infer<typeof BlobAttachmentSummarySchema>;\n\nexport const ListDocumentAttachmentsResponseSchema = arraySchema(\n BlobAttachmentSummarySchema,\n);\n\nexport type ListDocumentAttachmentsResponse = z.infer<\n typeof ListDocumentAttachmentsResponseSchema\n>;\n\n/**\n * A bind acknowledges by hash: the signed binding event's hash, the stored\n * content-key epoch, the verified write header's hash, and the hashes of the\n * server-resolved KEK target set and blob access manifest. It never echoes the\n * signed event, the content-key wraps, the write header, the KEK targets, or\n * the write authorization (which a staged upload's bind stores as exactly the\n * targets it wrapped to); the client compares each with what it signed.\n */\nexport const BlobAttachmentBindResponseSchema = loosePlainObject({\n bindingId: z.string(),\n blobAccessManifestHash: nonEmptyStringSchema,\n blobId: z.string(),\n blobKeyTargetHash: nonEmptyStringSchema,\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n documentManifestHash: z.string(),\n eventHash: nonEmptyStringSchema,\n previousBindingId: z.string().nullable(),\n slotId: z.string(),\n writeHeaderHash: z.string(),\n /** Present exactly when the request carried `documentSync`. */\n documentSync: DocumentCreateSeedResponseSchema.optional(),\n});\n\nexport type BlobAttachmentBindResponse = z.infer<\n typeof BlobAttachmentBindResponseSchema\n>;\n\nfunction sortedUniqueStrings(values: readonly string[]): string[] {\n return [...new Set(values)].sort((left, right) =>\n left < right ? -1 : left > right ? 1 : 0,\n );\n}\n\n/**\n * The listing entry a staged upload's bind committed, rebuilt from the\n * request it acknowledged: the bind stores exactly the signed event,\n * content-key bundle, and write header the request carried, and a staged\n * blob is new, so this binding is its only one and its KEK targets and write\n * authorization are exactly the targets the bundle wraps to. Callers must\n * first have matched the acknowledgement's hashes against that request.\n */\nexport function blobAttachmentSummaryFromStagedBind(\n request: {\n readonly body: unknown;\n readonly contentKeyBundle: {\n readonly targetHash: string;\n readonly targets: readonly BlobContentKeyTargetEnvelopeResponse[];\n };\n readonly event: Record<string, unknown>;\n readonly stagedBlob: { readonly writeHeader: Record<string, unknown> };\n },\n response: BlobAttachmentBindResponse,\n): BlobAttachmentSummary {\n const { organizationId } = request.event;\n if (typeof organizationId !== \"string\") {\n throw new Error(\"Attachment bind event organization id is invalid\");\n }\n const targets = request.contentKeyBundle.targets.map((target) => ({\n bindingId: target.bindingId,\n containerId: target.containerId,\n containerKeyEpoch: target.containerKeyEpoch,\n containerKeyEpochId: target.containerKeyEpochId,\n containerManifestHash: target.containerManifestHash,\n documentId: target.documentId,\n }));\n const blobKekTargets: BlobKekTargetsResponse = {\n activeBindingIds: [response.bindingId],\n blobAccessManifestHash: response.blobAccessManifestHash,\n blobId: response.blobId,\n blobKeyTargetHash: response.blobKeyTargetHash,\n documentManifestHashes: [response.documentManifestHash],\n linkedContainerKeyEpochIds: sortedUniqueStrings(\n targets.map((target) => target.containerKeyEpochId),\n ),\n linkedContainerManifestHashes: sortedUniqueStrings(\n targets.map((target) => target.containerManifestHash),\n ),\n organizationId,\n targets,\n };\n return {\n bindingEvent: {\n body: request.body,\n event: request.event,\n eventHash: response.eventHash,\n },\n bindingId: response.bindingId,\n blobId: response.blobId,\n blobKekTargets,\n contentKeyBundle: {\n blobId: response.blobId,\n contentKeyEpoch: response.contentKeyEpoch,\n targetHash: request.contentKeyBundle.targetHash,\n targets: [...request.contentKeyBundle.targets],\n },\n documentManifestHash: response.documentManifestHash,\n previousBindingId: response.previousBindingId,\n slotId: response.slotId,\n writeAuthorization: blobKekTargets,\n writeHeader: request.stagedBlob.writeHeader,\n };\n}\n\nexport const BlobAttachmentDetachResponseSchema = loosePlainObject({\n bindingId: z.string(),\n blobId: z.string(),\n documentId: z.string(),\n slotId: z.string(),\n});\n\nexport type BlobAttachmentDetachResponse = z.infer<\n typeof BlobAttachmentDetachResponseSchema\n>;\n\nexport function isInitiateMultipartBlobStageResponse(\n value: unknown,\n): value is InitiateMultipartBlobStageResponse {\n return InitiateMultipartBlobStageResponseSchema.safeParse(value).success;\n}\n\nexport function isMultipartBlobStageStatusResponse(\n value: unknown,\n): value is MultipartBlobStageStatusResponse {\n return MultipartBlobStageStatusResponseSchema.safeParse(value).success;\n}\n\nexport function isUploadMultipartBlobPartResponse(\n value: unknown,\n): value is UploadMultipartBlobPartResponse {\n return UploadMultipartBlobPartResponseSchema.safeParse(value).success;\n}\n\nexport function isListDocumentAttachmentsResponse(\n value: unknown,\n): value is ListDocumentAttachmentsResponse {\n return ListDocumentAttachmentsResponseSchema.safeParse(value).success;\n}\n\nexport function isBlobAttachmentBindResponse(\n value: unknown,\n): value is BlobAttachmentBindResponse {\n return BlobAttachmentBindResponseSchema.safeParse(value).success;\n}\n\nexport function isBlobAttachmentDetachResponse(\n value: unknown,\n): value is BlobAttachmentDetachResponse {\n return BlobAttachmentDetachResponseSchema.safeParse(value).success;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"blob.js","sourceRoot":"","sources":["blob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO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AO,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,kCAAkC,CAChD,KAAc;IAEd,OAAO,sCAAsC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAAc;IAEd,OAAO,qCAAqC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,KAAc;IAEd,OAAO,gCAAgC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,KAAc;IAEd,OAAO,kCAAkC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AACrE,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport { AccessEventBundleWireResponseSchema } from \"../util\";\nimport { MultipartBlobPartUploadSchema } from \"../util/blobTransferSchemas\";\nimport { DocumentCreateSeedResponseSchema } from \"./documentMutation\";\n\nexport const MultipartBlobStagePartSchema = loosePlainObject({\n byteLength: positiveIntegerSchema,\n etag: nonEmptyStringSchema,\n partNumber: positiveIntegerSchema,\n});\n\nexport type MultipartBlobStagePart = z.infer<\n typeof MultipartBlobStagePartSchema\n>;\n\nexport const InitiateMultipartBlobStageResponseSchema = loosePlainObject({\n organizationId: nonEmptyStringSchema,\n byteLength: positiveIntegerSchema,\n expiresAt: z.string(),\n // One upload source per requested first part, in request order.\n partUploads: arraySchema(MultipartBlobPartUploadSchema),\n sha256: nonEmptyStringSchema,\n stageId: z.string(),\n uploadedParts: arraySchema(MultipartBlobStagePartSchema),\n uploadId: z.string(),\n});\n\nexport type InitiateMultipartBlobStageResponse = z.infer<\n typeof InitiateMultipartBlobStageResponseSchema\n>;\n\nexport const MultipartBlobStageStatusResponseSchema = loosePlainObject({\n organizationId: nonEmptyStringSchema,\n byteLength: positiveIntegerSchema,\n completed: z.boolean(),\n expiresAt: z.string(),\n sha256: nonEmptyStringSchema,\n stageId: z.string(),\n uploadedParts: arraySchema(MultipartBlobStagePartSchema),\n uploadId: z.string(),\n});\n\nexport type MultipartBlobStageStatusResponse = z.infer<\n typeof MultipartBlobStageStatusResponseSchema\n>;\n\nexport const UploadMultipartBlobPartResponseSchema = loosePlainObject({\n part: MultipartBlobStagePartSchema,\n stageId: z.string(),\n uploadId: z.string(),\n});\n\nexport type UploadMultipartBlobPartResponse = z.infer<\n typeof UploadMultipartBlobPartResponseSchema\n>;\n\nexport const BlobContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n bindingId: z.string(),\n containerId: z.string(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: z.string(),\n containerManifestHash: z.string(),\n documentId: z.string(),\n wrappedKey: z.string(),\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type BlobContentKeyTargetEnvelopeResponse = z.infer<\n typeof BlobContentKeyTargetEnvelopeResponseSchema\n>;\n\nexport const BlobContentKeyBundleResponseSchema = loosePlainObject({\n blobId: z.string(),\n contentKeyEpoch: positiveIntegerSchema,\n targetHash: z.string(),\n targets: arraySchema(BlobContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type BlobContentKeyBundleResponse = z.infer<\n typeof BlobContentKeyBundleResponseSchema\n>;\n\nconst blobKekTargetsShape = {\n activeBindingIds: arraySchema(z.string()),\n blobAccessManifestHash: z.string(),\n blobId: z.string(),\n blobKeyTargetHash: z.string(),\n documentManifestHashes: arraySchema(z.string()),\n linkedContainerKeyEpochIds: arraySchema(z.string()),\n linkedContainerManifestHashes: arraySchema(z.string()),\n organizationId: z.string(),\n targets: arraySchema(plainObjectSchema),\n};\n\nexport const BlobKekTargetsResponseSchema =\n loosePlainObject(blobKekTargetsShape);\n\nexport type BlobKekTargetsResponse = z.infer<\n typeof BlobKekTargetsResponseSchema\n>;\n\n/**\n * The target set a blob's write was authorized against. `targets` is omitted\n * when `blobKeyTargetHash` equals the listing's current `blobKekTargets`\n * hash: the reader refills it from that set and re-hashes it.\n */\nconst BlobWriteAuthorizationResponseSchema = loosePlainObject({\n ...blobKekTargetsShape,\n targets: arraySchema(plainObjectSchema).optional(),\n});\n\nexport const BlobAttachmentSummarySchema = loosePlainObject({\n bindingEvent: AccessEventBundleWireResponseSchema,\n bindingId: z.string(),\n blobId: z.string(),\n blobKekTargets: BlobKekTargetsResponseSchema,\n contentKeyBundle: BlobContentKeyBundleResponseSchema,\n documentManifestHash: z.string(),\n previousBindingId: z.string().nullable(),\n slotId: z.string(),\n writeAuthorization: BlobWriteAuthorizationResponseSchema,\n writeHeader: plainObjectSchema,\n});\n\nexport type BlobAttachmentSummary = z.infer<typeof BlobAttachmentSummarySchema>;\n\nexport const ListDocumentAttachmentsResponseSchema = arraySchema(\n BlobAttachmentSummarySchema,\n);\n\nexport type ListDocumentAttachmentsResponse = z.infer<\n typeof ListDocumentAttachmentsResponseSchema\n>;\n\n/**\n * A bind acknowledges by hash: the signed binding event's hash, the stored\n * content-key epoch, the verified write header's hash, and the hashes of the\n * server-resolved KEK target set and blob access manifest. It never echoes the\n * signed event, the content-key wraps, the write header, the KEK targets, or\n * the write authorization (which a staged upload's bind stores as exactly the\n * targets it wrapped to); the client compares each with what it signed.\n */\nexport const BlobAttachmentBindResponseSchema = loosePlainObject({\n bindingId: z.string(),\n blobAccessManifestHash: nonEmptyStringSchema,\n blobId: z.string(),\n blobKeyTargetHash: nonEmptyStringSchema,\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n documentManifestHash: z.string(),\n eventHash: nonEmptyStringSchema,\n previousBindingId: z.string().nullable(),\n slotId: z.string(),\n writeHeaderHash: z.string(),\n /** Present exactly when the request carried `documentSync`. */\n documentSync: DocumentCreateSeedResponseSchema.optional(),\n});\n\nexport type BlobAttachmentBindResponse = z.infer<\n typeof BlobAttachmentBindResponseSchema\n>;\n\nfunction sortedUniqueStrings(values: readonly string[]): string[] {\n return [...new Set(values)].sort((left, right) =>\n left < right ? -1 : left > right ? 1 : 0,\n );\n}\n\n/**\n * The listing entry a staged upload's bind committed, rebuilt from the\n * request it acknowledged: the bind stores exactly the signed event,\n * content-key bundle, and write header the request carried, and a staged\n * blob is new, so this binding is its only one and its KEK targets and write\n * authorization are exactly the targets the bundle wraps to. Callers must\n * first have matched the acknowledgement's hashes against that request.\n */\nexport function blobAttachmentSummaryFromStagedBind(\n request: {\n readonly body: unknown;\n readonly contentKeyBundle: {\n readonly targetHash: string;\n readonly targets: readonly BlobContentKeyTargetEnvelopeResponse[];\n };\n readonly event: Record<string, unknown>;\n readonly stagedBlob: { readonly writeHeader: Record<string, unknown> };\n },\n response: BlobAttachmentBindResponse,\n): BlobAttachmentSummary {\n const { organizationId } = request.event;\n if (typeof organizationId !== \"string\") {\n throw new Error(\"Attachment bind event organization id is invalid\");\n }\n const targets = request.contentKeyBundle.targets.map((target) => ({\n bindingId: target.bindingId,\n containerId: target.containerId,\n containerKeyEpoch: target.containerKeyEpoch,\n containerKeyEpochId: target.containerKeyEpochId,\n containerManifestHash: target.containerManifestHash,\n documentId: target.documentId,\n }));\n const blobKekTargets: BlobKekTargetsResponse = {\n activeBindingIds: [response.bindingId],\n blobAccessManifestHash: response.blobAccessManifestHash,\n blobId: response.blobId,\n blobKeyTargetHash: response.blobKeyTargetHash,\n documentManifestHashes: [response.documentManifestHash],\n linkedContainerKeyEpochIds: sortedUniqueStrings(\n targets.map((target) => target.containerKeyEpochId),\n ),\n linkedContainerManifestHashes: sortedUniqueStrings(\n targets.map((target) => target.containerManifestHash),\n ),\n organizationId,\n targets,\n };\n return {\n bindingEvent: {\n body: request.body,\n event: request.event,\n eventHash: response.eventHash,\n },\n bindingId: response.bindingId,\n blobId: response.blobId,\n blobKekTargets,\n contentKeyBundle: {\n blobId: response.blobId,\n contentKeyEpoch: response.contentKeyEpoch,\n targetHash: request.contentKeyBundle.targetHash,\n targets: [...request.contentKeyBundle.targets],\n },\n documentManifestHash: response.documentManifestHash,\n previousBindingId: response.previousBindingId,\n slotId: response.slotId,\n writeAuthorization: blobKekTargets,\n writeHeader: request.stagedBlob.writeHeader,\n };\n}\n\nexport const BlobAttachmentDetachResponseSchema = loosePlainObject({\n bindingId: z.string(),\n blobId: z.string(),\n documentId: z.string(),\n slotId: z.string(),\n});\n\nexport type BlobAttachmentDetachResponse = z.infer<\n typeof BlobAttachmentDetachResponseSchema\n>;\n\nexport function isInitiateMultipartBlobStageResponse(\n value: unknown,\n): value is InitiateMultipartBlobStageResponse {\n return InitiateMultipartBlobStageResponseSchema.safeParse(value).success;\n}\n\nexport function isMultipartBlobStageStatusResponse(\n value: unknown,\n): value is MultipartBlobStageStatusResponse {\n return MultipartBlobStageStatusResponseSchema.safeParse(value).success;\n}\n\nexport function isUploadMultipartBlobPartResponse(\n value: unknown,\n): value is UploadMultipartBlobPartResponse {\n return UploadMultipartBlobPartResponseSchema.safeParse(value).success;\n}\n\nexport function isListDocumentAttachmentsResponse(\n value: unknown,\n): value is ListDocumentAttachmentsResponse {\n return ListDocumentAttachmentsResponseSchema.safeParse(value).success;\n}\n\nexport function isBlobAttachmentBindResponse(\n value: unknown,\n): value is BlobAttachmentBindResponse {\n return BlobAttachmentBindResponseSchema.safeParse(value).success;\n}\n\nexport function isBlobAttachmentDetachResponse(\n value: unknown,\n): value is BlobAttachmentDetachResponse {\n return BlobAttachmentDetachResponseSchema.safeParse(value).success;\n}\n"]}
|
|
@@ -9,10 +9,10 @@ export declare const CONTAINER_MUTATION_ERROR_CODES: {
|
|
|
9
9
|
readonly stateStale: "container_mutation_state_stale";
|
|
10
10
|
};
|
|
11
11
|
export declare const ContainerMutationBehaviorErrorCodeSchema: z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">;
|
|
12
|
-
export declare const ContainerMutationErrorCodeSchema: z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>;
|
|
12
|
+
export declare const ContainerMutationErrorCodeSchema: z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>;
|
|
13
13
|
export type ContainerMutationErrorCode = z.infer<typeof ContainerMutationErrorCodeSchema>;
|
|
14
14
|
export declare const ContainerMutationFailureResponseSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
15
|
-
code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
|
|
15
|
+
code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"container_mutation_state_stale" | "container_descendant_rekeys_required" | "container_ancestor_rekeys_required" | "container_descendant_rekeys_inaccessible" | "container_manifest_already_exists" | "container_path_too_deep">, z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>]>>;
|
|
16
16
|
error: z.ZodString;
|
|
17
17
|
requiredContainerIds: z.ZodOptional<z.ZodCustom<string[], string[]>>;
|
|
18
18
|
}, z.core.$loose>, z.ZodType<{
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const DOCUMENT_MUTATION_ERROR_CODES: {
|
|
3
3
|
readonly containerUnavailable: "container_unavailable";
|
|
4
|
+
readonly linkAttachmentsChanged: "document_link_attachments_changed";
|
|
4
5
|
readonly manifestAlreadyExists: "document_manifest_already_exists";
|
|
5
6
|
readonly unlinkRotationBaselineStale: "document_unlink_rotation_baseline_stale";
|
|
6
7
|
};
|
|
7
8
|
export declare const DocumentMutationBehaviorErrorCodeSchema: z.ZodLiteral<"document_manifest_already_exists">;
|
|
8
|
-
export declare const DocumentMutationErrorCodeSchema: z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>;
|
|
9
|
+
export declare const DocumentMutationErrorCodeSchema: z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>;
|
|
9
10
|
export type DocumentMutationErrorCode = z.infer<typeof DocumentMutationErrorCodeSchema>;
|
|
10
11
|
/**
|
|
11
12
|
* Document mutations retain uncoded terminal diagnostics while constraining
|
|
12
13
|
* every behavior-bearing code to the shared registry above.
|
|
13
14
|
*/
|
|
14
15
|
export declare const DocumentMutationFailureResponseSchema: z.ZodObject<{
|
|
15
|
-
code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>>;
|
|
16
|
+
code: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"document_manifest_already_exists">, z.ZodLiteral<"document_sync_checkpoint_coverage_conflict" | "document_sync_conflict" | "document_sync_descendant_rekeys_required" | "document_sync_state_stale" | "document_sync_update_id_conflict">, z.ZodLiteral<"document_not_found">, z.ZodLiteral<"container_unavailable">, z.ZodLiteral<"document_link_attachments_changed">, z.ZodLiteral<"document_unlink_rotation_baseline_stale">]>>;
|
|
16
17
|
error: z.ZodString;
|
|
17
18
|
}, z.core.$loose>;
|
|
18
19
|
export type DocumentMutationFailureResponse = z.infer<typeof DocumentMutationFailureResponseSchema>;
|
|
@@ -6,6 +6,10 @@ export const DOCUMENT_MUTATION_ERROR_CODES = {
|
|
|
6
6
|
// live row. Registered once here because the container envelope unions this
|
|
7
7
|
// schema (see ContainerMutationErrorCodeSchema).
|
|
8
8
|
containerUnavailable: CONTAINER_UNAVAILABLE_ERROR_CODE,
|
|
9
|
+
// A link or unlink's blob rewraps do not name exactly the document's active
|
|
10
|
+
// bindings. The client lists the attachments and retries; the binding check
|
|
11
|
+
// at commit stays authoritative on the server.
|
|
12
|
+
linkAttachmentsChanged: "document_link_attachments_changed",
|
|
9
13
|
manifestAlreadyExists: "document_manifest_already_exists",
|
|
10
14
|
// An unlink's rotation baseline does not cover a committed update. The
|
|
11
15
|
// client proves the full history again and retries; the rotation and its
|
|
@@ -20,6 +24,7 @@ export const DocumentMutationErrorCodeSchema = z.union([
|
|
|
20
24
|
DocumentSyncErrorCodeSchema,
|
|
21
25
|
z.literal(DOCUMENT_NOT_FOUND_ERROR_CODE),
|
|
22
26
|
z.literal(DOCUMENT_MUTATION_ERROR_CODES.containerUnavailable),
|
|
27
|
+
z.literal(DOCUMENT_MUTATION_ERROR_CODES.linkAttachmentsChanged),
|
|
23
28
|
z.literal(DOCUMENT_MUTATION_ERROR_CODES.unlinkRotationBaselineStale),
|
|
24
29
|
]);
|
|
25
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentMutationError.js","sourceRoot":"","sources":["documentMutationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,2EAA2E;IAC3E,4EAA4E;IAC5E,iDAAiD;IACjD,oBAAoB,EAAE,gCAAgC;IACtD,qBAAqB,EAAE,kCAAkC;IACzD,uEAAuE;IACvE,yEAAyE;IACzE,mDAAmD;IACnD,2BAA2B,EAAE,yCAAyC;CAC9D,CAAC;AAEX,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC,CAAC,OAAO,CAAC;IAC/D,6BAA6B,CAAC,qBAAqB;CACpD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC,KAAK,CAAC;IACrD,uCAAuC;IACvC,2BAA2B;IAC3B,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC;IACxC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,oBAAoB,CAAC;IAC7D,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,2BAA2B,CAAC;CACrE,CAAC,CAAC;AAMH;;;GAGG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAAC,CAAC,WAAW,CAAC;IACjE,IAAI,EAAE,+BAA+B,CAAC,QAAQ,EAAE;IAChD,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACzB,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { CONTAINER_UNAVAILABLE_ERROR_CODE } from \"./containerUnavailableError\";\nimport {\n DOCUMENT_NOT_FOUND_ERROR_CODE,\n DocumentSyncErrorCodeSchema,\n} from \"./documentSyncError\";\n\nexport const DOCUMENT_MUTATION_ERROR_CODES = {\n // Shared with container mutations: the cited container path element has no\n // live row. Registered once here because the container envelope unions this\n // schema (see ContainerMutationErrorCodeSchema).\n containerUnavailable: CONTAINER_UNAVAILABLE_ERROR_CODE,\n manifestAlreadyExists: \"document_manifest_already_exists\",\n // An unlink's rotation baseline does not cover a committed update. The\n // client proves the full history again and retries; the rotation and its\n // frontier check stay authoritative on the server.\n unlinkRotationBaselineStale: \"document_unlink_rotation_baseline_stale\",\n} as const;\n\nexport const DocumentMutationBehaviorErrorCodeSchema = z.literal([\n DOCUMENT_MUTATION_ERROR_CODES.manifestAlreadyExists,\n]);\n\nexport const DocumentMutationErrorCodeSchema = z.union([\n DocumentMutationBehaviorErrorCodeSchema,\n DocumentSyncErrorCodeSchema,\n z.literal(DOCUMENT_NOT_FOUND_ERROR_CODE),\n z.literal(DOCUMENT_MUTATION_ERROR_CODES.containerUnavailable),\n z.literal(DOCUMENT_MUTATION_ERROR_CODES.unlinkRotationBaselineStale),\n]);\n\nexport type DocumentMutationErrorCode = z.infer<\n typeof DocumentMutationErrorCodeSchema\n>;\n\n/**\n * Document mutations retain uncoded terminal diagnostics while constraining\n * every behavior-bearing code to the shared registry above.\n */\nexport const DocumentMutationFailureResponseSchema = z.looseObject({\n code: DocumentMutationErrorCodeSchema.optional(),\n error: z.string().min(1),\n});\n\nexport type DocumentMutationFailureResponse = z.infer<\n typeof DocumentMutationFailureResponseSchema\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"documentMutationError.js","sourceRoot":"","sources":["documentMutationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,2EAA2E;IAC3E,4EAA4E;IAC5E,iDAAiD;IACjD,oBAAoB,EAAE,gCAAgC;IACtD,4EAA4E;IAC5E,4EAA4E;IAC5E,+CAA+C;IAC/C,sBAAsB,EAAE,mCAAmC;IAC3D,qBAAqB,EAAE,kCAAkC;IACzD,uEAAuE;IACvE,yEAAyE;IACzE,mDAAmD;IACnD,2BAA2B,EAAE,yCAAyC;CAC9D,CAAC;AAEX,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC,CAAC,OAAO,CAAC;IAC/D,6BAA6B,CAAC,qBAAqB;CACpD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC,KAAK,CAAC;IACrD,uCAAuC;IACvC,2BAA2B;IAC3B,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC;IACxC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,oBAAoB,CAAC;IAC7D,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,sBAAsB,CAAC;IAC/D,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,2BAA2B,CAAC;CACrE,CAAC,CAAC;AAMH;;;GAGG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAAC,CAAC,WAAW,CAAC;IACjE,IAAI,EAAE,+BAA+B,CAAC,QAAQ,EAAE;IAChD,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACzB,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { CONTAINER_UNAVAILABLE_ERROR_CODE } from \"./containerUnavailableError\";\nimport {\n DOCUMENT_NOT_FOUND_ERROR_CODE,\n DocumentSyncErrorCodeSchema,\n} from \"./documentSyncError\";\n\nexport const DOCUMENT_MUTATION_ERROR_CODES = {\n // Shared with container mutations: the cited container path element has no\n // live row. Registered once here because the container envelope unions this\n // schema (see ContainerMutationErrorCodeSchema).\n containerUnavailable: CONTAINER_UNAVAILABLE_ERROR_CODE,\n // A link or unlink's blob rewraps do not name exactly the document's active\n // bindings. The client lists the attachments and retries; the binding check\n // at commit stays authoritative on the server.\n linkAttachmentsChanged: \"document_link_attachments_changed\",\n manifestAlreadyExists: \"document_manifest_already_exists\",\n // An unlink's rotation baseline does not cover a committed update. The\n // client proves the full history again and retries; the rotation and its\n // frontier check stay authoritative on the server.\n unlinkRotationBaselineStale: \"document_unlink_rotation_baseline_stale\",\n} as const;\n\nexport const DocumentMutationBehaviorErrorCodeSchema = z.literal([\n DOCUMENT_MUTATION_ERROR_CODES.manifestAlreadyExists,\n]);\n\nexport const DocumentMutationErrorCodeSchema = z.union([\n DocumentMutationBehaviorErrorCodeSchema,\n DocumentSyncErrorCodeSchema,\n z.literal(DOCUMENT_NOT_FOUND_ERROR_CODE),\n z.literal(DOCUMENT_MUTATION_ERROR_CODES.containerUnavailable),\n z.literal(DOCUMENT_MUTATION_ERROR_CODES.linkAttachmentsChanged),\n z.literal(DOCUMENT_MUTATION_ERROR_CODES.unlinkRotationBaselineStale),\n]);\n\nexport type DocumentMutationErrorCode = z.infer<\n typeof DocumentMutationErrorCodeSchema\n>;\n\n/**\n * Document mutations retain uncoded terminal diagnostics while constraining\n * every behavior-bearing code to the shared registry above.\n */\nexport const DocumentMutationFailureResponseSchema = z.looseObject({\n code: DocumentMutationErrorCodeSchema.optional(),\n error: z.string().min(1),\n});\n\nexport type DocumentMutationFailureResponse = z.infer<\n typeof DocumentMutationFailureResponseSchema\n>;\n"]}
|
|
@@ -115,12 +115,6 @@ export declare const DocumentContentKeyBundleResponseSchema: z.ZodType<{
|
|
|
115
115
|
export type DocumentContentKeyBundleResponse = z.infer<typeof DocumentContentKeyBundleResponseSchema>;
|
|
116
116
|
export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
|
|
117
117
|
accessEpoch: number;
|
|
118
|
-
authorizationTargets: {
|
|
119
|
-
containerId: string;
|
|
120
|
-
containerKeyEpoch: number;
|
|
121
|
-
containerKeyEpochId: string;
|
|
122
|
-
containerManifestHash: string;
|
|
123
|
-
}[];
|
|
124
118
|
authorFingerprint: string;
|
|
125
119
|
createdAt: string;
|
|
126
120
|
documentId: string;
|
|
@@ -130,17 +124,17 @@ export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
|
|
|
130
124
|
partialStartVersionVector: string;
|
|
131
125
|
plaintextHash: string;
|
|
132
126
|
writeHeader: Record<string, unknown>;
|
|
127
|
+
authorizationTargets?: {
|
|
128
|
+
containerId: string;
|
|
129
|
+
containerKeyEpoch: number;
|
|
130
|
+
containerKeyEpochId: string;
|
|
131
|
+
containerManifestHash: string;
|
|
132
|
+
}[] | undefined;
|
|
133
133
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
134
134
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
135
135
|
sourceVersionVector?: string | undefined;
|
|
136
136
|
}, {
|
|
137
137
|
accessEpoch: number;
|
|
138
|
-
authorizationTargets: {
|
|
139
|
-
containerId: string;
|
|
140
|
-
containerKeyEpoch: number;
|
|
141
|
-
containerKeyEpochId: string;
|
|
142
|
-
containerManifestHash: string;
|
|
143
|
-
}[];
|
|
144
138
|
authorFingerprint: string;
|
|
145
139
|
createdAt: string;
|
|
146
140
|
documentId: string;
|
|
@@ -150,17 +144,17 @@ export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
|
|
|
150
144
|
partialStartVersionVector: string;
|
|
151
145
|
plaintextHash: string;
|
|
152
146
|
writeHeader: Record<string, unknown>;
|
|
147
|
+
authorizationTargets?: {
|
|
148
|
+
containerId: string;
|
|
149
|
+
containerKeyEpoch: number;
|
|
150
|
+
containerKeyEpochId: string;
|
|
151
|
+
containerManifestHash: string;
|
|
152
|
+
}[] | undefined;
|
|
153
153
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
154
154
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
155
155
|
sourceVersionVector?: string | undefined;
|
|
156
156
|
}, z.core.$ZodTypeInternals<{
|
|
157
157
|
accessEpoch: number;
|
|
158
|
-
authorizationTargets: {
|
|
159
|
-
containerId: string;
|
|
160
|
-
containerKeyEpoch: number;
|
|
161
|
-
containerKeyEpochId: string;
|
|
162
|
-
containerManifestHash: string;
|
|
163
|
-
}[];
|
|
164
158
|
authorFingerprint: string;
|
|
165
159
|
createdAt: string;
|
|
166
160
|
documentId: string;
|
|
@@ -170,17 +164,17 @@ export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
|
|
|
170
164
|
partialStartVersionVector: string;
|
|
171
165
|
plaintextHash: string;
|
|
172
166
|
writeHeader: Record<string, unknown>;
|
|
167
|
+
authorizationTargets?: {
|
|
168
|
+
containerId: string;
|
|
169
|
+
containerKeyEpoch: number;
|
|
170
|
+
containerKeyEpochId: string;
|
|
171
|
+
containerManifestHash: string;
|
|
172
|
+
}[] | undefined;
|
|
173
173
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
174
174
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
175
175
|
sourceVersionVector?: string | undefined;
|
|
176
176
|
}, {
|
|
177
177
|
accessEpoch: number;
|
|
178
|
-
authorizationTargets: {
|
|
179
|
-
containerId: string;
|
|
180
|
-
containerKeyEpoch: number;
|
|
181
|
-
containerKeyEpochId: string;
|
|
182
|
-
containerManifestHash: string;
|
|
183
|
-
}[];
|
|
184
178
|
authorFingerprint: string;
|
|
185
179
|
createdAt: string;
|
|
186
180
|
documentId: string;
|
|
@@ -190,6 +184,12 @@ export declare const DocumentSyncUpdateResponseSchema: z.ZodType<{
|
|
|
190
184
|
partialStartVersionVector: string;
|
|
191
185
|
plaintextHash: string;
|
|
192
186
|
writeHeader: Record<string, unknown>;
|
|
187
|
+
authorizationTargets?: {
|
|
188
|
+
containerId: string;
|
|
189
|
+
containerKeyEpoch: number;
|
|
190
|
+
containerKeyEpochId: string;
|
|
191
|
+
containerManifestHash: string;
|
|
192
|
+
}[] | undefined;
|
|
193
193
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
194
194
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
195
195
|
sourceVersionVector?: string | undefined;
|
|
@@ -235,12 +235,6 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
|
|
|
235
235
|
};
|
|
236
236
|
updates: {
|
|
237
237
|
accessEpoch: number;
|
|
238
|
-
authorizationTargets: {
|
|
239
|
-
containerId: string;
|
|
240
|
-
containerKeyEpoch: number;
|
|
241
|
-
containerKeyEpochId: string;
|
|
242
|
-
containerManifestHash: string;
|
|
243
|
-
}[];
|
|
244
238
|
authorFingerprint: string;
|
|
245
239
|
createdAt: string;
|
|
246
240
|
documentId: string;
|
|
@@ -250,6 +244,12 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
|
|
|
250
244
|
partialStartVersionVector: string;
|
|
251
245
|
plaintextHash: string;
|
|
252
246
|
writeHeader: Record<string, unknown>;
|
|
247
|
+
authorizationTargets?: {
|
|
248
|
+
containerId: string;
|
|
249
|
+
containerKeyEpoch: number;
|
|
250
|
+
containerKeyEpochId: string;
|
|
251
|
+
containerManifestHash: string;
|
|
252
|
+
}[] | undefined;
|
|
253
253
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
254
254
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
255
255
|
sourceVersionVector?: string | undefined;
|
|
@@ -279,12 +279,6 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
|
|
|
279
279
|
};
|
|
280
280
|
updates: {
|
|
281
281
|
accessEpoch: number;
|
|
282
|
-
authorizationTargets: {
|
|
283
|
-
containerId: string;
|
|
284
|
-
containerKeyEpoch: number;
|
|
285
|
-
containerKeyEpochId: string;
|
|
286
|
-
containerManifestHash: string;
|
|
287
|
-
}[];
|
|
288
282
|
authorFingerprint: string;
|
|
289
283
|
createdAt: string;
|
|
290
284
|
documentId: string;
|
|
@@ -294,6 +288,12 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
|
|
|
294
288
|
partialStartVersionVector: string;
|
|
295
289
|
plaintextHash: string;
|
|
296
290
|
writeHeader: Record<string, unknown>;
|
|
291
|
+
authorizationTargets?: {
|
|
292
|
+
containerId: string;
|
|
293
|
+
containerKeyEpoch: number;
|
|
294
|
+
containerKeyEpochId: string;
|
|
295
|
+
containerManifestHash: string;
|
|
296
|
+
}[] | undefined;
|
|
297
297
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
298
298
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
299
299
|
sourceVersionVector?: string | undefined;
|
|
@@ -323,12 +323,6 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
|
|
|
323
323
|
};
|
|
324
324
|
updates: {
|
|
325
325
|
accessEpoch: number;
|
|
326
|
-
authorizationTargets: {
|
|
327
|
-
containerId: string;
|
|
328
|
-
containerKeyEpoch: number;
|
|
329
|
-
containerKeyEpochId: string;
|
|
330
|
-
containerManifestHash: string;
|
|
331
|
-
}[];
|
|
332
326
|
authorFingerprint: string;
|
|
333
327
|
createdAt: string;
|
|
334
328
|
documentId: string;
|
|
@@ -338,6 +332,12 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
|
|
|
338
332
|
partialStartVersionVector: string;
|
|
339
333
|
plaintextHash: string;
|
|
340
334
|
writeHeader: Record<string, unknown>;
|
|
335
|
+
authorizationTargets?: {
|
|
336
|
+
containerId: string;
|
|
337
|
+
containerKeyEpoch: number;
|
|
338
|
+
containerKeyEpochId: string;
|
|
339
|
+
containerManifestHash: string;
|
|
340
|
+
}[] | undefined;
|
|
341
341
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
342
342
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
343
343
|
sourceVersionVector?: string | undefined;
|
|
@@ -367,12 +367,6 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
|
|
|
367
367
|
};
|
|
368
368
|
updates: {
|
|
369
369
|
accessEpoch: number;
|
|
370
|
-
authorizationTargets: {
|
|
371
|
-
containerId: string;
|
|
372
|
-
containerKeyEpoch: number;
|
|
373
|
-
containerKeyEpochId: string;
|
|
374
|
-
containerManifestHash: string;
|
|
375
|
-
}[];
|
|
376
370
|
authorFingerprint: string;
|
|
377
371
|
createdAt: string;
|
|
378
372
|
documentId: string;
|
|
@@ -382,6 +376,12 @@ export declare const DocumentSyncResponseSchema: z.ZodType<{
|
|
|
382
376
|
partialStartVersionVector: string;
|
|
383
377
|
plaintextHash: string;
|
|
384
378
|
writeHeader: Record<string, unknown>;
|
|
379
|
+
authorizationTargets?: {
|
|
380
|
+
containerId: string;
|
|
381
|
+
containerKeyEpoch: number;
|
|
382
|
+
containerKeyEpochId: string;
|
|
383
|
+
containerManifestHash: string;
|
|
384
|
+
}[] | undefined;
|
|
385
385
|
checkpointKind?: "rotate_baseline" | undefined;
|
|
386
386
|
checkpointPayloadKind?: "full_history_snapshot" | undefined;
|
|
387
387
|
sourceVersionVector?: string | undefined;
|
|
@@ -35,7 +35,7 @@ export const DocumentContentKeyBundleResponseSchema = loosePlainObject({
|
|
|
35
35
|
});
|
|
36
36
|
export const DocumentSyncUpdateResponseSchema = registerJsonSchemaRuntimeRefinements(loosePlainObject({
|
|
37
37
|
accessEpoch: positiveIntegerSchema,
|
|
38
|
-
authorizationTargets: nonEmptyArraySchema(DocumentContentKeyTargetResponseSchema),
|
|
38
|
+
authorizationTargets: nonEmptyArraySchema(DocumentContentKeyTargetResponseSchema).optional(),
|
|
39
39
|
authorFingerprint: z.string(),
|
|
40
40
|
checkpointKind: z
|
|
41
41
|
.literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentSyncSchema.js","sourceRoot":"","sources":["documentSyncSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,oCAAoC,EACpC,gDAAgD,EAChD,sCAAsC,EACtC,8CAA8C,GAC/C,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,2CAA2C,EAC3C,+CAA+C,EAC/C,+CAA+C,EAC/C,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,kCAAkC,EAClC,oCAAoC,EACpC,uCAAuC,GACxC,MAAM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CACF,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n classifyDocumentSyncCheckpointFields,\n DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND,\n} from \"../documentSyncCheckpoint\";\nimport {\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseRotationRefinement,\n} from \"../documentSyncRefinements\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n arraySchema,\n boundedNonEmptyStringSchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport {\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n} from \"../util/documentSyncLimits\";\n\nexport const DocumentContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n wrappedKey: nonEmptyStringSchema,\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type DocumentContentKeyTargetEnvelopeResponse = z.infer<\n typeof DocumentContentKeyTargetEnvelopeResponseSchema\n>;\n\nconst DocumentContentKeyTargetResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n});\n\nexport const DocumentKekTargetsResponseSchema = loosePlainObject({\n documentId: z.string(),\n documentKeyTargetHash: nonEmptyStringSchema,\n linkedContainerKeyEpochIds: nonEmptyArraySchema(nonEmptyStringSchema),\n linkedContainerManifestHashes: nonEmptyArraySchema(nonEmptyStringSchema),\n linkSetManifestHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(plainObjectSchema),\n});\n\nexport type DocumentKekTargetsResponse = z.infer<\n typeof DocumentKekTargetsResponseSchema\n>;\n\nexport const DocumentContentKeyBundleResponseSchema = loosePlainObject({\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n linkSetManifestHash: nonEmptyStringSchema,\n targetHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(DocumentContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type DocumentContentKeyBundleResponse = z.infer<\n typeof DocumentContentKeyBundleResponseSchema\n>;\n\nexport const DocumentSyncUpdateResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n accessEpoch: positiveIntegerSchema,\n authorizationTargets: nonEmptyArraySchema(\n DocumentContentKeyTargetResponseSchema,\n ),\n authorFingerprint: z.string(),\n checkpointKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND)\n .optional(),\n checkpointPayloadKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND)\n .optional(),\n createdAt: z.string(),\n documentId: z.string(),\n encryptedData: z.string(),\n id: z.string(),\n partialEndVersionVector: z.string(),\n partialStartVersionVector: z.string(),\n plaintextHash: nonEmptyStringSchema,\n sourceVersionVector: z.string().min(1).optional(),\n writeHeader: plainObjectSchema,\n }).superRefine((update, context) => {\n if (classifyDocumentSyncCheckpointFields(update) === \"invalid\") {\n context.addIssue({\n code: \"custom\",\n message: DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n });\n }\n }),\n [documentSyncResponseRotationRefinement],\n );\n\nexport type DocumentSyncUpdateResponse = z.infer<\n typeof DocumentSyncUpdateResponseSchema\n>;\n\nexport const DocumentSyncPullPageResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n nextCursor: boundedNonEmptyStringSchema(\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n ).nullable(),\n});\n\nexport type DocumentSyncPullPageResponse = z.infer<\n typeof DocumentSyncPullPageResponseSchema\n>;\n\nfunction contentKeyEpochOf(bundle: unknown): number | null {\n if (typeof bundle !== \"object\" || bundle === null) return null;\n const contentKeyEpoch: unknown = Reflect.get(bundle, \"contentKeyEpoch\");\n return typeof contentKeyEpoch === \"number\" ? contentKeyEpoch : null;\n}\n\n/**\n * The client already holds the current epoch's bundle, so the array holds the\n * distinct older epochs that served updates cite; the client rejects any epoch\n * not older than the one it planned against. Field issues do not stop this\n * object refinement, so it judges only epochs that parsed.\n */\nfunction addHistoricalContentKeyBundleIssues(\n response: { readonly contentKeyBundles: unknown },\n context: z.RefinementCtx,\n): void {\n if (!Array.isArray(response.contentKeyBundles)) return;\n const seenEpochs = new Set<number>();\n // forEach skips holes exactly as arraySchema's item validation does.\n response.contentKeyBundles.forEach((bundle: unknown, index: number) => {\n const contentKeyEpoch = contentKeyEpochOf(bundle);\n if (contentKeyEpoch === null) return;\n if (seenEpochs.has(contentKeyEpoch)) {\n context.addIssue({\n code: \"custom\",\n message: \"content-key bundles must be distinct epochs\",\n path: [\"contentKeyBundles\", index, \"contentKeyEpoch\"],\n });\n }\n seenEpochs.add(contentKeyEpoch);\n });\n}\n\nexport const commitLsnResponseShape = {\n commitLsn: z.string().nullable(),\n commitLsnMode: z.union([z.literal(\"tracked\"), z.literal(\"untracked\")]),\n};\n\n/** The 0/0 sentinel and the untracked mode imply each other. */\nfunction addCommitLsnIssues(\n response: {\n readonly commitLsn: string | null;\n readonly commitLsnMode: \"tracked\" | \"untracked\";\n },\n context: z.RefinementCtx,\n): void {\n if (response.commitLsnMode === \"untracked\" && response.commitLsn !== \"0/0\") {\n context.addIssue({\n code: \"custom\",\n message: \"untracked commit LSN must use the 0/0 sentinel\",\n path: [\"commitLsn\"],\n });\n }\n if (response.commitLsn === \"0/0\" && response.commitLsnMode !== \"untracked\") {\n context.addIssue({\n code: \"custom\",\n message: \"0/0 commit LSN must be declared untracked\",\n path: [\"commitLsnMode\"],\n });\n }\n}\n\nexport const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n acceptedOutgoingUpdateIds: arraySchema(\n z.string(),\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n ),\n ...commitLsnResponseShape,\n contentKeyBundles: arraySchema(DocumentContentKeyBundleResponseSchema),\n documentId: z.string(),\n pullPage: DocumentSyncPullPageResponseSchema,\n updates: arraySchema(\n DocumentSyncUpdateResponseSchema,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n ),\n }).superRefine((response, context) => {\n if (\n response.pullPage !== undefined &&\n response.pullPage.hasMore !== (response.pullPage.nextCursor !== null)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"pull page continuation does not match hasMore\",\n path: [\"pullPage\", \"nextCursor\"],\n });\n }\n addCommitLsnIssues(response, context);\n addHistoricalContentKeyBundleIssues(response, context);\n }),\n [\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n ],\n);\n\nexport type DocumentSyncResponse = z.infer<typeof DocumentSyncResponseSchema>;\n"]}
|
|
1
|
+
{"version":3,"file":"documentSyncSchema.js","sourceRoot":"","sources":["documentSyncSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,oCAAoC,EACpC,gDAAgD,EAChD,sCAAsC,EACtC,8CAA8C,GAC/C,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,2CAA2C,EAC3C,+CAA+C,EAC/C,+CAA+C,EAC/C,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oCAAoC,EAAE,MAAM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,YAAY,CAAC;SACjC,CAAC,CAAC;IACL,CAAC;IACD,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,mCAAmC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC,EACF;IACE,2CAA2C;IAC3C,+CAA+C;IAC/C,sCAAsC;IACtC,+CAA+C;CAChD,CACF,CAAC","sourcesContent":["import { z } from \"zod\";\nimport {\n classifyDocumentSyncCheckpointFields,\n DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND,\n DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND,\n} from \"../documentSyncCheckpoint\";\nimport {\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseRotationRefinement,\n} from \"../documentSyncRefinements\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport {\n arraySchema,\n boundedNonEmptyStringSchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport {\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n} from \"../util/documentSyncLimits\";\n\nexport const DocumentContentKeyTargetEnvelopeResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n wrappedKey: nonEmptyStringSchema,\n wrappingMetadata: plainObjectSchema,\n});\n\nexport type DocumentContentKeyTargetEnvelopeResponse = z.infer<\n typeof DocumentContentKeyTargetEnvelopeResponseSchema\n>;\n\nconst DocumentContentKeyTargetResponseSchema = loosePlainObject({\n containerId: nonEmptyStringSchema,\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHash: nonEmptyStringSchema,\n});\n\nexport const DocumentKekTargetsResponseSchema = loosePlainObject({\n documentId: z.string(),\n documentKeyTargetHash: nonEmptyStringSchema,\n linkedContainerKeyEpochIds: nonEmptyArraySchema(nonEmptyStringSchema),\n linkedContainerManifestHashes: nonEmptyArraySchema(nonEmptyStringSchema),\n linkSetManifestHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(plainObjectSchema),\n});\n\nexport type DocumentKekTargetsResponse = z.infer<\n typeof DocumentKekTargetsResponseSchema\n>;\n\nexport const DocumentContentKeyBundleResponseSchema = loosePlainObject({\n contentKeyEpoch: positiveIntegerSchema,\n documentId: z.string(),\n linkSetManifestHash: nonEmptyStringSchema,\n targetHash: nonEmptyStringSchema,\n targets: nonEmptyArraySchema(DocumentContentKeyTargetEnvelopeResponseSchema),\n});\n\nexport type DocumentContentKeyBundleResponse = z.infer<\n typeof DocumentContentKeyBundleResponseSchema\n>;\n\nexport const DocumentSyncUpdateResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n accessEpoch: positiveIntegerSchema,\n authorizationTargets: nonEmptyArraySchema(\n DocumentContentKeyTargetResponseSchema,\n ).optional(),\n authorFingerprint: z.string(),\n checkpointKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_KIND)\n .optional(),\n checkpointPayloadKind: z\n .literal(DOCUMENT_SYNC_ROTATION_CHECKPOINT_PAYLOAD_KIND)\n .optional(),\n createdAt: z.string(),\n documentId: z.string(),\n encryptedData: z.string(),\n id: z.string(),\n partialEndVersionVector: z.string(),\n partialStartVersionVector: z.string(),\n plaintextHash: nonEmptyStringSchema,\n sourceVersionVector: z.string().min(1).optional(),\n writeHeader: plainObjectSchema,\n }).superRefine((update, context) => {\n if (classifyDocumentSyncCheckpointFields(update) === \"invalid\") {\n context.addIssue({\n code: \"custom\",\n message: DOCUMENT_SYNC_CHECKPOINT_FIELD_SET_ISSUE_MESSAGE,\n });\n }\n }),\n [documentSyncResponseRotationRefinement],\n );\n\nexport type DocumentSyncUpdateResponse = z.infer<\n typeof DocumentSyncUpdateResponseSchema\n>;\n\nexport const DocumentSyncPullPageResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n nextCursor: boundedNonEmptyStringSchema(\n MAX_DOCUMENT_SYNC_PULL_CURSOR_LENGTH,\n ).nullable(),\n});\n\nexport type DocumentSyncPullPageResponse = z.infer<\n typeof DocumentSyncPullPageResponseSchema\n>;\n\nfunction contentKeyEpochOf(bundle: unknown): number | null {\n if (typeof bundle !== \"object\" || bundle === null) return null;\n const contentKeyEpoch: unknown = Reflect.get(bundle, \"contentKeyEpoch\");\n return typeof contentKeyEpoch === \"number\" ? contentKeyEpoch : null;\n}\n\n/**\n * The client already holds the current epoch's bundle, so the array holds the\n * distinct older epochs that served updates cite; the client rejects any epoch\n * not older than the one it planned against. Field issues do not stop this\n * object refinement, so it judges only epochs that parsed.\n */\nfunction addHistoricalContentKeyBundleIssues(\n response: { readonly contentKeyBundles: unknown },\n context: z.RefinementCtx,\n): void {\n if (!Array.isArray(response.contentKeyBundles)) return;\n const seenEpochs = new Set<number>();\n // forEach skips holes exactly as arraySchema's item validation does.\n response.contentKeyBundles.forEach((bundle: unknown, index: number) => {\n const contentKeyEpoch = contentKeyEpochOf(bundle);\n if (contentKeyEpoch === null) return;\n if (seenEpochs.has(contentKeyEpoch)) {\n context.addIssue({\n code: \"custom\",\n message: \"content-key bundles must be distinct epochs\",\n path: [\"contentKeyBundles\", index, \"contentKeyEpoch\"],\n });\n }\n seenEpochs.add(contentKeyEpoch);\n });\n}\n\nexport const commitLsnResponseShape = {\n commitLsn: z.string().nullable(),\n commitLsnMode: z.union([z.literal(\"tracked\"), z.literal(\"untracked\")]),\n};\n\n/** The 0/0 sentinel and the untracked mode imply each other. */\nfunction addCommitLsnIssues(\n response: {\n readonly commitLsn: string | null;\n readonly commitLsnMode: \"tracked\" | \"untracked\";\n },\n context: z.RefinementCtx,\n): void {\n if (response.commitLsnMode === \"untracked\" && response.commitLsn !== \"0/0\") {\n context.addIssue({\n code: \"custom\",\n message: \"untracked commit LSN must use the 0/0 sentinel\",\n path: [\"commitLsn\"],\n });\n }\n if (response.commitLsn === \"0/0\" && response.commitLsnMode !== \"untracked\") {\n context.addIssue({\n code: \"custom\",\n message: \"0/0 commit LSN must be declared untracked\",\n path: [\"commitLsnMode\"],\n });\n }\n}\n\nexport const DocumentSyncResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n acceptedOutgoingUpdateIds: arraySchema(\n z.string(),\n MAX_DOCUMENT_SYNC_OUTGOING_UPDATES,\n ),\n ...commitLsnResponseShape,\n contentKeyBundles: arraySchema(DocumentContentKeyBundleResponseSchema),\n documentId: z.string(),\n pullPage: DocumentSyncPullPageResponseSchema,\n updates: arraySchema(\n DocumentSyncUpdateResponseSchema,\n MAX_DOCUMENT_SYNC_RESPONSE_PAGE_UPDATES,\n ),\n }).superRefine((response, context) => {\n if (\n response.pullPage !== undefined &&\n response.pullPage.hasMore !== (response.pullPage.nextCursor !== null)\n ) {\n context.addIssue({\n code: \"custom\",\n message: \"pull page continuation does not match hasMore\",\n path: [\"pullPage\", \"nextCursor\"],\n });\n }\n addCommitLsnIssues(response, context);\n addHistoricalContentKeyBundleIssues(response, context);\n }),\n [\n documentSyncResponseCommitLsnModeRefinement,\n documentSyncResponseCommitLsnSentinelRefinement,\n documentSyncResponsePullPageRefinement,\n documentSyncResponseHistoricalBundlesRefinement,\n ],\n);\n\nexport type DocumentSyncResponse = z.infer<typeof DocumentSyncResponseSchema>;\n"]}
|
package/package.json
CHANGED
|
@@ -190,6 +190,22 @@ function attachmentBindingDocumentId(binding) {
|
|
|
190
190
|
}
|
|
191
191
|
return readRecordString(readCanonicalRecord(binding.bindingEvent.body, "Attachment binding event body"), "documentId", "Attachment binding event body");
|
|
192
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* The listing omits the write's target set when its hash equals the current
|
|
195
|
+
* set's, so refill it from `blobKekTargets`; verification re-hashes it against
|
|
196
|
+
* the write authorization and the signed header. Any other omission fails.
|
|
197
|
+
*/
|
|
198
|
+
function writeAuthorizationWithTargets(binding) {
|
|
199
|
+
const { blobKekTargets, writeAuthorization } = binding;
|
|
200
|
+
if (!writeAuthorization)
|
|
201
|
+
return undefined;
|
|
202
|
+
if (writeAuthorization.targets)
|
|
203
|
+
return { ...writeAuthorization, targets: writeAuthorization.targets };
|
|
204
|
+
if (!blobKekTargets ||
|
|
205
|
+
writeAuthorization.blobKeyTargetHash !== blobKekTargets.blobKeyTargetHash)
|
|
206
|
+
throw new Error("Attachment blob write authorization lacks its targets");
|
|
207
|
+
return { ...writeAuthorization, targets: blobKekTargets.targets };
|
|
208
|
+
}
|
|
193
209
|
async function assertBlobWriteHeaderVerified(input) {
|
|
194
210
|
if (!input.authorization || !input.binding.writeHeader) {
|
|
195
211
|
throw new Error("Attachment blob lacks verified write authority");
|
|
@@ -206,7 +222,7 @@ async function assertBlobWriteHeaderVerified(input) {
|
|
|
206
222
|
});
|
|
207
223
|
const blobKekTargets = await verifiedBlobKekTargetsForBinding({
|
|
208
224
|
binding: input.binding,
|
|
209
|
-
projection: input.binding
|
|
225
|
+
projection: writeAuthorizationWithTargets(input.binding),
|
|
210
226
|
// The signed binding proves which slot exposes the blob now. Writer
|
|
211
227
|
// authorization describes the older target set committed when the bytes
|
|
212
228
|
// were written, so a later valid binding need not appear in that set.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.js","sourceRoot":"","sources":["decrypt.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,UAAU,EACV,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,mCAAmC,EACnC,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,mBAAmB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C,eAAe,EAC1D,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC;QACvC,uBAAuB,EAAE,YAAY;QACrC,iBAAiB,EAAE;YACjB,yBAAyB,EAAE,0BAA0B,CAAC;gBACpD,2BAA2B,EACzB,KAAK,CAAC,aAAa,CAAC,2BAA2B;gBACjD,wBAAwB,EAAE,MAAM,CAAC,wBAAwB;aAC1D,CAAC,CAAC,wBAAwB;YAC3B,cAAc;YACd,iBAAiB,EAAE,KAAK,CAAC,aAAa,CAAC,iBAAiB;SACzD;QACD,0BAA0B,EAAE,cAAc,CAAC,sBAAsB;QACjE,cAAc,EAAE;YACd,UAAU,EAAE,MAAM;YAClB,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;YAC9B,cAAc,EAAE,KAAK,CAAC,cAAc;SACrC;QACD,kBAAkB,EAAE,cAAc,CAAC,iBAAiB;QACpD,MAAM;QACN,eAAe,EAAE,MAAM,CAAC,gBAAgB;KACzC,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,QAAQ,CAAC,KAAK,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["import {\n blobContentMetadataHash,\n bytesToHex,\n CONTENT_RECORD_ENCRYPTION_SUITE,\n computeBlobAccessManifestHash,\n computeBlobContentKeyTargetHash,\n computeContentRecordNonceDomainHash,\n makeVerifiedBlobKekTargets,\n verifyWriteHeader,\n} from \"@tearleads/crypto\";\nimport type { BlobKekTargetsResponse } from \"@tearleads/validators/response\";\nimport { deriveBlobContentRecordKey } from \"../../../data/blobs/attachments/crypto\";\nimport { unwrapBlobContentKey } from \"../../../data/blobs/attachments/projection\";\nimport {\n parseBlobEncryptedBytes,\n readBlobKekTarget,\n readDocumentManifestIdentity,\n sortBlobTargets,\n} from \"../../../data/blobs/attachments/readers\";\nimport { assertBlobContentKeyBundleTargetHash } from \"../../../data/blobs/attachments/responses\";\nimport type {\n BlobEncryptedBytesHeader,\n DecryptDocumentAttachmentBlobInput,\n} from \"../../../data/blobs/attachments/types\";\nimport type { BlobBytes } from \"../../../data/blobs/blobContracts\";\nimport { importContentKeyMaterial } from \"../../../data/documents/shared/contentRecordKeys\";\nimport { assertDocumentWriterProjectionConsistent } from \"../../../data/documents/shared/projection\";\nimport { projectionVerificationOptions } from \"../../../data/documents/shared/projection/projectionVerificationOptions\";\nimport {\n asWebCryptoBytes,\n readWriteHeader,\n uniqueSortedStrings,\n} from \"../../../data/documents/shared/readers\";\nimport { readCanonicalRecord } from \"../../../data/keying/canonicalJson\";\nimport type { DocumentWriterProjectionAuthorization } from \"../../../data/keyingProjectionVerification\";\nimport {\n readRecordString,\n requireProjectionUserKeyResolver,\n resolveEventContainerPaths,\n} from \"../../../data/keyingProjectionVerification\";\n\nimport { assertAttachmentBindingVerified } from \"../verification/attachmentBindingVerification\";\nimport { assertBlobWrapScopeVerified } from \"../verification/verifiedWrapScope\";\nimport { decryptBlobChunks } from \"./blobChunkDecryption\";\n\nasync function assertBlobEncryptionMetadata(input: {\n readonly contentKeyBundle: DecryptDocumentAttachmentBlobInput[\"binding\"][\"contentKeyBundle\"];\n readonly encrypted: BlobEncryptedBytesHeader;\n readonly expectedBlobId: string;\n readonly organizationId: string;\n}): Promise<void> {\n const { contentKeyBundle, encrypted, expectedBlobId, organizationId } = input;\n if (\n encrypted.blobId !== expectedBlobId ||\n encrypted.contentRecordId !== expectedBlobId\n ) {\n throw new Error(\"Blob encrypted bytes blob id mismatch\");\n }\n if (\n encrypted.contentKeyEpoch !== contentKeyBundle.contentKeyEpoch ||\n contentKeyBundle.blobId !== expectedBlobId\n ) {\n throw new Error(\"Blob encrypted bytes content-key bundle mismatch\");\n }\n await assertBlobContentKeyBundleTargetHash(contentKeyBundle);\n\n const expectedNonceDomainHash = await computeContentRecordNonceDomainHash({\n version: 1,\n organizationId,\n objectKind: \"blob\",\n objectId: expectedBlobId,\n contentKeyEpoch: encrypted.contentKeyEpoch,\n encryptionSuite: CONTENT_RECORD_ENCRYPTION_SUITE,\n contentRecordId: encrypted.contentRecordId,\n });\n if (encrypted.nonceDomainHash !== expectedNonceDomainHash) {\n throw new Error(\"Blob encrypted bytes nonce domain mismatch\");\n }\n const expectedMetadataHash = await blobContentMetadataHash({\n blobId: expectedBlobId,\n byteLength: encrypted.byteLength,\n chunkCount: encrypted.chunkCount,\n chunkSize: encrypted.chunkSize,\n contentKeyEpoch: encrypted.contentKeyEpoch,\n });\n if (encrypted.metadataHash !== expectedMetadataHash) {\n throw new Error(\"Blob encrypted bytes metadata hash mismatch\");\n }\n}\n\nexport type AttachmentBlobDecryptionInput = Omit<\n DecryptDocumentAttachmentBlobInput,\n \"encryptedBytes\"\n> & {\n encrypted: BlobEncryptedBytesHeader;\n};\n\n/** Verifies metadata and authority; the caller must still authenticate ciphertext. */\nexport async function prepareDocumentAttachmentBlobDecryption({\n binding,\n encrypted,\n expectedDocumentId,\n expectedSlotId,\n execSql,\n resolveProjectionUserKey,\n targetSecretKey,\n stillCurrent,\n warmReferencedPrincipalPolicies,\n writerProjection,\n}: AttachmentBlobDecryptionInput): Promise<{\n contentKey: Uint8Array;\n recordKey: CryptoKey;\n organizationId: string;\n}> {\n const requiredResolveProjectionUserKey = requireProjectionUserKeyResolver(\n resolveProjectionUserKey,\n \"Document attachment blob decrypt\",\n );\n const verificationOptions = projectionVerificationOptions({\n execSql,\n stillCurrent,\n warmReferencedPrincipalPolicies,\n resolveProjectionUserKey: requiredResolveProjectionUserKey,\n });\n let documentAuthorization: DocumentWriterProjectionAuthorization | undefined;\n await assertDocumentWriterProjectionConsistent(writerProjection, {\n allowStaleContentKeyBundle: true,\n execSql,\n onVerifiedAuthorization: (authorization) => {\n documentAuthorization = authorization;\n },\n ...verificationOptions,\n });\n const { documentId, organizationId } =\n readDocumentManifestIdentity(writerProjection);\n await assertBlobEncryptionMetadata({\n contentKeyBundle: binding.contentKeyBundle,\n encrypted,\n expectedBlobId: binding.blobId,\n organizationId,\n });\n await assertAttachmentBindingVerified({\n authorization: documentAuthorization,\n binding,\n expectedDocumentId,\n expectedSlotId,\n resolveProjectionUserKey: requiredResolveProjectionUserKey,\n });\n await assertBlobWriteHeaderVerified({\n authorization: documentAuthorization,\n binding,\n encrypted,\n organizationId,\n resolveProjectionUserKey: requiredResolveProjectionUserKey,\n });\n\n if (!documentAuthorization)\n throw new Error(\"Blob document authorization is unavailable\");\n assertBlobWrapScopeVerified({\n authorization: documentAuthorization,\n binding,\n documentId,\n });\n const contentKey = await unwrapBlobContentKey({\n blobId: binding.blobId,\n contentKeyBundle: binding.contentKeyBundle,\n documentId,\n encrypted,\n execSql,\n expectedBindingId: binding.bindingId,\n secretKey: targetSecretKey,\n ...verificationOptions,\n writerProjection,\n });\n const contentKeyMaterial = await importContentKeyMaterial(contentKey);\n const recordKey = await deriveBlobContentRecordKey({\n blobId: binding.blobId,\n contentKeyEpoch: encrypted.contentKeyEpoch,\n contentKeyMaterial,\n contentRecordId: encrypted.contentRecordId,\n organizationId,\n usage: \"decrypt\",\n });\n return { contentKey, recordKey, organizationId };\n}\n\nasync function decryptDocumentAttachmentBlobWithKey(\n input: DecryptDocumentAttachmentBlobInput,\n): Promise<{ bytes: BlobBytes; contentKey: Uint8Array }> {\n const encrypted = parseBlobEncryptedBytes(input.encryptedBytes);\n const context = await prepareDocumentAttachmentBlobDecryption({\n ...input,\n encrypted,\n });\n const header = readWriteHeader(\n input.binding.writeHeader,\n \"Attachment blob write header\",\n );\n const ciphertextHash = bytesToHex(\n new Uint8Array(\n await crypto.subtle.digest(\n \"SHA-256\",\n asWebCryptoBytes(input.encryptedBytes),\n ),\n ),\n );\n if (header.ciphertextHash !== ciphertextHash)\n throw new Error(\"Attachment blob write header does not match ciphertext\");\n const bytes = await decryptBlobChunks({\n ...context,\n encrypted,\n expectedBlobId: input.binding.blobId,\n });\n return { bytes, contentKey: context.contentKey };\n}\n\nexport async function decryptDocumentAttachmentBlob(\n input: DecryptDocumentAttachmentBlobInput,\n): Promise<BlobBytes> {\n return (await decryptDocumentAttachmentBlobWithKey(input)).bytes;\n}\n\nfunction assertStringSetEquals(input: {\n readonly actual: readonly string[];\n readonly expected: readonly string[];\n readonly label: string;\n}): void {\n const actual = uniqueSortedStrings(input.actual);\n const expected = uniqueSortedStrings(input.expected);\n if (\n actual.length !== expected.length ||\n actual.some((value, index) => value !== expected[index])\n ) {\n throw new Error(`${input.label} is inconsistent`);\n }\n}\n\nasync function verifiedBlobKekTargetsForBinding(input: {\n readonly binding: DecryptDocumentAttachmentBlobInput[\"binding\"];\n readonly requireBindingMembership: boolean;\n readonly projection: BlobKekTargetsResponse | undefined;\n}) {\n const { binding, projection } = input;\n if (!projection) {\n throw new Error(\"Attachment binding lacks blob KEK verification material\");\n }\n const targets = sortBlobTargets(\n projection.targets.map((target, index) =>\n readBlobKekTarget(target, `Attachment blob KEK target[${index}]`),\n ),\n );\n const targetHash = await computeBlobContentKeyTargetHash(targets);\n if (\n targetHash !== projection.blobKeyTargetHash ||\n projection.blobId !== binding.blobId\n ) {\n throw new Error(\"Attachment blob KEK target hash is inconsistent\");\n }\n if (\n input.requireBindingMembership &&\n (!projection.activeBindingIds.includes(binding.bindingId) ||\n !targets.some(\n (target) =>\n target.bindingId === binding.bindingId &&\n target.documentId === attachmentBindingDocumentId(binding),\n ))\n ) {\n throw new Error(\"Attachment binding is absent from blob KEK targets\");\n }\n assertStringSetEquals({\n actual: projection.linkedContainerManifestHashes,\n expected: targets.map((target) => target.containerManifestHash),\n label: \"Attachment blob container manifests\",\n });\n assertStringSetEquals({\n actual: projection.linkedContainerKeyEpochIds,\n expected: targets.map((target) => target.containerKeyEpochId),\n label: \"Attachment blob container KEKs\",\n });\n const accessManifestHash = await computeBlobAccessManifestHash({\n version: 1,\n blobId: projection.blobId,\n organizationId: projection.organizationId,\n activeBindingIds: projection.activeBindingIds,\n documentManifestHashes: projection.documentManifestHashes,\n linkedContainerManifestHashes: projection.linkedContainerManifestHashes,\n linkedContainerKeyEpochIds: projection.linkedContainerKeyEpochIds,\n blobKeyTargetHash: projection.blobKeyTargetHash,\n });\n if (accessManifestHash !== projection.blobAccessManifestHash) {\n throw new Error(\"Attachment blob access manifest hash is inconsistent\");\n }\n return makeVerifiedBlobKekTargets({ ...projection, targets });\n}\n\nfunction attachmentBindingDocumentId(\n binding: DecryptDocumentAttachmentBlobInput[\"binding\"],\n): string {\n if (!binding.bindingEvent) {\n throw new Error(\"Attachment binding lacks a signed event\");\n }\n return readRecordString(\n readCanonicalRecord(\n binding.bindingEvent.body,\n \"Attachment binding event body\",\n ),\n \"documentId\",\n \"Attachment binding event body\",\n );\n}\n\nasync function assertBlobWriteHeaderVerified(input: {\n readonly authorization: DocumentWriterProjectionAuthorization | undefined;\n readonly binding: DecryptDocumentAttachmentBlobInput[\"binding\"];\n readonly encrypted: BlobEncryptedBytesHeader;\n readonly organizationId: string;\n readonly resolveProjectionUserKey: ReturnType<\n typeof requireProjectionUserKeyResolver\n >;\n}): Promise<void> {\n if (!input.authorization || !input.binding.writeHeader) {\n throw new Error(\"Attachment blob lacks verified write authority\");\n }\n const header = readWriteHeader(\n input.binding.writeHeader,\n \"Attachment blob write header\",\n );\n const writer = await input.resolveProjectionUserKey(header.writerUserId);\n if (!writer) {\n throw new Error(\"Attachment blob writer identity is unavailable\");\n }\n await verifiedBlobKekTargetsForBinding({\n binding: input.binding,\n projection: input.binding.blobKekTargets,\n requireBindingMembership: true,\n });\n const blobKekTargets = await verifiedBlobKekTargetsForBinding({\n binding: input.binding,\n projection: input.binding.writeAuthorization,\n // The signed binding proves which slot exposes the blob now. Writer\n // authorization describes the older target set committed when the bytes\n // were written, so a later valid binding need not appear in that set.\n requireBindingMembership: false,\n });\n if (\n header.metadataHash !== input.encrypted.metadataHash ||\n header.contentKeyEpoch !== input.encrypted.contentKeyEpoch ||\n header.contentRecordId !== input.encrypted.contentRecordId ||\n header.nonceDomainHash !== input.encrypted.nonceDomainHash\n ) {\n throw new Error(\"Attachment blob write header does not match ciphertext\");\n }\n const verified = await verifyWriteHeader({\n authorizationMembership: \"referenced\",\n blobAuthorization: {\n authorizingContainerPaths: resolveEventContainerPaths({\n containerPathByManifestHash:\n input.authorization.containerPathByManifestHash,\n dependencyManifestHashes: header.dependencyManifestHashes,\n }).dependencyContainerPaths,\n blobKekTargets,\n principalPolicies: input.authorization.principalPolicies,\n },\n expectedAccessManifestHash: blobKekTargets.blobAccessManifestHash,\n expectedObject: {\n objectKind: \"blob\",\n objectId: input.binding.blobId,\n organizationId: input.organizationId,\n },\n expectedTargetHash: blobKekTargets.blobKeyTargetHash,\n header,\n writerPublicKey: writer.signingPublicKey,\n });\n if (!verified.ok) {\n throw verified.error;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"decrypt.js","sourceRoot":"","sources":["decrypt.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,UAAU,EACV,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,mCAAmC,EACnC,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,4BAA4B,EAC5B,eAAe,GAChB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,oCAAoC,EAAE,MAAM,2CAA2C,CAAC;AAMjG,OAAO,EAAE,wBAAwB,EAAE,MAAM,kDAAkD,CAAC;AAC5F,OAAO,EAAE,wCAAwC,EAAE,MAAM,2CAA2C,CAAC;AACrG,OAAO,EAAE,6BAA6B,EAAE,MAAM,yEAAyE,CAAC;AACxH,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,mBAAmB,GACpB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,mBAAmB,E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;QACD,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC;QACvC,uBAAuB,EAAE,YAAY;QACrC,iBAAiB,EAAE;YACjB,yBAAyB,EAAE,0BAA0B,CAAC;gBACpD,2BAA2B,EACzB,KAAK,CAAC,aAAa,CAAC,2BAA2B;gBACjD,wBAAwB,EAAE,MAAM,CAAC,wBAAwB;aAC1D,CAAC,CAAC,wBAAwB;YAC3B,cAAc;YACd,iBAAiB,EAAE,KAAK,CAAC,aAAa,CAAC,iBAAiB;SACzD;QACD,0BAA0B,EAAE,cAAc,CAAC,sBAAsB;QACjE,cAAc,EAAE;YACd,UAAU,EAAE,MAAM;YAClB,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;YAC9B,cAAc,EAAE,KAAK,CAAC,cAAc;SACrC;QACD,kBAAkB,EAAE,cAAc,CAAC,iBAAiB;QACpD,MAAM;QACN,eAAe,EAAE,MAAM,CAAC,gBAAgB;KACzC,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,QAAQ,CAAC,KAAK,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["import {\n blobContentMetadataHash,\n bytesToHex,\n CONTENT_RECORD_ENCRYPTION_SUITE,\n computeBlobAccessManifestHash,\n computeBlobContentKeyTargetHash,\n computeContentRecordNonceDomainHash,\n makeVerifiedBlobKekTargets,\n verifyWriteHeader,\n} from \"@tearleads/crypto\";\nimport type { BlobKekTargetsResponse } from \"@tearleads/validators/response\";\nimport { deriveBlobContentRecordKey } from \"../../../data/blobs/attachments/crypto\";\nimport { unwrapBlobContentKey } from \"../../../data/blobs/attachments/projection\";\nimport {\n parseBlobEncryptedBytes,\n readBlobKekTarget,\n readDocumentManifestIdentity,\n sortBlobTargets,\n} from \"../../../data/blobs/attachments/readers\";\nimport { assertBlobContentKeyBundleTargetHash } from \"../../../data/blobs/attachments/responses\";\nimport type {\n BlobEncryptedBytesHeader,\n DecryptDocumentAttachmentBlobInput,\n} from \"../../../data/blobs/attachments/types\";\nimport type { BlobBytes } from \"../../../data/blobs/blobContracts\";\nimport { importContentKeyMaterial } from \"../../../data/documents/shared/contentRecordKeys\";\nimport { assertDocumentWriterProjectionConsistent } from \"../../../data/documents/shared/projection\";\nimport { projectionVerificationOptions } from \"../../../data/documents/shared/projection/projectionVerificationOptions\";\nimport {\n asWebCryptoBytes,\n readWriteHeader,\n uniqueSortedStrings,\n} from \"../../../data/documents/shared/readers\";\nimport { readCanonicalRecord } from \"../../../data/keying/canonicalJson\";\nimport type { DocumentWriterProjectionAuthorization } from \"../../../data/keyingProjectionVerification\";\nimport {\n readRecordString,\n requireProjectionUserKeyResolver,\n resolveEventContainerPaths,\n} from \"../../../data/keyingProjectionVerification\";\n\nimport { assertAttachmentBindingVerified } from \"../verification/attachmentBindingVerification\";\nimport { assertBlobWrapScopeVerified } from \"../verification/verifiedWrapScope\";\nimport { decryptBlobChunks } from \"./blobChunkDecryption\";\n\nasync function assertBlobEncryptionMetadata(input: {\n readonly contentKeyBundle: DecryptDocumentAttachmentBlobInput[\"binding\"][\"contentKeyBundle\"];\n readonly encrypted: BlobEncryptedBytesHeader;\n readonly expectedBlobId: string;\n readonly organizationId: string;\n}): Promise<void> {\n const { contentKeyBundle, encrypted, expectedBlobId, organizationId } = input;\n if (\n encrypted.blobId !== expectedBlobId ||\n encrypted.contentRecordId !== expectedBlobId\n ) {\n throw new Error(\"Blob encrypted bytes blob id mismatch\");\n }\n if (\n encrypted.contentKeyEpoch !== contentKeyBundle.contentKeyEpoch ||\n contentKeyBundle.blobId !== expectedBlobId\n ) {\n throw new Error(\"Blob encrypted bytes content-key bundle mismatch\");\n }\n await assertBlobContentKeyBundleTargetHash(contentKeyBundle);\n\n const expectedNonceDomainHash = await computeContentRecordNonceDomainHash({\n version: 1,\n organizationId,\n objectKind: \"blob\",\n objectId: expectedBlobId,\n contentKeyEpoch: encrypted.contentKeyEpoch,\n encryptionSuite: CONTENT_RECORD_ENCRYPTION_SUITE,\n contentRecordId: encrypted.contentRecordId,\n });\n if (encrypted.nonceDomainHash !== expectedNonceDomainHash) {\n throw new Error(\"Blob encrypted bytes nonce domain mismatch\");\n }\n const expectedMetadataHash = await blobContentMetadataHash({\n blobId: expectedBlobId,\n byteLength: encrypted.byteLength,\n chunkCount: encrypted.chunkCount,\n chunkSize: encrypted.chunkSize,\n contentKeyEpoch: encrypted.contentKeyEpoch,\n });\n if (encrypted.metadataHash !== expectedMetadataHash) {\n throw new Error(\"Blob encrypted bytes metadata hash mismatch\");\n }\n}\n\nexport type AttachmentBlobDecryptionInput = Omit<\n DecryptDocumentAttachmentBlobInput,\n \"encryptedBytes\"\n> & {\n encrypted: BlobEncryptedBytesHeader;\n};\n\n/** Verifies metadata and authority; the caller must still authenticate ciphertext. */\nexport async function prepareDocumentAttachmentBlobDecryption({\n binding,\n encrypted,\n expectedDocumentId,\n expectedSlotId,\n execSql,\n resolveProjectionUserKey,\n targetSecretKey,\n stillCurrent,\n warmReferencedPrincipalPolicies,\n writerProjection,\n}: AttachmentBlobDecryptionInput): Promise<{\n contentKey: Uint8Array;\n recordKey: CryptoKey;\n organizationId: string;\n}> {\n const requiredResolveProjectionUserKey = requireProjectionUserKeyResolver(\n resolveProjectionUserKey,\n \"Document attachment blob decrypt\",\n );\n const verificationOptions = projectionVerificationOptions({\n execSql,\n stillCurrent,\n warmReferencedPrincipalPolicies,\n resolveProjectionUserKey: requiredResolveProjectionUserKey,\n });\n let documentAuthorization: DocumentWriterProjectionAuthorization | undefined;\n await assertDocumentWriterProjectionConsistent(writerProjection, {\n allowStaleContentKeyBundle: true,\n execSql,\n onVerifiedAuthorization: (authorization) => {\n documentAuthorization = authorization;\n },\n ...verificationOptions,\n });\n const { documentId, organizationId } =\n readDocumentManifestIdentity(writerProjection);\n await assertBlobEncryptionMetadata({\n contentKeyBundle: binding.contentKeyBundle,\n encrypted,\n expectedBlobId: binding.blobId,\n organizationId,\n });\n await assertAttachmentBindingVerified({\n authorization: documentAuthorization,\n binding,\n expectedDocumentId,\n expectedSlotId,\n resolveProjectionUserKey: requiredResolveProjectionUserKey,\n });\n await assertBlobWriteHeaderVerified({\n authorization: documentAuthorization,\n binding,\n encrypted,\n organizationId,\n resolveProjectionUserKey: requiredResolveProjectionUserKey,\n });\n\n if (!documentAuthorization)\n throw new Error(\"Blob document authorization is unavailable\");\n assertBlobWrapScopeVerified({\n authorization: documentAuthorization,\n binding,\n documentId,\n });\n const contentKey = await unwrapBlobContentKey({\n blobId: binding.blobId,\n contentKeyBundle: binding.contentKeyBundle,\n documentId,\n encrypted,\n execSql,\n expectedBindingId: binding.bindingId,\n secretKey: targetSecretKey,\n ...verificationOptions,\n writerProjection,\n });\n const contentKeyMaterial = await importContentKeyMaterial(contentKey);\n const recordKey = await deriveBlobContentRecordKey({\n blobId: binding.blobId,\n contentKeyEpoch: encrypted.contentKeyEpoch,\n contentKeyMaterial,\n contentRecordId: encrypted.contentRecordId,\n organizationId,\n usage: \"decrypt\",\n });\n return { contentKey, recordKey, organizationId };\n}\n\nasync function decryptDocumentAttachmentBlobWithKey(\n input: DecryptDocumentAttachmentBlobInput,\n): Promise<{ bytes: BlobBytes; contentKey: Uint8Array }> {\n const encrypted = parseBlobEncryptedBytes(input.encryptedBytes);\n const context = await prepareDocumentAttachmentBlobDecryption({\n ...input,\n encrypted,\n });\n const header = readWriteHeader(\n input.binding.writeHeader,\n \"Attachment blob write header\",\n );\n const ciphertextHash = bytesToHex(\n new Uint8Array(\n await crypto.subtle.digest(\n \"SHA-256\",\n asWebCryptoBytes(input.encryptedBytes),\n ),\n ),\n );\n if (header.ciphertextHash !== ciphertextHash)\n throw new Error(\"Attachment blob write header does not match ciphertext\");\n const bytes = await decryptBlobChunks({\n ...context,\n encrypted,\n expectedBlobId: input.binding.blobId,\n });\n return { bytes, contentKey: context.contentKey };\n}\n\nexport async function decryptDocumentAttachmentBlob(\n input: DecryptDocumentAttachmentBlobInput,\n): Promise<BlobBytes> {\n return (await decryptDocumentAttachmentBlobWithKey(input)).bytes;\n}\n\nfunction assertStringSetEquals(input: {\n readonly actual: readonly string[];\n readonly expected: readonly string[];\n readonly label: string;\n}): void {\n const actual = uniqueSortedStrings(input.actual);\n const expected = uniqueSortedStrings(input.expected);\n if (\n actual.length !== expected.length ||\n actual.some((value, index) => value !== expected[index])\n ) {\n throw new Error(`${input.label} is inconsistent`);\n }\n}\n\nasync function verifiedBlobKekTargetsForBinding(input: {\n readonly binding: DecryptDocumentAttachmentBlobInput[\"binding\"];\n readonly requireBindingMembership: boolean;\n readonly projection: BlobKekTargetsResponse | undefined;\n}) {\n const { binding, projection } = input;\n if (!projection) {\n throw new Error(\"Attachment binding lacks blob KEK verification material\");\n }\n const targets = sortBlobTargets(\n projection.targets.map((target, index) =>\n readBlobKekTarget(target, `Attachment blob KEK target[${index}]`),\n ),\n );\n const targetHash = await computeBlobContentKeyTargetHash(targets);\n if (\n targetHash !== projection.blobKeyTargetHash ||\n projection.blobId !== binding.blobId\n ) {\n throw new Error(\"Attachment blob KEK target hash is inconsistent\");\n }\n if (\n input.requireBindingMembership &&\n (!projection.activeBindingIds.includes(binding.bindingId) ||\n !targets.some(\n (target) =>\n target.bindingId === binding.bindingId &&\n target.documentId === attachmentBindingDocumentId(binding),\n ))\n ) {\n throw new Error(\"Attachment binding is absent from blob KEK targets\");\n }\n assertStringSetEquals({\n actual: projection.linkedContainerManifestHashes,\n expected: targets.map((target) => target.containerManifestHash),\n label: \"Attachment blob container manifests\",\n });\n assertStringSetEquals({\n actual: projection.linkedContainerKeyEpochIds,\n expected: targets.map((target) => target.containerKeyEpochId),\n label: \"Attachment blob container KEKs\",\n });\n const accessManifestHash = await computeBlobAccessManifestHash({\n version: 1,\n blobId: projection.blobId,\n organizationId: projection.organizationId,\n activeBindingIds: projection.activeBindingIds,\n documentManifestHashes: projection.documentManifestHashes,\n linkedContainerManifestHashes: projection.linkedContainerManifestHashes,\n linkedContainerKeyEpochIds: projection.linkedContainerKeyEpochIds,\n blobKeyTargetHash: projection.blobKeyTargetHash,\n });\n if (accessManifestHash !== projection.blobAccessManifestHash) {\n throw new Error(\"Attachment blob access manifest hash is inconsistent\");\n }\n return makeVerifiedBlobKekTargets({ ...projection, targets });\n}\n\nfunction attachmentBindingDocumentId(\n binding: DecryptDocumentAttachmentBlobInput[\"binding\"],\n): string {\n if (!binding.bindingEvent) {\n throw new Error(\"Attachment binding lacks a signed event\");\n }\n return readRecordString(\n readCanonicalRecord(\n binding.bindingEvent.body,\n \"Attachment binding event body\",\n ),\n \"documentId\",\n \"Attachment binding event body\",\n );\n}\n\n/**\n * The listing omits the write's target set when its hash equals the current\n * set's, so refill it from `blobKekTargets`; verification re-hashes it against\n * the write authorization and the signed header. Any other omission fails.\n */\nfunction writeAuthorizationWithTargets(\n binding: DecryptDocumentAttachmentBlobInput[\"binding\"],\n): BlobKekTargetsResponse | undefined {\n const { blobKekTargets, writeAuthorization } = binding;\n if (!writeAuthorization) return undefined;\n if (writeAuthorization.targets)\n return { ...writeAuthorization, targets: writeAuthorization.targets };\n if (\n !blobKekTargets ||\n writeAuthorization.blobKeyTargetHash !== blobKekTargets.blobKeyTargetHash\n )\n throw new Error(\"Attachment blob write authorization lacks its targets\");\n return { ...writeAuthorization, targets: blobKekTargets.targets };\n}\n\nasync function assertBlobWriteHeaderVerified(input: {\n readonly authorization: DocumentWriterProjectionAuthorization | undefined;\n readonly binding: DecryptDocumentAttachmentBlobInput[\"binding\"];\n readonly encrypted: BlobEncryptedBytesHeader;\n readonly organizationId: string;\n readonly resolveProjectionUserKey: ReturnType<\n typeof requireProjectionUserKeyResolver\n >;\n}): Promise<void> {\n if (!input.authorization || !input.binding.writeHeader) {\n throw new Error(\"Attachment blob lacks verified write authority\");\n }\n const header = readWriteHeader(\n input.binding.writeHeader,\n \"Attachment blob write header\",\n );\n const writer = await input.resolveProjectionUserKey(header.writerUserId);\n if (!writer) {\n throw new Error(\"Attachment blob writer identity is unavailable\");\n }\n await verifiedBlobKekTargetsForBinding({\n binding: input.binding,\n projection: input.binding.blobKekTargets,\n requireBindingMembership: true,\n });\n const blobKekTargets = await verifiedBlobKekTargetsForBinding({\n binding: input.binding,\n projection: writeAuthorizationWithTargets(input.binding),\n // The signed binding proves which slot exposes the blob now. Writer\n // authorization describes the older target set committed when the bytes\n // were written, so a later valid binding need not appear in that set.\n requireBindingMembership: false,\n });\n if (\n header.metadataHash !== input.encrypted.metadataHash ||\n header.contentKeyEpoch !== input.encrypted.contentKeyEpoch ||\n header.contentRecordId !== input.encrypted.contentRecordId ||\n header.nonceDomainHash !== input.encrypted.nonceDomainHash\n ) {\n throw new Error(\"Attachment blob write header does not match ciphertext\");\n }\n const verified = await verifyWriteHeader({\n authorizationMembership: \"referenced\",\n blobAuthorization: {\n authorizingContainerPaths: resolveEventContainerPaths({\n containerPathByManifestHash:\n input.authorization.containerPathByManifestHash,\n dependencyManifestHashes: header.dependencyManifestHashes,\n }).dependencyContainerPaths,\n blobKekTargets,\n principalPolicies: input.authorization.principalPolicies,\n },\n expectedAccessManifestHash: blobKekTargets.blobAccessManifestHash,\n expectedObject: {\n objectKind: \"blob\",\n objectId: input.binding.blobId,\n organizationId: input.organizationId,\n },\n expectedTargetHash: blobKekTargets.blobKeyTargetHash,\n header,\n writerPublicKey: writer.signingPublicKey,\n });\n if (!verified.ok) {\n throw verified.error;\n }\n}\n"]}
|
|
@@ -19,19 +19,25 @@ export declare function createLinkSetAttachmentReuse(): LinkSetAttachmentReuse;
|
|
|
19
19
|
* was authenticated or wrapped by this device before that leg signed it, so a
|
|
20
20
|
* reuse propagates no key to a new scope; any target the previous leg did not
|
|
21
21
|
* wrap returns null and the leg lists and authenticates as usual. A bind or
|
|
22
|
-
* detach in between
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* detach in between makes the API refuse with a coded 409
|
|
23
|
+
* (`document_link_attachments_changed`); a content-key epoch change or a
|
|
24
|
+
* re-entered retired target (the API keeps its stored wrap over the fresh one)
|
|
25
|
+
* with an uncoded one. The caller re-lists once.
|
|
25
26
|
*/
|
|
26
27
|
export declare function reuseCommittedBlobRewraps(input: {
|
|
27
28
|
committed: BlobRewraps;
|
|
28
29
|
documentId: string;
|
|
29
30
|
targets: readonly DocumentContentKeyTarget[];
|
|
30
31
|
}): BlobRewraps | null;
|
|
31
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Authenticate the existing bytes before propagating their DEK to a new scope.
|
|
34
|
+
* `refreshListing` bypasses a cached listing, after the server refused a leg
|
|
35
|
+
* because its attachments changed.
|
|
36
|
+
*/
|
|
32
37
|
export declare function prepareDocumentLinkBlobRewraps(input: {
|
|
33
38
|
apiClient: DocumentLinkSetMutationApi;
|
|
34
39
|
execSql: ExecSql;
|
|
40
|
+
refreshListing?: boolean | undefined;
|
|
35
41
|
targetContainerProjection: ContainerWriterProjectionResponse;
|
|
36
42
|
targetSecretKey: Uint8Array;
|
|
37
43
|
targets: readonly DocumentContentKeyTarget[];
|