@tearleads/client-sdk 0.1.15 → 0.1.17

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.
Files changed (244) hide show
  1. package/client/Tearleads.d.ts +2 -0
  2. package/client/Tearleads.js +1 -0
  3. package/client/Tearleads.js.map +1 -1
  4. package/client/index.d.ts +1 -1
  5. package/client/index.js.map +1 -1
  6. package/client/organizations/currentPrincipalMutations.js +96 -0
  7. package/client/organizations/currentPrincipalMutations.js.map +1 -0
  8. package/client/organizations/index.d.ts +4 -42
  9. package/client/organizations/index.js +17 -3
  10. package/client/organizations/index.js.map +1 -1
  11. package/client/organizations/organizationGroupHistory.js +44 -0
  12. package/client/organizations/organizationGroupHistory.js.map +1 -0
  13. package/client/organizations/organizationGroupNameHydration.js +14 -1
  14. package/client/organizations/organizationGroupNameHydration.js.map +1 -1
  15. package/client/organizations/organizationGroupPresentation.d.ts +1 -0
  16. package/client/organizations/organizationGroupPresentation.js +16 -2
  17. package/client/organizations/organizationGroupPresentation.js.map +1 -1
  18. package/client/organizations/organizationReadModels.d.ts +1 -1
  19. package/client/organizations/organizationReadModels.js +11 -1
  20. package/client/organizations/organizationReadModels.js.map +1 -1
  21. package/client/organizations/organizationsTypes.d.ts +50 -0
  22. package/client/organizations/organizationsTypes.js +2 -0
  23. package/client/organizations/organizationsTypes.js.map +1 -0
  24. package/client/organizations/principalContainerMutations.js +2 -0
  25. package/client/organizations/principalContainerMutations.js.map +1 -1
  26. package/client/organizations/principalMutationRecovery.d.ts +16 -0
  27. package/client/organizations/principalMutationRecovery.js +23 -0
  28. package/client/organizations/principalMutationRecovery.js.map +1 -0
  29. package/client/organizations/principalMutationScope.js +7 -2
  30. package/client/organizations/principalMutationScope.js.map +1 -1
  31. package/client/organizations/principalMutations.d.ts +4 -308
  32. package/client/organizations/principalMutations.js +165 -87
  33. package/client/organizations/principalMutations.js.map +1 -1
  34. package/client/principalMutationApi.d.ts +24 -0
  35. package/client/principalMutationApi.js +108 -0
  36. package/client/principalMutationApi.js.map +1 -0
  37. package/client/principalMutationDeadline.js +23 -0
  38. package/client/principalMutationDeadline.js.map +1 -0
  39. package/client/workflowRuntime.d.ts +3 -1
  40. package/client/workflowRuntime.js +44 -5
  41. package/client/workflowRuntime.js.map +1 -1
  42. package/data/persistence/principalCurrentAcknowledgementPersistence.d.ts +27 -0
  43. package/data/persistence/principalCurrentAcknowledgementPersistence.js +116 -0
  44. package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -0
  45. package/data/persistence/principalGrantRetirementPersistence.d.ts +3 -3
  46. package/data/persistence/principalGrantRetirementPersistence.js +4 -1
  47. package/data/persistence/principalGrantRetirementPersistence.js.map +1 -1
  48. package/data/persistence/principalKeyEnvelopeCandidates.js +12 -1
  49. package/data/persistence/principalKeyEnvelopeCandidates.js.map +1 -1
  50. package/data/persistence/principalMutationJournalPersistence.d.ts +19 -0
  51. package/data/persistence/principalMutationJournalPersistence.js +53 -0
  52. package/data/persistence/principalMutationJournalPersistence.js.map +1 -0
  53. package/data/persistence/verifiedPrincipalPolicyBundle.js +7 -51
  54. package/data/persistence/verifiedPrincipalPolicyBundle.js.map +1 -1
  55. package/data/persistence/verifiedPrincipalPolicyCurrent.js +56 -0
  56. package/data/persistence/verifiedPrincipalPolicyCurrent.js.map +1 -0
  57. package/data/principals/currentPolicyReferenceResolver.js +2 -0
  58. package/data/principals/currentPolicyReferenceResolver.js.map +1 -0
  59. package/data/principals/principalHistoryScopeProtection.js +23 -0
  60. package/data/principals/principalHistoryScopeProtection.js.map +1 -0
  61. package/data/principals/principalMutationJournal.d.ts +26 -0
  62. package/data/principals/principalMutationJournal.js +90 -0
  63. package/data/principals/principalMutationJournal.js.map +1 -0
  64. package/data/principals/principalMutationJournalRecord.d.ts +8 -0
  65. package/data/principals/principalMutationJournalRecord.js +25 -0
  66. package/data/principals/principalMutationJournalRecord.js.map +1 -0
  67. package/data/principals/principalPolicyAdminSigners.js.map +1 -1
  68. package/data/sqlite/principalHistoryStageSchema.js +3 -0
  69. package/data/sqlite/principalHistoryStageSchema.js.map +1 -1
  70. package/data/sqlite/principalMutationJournalSchema.d.ts +85 -0
  71. package/data/sqlite/principalMutationJournalSchema.js +13 -0
  72. package/data/sqlite/principalMutationJournalSchema.js.map +1 -0
  73. package/data/sqlite/schema.d.ts +83 -0
  74. package/data/sqlite/schema.js +3 -0
  75. package/data/sqlite/schema.js.map +1 -1
  76. package/index.d.ts +3 -3
  77. package/index.js +1 -1
  78. package/index.js.map +1 -1
  79. package/internal/crypto/index.d.ts +1 -1
  80. package/internal/crypto/index.js +1 -1
  81. package/internal/crypto/index.js.map +1 -1
  82. package/internal/crypto/keying/index.d.ts +3 -0
  83. package/internal/crypto/keying/index.js +3 -0
  84. package/internal/crypto/keying/index.js.map +1 -1
  85. package/internal/crypto/keying/principalPolicyCurrent.d.ts +1 -1
  86. package/internal/crypto/keying/principalPolicyCurrent.js +3 -3
  87. package/internal/crypto/keying/principalPolicyCurrent.js.map +1 -1
  88. package/internal/crypto/keying/principalPolicyCurrentEvidence.js +16 -0
  89. package/internal/crypto/keying/principalPolicyCurrentEvidence.js.map +1 -0
  90. package/internal/crypto/keying/principalPolicyCurrentMutation.d.ts +10 -0
  91. package/internal/crypto/keying/principalPolicyCurrentMutation.js +51 -0
  92. package/internal/crypto/keying/principalPolicyCurrentMutation.js.map +1 -0
  93. package/internal/crypto/keying/principalPolicyCurrentPredecessorReferences.d.ts +8 -0
  94. package/internal/crypto/keying/principalPolicyCurrentPredecessorReferences.js +46 -0
  95. package/internal/crypto/keying/principalPolicyCurrentPredecessorReferences.js.map +1 -0
  96. package/internal/crypto/keying/principalPolicyCurrentSuccessor.d.ts +10 -0
  97. package/internal/crypto/keying/principalPolicyCurrentSuccessor.js +60 -0
  98. package/internal/crypto/keying/principalPolicyCurrentSuccessor.js.map +1 -0
  99. package/internal/crypto/keying/principalPolicyHistory.js +4 -1
  100. package/internal/crypto/keying/principalPolicyHistory.js.map +1 -1
  101. package/internal/crypto/keying/principalPolicyHistoryReferences.js +1 -1
  102. package/internal/crypto/keying/principalPolicyHistoryReferences.js.map +1 -1
  103. package/internal/crypto/keying/principalPolicyHistoryTypes.d.ts +5 -2
  104. package/internal/crypto/keying/principalPolicyHistoryTypes.js +6 -3
  105. package/internal/crypto/keying/principalPolicyHistoryTypes.js.map +1 -1
  106. package/package.json +1 -1
  107. package/workflows/containers/child/carriedDescendantRekeys.js +9 -1
  108. package/workflows/containers/child/carriedDescendantRekeys.js.map +1 -1
  109. package/workflows/containers/child/replacementPrincipalPolicyReferences.js +19 -0
  110. package/workflows/containers/child/replacementPrincipalPolicyReferences.js.map +1 -0
  111. package/workflows/containers/child/share.js +4 -0
  112. package/workflows/containers/child/share.js.map +1 -1
  113. package/workflows/containers/child/sharePrincipalPolicy.d.ts +1 -0
  114. package/workflows/containers/child/sharePrincipalPolicy.js.map +1 -1
  115. package/workflows/organizations/acknowledgedDirectoryBindings.js +18 -0
  116. package/workflows/organizations/acknowledgedDirectoryBindings.js.map +1 -0
  117. package/workflows/organizations/commitCurrentGroupPolicyMutation.js +72 -0
  118. package/workflows/organizations/commitCurrentGroupPolicyMutation.js.map +1 -0
  119. package/workflows/organizations/createCurrentOrganizationGroup.js +85 -0
  120. package/workflows/organizations/createCurrentOrganizationGroup.js.map +1 -0
  121. package/workflows/organizations/currentGroupMetadataAuthority.js +53 -0
  122. package/workflows/organizations/currentGroupMetadataAuthority.js.map +1 -0
  123. package/workflows/organizations/currentGroupMutationReferences.js +35 -0
  124. package/workflows/organizations/currentGroupMutationReferences.js.map +1 -0
  125. package/workflows/organizations/currentGroupPolicyMutationContext.js +79 -0
  126. package/workflows/organizations/currentGroupPolicyMutationContext.js.map +1 -0
  127. package/workflows/organizations/currentOrganizationAuthority.js +88 -0
  128. package/workflows/organizations/currentOrganizationAuthority.js.map +1 -0
  129. package/workflows/organizations/currentOrganizationGroupNames.js +72 -0
  130. package/workflows/organizations/currentOrganizationGroupNames.js.map +1 -0
  131. package/workflows/organizations/currentOrganizationMutationAuthority.js +16 -0
  132. package/workflows/organizations/currentOrganizationMutationAuthority.js.map +1 -0
  133. package/workflows/organizations/currentOrganizationMutationRetention.js +53 -0
  134. package/workflows/organizations/currentOrganizationMutationRetention.js.map +1 -0
  135. package/workflows/organizations/currentPolicyMutationAcknowledgement.js +65 -0
  136. package/workflows/organizations/currentPolicyMutationAcknowledgement.js.map +1 -0
  137. package/workflows/organizations/currentPrincipalMutationLease.js +38 -0
  138. package/workflows/organizations/currentPrincipalMutationLease.js.map +1 -0
  139. package/workflows/organizations/deleteCurrentOrganizationGroup.js +35 -0
  140. package/workflows/organizations/deleteCurrentOrganizationGroup.js.map +1 -0
  141. package/workflows/organizations/deleteOrganizationGroup.d.ts +1 -0
  142. package/workflows/organizations/deleteOrganizationGroup.js +11 -0
  143. package/workflows/organizations/deleteOrganizationGroup.js.map +1 -1
  144. package/workflows/organizations/groupCreation.d.ts +1 -0
  145. package/workflows/organizations/groupCreation.js +9 -0
  146. package/workflows/organizations/groupCreation.js.map +1 -1
  147. package/workflows/organizations/groupMembershipName.d.ts +1 -1
  148. package/workflows/organizations/groupMembershipName.js.map +1 -1
  149. package/workflows/organizations/groupMetadataAccess.d.ts +2 -2
  150. package/workflows/organizations/groupMetadataAccess.js +1 -1
  151. package/workflows/organizations/groupMetadataAccess.js.map +1 -1
  152. package/workflows/organizations/groupMetadataBinding.js.map +1 -1
  153. package/workflows/organizations/groupMetadataContainerAuthority.js +2 -47
  154. package/workflows/organizations/groupMetadataContainerAuthority.js.map +1 -1
  155. package/workflows/organizations/groupMetadataRootBinding.js +51 -0
  156. package/workflows/organizations/groupMetadataRootBinding.js.map +1 -0
  157. package/workflows/organizations/groupMetadataRuntime.js +26 -10
  158. package/workflows/organizations/groupMetadataRuntime.js.map +1 -1
  159. package/workflows/organizations/groupMutationAuthorization.js.map +1 -1
  160. package/workflows/organizations/groupNameUniqueness.js +1 -1
  161. package/workflows/organizations/groupNameUniqueness.js.map +1 -1
  162. package/workflows/organizations/groupPolicyHistoryPage.js +31 -0
  163. package/workflows/organizations/groupPolicyHistoryPage.js.map +1 -0
  164. package/workflows/organizations/groupPolicyMutationAcknowledgement.js +10 -75
  165. package/workflows/organizations/groupPolicyMutationAcknowledgement.js.map +1 -1
  166. package/workflows/organizations/groupPolicyMutationContext.d.ts +23 -13
  167. package/workflows/organizations/groupPolicyMutationContext.js +2 -1
  168. package/workflows/organizations/groupPolicyMutationContext.js.map +1 -1
  169. package/workflows/organizations/groupPolicyMutationEvidence.d.ts +26 -0
  170. package/workflows/organizations/groupPolicyMutationEvidence.js +64 -0
  171. package/workflows/organizations/groupPolicyMutationEvidence.js.map +1 -0
  172. package/workflows/organizations/groupPolicyMutationHead.js.map +1 -1
  173. package/workflows/organizations/groupPolicyRequests.js +69 -63
  174. package/workflows/organizations/groupPolicyRequests.js.map +1 -1
  175. package/workflows/organizations/index.d.ts +6 -0
  176. package/workflows/organizations/index.js +5 -0
  177. package/workflows/organizations/index.js.map +1 -1
  178. package/workflows/organizations/initialPrincipalCurrentPublication.js +83 -0
  179. package/workflows/organizations/initialPrincipalCurrentPublication.js.map +1 -0
  180. package/workflows/organizations/organizationGroupDirectory.js +6 -0
  181. package/workflows/organizations/organizationGroupDirectory.js.map +1 -1
  182. package/workflows/organizations/organizationGroupNames.js +7 -0
  183. package/workflows/organizations/organizationGroupNames.js.map +1 -1
  184. package/workflows/organizations/policyHistoryTypes.d.ts +2 -0
  185. package/workflows/organizations/policyHistoryTypes.js.map +1 -1
  186. package/workflows/organizations/principalContainerRematerialization.js +12 -2
  187. package/workflows/organizations/principalContainerRematerialization.js.map +1 -1
  188. package/workflows/organizations/principalContainerRematerializationPlanning.js +1 -0
  189. package/workflows/organizations/principalContainerRematerializationPlanning.js.map +1 -1
  190. package/workflows/organizations/principalContainerRematerializationTargets.js.map +1 -1
  191. package/workflows/organizations/principalCurrentPublicationSeal.js +51 -0
  192. package/workflows/organizations/principalCurrentPublicationSeal.js.map +1 -0
  193. package/workflows/organizations/principalMutationJournalLane.js +26 -0
  194. package/workflows/organizations/principalMutationJournalLane.js.map +1 -0
  195. package/workflows/organizations/principalMutationJournalManagement.d.ts +26 -0
  196. package/workflows/organizations/principalMutationJournalManagement.js +104 -0
  197. package/workflows/organizations/principalMutationJournalManagement.js.map +1 -0
  198. package/workflows/organizations/principalMutationJournalSession.d.ts +26 -0
  199. package/workflows/organizations/principalMutationJournalSession.js +85 -0
  200. package/workflows/organizations/principalMutationJournalSession.js.map +1 -0
  201. package/workflows/organizations/principalMutationReceipt.js +21 -0
  202. package/workflows/organizations/principalMutationReceipt.js.map +1 -0
  203. package/workflows/organizations/principalPolicyReceiptArtifacts.js +74 -0
  204. package/workflows/organizations/principalPolicyReceiptArtifacts.js.map +1 -0
  205. package/workflows/organizations/principalPolicyRequest.d.ts +5 -4
  206. package/workflows/organizations/principalPolicyRequest.js.map +1 -1
  207. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.d.ts +23 -0
  208. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js +159 -0
  209. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js.map +1 -0
  210. package/workflows/organizations/runtimeCurrentGroupMutation.js +85 -0
  211. package/workflows/organizations/runtimeCurrentGroupMutation.js.map +1 -0
  212. package/workflows/organizations/runtimeCurrentOrganizationMutation.js +48 -0
  213. package/workflows/organizations/runtimeCurrentOrganizationMutation.js.map +1 -0
  214. package/workflows/principals/loadRecoveredPrincipalHistoryPage.d.ts +11 -0
  215. package/workflows/principals/loadRecoveredPrincipalHistoryPage.js +120 -0
  216. package/workflows/principals/loadRecoveredPrincipalHistoryPage.js.map +1 -0
  217. package/workflows/principals/principalCurrentRecoveryBatch.js +14 -0
  218. package/workflows/principals/principalCurrentRecoveryBatch.js.map +1 -0
  219. package/workflows/principals/principalHistoryRecoveryReferences.js +8 -0
  220. package/workflows/principals/principalHistoryRecoveryReferences.js.map +1 -1
  221. package/workflows/principals/principalRecoveryDirectory.d.ts +1 -1
  222. package/workflows/principals/principalRecoveryDirectory.js +32 -12
  223. package/workflows/principals/principalRecoveryDirectory.js.map +1 -1
  224. package/workflows/principals/principalRecoveryDiscoveryPage.js +36 -0
  225. package/workflows/principals/principalRecoveryDiscoveryPage.js.map +1 -0
  226. package/workflows/principals/principalRecoveryLocalPreference.js +29 -0
  227. package/workflows/principals/principalRecoveryLocalPreference.js.map +1 -0
  228. package/workflows/principals/principalRecoveryMemo.d.ts +16 -0
  229. package/workflows/principals/principalRecoveryMemo.js +88 -16
  230. package/workflows/principals/principalRecoveryMemo.js.map +1 -1
  231. package/workflows/principals/recoverCurrentOrganizationPolicy.js +33 -0
  232. package/workflows/principals/recoverCurrentOrganizationPolicy.js.map +1 -0
  233. package/workflows/principals/recoverPrincipalHistoryPage.js +30 -0
  234. package/workflows/principals/recoverPrincipalHistoryPage.js.map +1 -0
  235. package/workflows/principals/recoverPrincipalPolicyHistory.d.ts +2 -0
  236. package/workflows/principals/recoverPrincipalPolicyHistory.js +14 -2
  237. package/workflows/principals/recoverPrincipalPolicyHistory.js.map +1 -1
  238. package/workflows/principals/recoverScopedPrincipalPolicyHistory.d.ts +8 -1
  239. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js +30 -20
  240. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js.map +1 -1
  241. package/workflows/principals/runtimePolicyRecovery.js +36 -9
  242. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  243. package/workflows/principals/runtimePolicyWarmer.js +2 -2
  244. package/workflows/principals/runtimePolicyWarmer.js.map +1 -1
