@tearleads/client-sdk 0.1.225 → 0.1.226
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/principalContainerMutations.js.map +1 -1
- package/client/organizations/recipientAdmission.js +1 -1
- package/client/organizations/recipientAdmission.js.map +1 -1
- package/client/organizations/rosterAdmissionEvidence.js +1 -1
- package/client/organizations/rosterAdmissionEvidence.js.map +1 -1
- package/data/containers/shared/authorAccess.d.ts +1 -1
- package/data/containers/shared/authorAccess.js.map +1 -1
- package/data/containers/shared/heldContainerHeads.js.map +1 -1
- package/data/containers/shared/principalPolicies.js.map +1 -1
- package/data/containers/shared/types.d.ts +1 -1
- package/data/containers/shared/types.js.map +1 -1
- package/data/keyingProjectionVerification/checkpoints/accessManifestCheckpointEnforcement.js.map +1 -1
- package/data/keyingProjectionVerification/checkpoints/checkpointContext.d.ts +1 -1
- package/data/keyingProjectionVerification/checkpoints/checkpointContext.js.map +1 -1
- package/data/keyingProjectionVerification/container/containerProjectionVerification.d.ts +1 -1
- package/data/keyingProjectionVerification/container/containerProjectionVerification.js.map +1 -1
- package/data/keyingProjectionVerification/documentPurge/documentPurgePrincipalEvidence.js +1 -1
- package/data/keyingProjectionVerification/documentPurge/documentPurgePrincipalEvidence.js.map +1 -1
- package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js +1 -1
- package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js.map +1 -1
- package/data/keyingProjectionVerification/principalPolicy/principalPolicyCache.js +2 -2
- package/data/keyingProjectionVerification/principalPolicy/principalPolicyCache.js.map +1 -1
- package/data/keyingProjectionVerification/principalPolicy/principalPolicySigners.js +2 -2
- package/data/keyingProjectionVerification/principalPolicy/principalPolicySigners.js.map +1 -1
- package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.d.ts +1 -1
- package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.js +4 -4
- package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.js.map +1 -1
- package/data/keyingProjectionVerification/types.d.ts +1 -1
- package/data/keyingProjectionVerification/types.js.map +1 -1
- package/data/persistence/keyingCheckpoints/keyingCheckpointAdvancePersistence.js +1 -1
- package/data/persistence/keyingCheckpoints/keyingCheckpointAdvancePersistence.js.map +1 -1
- package/data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.js +1 -1
- package/data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.js.map +1 -1
- package/data/persistence/keyingCheckpoints/organizationReplacementCheckpointPersistence.js +1 -1
- package/data/persistence/keyingCheckpoints/organizationReplacementCheckpointPersistence.js.map +1 -1
- package/data/persistence/organizationFounderPersistence.js +1 -1
- package/data/persistence/organizationFounderPersistence.js.map +1 -1
- package/data/persistence/principalCurrentAcknowledgementPersistence.js +1 -1
- package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -1
- package/data/persistence/principalPolicy/heldPrincipalState.js +1 -1
- package/data/persistence/principalPolicy/heldPrincipalState.js.map +1 -1
- package/data/persistence/principalPolicy/locallyAcknowledgedPrincipalPolicyPersistence.js +1 -1
- package/data/persistence/principalPolicy/locallyAcknowledgedPrincipalPolicyPersistence.js.map +1 -1
- package/data/persistence/principalPolicy/principalPolicyBundleRepository.js.map +1 -1
- package/data/persistence/principalPolicy/principalPolicyReferenceCheckpoint.js +1 -1
- package/data/persistence/principalPolicy/principalPolicyReferenceCheckpoint.js.map +1 -1
- package/data/persistence/principalPolicy/principalPolicyReferenceIndexPersistence.js +1 -1
- package/data/persistence/principalPolicy/principalPolicyReferenceIndexPersistence.js.map +1 -1
- package/data/persistence/principalPolicy/principalPolicyReferencePersistence.js +1 -1
- package/data/persistence/principalPolicy/principalPolicyReferencePersistence.js.map +1 -1
- package/data/principals/organizationGroupRoles.js +1 -1
- package/data/principals/organizationGroupRoles.js.map +1 -1
- package/package.json +1 -1
- package/workflows/containers/child/create/index.js.map +1 -1
- package/workflows/containers/child/move/moveRequest.js.map +1 -1
- package/workflows/containers/child/move/moveWraps.js.map +1 -1
- package/workflows/containers/child/mutationRequestCore.js.map +1 -1
- package/workflows/containers/child/mutationSubmit.d.ts +1 -1
- package/workflows/containers/child/mutationSubmit.js.map +1 -1
- package/workflows/containers/child/recitePlan.js.map +1 -1
- package/workflows/containers/child/rekey/carriedDescendantRekeys.d.ts +1 -1
- package/workflows/containers/child/rekey/carriedDescendantRekeys.js.map +1 -1
- package/workflows/containers/child/rekey/index.d.ts +1 -1
- package/workflows/containers/child/rekey/index.js.map +1 -1
- package/workflows/containers/child/revoke.d.ts +1 -1
- package/workflows/containers/child/revoke.js.map +1 -1
- package/workflows/containers/child/rotation/replacementPrincipalPolicyReferences.js.map +1 -1
- package/workflows/containers/child/rotation/rotationPrincipalPolicies.js.map +1 -1
- package/workflows/containers/child/rotation/rotationWraps.js.map +1 -1
- package/workflows/containers/child/share/sharePlanCore.d.ts +1 -1
- package/workflows/containers/child/share/sharePlanCore.js.map +1 -1
- package/workflows/containers/rematerialization/authoredPrincipalPolicyWarmer.js +1 -1
- package/workflows/containers/rematerialization/authoredPrincipalPolicyWarmer.js.map +1 -1
- package/workflows/containers/rematerialization/principalContainerRematerializationPlanning.js.map +1 -1
- package/workflows/containers/rematerialization/principalContainerRematerializationTargets.js.map +1 -1
- package/workflows/documents/linkSet/linkSetAuthority.js.map +1 -1
- package/workflows/organizations/currentOrganizationAuthority.d.ts +1 -1
- package/workflows/organizations/currentOrganizationAuthority.js +1 -1
- package/workflows/organizations/currentOrganizationAuthority.js.map +1 -1
- package/workflows/organizations/groupMetadata/currentGroupMetadataAuthority.js +1 -1
- package/workflows/organizations/groupMetadata/currentGroupMetadataAuthority.js.map +1 -1
- package/workflows/organizations/groupMetadata/groupMetadataBinding.js.map +1 -1
- package/workflows/organizations/groupMetadata/groupMetadataContainerAuthority.js +2 -2
- package/workflows/organizations/groupMetadata/groupMetadataContainerAuthority.js.map +1 -1
- package/workflows/organizations/groupMetadata/groupMetadataRootBinding.js +2 -2
- package/workflows/organizations/groupMetadata/groupMetadataRootBinding.js.map +1 -1
- package/workflows/organizations/groupNames/groupNameUniqueness.js +2 -2
- package/workflows/organizations/groupNames/groupNameUniqueness.js.map +1 -1
- package/workflows/organizations/groupNames/organizationGroupNamePolicies.js +2 -2
- package/workflows/organizations/groupNames/organizationGroupNamePolicies.js.map +1 -1
- package/workflows/organizations/groupPolicy/currentGroupPolicyMutationContext.js +1 -1
- package/workflows/organizations/groupPolicy/currentGroupPolicyMutationContext.js.map +1 -1
- package/workflows/organizations/groupPolicy/groupPolicyMutationContext.js +1 -1
- package/workflows/organizations/groupPolicy/groupPolicyMutationContext.js.map +1 -1
- package/workflows/organizations/groupPolicy/groupPolicyRequests.js +1 -1
- package/workflows/organizations/groupPolicy/groupPolicyRequests.js.map +1 -1
- package/workflows/organizations/groupPolicy/groupPolicyVerification.js +1 -1
- package/workflows/organizations/groupPolicy/groupPolicyVerification.js.map +1 -1
- package/workflows/organizations/groupShare/currentSharePrincipalPolicy.js +1 -1
- package/workflows/organizations/groupShare/currentSharePrincipalPolicy.js.map +1 -1
- package/workflows/organizations/groupShare/sharePrincipalPolicy.js +2 -2
- package/workflows/organizations/groupShare/sharePrincipalPolicy.js.map +1 -1
- package/workflows/organizations/groups/createCurrentOrganizationGroup.js +1 -1
- package/workflows/organizations/groups/createCurrentOrganizationGroup.js.map +1 -1
- package/workflows/organizations/groups/organizationGroupDirectory.js +1 -1
- package/workflows/organizations/groups/organizationGroupDirectory.js.map +1 -1
- package/workflows/organizations/memberships/leaveRequestMembersEvidence.js +1 -1
- package/workflows/organizations/memberships/leaveRequestMembersEvidence.js.map +1 -1
- package/workflows/organizations/policyHistory/organizationPolicyHistoryDetails.js.map +1 -1
- package/workflows/organizations/policyHistory/organizationPolicyHistoryVerification.js +1 -1
- package/workflows/organizations/policyHistory/organizationPolicyHistoryVerification.js.map +1 -1
- package/workflows/organizations/principalMutations/acknowledgedDirectoryBindings.js +1 -1
- package/workflows/organizations/principalMutations/acknowledgedDirectoryBindings.js.map +1 -1
- package/workflows/organizations/principalMutations/currentOrganizationMutationAuthority.js +1 -1
- package/workflows/organizations/principalMutations/currentOrganizationMutationAuthority.js.map +1 -1
- package/workflows/organizations/principalMutations/currentOrganizationMutationRetention.js +1 -1
- package/workflows/organizations/principalMutations/currentOrganizationMutationRetention.js.map +1 -1
- package/workflows/organizations/principalMutations/runtimeCurrentGroupMutation.js +1 -1
- package/workflows/organizations/principalMutations/runtimeCurrentGroupMutation.js.map +1 -1
- package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js +1 -1
- package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js.map +1 -1
- package/workflows/organizations/principalPolicy/principalPolicyRecipients.js +1 -1
- package/workflows/organizations/principalPolicy/principalPolicyRecipients.js.map +1 -1
- package/workflows/organizations/principalPolicy/principalPolicyRequest.js +1 -1
- package/workflows/organizations/principalPolicy/principalPolicyRequest.js.map +1 -1
- package/workflows/principals/acknowledgements/acknowledgedPrincipalPredecessor.js +2 -2
- package/workflows/principals/acknowledgements/acknowledgedPrincipalPredecessor.js.map +1 -1
- package/workflows/principals/acknowledgements/initialPrincipalCurrentPublication.js +1 -1
- package/workflows/principals/acknowledgements/initialPrincipalCurrentPublication.js.map +1 -1
- package/workflows/principals/acknowledgements/reconcileAcknowledgedPrincipalCurrent.js +1 -1
- package/workflows/principals/acknowledgements/reconcileAcknowledgedPrincipalCurrent.js.map +1 -1
- package/workflows/principals/externalAdminPolicy.d.ts +1 -1
- package/workflows/principals/externalAdminPolicy.js +2 -2
- package/workflows/principals/externalAdminPolicy.js.map +1 -1
- package/workflows/principals/historyRecovery/principalHistoryRecoveryAuthority.js +1 -1
- package/workflows/principals/historyRecovery/principalHistoryRecoveryAuthority.js.map +1 -1
- package/workflows/principals/historyRecovery/principalHistoryRecoveryReferences.js +1 -1
- package/workflows/principals/historyRecovery/principalHistoryRecoveryReferences.js.map +1 -1
- package/workflows/principals/historyRecovery/recoverPrincipalPolicyHistory.js +1 -1
- package/workflows/principals/historyRecovery/recoverPrincipalPolicyHistory.js.map +1 -1
- package/workflows/principals/historyRecovery/recoverScopedPrincipalPolicyHistory.js +1 -1
- package/workflows/principals/historyRecovery/recoverScopedPrincipalPolicyHistory.js.map +1 -1
- package/workflows/principals/policyCache/index.js +1 -1
- package/workflows/principals/policyCache/index.js.map +1 -1
- package/workflows/principals/policyCache/principalPolicyCacheValidation.js +1 -1
- package/workflows/principals/policyCache/principalPolicyCacheValidation.js.map +1 -1
- package/workflows/principals/policyCache/principalPolicyOrganizationScope.js +2 -2
- package/workflows/principals/policyCache/principalPolicyOrganizationScope.js.map +1 -1
- package/workflows/principals/policyVerification.js +1 -1
- package/workflows/principals/policyVerification.js.map +1 -1
- package/workflows/principals/principalPolicyService.js +1 -1
- package/workflows/principals/principalPolicyService.js.map +1 -1
- package/workflows/principals/publicHistory/publicPrincipalHistoryAuthority.js +1 -1
- package/workflows/principals/publicHistory/publicPrincipalHistoryAuthority.js.map +1 -1
- package/workflows/principals/publicHistory/publicPrincipalHistoryProgress.js +1 -1
- package/workflows/principals/publicHistory/publicPrincipalHistoryProgress.js.map +1 -1
- package/workflows/principals/publicHistory/publicProjectionDirectory.js +1 -1
- package/workflows/principals/publicHistory/publicProjectionDirectory.js.map +1 -1
- package/workflows/principals/publicHistory/publicProjectionPrincipal.js +1 -1
- package/workflows/principals/publicHistory/publicProjectionPrincipal.js.map +1 -1
- package/workflows/principals/publicHistory/recoverProjectionPolicyHistory.js +1 -1
- package/workflows/principals/publicHistory/recoverProjectionPolicyHistory.js.map +1 -1
- package/workflows/principals/publicHistory/recoverPublicPrincipalHistory.js +2 -2
- package/workflows/principals/publicHistory/recoverPublicPrincipalHistory.js.map +1 -1
- package/workflows/principals/publicHistory/selectPublicPrincipalHistory.js +1 -1
- package/workflows/principals/publicHistory/selectPublicPrincipalHistory.js.map +1 -1
- package/workflows/principals/recoveryOperation/principalRecoveryDirectory.d.ts +1 -1
- package/workflows/principals/recoveryOperation/principalRecoveryDirectory.js +1 -1
- package/workflows/principals/recoveryOperation/principalRecoveryDirectory.js.map +1 -1
- package/workflows/principals/recoveryOperation/principalRecoveryLocalPreference.js +1 -1
- package/workflows/principals/recoveryOperation/principalRecoveryLocalPreference.js.map +1 -1
- package/workflows/principals/recoveryOperation/principalRecoveryMemo.js +1 -1
- package/workflows/principals/recoveryOperation/principalRecoveryMemo.js.map +1 -1
- package/workflows/registration/organizationProvisioning.js +2 -2
- package/workflows/registration/organizationProvisioning.js.map +1 -1
- package/workflows/registration/provisionedPrincipalHistory.js +1 -1
- package/workflows/registration/provisionedPrincipalHistory.js.map +1 -1
- package/workflows/registration/registrationAccessHeadPersistence.js +1 -1
- package/workflows/registration/registrationAccessHeadPersistence.js.map +1 -1
- /package/data/persistence/{principalKeys → principalContracts}/principalGrantRetirementPersistence.js +0 -0
- /package/data/persistence/{principalKeys → principalContracts}/principalGrantRetirementPersistence.js.map +0 -0
- /package/data/{principals → principalContracts}/organizationAuthorityDescriptor.d.ts +0 -0
- /package/data/{principals → principalContracts}/organizationAuthorityDescriptor.js +0 -0
- /package/data/{principals → principalContracts}/organizationAuthorityDescriptor.js.map +0 -0
- /package/data/{principals → principalContracts}/principalIdentityCommitments.js +0 -0
- /package/data/{principals → principalContracts}/principalIdentityCommitments.js.map +0 -0
- /package/data/{principals → principalContracts}/principalPolicyAdminSigners.js +0 -0
- /package/data/{principals → principalContracts}/principalPolicyAdminSigners.js.map +0 -0
- /package/data/{principals → principalContracts}/principalPolicyEvidence.d.ts +0 -0
- /package/data/{principals → principalContracts}/principalPolicyEvidence.js +0 -0
- /package/data/{principals → principalContracts}/principalPolicyEvidence.js.map +0 -0
- /package/data/{principals → principalContracts}/principalPolicyStates.js +0 -0
- /package/data/{principals → principalContracts}/principalPolicyStates.js.map +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyingVerificationError, principalPolicyMatchesReference, verifyDocumentPurgeEvent, } from "../../../internal/crypto/index.js";
|
|
2
|
-
import { parseOrganizationAuthorityDescriptor } from "../../
|
|
2
|
+
import { parseOrganizationAuthorityDescriptor } from "../../principalContracts/organizationAuthorityDescriptor.js";
|
|
3
3
|
import { verifyStandaloneAccessEventBundle } from "../checkpoints/bundleVerification.js";
|
|
4
4
|
import { verifyPurgeDocumentManifest } from "./documentPurgeDocumentChainVerification.js";
|
|
5
5
|
function principalIdentity(input) {
|
package/data/keyingProjectionVerification/documentPurge/documentPurgePrincipalEvidence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentPurgePrincipalEvidence.js","sourceRoot":"","sources":["documentPurgePrincipalEvidence.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAEvB,+BAA+B,EAM/B,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,oCAAoC,EAAE,MAAM,kDAAkD,CAAC;AACxG,OAAO,EAAE,iCAAiC,EAAE,MAAM,mCAAmC,CAAC;AAGtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAEvF,SAAS,iBAAiB,CAAC,KAG1B;IACC,OAAO,GAAG,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,iCAAiC,CAAC,KAG1C;IACC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA2C,CAAC;IACpE,MAAM,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QACjC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC;YAAE,SAAS;QAC/D,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QA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AAK,CAAC,UAAU;YAClC,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,cAAc;YAC1C,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,sBAAsB,EAAE;gBACtB,GAAG,KAAK,CAAC,wBAAwB;gBACjC,GAAG,sBAAsB,CAAC,MAAM,EAAE;aACnC;YACD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;SAC7D,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicyAuthorization,\n principalPolicyMatchesReference,\n type ReferencedPrincipalHead,\n type VerifiedContainerAccessManifest,\n type VerifiedDocumentLinkSetManifest,\n type VerifiedDocumentLinkSetSnapshot,\n type VerifiedPrincipalPolicySelection,\n verifyDocumentPurgeEvent,\n} from \"@tearleads/crypto\";\nimport type { DocumentPurgeProofResponse } from \"@tearleads/validators/response\";\nimport { parseOrganizationAuthorityDescriptor } from \"../../principals/organizationAuthorityDescriptor\";\nimport { verifyStandaloneAccessEventBundle } from \"../checkpoints/bundleVerification\";\nimport type { ProjectionCheckpointContext } from \"../checkpoints/checkpointContext\";\nimport type { PrincipalPolicyCache, ProjectionUserKeyResolver } from \"../types\";\nimport { verifyPurgeDocumentManifest } from \"./documentPurgeDocumentChainVerification\";\n\nfunction principalIdentity(input: {\n readonly principalId: string;\n readonly principalType: string;\n}): string {\n return `${input.principalType}:${input.principalId}`;\n}\n\nfunction collectEvidenceContainerManifests(input: {\n readonly roots: readonly VerifiedContainerAccessManifest[];\n readonly verifiedByHash: ReadonlyMap<string, VerifiedContainerAccessManifest>;\n}): VerifiedContainerAccessManifest[] {\n const selected = new Map<string, VerifiedContainerAccessManifest>();\n const pending = [...input.roots];\n while (pending.length > 0) {\n const manifest = pending.shift();\n if (!manifest || selected.has(manifest.manifestHash)) continue;\n selected.set(manifest.manifestHash, manifest);\n for (const dependencyHash of [\n manifest.manifest.previousManifestHash,\n manifest.state.parentManifestHash,\n ]) {\n if (!dependencyHash) continue;\n const dependency = input.verifiedByHash.get(dependencyHash);\n if (dependency) pending.push(dependency);\n }\n }\n return [...selected.values()];\n}\n\nfunction requireExactPurgePrincipalEvidence<\n TPolicy extends PrincipalPolicyAuthorization,\n>(input: {\n readonly authorizationEvidence: readonly TPolicy[];\n readonly verifiedContainerManifests: readonly VerifiedContainerAccessManifest[];\n readonly policyEvidence: DocumentPurgeProofResponse[\"policyEvidence\"];\n}): TPolicy[] {\n const references: ReferencedPrincipalHead[] =\n input.verifiedContainerManifests.flatMap(\n (manifest) => manifest.state.referencedPrincipalHeads,\n );\n const requiredByPrincipal = new Set<string>();\n\n for (const reference of references) {\n const policy = input.authorizationEvidence.find((candidate) =>\n principalPolicyMatchesReference({ policy: candidate, reference }),\n );\n if (!policy) {\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Document purge proof omits referenced principal policy evidence\",\n );\n }\n const identity = principalIdentity(policy);\n requiredByPrincipal.add(identity);\n // External authority is verified incrementally by paged recovery. Its\n // historical entries need not be copied into this returned selection.\n }\n\n const allowed = new Set(requiredByPrincipal);\n // Paged recovery has authenticated these payloads against their signed\n // organization states and verified their exact group-head bindings. This\n // identity allow-list cannot authenticate an unverified directory payload.\n for (const { payload } of input.policyEvidence.organizationPayloads) {\n const directory = parseOrganizationAuthorityDescriptor(payload.ciphertext);\n if (\n directory.groupHeads.some((head) => allowed.has(principalIdentity(head)))\n ) {\n allowed.add(`group:${directory.adminGroupId}`);\n allowed.add(`organization:${directory.organizationId}`);\n }\n }\n if (\n input.authorizationEvidence.some(\n (policy) => !allowed.has(principalIdentity(policy)),\n )\n )\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"Document purge proof includes unrelated principal policy evidence\",\n );\n return input.authorizationEvidence.filter((policy) =>\n requiredByPrincipal.has(principalIdentity(policy)),\n );\n}\n\nasync function authenticateDocumentPurgeEvent(input: {\n readonly authorizationEvidence: readonly VerifiedPrincipalPolicySelection[];\n readonly authorizingContainerPath: readonly VerifiedContainerAccessManifest[];\n readonly documentManifest:\n | VerifiedDocumentLinkSetManifest\n | VerifiedDocumentLinkSetSnapshot;\n readonly expectedDocumentId: string;\n readonly purgeEvent: DocumentPurgeProofResponse[\"purgeEvent\"];\n readonly policyEvidence: DocumentPurgeProofResponse[\"policyEvidence\"];\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly rootContainerManifests: readonly VerifiedContainerAccessManifest[];\n readonly verifiedContainerManifests: ReadonlyMap<\n string,\n VerifiedContainerAccessManifest\n >;\n}): Promise<{\n readonly principalPolicies: VerifiedPrincipalPolicySelection[];\n readonly purgeEventHash: string;\n}> {\n const event = await verifyStandaloneAccessEventBundle({\n bundle: input.purgeEvent,\n label: \"Document purge event\",\n resolveUserKey: input.resolveUserKey,\n });\n const evidenceContainerManifests = collectEvidenceContainerManifests({\n roots: input.rootContainerManifests,\n verifiedByHash: input.verifiedContainerManifests,\n });\n const principalPolicies = requireExactPurgePrincipalEvidence({\n authorizationEvidence: input.authorizationEvidence,\n verifiedContainerManifests: evidenceContainerManifests,\n policyEvidence: input.policyEvidence,\n });\n const verified = await verifyDocumentPurgeEvent({\n authorizingContainerPath: input.authorizingContainerPath,\n documentManifest: input.documentManifest,\n event,\n expectedDocumentId: input.expectedDocumentId,\n principalPolicies,\n });\n if (!verified.ok) throw verified.error;\n return {\n principalPolicies: [...input.authorizationEvidence],\n purgeEventHash: verified.value.eventHash,\n };\n}\n\nexport async function authenticateDocumentPurgeArtifacts(input: {\n readonly authorizationEvidence: readonly VerifiedPrincipalPolicySelection[];\n readonly authorizingContainerPath: readonly VerifiedContainerAccessManifest[];\n readonly checkpointContext: ProjectionCheckpointContext;\n readonly containerPathByManifestHash: ReadonlyMap<\n string,\n readonly VerifiedContainerAccessManifest[]\n >;\n readonly enforceLocalCheckpoints: boolean;\n readonly expectedDocumentId: string;\n readonly principalPolicyCache: PrincipalPolicyCache;\n readonly proof: DocumentPurgeProofResponse;\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly verifiedContainerManifests: ReadonlyMap<\n string,\n VerifiedContainerAccessManifest\n >;\n}) {\n const usedContainerManifests = new Map<\n string,\n VerifiedContainerAccessManifest\n >();\n const documentManifest = await verifyPurgeDocumentManifest({\n authorizationEvidence: input.authorizationEvidence,\n checkpointContext: input.checkpointContext,\n containerPathByManifestHash: input.containerPathByManifestHash,\n enforceLocalCheckpoints: input.enforceLocalCheckpoints,\n principalPolicyCache: input.principalPolicyCache,\n proof: input.proof,\n resolveUserKey: input.resolveUserKey,\n usedContainerManifests,\n });\n return {\n documentManifest,\n ...(await authenticateDocumentPurgeEvent({\n authorizationEvidence: input.authorizationEvidence,\n authorizingContainerPath: input.authorizingContainerPath,\n documentManifest,\n expectedDocumentId: input.expectedDocumentId,\n purgeEvent: input.proof.purgeEvent,\n policyEvidence: input.proof.policyEvidence,\n resolveUserKey: input.resolveUserKey,\n rootContainerManifests: [\n ...input.authorizingContainerPath,\n ...usedContainerManifests.values(),\n ],\n verifiedContainerManifests: input.verifiedContainerManifests,\n })),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentPurgePrincipalEvidence.js","sourceRoot":"","sources":["documentPurgePrincipalEvidence.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAEvB,+BAA+B,EAM/B,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,oCAAoC,EAAE,MAAM,0DAA0D,CAAC;AAChH,OAAO,EAAE,iCAAiC,EAAE,MAAM,mCAAmC,CAAC;AAGtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAEvF,SAAS,iBAAiB,CAAC,KAG1B;IACC,OAAO,GAAG,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,iCAAiC,CAAC,KAG1C;IACC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA2C,CAAC;IACpE,MAAM,OAAO,GAAG,CAAC,GAAG,KAAK,CAAC,KAA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ClB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,sBAAsB;KACvB,CAAC,CAAC;IACH,OAAO;QACL,gBAAgB;QAChB,GAAG,CAAC,MAAM,8BAA8B,CAAC;YACvC,qBAAqB,EAAE,KAAK,CAAC,qBAAqB;YAClD,wBAAwB,EAAE,KAAK,CAAC,wBAAwB;YACxD,gBAAgB;YAChB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU;YAClC,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,cAAc;YAC1C,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,sBAAsB,EAAE;gBACtB,GAAG,KAAK,CAAC,wBAAwB;gBACjC,GAAG,sBAAsB,CAAC,MAAM,EAAE;aACnC;YACD,0BAA0B,EAAE,KAAK,CAAC,0BAA0B;SAC7D,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicyAuthorization,\n principalPolicyMatchesReference,\n type ReferencedPrincipalHead,\n type VerifiedContainerAccessManifest,\n type VerifiedDocumentLinkSetManifest,\n type VerifiedDocumentLinkSetSnapshot,\n type VerifiedPrincipalPolicySelection,\n verifyDocumentPurgeEvent,\n} from \"@tearleads/crypto\";\nimport type { DocumentPurgeProofResponse } from \"@tearleads/validators/response\";\nimport { parseOrganizationAuthorityDescriptor } from \"../../principalContracts/organizationAuthorityDescriptor\";\nimport { verifyStandaloneAccessEventBundle } from \"../checkpoints/bundleVerification\";\nimport type { ProjectionCheckpointContext } from \"../checkpoints/checkpointContext\";\nimport type { PrincipalPolicyCache, ProjectionUserKeyResolver } from \"../types\";\nimport { verifyPurgeDocumentManifest } from \"./documentPurgeDocumentChainVerification\";\n\nfunction principalIdentity(input: {\n readonly principalId: string;\n readonly principalType: string;\n}): string {\n return `${input.principalType}:${input.principalId}`;\n}\n\nfunction collectEvidenceContainerManifests(input: {\n readonly roots: readonly VerifiedContainerAccessManifest[];\n readonly verifiedByHash: ReadonlyMap<string, VerifiedContainerAccessManifest>;\n}): VerifiedContainerAccessManifest[] {\n const selected = new Map<string, VerifiedContainerAccessManifest>();\n const pending = [...input.roots];\n while (pending.length > 0) {\n const manifest = pending.shift();\n if (!manifest || selected.has(manifest.manifestHash)) continue;\n selected.set(manifest.manifestHash, manifest);\n for (const dependencyHash of [\n manifest.manifest.previousManifestHash,\n manifest.state.parentManifestHash,\n ]) {\n if (!dependencyHash) continue;\n const dependency = input.verifiedByHash.get(dependencyHash);\n if (dependency) pending.push(dependency);\n }\n }\n return [...selected.values()];\n}\n\nfunction requireExactPurgePrincipalEvidence<\n TPolicy extends PrincipalPolicyAuthorization,\n>(input: {\n readonly authorizationEvidence: readonly TPolicy[];\n readonly verifiedContainerManifests: readonly VerifiedContainerAccessManifest[];\n readonly policyEvidence: DocumentPurgeProofResponse[\"policyEvidence\"];\n}): TPolicy[] {\n const references: ReferencedPrincipalHead[] =\n input.verifiedContainerManifests.flatMap(\n (manifest) => manifest.state.referencedPrincipalHeads,\n );\n const requiredByPrincipal = new Set<string>();\n\n for (const reference of references) {\n const policy = input.authorizationEvidence.find((candidate) =>\n principalPolicyMatchesReference({ policy: candidate, reference }),\n );\n if (!policy) {\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Document purge proof omits referenced principal policy evidence\",\n );\n }\n const identity = principalIdentity(policy);\n requiredByPrincipal.add(identity);\n // External authority is verified incrementally by paged recovery. Its\n // historical entries need not be copied into this returned selection.\n }\n\n const allowed = new Set(requiredByPrincipal);\n // Paged recovery has authenticated these payloads against their signed\n // organization states and verified their exact group-head bindings. This\n // identity allow-list cannot authenticate an unverified directory payload.\n for (const { payload } of input.policyEvidence.organizationPayloads) {\n const directory = parseOrganizationAuthorityDescriptor(payload.ciphertext);\n if (\n directory.groupHeads.some((head) => allowed.has(principalIdentity(head)))\n ) {\n allowed.add(`group:${directory.adminGroupId}`);\n allowed.add(`organization:${directory.organizationId}`);\n }\n }\n if (\n input.authorizationEvidence.some(\n (policy) => !allowed.has(principalIdentity(policy)),\n )\n )\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"Document purge proof includes unrelated principal policy evidence\",\n );\n return input.authorizationEvidence.filter((policy) =>\n requiredByPrincipal.has(principalIdentity(policy)),\n );\n}\n\nasync function authenticateDocumentPurgeEvent(input: {\n readonly authorizationEvidence: readonly VerifiedPrincipalPolicySelection[];\n readonly authorizingContainerPath: readonly VerifiedContainerAccessManifest[];\n readonly documentManifest:\n | VerifiedDocumentLinkSetManifest\n | VerifiedDocumentLinkSetSnapshot;\n readonly expectedDocumentId: string;\n readonly purgeEvent: DocumentPurgeProofResponse[\"purgeEvent\"];\n readonly policyEvidence: DocumentPurgeProofResponse[\"policyEvidence\"];\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly rootContainerManifests: readonly VerifiedContainerAccessManifest[];\n readonly verifiedContainerManifests: ReadonlyMap<\n string,\n VerifiedContainerAccessManifest\n >;\n}): Promise<{\n readonly principalPolicies: VerifiedPrincipalPolicySelection[];\n readonly purgeEventHash: string;\n}> {\n const event = await verifyStandaloneAccessEventBundle({\n bundle: input.purgeEvent,\n label: \"Document purge event\",\n resolveUserKey: input.resolveUserKey,\n });\n const evidenceContainerManifests = collectEvidenceContainerManifests({\n roots: input.rootContainerManifests,\n verifiedByHash: input.verifiedContainerManifests,\n });\n const principalPolicies = requireExactPurgePrincipalEvidence({\n authorizationEvidence: input.authorizationEvidence,\n verifiedContainerManifests: evidenceContainerManifests,\n policyEvidence: input.policyEvidence,\n });\n const verified = await verifyDocumentPurgeEvent({\n authorizingContainerPath: input.authorizingContainerPath,\n documentManifest: input.documentManifest,\n event,\n expectedDocumentId: input.expectedDocumentId,\n principalPolicies,\n });\n if (!verified.ok) throw verified.error;\n return {\n principalPolicies: [...input.authorizationEvidence],\n purgeEventHash: verified.value.eventHash,\n };\n}\n\nexport async function authenticateDocumentPurgeArtifacts(input: {\n readonly authorizationEvidence: readonly VerifiedPrincipalPolicySelection[];\n readonly authorizingContainerPath: readonly VerifiedContainerAccessManifest[];\n readonly checkpointContext: ProjectionCheckpointContext;\n readonly containerPathByManifestHash: ReadonlyMap<\n string,\n readonly VerifiedContainerAccessManifest[]\n >;\n readonly enforceLocalCheckpoints: boolean;\n readonly expectedDocumentId: string;\n readonly principalPolicyCache: PrincipalPolicyCache;\n readonly proof: DocumentPurgeProofResponse;\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly verifiedContainerManifests: ReadonlyMap<\n string,\n VerifiedContainerAccessManifest\n >;\n}) {\n const usedContainerManifests = new Map<\n string,\n VerifiedContainerAccessManifest\n >();\n const documentManifest = await verifyPurgeDocumentManifest({\n authorizationEvidence: input.authorizationEvidence,\n checkpointContext: input.checkpointContext,\n containerPathByManifestHash: input.containerPathByManifestHash,\n enforceLocalCheckpoints: input.enforceLocalCheckpoints,\n principalPolicyCache: input.principalPolicyCache,\n proof: input.proof,\n resolveUserKey: input.resolveUserKey,\n usedContainerManifests,\n });\n return {\n documentManifest,\n ...(await authenticateDocumentPurgeEvent({\n authorizationEvidence: input.authorizationEvidence,\n authorizingContainerPath: input.authorizingContainerPath,\n documentManifest,\n expectedDocumentId: input.expectedDocumentId,\n purgeEvent: input.proof.purgeEvent,\n policyEvidence: input.proof.policyEvidence,\n resolveUserKey: input.resolveUserKey,\n rootContainerManifests: [\n ...input.authorizingContainerPath,\n ...usedContainerManifests.values(),\n ],\n verifiedContainerManifests: input.verifiedContainerManifests,\n })),\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyingVerificationError } from "../../../internal/crypto/index.js";
|
|
2
|
-
import { principalHeadMatchesReference } from "../../
|
|
2
|
+
import { principalHeadMatchesReference } from "../../principalContracts/organizationAuthorityDescriptor.js";
|
|
3
3
|
function newer(previous, next) {
|
|
4
4
|
if (!previous)
|
|
5
5
|
return true;
|
package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeProjectionPolicyEvidence.js","sourceRoot":"","sources":["mergeProjectionPolicyEvidence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAK5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"mergeProjectionPolicyEvidence.js","sourceRoot":"","sources":["mergeProjectionPolicyEvidence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAK5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0DAA0D,CAAC;AAEzG,SAAS,KAAK,CACZ,QAAiE,EACjE,IAA0C;IAE1C,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW;QACrD,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,wCAAwC,CACzC,CAAC;IACJ,IACE,QAAQ,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC,OAAO;QAC3C,CAAC,6BAA6B,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC;QAExD,MAAM,IAAI,uBAAuB,CAC/B,eAAe,EACf,gDAAgD,CACjD,CAAC;IACJ,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;AACnD,CAAC;AAKD,SAAS,gBAAgB,CACvB,QAA6B,EAC7B,OAA4B;IAE5B,OAAO,CACL,CAAC,6BAA6B,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC;QACrE,QAAQ,CAAC,OAAO,CAAC,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,WAAW;QAC5D,QAAQ,CAAC,OAAO,CAAC,aAAa,K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,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;QACD,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IACD,OAAO;QACL,YAAY,EAAE,SAAS,EAAE,YAAY,IAAI,IAAI;QAC7C,oBAAoB,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC5C,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport type {\n PrincipalPolicyHistorySourceResponse,\n ProjectionPolicyEvidenceResponse,\n} from \"@tearleads/validators/response\";\nimport { principalHeadMatchesReference } from \"../../principalContracts/organizationAuthorityDescriptor\";\n\nfunction newer(\n previous: PrincipalPolicyHistorySourceResponse | null | undefined,\n next: PrincipalPolicyHistorySourceResponse,\n): boolean {\n if (!previous) return true;\n if (previous.head.principalId !== next.head.principalId)\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Projection evidence crosses principals\",\n );\n if (\n previous.head.version === next.head.version &&\n !principalHeadMatchesReference(previous.head, next.head)\n )\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n \"Projection evidence contains conflicting heads\",\n );\n return previous.head.version < next.head.version;\n}\n\ntype OrganizationPayload =\n ProjectionPolicyEvidenceResponse[\"organizationPayloads\"][number];\n\nfunction payloadsConflict(\n previous: OrganizationPayload,\n payload: OrganizationPayload,\n): boolean {\n return (\n !principalHeadMatchesReference(previous.reference, payload.reference) ||\n previous.payload.principalId !== payload.payload.principalId ||\n previous.payload.principalType !== payload.payload.principalType ||\n previous.payload.ciphertext !== payload.payload.ciphertext ||\n previous.payload.ciphertextHash !== payload.payload.ciphertextHash\n );\n}\n\nfunction keepNewestGroups(\n groups: Map<string, PrincipalPolicyHistorySourceResponse>,\n candidates: readonly PrincipalPolicyHistorySourceResponse[],\n): void {\n for (const group of candidates) {\n const prior = groups.get(group.head.principalId);\n if (newer(prior, group)) groups.set(group.head.principalId, group);\n }\n}\n\n/** Combine proof material when locally composing projections; verification follows. */\nexport function mergeProjectionPolicyEvidence(\n evidence: readonly ProjectionPolicyEvidenceResponse[],\n): ProjectionPolicyEvidenceResponse {\n let directory: ProjectionPolicyEvidenceResponse | undefined;\n const groups = new Map<string, PrincipalPolicyHistorySourceResponse>();\n const payloads = new Map<string, OrganizationPayload>();\n for (const proof of evidence) {\n const organization = proof.organization;\n if (organization && newer(directory?.organization, organization))\n directory = proof;\n for (const payload of proof.organizationPayloads) {\n const previous = payloads.get(payload.reference.stateHash);\n if (previous && payloadsConflict(previous, payload))\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n \"Projection evidence contains conflicting directory payloads\",\n );\n payloads.set(payload.reference.stateHash, payload);\n }\n keepNewestGroups(groups, proof.groups);\n }\n return {\n organization: directory?.organization ?? null,\n organizationPayloads: [...payloads.values()],\n groups: [...groups.values()],\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { KeyingVerificationError } from "../../../internal/crypto/index.js";
|
|
2
2
|
import { KeyingCheckpointRepository } from "../../persistence/keyingCheckpoints/keyingCheckpointRepository.js";
|
|
3
|
-
import { principalPolicyEvidenceEntries, } from "../../
|
|
4
|
-
import { principalStateMatchesReference } from "../../
|
|
3
|
+
import { principalPolicyEvidenceEntries, } from "../../principalContracts/principalPolicyEvidence.js";
|
|
4
|
+
import { principalStateMatchesReference } from "../../principalContracts/principalPolicyStates.js";
|
|
5
5
|
import { verifiedPrincipalPolicyMeetsCheckpoint } from "./principalPolicyCheckpointSelection.js";
|
|
6
6
|
/**
|
|
7
7
|
* Cache key for a referenced principal policy. The in-memory principal-policy
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalPolicyCache.js","sourceRoot":"","sources":["principalPolicyCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE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oBAAoB,CAAC,GAAG,CACjD,4BAA4B,CAAC,SAAS,CAAC,CACxC,CAAC;QACF,IAAI,YAAY,EAAE,CAAC;YACjB,IACE,CAAC,wCAAwC,CAAC,YAAY,EAAE,SAAS,CAAC,EAClE,CAAC;gBACD,MAAM,IAAI,uBAAuB,CAC/B,eAAe,EACf,qEAAqE,CACtE,CAAC;YACJ,CAAC;YACD,IAAI,sCAAsC,CAAC,YAAY,EAAE,UAAU,CAAC,EAAE,CAAC;gBACrE,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,KAAK;aACvB,+BAA+B,CAAC,KAAK,CAAC,OAAO,CAAC;aAC9C,qCAAqC,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAChE,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACnC,CAAC,CAAC,CACH,CAAC;IACF,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,SAAS,EAAwC,EAAE,CAAC,SAAS,KAAK,IAAI,CACxE,CAAC;AACJ,CAAC","sourcesContent":["import type { ReferencedPrincipalHead } from \"@tearleads/crypto\";\nimport { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { KeyingCheckpointRepository } from \"../../persistence/keyingCheckpoints/keyingCheckpointRepository\";\nimport {\n type PrincipalPolicyCurrentEvidence,\n principalPolicyEvidenceEntries,\n} from \"../../principalContracts/principalPolicyEvidence\";\nimport { principalStateMatchesReference } from \"../../principalContracts/principalPolicyStates\";\nimport type { ExecSql } from \"../../sqlite/sqlSchema\";\nimport type { OpenPrincipalPolicyBundleReader } from \"../types\";\nimport { verifiedPrincipalPolicyMeetsCheckpoint } from \"./principalPolicyCheckpointSelection\";\n\n/**\n * Cache key for a referenced principal policy. The in-memory principal-policy\n * cache is populated and read from several call sites; they must agree on this\n * format byte-for-byte or a populated entry looks uncached (extra warm fetches)\n * — so this is the single source of truth, imported rather than re-declared.\n */\nexport function referencedPrincipalPolicyKey(\n reference: ReferencedPrincipalHead,\n): string {\n return JSON.stringify([\n reference.principalType,\n reference.principalId,\n reference.version,\n reference.stateHash,\n reference.keyEpoch,\n reference.keyFingerprint,\n ]);\n}\n\n/**\n * Dedupes references by their exact head identity, keyed with\n * {@link referencedPrincipalPolicyKey} so every consumer agrees on what\n * \"the same reference\" means. Later duplicates win, preserving each\n * caller's original last-wins behavior.\n */\nexport function dedupeReferencedPrincipalStates<\n TReference extends ReferencedPrincipalHead,\n>(references: ReadonlyArray<TReference>): TReference[] {\n const referencesByState = new Map<string, TReference>();\n for (const reference of references) {\n referencesByState.set(referencedPrincipalPolicyKey(reference), reference);\n }\n return Array.from(referencesByState.values());\n}\n\nexport function principalPolicyCacheForVerifiedPolicies(\n policies: readonly PrincipalPolicyCurrentEvidence[],\n): Map<string, PrincipalPolicyCurrentEvidence> {\n const cache = new Map<string, PrincipalPolicyCurrentEvidence>();\n for (const policy of policies) {\n const states = principalPolicyEvidenceEntries(policy).map(\n (entry) => entry.state,\n );\n for (const state of states) {\n cache.set(\n referencedPrincipalPolicyKey({\n principalType: state.principalType,\n principalId: state.principalId,\n version: state.version,\n keyEpoch: state.keyEpoch,\n stateHash: state.stateHash,\n keyFingerprint: state.keyFingerprint,\n }),\n policy,\n );\n }\n }\n return cache;\n}\n\nexport function verifiedPrincipalPolicyContainsReference(\n policy: PrincipalPolicyCurrentEvidence,\n reference: ReferencedPrincipalHead,\n): boolean {\n const states = principalPolicyEvidenceEntries(policy).map(\n ({ state }) => state,\n );\n return states.some((state) =>\n principalStateMatchesReference(state, reference),\n );\n}\n\n// Identify which referenced policies are absent from both the in-memory cache\n// and local storage, so the warmer fetches only what is genuinely missing.\nexport async function filterUncachedPrincipalPolicyReferences(input: {\n execSql: ExecSql;\n openPrincipalPolicyBundleReader: OpenPrincipalPolicyBundleReader;\n principalPolicyCache: ReadonlyMap<string, PrincipalPolicyCurrentEvidence>;\n references: readonly ReferencedPrincipalHead[];\n}): Promise<ReferencedPrincipalHead[]> {\n const results = await Promise.all(\n input.references.map(async (reference) => {\n const checkpoint = await new KeyingCheckpointRepository(\n input.execSql,\n ).loadPrincipalPolicyCheckpoint(\n reference.principalType,\n reference.principalId,\n );\n const cachedPolicy = input.principalPolicyCache.get(\n referencedPrincipalPolicyKey(reference),\n );\n if (cachedPolicy) {\n if (\n !verifiedPrincipalPolicyContainsReference(cachedPolicy, reference)\n ) {\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n \"in-memory principal policy cache does not match its exact reference\",\n );\n }\n if (verifiedPrincipalPolicyMeetsCheckpoint(cachedPolicy, checkpoint)) {\n return null;\n }\n }\n const bundle = await input\n .openPrincipalPolicyBundleReader(input.execSql)\n .loadPrincipalPolicyBundleForReference(reference, checkpoint);\n return bundle ? null : reference;\n }),\n );\n return results.filter(\n (reference): reference is ReferencedPrincipalHead => reference !== null,\n );\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KeyingVerificationError, toFingerprint, } from "../../../internal/crypto/index.js";
|
|
2
|
-
import { withUnauthenticatedPolicyIdentities } from "../../
|
|
3
|
-
import { principalPolicyBundleStates } from "../../
|
|
2
|
+
import { withUnauthenticatedPolicyIdentities } from "../../principalContracts/principalIdentityCommitments.js";
|
|
3
|
+
import { principalPolicyBundleStates } from "../../principalContracts/principalPolicyStates.js";
|
|
4
4
|
import { ProjectionDependencyUnavailableError } from "../../shared/dependencyUnavailable.js";
|
|
5
5
|
/**
|
|
6
6
|
* Signers and committed members of a fetched bundle, compared before its
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalPolicySigners.js","sourceRoot":"","sources":["principalPolicySigners.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAEvB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,mCAAmC,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"principalPolicySigners.js","sourceRoot":"","sources":["principalPolicySigners.ts"],"names":[],"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;YACD,MAAM,qBAAqB,GAAG,MAAM,aAAa,CAC/C,SAAS,CAAC,gBAAgB,CAC3B,CAAC;YACF,IAAI,qBAAqB,KAAK,KAAK,CAAC,wBAAwB,EAAE,CAAC;gBAC7D,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,GAAG,KAAK,CAAC,KAAK,kCAAkC,CACjD,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;gBACpB,MAAM,EAAE,KAAK,CAAC,YAAY;gBAC1B,qBAAqB;gBACrB,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/B,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicySignerPublicKey,\n toFingerprint,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport { withUnauthenticatedPolicyIdentities } from \"../../principalContracts/principalIdentityCommitments\";\nimport { principalPolicyBundleStates } from \"../../principalContracts/principalPolicyStates\";\nimport { ProjectionDependencyUnavailableError } from \"../../shared/dependencyUnavailable\";\nimport type { ProjectionUserKeyResolver } from \"../types\";\n\n/**\n * Signers and committed members of a fetched bundle, compared before its\n * signatures are checked and pinned only by `publishVerifiedPolicyBundle`\n * once the caller's verification succeeds.\n */\nexport async function collectPrincipalPolicySignerPublicKeys(input: {\n bundle: PrincipalPolicyBundleResponse;\n label: string;\n resolveUserKey: ProjectionUserKeyResolver;\n}): Promise<PrincipalPolicySignerPublicKey[]> {\n const states = principalPolicyBundleStates(input.bundle);\n // Signatures are checked after collection: compare, but pin nothing yet.\n return withUnauthenticatedPolicyIdentities(\n {\n signerUserIds: states.map((state) => state.signerUserId),\n projections: [\n ...input.bundle.previousStates.map((entry) => entry.projection),\n input.bundle.currentProjection,\n ],\n resolveTrustedUserIdentity: input.resolveUserKey,\n },\n async (resolve) => {\n const signers = new Map<string, PrincipalPolicySignerPublicKey>();\n for (const state of states) {\n const cacheKey = `${state.signerUserId}:${state.signerUserKeyFingerprint}`;\n if (signers.has(cacheKey)) continue;\n const signerKey = await resolve(state.signerUserId);\n if (!signerKey) {\n throw new ProjectionDependencyUnavailableError(\n `${input.label} signer key could not be resolved for ${state.signerUserId}`,\n );\n }\n const signingKeyFingerprint = await toFingerprint(\n signerKey.signingPublicKey,\n );\n if (signingKeyFingerprint !== state.signerUserKeyFingerprint) {\n throw new KeyingVerificationError(\n \"signer_mismatch\",\n `${input.label} signer key fingerprint mismatch`,\n );\n }\n signers.set(cacheKey, {\n userId: state.signerUserId,\n signingKeyFingerprint,\n signingPublicKey: signerKey.signingPublicKey,\n });\n }\n return [...signers.values()];\n },\n );\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReferencedPrincipalHead } from "../../../internal/crypto/index.js";
|
|
2
|
-
import { type PrincipalPolicyCurrentEvidence } from "../../
|
|
2
|
+
import { type PrincipalPolicyCurrentEvidence } from "../../principalContracts/principalPolicyEvidence.js";
|
|
3
3
|
import { type ProjectionCheckpointContext } from "../checkpoints/checkpointContext.js";
|
|
4
4
|
import type { PrincipalPolicyCache, ProjectionUserKeyResolver, ReferencedPrincipalPolicyWarmer } from "../types.js";
|
|
5
5
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { KeyingVerificationError, verifyPrincipalPolicyBundle, } from "../../../internal/crypto/index.js";
|
|
2
2
|
import { KeyingCheckpointRepository } from "../../persistence/keyingCheckpoints/keyingCheckpointRepository.js";
|
|
3
|
-
import { parseOrganizationAuthorityDescriptor, principalHeadMatchesReference, requireOrganizationGroupHead, } from "../../
|
|
4
|
-
import { assertPrincipalIdentityCommitments, publishVerifiedPolicyBundle, } from "../../
|
|
5
|
-
import { organizationAdminExternalAuthority, principalPolicyReferenceFromBundle, verifyOrganizationAdminPolicy, verifyPrincipalPolicyBundleWithExternalOrganizationAdmins, } from "../../
|
|
6
|
-
import { principalPolicyEvidenceEntries, } from "../../
|
|
3
|
+
import { parseOrganizationAuthorityDescriptor, principalHeadMatchesReference, requireOrganizationGroupHead, } from "../../principalContracts/organizationAuthorityDescriptor.js";
|
|
4
|
+
import { assertPrincipalIdentityCommitments, publishVerifiedPolicyBundle, } from "../../principalContracts/principalIdentityCommitments.js";
|
|
5
|
+
import { organizationAdminExternalAuthority, principalPolicyReferenceFromBundle, verifyOrganizationAdminPolicy, verifyPrincipalPolicyBundleWithExternalOrganizationAdmins, } from "../../principalContracts/principalPolicyAdminSigners.js";
|
|
6
|
+
import { principalPolicyEvidenceEntries, } from "../../principalContracts/principalPolicyEvidence.js";
|
|
7
7
|
import { observePrincipalPolicy, } from "../checkpoints/checkpointContext.js";
|
|
8
8
|
import { rethrowProjectionVerificationBoundaryError } from "../error.js";
|
|
9
9
|
import { assertProjectionVerificationCurrent, generationGuardedPrincipalPolicyWarmer, } from "../types.js";
|
package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalPolicyVerification.js","sourceRoot":"","sources":["principalPolicyVerification.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAIvB,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,gEAAgE,CAAC;AAC5G,OAAO,EACL,oCAAoC,EACpC,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACL,kCAAkC,EAClC,2BAA2B,GAC5B,MAAM,+CAA+C,CAAC;AACvD,OAAO,EACL,kCAAkC,EAClC,kCAAkC,EAClC,6BAA6B,EAC7B,yDAAyD,GAC1D,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAEL,8BAA8B,GAC/B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,sBA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AC;gBACpC,cAAc,EAAE,KAAK,CAAC,cAAc;gBACpC,UAAU,EAAE,QAAQ;aACrB,CAAC,CAAC;YACH,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,0EAA0E;IAC1E,OAAO,OAAO,CAAC,GAAG,CAChB,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAC3B,+BAA+B,CAAC;QAC9B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,SAAS;QACT,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,+BAA+B;KAChC,CAAC,CACH,CACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicyCheckpoint,\n type ReferencedPrincipalHead,\n type VerifiedPrincipalPolicy,\n verifyPrincipalPolicyBundle,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport { KeyingCheckpointRepository } from \"../../persistence/keyingCheckpoints/keyingCheckpointRepository\";\nimport {\n parseOrganizationAuthorityDescriptor,\n principalHeadMatchesReference,\n requireOrganizationGroupHead,\n} from \"../../principals/organizationAuthorityDescriptor\";\nimport {\n assertPrincipalIdentityCommitments,\n publishVerifiedPolicyBundle,\n} from \"../../principals/principalIdentityCommitments\";\nimport {\n organizationAdminExternalAuthority,\n principalPolicyReferenceFromBundle,\n verifyOrganizationAdminPolicy,\n verifyPrincipalPolicyBundleWithExternalOrganizationAdmins,\n} from \"../../principals/principalPolicyAdminSigners\";\nimport {\n type PrincipalPolicyCurrentEvidence,\n principalPolicyEvidenceEntries,\n} from \"../../principals/principalPolicyEvidence\";\nimport {\n observePrincipalPolicy,\n type ProjectionCheckpointContext,\n} from \"../checkpoints/checkpointContext\";\nimport { rethrowProjectionVerificationBoundaryError } from \"../error\";\nimport type {\n OpenPrincipalPolicyBundleReader,\n PrincipalPolicyCache,\n ProjectionUserKeyResolver,\n ReferencedPrincipalPolicyWarmer,\n} from \"../types\";\nimport {\n assertProjectionVerificationCurrent,\n generationGuardedPrincipalPolicyWarmer,\n} from \"../types\";\nimport {\n filterUncachedPrincipalPolicyReferences,\n referencedPrincipalPolicyKey,\n verifiedPrincipalPolicyContainsReference,\n} from \"./principalPolicyCache\";\nimport {\n principalPolicyHeadMeetsCheckpoint,\n verifiedPrincipalPolicyMeetsCheckpoint,\n} from \"./principalPolicyCheckpointSelection\";\nimport { collectPrincipalPolicySignerPublicKeys } from \"./principalPolicySigners\";\nimport { resolveReferencedPrincipalPolicy } from \"./resolvedPrincipalPolicy\";\n\nfunction principalPolicyReferenceLabel(\n reference: ReferencedPrincipalHead,\n): string {\n return `${reference.principalType}:${reference.principalId}@${reference.version}`;\n}\n\n/**\n * A referenced principal policy is not in the local store and warming could\n * not fetch it this pass — a transient cold-cache condition, typical for a\n * member whose access arrives via a group policy the device has not hydrated\n * yet. Sync passes discriminate on this type to defer the affected container\n * and retry on a later trigger, rather than failing the whole pass.\n */\nexport class PrincipalPolicyNotCachedError extends Error {\n constructor(referenceLabel: string) {\n super(`Principal policy ${referenceLabel} is not cached`);\n this.name = \"PrincipalPolicyNotCachedError\";\n }\n}\n\nexport function isPrincipalPolicyNotCachedError(error: unknown): boolean {\n return (\n error instanceof PrincipalPolicyNotCachedError ||\n (error instanceof Error && error.name === \"PrincipalPolicyNotCachedError\")\n );\n}\n\ntype OrganizationAdminPolicyInput = {\n checkpointContext: ProjectionCheckpointContext;\n organizationId: string;\n resolveUserKey: ProjectionUserKeyResolver;\n /** The verification's lifetime, checked inside every pin write. */\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n};\n\nasync function loadOrganizationPolicyForVerification(\n input: OrganizationAdminPolicyInput,\n): Promise<\n | {\n bundle: PrincipalPolicyBundleResponse;\n localCheckpoint: PrincipalPolicyCheckpoint | null;\n }\n | undefined\n> {\n const execSql = input.checkpointContext.execSql;\n let bundle = await input.checkpointContext\n .openPrincipalPolicyBundleReader(execSql)\n .loadPrincipalPolicyBundle(\"organization\", input.organizationId);\n if (!bundle) {\n return undefined;\n }\n let localCheckpoint = await new KeyingCheckpointRepository(\n execSql,\n ).loadPrincipalPolicyCheckpoint(\"organization\", input.organizationId);\n if (\n !principalPolicyHeadMeetsCheckpoint(bundle.currentState, localCheckpoint) &&\n input.warmReferencedPrincipalPolicies\n ) {\n await input.warmReferencedPrincipalPolicies({\n organizationId: input.organizationId,\n references: [principalPolicyReferenceFromBundle(bundle)],\n });\n bundle = await input.checkpointContext\n .openPrincipalPolicyBundleReader(execSql)\n .loadPrincipalPolicyBundle(\"organization\", input.organizationId);\n localCheckpoint = await new KeyingCheckpointRepository(\n execSql,\n ).loadPrincipalPolicyCheckpoint(\"organization\", input.organizationId);\n if (!bundle) {\n return undefined;\n }\n }\n\n return { bundle, localCheckpoint };\n}\n\nfunction assertReservedAdminsPolicyShape(\n policy: VerifiedPrincipalPolicy,\n): void {\n const history = policy.history ?? [{ projection: policy.projection }];\n if (\n history.some(\n (entry) =>\n entry.projection.length === 0 ||\n entry.projection.some((member) => member.role !== \"admin\"),\n )\n ) {\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"reserved Admins policy must contain only direct admin users\",\n );\n }\n}\n\nasync function verifyOrganizationAdminsPolicy(input: {\n adminGroupId: string;\n execSql: ProjectionCheckpointContext[\"execSql\"];\n openPrincipalPolicyBundleReader: OpenPrincipalPolicyBundleReader;\n expectedHead: ReferencedPrincipalHead;\n resolveUserKey: ProjectionUserKeyResolver;\n stillCurrent: (() => boolean) | undefined;\n}): Promise<VerifiedPrincipalPolicy | undefined> {\n const adminBundle = await input\n .openPrincipalPolicyBundleReader(input.execSql)\n .loadPrincipalPolicyBundle(\"group\", input.adminGroupId);\n if (!adminBundle) {\n return undefined;\n }\n if (\n !principalHeadMatchesReference(\n principalPolicyReferenceFromBundle(adminBundle),\n input.expectedHead,\n )\n ) {\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n \"Admins policy does not match the signed organization directory\",\n );\n }\n const adminCheckpoint = await new KeyingCheckpointRepository(\n input.execSql,\n ).loadPrincipalPolicyCheckpoint(\"group\", input.adminGroupId);\n const signerPublicKeys = await collectPrincipalPolicySignerPublicKeys({\n bundle: adminBundle,\n label: `Admins policy ${input.adminGroupId}`,\n resolveUserKey: input.resolveUserKey,\n });\n const verified = await verifyPrincipalPolicyBundle({\n bundle: adminBundle,\n expectedReference: input.expectedHead,\n localCheckpoint: adminCheckpoint,\n signerPublicKeys,\n });\n if (!verified.ok) {\n throw verified.error;\n }\n assertReservedAdminsPolicyShape(verified.value);\n await publishVerifiedPolicyBundle(adminBundle, input.resolveUserKey, () =>\n assertProjectionVerificationCurrent(input.stillCurrent),\n );\n return verified.value;\n}\n\nasync function loadOrganizationExternalAuthority(\n input: OrganizationAdminPolicyInput,\n): Promise<ReturnType<typeof organizationAdminExternalAuthority> | null> {\n const organizationPolicy = await loadOrganizationPolicyForVerification(input);\n if (!organizationPolicy) {\n return null;\n }\n\n try {\n const signerPublicKeys = await collectPrincipalPolicySignerPublicKeys({\n bundle: organizationPolicy.bundle,\n label: `Organization policy ${input.organizationId}`,\n resolveUserKey: input.resolveUserKey,\n });\n const verified = await verifyOrganizationAdminPolicy({\n bundle: organizationPolicy.bundle,\n localCheckpoint: organizationPolicy.localCheckpoint,\n organizationId: input.organizationId,\n signerPublicKeys,\n });\n if (!verified.ok) {\n throw verified.error;\n }\n await publishVerifiedPolicyBundle(\n organizationPolicy.bundle,\n input.resolveUserKey,\n () => assertProjectionVerificationCurrent(input.stillCurrent),\n );\n const descriptor = parseOrganizationAuthorityDescriptor(\n organizationPolicy.bundle.currentPayload.ciphertext,\n );\n if (descriptor.organizationId !== input.organizationId) {\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"organization authority descriptor scope does not match\",\n );\n }\n const verifiedAdmins = await verifyOrganizationAdminsPolicy({\n adminGroupId: descriptor.adminGroupId,\n execSql: input.checkpointContext.execSql,\n openPrincipalPolicyBundleReader:\n input.checkpointContext.openPrincipalPolicyBundleReader,\n expectedHead: requireOrganizationGroupHead(\n descriptor,\n descriptor.adminGroupId,\n ),\n resolveUserKey: input.resolveUserKey,\n stillCurrent: input.stillCurrent,\n });\n if (!verifiedAdmins) {\n return null;\n }\n observePrincipalPolicy(\n input.checkpointContext,\n verified.value,\n input.organizationId,\n );\n observePrincipalPolicy(\n input.checkpointContext,\n verifiedAdmins,\n input.organizationId,\n );\n return organizationAdminExternalAuthority(verifiedAdmins);\n } catch (error) {\n rethrowProjectionVerificationBoundaryError(error);\n if (error instanceof KeyingVerificationError) {\n throw error;\n }\n return null;\n }\n}\n\n/**\n * Fresh or reused: check every projection, history included; pin first\n * sights within the verification's lifetime. A freshly verified `bundle` also\n * pins its signers.\n */\nasync function assertVerifiedPolicyCommitments(\n policy: PrincipalPolicyCurrentEvidence,\n scope: {\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly stillCurrent?: (() => boolean) | undefined;\n },\n bundle?: PrincipalPolicyBundleResponse,\n): Promise<void> {\n const assertCurrent = () =>\n assertProjectionVerificationCurrent(scope.stillCurrent);\n await assertPrincipalIdentityCommitments({\n assertCurrent,\n authenticated: true,\n projections: [\n policy.projection,\n ...principalPolicyEvidenceEntries(policy).map(\n (entry) => entry.projection,\n ),\n ],\n resolveTrustedUserIdentity: scope.resolveUserKey,\n });\n if (bundle)\n await publishVerifiedPolicyBundle(\n bundle,\n scope.resolveUserKey,\n assertCurrent,\n );\n}\n\nasync function verifyReferencedPrincipalPolicy(input: {\n checkpointContext: ProjectionCheckpointContext;\n organizationId: string;\n principalPolicyCache: PrincipalPolicyCache;\n reference: ReferencedPrincipalHead;\n stillCurrent?: (() => boolean) | undefined;\n resolveUserKey: ProjectionUserKeyResolver;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<PrincipalPolicyCurrentEvidence> {\n // Scoped recovery carries organization, dependency and lifetime bindings.\n // A bare policy cache entry cannot replace those bindings.\n const recovered = await resolveReferencedPrincipalPolicy(input);\n if (recovered) {\n await assertVerifiedPolicyCommitments(recovered, input);\n return recovered;\n }\n const cacheKey = referencedPrincipalPolicyKey(input.reference);\n const cachedPolicy = input.principalPolicyCache.get(cacheKey);\n const execSql = input.checkpointContext.execSql;\n const localCheckpoint = await new KeyingCheckpointRepository(\n execSql,\n ).loadPrincipalPolicyCheckpoint(\n input.reference.principalType,\n input.reference.principalId,\n );\n if (cachedPolicy && !(\"retainedHistory\" in cachedPolicy)) {\n if (\n !verifiedPrincipalPolicyContainsReference(cachedPolicy, input.reference)\n ) {\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n \"in-memory principal policy cache does not match its exact reference\",\n );\n }\n if (verifiedPrincipalPolicyMeetsCheckpoint(cachedPolicy, localCheckpoint)) {\n await assertVerifiedPolicyCommitments(cachedPolicy, input);\n observePrincipalPolicy(\n input.checkpointContext,\n cachedPolicy,\n input.organizationId,\n );\n return cachedPolicy;\n }\n }\n\n const referenceLabel = principalPolicyReferenceLabel(input.reference);\n let bundle = await input.checkpointContext\n .openPrincipalPolicyBundleReader(execSql)\n .loadPrincipalPolicyBundleForReference(input.reference, localCheckpoint);\n if (!bundle && input.warmReferencedPrincipalPolicies) {\n // The reference is not cached locally — the common case for a member who\n // gained access via another org's group grant and never hydrated that\n // group's policy. Fetch+verify+persist it, then re-read from the cache.\n await input.warmReferencedPrincipalPolicies({\n organizationId: input.organizationId,\n references: [input.reference],\n });\n bundle = await input.checkpointContext\n .openPrincipalPolicyBundleReader(execSql)\n .loadPrincipalPolicyBundleForReference(input.reference, localCheckpoint);\n }\n if (!bundle) {\n throw new PrincipalPolicyNotCachedError(referenceLabel);\n }\n\n const signerPublicKeys = await collectPrincipalPolicySignerPublicKeys({\n bundle,\n label: `Principal policy ${referenceLabel}`,\n resolveUserKey: input.resolveUserKey,\n });\n const verified =\n await verifyPrincipalPolicyBundleWithExternalOrganizationAdmins({\n bundle,\n expectedReference: input.reference,\n loadExternalAuthority: () =>\n loadOrganizationExternalAuthority({\n checkpointContext: input.checkpointContext,\n organizationId: input.organizationId,\n resolveUserKey: input.resolveUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies:\n input.warmReferencedPrincipalPolicies,\n }),\n localCheckpoint,\n signerPublicKeys,\n });\n if (!verified.ok) {\n throw verified.error;\n }\n await assertVerifiedPolicyCommitments(verified.value, input, bundle);\n\n observePrincipalPolicy(\n input.checkpointContext,\n verified.value,\n input.organizationId,\n );\n input.principalPolicyCache.set(cacheKey, verified.value);\n return verified.value;\n}\n\nexport async function collectReferencedPrincipalPolicies(input: {\n checkpointContext: ProjectionCheckpointContext;\n organizationId: string;\n principalPolicyCache: PrincipalPolicyCache;\n references: readonly ReferencedPrincipalHead[];\n resolveUserKey: ProjectionUserKeyResolver;\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<PrincipalPolicyCurrentEvidence[]> {\n const warmReferencedPrincipalPolicies =\n generationGuardedPrincipalPolicyWarmer(\n input.warmReferencedPrincipalPolicies,\n input.stillCurrent,\n );\n const uniqueReferences = new Map<string, ReferencedPrincipalHead>();\n for (const reference of input.references) {\n uniqueReferences.set(referencedPrincipalPolicyKey(reference), reference);\n }\n\n const references = [...uniqueReferences.values()];\n // Warm every missing reference in one batched fetch before verifying, so a\n // path that references several uncached policies makes a single round of\n // requests rather than one per reference.\n if (\n warmReferencedPrincipalPolicies &&\n !warmReferencedPrincipalPolicies.resolveReference\n ) {\n const uncached = await filterUncachedPrincipalPolicyReferences({\n execSql: input.checkpointContext.execSql,\n openPrincipalPolicyBundleReader:\n input.checkpointContext.openPrincipalPolicyBundleReader,\n principalPolicyCache: input.principalPolicyCache,\n references,\n });\n if (uncached.length > 0) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n await warmReferencedPrincipalPolicies({\n organizationId: input.organizationId,\n references: uncached,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n }\n }\n\n // The warmer's operation shares one recovery view across its collections.\n return Promise.all(\n references.map((reference) =>\n verifyReferencedPrincipalPolicy({\n checkpointContext: input.checkpointContext,\n organizationId: input.organizationId,\n principalPolicyCache: input.principalPolicyCache,\n reference,\n stillCurrent: input.stillCurrent,\n resolveUserKey: input.resolveUserKey,\n warmReferencedPrincipalPolicies,\n }),\n ),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"principalPolicyVerification.js","sourceRoot":"","sources":["principalPolicyVerification.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAIvB,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,gEAAgE,CAAC;AAC5G,OAAO,EACL,oCAAoC,EACpC,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,0DAA0D,CAAC;AAClE,OAAO,EACL,kCAAkC,EAClC,2BAA2B,GAC5B,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EACL,kCAAkC,EAClC,kCAAkC,EAClC,6BAA6B,EAC7B,yDAAyD,GAC1D,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAEL,8BAA8B,GAC/B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACL,sBAAsB,GAEvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,0CAA0C,EAAE,MAAM,UAAU,CAAC;AAOtE,OAAO,EACL,mCAAmC,EACnC,sCAAsC,GACvC,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,uCAAuC,EACvC,4BAA4B,EAC5B,wCAAwC,GACzC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,kCAAkC,EAClC,sCAAsC,GACvC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAA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BAAiB;QAC1C,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,SAAS;QACT,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,+BAA+B;KAChC,CAAC,CACH,CACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicyCheckpoint,\n type ReferencedPrincipalHead,\n type VerifiedPrincipalPolicy,\n verifyPrincipalPolicyBundle,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport { KeyingCheckpointRepository } from \"../../persistence/keyingCheckpoints/keyingCheckpointRepository\";\nimport {\n parseOrganizationAuthorityDescriptor,\n principalHeadMatchesReference,\n requireOrganizationGroupHead,\n} from \"../../principalContracts/organizationAuthorityDescriptor\";\nimport {\n assertPrincipalIdentityCommitments,\n publishVerifiedPolicyBundle,\n} from \"../../principalContracts/principalIdentityCommitments\";\nimport {\n organizationAdminExternalAuthority,\n principalPolicyReferenceFromBundle,\n verifyOrganizationAdminPolicy,\n verifyPrincipalPolicyBundleWithExternalOrganizationAdmins,\n} from \"../../principalContracts/principalPolicyAdminSigners\";\nimport {\n type PrincipalPolicyCurrentEvidence,\n principalPolicyEvidenceEntries,\n} from \"../../principalContracts/principalPolicyEvidence\";\nimport {\n observePrincipalPolicy,\n type ProjectionCheckpointContext,\n} from \"../checkpoints/checkpointContext\";\nimport { rethrowProjectionVerificationBoundaryError } from \"../error\";\nimport type {\n OpenPrincipalPolicyBundleReader,\n PrincipalPolicyCache,\n ProjectionUserKeyResolver,\n ReferencedPrincipalPolicyWarmer,\n} from \"../types\";\nimport {\n assertProjectionVerificationCurrent,\n generationGuardedPrincipalPolicyWarmer,\n} from \"../types\";\nimport {\n filterUncachedPrincipalPolicyReferences,\n referencedPrincipalPolicyKey,\n verifiedPrincipalPolicyContainsReference,\n} from \"./principalPolicyCache\";\nimport {\n principalPolicyHeadMeetsCheckpoint,\n verifiedPrincipalPolicyMeetsCheckpoint,\n} from \"./principalPolicyCheckpointSelection\";\nimport { collectPrincipalPolicySignerPublicKeys } from \"./principalPolicySigners\";\nimport { resolveReferencedPrincipalPolicy } from \"./resolvedPrincipalPolicy\";\n\nfunction principalPolicyReferenceLabel(\n reference: ReferencedPrincipalHead,\n): string {\n return `${reference.principalType}:${reference.principalId}@${reference.version}`;\n}\n\n/**\n * A referenced principal policy is not in the local store and warming could\n * not fetch it this pass — a transient cold-cache condition, typical for a\n * member whose access arrives via a group policy the device has not hydrated\n * yet. Sync passes discriminate on this type to defer the affected container\n * and retry on a later trigger, rather than failing the whole pass.\n */\nexport class PrincipalPolicyNotCachedError extends Error {\n constructor(referenceLabel: string) {\n super(`Principal policy ${referenceLabel} is not cached`);\n this.name = \"PrincipalPolicyNotCachedError\";\n }\n}\n\nexport function isPrincipalPolicyNotCachedError(error: unknown): boolean {\n return (\n error instanceof PrincipalPolicyNotCachedError ||\n (error instanceof Error && error.name === \"PrincipalPolicyNotCachedError\")\n );\n}\n\ntype OrganizationAdminPolicyInput = {\n checkpointContext: ProjectionCheckpointContext;\n organizationId: string;\n resolveUserKey: ProjectionUserKeyResolver;\n /** The verification's lifetime, checked inside every pin write. */\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n};\n\nasync function loadOrganizationPolicyForVerification(\n input: OrganizationAdminPolicyInput,\n): Promise<\n | {\n bundle: PrincipalPolicyBundleResponse;\n localCheckpoint: PrincipalPolicyCheckpoint | null;\n }\n | undefined\n> {\n const execSql = input.checkpointContext.execSql;\n let bundle = await input.checkpointContext\n .openPrincipalPolicyBundleReader(execSql)\n .loadPrincipalPolicyBundle(\"organization\", input.organizationId);\n if (!bundle) {\n return undefined;\n }\n let localCheckpoint = await new KeyingCheckpointRepository(\n execSql,\n ).loadPrincipalPolicyCheckpoint(\"organization\", input.organizationId);\n if (\n !principalPolicyHeadMeetsCheckpoint(bundle.currentState, localCheckpoint) &&\n input.warmReferencedPrincipalPolicies\n ) {\n await input.warmReferencedPrincipalPolicies({\n organizationId: input.organizationId,\n references: [principalPolicyReferenceFromBundle(bundle)],\n });\n bundle = await input.checkpointContext\n .openPrincipalPolicyBundleReader(execSql)\n .loadPrincipalPolicyBundle(\"organization\", input.organizationId);\n localCheckpoint = await new KeyingCheckpointRepository(\n execSql,\n ).loadPrincipalPolicyCheckpoint(\"organization\", input.organizationId);\n if (!bundle) {\n return undefined;\n }\n }\n\n return { bundle, localCheckpoint };\n}\n\nfunction assertReservedAdminsPolicyShape(\n policy: VerifiedPrincipalPolicy,\n): void {\n const history = policy.history ?? [{ projection: policy.projection }];\n if (\n history.some(\n (entry) =>\n entry.projection.length === 0 ||\n entry.projection.some((member) => member.role !== \"admin\"),\n )\n ) {\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"reserved Admins policy must contain only direct admin users\",\n );\n }\n}\n\nasync function verifyOrganizationAdminsPolicy(input: {\n adminGroupId: string;\n execSql: ProjectionCheckpointContext[\"execSql\"];\n openPrincipalPolicyBundleReader: OpenPrincipalPolicyBundleReader;\n expectedHead: ReferencedPrincipalHead;\n resolveUserKey: ProjectionUserKeyResolver;\n stillCurrent: (() => boolean) | undefined;\n}): Promise<VerifiedPrincipalPolicy | undefined> {\n const adminBundle = await input\n .openPrincipalPolicyBundleReader(input.execSql)\n .loadPrincipalPolicyBundle(\"group\", input.adminGroupId);\n if (!adminBundle) {\n return undefined;\n }\n if (\n !principalHeadMatchesReference(\n principalPolicyReferenceFromBundle(adminBundle),\n input.expectedHead,\n )\n ) {\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n \"Admins policy does not match the signed organization directory\",\n );\n }\n const adminCheckpoint = await new KeyingCheckpointRepository(\n input.execSql,\n ).loadPrincipalPolicyCheckpoint(\"group\", input.adminGroupId);\n const signerPublicKeys = await collectPrincipalPolicySignerPublicKeys({\n bundle: adminBundle,\n label: `Admins policy ${input.adminGroupId}`,\n resolveUserKey: input.resolveUserKey,\n });\n const verified = await verifyPrincipalPolicyBundle({\n bundle: adminBundle,\n expectedReference: input.expectedHead,\n localCheckpoint: adminCheckpoint,\n signerPublicKeys,\n });\n if (!verified.ok) {\n throw verified.error;\n }\n assertReservedAdminsPolicyShape(verified.value);\n await publishVerifiedPolicyBundle(adminBundle, input.resolveUserKey, () =>\n assertProjectionVerificationCurrent(input.stillCurrent),\n );\n return verified.value;\n}\n\nasync function loadOrganizationExternalAuthority(\n input: OrganizationAdminPolicyInput,\n): Promise<ReturnType<typeof organizationAdminExternalAuthority> | null> {\n const organizationPolicy = await loadOrganizationPolicyForVerification(input);\n if (!organizationPolicy) {\n return null;\n }\n\n try {\n const signerPublicKeys = await collectPrincipalPolicySignerPublicKeys({\n bundle: organizationPolicy.bundle,\n label: `Organization policy ${input.organizationId}`,\n resolveUserKey: input.resolveUserKey,\n });\n const verified = await verifyOrganizationAdminPolicy({\n bundle: organizationPolicy.bundle,\n localCheckpoint: organizationPolicy.localCheckpoint,\n organizationId: input.organizationId,\n signerPublicKeys,\n });\n if (!verified.ok) {\n throw verified.error;\n }\n await publishVerifiedPolicyBundle(\n organizationPolicy.bundle,\n input.resolveUserKey,\n () => assertProjectionVerificationCurrent(input.stillCurrent),\n );\n const descriptor = parseOrganizationAuthorityDescriptor(\n organizationPolicy.bundle.currentPayload.ciphertext,\n );\n if (descriptor.organizationId !== input.organizationId) {\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"organization authority descriptor scope does not match\",\n );\n }\n const verifiedAdmins = await verifyOrganizationAdminsPolicy({\n adminGroupId: descriptor.adminGroupId,\n execSql: input.checkpointContext.execSql,\n openPrincipalPolicyBundleReader:\n input.checkpointContext.openPrincipalPolicyBundleReader,\n expectedHead: requireOrganizationGroupHead(\n descriptor,\n descriptor.adminGroupId,\n ),\n resolveUserKey: input.resolveUserKey,\n stillCurrent: input.stillCurrent,\n });\n if (!verifiedAdmins) {\n return null;\n }\n observePrincipalPolicy(\n input.checkpointContext,\n verified.value,\n input.organizationId,\n );\n observePrincipalPolicy(\n input.checkpointContext,\n verifiedAdmins,\n input.organizationId,\n );\n return organizationAdminExternalAuthority(verifiedAdmins);\n } catch (error) {\n rethrowProjectionVerificationBoundaryError(error);\n if (error instanceof KeyingVerificationError) {\n throw error;\n }\n return null;\n }\n}\n\n/**\n * Fresh or reused: check every projection, history included; pin first\n * sights within the verification's lifetime. A freshly verified `bundle` also\n * pins its signers.\n */\nasync function assertVerifiedPolicyCommitments(\n policy: PrincipalPolicyCurrentEvidence,\n scope: {\n readonly resolveUserKey: ProjectionUserKeyResolver;\n readonly stillCurrent?: (() => boolean) | undefined;\n },\n bundle?: PrincipalPolicyBundleResponse,\n): Promise<void> {\n const assertCurrent = () =>\n assertProjectionVerificationCurrent(scope.stillCurrent);\n await assertPrincipalIdentityCommitments({\n assertCurrent,\n authenticated: true,\n projections: [\n policy.projection,\n ...principalPolicyEvidenceEntries(policy).map(\n (entry) => entry.projection,\n ),\n ],\n resolveTrustedUserIdentity: scope.resolveUserKey,\n });\n if (bundle)\n await publishVerifiedPolicyBundle(\n bundle,\n scope.resolveUserKey,\n assertCurrent,\n );\n}\n\nasync function verifyReferencedPrincipalPolicy(input: {\n checkpointContext: ProjectionCheckpointContext;\n organizationId: string;\n principalPolicyCache: PrincipalPolicyCache;\n reference: ReferencedPrincipalHead;\n stillCurrent?: (() => boolean) | undefined;\n resolveUserKey: ProjectionUserKeyResolver;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<PrincipalPolicyCurrentEvidence> {\n // Scoped recovery carries organization, dependency and lifetime bindings.\n // A bare policy cache entry cannot replace those bindings.\n const recovered = await resolveReferencedPrincipalPolicy(input);\n if (recovered) {\n await assertVerifiedPolicyCommitments(recovered, input);\n return recovered;\n }\n const cacheKey = referencedPrincipalPolicyKey(input.reference);\n const cachedPolicy = input.principalPolicyCache.get(cacheKey);\n const execSql = input.checkpointContext.execSql;\n const localCheckpoint = await new KeyingCheckpointRepository(\n execSql,\n ).loadPrincipalPolicyCheckpoint(\n input.reference.principalType,\n input.reference.principalId,\n );\n if (cachedPolicy && !(\"retainedHistory\" in cachedPolicy)) {\n if (\n !verifiedPrincipalPolicyContainsReference(cachedPolicy, input.reference)\n ) {\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n \"in-memory principal policy cache does not match its exact reference\",\n );\n }\n if (verifiedPrincipalPolicyMeetsCheckpoint(cachedPolicy, localCheckpoint)) {\n await assertVerifiedPolicyCommitments(cachedPolicy, input);\n observePrincipalPolicy(\n input.checkpointContext,\n cachedPolicy,\n input.organizationId,\n );\n return cachedPolicy;\n }\n }\n\n const referenceLabel = principalPolicyReferenceLabel(input.reference);\n let bundle = await input.checkpointContext\n .openPrincipalPolicyBundleReader(execSql)\n .loadPrincipalPolicyBundleForReference(input.reference, localCheckpoint);\n if (!bundle && input.warmReferencedPrincipalPolicies) {\n // The reference is not cached locally — the common case for a member who\n // gained access via another org's group grant and never hydrated that\n // group's policy. Fetch+verify+persist it, then re-read from the cache.\n await input.warmReferencedPrincipalPolicies({\n organizationId: input.organizationId,\n references: [input.reference],\n });\n bundle = await input.checkpointContext\n .openPrincipalPolicyBundleReader(execSql)\n .loadPrincipalPolicyBundleForReference(input.reference, localCheckpoint);\n }\n if (!bundle) {\n throw new PrincipalPolicyNotCachedError(referenceLabel);\n }\n\n const signerPublicKeys = await collectPrincipalPolicySignerPublicKeys({\n bundle,\n label: `Principal policy ${referenceLabel}`,\n resolveUserKey: input.resolveUserKey,\n });\n const verified =\n await verifyPrincipalPolicyBundleWithExternalOrganizationAdmins({\n bundle,\n expectedReference: input.reference,\n loadExternalAuthority: () =>\n loadOrganizationExternalAuthority({\n checkpointContext: input.checkpointContext,\n organizationId: input.organizationId,\n resolveUserKey: input.resolveUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies:\n input.warmReferencedPrincipalPolicies,\n }),\n localCheckpoint,\n signerPublicKeys,\n });\n if (!verified.ok) {\n throw verified.error;\n }\n await assertVerifiedPolicyCommitments(verified.value, input, bundle);\n\n observePrincipalPolicy(\n input.checkpointContext,\n verified.value,\n input.organizationId,\n );\n input.principalPolicyCache.set(cacheKey, verified.value);\n return verified.value;\n}\n\nexport async function collectReferencedPrincipalPolicies(input: {\n checkpointContext: ProjectionCheckpointContext;\n organizationId: string;\n principalPolicyCache: PrincipalPolicyCache;\n references: readonly ReferencedPrincipalHead[];\n resolveUserKey: ProjectionUserKeyResolver;\n stillCurrent?: (() => boolean) | undefined;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<PrincipalPolicyCurrentEvidence[]> {\n const warmReferencedPrincipalPolicies =\n generationGuardedPrincipalPolicyWarmer(\n input.warmReferencedPrincipalPolicies,\n input.stillCurrent,\n );\n const uniqueReferences = new Map<string, ReferencedPrincipalHead>();\n for (const reference of input.references) {\n uniqueReferences.set(referencedPrincipalPolicyKey(reference), reference);\n }\n\n const references = [...uniqueReferences.values()];\n // Warm every missing reference in one batched fetch before verifying, so a\n // path that references several uncached policies makes a single round of\n // requests rather than one per reference.\n if (\n warmReferencedPrincipalPolicies &&\n !warmReferencedPrincipalPolicies.resolveReference\n ) {\n const uncached = await filterUncachedPrincipalPolicyReferences({\n execSql: input.checkpointContext.execSql,\n openPrincipalPolicyBundleReader:\n input.checkpointContext.openPrincipalPolicyBundleReader,\n principalPolicyCache: input.principalPolicyCache,\n references,\n });\n if (uncached.length > 0) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n await warmReferencedPrincipalPolicies({\n organizationId: input.organizationId,\n references: uncached,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n }\n }\n\n // The warmer's operation shares one recovery view across its collections.\n return Promise.all(\n references.map((reference) =>\n verifyReferencedPrincipalPolicy({\n checkpointContext: input.checkpointContext,\n organizationId: input.organizationId,\n principalPolicyCache: input.principalPolicyCache,\n reference,\n stillCurrent: input.stillCurrent,\n resolveUserKey: input.resolveUserKey,\n warmReferencedPrincipalPolicies,\n }),\n ),\n );\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PrincipalPolicyCheckpoint, ReferencedPrincipalHead, VerifiedPrincipalPolicyCurrent, VerifiedPrincipalPolicySelection } from "../../internal/crypto/index.js";
|
|
2
2
|
import type { PrincipalPolicyBundleResponse, PrincipalStateResponse, ProjectionPolicyEvidenceResponse } from "../../internal/validators/response/index.js";
|
|
3
|
-
import type { PrincipalPolicyCurrentEvidence } from "../
|
|
3
|
+
import type { PrincipalPolicyCurrentEvidence } from "../principalContracts/principalPolicyEvidence.js";
|
|
4
4
|
import type { ExecSql } from "../sqlite/sqlSchema.js";
|
|
5
5
|
import type { TrustedUserIdentity } from "../trustedUserIdentity/index.js";
|
|
6
6
|
export type ProjectionUserKey = TrustedUserIdentity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAsGA,MAAM,OAAO,oCAAqC,SAAQ,KAAK;IAC7D;QACE,KAAK,CAAC,4CAA4C,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,sCAAsC,CAAC;IACrD,CAAC;CACF;AAED,MAAM,kCAAkC,GACtC,IAAI,oCAAoC,EAAE,CAAC;AAE7C,MAAM,UAAU,sCAAsC,CACpD,KAAc;IAEd,OAAO,KAAK,KAAK,kCAAkC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,sCAAsC,CAAC,KAAc;IACnE,IAAI,sCAAsC,CAAC,KAAK,CAAC;QAAE,MAAM,KAAK,CAAC;AACjE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,wCAAwC,CAC5D,SAA2B;IAE3B,IAAI,CAAC;QACH,OAAO,MAAM,SAAS,EAAE,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,sCAAsC,CAAC,KAAK,CAAC;Y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AAO,CAAC,CAAC;wBAC7C,OAAO,MAAM,CAAC;oBAChB,CAAC;iBACF;gBACH,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO;gBACT,CAAC,CAAC;oBACE,gBAAgB,EAAE,KAAK,EAAE,KAAoC,EAAE,EAAE;wBAC/D,MAAM,OAAO,GAAG,GAAG,EAAE,CACnB,YAAY,EAAE,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,KAAK,CAAC;wBACrD,mCAAmC,CAAC,OAAO,CAAC,CAAC;wBAC7C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC;wBAClE,mCAAmC,CAAC,OAAO,CAAC,CAAC;wBAC7C,OAAO,MAAM,CAAC;oBAChB,CAAC;iBACF;gBACH,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAC;IACL,CAAC,CAAC;IACF,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,iCAAiC,CAO/C,KAAY;IACZ,OAAO;QACL,GAAG,KAAK;QACR,+BAA+B,EAAE,sCAAsC,CACrE,KAAK,CAAC,+BAA+B,EACrC,KAAK,CAAC,YAAY,CACnB;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n PrincipalPolicyCheckpoint,\n ReferencedPrincipalHead,\n VerifiedPrincipalPolicyCurrent,\n VerifiedPrincipalPolicySelection,\n} from \"@tearleads/crypto\";\nimport type {\n PrincipalPolicyBundleResponse,\n PrincipalStateResponse,\n ProjectionPolicyEvidenceResponse,\n} from \"@tearleads/validators/response\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAsGA,MAAM,OAAO,oCAAqC,SAAQ,KAAK;IAC7D;QACE,KAAK,CAAC,4CAA4C,CAAC,CAAC;QACpD,IAAI,CAA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,KAAK,CAAC,+BAA+B,EACrC,KAAK,CAAC,YAAY,CACnB;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n PrincipalPolicyCheckpoint,\n ReferencedPrincipalHead,\n VerifiedPrincipalPolicyCurrent,\n VerifiedPrincipalPolicySelection,\n} from \"@tearleads/crypto\";\nimport type {\n PrincipalPolicyBundleResponse,\n PrincipalStateResponse,\n ProjectionPolicyEvidenceResponse,\n} from \"@tearleads/validators/response\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../principalContracts/principalPolicyEvidence\";\nimport type { ExecSql } from \"../sqlite/sqlSchema\";\nimport type { TrustedUserIdentity } from \"../trustedUserIdentity\";\n\nexport type ProjectionUserKey = TrustedUserIdentity;\n\nexport type ProjectionUserKeyResolver = (\n userId: string,\n) => Promise<ProjectionUserKey | null>;\n\nexport type PrincipalPolicyCache = Map<string, PrincipalPolicyCurrentEvidence>;\n\n/**\n * The cached principal policy bundles verification reads, supplied by the\n * caller so verification does not depend on Principal Policy's store. Each\n * method ensures the principal policy tables on the executor it was opened on.\n */\nexport interface PrincipalPolicyBundleReader {\n ensurePrincipalPolicyTables(): Promise<void>;\n loadPrincipalPolicyBundle(\n principalType: PrincipalStateResponse[\"principalType\"],\n principalId: string,\n ): Promise<PrincipalPolicyBundleResponse | null>;\n /** The newest stored bundle containing exactly `reference`, never a guess. */\n loadPrincipalPolicyBundleForReference(\n reference: ReferencedPrincipalHead,\n checkpoint: PrincipalPolicyCheckpoint | null,\n ): Promise<PrincipalPolicyBundleResponse | null>;\n}\n\n/**\n * Opens the bundle reader on one executor. Verification opens it on the\n * executor each read runs on, a locked transaction handle included, so every\n * read sees that executor's snapshot.\n */\nexport type OpenPrincipalPolicyBundleReader = (\n execSql: ExecSql,\n) => PrincipalPolicyBundleReader;\n\nexport interface PrincipalPolicyResolveRequest {\n /** Reuse authenticated local ancestry before an authorized online recovery. */\n readonly preferLocalHistory?: boolean | undefined;\n /** One recovery view: the warmer's operation unless a caller supplies its own. */\n readonly recoveryBatch?: object | undefined;\n readonly organizationId: string;\n readonly reference: ReferencedPrincipalHead;\n readonly stillCurrent?: (() => boolean) | undefined;\n}\n\nexport interface ResolvedPrincipalPolicyEvidence {\n readonly stillCurrent: () => boolean;\n readonly organizationId: string;\n readonly policy: VerifiedPrincipalPolicyCurrent;\n readonly dependencies: readonly VerifiedPrincipalPolicyCurrent[];\n}\n\nexport interface ReferencedPrincipalPolicyWarmRequest {\n readonly organizationId: string;\n readonly references: readonly ReferencedPrincipalHead[];\n readonly stillCurrent?: (() => boolean) | undefined;\n}\n\nexport interface ProjectionPolicyHistoryResolveRequest {\n /** Authenticate terminal evidence first; its consumer must validate durable currency. */\n readonly historicalProof?: boolean | undefined;\n readonly organizationId: string;\n readonly evidence: ProjectionPolicyEvidenceResponse;\n readonly references: readonly ReferencedPrincipalHead[];\n readonly stillCurrent?: (() => boolean) | undefined;\n}\n\nexport interface ResolvedProjectionPolicyHistory {\n readonly policies: readonly VerifiedPrincipalPolicySelection[];\n readonly stillCurrent: () => boolean;\n}\n\nexport type ReferencedPrincipalPolicyWarmer = ((\n input: ReferencedPrincipalPolicyWarmRequest,\n) => Promise<void>) & {\n readonly resolveProjectionHistory?:\n | ((\n input: ProjectionPolicyHistoryResolveRequest,\n ) => Promise<ResolvedProjectionPolicyHistory>)\n | undefined;\n readonly resolveReference?:\n | ((\n input: PrincipalPolicyResolveRequest,\n ) => Promise<ResolvedPrincipalPolicyEvidence>)\n | undefined;\n};\n\nexport class ProjectionVerificationCancelledError extends Error {\n constructor() {\n super(\"Projection verification generation expired\");\n this.name = \"ProjectionVerificationCancelledError\";\n }\n}\n\nconst projectionVerificationCancellation =\n new ProjectionVerificationCancelledError();\n\nexport function isProjectionVerificationCancelledError(\n error: unknown,\n): error is ProjectionVerificationCancelledError {\n return error === projectionVerificationCancellation;\n}\n\nexport function rethrowProjectionVerificationCancelled(error: unknown): void {\n if (isProjectionVerificationCancelledError(error)) throw error;\n}\n\nexport async function nullOnProjectionVerificationCancellation<T>(\n operation: () => Promise<T>,\n): Promise<T | null> {\n try {\n return await operation();\n } catch (error) {\n if (isProjectionVerificationCancelledError(error)) return null;\n throw error;\n }\n}\n\nexport function assertProjectionVerificationCurrent(\n stillCurrent: (() => boolean) | undefined,\n): void {\n if (stillCurrent?.() === false) {\n throw projectionVerificationCancellation;\n }\n}\n\nexport function generationGuardedPrincipalPolicyWarmer(\n warmer: ReferencedPrincipalPolicyWarmer | undefined,\n stillCurrent: (() => boolean) | undefined,\n): ReferencedPrincipalPolicyWarmer | undefined {\n if (!warmer || !stillCurrent) return warmer;\n const guard =\n (operation: ReferencedPrincipalPolicyWarmer) =>\n async (input: ReferencedPrincipalPolicyWarmRequest) => {\n assertProjectionVerificationCurrent(stillCurrent);\n await operation({ ...input, stillCurrent });\n assertProjectionVerificationCurrent(stillCurrent);\n };\n const guardWithCapabilities = (\n operation: ReferencedPrincipalPolicyWarmer,\n ): ReferencedPrincipalPolicyWarmer => {\n const guarded = guard(operation);\n const resolve = operation.resolveReference;\n const resolveProjectionHistory = operation.resolveProjectionHistory;\n return Object.assign(guarded, {\n ...(resolveProjectionHistory\n ? {\n resolveProjectionHistory: async (\n input: ProjectionPolicyHistoryResolveRequest,\n ) => {\n const current = () =>\n stillCurrent() && input.stillCurrent?.() !== false;\n assertProjectionVerificationCurrent(current);\n const result = await resolveProjectionHistory({\n ...input,\n stillCurrent: current,\n });\n assertProjectionVerificationCurrent(current);\n return result;\n },\n }\n : {}),\n ...(resolve\n ? {\n resolveReference: async (input: PrincipalPolicyResolveRequest) => {\n const current = () =>\n stillCurrent() && input.stillCurrent?.() !== false;\n assertProjectionVerificationCurrent(current);\n const result = await resolve({ ...input, stillCurrent: current });\n assertProjectionVerificationCurrent(current);\n return result;\n },\n }\n : {}),\n });\n };\n return guardWithCapabilities(warmer);\n}\n\nexport function withGenerationGuardedPolicyWarmer<\n Input extends {\n readonly stillCurrent?: (() => boolean) | undefined;\n readonly warmReferencedPrincipalPolicies?:\n | ReferencedPrincipalPolicyWarmer\n | undefined;\n },\n>(input: Input): Input {\n return {\n ...input,\n warmReferencedPrincipalPolicies: generationGuardedPrincipalPolicyWarmer(\n input.warmReferencedPrincipalPolicies,\n input.stillCurrent,\n ),\n };\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { KeyingVerificationError, verifyAccessManifestLocalCheckpoint, verifyPri
|
|
|
2
2
|
import { keyingCheckpointTables } from "../../sqlite/schema/keyingCheckpointSchema.js";
|
|
3
3
|
import { principalPolicyTables } from "../../sqlite/schema/principalPolicySchema.js";
|
|
4
4
|
import { verifiedManifestBundleTables } from "../../sqlite/schema/verifiedManifestBundleSchema.js";
|
|
5
|
-
import { loadContainerRetirementCheck } from "../
|
|
5
|
+
import { loadContainerRetirementCheck } from "../principalContracts/principalGrantRetirementPersistence.js";
|
|
6
6
|
import { writeVerifiedManifestBundlesInTransaction, } from "../verifiedManifestBundlePersistence.js";
|
|
7
7
|
import { storeDocumentPurgeCheckpointInTransaction, } from "./documentPurgeCheckpointPersistence.js";
|
|
8
8
|
import { validateAccessManifestCheckpointEvidence } from "./keyingCheckpointEvidence.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyingCheckpointAdvancePersistence.js","sourceRoot":"","sources":["keyingCheckpointAdvancePersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,uBAAuB,EAIvB,mCAAmC,EACnC,+BAA+B,GAChC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAC;AAEhG,OAAO,EAAE,4BAA4B,EAAE,MAAM,sDAAsD,CAAC;AACpG,OAAO,EAGL,yCAAyC,GAC1C,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAEL,yCAAyC,GAC1C,MAAM,sCAAsC,CAAC;AAC9C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AAC;IACD,MAAM,yCAAyC,CAAC,EAAE,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import {\n type AccessManifestCheckpoint,\n type AnyVerifiedPrincipalPolicy,\n KeyingVerificationError,\n type VerifiedAccessManifestCheckpointEvidence,\n type VerifiedPrincipalPolicyCurrent,\n type VerifiedPrincipalPolicySelection,\n verifyAccessManifestLocalCheckpoint,\n verifyPrincipalPolicyCheckpoint,\n} from \"@tearleads/crypto\";\nimport { keyingCheckpointTables } from \"../../sqlite/schema/keyingCheckpointSchema\";\nimport { principalPolicyTables } from \"../../sqlite/schema/principalPolicySchema\";\nimport { verifiedManifestBundleTables } from \"../../sqlite/schema/verifiedManifestBundleSchema\";\nimport type { ClientSQLiteTransactionScope } from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { loadContainerRetirementCheck } from \"../principalKeys/principalGrantRetirementPersistence\";\nimport {\n type VerifiedManifestBundle,\n type VerifiedManifestBundleRow,\n writeVerifiedManifestBundlesInTransaction,\n} from \"../verifiedManifestBundlePersistence\";\nimport {\n type DocumentPurgeCheckpoint,\n storeDocumentPurgeCheckpointInTransaction,\n} from \"./documentPurgeCheckpointPersistence\";\nimport { validateAccessManifestCheckpointEvidence } from \"./keyingCheckpointEvidence\";\nimport {\n accessManifestObjectKey,\n loadAccessManifestCheckpointRows,\n loadStoredPrincipalPolicyCheckpoints,\n principalPolicyKey,\n upsertAccessManifestCheckpointsInTransaction,\n upsertPrincipalPolicyCheckpointsInTransaction,\n} from \"./keyingCheckpointPersistence\";\nimport { validatePrincipalAuthorizationCheckpoints } from \"./principalAuthorizationCheckpoints\";\n\nexport interface AccessManifestCheckpointAdvance {\n readonly head: VerifiedAccessManifestCheckpointEvidence;\n readonly predecessors: readonly VerifiedAccessManifestCheckpointEvidence[];\n}\n\ntype CheckpointPolicy =\n | AnyVerifiedPrincipalPolicy\n | VerifiedPrincipalPolicyCurrent;\n\n/** A verified batch of checkpoint candidates; the repository supplies the executor. */\nexport interface KeyingCheckpointBatch {\n readonly access: readonly AccessManifestCheckpointAdvance[];\n readonly policies: readonly CheckpointPolicy[];\n readonly authorizationPolicies?:\n | readonly VerifiedPrincipalPolicySelection[]\n | undefined;\n readonly stillCurrent?: (() => boolean) | undefined;\n /**\n * Bundles this projection verified. They are stored for later citation in\n * the same transaction, so they commit only with the batch they verified.\n */\n readonly verifiedBundles?: readonly VerifiedManifestBundle[] | undefined;\n}\n\nexport interface KeyingCheckpointAdvanceBatch extends KeyingCheckpointBatch {\n readonly documentPurgeCheckpoint?: DocumentPurgeCheckpoint | undefined;\n readonly organizationId?: string | undefined;\n}\n\ninterface PendingAccessCheckpoint {\n readonly changed: boolean;\n readonly checkpoint: AccessManifestCheckpoint;\n}\n\nfunction validateAccessAdvance(\n advance: AccessManifestCheckpointAdvance,\n localCheckpoint: AccessManifestCheckpoint | null,\n): PendingAccessCheckpoint {\n const current = {\n ...advance.head.checkpoint,\n previousManifestHash: advance.head.manifest.previousManifestHash,\n };\n const predecessors = [...advance.predecessors].sort(\n (left, right) => left.checkpoint.epoch - right.checkpoint.epoch,\n );\n\n if (localCheckpoint && current.epoch <= localCheckpoint.epoch) {\n verifyAccessManifestLocalCheckpoint({\n current,\n localCheckpoint,\n checkpointPredecessors: undefined,\n });\n }\n\n validateAccessManifestCheckpointEvidence({\n head: advance.head,\n predecessors,\n localCheckpoint,\n });\n\n verifyAccessManifestLocalCheckpoint({\n current,\n localCheckpoint,\n checkpointPredecessors: predecessors.filter(\n (manifest) =>\n localCheckpoint !== null &&\n manifest.checkpoint.epoch > localCheckpoint.epoch &&\n manifest.checkpoint.epoch < current.epoch,\n ),\n });\n\n return {\n changed:\n localCheckpoint?.epoch !== current.epoch ||\n localCheckpoint.manifestHash !== current.manifestHash,\n checkpoint: advance.head.checkpoint,\n };\n}\n\nasync function validateAccessAdvances(\n tx: ClientSQLiteTransactionScope,\n advances: readonly AccessManifestCheckpointAdvance[],\n): Promise<Map<string, PendingAccessCheckpoint>> {\n const pending = new Map<string, PendingAccessCheckpoint>();\n if (advances.length === 0) return pending;\n // Set reads first; the checks then replay in order, so the same advance\n // fails first with the same error.\n const heads = advances.map((advance) => advance.head.checkpoint);\n const assertNotRetired = await loadContainerRetirementCheck(tx, heads);\n const stored = await loadAccessManifestCheckpointRows(tx, heads);\n\n for (const advance of advances) {\n assertNotRetired(advance.head.checkpoint);\n const key = accessManifestObjectKey(advance.head.checkpoint);\n if (pending.has(key)) {\n throw new KeyingVerificationError(\n \"equivocation\",\n `projection declares multiple access checkpoint heads for ${key}`,\n );\n }\n const row = stored.get(key);\n const localCheckpoint = row ? { ...advance.head.checkpoint, ...row } : null;\n pending.set(key, validateAccessAdvance(advance, localCheckpoint));\n }\n\n return pending;\n}\n\nfunction extendsObservedPolicy(\n head: CheckpointPolicy,\n candidate: CheckpointPolicy,\n): boolean {\n const history =\n \"retainedHistory\" in head ? head.retainedHistory : head.history;\n return (\n history?.some(\n ({ state }) =>\n state.principalType === candidate.principalType &&\n state.principalId === candidate.principalId &&\n state.version === candidate.version &&\n state.stateHash === candidate.stateHash,\n ) ?? false\n );\n}\n\n/** The newest candidate, which must be unique and extend every other one. */\nfunction selectPrincipalPolicyHead(\n key: string,\n candidates: readonly CheckpointPolicy[],\n): CheckpointPolicy | null {\n const maxVersion = Math.max(...candidates.map((policy) => policy.version));\n const heads = candidates.filter((policy) => policy.version === maxVersion);\n const head = heads[0];\n if (!head) {\n return null;\n }\n if (heads.some((candidate) => candidate.stateHash !== head.stateHash)) {\n throw new KeyingVerificationError(\n \"equivocation\",\n `principal policy declares conflicting heads for ${key}`,\n );\n }\n for (const candidate of candidates) {\n if (candidate.version === head.version) {\n continue;\n }\n if (!extendsObservedPolicy(head, candidate)) {\n throw new KeyingVerificationError(\n \"stale_predecessor\",\n `principal policy head does not extend observed state for ${key}`,\n );\n }\n }\n return head;\n}\n\n/**\n * Checks, inside the caller's transaction, that each principal's newest policy\n * extends every other candidate and its durable checkpoint. Returns the heads\n * to pin, keyed by principal.\n */\nexport async function validatePrincipalPolicyCheckpointAdvances(\n tx: ClientSQLiteTransactionScope,\n policies: readonly CheckpointPolicy[],\n): Promise<Map<string, CheckpointPolicy>> {\n const policiesByPrincipal = new Map<string, CheckpointPolicy[]>();\n for (const policy of policies) {\n const key = principalPolicyKey(policy);\n const candidates = policiesByPrincipal.get(key) ?? [];\n candidates.push(policy);\n policiesByPrincipal.set(key, candidates);\n }\n\n const pending = new Map<string, CheckpointPolicy>();\n const stored = await loadStoredPrincipalPolicyCheckpoints(tx, policies);\n for (const key of [...policiesByPrincipal.keys()].sort()) {\n const head = selectPrincipalPolicyHead(\n key,\n policiesByPrincipal.get(key) ?? [],\n );\n if (!head) {\n continue;\n }\n\n const localCheckpoint = stored.get(key) ?? null;\n verifyPrincipalPolicyCheckpoint({\n chain:\n \"retainedHistory\" in head ? head.retainedHistory : (head.history ?? []),\n currentState: head.state,\n localCheckpoint,\n });\n pending.set(key, head);\n }\n\n return pending;\n}\n\nasync function writeAccessCheckpoints(\n tx: ClientSQLiteTransactionScope,\n pending: ReadonlyMap<string, PendingAccessCheckpoint>,\n updatedAt: string,\n): Promise<void> {\n await upsertAccessManifestCheckpointsInTransaction(\n tx,\n [...pending.values()]\n .filter(({ changed }) => changed)\n .map(({ checkpoint }) => checkpoint),\n updatedAt,\n );\n}\n\n/** Pins the heads `validatePrincipalPolicyCheckpointAdvances` returned. */\nexport async function writePrincipalPolicyCheckpoints(\n tx: ClientSQLiteTransactionScope,\n pending: ReadonlyMap<string, CheckpointPolicy>,\n updatedAt: string,\n organizationId?: string | undefined,\n): Promise<void> {\n await upsertPrincipalPolicyCheckpointsInTransaction(\n tx,\n [...pending.values()].map((policy) => policy.checkpoint),\n updatedAt,\n organizationId,\n );\n}\n\n/** Every table a batch touches, ensured before its transaction begins. */\nexport function keyingCheckpointBatchTables(\n batch: KeyingCheckpointBatch,\n bundleRows: readonly VerifiedManifestBundleRow[],\n) {\n return [\n ...(batch.policies.length > 0 ||\n (batch.authorizationPolicies?.length ?? 0) > 0\n ? principalPolicyTables\n : []),\n ...keyingCheckpointTables,\n ...(bundleRows.length > 0 ? verifiedManifestBundleTables : []),\n ];\n}\n\n/**\n * Re-checks verified candidates against durable pins without advancing them.\n * Only the verified bundles' citation rows are written.\n */\nexport async function validateKeyingCheckpointsInTransaction(\n tx: ClientSQLiteTransactionScope,\n batch: KeyingCheckpointBatch,\n bundleRows: readonly VerifiedManifestBundleRow[],\n verifiedAt: string,\n): Promise<void> {\n await validateAccessAdvances(tx, batch.access);\n await validatePrincipalPolicyCheckpointAdvances(tx, batch.policies);\n await validatePrincipalAuthorizationCheckpoints(\n tx,\n batch.authorizationPolicies ?? [],\n );\n await writeVerifiedManifestBundlesInTransaction(tx, bundleRows, verifiedAt);\n}\n\n/**\n * Re-check every verified projection candidate against the latest durable pins\n * and advance the complete batch. Signature verification and remote fetching\n * happen before the short transaction this runs in; only checkpoint comparison\n * and persistence, with the batch's verified bundles, are serialized here.\n */\nexport async function advanceKeyingCheckpointsInTransaction(\n tx: ClientSQLiteTransactionScope,\n batch: KeyingCheckpointAdvanceBatch,\n bundleRows: readonly VerifiedManifestBundleRow[],\n updatedAt: string,\n): Promise<void> {\n const access = await validateAccessAdvances(tx, batch.access);\n const policies = await validatePrincipalPolicyCheckpointAdvances(\n tx,\n batch.policies,\n );\n await validatePrincipalAuthorizationCheckpoints(\n tx,\n batch.authorizationPolicies ?? [],\n );\n\n await writeAccessCheckpoints(tx, access, updatedAt);\n await writePrincipalPolicyCheckpoints(\n tx,\n policies,\n updatedAt,\n batch.organizationId,\n );\n if (batch.documentPurgeCheckpoint) {\n await storeDocumentPurgeCheckpointInTransaction(\n tx,\n batch.documentPurgeCheckpoint,\n updatedAt,\n );\n }\n await writeVerifiedManifestBundlesInTransaction(tx, bundleRows, updatedAt);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"keyingCheckpointAdvancePersistence.js","sourceRoot":"","sources":["keyingCheckpointAdvancePersistence.ts"],"names":[],"m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D,EAAE,EACF,KAAK,CAAC,QAAQ,CACf,CAAC;IACF,MAAM,yCAAyC,CAC7C,EAAE,EACF,KAAK,CAAC,qBAAqB,IAAI,EAAE,CAClC,CAAC;IAEF,MAAM,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACpD,MAAM,+BAA+B,CACnC,EAAE,EACF,QAAQ,EACR,SAAS,EACT,KAAK,CAAC,cAAc,CACrB,CAAC;IACF,IAAI,KAAK,CAAC,uBAAuB,EAAE,CAAC;QAClC,MAAM,yCAAyC,CAC7C,EAAE,EACF,KAAK,CAAC,uBAAuB,EAC7B,SAAS,CACV,CAAC;IACJ,CAAC;IACD,MAAM,yCAAyC,CAAC,EAAE,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import {\n type AccessManifestCheckpoint,\n type AnyVerifiedPrincipalPolicy,\n KeyingVerificationError,\n type VerifiedAccessManifestCheckpointEvidence,\n type VerifiedPrincipalPolicyCurrent,\n type VerifiedPrincipalPolicySelection,\n verifyAccessManifestLocalCheckpoint,\n verifyPrincipalPolicyCheckpoint,\n} from \"@tearleads/crypto\";\nimport { keyingCheckpointTables } from \"../../sqlite/schema/keyingCheckpointSchema\";\nimport { principalPolicyTables } from \"../../sqlite/schema/principalPolicySchema\";\nimport { verifiedManifestBundleTables } from \"../../sqlite/schema/verifiedManifestBundleSchema\";\nimport type { ClientSQLiteTransactionScope } from \"../../sqlite/sqlitePersistenceRuntime\";\nimport { loadContainerRetirementCheck } from \"../principalContracts/principalGrantRetirementPersistence\";\nimport {\n type VerifiedManifestBundle,\n type VerifiedManifestBundleRow,\n writeVerifiedManifestBundlesInTransaction,\n} from \"../verifiedManifestBundlePersistence\";\nimport {\n type DocumentPurgeCheckpoint,\n storeDocumentPurgeCheckpointInTransaction,\n} from \"./documentPurgeCheckpointPersistence\";\nimport { validateAccessManifestCheckpointEvidence } from \"./keyingCheckpointEvidence\";\nimport {\n accessManifestObjectKey,\n loadAccessManifestCheckpointRows,\n loadStoredPrincipalPolicyCheckpoints,\n principalPolicyKey,\n upsertAccessManifestCheckpointsInTransaction,\n upsertPrincipalPolicyCheckpointsInTransaction,\n} from \"./keyingCheckpointPersistence\";\nimport { validatePrincipalAuthorizationCheckpoints } from \"./principalAuthorizationCheckpoints\";\n\nexport interface AccessManifestCheckpointAdvance {\n readonly head: VerifiedAccessManifestCheckpointEvidence;\n readonly predecessors: readonly VerifiedAccessManifestCheckpointEvidence[];\n}\n\ntype CheckpointPolicy =\n | AnyVerifiedPrincipalPolicy\n | VerifiedPrincipalPolicyCurrent;\n\n/** A verified batch of checkpoint candidates; the repository supplies the executor. */\nexport interface KeyingCheckpointBatch {\n readonly access: readonly AccessManifestCheckpointAdvance[];\n readonly policies: readonly CheckpointPolicy[];\n readonly authorizationPolicies?:\n | readonly VerifiedPrincipalPolicySelection[]\n | undefined;\n readonly stillCurrent?: (() => boolean) | undefined;\n /**\n * Bundles this projection verified. They are stored for later citation in\n * the same transaction, so they commit only with the batch they verified.\n */\n readonly verifiedBundles?: readonly VerifiedManifestBundle[] | undefined;\n}\n\nexport interface KeyingCheckpointAdvanceBatch extends KeyingCheckpointBatch {\n readonly documentPurgeCheckpoint?: DocumentPurgeCheckpoint | undefined;\n readonly organizationId?: string | undefined;\n}\n\ninterface PendingAccessCheckpoint {\n readonly changed: boolean;\n readonly checkpoint: AccessManifestCheckpoint;\n}\n\nfunction validateAccessAdvance(\n advance: AccessManifestCheckpointAdvance,\n localCheckpoint: AccessManifestCheckpoint | null,\n): PendingAccessCheckpoint {\n const current = {\n ...advance.head.checkpoint,\n previousManifestHash: advance.head.manifest.previousManifestHash,\n };\n const predecessors = [...advance.predecessors].sort(\n (left, right) => left.checkpoint.epoch - right.checkpoint.epoch,\n );\n\n if (localCheckpoint && current.epoch <= localCheckpoint.epoch) {\n verifyAccessManifestLocalCheckpoint({\n current,\n localCheckpoint,\n checkpointPredecessors: undefined,\n });\n }\n\n validateAccessManifestCheckpointEvidence({\n head: advance.head,\n predecessors,\n localCheckpoint,\n });\n\n verifyAccessManifestLocalCheckpoint({\n current,\n localCheckpoint,\n checkpointPredecessors: predecessors.filter(\n (manifest) =>\n localCheckpoint !== null &&\n manifest.checkpoint.epoch > localCheckpoint.epoch &&\n manifest.checkpoint.epoch < current.epoch,\n ),\n });\n\n return {\n changed:\n localCheckpoint?.epoch !== current.epoch ||\n localCheckpoint.manifestHash !== current.manifestHash,\n checkpoint: advance.head.checkpoint,\n };\n}\n\nasync function validateAccessAdvances(\n tx: ClientSQLiteTransactionScope,\n advances: readonly AccessManifestCheckpointAdvance[],\n): Promise<Map<string, PendingAccessCheckpoint>> {\n const pending = new Map<string, PendingAccessCheckpoint>();\n if (advances.length === 0) return pending;\n // Set reads first; the checks then replay in order, so the same advance\n // fails first with the same error.\n const heads = advances.map((advance) => advance.head.checkpoint);\n const assertNotRetired = await loadContainerRetirementCheck(tx, heads);\n const stored = await loadAccessManifestCheckpointRows(tx, heads);\n\n for (const advance of advances) {\n assertNotRetired(advance.head.checkpoint);\n const key = accessManifestObjectKey(advance.head.checkpoint);\n if (pending.has(key)) {\n throw new KeyingVerificationError(\n \"equivocation\",\n `projection declares multiple access checkpoint heads for ${key}`,\n );\n }\n const row = stored.get(key);\n const localCheckpoint = row ? { ...advance.head.checkpoint, ...row } : null;\n pending.set(key, validateAccessAdvance(advance, localCheckpoint));\n }\n\n return pending;\n}\n\nfunction extendsObservedPolicy(\n head: CheckpointPolicy,\n candidate: CheckpointPolicy,\n): boolean {\n const history =\n \"retainedHistory\" in head ? head.retainedHistory : head.history;\n return (\n history?.some(\n ({ state }) =>\n state.principalType === candidate.principalType &&\n state.principalId === candidate.principalId &&\n state.version === candidate.version &&\n state.stateHash === candidate.stateHash,\n ) ?? false\n );\n}\n\n/** The newest candidate, which must be unique and extend every other one. */\nfunction selectPrincipalPolicyHead(\n key: string,\n candidates: readonly CheckpointPolicy[],\n): CheckpointPolicy | null {\n const maxVersion = Math.max(...candidates.map((policy) => policy.version));\n const heads = candidates.filter((policy) => policy.version === maxVersion);\n const head = heads[0];\n if (!head) {\n return null;\n }\n if (heads.some((candidate) => candidate.stateHash !== head.stateHash)) {\n throw new KeyingVerificationError(\n \"equivocation\",\n `principal policy declares conflicting heads for ${key}`,\n );\n }\n for (const candidate of candidates) {\n if (candidate.version === head.version) {\n continue;\n }\n if (!extendsObservedPolicy(head, candidate)) {\n throw new KeyingVerificationError(\n \"stale_predecessor\",\n `principal policy head does not extend observed state for ${key}`,\n );\n }\n }\n return head;\n}\n\n/**\n * Checks, inside the caller's transaction, that each principal's newest policy\n * extends every other candidate and its durable checkpoint. Returns the heads\n * to pin, keyed by principal.\n */\nexport async function validatePrincipalPolicyCheckpointAdvances(\n tx: ClientSQLiteTransactionScope,\n policies: readonly CheckpointPolicy[],\n): Promise<Map<string, CheckpointPolicy>> {\n const policiesByPrincipal = new Map<string, CheckpointPolicy[]>();\n for (const policy of policies) {\n const key = principalPolicyKey(policy);\n const candidates = policiesByPrincipal.get(key) ?? [];\n candidates.push(policy);\n policiesByPrincipal.set(key, candidates);\n }\n\n const pending = new Map<string, CheckpointPolicy>();\n const stored = await loadStoredPrincipalPolicyCheckpoints(tx, policies);\n for (const key of [...policiesByPrincipal.keys()].sort()) {\n const head = selectPrincipalPolicyHead(\n key,\n policiesByPrincipal.get(key) ?? [],\n );\n if (!head) {\n continue;\n }\n\n const localCheckpoint = stored.get(key) ?? null;\n verifyPrincipalPolicyCheckpoint({\n chain:\n \"retainedHistory\" in head ? head.retainedHistory : (head.history ?? []),\n currentState: head.state,\n localCheckpoint,\n });\n pending.set(key, head);\n }\n\n return pending;\n}\n\nasync function writeAccessCheckpoints(\n tx: ClientSQLiteTransactionScope,\n pending: ReadonlyMap<string, PendingAccessCheckpoint>,\n updatedAt: string,\n): Promise<void> {\n await upsertAccessManifestCheckpointsInTransaction(\n tx,\n [...pending.values()]\n .filter(({ changed }) => changed)\n .map(({ checkpoint }) => checkpoint),\n updatedAt,\n );\n}\n\n/** Pins the heads `validatePrincipalPolicyCheckpointAdvances` returned. */\nexport async function writePrincipalPolicyCheckpoints(\n tx: ClientSQLiteTransactionScope,\n pending: ReadonlyMap<string, CheckpointPolicy>,\n updatedAt: string,\n organizationId?: string | undefined,\n): Promise<void> {\n await upsertPrincipalPolicyCheckpointsInTransaction(\n tx,\n [...pending.values()].map((policy) => policy.checkpoint),\n updatedAt,\n organizationId,\n );\n}\n\n/** Every table a batch touches, ensured before its transaction begins. */\nexport function keyingCheckpointBatchTables(\n batch: KeyingCheckpointBatch,\n bundleRows: readonly VerifiedManifestBundleRow[],\n) {\n return [\n ...(batch.policies.length > 0 ||\n (batch.authorizationPolicies?.length ?? 0) > 0\n ? principalPolicyTables\n : []),\n ...keyingCheckpointTables,\n ...(bundleRows.length > 0 ? verifiedManifestBundleTables : []),\n ];\n}\n\n/**\n * Re-checks verified candidates against durable pins without advancing them.\n * Only the verified bundles' citation rows are written.\n */\nexport async function validateKeyingCheckpointsInTransaction(\n tx: ClientSQLiteTransactionScope,\n batch: KeyingCheckpointBatch,\n bundleRows: readonly VerifiedManifestBundleRow[],\n verifiedAt: string,\n): Promise<void> {\n await validateAccessAdvances(tx, batch.access);\n await validatePrincipalPolicyCheckpointAdvances(tx, batch.policies);\n await validatePrincipalAuthorizationCheckpoints(\n tx,\n batch.authorizationPolicies ?? [],\n );\n await writeVerifiedManifestBundlesInTransaction(tx, bundleRows, verifiedAt);\n}\n\n/**\n * Re-check every verified projection candidate against the latest durable pins\n * and advance the complete batch. Signature verification and remote fetching\n * happen before the short transaction this runs in; only checkpoint comparison\n * and persistence, with the batch's verified bundles, are serialized here.\n */\nexport async function advanceKeyingCheckpointsInTransaction(\n tx: ClientSQLiteTransactionScope,\n batch: KeyingCheckpointAdvanceBatch,\n bundleRows: readonly VerifiedManifestBundleRow[],\n updatedAt: string,\n): Promise<void> {\n const access = await validateAccessAdvances(tx, batch.access);\n const policies = await validatePrincipalPolicyCheckpointAdvances(\n tx,\n batch.policies,\n );\n await validatePrincipalAuthorizationCheckpoints(\n tx,\n batch.authorizationPolicies ?? [],\n );\n\n await writeAccessCheckpoints(tx, access, updatedAt);\n await writePrincipalPolicyCheckpoints(\n tx,\n policies,\n updatedAt,\n batch.organizationId,\n );\n if (batch.documentPurgeCheckpoint) {\n await storeDocumentPurgeCheckpointInTransaction(\n tx,\n batch.documentPurgeCheckpoint,\n updatedAt,\n );\n }\n await writeVerifiedManifestBundlesInTransaction(tx, bundleRows, updatedAt);\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { accessManifestCheckpointFromManifest, KeyingVerificationError, verifyAccessManifestLocalCheckpoint, } from "../../../internal/crypto/index.js";
|
|
2
|
-
import { loadContainerRetirementCheck } from "../
|
|
2
|
+
import { loadContainerRetirementCheck } from "../principalContracts/principalGrantRetirementPersistence.js";
|
|
3
3
|
import { accessManifestObjectKey, loadAccessManifestCheckpointRows, loadPrincipalPolicyCheckpointRows, principalPolicyKey, storedPrincipalPolicyPin, upsertAccessManifestCheckpointsInTransaction, } from "./keyingCheckpointPersistence.js";
|
|
4
4
|
export function locallyAuthoredAccessManifestHead(plan) {
|
|
5
5
|
return {
|
|
@@ -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;AAE3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"locallyAcknowledgedCheckpointPersistence.js","sourceRoot":"","sources":["locallyAcknowledgedCheckpointPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,oCAAoC,EACpC,uBAAuB,EAEvB,mCAAmC,GACpC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,2DAA2D,C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AC/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 { ClientSQLiteTransactionScope } from \"../../sqlite/sqlitePersistenceRuntime\";\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\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\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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyingVerificationError, } from "../../../internal/crypto/index.js";
|
|
2
|
-
import { assertContainerNotRetired } from "../
|
|
2
|
+
import { assertContainerNotRetired } from "../principalContracts/principalGrantRetirementPersistence.js";
|
|
3
3
|
import { loadStoredAccessManifestCheckpoint, loadStoredPrincipalPolicyCheckpoint, upsertAccessManifestCheckpointInTransaction, upsertPrincipalPolicyCheckpointInTransaction, } from "./keyingCheckpointPersistence.js";
|
|
4
4
|
import { recordPrincipalPolicyOrganizationInTransaction } from "./principalPolicyOrganizationPersistence.js";
|
|
5
5
|
/**
|