@tearleads/client-sdk 0.1.19 → 0.1.21
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/index.js +2 -2
- package/client/organizations/index.js.map +1 -1
- package/client/organizations/organizationHistory.js +66 -0
- package/client/organizations/organizationHistory.js.map +1 -0
- package/client/organizations/organizationReadModels.d.ts +1 -1
- package/client/organizations/organizationReadModels.js +7 -27
- package/client/organizations/organizationReadModels.js.map +1 -1
- package/client/organizations/organizationsTypes.d.ts +1 -1
- package/client/organizations/organizationsTypes.js.map +1 -1
- package/data/containers/shared/types.d.ts +2 -2
- package/data/containers/shared/types.js.map +1 -1
- package/data/documents/shared/syncSubmitFailure.d.ts +2 -2
- package/data/documents/shared/syncSubmitFailure.js.map +1 -1
- package/data/keyingProjectionVerification/documentPurgeCheckpointCurrency.js +34 -8
- package/data/keyingProjectionVerification/documentPurgeCheckpointCurrency.js.map +1 -1
- package/data/keyingProjectionVerification/documentPurgeDocumentChainVerification.js.map +1 -1
- package/data/keyingProjectionVerification/documentPurgePolicyCheckpoints.js +17 -0
- package/data/keyingProjectionVerification/documentPurgePolicyCheckpoints.js.map +1 -0
- package/data/keyingProjectionVerification/documentPurgePolicyCurrency.js +55 -0
- package/data/keyingProjectionVerification/documentPurgePolicyCurrency.js.map +1 -0
- package/data/keyingProjectionVerification/documentPurgePrincipalEvidence.js +25 -13
- package/data/keyingProjectionVerification/documentPurgePrincipalEvidence.js.map +1 -1
- package/data/keyingProjectionVerification/documentPurgeProofVerification.d.ts +5 -3
- package/data/keyingProjectionVerification/documentPurgeProofVerification.js +52 -8
- package/data/keyingProjectionVerification/documentPurgeProofVerification.js.map +1 -1
- package/data/keyingProjectionVerification/projectionPolicyEvidence.js.map +1 -1
- package/data/keyingProjectionVerification/types.d.ts +4 -0
- package/data/keyingProjectionVerification/types.js.map +1 -1
- package/data/persistence/organizations/organizationReadModelProjection.js +2 -2
- package/data/persistence/organizations/organizationReadModelProjection.js.map +1 -1
- package/data/persistence/principalAuthorizationCheckpoints.js +1 -1
- package/data/persistence/principalAuthorizationCheckpoints.js.map +1 -1
- package/data/persistence/principalCurrentAcknowledgementPersistence.d.ts +1 -0
- package/data/persistence/principalCurrentAcknowledgementPersistence.js +58 -12
- package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -1
- package/data/persistence/principalHistoryEvidencePersistence.d.ts +2 -0
- package/data/persistence/principalHistoryEvidencePersistence.js +2 -0
- package/data/persistence/principalHistoryEvidencePersistence.js.map +1 -1
- package/data/persistence/principalHistoryIncompleteRetention.js +32 -0
- package/data/persistence/principalHistoryIncompleteRetention.js.map +1 -0
- package/data/persistence/principalHistoryNodeRetention.js +76 -0
- package/data/persistence/principalHistoryNodeRetention.js.map +1 -0
- package/data/persistence/principalHistoryPrefixPersistence.d.ts +1 -0
- package/data/persistence/principalHistoryPrefixPersistence.js +30 -1
- package/data/persistence/principalHistoryPrefixPersistence.js.map +1 -1
- package/data/persistence/principalHistoryRootOwnership.js +71 -0
- package/data/persistence/principalHistoryRootOwnership.js.map +1 -0
- package/data/persistence/principalHistoryStagePersistence.js +45 -0
- package/data/persistence/principalHistoryStagePersistence.js.map +1 -1
- package/data/persistence/principalHistoryStageRetention.js +44 -0
- package/data/persistence/principalHistoryStageRetention.js.map +1 -0
- package/data/persistence/principalHistoryUnpublishedRetention.js +71 -0
- package/data/persistence/principalHistoryUnpublishedRetention.js.map +1 -0
- package/data/persistence/principalKeyEnvelopeArchivePersistence.js +63 -0
- package/data/persistence/principalKeyEnvelopeArchivePersistence.js.map +1 -0
- package/data/persistence/principalKeyEnvelopeCandidates.js +10 -1
- package/data/persistence/principalKeyEnvelopeCandidates.js.map +1 -1
- package/data/persistence/principalPolicyReferencePersistence.js +2 -2
- package/data/persistence/principalPolicyReferencePersistence.js.map +1 -1
- package/data/sqlite/principalHistoryEvidenceSchema.js +2 -0
- package/data/sqlite/principalHistoryEvidenceSchema.js.map +1 -1
- package/data/sqlite/principalHistoryNodeRetentionSchema.js +30 -0
- package/data/sqlite/principalHistoryNodeRetentionSchema.js.map +1 -0
- package/data/sqlite/principalHistoryRetentionSchema.js +40 -0
- package/data/sqlite/principalHistoryRetentionSchema.js.map +1 -0
- package/data/sqlite/principalHistoryStageSchema.js +2 -0
- package/data/sqlite/principalHistoryStageSchema.js.map +1 -1
- package/data/sqlite/schema.d.ts +453 -0
- package/data/sqlite/schema.js +6 -0
- package/data/sqlite/schema.js.map +1 -1
- package/data/sqlite/sqliteCommitGuards.js +49 -0
- package/data/sqlite/sqliteCommitGuards.js.map +1 -0
- package/data/sqlite/sqlitePersistenceRuntime.js +14 -2
- package/data/sqlite/sqlitePersistenceRuntime.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +60 -137
- package/internal/api-client/ApiClient.js +7 -5
- package/internal/api-client/ApiClient.js.map +1 -1
- package/internal/api-client/apiRequestRuntime.js +7 -7
- package/internal/api-client/apiRequestRuntime.js.map +1 -1
- package/internal/api-client/documentPurge.js +25 -0
- package/internal/api-client/documentPurge.js.map +1 -0
- package/internal/api-client/organizationPolicyHistory.d.ts +53 -0
- package/internal/api-client/organizationPolicyHistory.js +15 -0
- package/internal/api-client/organizationPolicyHistory.js.map +1 -0
- package/internal/api-client/requestInternals.js +4 -4
- package/internal/api-client/requestInternals.js.map +1 -1
- package/internal/api-client/types.d.ts +2 -2
- package/internal/api-client/types.js.map +1 -1
- package/internal/crypto/keying/accessEvent.js +11 -9
- package/internal/crypto/keying/accessEvent.js.map +1 -1
- package/internal/crypto/keying/principalPolicyChainEntry.js +3 -0
- package/internal/crypto/keying/principalPolicyChainEntry.js.map +1 -1
- package/internal/crypto/keying/principalPolicyHistory.js +4 -0
- package/internal/crypto/keying/principalPolicyHistory.js.map +1 -1
- package/internal/crypto/keying/principalPolicyHistoryTypes.d.ts +2 -0
- package/internal/crypto/keying/principalPolicyHistoryTypes.js.map +1 -1
- package/internal/crypto/keying/principalPolicyTransition.d.ts +2 -1
- package/internal/crypto/keying/principalPolicyTransition.js +5 -0
- package/internal/crypto/keying/principalPolicyTransition.js.map +1 -1
- package/internal/crypto/principalState.js +2 -2
- package/internal/crypto/principalState.js.map +1 -1
- package/internal/validators/operation/containerMutations.d.ts +448 -6528
- package/internal/validators/operation/documentMutations.d.ts +323 -579
- package/internal/validators/operation/documentMutations.js +22 -4
- package/internal/validators/operation/documentMutations.js.map +1 -1
- package/internal/validators/operation/documentSync.d.ts +26 -406
- package/internal/validators/operation/organizationPolicyHistory.d.ts +188 -310
- package/internal/validators/operation/organizationPolicyHistory.js +17 -3
- package/internal/validators/operation/organizationPolicyHistory.js.map +1 -1
- package/internal/validators/operation/organizations.d.ts +2 -2
- package/internal/validators/request/principal.js +2 -2
- package/internal/validators/request/principal.js.map +1 -1
- package/internal/validators/response/containerMutationError.d.ts +28 -408
- package/internal/validators/response/documentMutation.d.ts +232 -544
- package/internal/validators/response/documentMutation.js +1 -2
- package/internal/validators/response/documentMutation.js.map +1 -1
- package/internal/validators/response/documentSyncError.d.ts +26 -406
- package/internal/validators/response/documentSyncError.js +4 -3
- package/internal/validators/response/documentSyncError.js.map +1 -1
- package/internal/validators/response/index.d.ts +1 -1
- package/internal/validators/response/index.js +1 -1
- package/internal/validators/response/index.js.map +1 -1
- package/internal/validators/response/organization.d.ts +1 -1
- package/internal/validators/response/organization.js +1 -1
- package/internal/validators/response/organization.js.map +1 -1
- package/internal/validators/response/organizationPolicyHistory.d.ts +127 -309
- package/internal/validators/response/organizationPolicyHistory.js +10 -4
- package/internal/validators/response/organizationPolicyHistory.js.map +1 -1
- package/internal/validators/response/organizationReadModel.d.ts +5 -5
- package/internal/validators/response/principal.d.ts +28 -408
- package/internal/validators/response/principal.js +3 -1
- package/internal/validators/response/principal.js.map +1 -1
- package/internal/validators/response/principalReference.d.ts +1 -1
- package/internal/validators/response/principalReference.js +1 -1
- package/internal/validators/response/principalReference.js.map +1 -1
- package/internal/validators/response/principalSnapshot.js +4 -4
- package/internal/validators/response/principalSnapshot.js.map +1 -1
- package/internal/validators/util/index.d.ts +1 -1
- package/internal/validators/util/index.js +1 -1
- package/internal/validators/util/index.js.map +1 -1
- package/internal/validators/util/principalHistoryWire.d.ts +2 -0
- package/internal/validators/util/principalHistoryWire.js +2 -0
- package/internal/validators/util/principalHistoryWire.js.map +1 -1
- package/package.json +1 -1
- package/workflows/container-contents/container-state/createWithMetadata.js +19 -49
- package/workflows/container-contents/container-state/createWithMetadata.js.map +1 -1
- package/workflows/container-contents/container-state/groupGrantVerification.js +29 -0
- package/workflows/container-contents/container-state/groupGrantVerification.js.map +1 -1
- package/workflows/container-contents/container-state/groupShareEpoch.js +33 -0
- package/workflows/container-contents/container-state/groupShareEpoch.js.map +1 -0
- package/workflows/container-contents/container-state/remote.js +4 -1
- package/workflows/container-contents/container-state/remote.js.map +1 -1
- package/workflows/container-contents/container-state/share.js +2 -24
- package/workflows/container-contents/container-state/share.js.map +1 -1
- package/workflows/container-contents/documentTombstoneEvidence.js +23 -12
- package/workflows/container-contents/documentTombstoneEvidence.js.map +1 -1
- package/workflows/containers/child/create.js +1 -3
- package/workflows/containers/child/create.js.map +1 -1
- package/workflows/containers/child/createSubmission.d.ts +1 -3
- package/workflows/containers/child/createSubmission.js +13 -15
- package/workflows/containers/child/createSubmission.js.map +1 -1
- package/workflows/containers/child/currentShareGrantMutation.js +82 -0
- package/workflows/containers/child/currentShareGrantMutation.js.map +1 -0
- package/workflows/containers/child/currentSharePrincipalPolicy.js +83 -0
- package/workflows/containers/child/currentSharePrincipalPolicy.js.map +1 -0
- package/workflows/containers/child/mutationSubmit.js +1 -1
- package/workflows/containers/child/mutationSubmit.js.map +1 -1
- package/workflows/containers/child/runtimeCurrentGroupShare.js +82 -0
- package/workflows/containers/child/runtimeCurrentGroupShare.js.map +1 -0
- package/workflows/containers/child/share.js +1 -14
- package/workflows/containers/child/share.js.map +1 -1
- package/workflows/containers/child/shareProjection.js +15 -0
- package/workflows/containers/child/shareProjection.js.map +1 -0
- package/workflows/containers/mutationResponse.js +1 -1
- package/workflows/containers/mutationResponse.js.map +1 -1
- package/workflows/documents/purge.d.ts +3 -0
- package/workflows/documents/purge.js +13 -0
- package/workflows/documents/purge.js.map +1 -1
- package/workflows/documents/sync.js +2 -0
- package/workflows/documents/sync.js.map +1 -1
- package/workflows/documents/syncFailures.js +2 -2
- package/workflows/documents/syncFailures.js.map +1 -1
- package/workflows/documents/syncPolicyRepair.js +15 -13
- package/workflows/documents/syncPolicyRepair.js.map +1 -1
- package/workflows/organizations/initialPrincipalCurrentPublication.js +2 -0
- package/workflows/organizations/initialPrincipalCurrentPublication.js.map +1 -1
- package/workflows/organizations/loadPolicyHistoryDetails.js +31 -32
- package/workflows/organizations/loadPolicyHistoryDetails.js.map +1 -1
- package/workflows/organizations/organizationPolicyHistoryDetails.js +37 -15
- package/workflows/organizations/organizationPolicyHistoryDetails.js.map +1 -1
- package/workflows/organizations/organizationPolicyHistoryVerification.js +56 -69
- package/workflows/organizations/organizationPolicyHistoryVerification.js.map +1 -1
- package/workflows/organizations/policyHistoryCache.js +5 -2
- package/workflows/organizations/policyHistoryCache.js.map +1 -1
- package/workflows/organizations/policyHistoryTypes.d.ts +1 -0
- package/workflows/organizations/policyHistoryTypes.js.map +1 -1
- package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js +4 -1
- package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js.map +1 -1
- package/workflows/principals/loadRecoveredPrincipalHistoryPage.d.ts +0 -1
- package/workflows/principals/loadRecoveredPrincipalHistoryPage.js +1 -2
- package/workflows/principals/loadRecoveredPrincipalHistoryPage.js.map +1 -1
- package/workflows/principals/policyRepair.js +38 -0
- package/workflows/principals/policyRepair.js.map +1 -0
- package/workflows/principals/policyRepairBudget.d.ts +2 -2
- package/workflows/principals/policyRepairBudget.js +3 -3
- package/workflows/principals/policyRepairBudget.js.map +1 -1
- package/workflows/principals/principalHistoryRecoveryPrefix.js +4 -0
- package/workflows/principals/principalHistoryRecoveryPrefix.js.map +1 -1
- package/workflows/principals/principalRecoveryLocalPreference.js +3 -2
- package/workflows/principals/principalRecoveryLocalPreference.js.map +1 -1
- package/workflows/principals/publicPrincipalHistoryPage.js +1 -0
- package/workflows/principals/publicPrincipalHistoryPage.js.map +1 -1
- package/workflows/principals/publicPrincipalHistoryProgress.js +1 -0
- package/workflows/principals/publicPrincipalHistoryProgress.js.map +1 -1
- package/workflows/principals/publicPrincipalHistoryTypes.d.ts +2 -0
- package/workflows/principals/publicPrincipalHistoryTypes.js.map +1 -1
- package/workflows/principals/publicProjectionPrincipal.js +1 -0
- package/workflows/principals/publicProjectionPrincipal.js.map +1 -1
- package/workflows/principals/recoverPrincipalHistoryPage.js +2 -1
- package/workflows/principals/recoverPrincipalHistoryPage.js.map +1 -1
- package/workflows/principals/recoverPrincipalPolicyHistory.js +1 -0
- package/workflows/principals/recoverPrincipalPolicyHistory.js.map +1 -1
- package/workflows/principals/recoverPublicPrincipalHistory.js +2 -0
- package/workflows/principals/recoverPublicPrincipalHistory.js.map +1 -1
- package/workflows/principals/runtimePolicyRecovery.js +2 -1
- package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
- package/workflows/principals/selectPublicPrincipalHistory.js +21 -15
- package/workflows/principals/selectPublicPrincipalHistory.js.map +1 -1
- package/workflows/sync/remoteResetPrincipalScope.js +6 -0
- package/workflows/sync/remoteResetPrincipalScope.js.map +1 -1
- package/data/keyingProjectionVerification/principalPolicySnapshotVerification.js +0 -208
- package/data/keyingProjectionVerification/principalPolicySnapshotVerification.js.map +0 -1
- package/data/keyingProjectionVerification/snapshotVerificationCache.js +0 -39
- package/data/keyingProjectionVerification/snapshotVerificationCache.js.map +0 -1
- package/workflows/containers/child/policyRepair.js +0 -23
- package/workflows/containers/child/policyRepair.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadRecoveredPrincipalHistoryPage.js","sourceRoot":"","sources":["loadRecoveredPrincipalHisto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AAC,YAAY,CAAC,aAAa;QACjD,WAAW,EAAE,OAAO,CAAC,YAAY,CAAC,WAAW;KAC9C,EACD,OAAO,CACR,CAAC;IACF,mCAAmC,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM;QACT,MAAM,IAAI,uBAAuB,CAC/B,oBAAoB,EACpB,4DAA4D,CAC7D,CAAC;IACJ,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9D,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,QAAQ,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;AAC9C,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicyHistoryReferenceProof,\n type PrincipalPolicyStateChainEntry,\n verifyPrincipalPolicyHistoryReferences,\n} from \"@tearleads/crypto\";\nimport {\n isPrincipalPolicyStateChainEntryResponse,\n type PrincipalPolicyStateChainEntryResponse,\n} from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalPolicyCheckpoint } from \"../../data/persistence/keyingCheckpointPersistence\";\nimport { loadPrincipalHistoryReference } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport { principalHistoryEvidenceScopeId } from \"../../data/principals/principalHistoryPrefixProtection\";\nimport { ownPrincipalHistoryProtection } from \"../../data/principals/principalHistoryProtection\";\nimport { loadVerifiedPrincipalHistoryPrefix } from \"./principalHistoryRecoveryPrefix\";\nimport { PrincipalHistoryEvidenceUnavailableError } from \"./principalHistoryRecoveryReferences\";\nimport {\n PrincipalHistoryRecoveryRaceError,\n type RecoverPrincipalPolicyHistoryOptions,\n} from \"./principalHistoryRecoveryTypes\";\nimport { principalHistoryVerificationContext } from \"./principalHistoryRecoveryVerification\";\n\nexport const PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE = 32;\n\nexport interface RecoveredPrincipalHistoryPage {\n /** Ascending entries, with the immediate predecessor kept separately for diffs. */\n readonly entries: readonly PrincipalPolicyStateChainEntryResponse[];\n readonly predecessor: PrincipalPolicyStateChainEntryResponse | null;\n readonly nextBeforeVersion: number | null;\n}\n\n/** Read a bounded historical window from an already recovered, exact private root. */\nexport async function loadRecoveredPrincipalHistoryPage(\n options: RecoverPrincipalPolicyHistoryOptions,\n beforeVersion = options.expectedHead.version + 1,\n): Promise<RecoveredPrincipalHistoryPage> {\n const owned = {\n ...options,\n expectedHead: structuredClone(options.expectedHead),\n protection: ownPrincipalHistoryProtection(options.protection),\n };\n try {\n return await readPage(owned, beforeVersion);\n } finally {\n owned.protection.localKey.fill(0);\n }\n}\n\nasync function readPage(\n options: RecoverPrincipalPolicyHistoryOptions,\n beforeVersion: number,\n): Promise<RecoveredPrincipalHistoryPage> {\n if (\n !Number.isSafeInteger(beforeVersion) ||\n beforeVersion <= 1 ||\n beforeVersion > options.expectedHead.version + 1\n )\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"Principal history page cursor is outside the selected history\",\n );\n const current = () => !options.signal?.aborted && options.stillCurrent();\n assertProjectionVerificationCurrent(current);\n const { scopeId, history } = await restoreReadRoot(options, current);\n const checkpoint = await loadPrincipalPolicyCheckpoint(\n options.execSql,\n options.expectedHead.principalType,\n options.expectedHead.principalId,\n );\n if (checkpoint && checkpoint.version > options.expectedHead.version)\n throw new PrincipalHistoryRecoveryRaceError(\n \"Principal checkpoint advanced beyond the selected display history\",\n );\n const load = (version: number) =>\n loadPageReference({\n execSql: options.execSql,\n scopeId,\n history,\n version,\n });\n const firstVersion = Math.max(\n 1,\n beforeVersion - PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE,\n );\n const references: PrincipalPolicyHistoryReferenceProof[] = [];\n for (\n let version = Math.max(1, firstVersion - 1);\n version < beforeVersion;\n version += 1\n ) {\n assertProjectionVerificationCurrent(current);\n references.push(await load(version));\n }\n const checkpointReference = checkpoint\n ? await load(checkpoint.version)\n : undefined;\n if (\n checkpointReference &&\n checkpointReference.reference.stateHash !== checkpoint?.stateHash\n )\n throw new KeyingVerificationError(\n \"equivocation\",\n \"Principal history page conflicts with its durable checkpoint\",\n );\n const selected = await verifyPrincipalPolicyHistoryReferences({\n history,\n references,\n checkpointReference,\n });\n if (!selected.ok)\n throw new PrincipalHistoryEvidenceUnavailableError(selected.error);\n await assertDisplayCheckpointCurrent(options, checkpoint);\n assertProjectionVerificationCurrent(current);\n // These exact rows passed inclusion and commitment verification above. Keep\n // their display-only server timestamps, which the private current strips.\n const retained = references.map(({ entry }) => responseEntry(entry));\n return {\n entries: retained.filter(\n ({ state }) =>\n state.version >= firstVersion && state.version < beforeVersion,\n ),\n predecessor:\n retained.find(({ state }) => state.version === firstVersion - 1) ?? null,\n nextBeforeVersion: firstVersion > 1 ? firstVersion : null,\n };\n}\n\nasync function assertDisplayCheckpointCurrent(\n options: RecoverPrincipalPolicyHistoryOptions,\n checkpoint: Awaited<ReturnType<typeof loadPrincipalPolicyCheckpoint>>,\n) {\n const latest = await loadPrincipalPolicyCheckpoint(\n options.execSql,\n options.expectedHead.principalType,\n options.expectedHead.principalId,\n );\n if (\n latest?.version !== checkpoint?.version ||\n latest?.stateHash !== checkpoint?.stateHash\n )\n throw new PrincipalHistoryRecoveryRaceError(\n \"Principal checkpoint changed while reading display history\",\n );\n}\n\nasync function loadPageReference(\n input: Parameters<typeof loadPrincipalHistoryReference>[0],\n) {\n try {\n return await loadPrincipalHistoryReference(input);\n } catch (error) {\n if (error instanceof KeyingVerificationError)\n throw new PrincipalHistoryEvidenceUnavailableError(error);\n throw error;\n }\n}\n\nfunction responseEntry(\n entry: PrincipalPolicyStateChainEntry,\n): PrincipalPolicyStateChainEntryResponse {\n if (!isPrincipalPolicyStateChainEntryResponse(entry))\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Principal history display metadata is unavailable\",\n );\n return entry;\n}\n\nasync function restoreReadRoot(\n options: RecoverPrincipalPolicyHistoryOptions,\n current: () => boolean,\n) {\n const normalized = {\n ...options,\n protection: {\n ...options.protection,\n context: principalHistoryVerificationContext(options),\n },\n };\n const scopeId = await principalHistoryEvidenceScopeId({\n organizationId: options.organizationId,\n head: options.expectedHead,\n protection: normalized.protection,\n });\n const prefix = await loadVerifiedPrincipalHistoryPrefix(\n normalized,\n {\n principalType: options.expectedHead.principalType,\n principalId: options.expectedHead.principalId,\n },\n scopeId,\n );\n assertProjectionVerificationCurrent(current);\n if (!prefix)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Principal history page requires a recovered private prefix\",\n );\n const finished = prefix.verifier.finish(options.expectedHead);\n if (!finished.ok) throw finished.error;\n return { scopeId, history: finished.value };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"loadRecoveredPrincipalHistoryPage.js","sourceRoot":"","sources":["loadRecoveredPrincipalHistoryPage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAGvB,sCAAsC,GACvC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wCAAwC,EACxC,mCAAmC,GAEpC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAC;AAC3G,OAAO,EAAE,+BAA+B,EAAE,MAAM,wDAAwD,CAAC;AACzG,OAAO,EAAE,6BAA6B,EAAE,MAAM,kDAAkD,CAAC;AACjG,OAAO,EAAE,kCAAkC,EAAE,MAAM,kCAAkC,CAAC;AACtF,OAAO,EAAE,wCAAwC,EAAE,MAAM,sCAAsC,CAAC;AAChG,OAAO,EACL,iCAAiC,GAElC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,mCAAmC,EAAE,MAAM,wCAAwC,CAAC;AAS7F,sFAAsF;AACtF,MAAM,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AuB,CAC/B,oBAAoB,EACpB,mDAAmD,CACpD,CAAC;IACJ,OAAO,KAAK,CAAC;AACf,CAAC;AAED,KAAK,UAAU,eAAe,CAC5B,OAA6C,EAC7C,OAAsB;IAEtB,MAAM,UAAU,GAAG;QACjB,GAAG,OAAO;QACV,UAAU,EAAE;YACV,GAAG,OAAO,CAAC,UAAU;YACrB,OAAO,EAAE,mCAAmC,CAAC,OAAO,CAAC;SACtD;KACF,CAAC;IACF,MAAM,OAAO,GAAG,MAAM,+BAA+B,CAAC;QACpD,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,IAAI,EAAE,OAAO,CAAC,YAAY;QAC1B,UAAU,EAAE,UAAU,CAAC,UAAU;KAClC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,kCAAkC,CACrD,UAAU,EACV;QACE,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC,aAAa;QACjD,WAAW,EAAE,OAAO,CAAC,YAAY,CAAC,WAAW;KAC9C,EACD,OAAO,CACR,CAAC;IACF,mCAAmC,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM;QACT,MAAM,IAAI,uBAAuB,CAC/B,oBAAoB,EACpB,4DAA4D,CAC7D,CAAC;IACJ,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9D,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,QAAQ,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;AAC9C,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicyHistoryReferenceProof,\n type PrincipalPolicyStateChainEntry,\n verifyPrincipalPolicyHistoryReferences,\n} from \"@tearleads/crypto\";\nimport {\n isPrincipalPolicyStateChainEntryResponse,\n PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE,\n type PrincipalPolicyStateChainEntryResponse,\n} from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalPolicyCheckpoint } from \"../../data/persistence/keyingCheckpointPersistence\";\nimport { loadPrincipalHistoryReference } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport { principalHistoryEvidenceScopeId } from \"../../data/principals/principalHistoryPrefixProtection\";\nimport { ownPrincipalHistoryProtection } from \"../../data/principals/principalHistoryProtection\";\nimport { loadVerifiedPrincipalHistoryPrefix } from \"./principalHistoryRecoveryPrefix\";\nimport { PrincipalHistoryEvidenceUnavailableError } from \"./principalHistoryRecoveryReferences\";\nimport {\n PrincipalHistoryRecoveryRaceError,\n type RecoverPrincipalPolicyHistoryOptions,\n} from \"./principalHistoryRecoveryTypes\";\nimport { principalHistoryVerificationContext } from \"./principalHistoryRecoveryVerification\";\n\nexport interface RecoveredPrincipalHistoryPage {\n /** Ascending entries, with the immediate predecessor kept separately for diffs. */\n readonly entries: readonly PrincipalPolicyStateChainEntryResponse[];\n readonly predecessor: PrincipalPolicyStateChainEntryResponse | null;\n readonly nextBeforeVersion: number | null;\n}\n\n/** Read a bounded historical window from an already recovered, exact private root. */\nexport async function loadRecoveredPrincipalHistoryPage(\n options: RecoverPrincipalPolicyHistoryOptions,\n beforeVersion = options.expectedHead.version + 1,\n): Promise<RecoveredPrincipalHistoryPage> {\n const owned = {\n ...options,\n expectedHead: structuredClone(options.expectedHead),\n protection: ownPrincipalHistoryProtection(options.protection),\n };\n try {\n return await readPage(owned, beforeVersion);\n } finally {\n owned.protection.localKey.fill(0);\n }\n}\n\nasync function readPage(\n options: RecoverPrincipalPolicyHistoryOptions,\n beforeVersion: number,\n): Promise<RecoveredPrincipalHistoryPage> {\n if (\n !Number.isSafeInteger(beforeVersion) ||\n beforeVersion <= 1 ||\n beforeVersion > options.expectedHead.version + 1\n )\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"Principal history page cursor is outside the selected history\",\n );\n const current = () => !options.signal?.aborted && options.stillCurrent();\n assertProjectionVerificationCurrent(current);\n const { scopeId, history } = await restoreReadRoot(options, current);\n const checkpoint = await loadPrincipalPolicyCheckpoint(\n options.execSql,\n options.expectedHead.principalType,\n options.expectedHead.principalId,\n );\n if (checkpoint && checkpoint.version > options.expectedHead.version)\n throw new PrincipalHistoryRecoveryRaceError(\n \"Principal checkpoint advanced beyond the selected display history\",\n );\n const load = (version: number) =>\n loadPageReference({\n execSql: options.execSql,\n scopeId,\n history,\n version,\n });\n const firstVersion = Math.max(\n 1,\n beforeVersion - PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE,\n );\n const references: PrincipalPolicyHistoryReferenceProof[] = [];\n for (\n let version = Math.max(1, firstVersion - 1);\n version < beforeVersion;\n version += 1\n ) {\n assertProjectionVerificationCurrent(current);\n references.push(await load(version));\n }\n const checkpointReference = checkpoint\n ? await load(checkpoint.version)\n : undefined;\n if (\n checkpointReference &&\n checkpointReference.reference.stateHash !== checkpoint?.stateHash\n )\n throw new KeyingVerificationError(\n \"equivocation\",\n \"Principal history page conflicts with its durable checkpoint\",\n );\n const selected = await verifyPrincipalPolicyHistoryReferences({\n history,\n references,\n checkpointReference,\n });\n if (!selected.ok)\n throw new PrincipalHistoryEvidenceUnavailableError(selected.error);\n await assertDisplayCheckpointCurrent(options, checkpoint);\n assertProjectionVerificationCurrent(current);\n // These exact rows passed inclusion and commitment verification above. Keep\n // their display-only server timestamps, which the private current strips.\n const retained = references.map(({ entry }) => responseEntry(entry));\n return {\n entries: retained.filter(\n ({ state }) =>\n state.version >= firstVersion && state.version < beforeVersion,\n ),\n predecessor:\n retained.find(({ state }) => state.version === firstVersion - 1) ?? null,\n nextBeforeVersion: firstVersion > 1 ? firstVersion : null,\n };\n}\n\nasync function assertDisplayCheckpointCurrent(\n options: RecoverPrincipalPolicyHistoryOptions,\n checkpoint: Awaited<ReturnType<typeof loadPrincipalPolicyCheckpoint>>,\n) {\n const latest = await loadPrincipalPolicyCheckpoint(\n options.execSql,\n options.expectedHead.principalType,\n options.expectedHead.principalId,\n );\n if (\n latest?.version !== checkpoint?.version ||\n latest?.stateHash !== checkpoint?.stateHash\n )\n throw new PrincipalHistoryRecoveryRaceError(\n \"Principal checkpoint changed while reading display history\",\n );\n}\n\nasync function loadPageReference(\n input: Parameters<typeof loadPrincipalHistoryReference>[0],\n) {\n try {\n return await loadPrincipalHistoryReference(input);\n } catch (error) {\n if (error instanceof KeyingVerificationError)\n throw new PrincipalHistoryEvidenceUnavailableError(error);\n throw error;\n }\n}\n\nfunction responseEntry(\n entry: PrincipalPolicyStateChainEntry,\n): PrincipalPolicyStateChainEntryResponse {\n if (!isPrincipalPolicyStateChainEntryResponse(entry))\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Principal history display metadata is unavailable\",\n );\n return entry;\n}\n\nasync function restoreReadRoot(\n options: RecoverPrincipalPolicyHistoryOptions,\n current: () => boolean,\n) {\n const normalized = {\n ...options,\n protection: {\n ...options.protection,\n context: principalHistoryVerificationContext(options),\n },\n };\n const scopeId = await principalHistoryEvidenceScopeId({\n organizationId: options.organizationId,\n head: options.expectedHead,\n protection: normalized.protection,\n });\n const prefix = await loadVerifiedPrincipalHistoryPrefix(\n normalized,\n {\n principalType: options.expectedHead.principalType,\n principalId: options.expectedHead.principalId,\n },\n scopeId,\n );\n assertProjectionVerificationCurrent(current);\n if (!prefix)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Principal history page requires a recovered private prefix\",\n );\n const finished = prefix.verifier.finish(options.expectedHead);\n if (!finished.ok) throw finished.error;\n return { scopeId, history: finished.value };\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { KeyingVerificationError } from "../../internal/crypto/index.js";
|
|
2
|
+
import { PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT } from "../../internal/validators/util/index.js";
|
|
3
|
+
import { verifiedPrincipalPolicyContainsReference } from "../../data/keyingProjectionVerification/principalPolicyCache.js";
|
|
4
|
+
import { assertProjectionVerificationCurrent, } from "../../data/keyingProjectionVerification/types.js";
|
|
5
|
+
/** Recover advisory repair heads; the consuming mutation still admits its pins. */
|
|
6
|
+
export async function recoverPrincipalPolicyRepair(input) {
|
|
7
|
+
// Keep the requested organization and lifetime stable across host callbacks.
|
|
8
|
+
input = { ...input };
|
|
9
|
+
const resolve = input.warmReferencedPrincipalPolicies?.resolveReference;
|
|
10
|
+
if (!input.heads?.length || !resolve || input.stillCurrent?.() === false)
|
|
11
|
+
return false;
|
|
12
|
+
if (input.heads.length > PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT)
|
|
13
|
+
throw new RangeError("Principal policy repair head limit exceeded");
|
|
14
|
+
const heads = input.heads.map((head) => ({ ...head }));
|
|
15
|
+
const recoveryBatch = {};
|
|
16
|
+
const recovered = [];
|
|
17
|
+
const assertCurrent = () => {
|
|
18
|
+
assertProjectionVerificationCurrent(input.stillCurrent);
|
|
19
|
+
for (const result of recovered)
|
|
20
|
+
assertProjectionVerificationCurrent(result.stillCurrent);
|
|
21
|
+
};
|
|
22
|
+
for (const reference of heads) {
|
|
23
|
+
assertCurrent();
|
|
24
|
+
const result = await resolve({
|
|
25
|
+
recoveryBatch,
|
|
26
|
+
organizationId: input.organizationId,
|
|
27
|
+
reference: { ...reference },
|
|
28
|
+
stillCurrent: input.stillCurrent,
|
|
29
|
+
});
|
|
30
|
+
recovered.push(result);
|
|
31
|
+
assertCurrent();
|
|
32
|
+
if (result.organizationId !== input.organizationId ||
|
|
33
|
+
!verifiedPrincipalPolicyContainsReference(result.policy, reference))
|
|
34
|
+
throw new KeyingVerificationError("object_mismatch", "Recovered repair evidence does not contain the requested scoped head");
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=policyRepair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policyRepair.js","sourceRoot":"","sources":["policyRepair.ts"],"names":[],"mappings":"AAAA,OAAO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,GAAG,SAAS,EAAE;YAC3B,YAAY,EAAE,KAAK,CAAC,YAAY;SACjC,CAAC,CAAC;QACH,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,aAAa,EAAE,CAAC;QAChB,IACE,MAAM,CAAC,cAAc,KAAK,KAAK,CAAC,cAAc;YAC9C,CAAC,wCAAwC,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;YAEnE,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,sEAAsE,CACvE,CAAC;IACN,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport type { ReferencedPrincipalStateResponse } from \"@tearleads/validators/response\";\nimport { PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT } from \"@tearleads/validators/util\";\nimport { verifiedPrincipalPolicyContainsReference } from \"../../data/keyingProjectionVerification/principalPolicyCache\";\nimport {\n assertProjectionVerificationCurrent,\n type ReferencedPrincipalPolicyWarmer,\n type ResolvedPrincipalPolicyEvidence,\n} from \"../../data/keyingProjectionVerification/types\";\n\n/** Recover advisory repair heads; the consuming mutation still admits its pins. */\nexport async function recoverPrincipalPolicyRepair(input: {\n readonly heads: readonly ReferencedPrincipalStateResponse[] | undefined;\n readonly organizationId: string;\n readonly warmReferencedPrincipalPolicies?:\n | ReferencedPrincipalPolicyWarmer\n | undefined;\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<boolean> {\n // Keep the requested organization and lifetime stable across host callbacks.\n input = { ...input };\n const resolve = input.warmReferencedPrincipalPolicies?.resolveReference;\n if (!input.heads?.length || !resolve || input.stillCurrent?.() === false)\n return false;\n if (input.heads.length > PRINCIPAL_POLICY_REPAIR_HEAD_LIMIT)\n throw new RangeError(\"Principal policy repair head limit exceeded\");\n const heads = input.heads.map((head) => ({ ...head }));\n const recoveryBatch = {};\n const recovered: ResolvedPrincipalPolicyEvidence[] = [];\n const assertCurrent = () => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n for (const result of recovered)\n assertProjectionVerificationCurrent(result.stillCurrent);\n };\n for (const reference of heads) {\n assertCurrent();\n const result = await resolve({\n recoveryBatch,\n organizationId: input.organizationId,\n reference: { ...reference },\n stillCurrent: input.stillCurrent,\n });\n recovered.push(result);\n assertCurrent();\n if (\n result.organizationId !== input.organizationId ||\n !verifiedPrincipalPolicyContainsReference(result.policy, reference)\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Recovered repair evidence does not contain the requested scoped head\",\n );\n }\n return true;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReferencedPrincipalStateResponse } from "../../internal/validators/response/index.js";
|
|
2
2
|
/** Bounded repair of paged stale-policy replies; identical pages never loop. */
|
|
3
3
|
export declare class PrincipalPolicyRepairBudget {
|
|
4
4
|
private attempts;
|
|
5
5
|
private readonly seen;
|
|
6
|
-
take(
|
|
6
|
+
take(references: readonly ReferencedPrincipalStateResponse[] | undefined): boolean;
|
|
7
7
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
export class PrincipalPolicyRepairBudget {
|
|
3
3
|
attempts = 0;
|
|
4
4
|
seen = new Set();
|
|
5
|
-
take(
|
|
6
|
-
if (!
|
|
5
|
+
take(references) {
|
|
6
|
+
if (!references?.length || this.attempts >= 16)
|
|
7
7
|
return false;
|
|
8
|
-
const heads =
|
|
8
|
+
const heads = references.map((head) => `${head.principalType}:${head.principalId}:${head.stateHash}`);
|
|
9
9
|
if (heads.every((head) => this.seen.has(head)))
|
|
10
10
|
return false;
|
|
11
11
|
this.attempts++;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policyRepairBudget.js","sourceRoot":"","sources":["policyRepairBudget.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,MAAM,OAAO,2BAA2B;IAC9B,QAAQ,GAAG,CAAC,CAAC;IACJ,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE1C,IAAI,
|
|
1
|
+
{"version":3,"file":"policyRepairBudget.js","sourceRoot":"","sources":["policyRepairBudget.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,MAAM,OAAO,2BAA2B;IAC9B,QAAQ,GAAG,CAAC,CAAC;IACJ,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE1C,IAAI,CACF,UAAmE;QAEnE,IAAI,CAAC,UAAU,EAAE,MAAM,IAAI,IAAI,CAAC,QAAQ,IAAI,EAAE;YAAE,OAAO,KAAK,CAAC;QAC7D,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAC1B,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,SAAS,EAAE,CACxE,CAAC;QACF,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7D,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import type { ReferencedPrincipalStateResponse } from \"@tearleads/validators/response\";\n\n/** Bounded repair of paged stale-policy replies; identical pages never loop. */\nexport class PrincipalPolicyRepairBudget {\n private attempts = 0;\n private readonly seen = new Set<string>();\n\n take(\n references: readonly ReferencedPrincipalStateResponse[] | undefined,\n ): boolean {\n if (!references?.length || this.attempts >= 16) return false;\n const heads = references.map(\n (head) => `${head.principalType}:${head.principalId}:${head.stateHash}`,\n );\n if (heads.every((head) => this.seen.has(head))) return false;\n this.attempts++;\n for (const head of heads) this.seen.add(head);\n return true;\n }\n}\n"]}
|
|
@@ -56,7 +56,11 @@ export async function publishReusablePrincipalHistoryPrefix(options, scopeId, ve
|
|
|
56
56
|
const sealed = await verifier.exportProgress(await principalHistoryPrefixProtection(options.protection, prefix));
|
|
57
57
|
if (!sealed.ok)
|
|
58
58
|
throw sealed.error;
|
|
59
|
+
const history = verifier.finish(options.expectedHead);
|
|
60
|
+
if (!history.ok)
|
|
61
|
+
throw history.error;
|
|
59
62
|
await savePrincipalHistoryPrefix({
|
|
63
|
+
indexRootHash: history.value.indexRootHash,
|
|
60
64
|
execSql: options.execSql,
|
|
61
65
|
prefix: { ...prefix, progress: sealed.value },
|
|
62
66
|
stillCurrent: () => !options.signal?.aborted && options.stillCurrent(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalHistoryRecoveryPrefix.js","sourceRoot":"","sources":["principalHistoryRecoveryPrefix.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,qCAAqC,EACrC,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kCAAkC,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,0DAA0D,CAAC;AAClE,OAAO,EAAE,gCAAgC,EAAE,MAAM,wDAAwD,CAAC;AAC1G,OAAO,EAAE,iCAAiC,EAAE,MAAM,uDAAuD,CAAC;AAG1G,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,OAAmE,EACnE,YAAyC,EACzC,OAAe;IAMf,MAAM,KAAK,GAAG,MAAM,0BAA0B,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzE,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,GAAG,IAAI,CAAC;IACd,CAAC;I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HistoryInput,\n type PrincipalPolicyHistoryVerifier,\n type ReferencedPrincipalHead,\n restorePrincipalPolicyHistoryVerifier,\n serializeKeyingCanonicalJson,\n} from \"@tearleads/crypto\";\nimport { isReferencedPrincipalStateResponse } from \"@tearleads/validators/response\";\nimport {\n discardPrincipalHistoryPrefix,\n loadPrincipalHistoryPrefix,\n savePrincipalHistoryPrefix,\n} from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport { principalHistoryPrefixProtection } from \"../../data/principals/principalHistoryPrefixProtection\";\nimport { parsePrincipalHistoryStageCurrent } from \"../../data/principals/principalHistoryStageProtection\";\nimport type { RecoverPrincipalPolicyHistoryOptions } from \"./principalHistoryRecoveryTypes\";\n\nexport async function loadVerifiedPrincipalHistoryPrefix(\n options: Omit<RecoverPrincipalPolicyHistoryOptions, \"expectedHead\">,\n historyInput: PrincipalPolicyHistoryInput,\n scopeId: string,\n): Promise<{\n verifier: PrincipalPolicyHistoryVerifier;\n head: ReferencedPrincipalHead;\n current: PrincipalPolicyPageCurrent;\n} | null> {\n const saved = await loadPrincipalHistoryPrefix(options.execSql, scopeId);\n if (!saved) return null;\n let head: unknown;\n try {\n head = JSON.parse(saved.headJson);\n } catch {\n head = null;\n }\n if (\n saved.organizationId === options.organizationId &&\n isReferencedPrincipalStateResponse(head) &&\n head.principalType === historyInput.principalType &&\n head.principalId === historyInput.principalId &&\n head.version === saved.version\n ) {\n const restored = await restorePrincipalPolicyHistoryVerifier(\n historyInput,\n saved.progress,\n await principalHistoryPrefixProtection(options.protection, saved),\n );\n const current = parsePrincipalHistoryStageCurrent({\n currentJson: saved.currentJson,\n afterVersion: saved.version - 1,\n });\n if (restored.ok && restored.value.finish(head).ok && current)\n return { verifier: restored.value, head, current };\n }\n await discardPrincipalHistoryPrefix({\n execSql: options.execSql,\n prefix: saved,\n stillCurrent: () => !options.signal?.aborted && options.stillCurrent(),\n });\n return null;\n}\n\nexport async function restoreReusablePrincipalHistoryPrefix(\n options: RecoverPrincipalPolicyHistoryOptions,\n historyInput: PrincipalPolicyHistoryInput,\n scopeId: string,\n) {\n const prefix = await loadVerifiedPrincipalHistoryPrefix(\n options,\n historyInput,\n scopeId,\n );\n if (!prefix || prefix.head.version > options.expectedHead.version)\n return null;\n if (\n prefix.head.version < options.expectedHead.version ||\n prefix.verifier.finish(options.expectedHead).ok\n )\n return { ...prefix, version: prefix.head.version };\n // An incompatible target cannot erase an independently valid local hint.\n return null;\n}\n\n/** The verifier must use stable empty selection/checkpoint inputs. */\nexport async function publishReusablePrincipalHistoryPrefix(\n options: RecoverPrincipalPolicyHistoryOptions,\n scopeId: string,\n verifier: PrincipalPolicyHistoryVerifier,\n current: PrincipalPolicyPageCurrent,\n): Promise<void> {\n const prefix = {\n scopeId,\n organizationId: options.organizationId,\n version: options.expectedHead.version,\n headJson: serializeKeyingCanonicalJson({ ...options.expectedHead }),\n currentJson: JSON.stringify(current),\n };\n const sealed = await verifier.exportProgress(\n await principalHistoryPrefixProtection(options.protection, prefix),\n );\n if (!sealed.ok) throw sealed.error;\n await savePrincipalHistoryPrefix({\n execSql: options.execSql,\n prefix: { ...prefix, progress: sealed.value },\n stillCurrent: () => !options.signal?.aborted && options.stillCurrent(),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"principalHistoryRecoveryPrefix.js","sourceRoot":"","sources":["principalHistoryRecoveryPrefix.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,qCAAqC,EACrC,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kCAAkC,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,0DAA0D,CAAC;AAClE,OAAO,EAAE,gCAAgC,EAAE,MAAM,wDAAwD,CAAC;AAC1G,OAAO,EAAE,iCAAiC,EAAE,MAAM,uDAAuD,CAAC;AAG1G,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,OAAmE,EACnE,YAAyC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OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACtD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,OAAO,CAAC,KAAK,CAAC;IACrC,MAAM,0BAA0B,CAAC;QAC/B,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,aAAa;QAC1C,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,EAAE;QAC7C,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE;KACvE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport {\n type PrincipalPolicyHistoryInput,\n type PrincipalPolicyHistoryVerifier,\n type ReferencedPrincipalHead,\n restorePrincipalPolicyHistoryVerifier,\n serializeKeyingCanonicalJson,\n} from \"@tearleads/crypto\";\nimport { isReferencedPrincipalStateResponse } from \"@tearleads/validators/response\";\nimport {\n discardPrincipalHistoryPrefix,\n loadPrincipalHistoryPrefix,\n savePrincipalHistoryPrefix,\n} from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport { principalHistoryPrefixProtection } from \"../../data/principals/principalHistoryPrefixProtection\";\nimport { parsePrincipalHistoryStageCurrent } from \"../../data/principals/principalHistoryStageProtection\";\nimport type { RecoverPrincipalPolicyHistoryOptions } from \"./principalHistoryRecoveryTypes\";\n\nexport async function loadVerifiedPrincipalHistoryPrefix(\n options: Omit<RecoverPrincipalPolicyHistoryOptions, \"expectedHead\">,\n historyInput: PrincipalPolicyHistoryInput,\n scopeId: string,\n): Promise<{\n verifier: PrincipalPolicyHistoryVerifier;\n head: ReferencedPrincipalHead;\n current: PrincipalPolicyPageCurrent;\n} | null> {\n const saved = await loadPrincipalHistoryPrefix(options.execSql, scopeId);\n if (!saved) return null;\n let head: unknown;\n try {\n head = JSON.parse(saved.headJson);\n } catch {\n head = null;\n }\n if (\n saved.organizationId === options.organizationId &&\n isReferencedPrincipalStateResponse(head) &&\n head.principalType === historyInput.principalType &&\n head.principalId === historyInput.principalId &&\n head.version === saved.version\n ) {\n const restored = await restorePrincipalPolicyHistoryVerifier(\n historyInput,\n saved.progress,\n await principalHistoryPrefixProtection(options.protection, saved),\n );\n const current = parsePrincipalHistoryStageCurrent({\n currentJson: saved.currentJson,\n afterVersion: saved.version - 1,\n });\n if (restored.ok && restored.value.finish(head).ok && current)\n return { verifier: restored.value, head, current };\n }\n await discardPrincipalHistoryPrefix({\n execSql: options.execSql,\n prefix: saved,\n stillCurrent: () => !options.signal?.aborted && options.stillCurrent(),\n });\n return null;\n}\n\nexport async function restoreReusablePrincipalHistoryPrefix(\n options: RecoverPrincipalPolicyHistoryOptions,\n historyInput: PrincipalPolicyHistoryInput,\n scopeId: string,\n) {\n const prefix = await loadVerifiedPrincipalHistoryPrefix(\n options,\n historyInput,\n scopeId,\n );\n if (!prefix || prefix.head.version > options.expectedHead.version)\n return null;\n if (\n prefix.head.version < options.expectedHead.version ||\n prefix.verifier.finish(options.expectedHead).ok\n )\n return { ...prefix, version: prefix.head.version };\n // An incompatible target cannot erase an independently valid local hint.\n return null;\n}\n\n/** The verifier must use stable empty selection/checkpoint inputs. */\nexport async function publishReusablePrincipalHistoryPrefix(\n options: RecoverPrincipalPolicyHistoryOptions,\n scopeId: string,\n verifier: PrincipalPolicyHistoryVerifier,\n current: PrincipalPolicyPageCurrent,\n): Promise<void> {\n const prefix = {\n scopeId,\n organizationId: options.organizationId,\n version: options.expectedHead.version,\n headJson: serializeKeyingCanonicalJson({ ...options.expectedHead }),\n currentJson: JSON.stringify(current),\n };\n const sealed = await verifier.exportProgress(\n await principalHistoryPrefixProtection(options.protection, prefix),\n );\n if (!sealed.ok) throw sealed.error;\n const history = verifier.finish(options.expectedHead);\n if (!history.ok) throw history.error;\n await savePrincipalHistoryPrefix({\n indexRootHash: history.value.indexRootHash,\n execSql: options.execSql,\n prefix: { ...prefix, progress: sealed.value },\n stillCurrent: () => !options.signal?.aborted && options.stillCurrent(),\n });\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { principalHeadMatchesReference } from "../../data/principals/organizatio
|
|
|
4
4
|
import { PrincipalHistoryRecoveryRaceError } from "./principalHistoryRecoveryTypes.js";
|
|
5
5
|
import { recoverWithPrincipalOutageFallback } from "./principalRecoveryOutage.js";
|
|
6
6
|
/** Reuse exact current artifacts, or a proved historical page within a newer prefix. */
|
|
7
|
-
export async function recoverWithPrincipalLocalPreference(recover, options, preferLocalCurrent) {
|
|
7
|
+
export async function recoverWithPrincipalLocalPreference(recover, options, preferLocalCurrent, allowHistoricalReference = false) {
|
|
8
8
|
if (preferLocalCurrent && !options.offline) {
|
|
9
9
|
try {
|
|
10
10
|
const local = await recover({
|
|
@@ -12,7 +12,8 @@ export async function recoverWithPrincipalLocalPreference(recover, options, pref
|
|
|
12
12
|
offline: true,
|
|
13
13
|
});
|
|
14
14
|
assertProjectionVerificationCurrent(options.stillCurrent);
|
|
15
|
-
if (
|
|
15
|
+
if (allowHistoricalReference ||
|
|
16
|
+
options.historyPage ||
|
|
16
17
|
principalHeadMatchesReference(local.policy.state, options.reference))
|
|
17
18
|
return local;
|
|
18
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalRecoveryLocalPreference.js","sourceRoot":"","sources":["principalRecoveryLocalPreference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EAAE,iCAAiC,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,kCAAkC,EAAE,MAAM,2BAA2B,CAAC;AAG/E,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,mCAAmC,CACvD,OAAmD,EACnD,OAAkE,EAClE,kBAA2B;
|
|
1
|
+
{"version":3,"file":"principalRecoveryLocalPreference.js","sourceRoot":"","sources":["principalRecoveryLocalPreference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EAAE,iCAAiC,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,kCAAkC,EAAE,MAAM,2BAA2B,CAAC;AAG/E,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,mCAAmC,CACvD,OAAmD,EACnD,OAAkE,EAClE,kBAA2B,EAC3B,wBAAwB,GAAG,KAAK;IAEhC,IAAI,kBAAkB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3C,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC;gBAC1B,GAAG,OAAO;gBACV,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;YACH,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC1D,IACE,wBAAwB;gBACxB,OAAO,CAAC,WAAW;gBACnB,6BAA6B,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC;gBAEpE,OAAO,KAAK,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC1D,IACE,CAAC,CAAC,KAAK,YAAY,iCAAiC,CAAC;gBACrD,CAAC,CACC,KAAK,YAAY,uBAAuB;oBACxC,KAAK,CAAC,IAAI,KAAK,oBAAoB,CACpC;gBAED,MAAM,KAAK,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,kCAAkC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport { PrincipalHistoryRecoveryRaceError } from \"./principalHistoryRecoveryTypes\";\nimport { recoverWithPrincipalOutageFallback } from \"./principalRecoveryOutage\";\nimport type { recoverScopedPrincipalPolicyHistory } from \"./recoverScopedPrincipalPolicyHistory\";\n\n/** Reuse exact current artifacts, or a proved historical page within a newer prefix. */\nexport async function recoverWithPrincipalLocalPreference(\n recover: typeof recoverScopedPrincipalPolicyHistory,\n options: Parameters<typeof recoverScopedPrincipalPolicyHistory>[0],\n preferLocalCurrent: boolean,\n allowHistoricalReference = false,\n) {\n if (preferLocalCurrent && !options.offline) {\n try {\n const local = await recover({\n ...options,\n offline: true,\n });\n assertProjectionVerificationCurrent(options.stillCurrent);\n if (\n allowHistoricalReference ||\n options.historyPage ||\n principalHeadMatchesReference(local.policy.state, options.reference)\n )\n return local;\n } catch (error) {\n assertProjectionVerificationCurrent(options.stillCurrent);\n if (\n !(error instanceof PrincipalHistoryRecoveryRaceError) &&\n !(\n error instanceof KeyingVerificationError &&\n error.code === \"missing_dependency\"\n )\n )\n throw error;\n }\n }\n return recoverWithPrincipalOutageFallback(recover, options);\n}\n"]}
|
|
@@ -67,6 +67,7 @@ export async function appendPublicPrincipalHistoryPage(input, progress, page) {
|
|
|
67
67
|
execSql: input.execSql,
|
|
68
68
|
stage: saved,
|
|
69
69
|
evidence: await preparePrincipalHistoryEvidencePage({
|
|
70
|
+
indexRootHash: appended.value.indexRootHash,
|
|
70
71
|
scopeId: progress.scopeId,
|
|
71
72
|
organizationId: input.organizationId,
|
|
72
73
|
entries,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicPrincipalHistoryPage.js","sourceRoot":"","sources":["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AAO,EAAE,QAAQ,CAAC,OAAO;YACzB,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,OAAO;YACP,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;SACjC,CAAC;QACF,gBAAgB,EAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,IAAI,IAAI;QAClD,YAAY;KACb,CAAC,CAAC;IACH,mCAAmC,CAAC,YAAY,CAAC,CAAC;IAClD,OAAO;QACL,GAAG,QAAQ;QACX,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,KAAK;QACL,kBAAkB,EAAE,+BAA+B,CACjD,QAAQ,CAAC,kBAAkB,EAC3B,UAAU,CACX;QACD,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicyStateChainEntry,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicySnapshotPageResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { preparePrincipalHistoryEvidencePage } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport { savePrincipalHistoryStage } from \"../../data/persistence/principalHistoryStagePersistence\";\nimport { principalHistoryStageProtection } from \"../../data/principals/principalHistoryStageProtection\";\nimport { collectPrincipalPolicySignerPublicKeys } from \"./policyVerification\";\nimport {\n loadPublicHistoryAuthority,\n publicHistoryAuthorityJson,\n publicHistoryAuthorityReference,\n} from \"./publicPrincipalHistoryAuthority\";\nimport type {\n PublicPrincipalHistoryOptions,\n PublicPrincipalHistoryProgress,\n} from \"./publicPrincipalHistoryTypes\";\n\nexport class PublicPrincipalHistoryPrefixDisconnectedError extends Error {\n constructor(readonly verificationError: KeyingVerificationError) {\n super(verificationError.message);\n this.name = \"PublicPrincipalHistoryPrefixDisconnectedError\";\n }\n}\n\nfunction assertPublicAuthorityScope(\n input: PublicPrincipalHistoryOptions,\n entries: readonly PrincipalPolicyStateChainEntry[],\n): void {\n if (\n input.strictAdmins &&\n entries.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 \"Public Admins history must contain only direct admin users\",\n );\n if (\n entries.some(\n ({ state }) =>\n state.externalAuthority &&\n state.externalAuthority.principalId !== input.authorityGroupId,\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Public history cites an authority outside its directory binding\",\n );\n}\n\nexport async function appendPublicPrincipalHistoryPage(\n input: PublicPrincipalHistoryOptions,\n progress: PublicPrincipalHistoryProgress,\n page: PrincipalPolicySnapshotPageResponse,\n): Promise<PublicPrincipalHistoryProgress> {\n const stillCurrent = () => !input.signal?.aborted && input.stillCurrent();\n const complete = page.historyPage.nextAfterVersion === null;\n const entries = [...page.previousStates];\n if (complete)\n entries.push({\n state: page.currentState,\n projection: page.currentProjection,\n grants: page.currentGrants,\n });\n assertPublicAuthorityScope(input, entries);\n const keys = await collectPrincipalPolicySignerPublicKeys({\n bundle: page,\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n });\n if (\"error\" in keys)\n throw new KeyingVerificationError(\n keys.error === \"not-found\" ? \"missing_dependency\" : \"signer_mismatch\",\n \"Public history signer identity is unavailable or mismatched\",\n );\n const references = entries.flatMap(({ state }) =>\n state.externalAuthority ? [state.externalAuthority] : [],\n );\n const externalAuthority = await loadPublicHistoryAuthority(input, references);\n assertProjectionVerificationCurrent(stillCurrent);\n const appended = await progress.verifier.append({\n entries,\n signerPublicKeys: keys.signerPublicKeys,\n ...(externalAuthority ? { externalAuthority } : {}),\n });\n if (!appended.ok) {\n if (appended.error.code === \"stale_predecessor\")\n throw new PublicPrincipalHistoryPrefixDisconnectedError(appended.error);\n throw appended.error;\n }\n const row = {\n id: progress.id,\n organizationId: input.organizationId,\n currentJson: publicHistoryAuthorityJson(\n publicHistoryAuthorityReference(progress.authorityReference, references),\n ),\n afterVersion: appended.value.throughVersion - (complete ? 1 : 0),\n complete,\n };\n const sealed = await progress.verifier.exportProgress(\n await principalHistoryStageProtection(\n input.protection,\n input.source.head,\n row,\n ),\n );\n if (!sealed.ok) throw sealed.error;\n const saved = { ...row, progress: sealed.value };\n await savePrincipalHistoryStage({\n execSql: input.execSql,\n stage: saved,\n evidence: await preparePrincipalHistoryEvidencePage({\n scopeId: progress.scopeId,\n organizationId: input.organizationId,\n entries,\n nodes: appended.value.indexNodes,\n }),\n previousProgress: progress.saved?.progress ?? null,\n stillCurrent,\n });\n assertProjectionVerificationCurrent(stillCurrent);\n return {\n ...progress,\n afterVersion: row.afterVersion,\n saved,\n authorityReference: publicHistoryAuthorityReference(\n progress.authorityReference,\n references,\n ),\n completedHead: complete ? input.source.head : null,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"publicPrincipalHistoryPage.js","sourceRoot":"","sources":["publicPrincipalHistoryPage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,mCAAmC,EAAE,MAAM,4DAA4D,CAAC;AACjH,OAAO,EAAE,yBAAyB,EAAE,MAAM,yDAAyD,CAAC;AACpG,OAAO,EAAE,+BAA+B,EAAE,MAAM,uDAAuD,CAAC;AACxG,OAAO,EAAE,sCAAsC,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,mCAAmC,CAAC;AAM3C,MAAM,OAAO,6CAA8C,SAAQ,KAAK;IACjD;IAArB,YAAqB,iBAA0C;QAC7D,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QADd,sBAAiB,GAAjB,iBAAiB,CAAyB;QAE7D,IAAI,CAAC,IAAI,GAAG,+CAA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icyStateChainEntry,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicySnapshotPageResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { preparePrincipalHistoryEvidencePage } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport { savePrincipalHistoryStage } from \"../../data/persistence/principalHistoryStagePersistence\";\nimport { principalHistoryStageProtection } from \"../../data/principals/principalHistoryStageProtection\";\nimport { collectPrincipalPolicySignerPublicKeys } from \"./policyVerification\";\nimport {\n loadPublicHistoryAuthority,\n publicHistoryAuthorityJson,\n publicHistoryAuthorityReference,\n} from \"./publicPrincipalHistoryAuthority\";\nimport type {\n PublicPrincipalHistoryOptions,\n PublicPrincipalHistoryProgress,\n} from \"./publicPrincipalHistoryTypes\";\n\nexport class PublicPrincipalHistoryPrefixDisconnectedError extends Error {\n constructor(readonly verificationError: KeyingVerificationError) {\n super(verificationError.message);\n this.name = \"PublicPrincipalHistoryPrefixDisconnectedError\";\n }\n}\n\nfunction assertPublicAuthorityScope(\n input: PublicPrincipalHistoryOptions,\n entries: readonly PrincipalPolicyStateChainEntry[],\n): void {\n if (\n input.strictAdmins &&\n entries.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 \"Public Admins history must contain only direct admin users\",\n );\n if (\n entries.some(\n ({ state }) =>\n state.externalAuthority &&\n state.externalAuthority.principalId !== input.authorityGroupId,\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Public history cites an authority outside its directory binding\",\n );\n}\n\nexport async function appendPublicPrincipalHistoryPage(\n input: PublicPrincipalHistoryOptions,\n progress: PublicPrincipalHistoryProgress,\n page: PrincipalPolicySnapshotPageResponse,\n): Promise<PublicPrincipalHistoryProgress> {\n const stillCurrent = () => !input.signal?.aborted && input.stillCurrent();\n const complete = page.historyPage.nextAfterVersion === null;\n const entries = [...page.previousStates];\n if (complete)\n entries.push({\n state: page.currentState,\n projection: page.currentProjection,\n grants: page.currentGrants,\n });\n assertPublicAuthorityScope(input, entries);\n const keys = await collectPrincipalPolicySignerPublicKeys({\n bundle: page,\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n });\n if (\"error\" in keys)\n throw new KeyingVerificationError(\n keys.error === \"not-found\" ? \"missing_dependency\" : \"signer_mismatch\",\n \"Public history signer identity is unavailable or mismatched\",\n );\n const references = entries.flatMap(({ state }) =>\n state.externalAuthority ? [state.externalAuthority] : [],\n );\n const externalAuthority = await loadPublicHistoryAuthority(input, references);\n assertProjectionVerificationCurrent(stillCurrent);\n const appended = await progress.verifier.append({\n entries,\n signerPublicKeys: keys.signerPublicKeys,\n ...(externalAuthority ? { externalAuthority } : {}),\n });\n if (!appended.ok) {\n if (appended.error.code === \"stale_predecessor\")\n throw new PublicPrincipalHistoryPrefixDisconnectedError(appended.error);\n throw appended.error;\n }\n const row = {\n id: progress.id,\n organizationId: input.organizationId,\n currentJson: publicHistoryAuthorityJson(\n publicHistoryAuthorityReference(progress.authorityReference, references),\n ),\n afterVersion: appended.value.throughVersion - (complete ? 1 : 0),\n complete,\n };\n const sealed = await progress.verifier.exportProgress(\n await principalHistoryStageProtection(\n input.protection,\n input.source.head,\n row,\n ),\n );\n if (!sealed.ok) throw sealed.error;\n const saved = { ...row, progress: sealed.value };\n await savePrincipalHistoryStage({\n execSql: input.execSql,\n stage: saved,\n evidence: await preparePrincipalHistoryEvidencePage({\n indexRootHash: appended.value.indexRootHash,\n scopeId: progress.scopeId,\n organizationId: input.organizationId,\n entries,\n nodes: appended.value.indexNodes,\n }),\n previousProgress: progress.saved?.progress ?? null,\n stillCurrent,\n });\n assertProjectionVerificationCurrent(stillCurrent);\n return {\n ...progress,\n afterVersion: row.afterVersion,\n saved,\n authorityReference: publicHistoryAuthorityReference(\n progress.authorityReference,\n references,\n ),\n completedHead: complete ? input.source.head : null,\n };\n}\n"]}
|
|
@@ -167,6 +167,7 @@ export async function publishPublicPrincipalHistoryPrefix(input, progress, histo
|
|
|
167
167
|
: await rejectedCompletedPrefix(input, progress, history));
|
|
168
168
|
const stillCurrent = () => !input.signal?.aborted && input.stillCurrent();
|
|
169
169
|
await savePrincipalHistoryPrefix({
|
|
170
|
+
indexRootHash: history.indexRootHash,
|
|
170
171
|
execSql: input.execSql,
|
|
171
172
|
prefix: { ...prefix, progress: sealed.value },
|
|
172
173
|
stillCurrent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicPrincipalHistoryProgress.js","sourceRoot":"","sources":["publicPrincipalHistoryProgress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oCAAoC,EACpC,uBAAuB,EACvB,qCAAqC,EACrC,4BAA4B,EAE5B,sCAAsC,GACvC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kCAAkC,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAC;AAC3G,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAE1B,0BAA0B,GAC3B,MAAM,0DAA0D,CAAC;AAClE,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,yDAAyD,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,GACjC,MAAM,wDAAwD,CAAC;AAChE,OAAO,EACL,uBAAuB,EACvB,+BAA+B,GAChC,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EACL,sCAAsC,EACtC,2BAA2B,EAC3B,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,mCAAmC,CAAC;AAM3C,KAAK,UAAU,mBAAmB,CAChC,KAAoC,EACpC,OAAe,EACf,EAAU,EACV,MAAqC;IAErC,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;IAC/B,MAAM,YAAY,GAAG;QACn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Z,cAAc;QACd,CAAC,QAAQ,CAAC,YAAY;YACpB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,MAAM,uBAAuB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/D,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;IAC1E,MAAM,0BAA0B,CAAC;QAC/B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,EAAE;QAC7C,YAAY;QACZ,cAAc,EAAE,QAAQ;KACzB,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,KAAK;QAChB,MAAM,4BAA4B,CAChC,KAAK,CAAC,OAAO,EACb,QAAQ,CAAC,KAAK,EACd,YAAY,CACb,CAAC;AACN,CAAC","sourcesContent":["import {\n createPrincipalPolicyHistoryVerifier,\n KeyingVerificationError,\n restorePrincipalPolicyHistoryVerifier,\n serializeKeyingCanonicalJson,\n type VerifiedPrincipalPolicyHistory,\n verifyPrincipalPolicyHistoryReferences,\n} from \"@tearleads/crypto\";\nimport { isReferencedPrincipalStateResponse } from \"@tearleads/validators/response\";\nimport { loadPrincipalHistoryReference } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport {\n discardPrincipalHistoryPrefix,\n loadPrincipalHistoryPrefix,\n type PrincipalHistoryPrefix,\n savePrincipalHistoryPrefix,\n} from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport {\n discardPrincipalHistoryStage,\n loadPrincipalHistoryStage,\n} from \"../../data/persistence/principalHistoryStagePersistence\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport {\n principalHistoryEvidenceScopeId,\n principalHistoryPrefixProtection,\n} from \"../../data/principals/principalHistoryPrefixProtection\";\nimport {\n principalHistoryStageId,\n principalHistoryStageProtection,\n} from \"../../data/principals/principalHistoryStageProtection\";\nimport {\n PublicHistoryAuthorityUnavailableError,\n parsePublicHistoryAuthority,\n publicHistoryAuthorityJson,\n validatePublicHistoryAuthority,\n} from \"./publicPrincipalHistoryAuthority\";\nimport type {\n PublicPrincipalHistoryOptions,\n PublicPrincipalHistoryProgress,\n} from \"./publicPrincipalHistoryTypes\";\n\nasync function restorePublicPrefix(\n input: PublicPrincipalHistoryOptions,\n scopeId: string,\n id: string,\n prefix: PrincipalHistoryPrefix | null,\n): Promise<PublicPrincipalHistoryProgress | null> {\n const head = input.source.head;\n const historyInput = {\n principalType: head.principalType,\n principalId: head.principalId,\n };\n const current = () => !input.signal?.aborted && input.stillCurrent();\n if (prefix) {\n const authorityReference = parsePublicHistoryAuthority(\n input,\n prefix.currentJson,\n );\n let prefixHead: unknown;\n try {\n prefixHead = JSON.parse(prefix.headJson);\n } catch {\n prefixHead = null;\n }\n if (\n prefix.organizationId === input.organizationId &&\n authorityReference !== undefined &&\n isReferencedPrincipalStateResponse(prefixHead) &&\n prefixHead.principalId === head.principalId &&\n prefixHead.principalType === head.principalType &&\n prefixHead.version === prefix.version\n ) {\n const restored = await restorePrincipalPolicyHistoryVerifier(\n historyInput,\n prefix.progress,\n await principalHistoryPrefixProtection(input.protection, prefix),\n );\n if (restored.ok && restored.value.finish(prefixHead).ok) {\n await validatePublicHistoryAuthority(input, authorityReference, prefix);\n return {\n id,\n scopeId,\n verifier: restored.value,\n completedHead: prefixHead.version >= head.version ? prefixHead : null,\n afterVersion: Math.min(prefixHead.version, head.version - 1),\n saved: null,\n cachedPrefix: prefix,\n authorityReference,\n };\n }\n }\n if (!input.offline)\n await discardPrincipalHistoryPrefix({\n execSql: input.execSql,\n prefix,\n stillCurrent: current,\n });\n }\n return null;\n}\n\nexport async function restorePublicPrincipalHistoryProgress(\n input: PublicPrincipalHistoryOptions,\n allowReuse: boolean,\n): Promise<PublicPrincipalHistoryProgress> {\n const head = input.source.head;\n const historyInput = {\n principalType: head.principalType,\n principalId: head.principalId,\n };\n const scopeId = await principalHistoryEvidenceScopeId({\n organizationId: input.organizationId,\n head,\n protection: input.protection,\n });\n const id = await principalHistoryStageId(\n input.organizationId,\n head,\n input.protection.context,\n );\n const current = () => !input.signal?.aborted && input.stillCurrent();\n const saved = await loadPrincipalHistoryStage(input.execSql, id);\n if (saved) {\n const authorityReference = parsePublicHistoryAuthority(\n input,\n saved.currentJson,\n );\n if (\n allowReuse &&\n saved.organizationId === input.organizationId &&\n authorityReference !== undefined\n ) {\n const restored = await restorePrincipalPolicyHistoryVerifier(\n historyInput,\n saved.progress,\n await principalHistoryStageProtection(input.protection, head, saved),\n );\n if (restored.ok && (!saved.complete || restored.value.finish(head).ok)) {\n await validatePublicHistoryAuthority(input, authorityReference);\n return {\n id,\n scopeId,\n verifier: restored.value,\n completedHead: saved.complete ? head : null,\n afterVersion: saved.afterVersion,\n saved,\n cachedPrefix: null,\n authorityReference,\n };\n }\n }\n if (!input.offline)\n await discardPrincipalHistoryStage(input.execSql, saved, current);\n }\n if (allowReuse) {\n const prefix = await restorePublicPrefix(\n input,\n scopeId,\n id,\n await loadPrincipalHistoryPrefix(input.execSql, scopeId),\n );\n if (prefix) return prefix;\n }\n return {\n id,\n scopeId,\n verifier: createPrincipalPolicyHistoryVerifier(historyInput),\n completedHead: null,\n afterVersion: 0,\n saved: null,\n cachedPrefix: null,\n authorityReference: null,\n };\n}\n\n/** A resumed stage may finish after the reader that rejected the prefix exits. */\nasync function rejectedCompletedPrefix(\n input: PublicPrincipalHistoryOptions,\n progress: PublicPrincipalHistoryProgress,\n history: VerifiedPrincipalPolicyHistory,\n): Promise<PrincipalHistoryPrefix | null> {\n const candidate = await loadPrincipalHistoryPrefix(\n input.execSql,\n progress.scopeId,\n );\n if (!candidate || candidate.version <= history.currentEntry.state.version)\n return null;\n try {\n const cached = await restorePublicPrefix(\n input,\n progress.scopeId,\n progress.id,\n candidate,\n );\n if (!cached?.completedHead) return null;\n const finished = cached.verifier.finish(cached.completedHead);\n if (!finished.ok) throw finished.error;\n const proof = await loadPrincipalHistoryReference({\n execSql: input.execSql,\n scopeId: progress.scopeId,\n history: finished.value,\n version: input.source.head.version,\n });\n const verified = await verifyPrincipalPolicyHistoryReferences({\n history: finished.value,\n references: [proof],\n });\n if (!verified.ok) throw verified.error;\n return principalHeadMatchesReference(proof.entry.state, input.source.head)\n ? null\n : candidate;\n } catch (error) {\n if (\n error instanceof KeyingVerificationError ||\n error instanceof PublicHistoryAuthorityUnavailableError\n )\n return candidate;\n throw error;\n }\n}\n\nexport async function publishPublicPrincipalHistoryPrefix(\n input: PublicPrincipalHistoryOptions,\n progress: PublicPrincipalHistoryProgress,\n history: VerifiedPrincipalPolicyHistory,\n rejectedPrefix: PrincipalHistoryPrefix | null,\n): Promise<void> {\n const state = history.currentEntry.state;\n const head = {\n principalType: state.principalType,\n principalId: state.principalId,\n version: state.version,\n stateHash: state.stateHash,\n keyEpoch: state.keyEpoch,\n keyFingerprint: state.keyFingerprint,\n };\n const prefix = {\n scopeId: progress.scopeId,\n organizationId: input.organizationId,\n version: head.version,\n headJson: serializeKeyingCanonicalJson(head),\n currentJson: publicHistoryAuthorityJson(progress.authorityReference),\n };\n const sealed = await progress.verifier.exportProgress(\n await principalHistoryPrefixProtection(input.protection, prefix),\n );\n if (!sealed.ok) throw sealed.error;\n const rejected =\n rejectedPrefix ??\n (progress.cachedPrefix\n ? null\n : await rejectedCompletedPrefix(input, progress, history));\n const stillCurrent = () => !input.signal?.aborted && input.stillCurrent();\n await savePrincipalHistoryPrefix({\n execSql: input.execSql,\n prefix: { ...prefix, progress: sealed.value },\n stillCurrent,\n rejectedPrefix: rejected,\n });\n if (progress.saved)\n await discardPrincipalHistoryStage(\n input.execSql,\n progress.saved,\n stillCurrent,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"publicPrincipalHistoryProgress.js","sourceRoot":"","sources":["publicPrincipalHistoryProgress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL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AM,CAAC,KAAK,EAAE;QAC7C,YAAY;QACZ,cAAc,EAAE,QAAQ;KACzB,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,KAAK;QAChB,MAAM,4BAA4B,CAChC,KAAK,CAAC,OAAO,EACb,QAAQ,CAAC,KAAK,EACd,YAAY,CACb,CAAC;AACN,CAAC","sourcesContent":["import {\n createPrincipalPolicyHistoryVerifier,\n KeyingVerificationError,\n restorePrincipalPolicyHistoryVerifier,\n serializeKeyingCanonicalJson,\n type VerifiedPrincipalPolicyHistory,\n verifyPrincipalPolicyHistoryReferences,\n} from \"@tearleads/crypto\";\nimport { isReferencedPrincipalStateResponse } from \"@tearleads/validators/response\";\nimport { loadPrincipalHistoryReference } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport {\n discardPrincipalHistoryPrefix,\n loadPrincipalHistoryPrefix,\n type PrincipalHistoryPrefix,\n savePrincipalHistoryPrefix,\n} from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport {\n discardPrincipalHistoryStage,\n loadPrincipalHistoryStage,\n} from \"../../data/persistence/principalHistoryStagePersistence\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport {\n principalHistoryEvidenceScopeId,\n principalHistoryPrefixProtection,\n} from \"../../data/principals/principalHistoryPrefixProtection\";\nimport {\n principalHistoryStageId,\n principalHistoryStageProtection,\n} from \"../../data/principals/principalHistoryStageProtection\";\nimport {\n PublicHistoryAuthorityUnavailableError,\n parsePublicHistoryAuthority,\n publicHistoryAuthorityJson,\n validatePublicHistoryAuthority,\n} from \"./publicPrincipalHistoryAuthority\";\nimport type {\n PublicPrincipalHistoryOptions,\n PublicPrincipalHistoryProgress,\n} from \"./publicPrincipalHistoryTypes\";\n\nasync function restorePublicPrefix(\n input: PublicPrincipalHistoryOptions,\n scopeId: string,\n id: string,\n prefix: PrincipalHistoryPrefix | null,\n): Promise<PublicPrincipalHistoryProgress | null> {\n const head = input.source.head;\n const historyInput = {\n principalType: head.principalType,\n principalId: head.principalId,\n };\n const current = () => !input.signal?.aborted && input.stillCurrent();\n if (prefix) {\n const authorityReference = parsePublicHistoryAuthority(\n input,\n prefix.currentJson,\n );\n let prefixHead: unknown;\n try {\n prefixHead = JSON.parse(prefix.headJson);\n } catch {\n prefixHead = null;\n }\n if (\n prefix.organizationId === input.organizationId &&\n authorityReference !== undefined &&\n isReferencedPrincipalStateResponse(prefixHead) &&\n prefixHead.principalId === head.principalId &&\n prefixHead.principalType === head.principalType &&\n prefixHead.version === prefix.version\n ) {\n const restored = await restorePrincipalPolicyHistoryVerifier(\n historyInput,\n prefix.progress,\n await principalHistoryPrefixProtection(input.protection, prefix),\n );\n if (restored.ok && restored.value.finish(prefixHead).ok) {\n await validatePublicHistoryAuthority(input, authorityReference, prefix);\n return {\n id,\n scopeId,\n verifier: restored.value,\n completedHead: prefixHead.version >= head.version ? prefixHead : null,\n afterVersion: Math.min(prefixHead.version, head.version - 1),\n saved: null,\n cachedPrefix: prefix,\n authorityReference,\n };\n }\n }\n if (!input.offline)\n await discardPrincipalHistoryPrefix({\n execSql: input.execSql,\n prefix,\n stillCurrent: current,\n });\n }\n return null;\n}\n\nexport async function restorePublicPrincipalHistoryProgress(\n input: PublicPrincipalHistoryOptions,\n allowReuse: boolean,\n): Promise<PublicPrincipalHistoryProgress> {\n const head = input.source.head;\n const historyInput = {\n principalType: head.principalType,\n principalId: head.principalId,\n };\n const scopeId = await principalHistoryEvidenceScopeId({\n organizationId: input.organizationId,\n head,\n protection: input.protection,\n });\n const id = await principalHistoryStageId(\n input.organizationId,\n head,\n input.protection.context,\n );\n const current = () => !input.signal?.aborted && input.stillCurrent();\n const saved = await loadPrincipalHistoryStage(input.execSql, id);\n if (saved) {\n const authorityReference = parsePublicHistoryAuthority(\n input,\n saved.currentJson,\n );\n if (\n allowReuse &&\n saved.organizationId === input.organizationId &&\n authorityReference !== undefined\n ) {\n const restored = await restorePrincipalPolicyHistoryVerifier(\n historyInput,\n saved.progress,\n await principalHistoryStageProtection(input.protection, head, saved),\n );\n if (restored.ok && (!saved.complete || restored.value.finish(head).ok)) {\n await validatePublicHistoryAuthority(input, authorityReference);\n return {\n id,\n scopeId,\n verifier: restored.value,\n completedHead: saved.complete ? head : null,\n afterVersion: saved.afterVersion,\n saved,\n cachedPrefix: null,\n authorityReference,\n };\n }\n }\n if (!input.offline)\n await discardPrincipalHistoryStage(input.execSql, saved, current);\n }\n if (allowReuse) {\n const prefix = await restorePublicPrefix(\n input,\n scopeId,\n id,\n await loadPrincipalHistoryPrefix(input.execSql, scopeId),\n );\n if (prefix) return prefix;\n }\n return {\n id,\n scopeId,\n verifier: createPrincipalPolicyHistoryVerifier(historyInput),\n completedHead: null,\n afterVersion: 0,\n saved: null,\n cachedPrefix: null,\n authorityReference: null,\n };\n}\n\n/** A resumed stage may finish after the reader that rejected the prefix exits. */\nasync function rejectedCompletedPrefix(\n input: PublicPrincipalHistoryOptions,\n progress: PublicPrincipalHistoryProgress,\n history: VerifiedPrincipalPolicyHistory,\n): Promise<PrincipalHistoryPrefix | null> {\n const candidate = await loadPrincipalHistoryPrefix(\n input.execSql,\n progress.scopeId,\n );\n if (!candidate || candidate.version <= history.currentEntry.state.version)\n return null;\n try {\n const cached = await restorePublicPrefix(\n input,\n progress.scopeId,\n progress.id,\n candidate,\n );\n if (!cached?.completedHead) return null;\n const finished = cached.verifier.finish(cached.completedHead);\n if (!finished.ok) throw finished.error;\n const proof = await loadPrincipalHistoryReference({\n execSql: input.execSql,\n scopeId: progress.scopeId,\n history: finished.value,\n version: input.source.head.version,\n });\n const verified = await verifyPrincipalPolicyHistoryReferences({\n history: finished.value,\n references: [proof],\n });\n if (!verified.ok) throw verified.error;\n return principalHeadMatchesReference(proof.entry.state, input.source.head)\n ? null\n : candidate;\n } catch (error) {\n if (\n error instanceof KeyingVerificationError ||\n error instanceof PublicHistoryAuthorityUnavailableError\n )\n return candidate;\n throw error;\n }\n}\n\nexport async function publishPublicPrincipalHistoryPrefix(\n input: PublicPrincipalHistoryOptions,\n progress: PublicPrincipalHistoryProgress,\n history: VerifiedPrincipalPolicyHistory,\n rejectedPrefix: PrincipalHistoryPrefix | null,\n): Promise<void> {\n const state = history.currentEntry.state;\n const head = {\n principalType: state.principalType,\n principalId: state.principalId,\n version: state.version,\n stateHash: state.stateHash,\n keyEpoch: state.keyEpoch,\n keyFingerprint: state.keyFingerprint,\n };\n const prefix = {\n scopeId: progress.scopeId,\n organizationId: input.organizationId,\n version: head.version,\n headJson: serializeKeyingCanonicalJson(head),\n currentJson: publicHistoryAuthorityJson(progress.authorityReference),\n };\n const sealed = await progress.verifier.exportProgress(\n await principalHistoryPrefixProtection(input.protection, prefix),\n );\n if (!sealed.ok) throw sealed.error;\n const rejected =\n rejectedPrefix ??\n (progress.cachedPrefix\n ? null\n : await rejectedCompletedPrefix(input, progress, history));\n const stillCurrent = () => !input.signal?.aborted && input.stillCurrent();\n await savePrincipalHistoryPrefix({\n indexRootHash: history.indexRootHash,\n execSql: input.execSql,\n prefix: { ...prefix, progress: sealed.value },\n stillCurrent,\n rejectedPrefix: rejected,\n });\n if (progress.saved)\n await discardPrincipalHistoryStage(\n input.execSql,\n progress.saved,\n stillCurrent,\n );\n}\n"]}
|
|
@@ -7,6 +7,8 @@ import type { ExecSql } from "../../data/sqlite/sqlSchema.js";
|
|
|
7
7
|
import type { TrustedUserIdentityResolver } from "../../data/trustedUserIdentity/index.js";
|
|
8
8
|
export interface PublicPrincipalHistoryOptions {
|
|
9
9
|
readonly apiClient: Pick<ApiClient, "getProjectionPolicyHistoryPages">;
|
|
10
|
+
/** Terminal proof verification defers durable currency until all artifacts authenticate. */
|
|
11
|
+
readonly historicalProof?: boolean | undefined;
|
|
10
12
|
readonly source: PrincipalPolicyHistorySourceResponse;
|
|
11
13
|
readonly organizationId: string;
|
|
12
14
|
readonly execSql: ExecSql;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicPrincipalHistoryTypes.js","sourceRoot":"","sources":["publicPrincipalHistoryTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { ApiClient } from \"@tearleads/api-client\";\nimport type {\n PrincipalPolicyExternalAuthority,\n PrincipalPolicyHistoryProgressOptions,\n PrincipalPolicyHistoryVerifier,\n ReferencedPrincipalHead,\n VerifiedPrincipalPolicyHistory,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyHistorySourceResponse } from \"@tearleads/validators/response\";\nimport type { PrincipalHistoryPrefix } from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport type { PrincipalHistoryStage } from \"../../data/persistence/principalHistoryStagePersistence\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\n\nexport interface PublicPrincipalHistoryOptions {\n readonly apiClient: Pick<ApiClient, \"getProjectionPolicyHistoryPages\">;\n readonly source: PrincipalPolicyHistorySourceResponse;\n readonly organizationId: string;\n readonly execSql: ExecSql;\n readonly protection: PrincipalPolicyHistoryProgressOptions;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly stillCurrent: () => boolean;\n readonly signal?: AbortSignal | undefined;\n readonly offline?: boolean | undefined;\n /** Retry disposable evidence loss once from signatures, without reusing hints. */\n readonly replay?: boolean | undefined;\n readonly strictAdmins?: boolean | undefined;\n /** Already verified organization binding; included in the protected cache scope. */\n readonly authorityGroupId?: string | undefined;\n readonly loadExternalAuthority?:\n | ((\n references: readonly ReferencedPrincipalHead[],\n cachedPrefix?: boolean,\n ) => Promise<PrincipalPolicyExternalAuthority | undefined>)\n | undefined;\n}\n\nexport interface PublicPrincipalHistoryProgress {\n readonly id: string;\n readonly scopeId: string;\n readonly verifier: PrincipalPolicyHistoryVerifier;\n readonly completedHead: ReferencedPrincipalHead | null;\n readonly afterVersion: number;\n readonly saved: PrincipalHistoryStage | null;\n readonly cachedPrefix: PrincipalHistoryPrefix | null;\n readonly authorityReference: ReferencedPrincipalHead | null;\n}\n\n/** Public authorization only; caller must check directory binding and local pins. */\nexport interface RecoveredPublicPrincipalHistory {\n readonly scopeId: string;\n readonly history: VerifiedPrincipalPolicyHistory;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"publicPrincipalHistoryTypes.js","sourceRoot":"","sources":["publicPrincipalHistoryTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { ApiClient } from \"@tearleads/api-client\";\nimport type {\n PrincipalPolicyExternalAuthority,\n PrincipalPolicyHistoryProgressOptions,\n PrincipalPolicyHistoryVerifier,\n ReferencedPrincipalHead,\n VerifiedPrincipalPolicyHistory,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyHistorySourceResponse } from \"@tearleads/validators/response\";\nimport type { PrincipalHistoryPrefix } from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport type { PrincipalHistoryStage } from \"../../data/persistence/principalHistoryStagePersistence\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\n\nexport interface PublicPrincipalHistoryOptions {\n readonly apiClient: Pick<ApiClient, \"getProjectionPolicyHistoryPages\">;\n /** Terminal proof verification defers durable currency until all artifacts authenticate. */\n readonly historicalProof?: boolean | undefined;\n readonly source: PrincipalPolicyHistorySourceResponse;\n readonly organizationId: string;\n readonly execSql: ExecSql;\n readonly protection: PrincipalPolicyHistoryProgressOptions;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly stillCurrent: () => boolean;\n readonly signal?: AbortSignal | undefined;\n readonly offline?: boolean | undefined;\n /** Retry disposable evidence loss once from signatures, without reusing hints. */\n readonly replay?: boolean | undefined;\n readonly strictAdmins?: boolean | undefined;\n /** Already verified organization binding; included in the protected cache scope. */\n readonly authorityGroupId?: string | undefined;\n readonly loadExternalAuthority?:\n | ((\n references: readonly ReferencedPrincipalHead[],\n cachedPrefix?: boolean,\n ) => Promise<PrincipalPolicyExternalAuthority | undefined>)\n | undefined;\n}\n\nexport interface PublicPrincipalHistoryProgress {\n readonly id: string;\n readonly scopeId: string;\n readonly verifier: PrincipalPolicyHistoryVerifier;\n readonly completedHead: ReferencedPrincipalHead | null;\n readonly afterVersion: number;\n readonly saved: PrincipalHistoryStage | null;\n readonly cachedPrefix: PrincipalHistoryPrefix | null;\n readonly authorityReference: ReferencedPrincipalHead | null;\n}\n\n/** Public authorization only; caller must check directory binding and local pins. */\nexport interface RecoveredPublicPrincipalHistory {\n readonly scopeId: string;\n readonly history: VerifiedPrincipalPolicyHistory;\n}\n"]}
|
|
@@ -16,6 +16,7 @@ export async function selectPublicProjectionPrincipal(principal, references = pr
|
|
|
16
16
|
recovered: principal.recovered,
|
|
17
17
|
references: [options.source.head, ...references],
|
|
18
18
|
checkpoint,
|
|
19
|
+
deferCheckpointCheck: options.historicalProof,
|
|
19
20
|
includeGenesis: options.source.head.principalType === "organization",
|
|
20
21
|
stillCurrent: current,
|
|
21
22
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicProjectionPrincipal.js","sourceRoot":"","sources":["publicProjectionPrincipal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,wCAAwC,EAAE,MAAM,sCAAsC,CAAC;AAKhG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAS9E,uFAAuF;AACvF,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,SAAoC,EACpC,aAAiD,SAAS,CAAC,UAAU;IAErE,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;IAC9B,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,OAAO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KAAK,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CACvD,CAAC;IACF,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACrE,sBAAsB,CAAC,2CAA2C,CAAC,CAAC;IACtE,MAAM,SAAS,GAAG;QAChB,OAAO;QACP,UAAU,EAAE,eAAe,CAAC,QAAQ,CAAC;QACrC,SAAS,EAAE,MAAM,6BAA6B,CAAC,OAAO,CAAC;QACvD,QAAQ,EAAE,KAAK;KAChB,CAAC;IACF,MAAM,+BAA+B,CAAC,SAAS,CAAC,CAAC;IACjD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,8BAA8B,OAAO,EAAE,CACxC,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalPolicyCheckpoint } from \"../../data/persistence/keyingCheckpointPersistence\";\nimport { PrincipalHistoryEvidenceUnavailableError } from \"./principalHistoryRecoveryReferences\";\nimport type {\n PublicPrincipalHistoryOptions,\n RecoveredPublicPrincipalHistory,\n} from \"./publicPrincipalHistoryTypes\";\nimport { recoverPublicPrincipalHistory } from \"./recoverPublicPrincipalHistory\";\nimport { selectPublicPrincipalHistory } from \"./selectPublicPrincipalHistory\";\n\nexport interface PublicProjectionPrincipal {\n readonly options: PublicPrincipalHistoryOptions;\n readonly references: readonly ReferencedPrincipalHead[];\n recovered: RecoveredPublicPrincipalHistory;\n replayed: boolean;\n}\n\n/** The source head and every citation remain bound independently of a newer prefix. */\nexport async function selectPublicProjectionPrincipal(\n principal: PublicProjectionPrincipal,\n references: readonly ReferencedPrincipalHead[] = principal.references,\n) {\n const { options } = principal;\n const current = () => !options.signal?.aborted && options.stillCurrent();\n assertProjectionVerificationCurrent(current);\n const checkpoint = await loadPrincipalPolicyCheckpoint(\n options.execSql,\n options.source.head.principalType,\n options.source.head.principalId,\n );\n try {\n return await selectPublicPrincipalHistory({\n execSql: options.execSql,\n recovered: principal.recovered,\n references: [options.source.head, ...references],\n checkpoint,\n includeGenesis: options.source.head.principalType === \"organization\",\n stillCurrent: current,\n });\n } catch (error) {\n if (!(error instanceof PrincipalHistoryEvidenceUnavailableError))\n throw error;\n if (options.offline || principal.replayed) throw error.verificationError;\n principal.replayed = true;\n principal.recovered = await recoverPublicPrincipalHistory({\n ...options,\n replay: true,\n });\n return selectPublicProjectionPrincipal(principal, references);\n }\n}\n\nexport async function recoverPublicProjectionPrincipal(\n options: PublicPrincipalHistoryOptions,\n references: readonly ReferencedPrincipalHead[],\n): Promise<PublicProjectionPrincipal> {\n const selected = references.filter(\n (head) =>\n head.principalType === options.source.head.principalType &&\n head.principalId === options.source.head.principalId,\n );\n if (selected.some((head) => head.version > options.source.head.version))\n rejectPublicProjection(\"citation exceeds its supplied source head\");\n const principal = {\n options,\n references: structuredClone(selected),\n recovered: await recoverPublicPrincipalHistory(options),\n replayed: false,\n };\n await selectPublicProjectionPrincipal(principal);\n return principal;\n}\n\nexport function rejectPublicProjection(message: string): never {\n throw new KeyingVerificationError(\n \"object_mismatch\",\n `Public projection history: ${message}`,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"publicProjectionPrincipal.js","sourceRoot":"","sources":["publicProjectionPrincipal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,wCAAwC,EAAE,MAAM,sCAAsC,CAAC;AAKhG,OA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AAC;YACxD,GAAG,OAAO;YACV,MAAM,EAAE,IAAI;SACb,CAAC,CAAC;QACH,OAAO,+BAA+B,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,OAAsC,EACtC,UAA8C;IAE9C,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAChC,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,aAAa,KAAK,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa;QACxD,IAAI,CAAC,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CACvD,CAAC;IACF,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACrE,sBAAsB,CAAC,2CAA2C,CAAC,CAAC;IACtE,MAAM,SAAS,GAAG;QAChB,OAAO;QACP,UAAU,EAAE,eAAe,CAAC,QAAQ,CAAC;QACrC,SAAS,EAAE,MAAM,6BAA6B,CAAC,OAAO,CAAC;QACvD,QAAQ,EAAE,KAAK;KAChB,CAAC;IACF,MAAM,+BAA+B,CAAC,SAAS,CAAC,CAAC;IACjD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,8BAA8B,OAAO,EAAE,CACxC,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalPolicyCheckpoint } from \"../../data/persistence/keyingCheckpointPersistence\";\nimport { PrincipalHistoryEvidenceUnavailableError } from \"./principalHistoryRecoveryReferences\";\nimport type {\n PublicPrincipalHistoryOptions,\n RecoveredPublicPrincipalHistory,\n} from \"./publicPrincipalHistoryTypes\";\nimport { recoverPublicPrincipalHistory } from \"./recoverPublicPrincipalHistory\";\nimport { selectPublicPrincipalHistory } from \"./selectPublicPrincipalHistory\";\n\nexport interface PublicProjectionPrincipal {\n readonly options: PublicPrincipalHistoryOptions;\n readonly references: readonly ReferencedPrincipalHead[];\n recovered: RecoveredPublicPrincipalHistory;\n replayed: boolean;\n}\n\n/** The source head and every citation remain bound independently of a newer prefix. */\nexport async function selectPublicProjectionPrincipal(\n principal: PublicProjectionPrincipal,\n references: readonly ReferencedPrincipalHead[] = principal.references,\n) {\n const { options } = principal;\n const current = () => !options.signal?.aborted && options.stillCurrent();\n assertProjectionVerificationCurrent(current);\n const checkpoint = await loadPrincipalPolicyCheckpoint(\n options.execSql,\n options.source.head.principalType,\n options.source.head.principalId,\n );\n try {\n return await selectPublicPrincipalHistory({\n execSql: options.execSql,\n recovered: principal.recovered,\n references: [options.source.head, ...references],\n checkpoint,\n deferCheckpointCheck: options.historicalProof,\n includeGenesis: options.source.head.principalType === \"organization\",\n stillCurrent: current,\n });\n } catch (error) {\n if (!(error instanceof PrincipalHistoryEvidenceUnavailableError))\n throw error;\n if (options.offline || principal.replayed) throw error.verificationError;\n principal.replayed = true;\n principal.recovered = await recoverPublicPrincipalHistory({\n ...options,\n replay: true,\n });\n return selectPublicProjectionPrincipal(principal, references);\n }\n}\n\nexport async function recoverPublicProjectionPrincipal(\n options: PublicPrincipalHistoryOptions,\n references: readonly ReferencedPrincipalHead[],\n): Promise<PublicProjectionPrincipal> {\n const selected = references.filter(\n (head) =>\n head.principalType === options.source.head.principalType &&\n head.principalId === options.source.head.principalId,\n );\n if (selected.some((head) => head.version > options.source.head.version))\n rejectPublicProjection(\"citation exceeds its supplied source head\");\n const principal = {\n options,\n references: structuredClone(selected),\n recovered: await recoverPublicPrincipalHistory(options),\n replayed: false,\n };\n await selectPublicProjectionPrincipal(principal);\n return principal;\n}\n\nexport function rejectPublicProjection(message: string): never {\n throw new KeyingVerificationError(\n \"object_mismatch\",\n `Public projection history: ${message}`,\n );\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { KeyingVerificationError } from "../../internal/crypto/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE } from "../../internal/validators/response/index.js";
|
|
3
|
+
import { loadRecoveredPrincipalHistoryPage } from "./loadRecoveredPrincipalHistoryPage.js";
|
|
3
4
|
import { PrincipalHistoryEvidenceUnavailableError } from "./principalHistoryRecoveryReferences.js";
|
|
4
5
|
import { recoverPrincipalPolicyHistoryWithVersions } from "./recoverPrincipalPolicyHistory.js";
|
|
5
6
|
/** Disposable page proof loss may replay signed pages once online, preserving durable pins. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recoverPrincipalHistoryPage.js","sourceRoot":"","sources":["recoverPrincipalHistoryPage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"recoverPrincipalHistoryPage.js","sourceRoot":"","sources":["recoverPrincipalHistoryPage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,mCAAmC,EAAE,MAAM,gCAAgC,CAAC;AACrF,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,wCAAwC,EAAE,MAAM,sCAAsC,CAAC;AAEhG,OAAO,EAAE,yCAAyC,EAAE,MAAM,iCAAiC,CAAC;AAE5F,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAA6C,EAC7C,aAAqB;IAErB,IAAI,CAAC;QACH,OAAO,MAAM,iCAAiC,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACzE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,wCAAwC,CAAC;YAC9D,MAAM,KAAK,CAAC;QACd,sEAAsE;QACtE,4EAA4E;QAC5E,0EAA0E;QAC1E,IAAI,OAAO,CAAC,OAAO;YACjB,MAAM,IAAI,uBAAuB,CAC/B,oBAAoB,EACpB,gDAAgD,CACjD,CAAC;IACN,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CACpB,CAAC,EACD,aAAa,GAAG,mCAAmC,GAAG,CAAC,CACxD,CAAC;IACF,MAAM,yCAAyC,CAC7C,OAAO,EACP,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,aAAa,GAAG,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,CAC3E,CAAC;IACF,IAAI,CAAC;QACH,OAAO,MAAM,iCAAiC,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACzE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,YAAY,wCAAwC;YAC7D,CAAC,CAAC,KAAK,CAAC,iBAAiB;YACzB,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE } from \"@tearleads/validators/response\";\nimport { loadRecoveredPrincipalHistoryPage } from \"./loadRecoveredPrincipalHistoryPage\";\nimport { PrincipalHistoryEvidenceUnavailableError } from \"./principalHistoryRecoveryReferences\";\nimport type { RecoverPrincipalPolicyHistoryOptions } from \"./principalHistoryRecoveryTypes\";\nimport { recoverPrincipalPolicyHistoryWithVersions } from \"./recoverPrincipalPolicyHistory\";\n\n/** Disposable page proof loss may replay signed pages once online, preserving durable pins. */\nexport async function recoverPrincipalHistoryPage(\n options: RecoverPrincipalPolicyHistoryOptions,\n beforeVersion: number,\n) {\n try {\n return await loadRecoveredPrincipalHistoryPage(options, beforeVersion);\n } catch (error) {\n if (!(error instanceof PrincipalHistoryEvidenceUnavailableError))\n throw error;\n // A local-first display read must distinguish disposable proof damage\n // from a durable fork or an invalid caller citation, which are not wrapped.\n // Preserve that distinction so the online caller can replay signed pages.\n if (options.offline)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Principal history display proof is unavailable\",\n );\n }\n const first = Math.max(\n 1,\n beforeVersion - PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE - 1,\n );\n await recoverPrincipalPolicyHistoryWithVersions(\n options,\n Array.from({ length: beforeVersion - first }, (_, index) => first + index),\n );\n try {\n return await loadRecoveredPrincipalHistoryPage(options, beforeVersion);\n } catch (error) {\n throw error instanceof PrincipalHistoryEvidenceUnavailableError\n ? error.verificationError\n : error;\n }\n}\n"]}
|
|
@@ -101,6 +101,7 @@ async function acceptPage(input, stage, response) {
|
|
|
101
101
|
execSql: input.execSql,
|
|
102
102
|
stage: saved,
|
|
103
103
|
evidence: await preparePrincipalHistoryEvidencePage({
|
|
104
|
+
indexRootHash: appended.value.indexRootHash,
|
|
104
105
|
scopeId: stage.scopeId,
|
|
105
106
|
organizationId: input.organizationId,
|
|
106
107
|
entries,
|