@@ -0,0 +1,159 @@
1
+ import { KeyingVerificationError, restorePrincipalPolicyHistoryVerifier, verifyPrincipalPolicyCurrent, } from "../../internal/crypto/index.js";
2
+ import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
3
+ import { persistAcknowledgedPrincipalCurrents, } from "../../data/persistence/principalCurrentAcknowledgementPersistence.js";
4
+ import { preparePrincipalHistoryEvidencePage } from "../../data/persistence/principalHistoryEvidencePersistence.js";
5
+ import { loadPrincipalHistoryPrefix } from "../../data/persistence/principalHistoryPrefixPersistence.js";
6
+ import { principalHistoryEvidenceScopeId, principalHistoryPrefixProtection, } from "../../data/principals/principalHistoryPrefixProtection.js";
7
+ import { ownPrincipalHistoryProtection } from "../../data/principals/principalHistoryProtection.js";
8
+ import { parsePrincipalHistoryStageCurrent } from "../../data/principals/principalHistoryStageProtection.js";
9
+ import { collectPrincipalPolicySignerPublicKeys } from "../principals/policyVerification.js";
10
+ import { assertPrincipalHistoryVerificationMode, principalHistoryVerificationContext, } from "../principals/principalHistoryRecoveryVerification.js";
11
+ import { assertAcknowledgedDirectoryBindings } from "./acknowledgedDirectoryBindings.js";
12
+ import { acknowledgeGroupPolicyState } from "./groupPolicyMutationAcknowledgement.js";
13
+ import { groupPolicyMutationHead } from "./groupPolicyMutationHead.js";
14
+ import { prepareInitialGroupCurrentPublication } from "./initialPrincipalCurrentPublication.js";
15
+ import { sealPrincipalCurrentPublication, sealPrincipalCurrentStage, } from "./principalCurrentPublicationSeal.js";
16
+ import { assertPrincipalPolicyReceiptArtifacts } from "./principalPolicyReceiptArtifacts.js";
17
+ async function restorePredecessor(options) {
18
+ const scopeId = await principalHistoryEvidenceScopeId({
19
+ organizationId: options.organizationId,
20
+ head: options.expectedHead,
21
+ protection: options.protection,
22
+ });
23
+ const saved = await loadPrincipalHistoryPrefix(options.execSql, scopeId);
24
+ if (!saved || saved.organizationId !== options.organizationId)
25
+ throw new KeyingVerificationError("missing_dependency", "Acknowledgement requires its authenticated predecessor prefix");
26
+ const restored = await restorePrincipalPolicyHistoryVerifier({
27
+ principalId: options.expectedHead.principalId,
28
+ principalType: options.expectedHead.principalType,
29
+ }, saved.progress, await principalHistoryPrefixProtection(options.protection, saved));
30
+ if (!restored.ok)
31
+ throw restored.error;
32
+ const history = restored.value.finish(options.expectedHead);
33
+ if (!history.ok)
34
+ throw history.error;
35
+ const artifacts = parsePrincipalHistoryStageCurrent({
36
+ currentJson: saved.currentJson,
37
+ afterVersion: saved.version - 1,
38
+ });
39
+ if (!artifacts)
40
+ throw new KeyingVerificationError("invalid_shape", "Acknowledged predecessor artifacts are malformed");
41
+ const previous = await verifyPrincipalPolicyCurrent({
42
+ current: artifacts,
43
+ history: history.value,
44
+ });
45
+ if (!previous.ok)
46
+ throw previous.error;
47
+ return {
48
+ scopeId,
49
+ saved,
50
+ artifacts,
51
+ verifier: restored.value,
52
+ previous: previous.value,
53
+ };
54
+ }
55
+ async function preparePublication(options, request, response) {
56
+ options = {
57
+ ...options,
58
+ protection: {
59
+ ...options.protection,
60
+ context: principalHistoryVerificationContext(options),
61
+ },
62
+ };
63
+ const current = () => !options.signal?.aborted && options.stillCurrent();
64
+ assertProjectionVerificationCurrent(current);
65
+ const { scopeId, saved, artifacts, verifier, previous } = await restorePredecessor(options);
66
+ const expectedHead = await groupPolicyMutationHead(request);
67
+ assertPrincipalPolicyReceiptArtifacts({ expectedHead, request, response });
68
+ const keys = await collectPrincipalPolicySignerPublicKeys({
69
+ bundle: { currentState: response.currentState, previousStates: [] },
70
+ resolveTrustedUserIdentity: options.resolveTrustedUserIdentity,
71
+ });
72
+ assertProjectionVerificationCurrent(current);
73
+ if ("error" in keys)
74
+ throw new KeyingVerificationError(keys.error === "not-found" ? "missing_dependency" : "signer_mismatch", "Acknowledged principal signer could not be authenticated");
75
+ const externalAuthority = await options.loadExternalAuthority?.(request.state.externalAuthority ? [request.state.externalAuthority] : []);
76
+ assertProjectionVerificationCurrent(current);
77
+ const policy = await acknowledgeGroupPolicyState({
78
+ verifiedCurrentPolicy: previous,
79
+ expectedHead,
80
+ request,
81
+ response: response.currentState,
82
+ signerPublicKeys: keys.signerPublicKeys,
83
+ externalAuthority,
84
+ stillCurrent: current,
85
+ });
86
+ const entry = {
87
+ state: response.currentState,
88
+ projection: response.currentProjection,
89
+ grants: response.currentGrants,
90
+ };
91
+ assertPrincipalHistoryVerificationMode(options, [entry]);
92
+ const predecessorStage = await sealPrincipalCurrentStage(options, previous.state, verifier, artifacts);
93
+ const appended = await verifier.append({
94
+ entries: [entry],
95
+ signerPublicKeys: keys.signerPublicKeys,
96
+ ...(externalAuthority ? { externalAuthority } : {}),
97
+ });
98
+ if (!appended.ok)
99
+ throw appended.error;
100
+ const sealed = await sealPrincipalCurrentPublication(options, scopeId, expectedHead, verifier, response);
101
+ assertProjectionVerificationCurrent(current);
102
+ return {
103
+ policy,
104
+ previousPrefixProgress: saved.progress,
105
+ predecessorStage,
106
+ ...sealed,
107
+ evidence: await preparePrincipalHistoryEvidencePage({
108
+ scopeId,
109
+ organizationId: options.organizationId,
110
+ entries: [entry],
111
+ nodes: appended.value.indexNodes,
112
+ }),
113
+ };
114
+ }
115
+ /** Extend authenticated local progress and retain exact acknowledged artifacts atomically with pins. */
116
+ export async function retainAcknowledgedPrincipalCurrents(input) {
117
+ const execSql = input.execSql;
118
+ const organizationId = input.organizationId;
119
+ const stillCurrent = input.stillCurrent;
120
+ const retirements = structuredClone(input.retirements ?? []);
121
+ const entries = [];
122
+ try {
123
+ assertProjectionVerificationCurrent(stillCurrent);
124
+ for (const entry of input.entries)
125
+ entries.push({
126
+ initialGroup: entry.initialGroup === true,
127
+ request: structuredClone(entry.request),
128
+ response: structuredClone(entry.response),
129
+ options: {
130
+ ...entry.recovery,
131
+ expectedHead: structuredClone(entry.recovery.expectedHead),
132
+ protection: ownPrincipalHistoryProtection(entry.recovery.protection),
133
+ execSql,
134
+ organizationId,
135
+ stillCurrent,
136
+ },
137
+ });
138
+ const publications = [];
139
+ for (const entry of entries)
140
+ publications.push(await (entry.initialGroup
141
+ ? prepareInitialGroupCurrentPublication
142
+ : preparePublication)(entry.options, entry.request, entry.response));
143
+ assertAcknowledgedDirectoryBindings(organizationId, entries.map(({ response }) => response));
144
+ await persistAcknowledgedPrincipalCurrents({
145
+ execSql,
146
+ organizationId,
147
+ entries: publications,
148
+ retirements,
149
+ stillCurrent: () => stillCurrent() &&
150
+ entries.every((entry) => !entry.options.signal?.aborted),
151
+ });
152
+ return publications.map(({ policy }) => policy);
153
+ }
154
+ finally {
155
+ for (const entry of entries)
156
+ entry.options.protection.localKey.fill(0);
157
+ }
158
+ }
159
+ //# sourceMappingURL=retainAcknowledgedPrincipalCurrents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retainAcknowledgedPrincipalCurrents.js","sourceRoot":"","sources":["retainAcknowledgedPrincipalCurrents.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,qCAAqC,EAErC,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAGL,oCAAoC,GACrC,MAAM,mEAAmE,CAAC;AAC3E,OAAO,EAAE,mCAAmC,EAAE,MAAM,4DAA4D,CAAC;AACjH,OAAO,EAAE,0BAA0B,EAAE,MAAM,0DAA0D,CAAC;AACtG,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,GACjC,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,kDAAkD,CAAC;AACjG,OAAO,EAAE,iCAAiC,EAAE,MAAM,uDAAuD,CAAC;AAE1G,OAAO,EAAE,sCAAsC,EAAE,MAAM,kCAAkC,CAAC;AAE1F,OAAO,EACL,sCAAsC,EACtC,mCAAmC,GACpC,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAC7F,OAAO,EACL,+BAA+B,EAC/B,yBAAyB,GAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,qCAAqC,EAAE,MAAM,mCAAmC,CAAC;AAgB1F,KAAK,UAAU,kBAAkB,C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,CAAC;QACL,MAAM,YAAY,GAA8C,EAAE,CAAC;QACnE,KAAK,MAAM,KAAK,IAAI,OAAO;YACzB,YAAY,CAAC,IAAI,CACf,MAAM,CAAC,KAAK,CAAC,YAAY;gBACvB,CAAC,CAAC,qCAAqC;gBACvC,CAAC,CAAC,kBAAkB,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,CACtE,CAAC;QACJ,mCAAmC,CACjC,cAAc,EACd,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,CACxC,CAAC;QACF,MAAM,oCAAoC,CAAC;YACzC,OAAO;YACP,cAAc;YACd,OAAO,EAAE,YAAY;YACrB,WAAW;YACX,YAAY,EAAE,GAAG,EAAE,CACjB,YAAY,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC;SAC3D,CAAC,CAAC;QACH,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,KAAK,IAAI,OAAO;YAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;AACH,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n restorePrincipalPolicyHistoryVerifier,\n type VerifiedPrincipalPolicyCurrent,\n verifyPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyMutationResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport {\n type AcknowledgedPrincipalCurrentPublication,\n type AcknowledgedPrincipalCurrentRetirement,\n persistAcknowledgedPrincipalCurrents,\n} from \"../../data/persistence/principalCurrentAcknowledgementPersistence\";\nimport { preparePrincipalHistoryEvidencePage } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport { loadPrincipalHistoryPrefix } from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport {\n principalHistoryEvidenceScopeId,\n principalHistoryPrefixProtection,\n} from \"../../data/principals/principalHistoryPrefixProtection\";\nimport { ownPrincipalHistoryProtection } from \"../../data/principals/principalHistoryProtection\";\nimport { parsePrincipalHistoryStageCurrent } from \"../../data/principals/principalHistoryStageProtection\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport { collectPrincipalPolicySignerPublicKeys } from \"../principals/policyVerification\";\nimport type { RecoverPrincipalPolicyHistoryOptions } from \"../principals/principalHistoryRecoveryTypes\";\nimport {\n assertPrincipalHistoryVerificationMode,\n principalHistoryVerificationContext,\n} from \"../principals/principalHistoryRecoveryVerification\";\nimport { assertAcknowledgedDirectoryBindings } from \"./acknowledgedDirectoryBindings\";\nimport { acknowledgeGroupPolicyState } from \"./groupPolicyMutationAcknowledgement\";\nimport { groupPolicyMutationHead } from \"./groupPolicyMutationHead\";\nimport { prepareInitialGroupCurrentPublication } from \"./initialPrincipalCurrentPublication\";\nimport {\n sealPrincipalCurrentPublication,\n sealPrincipalCurrentStage,\n} from \"./principalCurrentPublicationSeal\";\nimport { assertPrincipalPolicyReceiptArtifacts } from \"./principalPolicyReceiptArtifacts\";\n\nexport type { AcknowledgedPrincipalCurrentRetirement } from \"../../data/persistence/principalCurrentAcknowledgementPersistence\";\n\nexport interface AcknowledgedPrincipalCurrentInput {\n /** Only a newly authored group at version one; never skips a predecessor. */\n readonly initialGroup?: boolean | undefined;\n /** The same scoped protection and verification mode used to recover the predecessor. */\n readonly recovery: Omit<\n RecoverPrincipalPolicyHistoryOptions,\n \"execSql\" | \"organizationId\" | \"stillCurrent\"\n >;\n readonly request: PutPrincipalPolicyRequest;\n readonly response: PrincipalPolicyMutationResponse;\n}\n\nasync function restorePredecessor(\n options: RecoverPrincipalPolicyHistoryOptions,\n) {\n const scopeId = await principalHistoryEvidenceScopeId({\n organizationId: options.organizationId,\n head: options.expectedHead,\n protection: options.protection,\n });\n const saved = await loadPrincipalHistoryPrefix(options.execSql, scopeId);\n if (!saved || saved.organizationId !== options.organizationId)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Acknowledgement requires its authenticated predecessor prefix\",\n );\n const restored = await restorePrincipalPolicyHistoryVerifier(\n {\n principalId: options.expectedHead.principalId,\n principalType: options.expectedHead.principalType,\n },\n saved.progress,\n await principalHistoryPrefixProtection(options.protection, saved),\n );\n if (!restored.ok) throw restored.error;\n const history = restored.value.finish(options.expectedHead);\n if (!history.ok) throw history.error;\n const artifacts = parsePrincipalHistoryStageCurrent({\n currentJson: saved.currentJson,\n afterVersion: saved.version - 1,\n });\n if (!artifacts)\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"Acknowledged predecessor artifacts are malformed\",\n );\n const previous = await verifyPrincipalPolicyCurrent({\n current: artifacts,\n history: history.value,\n });\n if (!previous.ok) throw previous.error;\n return {\n scopeId,\n saved,\n artifacts,\n verifier: restored.value,\n previous: previous.value,\n };\n}\n\nasync function preparePublication(\n options: RecoverPrincipalPolicyHistoryOptions,\n request: PutPrincipalPolicyRequest,\n response: PrincipalPolicyMutationResponse,\n): Promise<AcknowledgedPrincipalCurrentPublication> {\n options = {\n ...options,\n protection: {\n ...options.protection,\n context: principalHistoryVerificationContext(options),\n },\n };\n const current = () => !options.signal?.aborted && options.stillCurrent();\n assertProjectionVerificationCurrent(current);\n const { scopeId, saved, artifacts, verifier, previous } =\n await restorePredecessor(options);\n const expectedHead = await groupPolicyMutationHead(request);\n assertPrincipalPolicyReceiptArtifacts({ expectedHead, request, response });\n const keys = await collectPrincipalPolicySignerPublicKeys({\n bundle: { currentState: response.currentState, previousStates: [] },\n resolveTrustedUserIdentity: options.resolveTrustedUserIdentity,\n });\n assertProjectionVerificationCurrent(current);\n if (\"error\" in keys)\n throw new KeyingVerificationError(\n keys.error === \"not-found\" ? \"missing_dependency\" : \"signer_mismatch\",\n \"Acknowledged principal signer could not be authenticated\",\n );\n const externalAuthority = await options.loadExternalAuthority?.(\n request.state.externalAuthority ? [request.state.externalAuthority] : [],\n );\n assertProjectionVerificationCurrent(current);\n const policy = await acknowledgeGroupPolicyState({\n verifiedCurrentPolicy: previous,\n expectedHead,\n request,\n response: response.currentState,\n signerPublicKeys: keys.signerPublicKeys,\n externalAuthority,\n stillCurrent: current,\n });\n const entry = {\n state: response.currentState,\n projection: response.currentProjection,\n grants: response.currentGrants,\n };\n assertPrincipalHistoryVerificationMode(options, [entry]);\n const predecessorStage = await sealPrincipalCurrentStage(\n options,\n previous.state,\n verifier,\n artifacts,\n );\n const appended = await verifier.append({\n entries: [entry],\n signerPublicKeys: keys.signerPublicKeys,\n ...(externalAuthority ? { externalAuthority } : {}),\n });\n if (!appended.ok) throw appended.error;\n const sealed = await sealPrincipalCurrentPublication(\n options,\n scopeId,\n expectedHead,\n verifier,\n response,\n );\n assertProjectionVerificationCurrent(current);\n return {\n policy,\n previousPrefixProgress: saved.progress,\n predecessorStage,\n ...sealed,\n evidence: await preparePrincipalHistoryEvidencePage({\n scopeId,\n organizationId: options.organizationId,\n entries: [entry],\n nodes: appended.value.indexNodes,\n }),\n };\n}\n\n/** Extend authenticated local progress and retain exact acknowledged artifacts atomically with pins. */\nexport async function retainAcknowledgedPrincipalCurrents(input: {\n readonly execSql: ExecSql;\n readonly organizationId: string;\n readonly entries: readonly AcknowledgedPrincipalCurrentInput[];\n readonly retirements?:\n | readonly AcknowledgedPrincipalCurrentRetirement[]\n | undefined;\n readonly stillCurrent: () => boolean;\n}): Promise<VerifiedPrincipalPolicyCurrent[]> {\n const execSql = input.execSql;\n const organizationId = input.organizationId;\n const stillCurrent = input.stillCurrent;\n const retirements = structuredClone(input.retirements ?? []);\n const entries: {\n initialGroup: boolean;\n request: PutPrincipalPolicyRequest;\n response: PrincipalPolicyMutationResponse;\n options: RecoverPrincipalPolicyHistoryOptions;\n }[] = [];\n try {\n assertProjectionVerificationCurrent(stillCurrent);\n for (const entry of input.entries)\n entries.push({\n initialGroup: entry.initialGroup === true,\n request: structuredClone(entry.request),\n response: structuredClone(entry.response),\n options: {\n ...entry.recovery,\n expectedHead: structuredClone(entry.recovery.expectedHead),\n protection: ownPrincipalHistoryProtection(entry.recovery.protection),\n execSql,\n organizationId,\n stillCurrent,\n },\n });\n const publications: AcknowledgedPrincipalCurrentPublication[] = [];\n for (const entry of entries)\n publications.push(\n await (entry.initialGroup\n ? prepareInitialGroupCurrentPublication\n : preparePublication)(entry.options, entry.request, entry.response),\n );\n assertAcknowledgedDirectoryBindings(\n organizationId,\n entries.map(({ response }) => response),\n );\n await persistAcknowledgedPrincipalCurrents({\n execSql,\n organizationId,\n entries: publications,\n retirements,\n stillCurrent: () =>\n stillCurrent() &&\n entries.every((entry) => !entry.options.signal?.aborted),\n });\n return publications.map(({ policy }) => policy);\n } finally {\n for (const entry of entries) entry.options.protection.localKey.fill(0);\n }\n}\n"]}
@@ -0,0 +1,85 @@
1
+ import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
2
+ import { scopedGroupHistoryProtection } from "../../data/principals/principalHistoryScopeProtection.js";
3
+ import { principalPolicyReferenceFromBundle } from "../../data/principals/principalPolicyAdminSigners.js";
4
+ import { resolveCurrentGroupMutationReferences } from "./currentGroupMutationReferences.js";
5
+ import { loadCurrentGroupPolicyMutationContext } from "./currentGroupPolicyMutationContext.js";
6
+ import { createCurrentPrincipalMutationLease } from "./currentPrincipalMutationLease.js";
7
+ import { retainAcknowledgedPrincipalCurrents, } from "./retainAcknowledgedPrincipalCurrents.js";
8
+ /** Keep private prefix custody inside the entire mutation and its acknowledgement. */
9
+ export function createRuntimeCurrentGroupMutation(runtime) {
10
+ const lease = createCurrentPrincipalMutationLease(runtime);
11
+ if (!lease)
12
+ return undefined;
13
+ return async (input, work) => {
14
+ input = { ...input };
15
+ return lease(input.stillCurrent, async ({ protection, stillCurrent, resolveCurrentPolicy, readPages, directoryRecovery, }) => {
16
+ const context = await loadCurrentGroupPolicyMutationContext({
17
+ ...input,
18
+ execSql: runtime.infra.execSql,
19
+ resolveCurrentPolicy,
20
+ recoverPendingPrincipalMutation: (organizationId) => runtime.apiClient.recoverPendingPrincipalMutation(organizationId),
21
+ stillCurrent,
22
+ });
23
+ const result = await work({
24
+ ...context,
25
+ resolveAuthoredPolicyReferences: (current, references) => resolveCurrentGroupMutationReferences({
26
+ current,
27
+ predecessor: context.verifiedCurrentPolicy,
28
+ references,
29
+ readPredecessorReference: context.readPredecessorReference,
30
+ stillCurrent: context.stillCurrent,
31
+ }),
32
+ retainAcknowledged: createCurrentMutationRetention(runtime, input, context, protection, readPages, directoryRecovery(context.organizationCurrent.current)),
33
+ });
34
+ assertProjectionVerificationCurrent(context.stillCurrent);
35
+ return result;
36
+ });
37
+ };
38
+ }
39
+ function createCurrentMutationRetention(runtime, input, context, protection, readPages, directoryRecovery) {
40
+ const common = {
41
+ apiClient: { getPrincipalPolicyPages: readPages },
42
+ resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,
43
+ };
44
+ const groupRecovery = {
45
+ ...common,
46
+ expectedHead: principalPolicyReferenceFromBundle(context.currentPolicy),
47
+ protection: context.isOrganizationAdminsGroup
48
+ ? protection
49
+ : scopedGroupHistoryProtection(protection, input.organizationId, context.adminGroupId),
50
+ historyVerification: context.isOrganizationAdminsGroup
51
+ ? "direct-admins"
52
+ : "standard",
53
+ ...(context.isOrganizationAdminsGroup
54
+ ? {}
55
+ : { loadExternalAuthority: async () => context.externalAuthority }),
56
+ };
57
+ return async (receipt) => {
58
+ assertProjectionVerificationCurrent(context.stillCurrent);
59
+ await retainAcknowledgedPrincipalCurrents({
60
+ execSql: runtime.infra.execSql,
61
+ organizationId: input.organizationId,
62
+ entries: [
63
+ {
64
+ recovery: groupRecovery,
65
+ request: receipt.request,
66
+ response: receipt.response.groupPolicy,
67
+ },
68
+ {
69
+ recovery: directoryRecovery,
70
+ request: receipt.organizationRequest,
71
+ response: receipt.response.organizationPolicy,
72
+ },
73
+ ],
74
+ retirements: [
75
+ {
76
+ principalId: input.groupId,
77
+ principalType: "group",
78
+ containerIds: receipt.retiredContainerIds ?? [],
79
+ },
80
+ ],
81
+ stillCurrent: context.stillCurrent,
82
+ });
83
+ };
84
+ }
85
+ //# sourceMappingURL=runtimeCurrentGroupMutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeCurrentGroupMutation.js","sourceRoot":"","sources":["runtimeCurrentGroupMutation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AAEpG,OAAO,EAAE,4BAA4B,EAAE,MAAM,uDAAuD,CAAC;AACrG,OAAO,EAAE,kCAAkC,EAAE,MAAM,mDAAmD,CAAC;AAEvG,OAAO,EAAE,qCAAqC,EAAE,MAAM,kCAAkC,CAAC;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,qCAAqC,CAAC;AAC5F,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AAEtF,OAAO,EAEL,mCAAmC,GACpC,MAAM,uCAAuC,CAAC;AAgC/C,sFAAsF;AACtF,MAAM,UAAU,iCAAiC,CAAC,OAAwB;IACxE,MAAM,KAAK,GAAG,mCAAmC,CAAC,OAAO,CAAC,CAAC;IAC3D,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,OAAO,KAAK,EACV,KAAoB,EACpB,IAAiE,EACrD,EAAE;QACd,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QACrB,OAAO,KAAK,CACV,KAAK,CAAC,YAAY,EAClB,KAAK,EAAE,EACL,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,SAAS,EACT,iBAAiB,GAClB,EAAE,EAAE;YACH,M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AAU;YACZ,CAAC,CAAC,4BAA4B,CAC1B,UAAU,EACV,KAAK,CAAC,cAAc,EACpB,OAAO,CAAC,YAAY,CACrB;QACL,mBAAmB,EAAE,OAAO,CAAC,yBAAyB;YACpD,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,UAAU;QACd,GAAG,CAAC,OAAO,CAAC,yBAAyB;YACnC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,qBAAqB,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;KACtE,CAAC;IACF,OAAO,KAAK,EAAE,OAA+B,EAAiB,EAAE;QAC9D,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC1D,MAAM,mCAAmC,CAAC;YACxC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;YAC9B,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,OAAO,EAAE;gBACP;oBACE,QAAQ,EAAE,aAAa;oBACvB,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW;iBACvC;gBACD;oBACE,QAAQ,EAAE,iBAAiB;oBAC3B,OAAO,EAAE,OAAO,CAAC,mBAAmB;oBACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,kBAAkB;iBAC9C;aACF;YACD,WAAW,EAAE;gBACX;oBACE,WAAW,EAAE,KAAK,CAAC,OAAO;oBAC1B,aAAa,EAAE,OAAO;oBACtB,YAAY,EAAE,OAAO,CAAC,mBAAmB,IAAI,EAAE;iBAChD;aACF;YACD,YAAY,EAAE,OAAO,CAAC,YAAY;SACnC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { ApiClient } from \"@tearleads/api-client\";\nimport type { PrincipalPolicyHistoryProgressOptions } from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { CommitOrganizationGroupPolicyResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport type { CurrentPolicyReferenceResolver } from \"../../data/principals/currentPolicyReferenceResolver\";\nimport { scopedGroupHistoryProtection } from \"../../data/principals/principalHistoryScopeProtection\";\nimport { principalPolicyReferenceFromBundle } from \"../../data/principals/principalPolicyAdminSigners\";\nimport type { PrincipalPolicyRecoveryRuntime } from \"../principals/runtimePolicyRecovery\";\nimport { resolveCurrentGroupMutationReferences } from \"./currentGroupMutationReferences\";\nimport { loadCurrentGroupPolicyMutationContext } from \"./currentGroupPolicyMutationContext\";\nimport { createCurrentPrincipalMutationLease } from \"./currentPrincipalMutationLease\";\nimport type { PrincipalMutationRecoveryApi } from \"./principalMutationJournalManagement\";\nimport {\n type AcknowledgedPrincipalCurrentInput,\n retainAcknowledgedPrincipalCurrents,\n} from \"./retainAcknowledgedPrincipalCurrents\";\n\ntype MutationRuntime = PrincipalPolicyRecoveryRuntime & {\n readonly apiClient: PrincipalPolicyRecoveryRuntime[\"apiClient\"] &\n Pick<PrincipalMutationRecoveryApi, \"recoverPendingPrincipalMutation\">;\n};\n\ntype CurrentMutationContext = Awaited<\n ReturnType<typeof loadCurrentGroupPolicyMutationContext>\n>;\n\nexport type RuntimeCurrentGroupMutationContext = CurrentMutationContext & {\n readonly resolveAuthoredPolicyReferences: CurrentPolicyReferenceResolver;\n readonly retainAcknowledged: (\n receipt: CurrentMutationReceipt,\n ) => Promise<void>;\n};\n\ninterface CurrentMutationReceipt {\n readonly request: PutPrincipalPolicyRequest;\n readonly organizationRequest: PutPrincipalPolicyRequest;\n readonly response: CommitOrganizationGroupPolicyResponse;\n readonly retiredContainerIds?: readonly string[] | undefined;\n}\n\ninterface MutationInput {\n readonly groupId: string;\n readonly organizationId: string;\n readonly signerUserId: string;\n readonly stillCurrent: () => boolean;\n}\n\n/** Keep private prefix custody inside the entire mutation and its acknowledgement. */\nexport function createRuntimeCurrentGroupMutation(runtime: MutationRuntime) {\n const lease = createCurrentPrincipalMutationLease(runtime);\n if (!lease) return undefined;\n return async <T>(\n input: MutationInput,\n work: (context: RuntimeCurrentGroupMutationContext) => Promise<T>,\n ): Promise<T> => {\n input = { ...input };\n return lease(\n input.stillCurrent,\n async ({\n protection,\n stillCurrent,\n resolveCurrentPolicy,\n readPages,\n directoryRecovery,\n }) => {\n const context = await loadCurrentGroupPolicyMutationContext({\n ...input,\n execSql: runtime.infra.execSql,\n resolveCurrentPolicy,\n recoverPendingPrincipalMutation: (organizationId) =>\n runtime.apiClient.recoverPendingPrincipalMutation(organizationId),\n stillCurrent,\n });\n const result = await work({\n ...context,\n resolveAuthoredPolicyReferences: (current, references) =>\n resolveCurrentGroupMutationReferences({\n current,\n predecessor: context.verifiedCurrentPolicy,\n references,\n readPredecessorReference: context.readPredecessorReference,\n stillCurrent: context.stillCurrent,\n }),\n retainAcknowledged: createCurrentMutationRetention(\n runtime,\n input,\n context,\n protection,\n readPages,\n directoryRecovery(context.organizationCurrent.current),\n ),\n });\n assertProjectionVerificationCurrent(context.stillCurrent);\n return result;\n },\n );\n };\n}\n\nfunction createCurrentMutationRetention(\n runtime: MutationRuntime,\n input: MutationInput,\n context: CurrentMutationContext,\n protection: PrincipalPolicyHistoryProgressOptions,\n readPages: ApiClient[\"getPrincipalPolicyPages\"],\n directoryRecovery: AcknowledgedPrincipalCurrentInput[\"recovery\"],\n) {\n const common = {\n apiClient: { getPrincipalPolicyPages: readPages },\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n };\n const groupRecovery: AcknowledgedPrincipalCurrentInput[\"recovery\"] = {\n ...common,\n expectedHead: principalPolicyReferenceFromBundle(context.currentPolicy),\n protection: context.isOrganizationAdminsGroup\n ? protection\n : scopedGroupHistoryProtection(\n protection,\n input.organizationId,\n context.adminGroupId,\n ),\n historyVerification: context.isOrganizationAdminsGroup\n ? \"direct-admins\"\n : \"standard\",\n ...(context.isOrganizationAdminsGroup\n ? {}\n : { loadExternalAuthority: async () => context.externalAuthority }),\n };\n return async (receipt: CurrentMutationReceipt): Promise<void> => {\n assertProjectionVerificationCurrent(context.stillCurrent);\n await retainAcknowledgedPrincipalCurrents({\n execSql: runtime.infra.execSql,\n organizationId: input.organizationId,\n entries: [\n {\n recovery: groupRecovery,\n request: receipt.request,\n response: receipt.response.groupPolicy,\n },\n {\n recovery: directoryRecovery,\n request: receipt.organizationRequest,\n response: receipt.response.organizationPolicy,\n },\n ],\n retirements: [\n {\n principalId: input.groupId,\n principalType: \"group\",\n containerIds: receipt.retiredContainerIds ?? [],\n },\n ],\n stillCurrent: context.stillCurrent,\n });\n };\n}\n"]}
@@ -0,0 +1,48 @@
1
+ import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
2
+ import { advanceKeyingCheckpointsAtomically } from "../../data/persistence/keyingCheckpointAdvancePersistence.js";
3
+ import { loadCurrentOrganizationMutationAuthority } from "./currentOrganizationMutationAuthority.js";
4
+ import { createCurrentOrganizationMutationRetention } from "./currentOrganizationMutationRetention.js";
5
+ import { createCurrentPrincipalMutationLease } from "./currentPrincipalMutationLease.js";
6
+ /** Keep directory authoring and exact acknowledgement inside one private lease. */
7
+ export function createRuntimeCurrentOrganizationMutation(runtime) {
8
+ const lease = createCurrentPrincipalMutationLease(runtime);
9
+ if (!lease)
10
+ return undefined;
11
+ return async (input, work) => {
12
+ const owned = { ...input };
13
+ return lease(owned.stillCurrent, async ({ protection, readPages, stillCurrent, resolveCurrentPolicy, directoryRecovery, }) => {
14
+ const { authority } = await loadCurrentOrganizationMutationAuthority({
15
+ execSql: runtime.infra.execSql,
16
+ organizationId: owned.organizationId,
17
+ signerUserId: owned.signerUserId,
18
+ recoverPendingPrincipalMutation: (organizationId) => runtime.apiClient.recoverPendingPrincipalMutation(organizationId),
19
+ resolveCurrentPolicy,
20
+ stillCurrent,
21
+ });
22
+ const current = () => stillCurrent() && authority.stillCurrent();
23
+ await advanceKeyingCheckpointsAtomically({
24
+ access: [],
25
+ execSql: runtime.infra.execSql,
26
+ organizationId: owned.organizationId,
27
+ policies: [authority.directory.policy, authority.admins.policy],
28
+ stillCurrent: current,
29
+ });
30
+ const result = await work({
31
+ ...authority,
32
+ stillCurrent: current,
33
+ ...createCurrentOrganizationMutationRetention({
34
+ runtime,
35
+ authority,
36
+ protection,
37
+ readPages,
38
+ organizationId: owned.organizationId,
39
+ directoryRecovery: directoryRecovery(authority.directory.current),
40
+ stillCurrent: current,
41
+ }),
42
+ });
43
+ assertProjectionVerificationCurrent(current);
44
+ return result;
45
+ });
46
+ };
47
+ }
48
+ //# sourceMappingURL=runtimeCurrentOrganizationMutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeCurrentOrganizationMutation.js","sourceRoot":"","sources":["runtimeCurrentOrganizationMutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,kCAAkC,EAAE,MAAM,2DAA2D,CAAC;AAG/G,OAAO,EAAE,wCAAwC,EAAE,MAAM,wCAAwC,CAAC;AAClG,OAAO,EAAE,0CAA0C,EAAE,MAAM,wCAAwC,CAAC;AACpG,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AAmBtF,mFAAmF;AACnF,MAAM,UAAU,wCAAwC,CAAC,OAAgB;IACvE,MAAM,KAAK,GAAG,mCAAmC,CAAC,OAAO,CAAC,CAAC;IAC3D,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,OAAO,KAAK,EACV,KAAY,EACZ,IAAiE,EACrD,EAAE;QACd,MAAM,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CACV,KAAK,CAAC,YAAY,EAClB,KAAK,EAAE,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,GAClB,EAAE,EAAE;YACH,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,wCAAwC,CAAC;gBACnE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;gBAC9B,cAAc,EAAE,KAAK,CAAC,cAAc;gBACpC,YAAY,EAAE,KAAK,CAAC,YAAY;gBAChC,+BAA+B,EAAE,CAAC,cAAc,EAAE,EAAE,CAClD,OAAO,CAAC,SAAS,CAAC,+BAA+B,CAAC,cAAc,CAAC;gBACnE,oBAAoB;gBACpB,YAAY;aACb,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,YAAY,EAAE,IAAI,SAAS,CAAC,YAAY,EAAE,CAAC;YACjE,MAAM,kCAAkC,CAAC;gBACvC,MAAM,EAAE,EAAE;gBACV,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;gBAC9B,cAAc,EAAE,KAAK,CAAC,cAAc;gBACpC,QAAQ,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;gBAC/D,YAAY,EAAE,OAAO;aACtB,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC;gBACxB,GAAG,SAAS;gBACZ,YAAY,EAAE,OAAO;gBACrB,GAAG,0CAA0C,CAAC;oBAC5C,OAAO;oBACP,SAAS;oBACT,UAAU;oBACV,SAAS;oBACT,cAAc,EAAE,KAAK,CAAC,cAAc;oBACpC,iBAAiB,EAAE,iBAAiB,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC;oBACjE,YAAY,EAAE,OAAO;iBACtB,CAAC;aACH,CAAC,CAAC;YACH,mCAAmC,CAAC,OAAO,CAAC,CAAC;YAC7C,OAAO,MAAM,CAAC;QAChB,CAAC,CACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { advanceKeyingCheckpointsAtomically } from \"../../data/persistence/keyingCheckpointAdvancePersistence\";\nimport type { PrincipalPolicyRecoveryRuntime } from \"../principals/runtimePolicyRecovery\";\nimport type { loadCurrentOrganizationAuthority } from \"./currentOrganizationAuthority\";\nimport { loadCurrentOrganizationMutationAuthority } from \"./currentOrganizationMutationAuthority\";\nimport { createCurrentOrganizationMutationRetention } from \"./currentOrganizationMutationRetention\";\nimport { createCurrentPrincipalMutationLease } from \"./currentPrincipalMutationLease\";\nimport type { PrincipalMutationRecoveryApi } from \"./principalMutationJournalManagement\";\n\ntype Runtime = PrincipalPolicyRecoveryRuntime & {\n readonly apiClient: PrincipalPolicyRecoveryRuntime[\"apiClient\"] &\n Pick<PrincipalMutationRecoveryApi, \"recoverPendingPrincipalMutation\">;\n};\n\ninterface Input {\n readonly organizationId: string;\n readonly signerUserId: string;\n readonly stillCurrent: () => boolean;\n}\n\ntype Authority = Awaited<ReturnType<typeof loadCurrentOrganizationAuthority>>;\n\nexport type CurrentOrganizationMutationContext = Authority &\n ReturnType<typeof createCurrentOrganizationMutationRetention>;\n\n/** Keep directory authoring and exact acknowledgement inside one private lease. */\nexport function createRuntimeCurrentOrganizationMutation(runtime: Runtime) {\n const lease = createCurrentPrincipalMutationLease(runtime);\n if (!lease) return undefined;\n return async <T>(\n input: Input,\n work: (context: CurrentOrganizationMutationContext) => Promise<T>,\n ): Promise<T> => {\n const owned = { ...input };\n return lease(\n owned.stillCurrent,\n async ({\n protection,\n readPages,\n stillCurrent,\n resolveCurrentPolicy,\n directoryRecovery,\n }) => {\n const { authority } = await loadCurrentOrganizationMutationAuthority({\n execSql: runtime.infra.execSql,\n organizationId: owned.organizationId,\n signerUserId: owned.signerUserId,\n recoverPendingPrincipalMutation: (organizationId) =>\n runtime.apiClient.recoverPendingPrincipalMutation(organizationId),\n resolveCurrentPolicy,\n stillCurrent,\n });\n const current = () => stillCurrent() && authority.stillCurrent();\n await advanceKeyingCheckpointsAtomically({\n access: [],\n execSql: runtime.infra.execSql,\n organizationId: owned.organizationId,\n policies: [authority.directory.policy, authority.admins.policy],\n stillCurrent: current,\n });\n const result = await work({\n ...authority,\n stillCurrent: current,\n ...createCurrentOrganizationMutationRetention({\n runtime,\n authority,\n protection,\n readPages,\n organizationId: owned.organizationId,\n directoryRecovery: directoryRecovery(authority.directory.current),\n stillCurrent: current,\n }),\n });\n assertProjectionVerificationCurrent(current);\n return result;\n },\n );\n };\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { type PrincipalPolicyStateChainEntryResponse } from "../../internal/validators/response/index.js";
2
+ import { type RecoverPrincipalPolicyHistoryOptions } from "./principalHistoryRecoveryTypes.js";
3
+ export declare const PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE = 32;
4
+ export interface RecoveredPrincipalHistoryPage {
5
+ /** Ascending entries, with the immediate predecessor kept separately for diffs. */
6
+ readonly entries: readonly PrincipalPolicyStateChainEntryResponse[];
7
+ readonly predecessor: PrincipalPolicyStateChainEntryResponse | null;
8
+ readonly nextBeforeVersion: number | null;
9
+ }
10
+ /** Read a bounded historical window from an already recovered, exact private root. */
11
+ export declare function loadRecoveredPrincipalHistoryPage(options: RecoverPrincipalPolicyHistoryOptions, beforeVersion?: number): Promise<RecoveredPrincipalHistoryPage>;
@@ -0,0 +1,120 @@
1
+ import { KeyingVerificationError, verifyPrincipalPolicyHistoryReferences, } from "../../internal/crypto/index.js";
2
+ import { isPrincipalPolicyStateChainEntryResponse, } from "../../internal/validators/response/index.js";
3
+ import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
4
+ import { loadPrincipalPolicyCheckpoint } from "../../data/persistence/keyingCheckpointPersistence.js";
5
+ import { loadPrincipalHistoryReference } from "../../data/persistence/principalHistoryEvidencePersistence.js";
6
+ import { principalHistoryEvidenceScopeId } from "../../data/principals/principalHistoryPrefixProtection.js";
7
+ import { ownPrincipalHistoryProtection } from "../../data/principals/principalHistoryProtection.js";
8
+ import { loadVerifiedPrincipalHistoryPrefix } from "./principalHistoryRecoveryPrefix.js";
9
+ import { PrincipalHistoryEvidenceUnavailableError } from "./principalHistoryRecoveryReferences.js";
10
+ import { PrincipalHistoryRecoveryRaceError, } from "./principalHistoryRecoveryTypes.js";
11
+ import { principalHistoryVerificationContext } from "./principalHistoryRecoveryVerification.js";
12
+ export const PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE = 32;
13
+ /** Read a bounded historical window from an already recovered, exact private root. */
14
+ export async function loadRecoveredPrincipalHistoryPage(options, beforeVersion = options.expectedHead.version + 1) {
15
+ const owned = {
16
+ ...options,
17
+ expectedHead: structuredClone(options.expectedHead),
18
+ protection: ownPrincipalHistoryProtection(options.protection),
19
+ };
20
+ try {
21
+ return await readPage(owned, beforeVersion);
22
+ }
23
+ finally {
24
+ owned.protection.localKey.fill(0);
25
+ }
26
+ }
27
+ async function readPage(options, beforeVersion) {
28
+ if (!Number.isSafeInteger(beforeVersion) ||
29
+ beforeVersion <= 1 ||
30
+ beforeVersion > options.expectedHead.version + 1)
31
+ throw new KeyingVerificationError("invalid_shape", "Principal history page cursor is outside the selected history");
32
+ const current = () => !options.signal?.aborted && options.stillCurrent();
33
+ assertProjectionVerificationCurrent(current);
34
+ const { scopeId, history } = await restoreReadRoot(options, current);
35
+ const checkpoint = await loadPrincipalPolicyCheckpoint(options.execSql, options.expectedHead.principalType, options.expectedHead.principalId);
36
+ if (checkpoint && checkpoint.version > options.expectedHead.version)
37
+ throw new PrincipalHistoryRecoveryRaceError("Principal checkpoint advanced beyond the selected display history");
38
+ const load = (version) => loadPageReference({
39
+ execSql: options.execSql,
40
+ scopeId,
41
+ history,
42
+ version,
43
+ });
44
+ const firstVersion = Math.max(1, beforeVersion - PRINCIPAL_DISPLAY_HISTORY_PAGE_SIZE);
45
+ const references = [];
46
+ for (let version = Math.max(1, firstVersion - 1); version < beforeVersion; version += 1) {
47
+ assertProjectionVerificationCurrent(current);
48
+ references.push(await load(version));
49
+ }
50
+ const checkpointReference = checkpoint
51
+ ? await load(checkpoint.version)
52
+ : undefined;
53
+ if (checkpointReference &&
54
+ checkpointReference.reference.stateHash !== checkpoint?.stateHash)
55
+ throw new KeyingVerificationError("equivocation", "Principal history page conflicts with its durable checkpoint");
56
+ const selected = await verifyPrincipalPolicyHistoryReferences({
57
+ history,
58
+ references,
59
+ checkpointReference,
60
+ });
61
+ if (!selected.ok)
62
+ throw new PrincipalHistoryEvidenceUnavailableError(selected.error);
63
+ await assertDisplayCheckpointCurrent(options, checkpoint);
64
+ assertProjectionVerificationCurrent(current);
65
+ // These exact rows passed inclusion and commitment verification above. Keep
66
+ // their display-only server timestamps, which the private current strips.
67
+ const retained = references.map(({ entry }) => responseEntry(entry));
68
+ return {
69
+ entries: retained.filter(({ state }) => state.version >= firstVersion && state.version < beforeVersion),
70
+ predecessor: retained.find(({ state }) => state.version === firstVersion - 1) ?? null,
71
+ nextBeforeVersion: firstVersion > 1 ? firstVersion : null,
72
+ };
73
+ }
74
+ async function assertDisplayCheckpointCurrent(options, checkpoint) {
75
+ const latest = await loadPrincipalPolicyCheckpoint(options.execSql, options.expectedHead.principalType, options.expectedHead.principalId);
76
+ if (latest?.version !== checkpoint?.version ||
77
+ latest?.stateHash !== checkpoint?.stateHash)
78
+ throw new PrincipalHistoryRecoveryRaceError("Principal checkpoint changed while reading display history");
79
+ }
80
+ async function loadPageReference(input) {
81
+ try {
82
+ return await loadPrincipalHistoryReference(input);
83
+ }
84
+ catch (error) {
85
+ if (error instanceof KeyingVerificationError)
86
+ throw new PrincipalHistoryEvidenceUnavailableError(error);
87
+ throw error;
88
+ }
89
+ }
90
+ function responseEntry(entry) {
91
+ if (!isPrincipalPolicyStateChainEntryResponse(entry))
92
+ throw new KeyingVerificationError("missing_dependency", "Principal history display metadata is unavailable");
93
+ return entry;
94
+ }
95
+ async function restoreReadRoot(options, current) {
96
+ const normalized = {
97
+ ...options,
98
+ protection: {
99
+ ...options.protection,
100
+ context: principalHistoryVerificationContext(options),
101
+ },
102
+ };
103
+ const scopeId = await principalHistoryEvidenceScopeId({
104
+ organizationId: options.organizationId,
105
+ head: options.expectedHead,
106
+ protection: normalized.protection,
107
+ });
108
+ const prefix = await loadVerifiedPrincipalHistoryPrefix(normalized, {
109
+ principalType: options.expectedHead.principalType,
110
+ principalId: options.expectedHead.principalId,
111
+ }, scopeId);
112
+ assertProjectionVerificationCurrent(current);
113
+ if (!prefix)
114
+ throw new KeyingVerificationError("missing_dependency", "Principal history page requires a recovered private prefix");
115
+ const finished = prefix.verifier.finish(options.expectedHead);
116
+ if (!finished.ok)
117
+ throw finished.error;
118
+ return { scopeId, history: finished.value };
119
+ }
120
+ //# sourceMappingURL=loadRecoveredPrincipalHistoryPage.js.map
@@ -0,0 +1 @@
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,GAEzC,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;AAE7F,MAAM,CAAC,MAAM,mCAAmC,GAAG,EAAE,CAAC;AAStD,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,OAA6C,EAC7C,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,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AED,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 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"]}
@@ -0,0 +1,14 @@
1
+ import { recoverCurrentOrganizationPolicy } from "./recoverCurrentOrganizationPolicy.js";
2
+ import { createScopedPrincipalPolicyHistoryBatch } from "./recoverScopedPrincipalPolicyHistory.js";
3
+ /** Discovery and selected references share one authenticated collection view. */
4
+ export function createPrincipalCurrentRecoveryBatch() {
5
+ const memo = {
6
+ directories: new Map(),
7
+ admins: new Map(),
8
+ };
9
+ return {
10
+ recover: createScopedPrincipalPolicyHistoryBatch(memo),
11
+ discover: (input) => recoverCurrentOrganizationPolicy(input, memo),
12
+ };
13
+ }
14
+ //# sourceMappingURL=principalCurrentRecoveryBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"principalCurrentRecoveryBatch.js","sourceRoot":"","sources":["principalCurrentRecoveryBatch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,EAAE,uCAAuC,EAAE,MAAM,uCAAuC,CAAC;AAEhG,iFAAiF;AACjF,MAAM,UAAU,mCAAmC;IACjD,MAAM,IAAI,GAA0B;QAClC,WAAW,EAAE,IAAI,GAAG,EAAE;QACtB,MAAM,EAAE,IAAI,GAAG,EAAE;KAClB,CAAC;IACF,OAAO;QACL,OAAO,EAAE,uCAAuC,CAAC,IAAI,CAAC;QACtD,QAAQ,EAAE,CAAC,KAA+B,EAAE,EAAE,CAC5C,gCAAgC,CAAC,KAAK,EAAE,IAAI,CAAC;KAChD,CAAC;AACJ,CAAC","sourcesContent":["import type { PrincipalRecoveryContext } from \"./principalRecoveryDirectory\";\nimport type { PrincipalRecoveryMemo } from \"./principalRecoveryMemo\";\nimport { recoverCurrentOrganizationPolicy } from \"./recoverCurrentOrganizationPolicy\";\nimport { createScopedPrincipalPolicyHistoryBatch } from \"./recoverScopedPrincipalPolicyHistory\";\n\n/** Discovery and selected references share one authenticated collection view. */\nexport function createPrincipalCurrentRecoveryBatch() {\n const memo: PrincipalRecoveryMemo = {\n directories: new Map(),\n admins: new Map(),\n };\n return {\n recover: createScopedPrincipalPolicyHistoryBatch(memo),\n discover: (input: PrincipalRecoveryContext) =>\n recoverCurrentOrganizationPolicy(input, memo),\n };\n}\n"]}
@@ -22,6 +22,14 @@ async function selectReferences(input) {
22
22
  version: reference.version,
23
23
  }));
