@tearleads/client-sdk 0.1.243 → 0.1.244
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/organizations/principalMutations.d.ts +5 -0
- package/data/containers/shared/mutationAcknowledgement.d.ts +1 -1
- package/data/containers/shared/mutationAcknowledgement.js +3 -8
- package/data/containers/shared/mutationAcknowledgement.js.map +1 -1
- package/data/documents/shared/sync/mutationAcknowledgement.js +11 -2
- package/data/documents/shared/sync/mutationAcknowledgement.js.map +1 -1
- package/data/keyingProjectionVerification/checkpoints/heldBundleRecovery.d.ts +26 -0
- package/data/keyingProjectionVerification/checkpoints/heldBundleRecovery.js +46 -0
- package/data/keyingProjectionVerification/checkpoints/heldBundleRecovery.js.map +1 -0
- package/data/keyingProjectionVerification/container/containerDestinationVerification.d.ts +7 -4
- package/data/keyingProjectionVerification/container/containerDestinationVerification.js +5 -1
- package/data/keyingProjectionVerification/container/containerDestinationVerification.js.map +1 -1
- package/data/keyingProjectionVerification/container/containerProjectionVerification.js +9 -2
- package/data/keyingProjectionVerification/container/containerProjectionVerification.js.map +1 -1
- package/data/keyingProjectionVerification/document/documentContainerProjections.js +2 -1
- package/data/keyingProjectionVerification/document/documentContainerProjections.js.map +1 -1
- package/data/keyingProjectionVerification/document/documentProjectionVerification.js +9 -2
- package/data/keyingProjectionVerification/document/documentProjectionVerification.js.map +1 -1
- package/data/keyingProjectionVerification/index.d.ts +1 -0
- package/data/keyingProjectionVerification/index.js +1 -0
- package/data/keyingProjectionVerification/index.js.map +1 -1
- package/data/persistence/keyingCheckpoints/keyingCheckpointRepository.js +16 -4
- package/data/persistence/keyingCheckpoints/keyingCheckpointRepository.js.map +1 -1
- package/data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.d.ts +13 -0
- package/data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.js +11 -0
- package/data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.js.map +1 -1
- package/data/persistence/verifiedCitations/authoredBundleCitation.d.ts +20 -0
- package/data/persistence/verifiedCitations/authoredBundleCitation.js +32 -0
- package/data/persistence/verifiedCitations/authoredBundleCitation.js.map +1 -0
- package/data/persistence/verifiedManifestBundlePersistence.d.ts +10 -0
- package/data/persistence/verifiedManifestBundlePersistence.js +95 -9
- package/data/persistence/verifiedManifestBundlePersistence.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +55 -0
- package/internal/api-client/client/containerMutations.d.ts +11 -0
- package/internal/api-client/client/documents.d.ts +5 -0
- package/internal/api-client/client/organizations.d.ts +20 -0
- package/internal/api-client/client/principalPolicies.d.ts +9 -0
- package/internal/api-client/client/session.d.ts +10 -0
- package/internal/api-client/principalPolicyRequests.d.ts +7 -0
- package/internal/api-client/writerProjectionCitations.d.ts +3 -0
- package/internal/api-client/writerProjectionCitations.js +12 -0
- package/internal/api-client/writerProjectionCitations.js.map +1 -1
- package/internal/crypto/index.d.ts +1 -1
- package/internal/crypto/index.js +1 -1
- package/internal/crypto/index.js.map +1 -1
- package/internal/crypto/keying/canonicalJsonGuard.d.ts +13 -0
- package/internal/crypto/keying/canonicalJsonGuard.js +23 -0
- package/internal/crypto/keying/canonicalJsonGuard.js.map +1 -1
- package/internal/crypto/keying/index.d.ts +1 -1
- package/internal/crypto/keying/index.js +1 -1
- package/internal/crypto/keying/index.js.map +1 -1
- package/internal/crypto/keying/keyingHashDomains.d.ts +1 -1
- package/internal/crypto/keying/keyingHashDomains.js.map +1 -1
- package/internal/validators/operation/auth.d.ts +40 -0
- package/internal/validators/operation/containerMutations.d.ts +44 -0
- package/internal/validators/operation/documentMutations.d.ts +12 -0
- package/internal/validators/operation/organizations.d.ts +48 -0
- package/internal/validators/operation/principals.d.ts +16 -0
- package/internal/validators/response/areas/containers.d.ts +1 -1
- package/internal/validators/response/areas/containers.js +1 -1
- package/internal/validators/response/areas/containers.js.map +1 -1
- package/internal/validators/response/container.d.ts +16 -0
- package/internal/validators/response/container.js +3 -0
- package/internal/validators/response/container.js.map +1 -1
- package/internal/validators/response/containerMetadata.d.ts +8 -0
- package/internal/validators/response/documentMutation.d.ts +8 -0
- package/internal/validators/response/documentMutation.js +2 -1
- package/internal/validators/response/documentMutation.js.map +1 -1
- package/internal/validators/response/organization.d.ts +8 -0
- package/internal/validators/response/organizationProvisioning.d.ts +113 -0
- package/internal/validators/response/organizationProvisioning.js +2 -1
- package/internal/validators/response/organizationProvisioning.js.map +1 -1
- package/internal/validators/response/principal.d.ts +16 -0
- package/internal/validators/response/registration.d.ts +40 -0
- package/internal/validators/response/writerProjectionWire.d.ts +25 -0
- package/internal/validators/response/writerProjectionWire.js +109 -3
- package/internal/validators/response/writerProjectionWire.js.map +1 -1
- package/package.json +1 -1
- package/stores/documents/documentStore/rotation/index.js +3 -1
- package/stores/documents/documentStore/rotation/index.js.map +1 -1
- package/stores/documents/documentStore/sync/syncAttachments.js +4 -1
- package/stores/documents/documentStore/sync/syncAttachments.js.map +1 -1
- package/stores/documents/documentStore/sync/syncDetachedAttachments.js +3 -1
- package/stores/documents/documentStore/sync/syncDetachedAttachments.js.map +1 -1
- package/stores/documents/documentStore/sync/syncRequest.js +3 -1
- package/stores/documents/documentStore/sync/syncRequest.js.map +1 -1
- package/workflows/container-contents/container-state/create/createAdoption.js +11 -3
- package/workflows/container-contents/container-state/create/createAdoption.js.map +1 -1
- package/workflows/container-contents/container-state/create/createWithMetadata.js +2 -2
- package/workflows/container-contents/container-state/create/createWithMetadata.js.map +1 -1
- package/workflows/container-contents/container-state/projectionCache.js +3 -0
- package/workflows/container-contents/container-state/projectionCache.js.map +1 -1
- package/workflows/container-contents/metadata/index.js +5 -2
- package/workflows/container-contents/metadata/index.js.map +1 -1
- package/workflows/containers/child/recite.js +4 -2
- package/workflows/containers/child/recite.js.map +1 -1
- package/workflows/documents/create/createAdoption.js +11 -2
- package/workflows/documents/create/createAdoption.js.map +1 -1
- package/workflows/documents/create/createResponse.js +1 -0
- package/workflows/documents/create/createResponse.js.map +1 -1
- package/workflows/documents/linkSet/linkSetRemote.js +1 -0
- package/workflows/documents/linkSet/linkSetRemote.js.map +1 -1
- package/workflows/documents/sync/syncAttemptPlanning.js +8 -2
- package/workflows/documents/sync/syncAttemptPlanning.js.map +1 -1
- package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js +3 -2
- package/workflows/documents/syncRekeys/syncAutomaticContainerRekeys.js.map +1 -1
- package/workflows/documents/syncRekeys/syncContainerRekeyProjection.js +3 -2
- package/workflows/documents/syncRekeys/syncContainerRekeyProjection.js.map +1 -1
- package/workflows/registration/organizationCreation/organizationCreationIntent.d.ts +10 -0
- package/workflows/registration/provisioningAcknowledgement.js +16 -11
- package/workflows/registration/provisioningAcknowledgement.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentProjectionVerification.js","sourceRoot":"","sources":["documentProjectionVerification.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EACL,iCAAiC,EACjC,6BAA6B,EAC7B,gCAAgC,EAChC,wBAAwB,EACxB,gCAAgC,GAEjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,0CAA0C,GAC3C,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,8BAA8B,EAAE,MAAM,qDAAqD,CAAC;AACrG,OAAO,EAAE,mCAAmC,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,qCAAqC,EAAE,MAAM,oDAAoD,CAAC;AAC3G,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAOhD,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,iCAAiC,EAAE,MAAM,gCAAgC,CA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YAC1D,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,+BAA+B,EAAE,KAAK,CAAC,+BAA+B;SACvE,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,yCAAyC,CAC9D,iCAAiC,CAAC,KAAK,CAAC,EACxC,iBAAiB,CAClB,CAAC;QACF,wCAAwC,CACtC,iBAAiB,EACjB,KAAK,CAAC,UAAU,EAChB,QAAQ,CAAC,aAAa,CACvB,CAAC;QACF,MAAM,6BAA6B,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,QAAQ,CAAC,aAAa,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mCAAmC,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC","sourcesContent":["import type {\n PrincipalPolicyAuthorization,\n VerifiedContainerAccessManifest,\n VerifiedDocumentLinkSetManifest,\n VerifiedPrincipalPolicy,\n} from \"@tearleads/crypto\";\nimport type {\n AccessManifestBundleWireResponse,\n DocumentWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport type { ExecSql } from \"../../sqlite/sqlSchema\";\nimport { addBundleByHash } from \"../checkpoints/bundleVerification\";\nimport {\n createProjectionCheckpointContext,\n finalizeProjectionCheckpoints,\n observeAccessManifestCheckpoints,\n observeVerifiedKekLevels,\n observeVerifiedProjectionBundles,\n type ProjectionCheckpointContext,\n} from \"../checkpoints/checkpointContext\";\nimport { verifyContainerManifestPath } from \"../container/containerPathVerification\";\nimport {\n addContainerWriterProjectionBundles,\n verifiedContainerManifestsForBundles,\n verifyContainerWriterProjectionWithContext,\n} from \"../container/containerProjectionVerification\";\nimport { rejectPurgedDocumentProjection } from \"../documentPurge/documentPurgeCheckpointEnforcement\";\nimport { throwKeyingVerificationShapeFailure } from \"../error\";\nimport { verifyProjectionAuthorizationEvidence } from \"../principalPolicy/projectionAuthorizationEvidence\";\nimport { readAccessManifest } from \"../readers\";\nimport type {\n OpenPrincipalPolicyBundleReader,\n PrincipalPolicyCache,\n ProjectionUserKeyResolver,\n ReferencedPrincipalPolicyWarmer,\n} from \"../types\";\nimport { withGenerationGuardedPolicyWarmer } from \"../types\";\nimport { documentContainerProjections } from \"./documentContainerProjections\";\nimport { verifyDocumentProjectionManifests } from \"./documentManifestVerification\";\n\ntype VerifiedManifestMap = Map<string, VerifiedContainerAccessManifest>;\ntype PolicyWarmer = ReferencedPrincipalPolicyWarmer | undefined;\n\nfunction readDocumentProjectionContainerPaths(\n projection: DocumentWriterProjectionResponse,\n): AccessManifestBundleWireResponse[][] {\n return [\n ...projection.documentManifestContainerPaths,\n ...projection.authorizingContainerPaths.map((path) => path.path),\n ];\n}\n\nfunction collectDocumentProjectionContainerBundles(\n projection: DocumentWriterProjectionResponse,\n): Map<string, AccessManifestBundleWireResponse> {\n const bundlesByHash = new Map<string, AccessManifestBundleWireResponse>();\n for (const [index, authorizing] of documentContainerProjections(\n projection,\n ).entries()) {\n addContainerWriterProjectionBundles(\n bundlesByHash,\n authorizing,\n `Document writer projection authorizing path[${index}]`,\n );\n }\n for (const [index, path] of readDocumentProjectionContainerPaths(\n projection,\n ).entries()) {\n for (const [pathIndex, bundle] of path.entries()) {\n addBundleByHash(\n bundlesByHash,\n bundle,\n `Document writer projection dependency path[${index}][${pathIndex}]`,\n );\n }\n }\n for (const [\n index,\n bundle,\n ] of projection.documentContainerManifestHistory.entries()) {\n addBundleByHash(\n bundlesByHash,\n bundle,\n `Document writer projection container history[${index}]`,\n );\n }\n return bundlesByHash;\n}\n\nasync function verifyProjectionContainerPaths(input: {\n readonly authorizationEvidence: readonly PrincipalPolicyAuthorization[];\n readonly checkpointContext: ProjectionCheckpointContext;\n readonly principalPolicyCache: PrincipalPolicyCache;\n readonly projection: DocumentWriterProjectionResponse;\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly verifiedByHash?: VerifiedManifestMap | undefined;\n readonly warmReferencedPrincipalPolicies?: PolicyWarmer;\n}): Promise<Map<string, readonly VerifiedContainerAccessManifest[]>> {\n const bundlesByHash = collectDocumentProjectionContainerBundles(\n input.projection,\n );\n const containerPathByManifestHash = new Map<\n string,\n readonly VerifiedContainerAccessManifest[]\n >();\n // Reuse a caller-supplied cache when provided so a later unwrap pass over the\n // same authorizing container paths does not re-verify identical manifests.\n const verifiedByHash =\n input.verifiedByHash ?? new Map<string, VerifiedContainerAccessManifest>();\n for (const projection of documentContainerProjections(input.projection)) {\n const path = await verifyContainerWriterProjectionWithContext(\n {\n authorizationEvidence: input.authorizationEvidence,\n principalPolicyCache: input.principalPolicyCache,\n projection,\n resolveUserKey: input.resolveUserKey,\n verifiedByHash,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n },\n input.checkpointContext,\n );\n const leaf = path.at(-1);\n if (leaf) {\n containerPathByManifestHash.set(leaf.manifestHash, path);\n }\n for (const manifest of path) {\n verifiedByHash.set(manifest.manifestHash, manifest);\n }\n }\n // Grouping supplies evidence only; each signed artifact selects its citations.\n for (const [\n index,\n path,\n ] of input.projection.documentManifestContainerPaths.entries()) {\n // Historical dependency evidence is verified without current checkpoint\n // enforcement. Its grouping cannot substitute an uncited ancestor into\n // document or content-write authorization.\n const verifiedPath = await verifyContainerManifestPath({\n authorizationEvidence: input.authorizationEvidence,\n requireAuthorizationEvidence: true,\n servedAsCurrent: false,\n authorizationMembership: \"referenced\",\n bundlesByHash,\n checkpointContext: input.checkpointContext,\n enforceLocalCheckpoints: false,\n label: `Document writer projection dependency path[${index}]`,\n path,\n principalPolicyCache: input.principalPolicyCache,\n resolveUserKey: input.resolveUserKey,\n verifiedByHash,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n // The authorizing path recorded for the same leaf takes precedence.\n const leaf = verifiedPath.at(-1);\n if (leaf && !containerPathByManifestHash.has(leaf.manifestHash)) {\n containerPathByManifestHash.set(leaf.manifestHash, verifiedPath);\n }\n }\n\n // Keep every verified head as evidence. Events and content headers select\n // their own signed paths through resolveEventContainerPaths.\n for (const [hash, manifest] of verifiedByHash) {\n if (!containerPathByManifestHash.has(hash))\n containerPathByManifestHash.set(hash, [manifest]);\n }\n\n observeAccessManifestCheckpoints(input.checkpointContext, {\n verifiedHeads: [],\n verifiedManifests: verifiedContainerManifestsForBundles(\n bundlesByHash,\n verifiedByHash,\n ),\n });\n\n return containerPathByManifestHash;\n}\n\ninterface DocumentWriterProjectionVerificationInput {\n readonly execSql: ExecSql;\n readonly openPrincipalPolicyBundleReader: OpenPrincipalPolicyBundleReader;\n readonly persistVerificationCheckpoints?: boolean | undefined;\n readonly principalPolicyCache?: PrincipalPolicyCache | undefined;\n readonly projection: DocumentWriterProjectionResponse;\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly stillCurrent?: (() => boolean) | undefined;\n readonly verifiedByHash?: VerifiedManifestMap | undefined;\n readonly warmReferencedPrincipalPolicies?: PolicyWarmer;\n}\nexport interface DocumentWriterProjectionAuthorization {\n readonly containerPathByManifestHash: ReadonlyMap<\n string,\n readonly VerifiedContainerAccessManifest[]\n >;\n readonly documentManifestByHash: ReadonlyMap<\n string,\n VerifiedDocumentLinkSetManifest\n >;\n readonly principalPolicies: readonly PrincipalPolicyAuthorization[];\n}\n\ninterface VerifiedDocumentWriterProjectionResult {\n readonly authorization: DocumentWriterProjectionAuthorization;\n readonly headManifest: VerifiedDocumentLinkSetManifest;\n}\n\nasync function verifyDocumentWriterProjectionWithContext(\n input: Omit<DocumentWriterProjectionVerificationInput, \"execSql\">,\n checkpointContext: ProjectionCheckpointContext,\n): Promise<VerifiedDocumentWriterProjectionResult> {\n const principalPolicyCache =\n input.principalPolicyCache ?? new Map<string, VerifiedPrincipalPolicy>();\n const authorizationEvidence = await verifyProjectionAuthorizationEvidence({\n bundles: [\n input.projection.documentManifest,\n ...input.projection.documentManifestHistory,\n ...collectDocumentProjectionContainerBundles(input.projection).values(),\n ],\n checkpointContext,\n policyEvidence: input.projection.policyEvidence,\n organizationId: readAccessManifest(\n input.projection.documentManifest.manifest,\n \"Document projection manifest\",\n ).organizationId,\n principalPolicyCache,\n resolveUserKey: input.resolveUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n const containerPathByManifestHash = await verifyProjectionContainerPaths({\n authorizationEvidence,\n checkpointContext,\n principalPolicyCache,\n projection: input.projection,\n resolveUserKey: input.resolveUserKey,\n verifiedByHash: input.verifiedByHash,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n const { headManifest, verifiedByHash } =\n await verifyDocumentProjectionManifests({\n authorizationEvidence,\n checkpointContext,\n containerPathByManifestHash,\n principalPolicyCache,\n projection: input.projection,\n resolveUserKey: input.resolveUserKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n await rejectPurgedDocumentProjection(\n headManifest.state.documentId,\n checkpointContext.execSql,\n );\n\n observeAccessManifestCheckpoints(checkpointContext, {\n verifiedHeads: [headManifest],\n verifiedManifests: [...verifiedByHash.values()],\n });\n\n return {\n authorization: {\n containerPathByManifestHash,\n documentManifestByHash: verifiedByHash,\n principalPolicies: authorizationEvidence,\n },\n headManifest,\n };\n}\n\n/** Each served bundle, document and container, whose manifest verified. */\nfunction observeVerifiedDocumentProjectionBundles(\n checkpointContext: ProjectionCheckpointContext,\n projection: DocumentWriterProjectionResponse,\n authorization: DocumentWriterProjectionAuthorization,\n): void {\n observeVerifiedProjectionBundles(\n checkpointContext,\n new Map(\n [projection.documentManifest, ...projection.documentManifestHistory].map(\n (bundle) => [bundle.manifestHash, bundle],\n ),\n ),\n authorization.documentManifestByHash,\n );\n observeVerifiedProjectionBundles(\n checkpointContext,\n collectDocumentProjectionContainerBundles(projection),\n new Map(\n [...authorization.containerPathByManifestHash.values()]\n .flat()\n .map((manifest) => [manifest.manifestHash, manifest]),\n ),\n );\n observeVerifiedKekLevels(\n checkpointContext,\n projection.authorizingContainerPaths,\n );\n}\n\nexport async function verifyDocumentWriterProjection(\n input: DocumentWriterProjectionVerificationInput,\n): Promise<VerifiedDocumentLinkSetManifest> {\n const checkpointContext = createProjectionCheckpointContext({\n execSql: input.execSql,\n openPrincipalPolicyBundleReader: input.openPrincipalPolicyBundleReader,\n });\n const verified = await verifyDocumentWriterProjectionWithContext(\n withGenerationGuardedPolicyWarmer(input),\n checkpointContext,\n );\n observeVerifiedDocumentProjectionBundles(\n checkpointContext,\n input.projection,\n verified.authorization,\n );\n await finalizeProjectionCheckpoints(checkpointContext, input);\n return verified.headManifest;\n}\n\nexport async function verifyDocumentWriterProjectionAuthorization(\n input: DocumentWriterProjectionVerificationInput,\n): Promise<DocumentWriterProjectionAuthorization> {\n try {\n const checkpointContext = createProjectionCheckpointContext({\n execSql: input.execSql,\n openPrincipalPolicyBundleReader: input.openPrincipalPolicyBundleReader,\n });\n const verified = await verifyDocumentWriterProjectionWithContext(\n withGenerationGuardedPolicyWarmer(input),\n checkpointContext,\n );\n observeVerifiedDocumentProjectionBundles(\n checkpointContext,\n input.projection,\n verified.authorization,\n );\n await finalizeProjectionCheckpoints(checkpointContext, input);\n return verified.authorization;\n } catch (error) {\n throwKeyingVerificationShapeFailure(error);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentProjectionVerification.js","sourceRoot":"","sources":["documentProjectionVerification.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EACL,iCAAiC,EACjC,6BAA6B,EAC7B,gCAAgC,EAChC,wBAAwB,EACxB,gCAAgC,GAEjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,0CAA0C,GAC3C,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,8BAA8B,EAAE,MAAM,qDAAqD,CAAC;AACrG,OAAO,EAAE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,+BAA+B;KACvE,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,MAAM,yCAAyC,CAC9D,iCAAiC,CAAC,KAAK,CAAC,EACxC,iBAAiB,CAClB,CAAC;IACF,wCAAwC,CACtC,iBAAiB,EACjB,KAAK,CAAC,UAAU,EAChB,QAAQ,CAAC,aAAa,CACvB,CAAC;IACF,MAAM,6BAA6B,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IAC9D,OAAO,QAAQ,CAAC,YAAY,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,2CAA2C,CACzD,KAAgD;IAEhD,OAAO,4BAA4B,CAAC,KAAK,EAAE,GAAG,EAAE,CAC9C,+CAA+C,CAAC,KAAK,CAAC,CACvD,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,+CAA+C,CAC5D,KAAgD;IAEhD,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG,iCAAiC,CAAC;YAC1D,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,+BAA+B,EAAE,KAAK,CAAC,+BAA+B;SACvE,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,yCAAyC,CAC9D,iCAAiC,CAAC,KAAK,CAAC,EACxC,iBAAiB,CAClB,CAAC;QACF,wCAAwC,CACtC,iBAAiB,EACjB,KAAK,CAAC,UAAU,EAChB,QAAQ,CAAC,aAAa,CACvB,CAAC;QACF,MAAM,6BAA6B,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,QAAQ,CAAC,aAAa,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mCAAmC,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC","sourcesContent":["import type {\n PrincipalPolicyAuthorization,\n VerifiedContainerAccessManifest,\n VerifiedDocumentLinkSetManifest,\n VerifiedPrincipalPolicy,\n} from \"@tearleads/crypto\";\nimport type {\n AccessManifestBundleWireResponse,\n DocumentWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport type { ExecSql } from \"../../sqlite/sqlSchema\";\nimport { addBundleByHash } from \"../checkpoints/bundleVerification\";\nimport {\n createProjectionCheckpointContext,\n finalizeProjectionCheckpoints,\n observeAccessManifestCheckpoints,\n observeVerifiedKekLevels,\n observeVerifiedProjectionBundles,\n type ProjectionCheckpointContext,\n} from \"../checkpoints/checkpointContext\";\nimport { verifyWithHeldBundleRecovery } from \"../checkpoints/heldBundleRecovery\";\nimport { verifyContainerManifestPath } from \"../container/containerPathVerification\";\nimport {\n addContainerWriterProjectionBundles,\n verifiedContainerManifestsForBundles,\n verifyContainerWriterProjectionWithContext,\n} from \"../container/containerProjectionVerification\";\nimport { rejectPurgedDocumentProjection } from \"../documentPurge/documentPurgeCheckpointEnforcement\";\nimport { throwKeyingVerificationShapeFailure } from \"../error\";\nimport { verifyProjectionAuthorizationEvidence } from \"../principalPolicy/projectionAuthorizationEvidence\";\nimport { readAccessManifest } from \"../readers\";\nimport type {\n OpenPrincipalPolicyBundleReader,\n PrincipalPolicyCache,\n ProjectionUserKeyResolver,\n ReferencedPrincipalPolicyWarmer,\n} from \"../types\";\nimport { withGenerationGuardedPolicyWarmer } from \"../types\";\nimport { documentContainerProjections } from \"./documentContainerProjections\";\nimport { verifyDocumentProjectionManifests } from \"./documentManifestVerification\";\n\ntype VerifiedManifestMap = Map<string, VerifiedContainerAccessManifest>;\ntype PolicyWarmer = ReferencedPrincipalPolicyWarmer | undefined;\n\nfunction readDocumentProjectionContainerPaths(\n projection: DocumentWriterProjectionResponse,\n): AccessManifestBundleWireResponse[][] {\n return [\n ...projection.documentManifestContainerPaths,\n ...projection.authorizingContainerPaths.map((path) => path.path),\n ];\n}\n\nfunction collectDocumentProjectionContainerBundles(\n projection: DocumentWriterProjectionResponse,\n): Map<string, AccessManifestBundleWireResponse> {\n const bundlesByHash = new Map<string, AccessManifestBundleWireResponse>();\n for (const [index, authorizing] of documentContainerProjections(\n projection,\n ).entries()) {\n addContainerWriterProjectionBundles(\n bundlesByHash,\n authorizing,\n `Document writer projection authorizing path[${index}]`,\n );\n }\n for (const [index, path] of readDocumentProjectionContainerPaths(\n projection,\n ).entries()) {\n for (const [pathIndex, bundle] of path.entries()) {\n addBundleByHash(\n bundlesByHash,\n bundle,\n `Document writer projection dependency path[${index}][${pathIndex}]`,\n );\n }\n }\n for (const [\n index,\n bundle,\n ] of projection.documentContainerManifestHistory.entries()) {\n addBundleByHash(\n bundlesByHash,\n bundle,\n `Document writer projection container history[${index}]`,\n );\n }\n return bundlesByHash;\n}\n\nasync function verifyProjectionContainerPaths(input: {\n readonly authorizationEvidence: readonly PrincipalPolicyAuthorization[];\n readonly checkpointContext: ProjectionCheckpointContext;\n readonly principalPolicyCache: PrincipalPolicyCache;\n readonly projection: DocumentWriterProjectionResponse;\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly verifiedByHash?: VerifiedManifestMap | undefined;\n readonly warmReferencedPrincipalPolicies?: PolicyWarmer;\n}): Promise<Map<string, readonly VerifiedContainerAccessManifest[]>> {\n const bundlesByHash = collectDocumentProjectionContainerBundles(\n input.projection,\n );\n const containerPathByManifestHash = new Map<\n string,\n readonly VerifiedContainerAccessManifest[]\n >();\n // Reuse a caller-supplied cache when provided so a later unwrap pass over the\n // same authorizing container paths does not re-verify identical manifests.\n const verifiedByHash =\n input.verifiedByHash ?? new Map<string, VerifiedContainerAccessManifest>();\n for (const projection of documentContainerProjections(input.projection)) {\n const path = await verifyContainerWriterProjectionWithContext(\n {\n authorizationEvidence: input.authorizationEvidence,\n principalPolicyCache: input.principalPolicyCache,\n projection,\n resolveUserKey: input.resolveUserKey,\n verifiedByHash,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n },\n input.checkpointContext,\n );\n const leaf = path.at(-1);\n if (leaf) {\n containerPathByManifestHash.set(leaf.manifestHash, path);\n }\n for (const manifest of path) {\n verifiedByHash.set(manifest.manifestHash, manifest);\n }\n }\n // Grouping supplies evidence only; each signed artifact selects its citations.\n for (const [\n index,\n path,\n ] of input.projection.documentManifestContainerPaths.entries()) {\n // Historical dependency evidence is verified without current checkpoint\n // enforcement. Its grouping cannot substitute an uncited ancestor into\n // document or content-write authorization.\n const verifiedPath = await verifyContainerManifestPath({\n authorizationEvidence: input.authorizationEvidence,\n requireAuthorizationEvidence: true,\n servedAsCurrent: false,\n authorizationMembership: \"referenced\",\n bundlesByHash,\n checkpointContext: input.checkpointContext,\n enforceLocalCheckpoints: false,\n label: `Document writer projection dependency path[${index}]`,\n path,\n principalPolicyCache: input.principalPolicyCache,\n resolveUserKey: input.resolveUserKey,\n verifiedByHash,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n // The authorizing path recorded for the same leaf takes precedence.\n const leaf = verifiedPath.at(-1);\n if (leaf && !containerPathByManifestHash.has(leaf.manifestHash)) {\n containerPathByManifestHash.set(leaf.manifestHash, verifiedPath);\n }\n }\n\n // Keep every verified head as evidence. Events and content headers select\n // their own signed paths through resolveEventContainerPaths.\n for (const [hash, manifest] of verifiedByHash) {\n if (!containerPathByManifestHash.has(hash))\n containerPathByManifestHash.set(hash, [manifest]);\n }\n\n observeAccessManifestCheckpoints(input.checkpointContext, {\n verifiedHeads: [],\n verifiedManifests: verifiedContainerManifestsForBundles(\n bundlesByHash,\n verifiedByHash,\n ),\n });\n\n return containerPathByManifestHash;\n}\n\ninterface DocumentWriterProjectionVerificationInput {\n readonly execSql: ExecSql;\n readonly openPrincipalPolicyBundleReader: OpenPrincipalPolicyBundleReader;\n readonly persistVerificationCheckpoints?: boolean | undefined;\n readonly principalPolicyCache?: PrincipalPolicyCache | undefined;\n readonly projection: DocumentWriterProjectionResponse;\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly stillCurrent?: (() => boolean) | undefined;\n readonly verifiedByHash?: VerifiedManifestMap | undefined;\n readonly warmReferencedPrincipalPolicies?: PolicyWarmer;\n}\nexport interface DocumentWriterProjectionAuthorization {\n readonly containerPathByManifestHash: ReadonlyMap<\n string,\n readonly VerifiedContainerAccessManifest[]\n >;\n readonly documentManifestByHash: ReadonlyMap<\n string,\n VerifiedDocumentLinkSetManifest\n >;\n readonly principalPolicies: readonly PrincipalPolicyAuthorization[];\n}\n\ninterface VerifiedDocumentWriterProjectionResult {\n readonly authorization: DocumentWriterProjectionAuthorization;\n readonly headManifest: VerifiedDocumentLinkSetManifest;\n}\n\nasync function verifyDocumentWriterProjectionWithContext(\n input: Omit<DocumentWriterProjectionVerificationInput, \"execSql\">,\n checkpointContext: ProjectionCheckpointContext,\n): Promise<VerifiedDocumentWriterProjectionResult> {\n const principalPolicyCache =\n input.principalPolicyCache ?? new Map<string, VerifiedPrincipalPolicy>();\n const authorizationEvidence = await verifyProjectionAuthorizationEvidence({\n bundles: [\n input.projection.documentManifest,\n ...input.projection.documentManifestHistory,\n ...collectDocumentProjectionContainerBundles(input.projection).values(),\n ],\n checkpointContext,\n policyEvidence: input.projection.policyEvidence,\n organizationId: readAccessManifest(\n input.projection.documentManifest.manifest,\n \"Document projection manifest\",\n ).organizationId,\n principalPolicyCache,\n resolveUserKey: input.resolveUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n const containerPathByManifestHash = await verifyProjectionContainerPaths({\n authorizationEvidence,\n checkpointContext,\n principalPolicyCache,\n projection: input.projection,\n resolveUserKey: input.resolveUserKey,\n verifiedByHash: input.verifiedByHash,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n const { headManifest, verifiedByHash } =\n await verifyDocumentProjectionManifests({\n authorizationEvidence,\n checkpointContext,\n containerPathByManifestHash,\n principalPolicyCache,\n projection: input.projection,\n resolveUserKey: input.resolveUserKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n await rejectPurgedDocumentProjection(\n headManifest.state.documentId,\n checkpointContext.execSql,\n );\n\n observeAccessManifestCheckpoints(checkpointContext, {\n verifiedHeads: [headManifest],\n verifiedManifests: [...verifiedByHash.values()],\n });\n\n return {\n authorization: {\n containerPathByManifestHash,\n documentManifestByHash: verifiedByHash,\n principalPolicies: authorizationEvidence,\n },\n headManifest,\n };\n}\n\n/** Each served bundle, document and container, whose manifest verified. */\nfunction observeVerifiedDocumentProjectionBundles(\n checkpointContext: ProjectionCheckpointContext,\n projection: DocumentWriterProjectionResponse,\n authorization: DocumentWriterProjectionAuthorization,\n): void {\n observeVerifiedProjectionBundles(\n checkpointContext,\n new Map(\n [projection.documentManifest, ...projection.documentManifestHistory].map(\n (bundle) => [bundle.manifestHash, bundle],\n ),\n ),\n authorization.documentManifestByHash,\n );\n observeVerifiedProjectionBundles(\n checkpointContext,\n collectDocumentProjectionContainerBundles(projection),\n new Map(\n [...authorization.containerPathByManifestHash.values()]\n .flat()\n .map((manifest) => [manifest.manifestHash, manifest]),\n ),\n );\n observeVerifiedKekLevels(\n checkpointContext,\n projection.authorizingContainerPaths,\n );\n}\n\nexport function verifyDocumentWriterProjection(\n input: DocumentWriterProjectionVerificationInput,\n): Promise<VerifiedDocumentLinkSetManifest> {\n return verifyWithHeldBundleRecovery(input, () =>\n verifyDocumentWriterProjectionOnce(input),\n );\n}\n\nasync function verifyDocumentWriterProjectionOnce(\n input: DocumentWriterProjectionVerificationInput,\n): Promise<VerifiedDocumentLinkSetManifest> {\n const checkpointContext = createProjectionCheckpointContext({\n execSql: input.execSql,\n openPrincipalPolicyBundleReader: input.openPrincipalPolicyBundleReader,\n });\n const verified = await verifyDocumentWriterProjectionWithContext(\n withGenerationGuardedPolicyWarmer(input),\n checkpointContext,\n );\n observeVerifiedDocumentProjectionBundles(\n checkpointContext,\n input.projection,\n verified.authorization,\n );\n await finalizeProjectionCheckpoints(checkpointContext, input);\n return verified.headManifest;\n}\n\nexport function verifyDocumentWriterProjectionAuthorization(\n input: DocumentWriterProjectionVerificationInput,\n): Promise<DocumentWriterProjectionAuthorization> {\n return verifyWithHeldBundleRecovery(input, () =>\n verifyDocumentWriterProjectionAuthorizationOnce(input),\n );\n}\n\nasync function verifyDocumentWriterProjectionAuthorizationOnce(\n input: DocumentWriterProjectionVerificationInput,\n): Promise<DocumentWriterProjectionAuthorization> {\n try {\n const checkpointContext = createProjectionCheckpointContext({\n execSql: input.execSql,\n openPrincipalPolicyBundleReader: input.openPrincipalPolicyBundleReader,\n });\n const verified = await verifyDocumentWriterProjectionWithContext(\n withGenerationGuardedPolicyWarmer(input),\n checkpointContext,\n );\n observeVerifiedDocumentProjectionBundles(\n checkpointContext,\n input.projection,\n verified.authorization,\n );\n await finalizeProjectionCheckpoints(checkpointContext, input);\n return verified.authorization;\n } catch (error) {\n throwKeyingVerificationShapeFailure(error);\n }\n}\n"]}
|
|
@@ -4,6 +4,7 @@ export { readAccessEvent, readRecordString, readRequiredRecordValue, } from "./r
|
|
|
4
4
|
export type { PrincipalPolicyCache, ProjectionUserKeyResolver, ReferencedPrincipalPolicyWarmer, } from "./types.js";
|
|
5
5
|
export { isProjectionVerificationCancelledError, nullOnProjectionVerificationCancellation, } from "./types.js";
|
|
6
6
|
export declare function requireProjectionUserKeyResolver(resolveProjectionUserKey: ProjectionUserKeyResolver | null | undefined, label: string): ProjectionUserKeyResolver;
|
|
7
|
+
export { checkWithHeldBundleRecovery } from "./checkpoints/heldBundleRecovery.js";
|
|
7
8
|
export { verifiedContainerCreateManifest } from "./container/containerCreateManifest.js";
|
|
8
9
|
export { verifyContainerDestinationProjection } from "./container/containerDestinationVerification.js";
|
|
9
10
|
export { collectContainerWriterProjectionPrincipalPolicies, verifyContainerWriterProjection, } from "./container/containerProjectionVerification.js";
|
|
@@ -10,6 +10,7 @@ export function requireProjectionUserKeyResolver(resolveProjectionUserKey, label
|
|
|
10
10
|
// provides the untrusted-shape and wrong-user guards (with identity caching).
|
|
11
11
|
return requireTrustedUserIdentityResolver(resolveProjectionUserKey);
|
|
12
12
|
}
|
|
13
|
+
export { checkWithHeldBundleRecovery } from "./checkpoints/heldBundleRecovery.js";
|
|
13
14
|
export { verifiedContainerCreateManifest } from "./container/containerCreateManifest.js";
|
|
14
15
|
export { verifyContainerDestinationProjection } from "./container/containerDestinationVerification.js";
|
|
15
16
|
export { collectContainerWriterProjectionPrincipalPolicies, verifyContainerWriterProjection, } from "./container/containerProjectionVerification.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAC;AAG5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,WAAW,CAAC;AAOnB,OAAO,EACL,sCAAsC,EACtC,wCAAwC,GACzC,MAAM,SAAS,CAAC;AAEjB,MAAM,UAAU,gCAAgC,CAC9C,wBAAsE,EACtE,KAAa;IAEb,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,uCAAuC,CAAC,CAAC;IACnE,CAAC;IAED,sEAAsE;IACtE,8EAA8E;IAC9E,OAAO,kCAAkC,CAAC,wBAAwB,CAAC,CAAC;AACtE,CAAC;AAED,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,oCAAoC,EAAE,MAAM,8CAA8C,CAAC;AACpG,OAAO,EACL,iDAAiD,EACjD,+BAA+B,GAChC,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAEL,8BAA8B,EAC9B,2CAA2C,GAC5C,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,wBAAwB,EACxB,gCAAgC,GACjC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAChG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sDAAsD,CAAC;AAC1G,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC","sourcesContent":["import { requireTrustedUserIdentityResolver } from \"../trustedUserIdentity\";\nimport type { ProjectionUserKeyResolver } from \"./types\";\n\nexport { resolveEventContainerPaths } from \"./document/documentDependencyPaths\";\nexport {\n readAccessEvent,\n readRecordString,\n readRequiredRecordValue,\n} from \"./readers\";\n\nexport type {\n PrincipalPolicyCache,\n ProjectionUserKeyResolver,\n ReferencedPrincipalPolicyWarmer,\n} from \"./types\";\nexport {\n isProjectionVerificationCancelledError,\n nullOnProjectionVerificationCancellation,\n} from \"./types\";\n\nexport function requireProjectionUserKeyResolver(\n resolveProjectionUserKey: ProjectionUserKeyResolver | null | undefined,\n label: string,\n): ProjectionUserKeyResolver {\n if (!resolveProjectionUserKey) {\n throw new Error(`${label} requires projection key verification`);\n }\n\n // A ProjectionUserKey is a TrustedUserIdentity, so the shared adapter\n // provides the untrusted-shape and wrong-user guards (with identity caching).\n return requireTrustedUserIdentityResolver(resolveProjectionUserKey);\n}\n\nexport { verifiedContainerCreateManifest } from \"./container/containerCreateManifest\";\nexport { verifyContainerDestinationProjection } from \"./container/containerDestinationVerification\";\nexport {\n collectContainerWriterProjectionPrincipalPolicies,\n verifyContainerWriterProjection,\n} from \"./container/containerProjectionVerification\";\nexport {\n type DocumentWriterProjectionAuthorization,\n verifyDocumentWriterProjection,\n verifyDocumentWriterProjectionAuthorization,\n} from \"./document/documentProjectionVerification\";\nexport {\n verifyDocumentPurgeProof,\n verifyDocumentPurgeProofBaseline,\n} from \"./documentPurge/documentPurgeProofVerification\";\nexport { mergeProjectionPolicyEvidence } from \"./principalPolicy/mergeProjectionPolicyEvidence\";\nexport { principalPolicyHeadMeetsCheckpoint } from \"./principalPolicy/principalPolicyCheckpointSelection\";\nexport { isPrincipalPolicyNotCachedError } from \"./principalPolicy/principalPolicyVerification\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAC;AAG5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,WAAW,CAAC;AAOnB,OAAO,EACL,sCAAsC,EACtC,wCAAwC,GACzC,MAAM,SAAS,CAAC;AAEjB,MAAM,UAAU,gCAAgC,CAC9C,wBAAsE,EACtE,KAAa;IAEb,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,uCAAuC,CAAC,CAAC;IACnE,CAAC;IAED,sEAAsE;IACtE,8EAA8E;IAC9E,OAAO,kCAAkC,CAAC,wBAAwB,CAAC,CAAC;AACtE,CAAC;AAED,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AACtF,OAAO,EAAE,oCAAoC,EAAE,MAAM,8CAA8C,CAAC;AACpG,OAAO,EACL,iDAAiD,EACjD,+BAA+B,GAChC,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAEL,8BAA8B,EAC9B,2CAA2C,GAC5C,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,wBAAwB,EACxB,gCAAgC,GACjC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAChG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sDAAsD,CAAC;AAC1G,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC","sourcesContent":["import { requireTrustedUserIdentityResolver } from \"../trustedUserIdentity\";\nimport type { ProjectionUserKeyResolver } from \"./types\";\n\nexport { resolveEventContainerPaths } from \"./document/documentDependencyPaths\";\nexport {\n readAccessEvent,\n readRecordString,\n readRequiredRecordValue,\n} from \"./readers\";\n\nexport type {\n PrincipalPolicyCache,\n ProjectionUserKeyResolver,\n ReferencedPrincipalPolicyWarmer,\n} from \"./types\";\nexport {\n isProjectionVerificationCancelledError,\n nullOnProjectionVerificationCancellation,\n} from \"./types\";\n\nexport function requireProjectionUserKeyResolver(\n resolveProjectionUserKey: ProjectionUserKeyResolver | null | undefined,\n label: string,\n): ProjectionUserKeyResolver {\n if (!resolveProjectionUserKey) {\n throw new Error(`${label} requires projection key verification`);\n }\n\n // A ProjectionUserKey is a TrustedUserIdentity, so the shared adapter\n // provides the untrusted-shape and wrong-user guards (with identity caching).\n return requireTrustedUserIdentityResolver(resolveProjectionUserKey);\n}\n\nexport { checkWithHeldBundleRecovery } from \"./checkpoints/heldBundleRecovery\";\nexport { verifiedContainerCreateManifest } from \"./container/containerCreateManifest\";\nexport { verifyContainerDestinationProjection } from \"./container/containerDestinationVerification\";\nexport {\n collectContainerWriterProjectionPrincipalPolicies,\n verifyContainerWriterProjection,\n} from \"./container/containerProjectionVerification\";\nexport {\n type DocumentWriterProjectionAuthorization,\n verifyDocumentWriterProjection,\n verifyDocumentWriterProjectionAuthorization,\n} from \"./document/documentProjectionVerification\";\nexport {\n verifyDocumentPurgeProof,\n verifyDocumentPurgeProofBaseline,\n} from \"./documentPurge/documentPurgeProofVerification\";\nexport { mergeProjectionPolicyEvidence } from \"./principalPolicy/mergeProjectionPolicyEvidence\";\nexport { principalPolicyHeadMeetsCheckpoint } from \"./principalPolicy/principalPolicyCheckpointSelection\";\nexport { isPrincipalPolicyNotCachedError } from \"./principalPolicy/principalPolicyVerification\";\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { eq } from "drizzle-orm";
|
|
2
2
|
import { documentPurgeCheckpoints, keyingCheckpointTables, } from "../../sqlite/schema/keyingCheckpointSchema.js";
|
|
3
3
|
import { principalPolicyTables } from "../../sqlite/schema/principalPolicySchema.js";
|
|
4
|
+
import { verifiedManifestBundleTables } from "../../sqlite/schema/verifiedManifestBundleSchema.js";
|
|
4
5
|
import { getClientSQLitePersistenceRuntime, } from "../../sqlite/sqlitePersistenceRuntime.js";
|
|
5
6
|
import { ensureSqlTables } from "../../sqlite/sqlSchema.js";
|
|
6
|
-
import { verifiedManifestBundleRows, } from "../verifiedManifestBundlePersistence.js";
|
|
7
|
+
import { verifiedManifestBundleRows, writeVerifiedManifestBundlesInTransaction, } from "../verifiedManifestBundlePersistence.js";
|
|
7
8
|
import { advanceKeyingCheckpointsInTransaction, keyingCheckpointBatchTables, validateKeyingCheckpointsInTransaction, } from "./keyingCheckpointAdvancePersistence.js";
|
|
8
9
|
import { loadAccessManifestCheckpointRow, loadPrincipalPolicyCheckpointRow, } from "./keyingCheckpointPersistence.js";
|
|
9
10
|
import { acknowledgeLocallyAuthoredHeadsInTransaction, } from "./locallyAcknowledgedCheckpointPersistence.js";
|
|
@@ -86,12 +87,23 @@ export class KeyingCheckpointRepository {
|
|
|
86
87
|
}
|
|
87
88
|
await runtime.transaction(advance, { behavior: "immediate" });
|
|
88
89
|
}
|
|
89
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Whether the heads committed; false only when `stillCurrent` turned false.
|
|
92
|
+
* A head's authored bundle, when its acknowledgement matched, is stored for
|
|
93
|
+
* citation in the same transaction, so it commits only with its pin.
|
|
94
|
+
*/
|
|
90
95
|
async advanceLocallyAcknowledgedAccessManifestHeadsAtomically(advance) {
|
|
91
|
-
await
|
|
96
|
+
const bundleRows = await verifiedManifestBundleRows(advance.heads.flatMap(({ checkpoint, servedBundle }) => servedBundle ? [{ bundle: servedBundle, checkpoint }] : []));
|
|
97
|
+
await ensureSqlTables(this.execSql, [
|
|
98
|
+
...keyingCheckpointTables,
|
|
99
|
+
...(bundleRows.length > 0 ? verifiedManifestBundleTables : []),
|
|
100
|
+
]);
|
|
92
101
|
const updatedAt = this.now().toISOString();
|
|
93
102
|
const runtime = getClientSQLitePersistenceRuntime(this.execSql);
|
|
94
|
-
const acknowledge = (tx) =>
|
|
103
|
+
const acknowledge = async (tx) => {
|
|
104
|
+
await acknowledgeLocallyAuthoredHeadsInTransaction(tx, advance, updatedAt);
|
|
105
|
+
await writeVerifiedManifestBundlesInTransaction(tx, bundleRows, updatedAt);
|
|
106
|
+
};
|
|
95
107
|
if (advance.stillCurrent) {
|
|
96
108
|
return (await runtime.guardedTransaction(acknowledge, advance.stillCurrent, {
|
|
97
109
|
behavior: "immediate",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyingCheckpointRepository.js","sourceRoot":"","sources":["keyingCheckpointRepository.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,EAEL,iCAAiC,GAClC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAgB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAEL,0BAA0B,GAC3B,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,qCAAqC,EAGrC,2BAA2B,EAC3B,sCAAsC,GACvC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,GACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,4CAA4C,GAE7C,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,mDAAmD,EAAE,MAAM,gDAAgD,CAAC;AAErH;;;;;;GAMG;AACH,MAAM,OAAO,0BAA0B;IACpB,OAAO,CAAU;IACjB,GAAG,CAAa;IAEjC,YAAY,OAAgB,EAAE,MAAkB,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;QAC9D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,4BAA4B,CAChC,UAA4B,EAC5B,cAAsB,EACtB,QAAgB;QAEhB,MAAM,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,sBAAsB,CAAC,C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C,CAAC,EAAE,EAAE,EAAE,CACL,mDAAmD,CACjD,EAAE,EACF,KAAK,CAAC,aAAa,EACnB,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CACzB,EACH,KAAK,CAAC,YAAY,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAClC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAC1B,CAAC;QACF,OAAO,MAAM,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,YAAY,CACxB,KAA4B;QAE5B,MAAM,UAAU,GAAG,MAAM,0BAA0B,CACjD,KAAK,CAAC,eAAe,IAAI,EAAE,CAC5B,CAAC;QACF,MAAM,eAAe,CACnB,IAAI,CAAC,OAAO,EACZ,2BAA2B,CAAC,KAAK,EAAE,UAAU,CAAC,CAC/C,CAAC;QACF,OAAO,UAAU,CAAC;IACpB,CAAC;CACF","sourcesContent":["import type {\n AccessManifestCheckpoint,\n AccessObjectKind,\n ManagedPrincipalKind,\n PrincipalPolicyCheckpoint,\n VerifiedOrganizationReplacementAuthorization,\n} from \"@tearleads/crypto\";\nimport { eq } from \"drizzle-orm\";\nimport {\n documentPurgeCheckpoints,\n keyingCheckpointTables,\n} from \"../../sqlite/schema/keyingCheckpointSchema\";\nimport { principalPolicyTables } from \"../../sqlite/schema/principalPolicySchema\";\nimport {\n type ClientSQLiteTransactionScope,\n getClientSQLitePersistenceRuntime,\n} from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { type ExecSql, ensureSqlTables } from \"../../sqlite/sqlSchema\";\nimport {\n type VerifiedManifestBundleRow,\n verifiedManifestBundleRows,\n} from \"../verifiedManifestBundlePersistence\";\nimport type { DocumentPurgeCheckpoint } from \"./documentPurgeCheckpointPersistence\";\nimport {\n advanceKeyingCheckpointsInTransaction,\n type KeyingCheckpointAdvanceBatch,\n type KeyingCheckpointBatch,\n keyingCheckpointBatchTables,\n validateKeyingCheckpointsInTransaction,\n} from \"./keyingCheckpointAdvancePersistence\";\nimport {\n loadAccessManifestCheckpointRow,\n loadPrincipalPolicyCheckpointRow,\n} from \"./keyingCheckpointPersistence\";\nimport {\n acknowledgeLocallyAuthoredHeadsInTransaction,\n type LocallyAcknowledgedAdvance,\n} from \"./locallyAcknowledgedCheckpointPersistence\";\nimport { seedOrganizationReplacementCheckpointsInTransaction } from \"./organizationReplacementCheckpointPersistence\";\n\n/**\n * The durable keying pins projection verification compares against: access\n * manifest, principal policy, and document purge checkpoints, bound to one\n * executor and clock. Each method ensures its tables and runs its own\n * immediate transaction. Work inside a caller's transaction takes the locked\n * handle per call through the `*InTransaction` functions instead.\n */\nexport class KeyingCheckpointRepository {\n private readonly execSql: ExecSql;\n private readonly now: () => Date;\n\n constructor(execSql: ExecSql, now: () => Date = () => new Date()) {\n this.execSql = execSql;\n this.now = now;\n }\n\n async loadAccessManifestCheckpoint(\n objectKind: AccessObjectKind,\n organizationId: string,\n objectId: string,\n ): Promise<AccessManifestCheckpoint | null> {\n await ensureSqlTables(this.execSql, keyingCheckpointTables);\n const { db } = getClientSQLitePersistenceRuntime(this.execSql);\n const row = await loadAccessManifestCheckpointRow(db, {\n objectKind,\n organizationId,\n objectId,\n });\n return row ? { objectKind, objectId, organizationId, ...row } : null;\n }\n\n async loadPrincipalPolicyCheckpoint(\n principalType: ManagedPrincipalKind,\n principalId: string,\n ): Promise<PrincipalPolicyCheckpoint | null> {\n await ensureSqlTables(this.execSql, keyingCheckpointTables);\n const { db } = getClientSQLitePersistenceRuntime(this.execSql);\n const row = await loadPrincipalPolicyCheckpointRow(db, {\n principalType,\n principalId,\n });\n return row ? { principalType, principalId, ...row } : null;\n }\n\n async loadDocumentPurgeCheckpoint(\n documentId: string,\n ): Promise<DocumentPurgeCheckpoint | null> {\n await ensureSqlTables(this.execSql, keyingCheckpointTables);\n const [row] = await getClientSQLitePersistenceRuntime(this.execSql)\n .db.select({\n documentId: documentPurgeCheckpoints.documentId,\n documentManifestHash: documentPurgeCheckpoints.documentManifestHash,\n organizationId: documentPurgeCheckpoints.organizationId,\n purgeEventHash: documentPurgeCheckpoints.purgeEventHash,\n })\n .from(documentPurgeCheckpoints)\n .where(eq(documentPurgeCheckpoints.documentId, documentId))\n .limit(1);\n return row ?? null;\n }\n\n /**\n * Re-checks verified candidates against durable pins without advancing\n * them; only the verified bundles' citation rows are written.\n */\n async validateKeyingCheckpointsAtomically(\n batch: KeyingCheckpointBatch,\n ): Promise<void> {\n const bundleRows = await this.prepareBatch(batch);\n const verifiedAt = this.now().toISOString();\n const validate = (tx: ClientSQLiteTransactionScope) =>\n validateKeyingCheckpointsInTransaction(tx, batch, bundleRows, verifiedAt);\n const runtime = getClientSQLitePersistenceRuntime(this.execSql);\n if (batch.stillCurrent) {\n await runtime.guardedTransaction(validate, batch.stillCurrent, {\n behavior: \"immediate\",\n });\n return;\n }\n await runtime.transaction(validate, { behavior: \"immediate\" });\n }\n\n /** Advances the complete verified batch in one immediate transaction. */\n async advanceKeyingCheckpointsAtomically(\n batch: KeyingCheckpointAdvanceBatch,\n ): Promise<void> {\n const bundleRows = await this.prepareBatch(batch);\n const updatedAt = this.now().toISOString();\n const advance = (tx: ClientSQLiteTransactionScope) =>\n advanceKeyingCheckpointsInTransaction(tx, batch, bundleRows, updatedAt);\n const runtime = getClientSQLitePersistenceRuntime(this.execSql);\n if (batch.stillCurrent) {\n await runtime.guardedTransaction(advance, batch.stillCurrent, {\n behavior: \"immediate\",\n });\n return;\n }\n await runtime.transaction(advance, { behavior: \"immediate\" });\n }\n\n /** Whether the heads committed; false only when `stillCurrent` turned false. */\n async advanceLocallyAcknowledgedAccessManifestHeadsAtomically(\n advance: LocallyAcknowledgedAdvance,\n ): Promise<boolean> {\n await ensureSqlTables(this.execSql, keyingCheckpointTables);\n const updatedAt = this.now().toISOString();\n const runtime = getClientSQLitePersistenceRuntime(this.execSql);\n const acknowledge = (tx: ClientSQLiteTransactionScope) =>\n acknowledgeLocallyAuthoredHeadsInTransaction(tx, advance, updatedAt);\n if (advance.stillCurrent) {\n return (\n await runtime.guardedTransaction(acknowledge, advance.stillCurrent, {\n behavior: \"immediate\",\n })\n ).committed;\n }\n await runtime.transaction(acknowledge, { behavior: \"immediate\" });\n return true;\n }\n\n /** Seeds a replacement organization's genesis pins; false if superseded. */\n async persistOrganizationReplacementCheckpoints(input: {\n readonly authorization: VerifiedOrganizationReplacementAuthorization;\n readonly stillCurrent?: (() => boolean) | undefined;\n }): Promise<boolean> {\n await ensureSqlTables(this.execSql, [\n ...principalPolicyTables,\n ...keyingCheckpointTables,\n ]);\n const runtime = getClientSQLitePersistenceRuntime(this.execSql);\n const result = await runtime.guardedTransaction(\n (tx) =>\n seedOrganizationReplacementCheckpointsInTransaction(\n tx,\n input.authorization,\n this.now().toISOString(),\n ),\n input.stillCurrent ?? (() => true),\n { behavior: \"immediate\" },\n );\n return result.committed;\n }\n\n /**\n * Digests the verified bundles and ensures every table the batch touches,\n * all before its transaction begins.\n */\n private async prepareBatch(\n batch: KeyingCheckpointBatch,\n ): Promise<VerifiedManifestBundleRow[]> {\n const bundleRows = await verifiedManifestBundleRows(\n batch.verifiedBundles ?? [],\n );\n await ensureSqlTables(\n this.execSql,\n keyingCheckpointBatchTables(batch, bundleRows),\n );\n return bundleRows;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"keyingCheckpointRepository.js","sourceRoot":"","sources":["keyingCheckpointRepository.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAC;AAChG,OAAO,EAEL,iCAAiC,GAClC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAgB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAEL,0BAA0B,EAC1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C,GAAG,EAAE,CAAC,WAAW,EAAE,CACzB,EACH,KAAK,CAAC,YAAY,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAClC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAC1B,CAAC;QACF,OAAO,MAAM,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,YAAY,CACxB,KAA4B;QAE5B,MAAM,UAAU,GAAG,MAAM,0BAA0B,CACjD,KAAK,CAAC,eAAe,IAAI,EAAE,CAC5B,CAAC;QACF,MAAM,eAAe,CACnB,IAAI,CAAC,OAAO,EACZ,2BAA2B,CAAC,KAAK,EAAE,UAAU,CAAC,CAC/C,CAAC;QACF,OAAO,UAAU,CAAC;IACpB,CAAC;CACF","sourcesContent":["import type {\n AccessManifestCheckpoint,\n AccessObjectKind,\n ManagedPrincipalKind,\n PrincipalPolicyCheckpoint,\n VerifiedOrganizationReplacementAuthorization,\n} from \"@tearleads/crypto\";\nimport { eq } from \"drizzle-orm\";\nimport {\n documentPurgeCheckpoints,\n keyingCheckpointTables,\n} from \"../../sqlite/schema/keyingCheckpointSchema\";\nimport { principalPolicyTables } from \"../../sqlite/schema/principalPolicySchema\";\nimport { verifiedManifestBundleTables } from \"../../sqlite/schema/verifiedManifestBundleSchema\";\nimport {\n type ClientSQLiteTransactionScope,\n getClientSQLitePersistenceRuntime,\n} from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { type ExecSql, ensureSqlTables } from \"../../sqlite/sqlSchema\";\nimport {\n type VerifiedManifestBundleRow,\n verifiedManifestBundleRows,\n writeVerifiedManifestBundlesInTransaction,\n} from \"../verifiedManifestBundlePersistence\";\nimport type { DocumentPurgeCheckpoint } from \"./documentPurgeCheckpointPersistence\";\nimport {\n advanceKeyingCheckpointsInTransaction,\n type KeyingCheckpointAdvanceBatch,\n type KeyingCheckpointBatch,\n keyingCheckpointBatchTables,\n validateKeyingCheckpointsInTransaction,\n} from \"./keyingCheckpointAdvancePersistence\";\nimport {\n loadAccessManifestCheckpointRow,\n loadPrincipalPolicyCheckpointRow,\n} from \"./keyingCheckpointPersistence\";\nimport {\n acknowledgeLocallyAuthoredHeadsInTransaction,\n type LocallyAcknowledgedAdvance,\n} from \"./locallyAcknowledgedCheckpointPersistence\";\nimport { seedOrganizationReplacementCheckpointsInTransaction } from \"./organizationReplacementCheckpointPersistence\";\n\n/**\n * The durable keying pins projection verification compares against: access\n * manifest, principal policy, and document purge checkpoints, bound to one\n * executor and clock. Each method ensures its tables and runs its own\n * immediate transaction. Work inside a caller's transaction takes the locked\n * handle per call through the `*InTransaction` functions instead.\n */\nexport class KeyingCheckpointRepository {\n private readonly execSql: ExecSql;\n private readonly now: () => Date;\n\n constructor(execSql: ExecSql, now: () => Date = () => new Date()) {\n this.execSql = execSql;\n this.now = now;\n }\n\n async loadAccessManifestCheckpoint(\n objectKind: AccessObjectKind,\n organizationId: string,\n objectId: string,\n ): Promise<AccessManifestCheckpoint | null> {\n await ensureSqlTables(this.execSql, keyingCheckpointTables);\n const { db } = getClientSQLitePersistenceRuntime(this.execSql);\n const row = await loadAccessManifestCheckpointRow(db, {\n objectKind,\n organizationId,\n objectId,\n });\n return row ? { objectKind, objectId, organizationId, ...row } : null;\n }\n\n async loadPrincipalPolicyCheckpoint(\n principalType: ManagedPrincipalKind,\n principalId: string,\n ): Promise<PrincipalPolicyCheckpoint | null> {\n await ensureSqlTables(this.execSql, keyingCheckpointTables);\n const { db } = getClientSQLitePersistenceRuntime(this.execSql);\n const row = await loadPrincipalPolicyCheckpointRow(db, {\n principalType,\n principalId,\n });\n return row ? { principalType, principalId, ...row } : null;\n }\n\n async loadDocumentPurgeCheckpoint(\n documentId: string,\n ): Promise<DocumentPurgeCheckpoint | null> {\n await ensureSqlTables(this.execSql, keyingCheckpointTables);\n const [row] = await getClientSQLitePersistenceRuntime(this.execSql)\n .db.select({\n documentId: documentPurgeCheckpoints.documentId,\n documentManifestHash: documentPurgeCheckpoints.documentManifestHash,\n organizationId: documentPurgeCheckpoints.organizationId,\n purgeEventHash: documentPurgeCheckpoints.purgeEventHash,\n })\n .from(documentPurgeCheckpoints)\n .where(eq(documentPurgeCheckpoints.documentId, documentId))\n .limit(1);\n return row ?? null;\n }\n\n /**\n * Re-checks verified candidates against durable pins without advancing\n * them; only the verified bundles' citation rows are written.\n */\n async validateKeyingCheckpointsAtomically(\n batch: KeyingCheckpointBatch,\n ): Promise<void> {\n const bundleRows = await this.prepareBatch(batch);\n const verifiedAt = this.now().toISOString();\n const validate = (tx: ClientSQLiteTransactionScope) =>\n validateKeyingCheckpointsInTransaction(tx, batch, bundleRows, verifiedAt);\n const runtime = getClientSQLitePersistenceRuntime(this.execSql);\n if (batch.stillCurrent) {\n await runtime.guardedTransaction(validate, batch.stillCurrent, {\n behavior: \"immediate\",\n });\n return;\n }\n await runtime.transaction(validate, { behavior: \"immediate\" });\n }\n\n /** Advances the complete verified batch in one immediate transaction. */\n async advanceKeyingCheckpointsAtomically(\n batch: KeyingCheckpointAdvanceBatch,\n ): Promise<void> {\n const bundleRows = await this.prepareBatch(batch);\n const updatedAt = this.now().toISOString();\n const advance = (tx: ClientSQLiteTransactionScope) =>\n advanceKeyingCheckpointsInTransaction(tx, batch, bundleRows, updatedAt);\n const runtime = getClientSQLitePersistenceRuntime(this.execSql);\n if (batch.stillCurrent) {\n await runtime.guardedTransaction(advance, batch.stillCurrent, {\n behavior: \"immediate\",\n });\n return;\n }\n await runtime.transaction(advance, { behavior: \"immediate\" });\n }\n\n /**\n * Whether the heads committed; false only when `stillCurrent` turned false.\n * A head's authored bundle, when its acknowledgement matched, is stored for\n * citation in the same transaction, so it commits only with its pin.\n */\n async advanceLocallyAcknowledgedAccessManifestHeadsAtomically(\n advance: LocallyAcknowledgedAdvance,\n ): Promise<boolean> {\n const bundleRows = await verifiedManifestBundleRows(\n advance.heads.flatMap(({ checkpoint, servedBundle }) =>\n servedBundle ? [{ bundle: servedBundle, checkpoint }] : [],\n ),\n );\n await ensureSqlTables(this.execSql, [\n ...keyingCheckpointTables,\n ...(bundleRows.length > 0 ? verifiedManifestBundleTables : []),\n ]);\n const updatedAt = this.now().toISOString();\n const runtime = getClientSQLitePersistenceRuntime(this.execSql);\n const acknowledge = async (tx: ClientSQLiteTransactionScope) => {\n await acknowledgeLocallyAuthoredHeadsInTransaction(\n tx,\n advance,\n updatedAt,\n );\n await writeVerifiedManifestBundlesInTransaction(\n tx,\n bundleRows,\n updatedAt,\n );\n };\n if (advance.stillCurrent) {\n return (\n await runtime.guardedTransaction(acknowledge, advance.stillCurrent, {\n behavior: \"immediate\",\n })\n ).committed;\n }\n await runtime.transaction(acknowledge, { behavior: \"immediate\" });\n return true;\n }\n\n /** Seeds a replacement organization's genesis pins; false if superseded. */\n async persistOrganizationReplacementCheckpoints(input: {\n readonly authorization: VerifiedOrganizationReplacementAuthorization;\n readonly stillCurrent?: (() => boolean) | undefined;\n }): Promise<boolean> {\n await ensureSqlTables(this.execSql, [\n ...principalPolicyTables,\n ...keyingCheckpointTables,\n ]);\n const runtime = getClientSQLitePersistenceRuntime(this.execSql);\n const result = await runtime.guardedTransaction(\n (tx) =>\n seedOrganizationReplacementCheckpointsInTransaction(\n tx,\n input.authorization,\n this.now().toISOString(),\n ),\n input.stillCurrent ?? (() => true),\n { behavior: \"immediate\" },\n );\n return result.committed;\n }\n\n /**\n * Digests the verified bundles and ensures every table the batch touches,\n * all before its transaction begins.\n */\n private async prepareBatch(\n batch: KeyingCheckpointBatch,\n ): Promise<VerifiedManifestBundleRow[]> {\n const bundleRows = await verifiedManifestBundleRows(\n batch.verifiedBundles ?? [],\n );\n await ensureSqlTables(\n this.execSql,\n keyingCheckpointBatchTables(batch, bundleRows),\n );\n return bundleRows;\n }\n}\n"]}
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { type AccessManifest, type AccessManifestCheckpoint, type PrincipalPolicyCheckpoint } from "../../../internal/crypto/index.js";
|
|
2
|
+
import type { ServedAccessManifestBundleWireResponse } from "../../../internal/validators/util/index.js";
|
|
2
3
|
import type { ClientSQLiteTransactionScope } from "../../sqlite/sqlitePersistenceRuntime.js";
|
|
4
|
+
import { type AuthoredManifestBundle } from "../verifiedCitations/authoredBundleCitation.js";
|
|
5
|
+
export type { AuthoredManifestBundle } from "../verifiedCitations/authoredBundleCitation.js";
|
|
3
6
|
export interface LocallyAcknowledgedAccessManifestHead {
|
|
4
7
|
readonly checkpoint: AccessManifestCheckpoint;
|
|
5
8
|
readonly previousManifestHash: string | null;
|
|
9
|
+
/**
|
|
10
|
+
* The head's bundle as a projection serves it, when the acknowledgement's
|
|
11
|
+
* digest matched the plan; stored for citation with the checkpoint.
|
|
12
|
+
*/
|
|
13
|
+
readonly servedBundle?: ServedAccessManifestBundleWireResponse | null;
|
|
6
14
|
}
|
|
7
15
|
export declare function locallyAuthoredAccessManifestHead(plan: {
|
|
8
16
|
readonly manifest: AccessManifest;
|
|
9
17
|
readonly manifestHash: string;
|
|
10
18
|
}): LocallyAcknowledgedAccessManifestHead;
|
|
19
|
+
/**
|
|
20
|
+
* An authored head with its served bundle for citation, when the
|
|
21
|
+
* acknowledgement's digest names exactly the bundle the plan builds.
|
|
22
|
+
*/
|
|
23
|
+
export declare function locallyAcknowledgedAuthoredHead(plan: AuthoredManifestBundle, bundleDigest: string): Promise<LocallyAcknowledgedAccessManifestHead>;
|
|
11
24
|
/** Heads this client authored, with the pins its plan read. */
|
|
12
25
|
export interface LocallyAcknowledgedAdvance {
|
|
13
26
|
readonly heads: readonly LocallyAcknowledgedAccessManifestHead[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { accessManifestCheckpointFromManifest, KeyingVerificationError, verifyAccessManifestLocalCheckpoint, } from "../../../internal/crypto/index.js";
|
|
2
|
+
import { acknowledgedAuthoredBundle, } from "../verifiedCitations/authoredBundleCitation.js";
|
|
2
3
|
import { loadContainerRetirementCheck } from "../principalContracts/principalGrantRetirementPersistence.js";
|
|
3
4
|
import { accessManifestObjectKey, loadAccessManifestCheckpointRows, loadPrincipalPolicyCheckpointRows, principalPolicyKey, storedPrincipalPolicyPin, upsertAccessManifestCheckpointsInTransaction, } from "./keyingCheckpointPersistence.js";
|
|
4
5
|
export function locallyAuthoredAccessManifestHead(plan) {
|
|
@@ -10,6 +11,16 @@ export function locallyAuthoredAccessManifestHead(plan) {
|
|
|
10
11
|
previousManifestHash: plan.manifest.previousManifestHash,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* An authored head with its served bundle for citation, when the
|
|
16
|
+
* acknowledgement's digest names exactly the bundle the plan builds.
|
|
17
|
+
*/
|
|
18
|
+
export async function locallyAcknowledgedAuthoredHead(plan, bundleDigest) {
|
|
19
|
+
return {
|
|
20
|
+
...locallyAuthoredAccessManifestHead(plan),
|
|
21
|
+
servedBundle: await acknowledgedAuthoredBundle(plan, bundleDigest),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
13
24
|
function validateAcknowledgedHead(head, localCheckpoint) {
|
|
14
25
|
if (!localCheckpoint) {
|
|
15
26
|
if (head.checkpoint.epoch !== 1 || head.previousManifestHash !== null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locallyAcknowledgedCheckpointPersistence.js","sourceRoot":"","sources":["locallyAcknowledgedCheckpointPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,oCAAoC,EACpC,uBAAuB,EAEvB,mCAAmC,GACpC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"locallyAcknowledgedCheckpointPersistence.js","sourceRoot":"","sources":["locallyAcknowledgedCheckpointPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,oCAAoC,EACpC,uBAAuB,EAEvB,mCAAmC,GACpC,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAEL,0BAA0B,GAC3B,MAAM,6CAA6C,CAAC;AAIrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2DAA2D,CAAC;AACzG,OAAO,EACL,uBAAuB,E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,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC9D,IACE,OAAO,EAAE,KAAK,KAAK,QAAQ,CAAC,KAAK;YACjC,OAAO,CAAC,YAAY,KAAK,QAAQ,CAAC,YAAY,EAC9C,CAAC;YACD,MAAM,IAAI,uBAAuB,CAC/B,mBAAmB,EACnB,mEAAmE,CACpE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,iCAAiC,CACtD,EAAE,EACF,gBAAgB,CACjB,CAAC;IACF,KAAK,MAAM,QAAQ,IAAI,gBAAgB,EAAE,CAAC;QACxC,MAAM,OAAO,GAAG,wBAAwB,CACtC,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAC3C,CAAC;QACF,IACE,OAAO,EAAE,OAAO,KAAK,QAAQ,CAAC,OAAO;YACrC,OAAO,CAAC,SAAS,KAAK,QAAQ,CAAC,SAAS,EACxC,CAAC;YACD,MAAM,IAAI,uBAAuB,CAC/B,mBAAmB,EACnB,0EAA0E,CAC3E,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,yBAAyB,CAAC,EAAE,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3E,MAAM,4CAA4C,CAChD,EAAE,EACF,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EACrB,SAAS,CACV,CAAC;AACJ,CAAC","sourcesContent":["import {\n type AccessManifest,\n type AccessManifestCheckpoint,\n accessManifestCheckpointFromManifest,\n KeyingVerificationError,\n type PrincipalPolicyCheckpoint,\n verifyAccessManifestLocalCheckpoint,\n} from \"@tearleads/crypto\";\nimport type { ServedAccessManifestBundleWireResponse } from \"@tearleads/validators/util\";\nimport type { ClientSQLiteTransactionScope } from \"../../sqlite/sqlitePersistenceRuntime\";\nimport {\n type AuthoredManifestBundle,\n acknowledgedAuthoredBundle,\n} from \"../verifiedCitations/authoredBundleCitation\";\n\nexport type { AuthoredManifestBundle } from \"../verifiedCitations/authoredBundleCitation\";\n\nimport { loadContainerRetirementCheck } from \"../principalContracts/principalGrantRetirementPersistence\";\nimport {\n accessManifestObjectKey,\n loadAccessManifestCheckpointRows,\n loadPrincipalPolicyCheckpointRows,\n principalPolicyKey,\n storedPrincipalPolicyPin,\n upsertAccessManifestCheckpointsInTransaction,\n} from \"./keyingCheckpointPersistence\";\n\nexport interface LocallyAcknowledgedAccessManifestHead {\n readonly checkpoint: AccessManifestCheckpoint;\n readonly previousManifestHash: string | null;\n /**\n * The head's bundle as a projection serves it, when the acknowledgement's\n * digest matched the plan; stored for citation with the checkpoint.\n */\n readonly servedBundle?: ServedAccessManifestBundleWireResponse | null;\n}\n\nexport function locallyAuthoredAccessManifestHead(plan: {\n readonly manifest: AccessManifest;\n readonly manifestHash: string;\n}): LocallyAcknowledgedAccessManifestHead {\n return {\n checkpoint: accessManifestCheckpointFromManifest({\n manifest: plan.manifest,\n manifestHash: plan.manifestHash,\n }),\n previousManifestHash: plan.manifest.previousManifestHash,\n };\n}\n\n/**\n * An authored head with its served bundle for citation, when the\n * acknowledgement's digest names exactly the bundle the plan builds.\n */\nexport async function locallyAcknowledgedAuthoredHead(\n plan: AuthoredManifestBundle,\n bundleDigest: string,\n): Promise<LocallyAcknowledgedAccessManifestHead> {\n return {\n ...locallyAuthoredAccessManifestHead(plan),\n servedBundle: await acknowledgedAuthoredBundle(plan, bundleDigest),\n };\n}\n\nfunction validateAcknowledgedHead(\n head: LocallyAcknowledgedAccessManifestHead,\n localCheckpoint: AccessManifestCheckpoint | null,\n): void {\n if (!localCheckpoint) {\n if (head.checkpoint.epoch !== 1 || head.previousManifestHash !== null) {\n throw new KeyingVerificationError(\n \"stale_predecessor\",\n \"locally acknowledged access manifest does not begin at epoch 1\",\n );\n }\n return;\n }\n\n verifyAccessManifestLocalCheckpoint({\n checkpointPredecessors: [],\n current: {\n ...head.checkpoint,\n previousManifestHash: head.previousManifestHash,\n },\n localCheckpoint,\n });\n}\n\nasync function validateAcknowledgedHeads(\n tx: ClientSQLiteTransactionScope,\n heads: readonly LocallyAcknowledgedAccessManifestHead[],\n stored: Awaited<ReturnType<typeof loadAccessManifestCheckpointRows>>,\n): Promise<Map<string, AccessManifestCheckpoint>> {\n const pending = new Map<string, AccessManifestCheckpoint>();\n const assertNotRetired = await loadContainerRetirementCheck(\n tx,\n heads.map((head) => head.checkpoint),\n );\n for (const head of heads) {\n assertNotRetired(head.checkpoint);\n const key = accessManifestObjectKey(head.checkpoint);\n if (pending.has(key)) {\n throw new KeyingVerificationError(\n \"equivocation\",\n `locally acknowledged batch contains multiple heads for ${key}`,\n );\n }\n const row = stored.get(key);\n validateAcknowledgedHead(head, row ? { ...head.checkpoint, ...row } : null);\n pending.set(key, head.checkpoint);\n }\n return pending;\n}\n\n/** Heads this client authored, with the pins its plan read. */\nexport interface LocallyAcknowledgedAdvance {\n readonly heads: readonly LocallyAcknowledgedAccessManifestHead[];\n /** Optional optimistic read dependencies, checked inside the write transaction. */\n readonly expectedAccessManifestCheckpoints?: readonly AccessManifestCheckpoint[];\n readonly expectedPrincipalPolicyCheckpoints?: readonly PrincipalPolicyCheckpoint[];\n readonly stillCurrent?: (() => boolean) | undefined;\n}\n\n/**\n * Commits only heads authored and signed by this client after an exact remote\n * acknowledgement check. Every non-initial head must directly extend the\n * latest durable pin; arbitrary remote projections must use the verified\n * projection checkpoint path instead.\n */\nexport async function acknowledgeLocallyAuthoredHeadsInTransaction(\n tx: ClientSQLiteTransactionScope,\n advance: LocallyAcknowledgedAdvance,\n updatedAt: string,\n): Promise<void> {\n const expectedAccess = advance.expectedAccessManifestCheckpoints ?? [];\n const expectedPolicies = advance.expectedPrincipalPolicyCheckpoints ?? [];\n const stored = await loadAccessManifestCheckpointRows(tx, [\n ...advance.heads.map((head) => head.checkpoint),\n ...expectedAccess,\n ]);\n for (const expected of expectedAccess) {\n const current = stored.get(accessManifestObjectKey(expected));\n if (\n current?.epoch !== expected.epoch ||\n current.manifestHash !== expected.manifestHash\n ) {\n throw new KeyingVerificationError(\n \"stale_predecessor\",\n \"A re-citation container checkpoint changed before acknowledgement\",\n );\n }\n }\n const policies = await loadPrincipalPolicyCheckpointRows(\n tx,\n expectedPolicies,\n );\n for (const expected of expectedPolicies) {\n const current = storedPrincipalPolicyPin(\n policies.get(principalPolicyKey(expected)),\n );\n if (\n current?.version !== expected.version ||\n current.stateHash !== expected.stateHash\n ) {\n throw new KeyingVerificationError(\n \"stale_predecessor\",\n \"A re-citation principal policy checkpoint changed before acknowledgement\",\n );\n }\n }\n const pending = await validateAcknowledgedHeads(tx, advance.heads, stored);\n await upsertAccessManifestCheckpointsInTransaction(\n tx,\n [...pending.values()],\n updatedAt,\n );\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type AccessEvent, type AccessManifest } from "../../../internal/crypto/index.js";
|
|
2
|
+
import { type ServedAccessManifestBundleWireResponse } from "../../../internal/validators/util/index.js";
|
|
3
|
+
/** The signed parts and derived state of a head this client authored. */
|
|
4
|
+
export interface AuthoredManifestBundle {
|
|
5
|
+
readonly body: unknown;
|
|
6
|
+
readonly event: AccessEvent;
|
|
7
|
+
readonly eventHash: string;
|
|
8
|
+
readonly manifest: AccessManifest;
|
|
9
|
+
readonly manifestHash: string;
|
|
10
|
+
readonly state: object;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The bundle a writer projection serves for a head this client authored,
|
|
14
|
+
* built from its own signed plan, when it has exactly the citation digest
|
|
15
|
+
* the acknowledgement named. A projection request may then cite it instead
|
|
16
|
+
* of downloading it back. Any difference only means the next read carries
|
|
17
|
+
* those bytes: a cited projection is verified from scratch, and a stored
|
|
18
|
+
* bundle that fails verification is dropped and read again uncited.
|
|
19
|
+
*/
|
|
20
|
+
export declare function acknowledgedAuthoredBundle(plan: AuthoredManifestBundle, bundleDigest: string): Promise<ServedAccessManifestBundleWireResponse | null>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { computeAccessManifestBundleDigest, readKeyingCanonicalJson, } from "../../../internal/crypto/index.js";
|
|
2
|
+
import { toServedAccessManifestBundle, } from "../../../internal/validators/util/index.js";
|
|
3
|
+
import { readCanonicalRecord } from "../../keying/canonicalJson.js";
|
|
4
|
+
/**
|
|
5
|
+
* The bundle a writer projection serves for a head this client authored,
|
|
6
|
+
* built from its own signed plan, when it has exactly the citation digest
|
|
7
|
+
* the acknowledgement named. A projection request may then cite it instead
|
|
8
|
+
* of downloading it back. Any difference only means the next read carries
|
|
9
|
+
* those bytes: a cited projection is verified from scratch, and a stored
|
|
10
|
+
* bundle that fails verification is dropped and read again uncited.
|
|
11
|
+
*/
|
|
12
|
+
export async function acknowledgedAuthoredBundle(plan, bundleDigest) {
|
|
13
|
+
try {
|
|
14
|
+
const served = toServedAccessManifestBundle({
|
|
15
|
+
event: {
|
|
16
|
+
body: readKeyingCanonicalJson(plan.body, "Authored event body"),
|
|
17
|
+
event: readCanonicalRecord({ ...plan.event }, "Authored event"),
|
|
18
|
+
eventHash: plan.eventHash,
|
|
19
|
+
},
|
|
20
|
+
manifest: readCanonicalRecord({ ...plan.manifest }, "Authored manifest"),
|
|
21
|
+
manifestHash: plan.manifestHash,
|
|
22
|
+
state: readCanonicalRecord({ ...plan.state }, "Authored state"),
|
|
23
|
+
});
|
|
24
|
+
return (await computeAccessManifestBundleDigest(served)) === bundleDigest
|
|
25
|
+
? served
|
|
26
|
+
: null;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=authoredBundleCitation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoredBundleCitation.js","sourceRoot":"","sources":["authoredBundleCitation.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iCAAiC,EACjC,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,4BAA4B,GAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAYjE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,IAA4B,EAC5B,YAAoB;IAEpB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,4BAA4B,CAAC;YAC1C,KAAK,EAAE;gBACL,IAAI,EAAE,uBAAuB,CAAC,IAAI,CAAC,IAAI,EAAE,qBAAqB,CAAC;gBAC/D,KAAK,EAAE,mBAAmB,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,gBAAgB,CAAC;gBAC/D,SAAS,EAAE,IAAI,CAAC,SAAS;aAC1B;YACD,QAAQ,EAAE,mBAAmB,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,EAAE,mBAAmB,CAAC;YACxE,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,mBAAmB,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,gBAAgB,CAAC;SAChE,CAAC,CAAC;QACH,OAAO,CAAC,MAAM,iCAAiC,CAAC,MAAM,CAAC,CAAC,KAAK,YAAY;YACvE,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import {\n type AccessEvent,\n type AccessManifest,\n computeAccessManifestBundleDigest,\n readKeyingCanonicalJson,\n} from \"@tearleads/crypto\";\nimport {\n type ServedAccessManifestBundleWireResponse,\n toServedAccessManifestBundle,\n} from \"@tearleads/validators/util\";\nimport { readCanonicalRecord } from \"../../keying/canonicalJson\";\n\n/** The signed parts and derived state of a head this client authored. */\nexport interface AuthoredManifestBundle {\n readonly body: unknown;\n readonly event: AccessEvent;\n readonly eventHash: string;\n readonly manifest: AccessManifest;\n readonly manifestHash: string;\n readonly state: object;\n}\n\n/**\n * The bundle a writer projection serves for a head this client authored,\n * built from its own signed plan, when it has exactly the citation digest\n * the acknowledgement named. A projection request may then cite it instead\n * of downloading it back. Any difference only means the next read carries\n * those bytes: a cited projection is verified from scratch, and a stored\n * bundle that fails verification is dropped and read again uncited.\n */\nexport async function acknowledgedAuthoredBundle(\n plan: AuthoredManifestBundle,\n bundleDigest: string,\n): Promise<ServedAccessManifestBundleWireResponse | null> {\n try {\n const served = toServedAccessManifestBundle({\n event: {\n body: readKeyingCanonicalJson(plan.body, \"Authored event body\"),\n event: readCanonicalRecord({ ...plan.event }, \"Authored event\"),\n eventHash: plan.eventHash,\n },\n manifest: readCanonicalRecord({ ...plan.manifest }, \"Authored manifest\"),\n manifestHash: plan.manifestHash,\n state: readCanonicalRecord({ ...plan.state }, \"Authored state\"),\n });\n return (await computeAccessManifestBundleDigest(served)) === bundleDigest\n ? served\n : null;\n } catch {\n return null;\n }\n}\n"]}
|
|
@@ -48,6 +48,16 @@ export declare function writeVerifiedManifestBundlesInTransaction(tx: ClientSQLi
|
|
|
48
48
|
* dropped.
|
|
49
49
|
*/
|
|
50
50
|
export declare function loadVerifiedManifestCitations(execSql: ExecSql, target: WriterProjectionTarget, requestedLimit?: number): Promise<HeldProjectionCitation[]>;
|
|
51
|
+
/** Keeps these held bundles out of citations until the release runs. */
|
|
52
|
+
export declare function suppressHeldCitations(manifestHashes: readonly string[]): () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Drops the stored rows of held bundles a projection that cited them failed
|
|
55
|
+
* to verify with, so the next read fetches them from the server. Only a row
|
|
56
|
+
* still holding the exact bytes cited goes, so a newer verified copy written
|
|
57
|
+
* meanwhile stays; nothing is dropped once `stillCurrent` turns false.
|
|
58
|
+
* Resolves whether the drop committed.
|
|
59
|
+
*/
|
|
60
|
+
export declare function dropHeldManifestBundles(execSql: ExecSql, heldBundles: readonly ServedAccessManifestBundleWireResponse[], stillCurrent?: () => boolean): Promise<boolean>;
|
|
51
61
|
/** Cites from whichever database the signed-in identity currently uses. */
|
|
52
62
|
export declare function createVerifiedManifestCitations(resolveExecSql: () => ExecSql | null): VerifiedManifestCitations;
|
|
53
63
|
/** Drops an organization's verified bundles when a remote reset forgets it. */
|
|
@@ -167,6 +167,18 @@ export async function loadVerifiedManifestCitations(execSql, target, requestedLi
|
|
|
167
167
|
const limit = Math.min(KNOWN_MANIFEST_HINT_LIMIT, Math.floor(requestedLimit));
|
|
168
168
|
if (!(limit > 0))
|
|
169
169
|
return [];
|
|
170
|
+
const loadGeneration = evictionGeneration;
|
|
171
|
+
citationLoadsInFlight += 1;
|
|
172
|
+
try {
|
|
173
|
+
return await loadCitableManifestCitations(execSql, target, limit).then((cited) => cited.filter((citation) => citable(citation, loadGeneration)));
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
citationLoadsInFlight -= 1;
|
|
177
|
+
if (citationLoadsInFlight === 0)
|
|
178
|
+
evictedInGeneration.clear();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async function loadCitableManifestCitations(execSql, target, limit) {
|
|
170
182
|
await ensureSqlTables(execSql, [
|
|
171
183
|
...verifiedManifestBundleTables,
|
|
172
184
|
...containerTables,
|
|
@@ -181,17 +193,91 @@ export async function loadVerifiedManifestCitations(execSql, target, requestedLi
|
|
|
181
193
|
return [];
|
|
182
194
|
const { cited, damaged } = await collectVerifiedManifestCitations(db, organizationId, objects, target, limit);
|
|
183
195
|
if (damaged.length > 0)
|
|
184
|
-
await
|
|
185
|
-
.runMutation(async (handle) => {
|
|
186
|
-
for (const batch of batches([...new Set(damaged)]))
|
|
187
|
-
await handle
|
|
188
|
-
.delete(bundles)
|
|
189
|
-
.where(inArray(bundles.manifestHash, batch))
|
|
190
|
-
.run();
|
|
191
|
-
})
|
|
192
|
-
.catch(() => undefined);
|
|
196
|
+
await dropVerifiedManifestBundles(execSql, damaged).catch(() => undefined);
|
|
193
197
|
return cited;
|
|
194
198
|
}
|
|
199
|
+
// Manifest hashes whose held rows a refused read is dropping: no read cites
|
|
200
|
+
// them meanwhile, so none can be rebuilt from the bytes being dropped. Each
|
|
201
|
+
// eviction also advances a generation, so a citation load that started
|
|
202
|
+
// before it never returns the rows it read: they may already be gone.
|
|
203
|
+
const suppressedCitations = new Map();
|
|
204
|
+
const evictedInGeneration = new Map();
|
|
205
|
+
let evictionGeneration = 0;
|
|
206
|
+
// Loads in flight; once none overlap, the eviction log has nothing to guard.
|
|
207
|
+
let citationLoadsInFlight = 0;
|
|
208
|
+
/** Keeps these held bundles out of citations until the release runs. */
|
|
209
|
+
export function suppressHeldCitations(manifestHashes) {
|
|
210
|
+
evictionGeneration += 1;
|
|
211
|
+
for (const hash of manifestHashes) {
|
|
212
|
+
suppressedCitations.set(hash, (suppressedCitations.get(hash) ?? 0) + 1);
|
|
213
|
+
evictedInGeneration.set(hash, evictionGeneration);
|
|
214
|
+
}
|
|
215
|
+
return () => {
|
|
216
|
+
// The drop is complete: a load that started before now may hold the
|
|
217
|
+
// dropped bytes, so it is newer than none of them.
|
|
218
|
+
evictionGeneration += 1;
|
|
219
|
+
for (const hash of manifestHashes) {
|
|
220
|
+
evictedInGeneration.set(hash, evictionGeneration);
|
|
221
|
+
const count = (suppressedCitations.get(hash) ?? 1) - 1;
|
|
222
|
+
if (count > 0)
|
|
223
|
+
suppressedCitations.set(hash, count);
|
|
224
|
+
else
|
|
225
|
+
suppressedCitations.delete(hash);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function citable(citation, loadGeneration) {
|
|
230
|
+
if (!("manifestHash" in citation))
|
|
231
|
+
return true;
|
|
232
|
+
const { manifestHash } = citation;
|
|
233
|
+
return (!suppressedCitations.has(manifestHash) &&
|
|
234
|
+
(evictedInGeneration.get(manifestHash) ?? 0) <= loadGeneration);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Drops the stored rows of held bundles a projection that cited them failed
|
|
238
|
+
* to verify with, so the next read fetches them from the server. Only a row
|
|
239
|
+
* still holding the exact bytes cited goes, so a newer verified copy written
|
|
240
|
+
* meanwhile stays; nothing is dropped once `stillCurrent` turns false.
|
|
241
|
+
* Resolves whether the drop committed.
|
|
242
|
+
*/
|
|
243
|
+
export async function dropHeldManifestBundles(execSql, heldBundles, stillCurrent) {
|
|
244
|
+
if (heldBundles.length === 0)
|
|
245
|
+
return true;
|
|
246
|
+
const cited = await Promise.all(heldBundles.map(async (bundle) => ({
|
|
247
|
+
manifestHash: bundle.manifestHash,
|
|
248
|
+
bundleDigest: await sha256Hex(JSON.stringify(bundle)),
|
|
249
|
+
})));
|
|
250
|
+
await ensureSqlTables(execSql, verifiedManifestBundleTables);
|
|
251
|
+
const runtime = getClientSQLitePersistenceRuntime(execSql);
|
|
252
|
+
const drop = async (tx) => {
|
|
253
|
+
for (const row of cited)
|
|
254
|
+
await tx
|
|
255
|
+
.delete(bundles)
|
|
256
|
+
.where(and(eq(bundles.manifestHash, row.manifestHash), eq(bundles.bundleDigest, row.bundleDigest)))
|
|
257
|
+
.run();
|
|
258
|
+
};
|
|
259
|
+
if (!stillCurrent) {
|
|
260
|
+
await runtime.transaction(drop, { behavior: "immediate" });
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
const { committed } = await runtime.guardedTransaction(drop, stillCurrent, {
|
|
264
|
+
behavior: "immediate",
|
|
265
|
+
});
|
|
266
|
+
return committed;
|
|
267
|
+
}
|
|
268
|
+
/** Drops damaged stored rows so no later read cites them. */
|
|
269
|
+
async function dropVerifiedManifestBundles(execSql, manifestHashes) {
|
|
270
|
+
if (manifestHashes.length === 0)
|
|
271
|
+
return;
|
|
272
|
+
await ensureSqlTables(execSql, verifiedManifestBundleTables);
|
|
273
|
+
await getClientSQLitePersistenceRuntime(execSql).runMutation(async (handle) => {
|
|
274
|
+
for (const batch of batches([...new Set(manifestHashes)]))
|
|
275
|
+
await handle
|
|
276
|
+
.delete(bundles)
|
|
277
|
+
.where(inArray(bundles.manifestHash, batch))
|
|
278
|
+
.run();
|
|
279
|
+
});
|
|
280
|
+
}
|
|
195
281
|
/** Cites from whichever database the signed-in identity currently uses. */
|
|
196
282
|
export function createVerifiedManifestCitations(resolveExecSql) {
|
|
197
283
|
return {
|