24
24
  }
25
+ const versions = new Set((options.retainedReferences ?? []).map((reference) => reference.version));
26
+ for (const version of options.retainedVersions ?? []) {
27
+ if (versions.has(version))
28
+ continue;
29
+ versions.add(version);
30
+ assertProjectionVerificationCurrent(current);
31
+ references.push(await loadPrincipalHistoryReference({ ...base, version }));
32
+ }
25
33
  assertProjectionVerificationCurrent(current);
26
34
  const checkpointReference = input.checkpoint
27
35
  ? await loadPrincipalHistoryReference({
@@ -1 +1 @@
1
- {"version":3,"file":"principalHistoryRecoveryReferences.js","sourceRoot":"","sources":["principalHistoryRecoveryReferences.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAIvB,sCAAsC,GACvC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAC;AAC3G,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AAGtG,MAAM,OAAO,wCAAyC,SAAQ,KAAK;IAC5C;IAArB,YAAqB,iBAA0C;QAC7D,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QADd,sBAAiB,GAAjB,iBAAiB,CAAyB;QAE7D,IAAI,CAAC,IAAI,GAAG,0CAA0C,CAAC;IACzD,CAAC;CACF;AAED,KAAK,UAAU,gBAAgB,CAAC,KAK/B;IACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC5C,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IACzE,MAAM,IAAI,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC5D,MAAM,UAAU,GAA2C,EAAE,CAAC;IAC9D,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,kBAAkB,IAAI,EAAE,EAAE,CAAC;QACzD,mCAAmC,CAAC,OAAO,CAAC,CAAC;QAC7C,UAAU,CAAC,IAAI,CACb,MAAM,6BAA6B,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,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicyCheckpoint,\n type PrincipalPolicyHistoryReferenceProof,\n type VerifiedPrincipalPolicyHistory,\n verifyPrincipalPolicyHistoryReferences,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalHistoryReference } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport type { RecoverPrincipalPolicyHistoryOptions } from \"./principalHistoryRecoveryTypes\";\n\nexport class PrincipalHistoryEvidenceUnavailableError extends Error {\n constructor(readonly verificationError: KeyingVerificationError) {\n super(verificationError.message);\n this.name = \"PrincipalHistoryEvidenceUnavailableError\";\n }\n}\n\nasync function selectReferences(input: {\n readonly options: RecoverPrincipalPolicyHistoryOptions;\n readonly scopeId: string;\n readonly history: VerifiedPrincipalPolicyHistory;\n readonly checkpoint: PrincipalPolicyCheckpoint | null;\n}): Promise<VerifiedPrincipalPolicyHistory> {\n const { options, scopeId, history } = input;\n const current = () => !options.signal?.aborted && options.stillCurrent();\n const base = { execSql: options.execSql, scopeId, history };\n const references: PrincipalPolicyHistoryReferenceProof[] = [];\n for (const reference of options.retainedReferences ?? []) {\n assertProjectionVerificationCurrent(current);\n references.push(\n await loadPrincipalHistoryReference({\n ...base,\n version: reference.version,\n }),\n );\n }\n assertProjectionVerificationCurrent(current);\n const checkpointReference = input.checkpoint\n ? await loadPrincipalHistoryReference({\n ...base,\n version: input.checkpoint.version,\n })\n : undefined;\n const selected = await verifyPrincipalPolicyHistoryReferences({\n history,\n references,\n checkpointReference,\n });\n if (!selected.ok) throw selected.error;\n assertProjectionVerificationCurrent(current);\n return selected.value;\n}\n\nexport async function selectRecoveredPrincipalHistory(\n input: Parameters<typeof selectReferences>[0],\n): Promise<VerifiedPrincipalPolicyHistory> {\n let selected: VerifiedPrincipalPolicyHistory;\n try {\n selected = await selectReferences(input);\n } catch (error) {\n if (error instanceof KeyingVerificationError)\n throw new PrincipalHistoryEvidenceUnavailableError(error);\n throw error;\n }\n // First authenticate the stored entry against the private root. Only then\n // compare the caller's citation, so a bad request is not treated as cache loss.\n for (const reference of input.options.retainedReferences ?? []) {\n if (\n !selected.retainedEntries.some(({ state }) =>\n principalHeadMatchesReference(state, reference),\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Requested citation does not match the verified principal history\",\n );\n }\n return selected;\n}\n"]}
1
+ {"version":3,"file":"principalHistoryRecoveryReferences.js","sourceRoot":"","sources":["principalHistoryRecoveryReferences.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAIvB,sCAAsC,GACvC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAC;AAC3G,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AAStG,MAAM,OAAO,wCAAyC,SAAQ,KAAK;IAC5C;IAArB,YAAqB,iBAA0C;QAC7D,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QADd,sBAAiB,GAAjB,iBAAiB,CAAyB;QAE7D,IAAI,CAAC,IAAI,GAAG,0CAA0C,CAAC;IACzD,CAAC;CACF;AAED,KAAK,UAAU,gBAAgB,CAAC,KAK/B;IACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC5C,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IACzE,MAAM,IAAI,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC5D,MAAM,UAAU,GAA2C,EAA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AQ,CAAC,KAAK,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,KAA6C;IAE7C,IAAI,QAAwC,CAAC;IAC7C,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,uBAAuB;YAC1C,MAAM,IAAI,wCAAwC,CAAC,KAAK,CAAC,CAAC;QAC5D,MAAM,KAAK,CAAC;IACd,CAAC;IACD,0EAA0E;IAC1E,gFAAgF;IAChF,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,kBAAkB,IAAI,EAAE,EAAE,CAAC;QAC/D,IACE,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAC3C,6BAA6B,CAAC,KAAK,EAAE,SAAS,CAAC,CAChD;YAED,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,kEAAkE,CACnE,CAAC;IACN,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type PrincipalPolicyCheckpoint,\n type PrincipalPolicyHistoryReferenceProof,\n type VerifiedPrincipalPolicyHistory,\n verifyPrincipalPolicyHistoryReferences,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalHistoryReference } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport type { RecoverPrincipalPolicyHistoryOptions } from \"./principalHistoryRecoveryTypes\";\n\nexport interface PrincipalHistorySelectionOptions\n extends RecoverPrincipalPolicyHistoryOptions {\n /** Internal page selection by version; every selected row still needs a private-root proof. */\n readonly retainedVersions?: readonly number[] | undefined;\n}\n\nexport class PrincipalHistoryEvidenceUnavailableError extends Error {\n constructor(readonly verificationError: KeyingVerificationError) {\n super(verificationError.message);\n this.name = \"PrincipalHistoryEvidenceUnavailableError\";\n }\n}\n\nasync function selectReferences(input: {\n readonly options: PrincipalHistorySelectionOptions;\n readonly scopeId: string;\n readonly history: VerifiedPrincipalPolicyHistory;\n readonly checkpoint: PrincipalPolicyCheckpoint | null;\n}): Promise<VerifiedPrincipalPolicyHistory> {\n const { options, scopeId, history } = input;\n const current = () => !options.signal?.aborted && options.stillCurrent();\n const base = { execSql: options.execSql, scopeId, history };\n const references: PrincipalPolicyHistoryReferenceProof[] = [];\n for (const reference of options.retainedReferences ?? []) {\n assertProjectionVerificationCurrent(current);\n references.push(\n await loadPrincipalHistoryReference({\n ...base,\n version: reference.version,\n }),\n );\n }\n const versions = new Set(\n (options.retainedReferences ?? []).map((reference) => reference.version),\n );\n for (const version of options.retainedVersions ?? []) {\n if (versions.has(version)) continue;\n versions.add(version);\n assertProjectionVerificationCurrent(current);\n references.push(await loadPrincipalHistoryReference({ ...base, version }));\n }\n assertProjectionVerificationCurrent(current);\n const checkpointReference = input.checkpoint\n ? await loadPrincipalHistoryReference({\n ...base,\n version: input.checkpoint.version,\n })\n : undefined;\n const selected = await verifyPrincipalPolicyHistoryReferences({\n history,\n references,\n checkpointReference,\n });\n if (!selected.ok) throw selected.error;\n assertProjectionVerificationCurrent(current);\n return selected.value;\n}\n\nexport async function selectRecoveredPrincipalHistory(\n input: Parameters<typeof selectReferences>[0],\n): Promise<VerifiedPrincipalPolicyHistory> {\n let selected: VerifiedPrincipalPolicyHistory;\n try {\n selected = await selectReferences(input);\n } catch (error) {\n if (error instanceof KeyingVerificationError)\n throw new PrincipalHistoryEvidenceUnavailableError(error);\n throw error;\n }\n // First authenticate the stored entry against the private root. Only then\n // compare the caller's citation, so a bad request is not treated as cache loss.\n for (const reference of input.options.retainedReferences ?? []) {\n if (\n !selected.retainedEntries.some(({ state }) =>\n principalHeadMatchesReference(state, reference),\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Requested citation does not match the verified principal history\",\n );\n }\n return selected;\n}\n"]}
@@ -7,4 +7,4 @@ export interface RecoveredPolicyDirectory extends RecoveredPrincipalPolicyHistor
7
7
  }
8
8
  export declare class PrincipalRecoveryDirectoryAdvanced extends Error {
9
9
  }
10
- export declare function recoverPolicyDirectory(input: PrincipalRecoveryContext, references: readonly ReferencedPrincipalHead[]): Promise<RecoveredPolicyDirectory>;
10
+ export declare function recoverPolicyDirectory(input: PrincipalRecoveryContext, references: readonly ReferencedPrincipalHead[], selected?: RecoveredPolicyDirectory): Promise<RecoveredPolicyDirectory>;