@tearleads/client-sdk 0.1.14 → 0.1.16

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 (354) 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/containerContents.js +2 -1
  5. package/client/containerContents.js.map +1 -1
  6. package/client/index.d.ts +1 -1
  7. package/client/index.js.map +1 -1
  8. package/client/organizations/index.d.ts +4 -42
  9. package/client/organizations/index.js +13 -0
  10. package/client/organizations/index.js.map +1 -1
  11. package/client/organizations/organizationGroupNameHydration.js +8 -1
  12. package/client/organizations/organizationGroupNameHydration.js.map +1 -1
  13. package/client/organizations/organizationsTypes.d.ts +47 -0
  14. package/client/organizations/organizationsTypes.js +2 -0
  15. package/client/organizations/organizationsTypes.js.map +1 -0
  16. package/client/organizations/principalMutationRecovery.d.ts +16 -0
  17. package/client/organizations/principalMutationRecovery.js +23 -0
  18. package/client/organizations/principalMutationRecovery.js.map +1 -0
  19. package/client/organizations/principalMutationScope.js +7 -2
  20. package/client/organizations/principalMutationScope.js.map +1 -1
  21. package/client/principalMutationApi.d.ts +24 -0
  22. package/client/principalMutationApi.js +108 -0
  23. package/client/principalMutationApi.js.map +1 -0
  24. package/client/principalMutationDeadline.js +23 -0
  25. package/client/principalMutationDeadline.js.map +1 -0
  26. package/client/workflowRuntime.d.ts +3 -1
  27. package/client/workflowRuntime.js +44 -5
  28. package/client/workflowRuntime.js.map +1 -1
  29. package/data/documents/blob/shared/types.d.ts +4 -0
  30. package/data/documents/blob/shared/types.js.map +1 -1
  31. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js +2 -0
  32. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js.map +1 -1
  33. package/data/keyingProjectionVerification/checkpointContext.d.ts +2 -1
  34. package/data/keyingProjectionVerification/checkpointContext.js +22 -0
  35. package/data/keyingProjectionVerification/checkpointContext.js.map +1 -1
  36. package/data/keyingProjectionVerification/containerDestinationVerification.js +11 -1
  37. package/data/keyingProjectionVerification/containerDestinationVerification.js.map +1 -1
  38. package/data/keyingProjectionVerification/containerManifestVerification.js.map +1 -1
  39. package/data/keyingProjectionVerification/containerPathVerification.js.map +1 -1
  40. package/data/keyingProjectionVerification/containerProjectionVerification.d.ts +3 -2
  41. package/data/keyingProjectionVerification/containerProjectionVerification.js +10 -11
  42. package/data/keyingProjectionVerification/containerProjectionVerification.js.map +1 -1
  43. package/data/keyingProjectionVerification/documentManifestPolicies.js.map +1 -1
  44. package/data/keyingProjectionVerification/documentManifestVerification.js.map +1 -1
  45. package/data/keyingProjectionVerification/documentProjectionVerification.d.ts +2 -3
  46. package/data/keyingProjectionVerification/documentProjectionVerification.js +4 -0
  47. package/data/keyingProjectionVerification/documentProjectionVerification.js.map +1 -1
  48. package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js +14 -12
  49. package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js.map +1 -1
  50. package/data/keyingProjectionVerification/organizationFounderBinding.js.map +1 -1
  51. package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js +33 -6
  52. package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js.map +1 -1
  53. package/data/keyingProjectionVerification/projectionLifetimes.js +13 -0
  54. package/data/keyingProjectionVerification/projectionLifetimes.js.map +1 -0
  55. package/data/keyingProjectionVerification/projectionPolicyEvidence.js +19 -66
  56. package/data/keyingProjectionVerification/projectionPolicyEvidence.js.map +1 -1
  57. package/data/keyingProjectionVerification/types.d.ts +13 -2
  58. package/data/keyingProjectionVerification/types.js +15 -0
  59. package/data/keyingProjectionVerification/types.js.map +1 -1
  60. package/data/persistence/keyingCheckpointAdvancePersistence.js +4 -1
  61. package/data/persistence/keyingCheckpointAdvancePersistence.js.map +1 -1
  62. package/data/persistence/organizationFounderPersistence.js +2 -2
  63. package/data/persistence/organizationFounderPersistence.js.map +1 -1
  64. package/data/persistence/principalAuthorizationCheckpoints.js +29 -0
  65. package/data/persistence/principalAuthorizationCheckpoints.js.map +1 -0
  66. package/data/persistence/principalCurrentAcknowledgementPersistence.d.ts +27 -0
  67. package/data/persistence/principalCurrentAcknowledgementPersistence.js +109 -0
  68. package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -0
  69. package/data/persistence/principalGrantRetirementPersistence.d.ts +3 -3
  70. package/data/persistence/principalGrantRetirementPersistence.js +4 -1
  71. package/data/persistence/principalGrantRetirementPersistence.js.map +1 -1
  72. package/data/persistence/principalHistoryEvidencePersistence.d.ts +30 -0
  73. package/data/persistence/principalHistoryPrefixPersistence.d.ts +24 -0
  74. package/data/persistence/principalHistoryPrefixPersistence.js +6 -2
  75. package/data/persistence/principalHistoryPrefixPersistence.js.map +1 -1
  76. package/data/persistence/principalHistoryStagePersistence.d.ts +21 -0
  77. package/data/persistence/principalKeyEnvelopeCandidates.js +12 -1
  78. package/data/persistence/principalKeyEnvelopeCandidates.js.map +1 -1
  79. package/data/persistence/principalMutationJournalPersistence.d.ts +19 -0
  80. package/data/persistence/principalMutationJournalPersistence.js +53 -0
  81. package/data/persistence/principalMutationJournalPersistence.js.map +1 -0
  82. package/data/persistence/verifiedPrincipalPolicyBundle.js +7 -51
  83. package/data/persistence/verifiedPrincipalPolicyBundle.js.map +1 -1
  84. package/data/persistence/verifiedPrincipalPolicyCurrent.js +56 -0
  85. package/data/persistence/verifiedPrincipalPolicyCurrent.js.map +1 -0
  86. package/data/principals/principalHistoryRuntime.js +12 -0
  87. package/data/principals/principalHistoryRuntime.js.map +1 -0
  88. package/data/principals/principalHistoryStageProtection.js +2 -12
  89. package/data/principals/principalHistoryStageProtection.js.map +1 -1
  90. package/data/principals/principalMutationJournal.d.ts +26 -0
  91. package/data/principals/principalMutationJournal.js +90 -0
  92. package/data/principals/principalMutationJournal.js.map +1 -0
  93. package/data/principals/principalMutationJournalRecord.d.ts +8 -0
  94. package/data/principals/principalMutationJournalRecord.js +25 -0
  95. package/data/principals/principalMutationJournalRecord.js.map +1 -0
  96. package/data/principals/principalPolicyEvidence.d.ts +2 -2
  97. package/data/principals/principalPolicyEvidence.js.map +1 -1
  98. package/data/sqlite/principalHistoryEvidenceSchema.d.ts +308 -0
  99. package/data/sqlite/principalHistoryStageSchema.d.ts +119 -0
  100. package/data/sqlite/principalHistoryStageSchema.js +3 -0
  101. package/data/sqlite/principalHistoryStageSchema.js.map +1 -1
  102. package/data/sqlite/principalMutationJournalSchema.d.ts +85 -0
  103. package/data/sqlite/principalMutationJournalSchema.js +13 -0
  104. package/data/sqlite/principalMutationJournalSchema.js.map +1 -0
  105. package/data/sqlite/schema.d.ts +83 -0
  106. package/data/sqlite/schema.js +3 -0
  107. package/data/sqlite/schema.js.map +1 -1
  108. package/index.d.ts +5 -5
  109. package/index.js +2 -2
  110. package/index.js.map +1 -1
  111. package/internal/api-client/ApiCache.d.ts +54 -0
  112. package/internal/api-client/ApiClient.d.ts +255 -309
  113. package/internal/api-client/ApiClient.js +15 -6
  114. package/internal/api-client/ApiClient.js.map +1 -1
  115. package/internal/api-client/index.d.ts +1 -0
  116. package/internal/api-client/index.js.map +1 -1
  117. package/internal/api-client/principalHistoryDeadline.js +20 -0
  118. package/internal/api-client/principalHistoryDeadline.js.map +1 -0
  119. package/internal/api-client/principalHistoryRequest.js +59 -22
  120. package/internal/api-client/principalHistoryRequest.js.map +1 -1
  121. package/internal/api-client/principalHistoryRequestContext.js +18 -5
  122. package/internal/api-client/principalHistoryRequestContext.js.map +1 -1
  123. package/internal/api-client/principalPolicyRequests.d.ts +799 -0
  124. package/internal/api-client/principalPolicyRequests.js +9 -4
  125. package/internal/api-client/principalPolicyRequests.js.map +1 -1
  126. package/internal/api-client/projectionPolicyHistoryPages.d.ts +9 -0
  127. package/internal/api-client/projectionPolicyHistoryPages.js +88 -0
  128. package/internal/api-client/projectionPolicyHistoryPages.js.map +1 -0
  129. package/internal/api-client/writerProjectionRequests.js +26 -0
  130. package/internal/api-client/writerProjectionRequests.js.map +1 -0
  131. package/internal/crypto/index.d.ts +1 -1
  132. package/internal/crypto/index.js +1 -1
  133. package/internal/crypto/index.js.map +1 -1
  134. package/internal/crypto/keying/index.d.ts +2 -0
  135. package/internal/crypto/keying/index.js +2 -0
  136. package/internal/crypto/keying/index.js.map +1 -1
  137. package/internal/crypto/keying/principalPolicyCurrent.d.ts +1 -1
  138. package/internal/crypto/keying/principalPolicyCurrent.js +3 -3
  139. package/internal/crypto/keying/principalPolicyCurrent.js.map +1 -1
  140. package/internal/crypto/keying/principalPolicyCurrentEvidence.js +16 -0
  141. package/internal/crypto/keying/principalPolicyCurrentEvidence.js.map +1 -0
  142. package/internal/crypto/keying/principalPolicyCurrentMutation.d.ts +10 -0
  143. package/internal/crypto/keying/principalPolicyCurrentMutation.js +51 -0
  144. package/internal/crypto/keying/principalPolicyCurrentMutation.js.map +1 -0
  145. package/internal/crypto/keying/principalPolicyCurrentSuccessor.d.ts +10 -0
  146. package/internal/crypto/keying/principalPolicyCurrentSuccessor.js +60 -0
  147. package/internal/crypto/keying/principalPolicyCurrentSuccessor.js.map +1 -0
  148. package/internal/crypto/keying/principalPolicyHistory.js +8 -1
  149. package/internal/crypto/keying/principalPolicyHistory.js.map +1 -1
  150. package/internal/crypto/keying/principalPolicyHistoryReferences.js +1 -1
  151. package/internal/crypto/keying/principalPolicyHistoryReferences.js.map +1 -1
  152. package/internal/crypto/keying/principalPolicyHistoryTypes.d.ts +7 -2
  153. package/internal/crypto/keying/principalPolicyHistoryTypes.js +6 -3
  154. package/internal/crypto/keying/principalPolicyHistoryTypes.js.map +1 -1
  155. package/internal/crypto/projectionHistorySlots.js +0 -4
  156. package/internal/crypto/projectionHistorySlots.js.map +1 -1
  157. package/internal/validators/operation/index.d.ts +1 -0
  158. package/internal/validators/operation/index.js +1 -0
  159. package/internal/validators/operation/index.js.map +1 -1
  160. package/internal/validators/operation/principals.d.ts +38 -16
  161. package/internal/validators/operation/principals.js +11 -5
  162. package/internal/validators/operation/principals.js.map +1 -1
  163. package/internal/validators/operation/projectionPolicyHistory.d.ts +512 -0
  164. package/internal/validators/operation/projectionPolicyHistory.js +37 -0
  165. package/internal/validators/operation/projectionPolicyHistory.js.map +1 -0
  166. package/internal/validators/operation/registry.d.ts +2 -0
  167. package/internal/validators/operation/registry.js +2 -0
  168. package/internal/validators/operation/registry.js.map +1 -1
  169. package/internal/validators/operation/writerProjections.d.ts +178 -1224
  170. package/internal/validators/operation/writerProjections.js +9 -2
  171. package/internal/validators/operation/writerProjections.js.map +1 -1
  172. package/internal/validators/response/container.d.ts +84 -612
  173. package/internal/validators/response/documentMutation.d.ts +84 -612
  174. package/internal/validators/response/index.d.ts +1 -0
  175. package/internal/validators/response/index.js +1 -0
  176. package/internal/validators/response/index.js.map +1 -1
  177. package/internal/validators/response/organizationBilling.d.ts +1 -0
  178. package/internal/validators/response/organizationBilling.js +1 -1
  179. package/internal/validators/response/organizationBilling.js.map +1 -1
  180. package/internal/validators/response/principalHistoryPreparation.js +28 -1
  181. package/internal/validators/response/principalHistoryPreparation.js.map +1 -1
  182. package/internal/validators/response/principalPolicySnapshotPage.d.ts +388 -0
  183. package/internal/validators/response/principalPolicySnapshotPage.js +24 -0
  184. package/internal/validators/response/principalPolicySnapshotPage.js.map +1 -0
  185. package/internal/validators/response/projectionPolicyEvidence.d.ts +85 -613
  186. package/internal/validators/response/projectionPolicyEvidence.js +10 -5
  187. package/internal/validators/response/projectionPolicyEvidence.js.map +1 -1
  188. package/package.json +1 -1
  189. package/stores/documents/documentStore/attachmentHydration.js +3 -0
  190. package/stores/documents/documentStore/attachmentHydration.js.map +1 -1
  191. package/stores/documents/documentStore/syncDetachedAttachments.js +3 -0
  192. package/stores/documents/documentStore/syncDetachedAttachments.js.map +1 -1
  193. package/workflows/blobs/decrypt.d.ts +1 -1
  194. package/workflows/blobs/decrypt.js +3 -1
  195. package/workflows/blobs/decrypt.js.map +1 -1
  196. package/workflows/blobs/detach.js +6 -1
  197. package/workflows/blobs/detach.js.map +1 -1
  198. package/workflows/blobs/hydrate.d.ts +3 -1
  199. package/workflows/blobs/hydrate.js +2 -0
  200. package/workflows/blobs/hydrate.js.map +1 -1
  201. package/workflows/blobs/retainedAttachmentVerification.js +2 -0
  202. package/workflows/blobs/retainedAttachmentVerification.js.map +1 -1
  203. package/workflows/container-contents/container-state/createAdoption.js +2 -0
  204. package/workflows/container-contents/container-state/createAdoption.js.map +1 -1
  205. package/workflows/container-contents/container-state/createWithMetadata.js +7 -39
  206. package/workflows/container-contents/container-state/createWithMetadata.js.map +1 -1
  207. package/workflows/container-contents/container-state/createWithMetadataPlan.js +68 -0
  208. package/workflows/container-contents/container-state/createWithMetadataPlan.js.map +1 -0
  209. package/workflows/container-contents/remoteContainerState.js +3 -1
  210. package/workflows/container-contents/remoteContainerState.js.map +1 -1
  211. package/workflows/container-contents/remoteHydration/verifiedDestination.js +3 -0
  212. package/workflows/container-contents/remoteHydration/verifiedDestination.js.map +1 -1
  213. package/workflows/container-contents/runtime.d.ts +3 -0
  214. package/workflows/container-contents/runtime.js +7 -6
  215. package/workflows/container-contents/runtime.js.map +1 -1
  216. package/workflows/containers/child/share.js +4 -0
  217. package/workflows/containers/child/share.js.map +1 -1
  218. package/workflows/containers/child/sharePrincipalPolicy.d.ts +1 -0
  219. package/workflows/containers/child/sharePrincipalPolicy.js.map +1 -1
  220. package/workflows/documents/create.d.ts +2 -15
  221. package/workflows/documents/create.js +9 -64
  222. package/workflows/documents/create.js.map +1 -1
  223. package/workflows/documents/createProjection.d.ts +14 -0
  224. package/workflows/documents/createProjection.js +26 -0
  225. package/workflows/documents/createProjection.js.map +1 -0
  226. package/workflows/documents/createResponse.js +49 -0
  227. package/workflows/documents/createResponse.js.map +1 -0
  228. package/workflows/documents/linkSetBlobRewraps.js +2 -0
  229. package/workflows/documents/linkSetBlobRewraps.js.map +1 -1
  230. package/workflows/documents/runtime.d.ts +3 -0
  231. package/workflows/documents/runtime.js +3 -2
  232. package/workflows/documents/runtime.js.map +1 -1
  233. package/workflows/documents/syncFailureClassification.js +3 -1
  234. package/workflows/documents/syncFailureClassification.js.map +1 -1
  235. package/workflows/organizations/acknowledgedDirectoryBindings.js +18 -0
  236. package/workflows/organizations/acknowledgedDirectoryBindings.js.map +1 -0
  237. package/workflows/organizations/currentGroupMetadataAuthority.js +32 -0
  238. package/workflows/organizations/currentGroupMetadataAuthority.js.map +1 -0
  239. package/workflows/organizations/currentOrganizationAuthority.js +88 -0
  240. package/workflows/organizations/currentOrganizationAuthority.js.map +1 -0
  241. package/workflows/organizations/currentOrganizationGroupNames.js +68 -0
  242. package/workflows/organizations/currentOrganizationGroupNames.js.map +1 -0
  243. package/workflows/organizations/currentPolicyMutationAcknowledgement.js +65 -0
  244. package/workflows/organizations/currentPolicyMutationAcknowledgement.js.map +1 -0
  245. package/workflows/organizations/deleteOrganizationGroup.js +1 -0
  246. package/workflows/organizations/deleteOrganizationGroup.js.map +1 -1
  247. package/workflows/organizations/groupCreation.js +1 -0
  248. package/workflows/organizations/groupCreation.js.map +1 -1
  249. package/workflows/organizations/groupMetadataAccess.d.ts +2 -2
  250. package/workflows/organizations/groupMetadataAccess.js +1 -1
  251. package/workflows/organizations/groupMetadataAccess.js.map +1 -1
  252. package/workflows/organizations/groupMetadataBinding.js.map +1 -1
  253. package/workflows/organizations/groupMetadataContainerAuthority.js +2 -47
  254. package/workflows/organizations/groupMetadataContainerAuthority.js.map +1 -1
  255. package/workflows/organizations/groupMetadataRootBinding.js +51 -0
  256. package/workflows/organizations/groupMetadataRootBinding.js.map +1 -0
  257. package/workflows/organizations/groupMetadataRuntime.js +20 -9
  258. package/workflows/organizations/groupMetadataRuntime.js.map +1 -1
  259. package/workflows/organizations/groupMutationAuthorization.js.map +1 -1
  260. package/workflows/organizations/groupPolicyMutationAcknowledgement.js +9 -75
  261. package/workflows/organizations/groupPolicyMutationAcknowledgement.js.map +1 -1
  262. package/workflows/organizations/groupPolicyMutationContext.d.ts +5 -13
  263. package/workflows/organizations/groupPolicyMutationContext.js +1 -0
  264. package/workflows/organizations/groupPolicyMutationContext.js.map +1 -1
  265. package/workflows/organizations/groupPolicyMutationEvidence.d.ts +26 -0
  266. package/workflows/organizations/groupPolicyMutationEvidence.js +64 -0
  267. package/workflows/organizations/groupPolicyMutationEvidence.js.map +1 -0
  268. package/workflows/organizations/groupPolicyMutationHead.js.map +1 -1
  269. package/workflows/organizations/groupPolicyRequests.js +69 -63
  270. package/workflows/organizations/groupPolicyRequests.js.map +1 -1
  271. package/workflows/organizations/index.d.ts +6 -0
  272. package/workflows/organizations/index.js +5 -0
  273. package/workflows/organizations/index.js.map +1 -1
  274. package/workflows/organizations/organizationGroupNames.js +7 -0
  275. package/workflows/organizations/organizationGroupNames.js.map +1 -1
  276. package/workflows/organizations/principalCurrentPublicationSeal.js +51 -0
  277. package/workflows/organizations/principalCurrentPublicationSeal.js.map +1 -0
  278. package/workflows/organizations/principalMutationJournalLane.js +26 -0
  279. package/workflows/organizations/principalMutationJournalLane.js.map +1 -0
  280. package/workflows/organizations/principalMutationJournalManagement.d.ts +26 -0
  281. package/workflows/organizations/principalMutationJournalManagement.js +104 -0
  282. package/workflows/organizations/principalMutationJournalManagement.js.map +1 -0
  283. package/workflows/organizations/principalMutationJournalSession.d.ts +26 -0
  284. package/workflows/organizations/principalMutationJournalSession.js +85 -0
  285. package/workflows/organizations/principalMutationJournalSession.js.map +1 -0
  286. package/workflows/organizations/principalMutationReceipt.js +21 -0
  287. package/workflows/organizations/principalMutationReceipt.js.map +1 -0
  288. package/workflows/organizations/principalPolicyReceiptArtifacts.js +74 -0
  289. package/workflows/organizations/principalPolicyReceiptArtifacts.js.map +1 -0
  290. package/workflows/organizations/principalPolicyRequest.d.ts +5 -4
  291. package/workflows/organizations/principalPolicyRequest.js.map +1 -1
  292. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.d.ts +21 -0
  293. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js +155 -0
  294. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js.map +1 -0
  295. package/workflows/principals/index.d.ts +2 -0
  296. package/workflows/principals/index.js +1 -0
  297. package/workflows/principals/index.js.map +1 -1
  298. package/workflows/principals/policyVerification.js.map +1 -1
  299. package/workflows/principals/principalCurrentRecoveryBatch.js +14 -0
  300. package/workflows/principals/principalCurrentRecoveryBatch.js.map +1 -0
  301. package/workflows/principals/principalHistoryRecoveryAuthority.js +20 -0
  302. package/workflows/principals/principalHistoryRecoveryAuthority.js.map +1 -0
  303. package/workflows/principals/principalHistoryRecoveryStage.js +1 -1
  304. package/workflows/principals/principalHistoryRecoveryStage.js.map +1 -1
  305. package/workflows/principals/principalHistoryRecoveryTypes.d.ts +3 -3
  306. package/workflows/principals/principalHistoryRecoveryTypes.js.map +1 -1
  307. package/workflows/principals/principalHistoryRecoveryVerification.js +6 -1
  308. package/workflows/principals/principalHistoryRecoveryVerification.js.map +1 -1
  309. package/workflows/principals/principalRecoveryDirectory.d.ts +1 -1
  310. package/workflows/principals/principalRecoveryDirectory.js +29 -4
  311. package/workflows/principals/principalRecoveryDirectory.js.map +1 -1
  312. package/workflows/principals/principalRecoveryDiscoveryPage.js +36 -0
  313. package/workflows/principals/principalRecoveryDiscoveryPage.js.map +1 -0
  314. package/workflows/principals/principalRecoveryLocalPreference.js +28 -0
  315. package/workflows/principals/principalRecoveryLocalPreference.js.map +1 -0
  316. package/workflows/principals/principalRecoveryMemo.d.ts +16 -0
  317. package/workflows/principals/principalRecoveryMemo.js +88 -16
  318. package/workflows/principals/principalRecoveryMemo.js.map +1 -1
  319. package/workflows/principals/principalRecoveryOutage.js +1 -1
  320. package/workflows/principals/principalRecoveryOutage.js.map +1 -1
  321. package/workflows/principals/publicPrincipalHistoryAuthority.js +60 -0
  322. package/workflows/principals/publicPrincipalHistoryAuthority.js.map +1 -0
  323. package/workflows/principals/publicPrincipalHistoryPage.js +87 -0
  324. package/workflows/principals/publicPrincipalHistoryPage.js.map +1 -0
  325. package/workflows/principals/publicPrincipalHistoryProgress.js +178 -0
  326. package/workflows/principals/publicPrincipalHistoryProgress.js.map +1 -0
  327. package/workflows/principals/publicPrincipalHistoryTypes.d.ts +39 -0
  328. package/workflows/principals/publicPrincipalHistoryTypes.js +2 -0
  329. package/workflows/principals/publicPrincipalHistoryTypes.js.map +1 -0
  330. package/workflows/principals/publicProjectionDirectory.js +40 -0
  331. package/workflows/principals/publicProjectionDirectory.js.map +1 -0
  332. package/workflows/principals/publicProjectionPrincipal.js +53 -0
  333. package/workflows/principals/publicProjectionPrincipal.js.map +1 -0
  334. package/workflows/principals/recoverCurrentOrganizationPolicy.js +33 -0
  335. package/workflows/principals/recoverCurrentOrganizationPolicy.js.map +1 -0
  336. package/workflows/principals/recoverPrincipalPolicyHistory.js +4 -1
  337. package/workflows/principals/recoverPrincipalPolicyHistory.js.map +1 -1
  338. package/workflows/principals/recoverProjectionPolicyHistory.d.ts +9 -0
  339. package/workflows/principals/recoverProjectionPolicyHistory.js +98 -0
  340. package/workflows/principals/recoverProjectionPolicyHistory.js.map +1 -0
  341. package/workflows/principals/recoverPublicPrincipalHistory.js +176 -0
  342. package/workflows/principals/recoverPublicPrincipalHistory.js.map +1 -0
  343. package/workflows/principals/recoverScopedPrincipalPolicyHistory.d.ts +2 -1
  344. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js +15 -20
  345. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js.map +1 -1
  346. package/workflows/principals/runtimePolicyRecovery.js +16 -9
  347. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  348. package/workflows/principals/runtimePolicyWarmer.js +2 -0
  349. package/workflows/principals/runtimePolicyWarmer.js.map +1 -1
  350. package/workflows/principals/runtimeProjectionPolicyRecovery.js +56 -0
  351. package/workflows/principals/runtimeProjectionPolicyRecovery.js.map +1 -0
  352. package/workflows/principals/selectPublicPrincipalHistory.js +90 -0
  353. package/workflows/principals/selectPublicPrincipalHistory.js.map +1 -0
  354. package/workflows/registration/provisioningBootstrapBuilders.d.ts +21 -153
@@ -0,0 +1,28 @@
1
+ import { KeyingVerificationError } from "../../internal/crypto/index.js";
2
+ import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
3
+ import { principalHeadMatchesReference } from "../../data/principals/organizationAuthorityDescriptor.js";
4
+ import { PrincipalHistoryRecoveryRaceError } from "./principalHistoryRecoveryTypes.js";
5
+ import { recoverWithPrincipalOutageFallback } from "./principalRecoveryOutage.js";
6
+ /** Reuse authenticated local artifacts only for the exact current head a caller selected. */
7
+ export async function recoverWithPrincipalLocalPreference(recover, options, preferLocalCurrent) {
8
+ if (preferLocalCurrent && !options.offline) {
9
+ try {
10
+ const local = await recover({
11
+ ...options,
12
+ offline: true,
13
+ });
14
+ assertProjectionVerificationCurrent(options.stillCurrent);
15
+ if (principalHeadMatchesReference(local.policy.state, options.reference))
16
+ return local;
17
+ }
18
+ catch (error) {
19
+ assertProjectionVerificationCurrent(options.stillCurrent);
20
+ if (!(error instanceof PrincipalHistoryRecoveryRaceError) &&
21
+ !(error instanceof KeyingVerificationError &&
22
+ error.code === "missing_dependency"))
23
+ throw error;
24
+ }
25
+ }
26
+ return recoverWithPrincipalOutageFallback(recover, options);
27
+ }
28
+ //# sourceMappingURL=principalRecoveryLocalPreference.js.map
@@ -0,0 +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,6FAA6F;AAC7F,MAAM,CAAC,KAAK,UAAU,mCAAmC,CACvD,OAAmD,EACnD,OAAkE,EAClE,kBAA2B;IAE3B,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,IAAI,6BAA6B,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC;gBACtE,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 authenticated local artifacts only for the exact current head a caller selected. */\nexport async function recoverWithPrincipalLocalPreference(\n recover: typeof recoverScopedPrincipalPolicyHistory,\n options: Parameters<typeof recoverScopedPrincipalPolicyHistory>[0],\n preferLocalCurrent: boolean,\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 (principalHeadMatchesReference(local.policy.state, options.reference))\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"]}
@@ -0,0 +1,16 @@
1
+ import { type ReferencedPrincipalHead } from "../../internal/crypto/index.js";
2
+ import type { RecoveredPrincipalPolicyHistory } from "./principalHistoryRecoveryTypes.js";
3
+ import { type PrincipalRecoveryContext, type RecoveredPolicyDirectory } from "./principalRecoveryDirectory.js";
4
+ type Memo<T> = Map<string, Promise<{
5
+ value: T;
6
+ stillCurrent: () => boolean;
7
+ }>>;
8
+ export interface PrincipalRecoveryMemo {
9
+ readonly directories: Memo<RecoveredPolicyDirectory>;
10
+ readonly admins: Memo<RecoveredPrincipalPolicyHistory>;
11
+ }
12
+ export declare function createPrincipalRecoveryReader(input: PrincipalRecoveryContext, memo?: PrincipalRecoveryMemo): {
13
+ directory: (references: readonly ReferencedPrincipalHead[]) => Promise<RecoveredPolicyDirectory>;
14
+ admins: (expectedHead: ReferencedPrincipalHead, retainedReferences?: readonly ReferencedPrincipalHead[]) => Promise<RecoveredPrincipalPolicyHistory>;
15
+ };
16
+ export {};
@@ -1,5 +1,6 @@
1
- import { serializeKeyingCanonicalJson, } from "../../internal/crypto/index.js";
1
+ import { KeyingVerificationError, serializeKeyingCanonicalJson, } from "../../internal/crypto/index.js";
2
2
  import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
3
+ import { principalHeadMatchesReference } from "../../data/principals/organizationAuthorityDescriptor.js";
3
4
  import { recoverPolicyDirectory, } from "./principalRecoveryDirectory.js";
4
5
  import { recoverPrincipalPolicyHistory } from "./recoverPrincipalPolicyHistory.js";
5
6
  /** Only share authenticated results within one projection collection lifetime. */
@@ -19,28 +20,99 @@ async function memoPrincipalRecovery(memo, key, stillCurrent, work) {
19
20
  assertProjectionVerificationCurrent(stillCurrent);
20
21
  return result.value;
21
22
  }
23
+ async function readMemoizedAdmins(input, memo, scope, expectedHead, retainedReferences) {
24
+ // Every recovered Current already retains its own exact head.
25
+ const references = retainedReferences.filter((reference) => !principalHeadMatchesReference(expectedHead, reference));
26
+ const key = (selected) => serializeKeyingCanonicalJson([
27
+ ...scope,
28
+ { ...expectedHead },
29
+ selected.map((reference) => ({ ...reference })),
30
+ ]);
31
+ const known = memo?.get(key([]));
32
+ let sourceCurrent = () => true;
33
+ const current = () => !input.signal?.aborted && input.stillCurrent() && sourceCurrent();
34
+ return memoPrincipalRecovery(memo, key(references), current, async () => {
35
+ const options = {
36
+ ...input,
37
+ expectedHead,
38
+ retainedReferences,
39
+ historyVerification: "direct-admins",
40
+ stillCurrent: current,
41
+ };
42
+ if (known) {
43
+ sourceCurrent = (await known).stillCurrent;
44
+ assertProjectionVerificationCurrent(current);
45
+ try {
46
+ // A freshly verified exact head only needs local proofs for additional
47
+ // citations; their signature and private-root checks still run.
48
+ return await recoverPrincipalPolicyHistory({
49
+ ...options,
50
+ offline: true,
51
+ });
52
+ }
53
+ catch (error) {
54
+ assertProjectionVerificationCurrent(current);
55
+ if (input.offline ||
56
+ !(error instanceof KeyingVerificationError) ||
57
+ error.code !== "missing_dependency")
58
+ throw error;
59
+ }
60
+ }
61
+ return recoverPrincipalPolicyHistory(options);
62
+ });
63
+ }
64
+ async function readMemoizedDirectory(input, memo, key, references) {
65
+ const known = references.length > 0 ? memo?.get(key([])) : undefined;
66
+ let sourceCurrent = () => true;
67
+ const current = () => !input.signal?.aborted && input.stillCurrent() && sourceCurrent();
68
+ return memoPrincipalRecovery(memo, key(references), current, async () => {
69
+ if (!known)
70
+ return recoverPolicyDirectory(input, references);
71
+ const source = await known;
72
+ sourceCurrent = source.stillCurrent;
73
+ assertProjectionVerificationCurrent(current);
74
+ try {
75
+ // Add authenticated historical citations to this batch's exact directory
76
+ // view. A newer private prefix must not silently replace that view.
77
+ return await recoverPolicyDirectory({ ...input, offline: true, stillCurrent: current }, references, source.value);
78
+ }
79
+ catch (error) {
80
+ assertProjectionVerificationCurrent(current);
81
+ if (input.offline ||
82
+ !(error instanceof KeyingVerificationError) ||
83
+ error.code !== "missing_dependency")
84
+ throw error;
85
+ }
86
+ return recoverPolicyDirectory({ ...input, stillCurrent: current }, references, source.value);
87
+ });
88
+ }
22
89
  export function createPrincipalRecoveryReader(input, memo) {
23
90
  const scope = [
24
91
  input.organizationId,
25
92
  input.protection.context,
26
93
  input.offline === true,
27
94
  ];
28
- const current = () => !input.signal?.aborted && input.stillCurrent();
95
+ const directoryKey = (references) => serializeKeyingCanonicalJson([
96
+ ...scope,
97
+ references.map((reference) => ({ ...reference })),
98
+ ]);
29
99
  return {
30
- directory: (references) => memoPrincipalRecovery(memo?.directories, serializeKeyingCanonicalJson([
31
- ...scope,
32
- references.map((reference) => ({ ...reference })),
33
- ]), current, () => recoverPolicyDirectory(input, references)),
34
- admins: (expectedHead, retainedReferences = []) => memoPrincipalRecovery(memo?.admins, serializeKeyingCanonicalJson([
35
- ...scope,
36
- { ...expectedHead },
37
- retainedReferences.map((reference) => ({ ...reference })),
38
- ]), current, () => recoverPrincipalPolicyHistory({
39
- ...input,
40
- expectedHead,
41
- retainedReferences,
42
- historyVerification: "direct-admins",
43
- })),
100
+ directory: async (references) => {
101
+ const value = await readMemoizedDirectory(input, memo?.directories, directoryKey, references);
102
+ // Retaining extra citations does not prevent this authenticated directory
103
+ // from satisfying a later read with no selected historical references.
104
+ const unselectedKey = directoryKey([]);
105
+ const selected = memo?.directories.get(directoryKey(references));
106
+ if (memo &&
107
+ selected &&
108
+ references.length > 0 &&
109
+ !memo.directories.has(unselectedKey))
110
+ // Keep the original lease: its expiry requires a new batch, even if
111
+ // a later caller still has a live lease of its own.
112
+ memo.directories.set(unselectedKey, selected);
113
+ return value;
114
+ },
115
+ admins: (expectedHead, retainedReferences = []) => readMemoizedAdmins(input, memo?.admins, scope, expectedHead, retainedReferences),
44
116
  };
45
117
  }
46
118
  //# sourceMappingURL=principalRecoveryMemo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"principalRecoveryMemo.js","sourceRoot":"","sources":["principalRecoveryMemo.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AAEpG,OAAO,EAGL,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAShF,kFAAkF;AAClF,KAAK,UAAU,qBAAqB,CAClC,IAAyB,EACzB,GAAW,EACX,YAA2B,EAC3B,IAAsB;IAEtB,mCAAmC,CAAC,YAAY,CAAC,CAAC;IAClD,IAAI,OAAO,GAAG,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;QAC5D,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACpD,IAAI,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO;YAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IACH,mCAAmC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACzD,mCAAmC,CAAC,YAAY,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,KAA+B,EAC/B,IAA4B;IAE5B,MAAM,KAAK,GAAG;QACZ,KAAK,CAAC,cAAc;QACpB,KAAK,CAAC,UAAU,CAAC,OAAO;QACxB,KAAK,CAAC,OAAO,KAAK,IAAI;KACvB,CAAC;IACF,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;IACrE,OAAO;QACL,SAAS,EAAE,CAAC,UAA8C,EAAE,EAAE,CAC5D,qBAAqB,CACnB,IAAI,EAAE,WAAW,EACjB,4BAA4B,CAAC;YAC3B,GAAG,KAAK;YACR,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;SAClD,CAAC,EACF,OAAO,EACP,GAAG,EAAE,CAAC,sBAAsB,CAAC,KAAK,EAAE,UAAU,CAAC,CAChD;QACH,MAAM,EAAE,CACN,YAAqC,EACrC,qBAAyD,EAAE,EAC3D,EAAE,CACF,qBAAqB,CACnB,IAAI,EAAE,MAAM,EACZ,4BAA4B,CAAC;YAC3B,GAAG,KAAK;YACR,EAAE,GAAG,YAAY,EAAE;YACnB,kBAAkB,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;SAC1D,CAAC,EACF,OAAO,EACP,GAAG,EAAE,CACH,6BAA6B,CAAC;YAC5B,GAAG,KAAK;YACR,YAAY;YACZ,kBAAkB;YAClB,mBAAmB,EAAE,eAAe;SACrC,CAAC,CACL;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ReferencedPrincipalHead,\n serializeKeyingCanonicalJson,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport type { RecoveredPrincipalPolicyHistory } from \"./principalHistoryRecoveryTypes\";\nimport {\n type PrincipalRecoveryContext,\n type RecoveredPolicyDirectory,\n recoverPolicyDirectory,\n} from \"./principalRecoveryDirectory\";\nimport { recoverPrincipalPolicyHistory } from \"./recoverPrincipalPolicyHistory\";\n\ntype Memo<T> = Map<string, Promise<{ value: T; stillCurrent: () => boolean }>>;\n\nexport interface PrincipalRecoveryMemo {\n readonly directories: Memo<RecoveredPolicyDirectory>;\n readonly admins: Memo<RecoveredPrincipalPolicyHistory>;\n}\n\n/** Only share authenticated results within one projection collection lifetime. */\nasync function memoPrincipalRecovery<T>(\n memo: Memo<T> | undefined,\n key: string,\n stillCurrent: () => boolean,\n work: () => Promise<T>,\n): Promise<T> {\n assertProjectionVerificationCurrent(stillCurrent);\n let pending = memo?.get(key);\n if (!pending) {\n pending = work().then((value) => ({ value, stillCurrent }));\n memo?.set(key, pending);\n }\n const result = await pending.catch((error: unknown) => {\n if (memo?.get(key) === pending) memo.delete(key);\n throw error;\n });\n assertProjectionVerificationCurrent(result.stillCurrent);\n assertProjectionVerificationCurrent(stillCurrent);\n return result.value;\n}\n\nexport function createPrincipalRecoveryReader(\n input: PrincipalRecoveryContext,\n memo?: PrincipalRecoveryMemo,\n) {\n const scope = [\n input.organizationId,\n input.protection.context,\n input.offline === true,\n ];\n const current = () => !input.signal?.aborted && input.stillCurrent();\n return {\n directory: (references: readonly ReferencedPrincipalHead[]) =>\n memoPrincipalRecovery(\n memo?.directories,\n serializeKeyingCanonicalJson([\n ...scope,\n references.map((reference) => ({ ...reference })),\n ]),\n current,\n () => recoverPolicyDirectory(input, references),\n ),\n admins: (\n expectedHead: ReferencedPrincipalHead,\n retainedReferences: readonly ReferencedPrincipalHead[] = [],\n ) =>\n memoPrincipalRecovery(\n memo?.admins,\n serializeKeyingCanonicalJson([\n ...scope,\n { ...expectedHead },\n retainedReferences.map((reference) => ({ ...reference })),\n ]),\n current,\n () =>\n recoverPrincipalPolicyHistory({\n ...input,\n expectedHead,\n retainedReferences,\n historyVerification: \"direct-admins\",\n }),\n ),\n };\n}\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AAG,CAAC,aAAa,CAAC;gBAEpC,oEAAoE;gBACpE,oDAAoD;gBACpD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;YAChD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,EAAE,CACN,YAAqC,EACrC,qBAAyD,EAAE,EAC3D,EAAE,CACF,kBAAkB,CAChB,KAAK,EACL,IAAI,EAAE,MAAM,EACZ,KAAK,EACL,YAAY,EACZ,kBAAkB,CACnB;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type ReferencedPrincipalHead,\n serializeKeyingCanonicalJson,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport type { RecoveredPrincipalPolicyHistory } from \"./principalHistoryRecoveryTypes\";\nimport {\n type PrincipalRecoveryContext,\n type RecoveredPolicyDirectory,\n recoverPolicyDirectory,\n} from \"./principalRecoveryDirectory\";\nimport { recoverPrincipalPolicyHistory } from \"./recoverPrincipalPolicyHistory\";\n\ntype Memo<T> = Map<string, Promise<{ value: T; stillCurrent: () => boolean }>>;\n\nexport interface PrincipalRecoveryMemo {\n readonly directories: Memo<RecoveredPolicyDirectory>;\n readonly admins: Memo<RecoveredPrincipalPolicyHistory>;\n}\n\n/** Only share authenticated results within one projection collection lifetime. */\nasync function memoPrincipalRecovery<T>(\n memo: Memo<T> | undefined,\n key: string,\n stillCurrent: () => boolean,\n work: () => Promise<T>,\n): Promise<T> {\n assertProjectionVerificationCurrent(stillCurrent);\n let pending = memo?.get(key);\n if (!pending) {\n pending = work().then((value) => ({ value, stillCurrent }));\n memo?.set(key, pending);\n }\n const result = await pending.catch((error: unknown) => {\n if (memo?.get(key) === pending) memo.delete(key);\n throw error;\n });\n assertProjectionVerificationCurrent(result.stillCurrent);\n assertProjectionVerificationCurrent(stillCurrent);\n return result.value;\n}\n\nasync function readMemoizedAdmins(\n input: PrincipalRecoveryContext,\n memo: Memo<RecoveredPrincipalPolicyHistory> | undefined,\n scope: readonly (string | boolean)[],\n expectedHead: ReferencedPrincipalHead,\n retainedReferences: readonly ReferencedPrincipalHead[],\n) {\n // Every recovered Current already retains its own exact head.\n const references = retainedReferences.filter(\n (reference) => !principalHeadMatchesReference(expectedHead, reference),\n );\n const key = (selected: readonly ReferencedPrincipalHead[]) =>\n serializeKeyingCanonicalJson([\n ...scope,\n { ...expectedHead },\n selected.map((reference) => ({ ...reference })),\n ]);\n const known = memo?.get(key([]));\n let sourceCurrent = () => true;\n const current = () =>\n !input.signal?.aborted && input.stillCurrent() && sourceCurrent();\n return memoPrincipalRecovery(memo, key(references), current, async () => {\n const options = {\n ...input,\n expectedHead,\n retainedReferences,\n historyVerification: \"direct-admins\" as const,\n stillCurrent: current,\n };\n if (known) {\n sourceCurrent = (await known).stillCurrent;\n assertProjectionVerificationCurrent(current);\n try {\n // A freshly verified exact head only needs local proofs for additional\n // citations; their signature and private-root checks still run.\n return await recoverPrincipalPolicyHistory({\n ...options,\n offline: true,\n });\n } catch (error) {\n assertProjectionVerificationCurrent(current);\n if (\n input.offline ||\n !(error instanceof KeyingVerificationError) ||\n error.code !== \"missing_dependency\"\n )\n throw error;\n }\n }\n return recoverPrincipalPolicyHistory(options);\n });\n}\n\nasync function readMemoizedDirectory(\n input: PrincipalRecoveryContext,\n memo: Memo<RecoveredPolicyDirectory> | undefined,\n key: (references: readonly ReferencedPrincipalHead[]) => string,\n references: readonly ReferencedPrincipalHead[],\n) {\n const known = references.length > 0 ? memo?.get(key([])) : undefined;\n let sourceCurrent = () => true;\n const current = () =>\n !input.signal?.aborted && input.stillCurrent() && sourceCurrent();\n return memoPrincipalRecovery(memo, key(references), current, async () => {\n if (!known) return recoverPolicyDirectory(input, references);\n const source = await known;\n sourceCurrent = source.stillCurrent;\n assertProjectionVerificationCurrent(current);\n try {\n // Add authenticated historical citations to this batch's exact directory\n // view. A newer private prefix must not silently replace that view.\n return await recoverPolicyDirectory(\n { ...input, offline: true, stillCurrent: current },\n references,\n source.value,\n );\n } catch (error) {\n assertProjectionVerificationCurrent(current);\n if (\n input.offline ||\n !(error instanceof KeyingVerificationError) ||\n error.code !== \"missing_dependency\"\n )\n throw error;\n }\n return recoverPolicyDirectory(\n { ...input, stillCurrent: current },\n references,\n source.value,\n );\n });\n}\n\nexport function createPrincipalRecoveryReader(\n input: PrincipalRecoveryContext,\n memo?: PrincipalRecoveryMemo,\n) {\n const scope = [\n input.organizationId,\n input.protection.context,\n input.offline === true,\n ];\n const directoryKey = (references: readonly ReferencedPrincipalHead[]) =>\n serializeKeyingCanonicalJson([\n ...scope,\n references.map((reference) => ({ ...reference })),\n ]);\n return {\n directory: async (references: readonly ReferencedPrincipalHead[]) => {\n const value = await readMemoizedDirectory(\n input,\n memo?.directories,\n directoryKey,\n references,\n );\n // Retaining extra citations does not prevent this authenticated directory\n // from satisfying a later read with no selected historical references.\n const unselectedKey = directoryKey([]);\n const selected = memo?.directories.get(directoryKey(references));\n if (\n memo &&\n selected &&\n references.length > 0 &&\n !memo.directories.has(unselectedKey)\n )\n // Keep the original lease: its expiry requires a new batch, even if\n // a later caller still has a live lease of its own.\n memo.directories.set(unselectedKey, selected);\n return value;\n },\n admins: (\n expectedHead: ReferencedPrincipalHead,\n retainedReferences: readonly ReferencedPrincipalHead[] = [],\n ) =>\n readMemoizedAdmins(\n input,\n memo?.admins,\n scope,\n expectedHead,\n retainedReferences,\n ),\n };\n}\n"]}
@@ -4,7 +4,7 @@ import { assertProjectionVerificationCurrent } from "../../data/keyingProjection
4
4
  import { PrincipalPolicyHistoryReadError } from "./principalHistoryRecoveryTypes.js";
5
5
  import { recoverScopedPrincipalPolicyHistory } from "./recoverScopedPrincipalPolicyHistory.js";
6
6
  /** Refusals and invalid evidence must never silently select a cached policy. */
7
- function isPrincipalRecoveryOutage(error) {
7
+ export function isPrincipalRecoveryOutage(error) {
8
8
  if (!(error instanceof PrincipalPolicyHistoryReadError))
9
9
  return false;
10
10
  const { failure } = error;
@@ -1 +1 @@
1
- {"version":3,"file":"principalRecoveryOutage.js","sourceRoot":"","sources":["principalRecoveryOutage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAClF,OAAO,EAAE,mCAAmC,EAAE,MAAM,uCAAuC,CAAC;AAE5F,gFAAgF;AAChF,SAAS,yBAAyB,CAAC,KAAc;IAC/C,IAAI,CAAC,CAAC,KAAK,YAAY,+BAA+B,CAAC;QAAE,OAAO,KAAK,CAAC;IACtE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,OAAO,CACL,OAAO,CAAC,IAAI,KAAK,SAAS;QAC1B,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM;YACtB,OAAO,CAAC,MAAM,KAAK,IAAI;YACvB,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC;QACxB,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW;YAC3B,OAAO,CAAC,IAAI,KAAK,qCAAqC,CAAC,CAC1D,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,OAAmD,EACnD,OAAkE;IAElE,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC1D,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,yBAAyB,CAAC,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QACtE,IAAI,CAAC;YACH,OAAO,MAAM,mCAAmC,CAAC;gBAC/C,GAAG,OAAO;gBACV,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,UAAU,EAAE,CAAC;YACpB,IACE,UAAU,YAAY,uBAAuB;gBAC7C,UAAU,CAAC,IAAI,KAAK,oBAAoB;gBAExC,MAAM,IAAI,oCAAoC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YACrE,MAAM,UAAU,CAAC;QACnB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { PrincipalPolicyHistoryReadError } from \"./principalHistoryRecoveryTypes\";\nimport { recoverScopedPrincipalPolicyHistory } from \"./recoverScopedPrincipalPolicyHistory\";\n\n/** Refusals and invalid evidence must never silently select a cached policy. */\nfunction isPrincipalRecoveryOutage(error: unknown): boolean {\n if (!(error instanceof PrincipalPolicyHistoryReadError)) return false;\n const { failure } = error;\n return (\n failure.kind === \"network\" ||\n (failure.kind === \"http\" &&\n failure.status !== null &&\n failure.status >= 500) ||\n (failure.kind === \"cancelled\" &&\n failure.code === \"principal_history_request_timed_out\")\n );\n}\n\nexport async function recoverWithPrincipalOutageFallback(\n recover: typeof recoverScopedPrincipalPolicyHistory,\n options: Parameters<typeof recoverScopedPrincipalPolicyHistory>[0],\n) {\n try {\n return await recover(options);\n } catch (error) {\n assertProjectionVerificationCurrent(options.stillCurrent);\n if (options.offline || !isPrincipalRecoveryOutage(error)) throw error;\n try {\n return await recoverScopedPrincipalPolicyHistory({\n ...options,\n offline: true,\n });\n } catch (localError) {\n if (\n localError instanceof KeyingVerificationError &&\n localError.code === \"missing_dependency\"\n )\n throw new ProjectionDependencyUnavailableError(localError.message);\n throw localError;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"principalRecoveryOutage.js","sourceRoot":"","s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IACE,UAAU,YAAY,uBAAuB;gBAC7C,UAAU,CAAC,IAAI,KAAK,oBAAoB;gBAExC,MAAM,IAAI,oCAAoC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YACrE,MAAM,UAAU,CAAC;QACnB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { PrincipalPolicyHistoryReadError } from \"./principalHistoryRecoveryTypes\";\nimport { recoverScopedPrincipalPolicyHistory } from \"./recoverScopedPrincipalPolicyHistory\";\n\n/** Refusals and invalid evidence must never silently select a cached policy. */\nexport function isPrincipalRecoveryOutage(error: unknown): boolean {\n if (!(error instanceof PrincipalPolicyHistoryReadError)) return false;\n const { failure } = error;\n return (\n failure.kind === \"network\" ||\n (failure.kind === \"http\" &&\n failure.status !== null &&\n failure.status >= 500) ||\n (failure.kind === \"cancelled\" &&\n failure.code === \"principal_history_request_timed_out\")\n );\n}\n\nexport async function recoverWithPrincipalOutageFallback(\n recover: typeof recoverScopedPrincipalPolicyHistory,\n options: Parameters<typeof recoverScopedPrincipalPolicyHistory>[0],\n) {\n try {\n return await recover(options);\n } catch (error) {\n assertProjectionVerificationCurrent(options.stillCurrent);\n if (options.offline || !isPrincipalRecoveryOutage(error)) throw error;\n try {\n return await recoverScopedPrincipalPolicyHistory({\n ...options,\n offline: true,\n });\n } catch (localError) {\n if (\n localError instanceof KeyingVerificationError &&\n localError.code === \"missing_dependency\"\n )\n throw new ProjectionDependencyUnavailableError(localError.message);\n throw localError;\n }\n }\n}\n"]}
@@ -0,0 +1,60 @@
1
+ import { KeyingVerificationError, serializeKeyingCanonicalJson, } from "../../internal/crypto/index.js";
2
+ import { isReferencedPrincipalStateResponse } from "../../internal/validators/response/index.js";
3
+ import { principalHeadMatchesReference } from "../../data/principals/organizationAuthorityDescriptor.js";
4
+ /** The greatest cited Admins head commits to the lineage of every earlier citation. */
5
+ export function publicHistoryAuthorityReference(previous, references) {
6
+ return references.reduce((head, reference) => !head || reference.version > head.version ? reference : head, previous);
7
+ }
8
+ export function publicHistoryAuthorityJson(reference) {
9
+ return serializeKeyingCanonicalJson(reference ? { ...reference } : null);
10
+ }
11
+ export function parsePublicHistoryAuthority(input, json) {
12
+ try {
13
+ const value = JSON.parse(json);
14
+ if (value === null)
15
+ return null;
16
+ if (isReferencedPrincipalStateResponse(value) &&
17
+ value.principalType === "group" &&
18
+ value.principalId === input.authorityGroupId)
19
+ return value;
20
+ }
21
+ catch {
22
+ /* Invalid disposable metadata cannot restore verified progress. */
23
+ }
24
+ return undefined;
25
+ }
26
+ export async function loadPublicHistoryAuthority(input, references, cachedPrefix = false) {
27
+ if (!references.length)
28
+ return undefined;
29
+ const authority = await input.loadExternalAuthority?.(references, cachedPrefix);
30
+ if (authority &&
31
+ (authority.currentHead.principalId !== input.authorityGroupId ||
32
+ authority.states.some(({ head }) => head.principalId !== input.authorityGroupId)))
33
+ throw new KeyingVerificationError("object_mismatch", "Authority callback differs from the directory binding");
34
+ if (references.some((reference) => !authority?.states.some(({ head }) => principalHeadMatchesReference(head, reference))))
35
+ throw new KeyingVerificationError("stale_predecessor", "Public history authority differs from its verified Admins lineage");
36
+ return authority;
37
+ }
38
+ export async function validatePublicHistoryAuthority(input, reference, rejectedPrefix = null) {
39
+ try {
40
+ if (reference)
41
+ await loadPublicHistoryAuthority(input, [reference], true);
42
+ }
43
+ catch (error) {
44
+ if (error instanceof KeyingVerificationError)
45
+ throw new PublicHistoryAuthorityUnavailableError(error, rejectedPrefix);
46
+ throw error;
47
+ }
48
+ }
49
+ /** Only cache restoration can request a replay after an authority mismatch. */
50
+ export class PublicHistoryAuthorityUnavailableError extends Error {
51
+ verificationError;
52
+ rejectedPrefix;
53
+ constructor(verificationError, rejectedPrefix) {
54
+ super(verificationError.message);
55
+ this.verificationError = verificationError;
56
+ this.rejectedPrefix = rejectedPrefix;
57
+ this.name = "PublicHistoryAuthorityUnavailableError";
58
+ }
59
+ }
60
+ //# sourceMappingURL=publicPrincipalHistoryAuthority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicPrincipalHistoryAuthority.js","sourceRoot":"","sources":["publicPrincipalHistoryAuthority.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAEvB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kCAAkC,EAAE,MAAM,gCAAgC,CAAC;AAEpF,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AAGtG,uFAAuF;AACvF,MAAM,UAAU,+BAA+B,CAC7C,QAAwC,EACxC,UAA8C;IAE9C,OAAO,UAAU,CAAC,MAAM,CACtB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,CAClB,CAAC,IAAI,IAAI,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,EAC9D,QAAQ,CACT,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,SAAyC;IAEzC,OAAO,4BAA4B,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,KAAoC,EACpC,IAAY;IAEZ,IAAI,CAAC;QACH,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAChC,IACE,kCAAkC,CAAC,KAAK,CAAC;YACzC,KAAK,CAAC,aAAa,KAAK,OAAO;YAC/B,KAAK,CAAC,WAAW,KAAK,KAAK,CAAC,gBAAgB;YAE5C,OAAO,KAAK,CAAC;IACjB,CAAC;IAAC,MAAM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Ac,CAAC,CAAC;QAC1E,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,MAAM,OAAO,sCAAuC,SAAQ,KAAK;IAEpD;IACA;IAFX,YACW,iBAA0C,EAC1C,cAA6C;QAEtD,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAHxB,sBAAiB,GAAjB,iBAAiB,CAAyB;QAC1C,mBAAc,GAAd,cAAc,CAA+B;QAGtD,IAAI,CAAC,IAAI,GAAG,wCAAwC,CAAC;IACvD,CAAC;CACF","sourcesContent":["import {\n KeyingVerificationError,\n type ReferencedPrincipalHead,\n serializeKeyingCanonicalJson,\n} from \"@tearleads/crypto\";\nimport { isReferencedPrincipalStateResponse } from \"@tearleads/validators/response\";\nimport type { PrincipalHistoryPrefix } from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport type { PublicPrincipalHistoryOptions } from \"./publicPrincipalHistoryTypes\";\n\n/** The greatest cited Admins head commits to the lineage of every earlier citation. */\nexport function publicHistoryAuthorityReference(\n previous: ReferencedPrincipalHead | null,\n references: readonly ReferencedPrincipalHead[],\n) {\n return references.reduce<ReferencedPrincipalHead | null>(\n (head, reference) =>\n !head || reference.version > head.version ? reference : head,\n previous,\n );\n}\n\nexport function publicHistoryAuthorityJson(\n reference: ReferencedPrincipalHead | null,\n) {\n return serializeKeyingCanonicalJson(reference ? { ...reference } : null);\n}\n\nexport function parsePublicHistoryAuthority(\n input: PublicPrincipalHistoryOptions,\n json: string,\n): ReferencedPrincipalHead | null | undefined {\n try {\n const value: unknown = JSON.parse(json);\n if (value === null) return null;\n if (\n isReferencedPrincipalStateResponse(value) &&\n value.principalType === \"group\" &&\n value.principalId === input.authorityGroupId\n )\n return value;\n } catch {\n /* Invalid disposable metadata cannot restore verified progress. */\n }\n return undefined;\n}\n\nexport async function loadPublicHistoryAuthority(\n input: PublicPrincipalHistoryOptions,\n references: readonly ReferencedPrincipalHead[],\n cachedPrefix = false,\n) {\n if (!references.length) return undefined;\n const authority = await input.loadExternalAuthority?.(\n references,\n cachedPrefix,\n );\n if (\n authority &&\n (authority.currentHead.principalId !== input.authorityGroupId ||\n authority.states.some(\n ({ head }) => head.principalId !== input.authorityGroupId,\n ))\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Authority callback differs from the directory binding\",\n );\n if (\n references.some(\n (reference) =>\n !authority?.states.some(({ head }) =>\n principalHeadMatchesReference(head, reference),\n ),\n )\n )\n throw new KeyingVerificationError(\n \"stale_predecessor\",\n \"Public history authority differs from its verified Admins lineage\",\n );\n return authority;\n}\n\nexport async function validatePublicHistoryAuthority(\n input: PublicPrincipalHistoryOptions,\n reference: ReferencedPrincipalHead | null,\n rejectedPrefix: PrincipalHistoryPrefix | null = null,\n): Promise<void> {\n try {\n if (reference) await loadPublicHistoryAuthority(input, [reference], true);\n } catch (error) {\n if (error instanceof KeyingVerificationError)\n throw new PublicHistoryAuthorityUnavailableError(error, rejectedPrefix);\n throw error;\n }\n}\n\n/** Only cache restoration can request a replay after an authority mismatch. */\nexport class PublicHistoryAuthorityUnavailableError extends Error {\n constructor(\n readonly verificationError: KeyingVerificationError,\n readonly rejectedPrefix: PrincipalHistoryPrefix | null,\n ) {\n super(verificationError.message);\n this.name = \"PublicHistoryAuthorityUnavailableError\";\n }\n}\n"]}
@@ -0,0 +1,87 @@
1
+ import { KeyingVerificationError, } from "../../internal/crypto/index.js";
2
+ import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
3
+ import { preparePrincipalHistoryEvidencePage } from "../../data/persistence/principalHistoryEvidencePersistence.js";
4
+ import { savePrincipalHistoryStage } from "../../data/persistence/principalHistoryStagePersistence.js";
5
+ import { principalHistoryStageProtection } from "../../data/principals/principalHistoryStageProtection.js";
6
+ import { collectPrincipalPolicySignerPublicKeys } from "./policyVerification.js";
7
+ import { loadPublicHistoryAuthority, publicHistoryAuthorityJson, publicHistoryAuthorityReference, } from "./publicPrincipalHistoryAuthority.js";
8
+ export class PublicPrincipalHistoryPrefixDisconnectedError extends Error {
9
+ verificationError;
10
+ constructor(verificationError) {
11
+ super(verificationError.message);
12
+ this.verificationError = verificationError;
13
+ this.name = "PublicPrincipalHistoryPrefixDisconnectedError";
14
+ }
15
+ }
16
+ function assertPublicAuthorityScope(input, entries) {
17
+ if (input.strictAdmins &&
18
+ entries.some((entry) => entry.projection.length === 0 ||
19
+ entry.projection.some((member) => member.role !== "admin")))
20
+ throw new KeyingVerificationError("invalid_shape", "Public Admins history must contain only direct admin users");
21
+ if (entries.some(({ state }) => state.externalAuthority &&
22
+ state.externalAuthority.principalId !== input.authorityGroupId))
23
+ throw new KeyingVerificationError("object_mismatch", "Public history cites an authority outside its directory binding");
24
+ }
25
+ export async function appendPublicPrincipalHistoryPage(input, progress, page) {
26
+ const stillCurrent = () => !input.signal?.aborted && input.stillCurrent();
27
+ const complete = page.historyPage.nextAfterVersion === null;
28
+ const entries = [...page.previousStates];
29
+ if (complete)
30
+ entries.push({
31
+ state: page.currentState,
32
+ projection: page.currentProjection,
33
+ grants: page.currentGrants,
34
+ });
35
+ assertPublicAuthorityScope(input, entries);
36
+ const keys = await collectPrincipalPolicySignerPublicKeys({
37
+ bundle: page,
38
+ resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,
39
+ });
40
+ if ("error" in keys)
41
+ throw new KeyingVerificationError(keys.error === "not-found" ? "missing_dependency" : "signer_mismatch", "Public history signer identity is unavailable or mismatched");
42
+ const references = entries.flatMap(({ state }) => state.externalAuthority ? [state.externalAuthority] : []);
43
+ const externalAuthority = await loadPublicHistoryAuthority(input, references);
44
+ assertProjectionVerificationCurrent(stillCurrent);
45
+ const appended = await progress.verifier.append({
46
+ entries,
47
+ signerPublicKeys: keys.signerPublicKeys,
48
+ ...(externalAuthority ? { externalAuthority } : {}),
49
+ });
50
+ if (!appended.ok) {
51
+ if (appended.error.code === "stale_predecessor")
52
+ throw new PublicPrincipalHistoryPrefixDisconnectedError(appended.error);
53
+ throw appended.error;
54
+ }
55
+ const row = {
56
+ id: progress.id,
57
+ organizationId: input.organizationId,
58
+ currentJson: publicHistoryAuthorityJson(publicHistoryAuthorityReference(progress.authorityReference, references)),
59
+ afterVersion: appended.value.throughVersion - (complete ? 1 : 0),
60
+ complete,
61
+ };
62
+ const sealed = await progress.verifier.exportProgress(await principalHistoryStageProtection(input.protection, input.source.head, row));
63
+ if (!sealed.ok)
64
+ throw sealed.error;
65
+ const saved = { ...row, progress: sealed.value };
66
+ await savePrincipalHistoryStage({
67
+ execSql: input.execSql,
68
+ stage: saved,
69
+ evidence: await preparePrincipalHistoryEvidencePage({
70
+ scopeId: progress.scopeId,
71
+ organizationId: input.organizationId,
72
+ entries,
73
+ nodes: appended.value.indexNodes,
74
+ }),
75
+ previousProgress: progress.saved?.progress ?? null,
76
+ stillCurrent,
77
+ });
78
+ assertProjectionVerificationCurrent(stillCurrent);
79
+ return {
80
+ ...progress,
81
+ afterVersion: row.afterVersion,
82
+ saved,
83
+ authorityReference: publicHistoryAuthorityReference(progress.authorityReference, references),
84
+ completedHead: complete ? input.source.head : null,
85
+ };
86
+ }
87
+ //# sourceMappingURL=publicPrincipalHistoryPage.js.map
@@ -0,0 +1 @@
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,0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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"]}
@@ -0,0 +1,178 @@
1
+ import { createPrincipalPolicyHistoryVerifier, KeyingVerificationError, restorePrincipalPolicyHistoryVerifier, serializeKeyingCanonicalJson, verifyPrincipalPolicyHistoryReferences, } from "../../internal/crypto/index.js";
2
+ import { isReferencedPrincipalStateResponse } from "../../internal/validators/response/index.js";
3
+ import { loadPrincipalHistoryReference } from "../../data/persistence/principalHistoryEvidencePersistence.js";
4
+ import { discardPrincipalHistoryPrefix, loadPrincipalHistoryPrefix, savePrincipalHistoryPrefix, } from "../../data/persistence/principalHistoryPrefixPersistence.js";
5
+ import { discardPrincipalHistoryStage, loadPrincipalHistoryStage, } from "../../data/persistence/principalHistoryStagePersistence.js";
6
+ import { principalHeadMatchesReference } from "../../data/principals/organizationAuthorityDescriptor.js";
7
+ import { principalHistoryEvidenceScopeId, principalHistoryPrefixProtection, } from "../../data/principals/principalHistoryPrefixProtection.js";
8
+ import { principalHistoryStageId, principalHistoryStageProtection, } from "../../data/principals/principalHistoryStageProtection.js";
9
+ import { PublicHistoryAuthorityUnavailableError, parsePublicHistoryAuthority, publicHistoryAuthorityJson, validatePublicHistoryAuthority, } from "./publicPrincipalHistoryAuthority.js";
10
+ async function restorePublicPrefix(input, scopeId, id, prefix) {
11
+ const head = input.source.head;
12
+ const historyInput = {
13
+ principalType: head.principalType,
14
+ principalId: head.principalId,
15
+ };
16
+ const current = () => !input.signal?.aborted && input.stillCurrent();
17
+ if (prefix) {
18
+ const authorityReference = parsePublicHistoryAuthority(input, prefix.currentJson);
19
+ let prefixHead;
20
+ try {
21
+ prefixHead = JSON.parse(prefix.headJson);
22
+ }
23
+ catch {
24
+ prefixHead = null;
25
+ }
26
+ if (prefix.organizationId === input.organizationId &&
27
+ authorityReference !== undefined &&
28
+ isReferencedPrincipalStateResponse(prefixHead) &&
29
+ prefixHead.principalId === head.principalId &&
30
+ prefixHead.principalType === head.principalType &&
31
+ prefixHead.version === prefix.version) {
32
+ const restored = await restorePrincipalPolicyHistoryVerifier(historyInput, prefix.progress, await principalHistoryPrefixProtection(input.protection, prefix));
33
+ if (restored.ok && restored.value.finish(prefixHead).ok) {
34
+ await validatePublicHistoryAuthority(input, authorityReference, prefix);
35
+ return {
36
+ id,
37
+ scopeId,
38
+ verifier: restored.value,
39
+ completedHead: prefixHead.version >= head.version ? prefixHead : null,
40
+ afterVersion: Math.min(prefixHead.version, head.version - 1),
41
+ saved: null,
42
+ cachedPrefix: prefix,
43
+ authorityReference,
44
+ };
45
+ }
46
+ }
47
+ if (!input.offline)
48
+ await discardPrincipalHistoryPrefix({
49
+ execSql: input.execSql,
50
+ prefix,
51
+ stillCurrent: current,
52
+ });
53
+ }
54
+ return null;
55
+ }
56
+ export async function restorePublicPrincipalHistoryProgress(input, allowReuse) {
57
+ const head = input.source.head;
58
+ const historyInput = {
59
+ principalType: head.principalType,
60
+ principalId: head.principalId,
61
+ };
62
+ const scopeId = await principalHistoryEvidenceScopeId({
63
+ organizationId: input.organizationId,
64
+ head,
65
+ protection: input.protection,
66
+ });
67
+ const id = await principalHistoryStageId(input.organizationId, head, input.protection.context);
68
+ const current = () => !input.signal?.aborted && input.stillCurrent();
69
+ const saved = await loadPrincipalHistoryStage(input.execSql, id);
70
+ if (saved) {
71
+ const authorityReference = parsePublicHistoryAuthority(input, saved.currentJson);
72
+ if (allowReuse &&
73
+ saved.organizationId === input.organizationId &&
74
+ authorityReference !== undefined) {
75
+ const restored = await restorePrincipalPolicyHistoryVerifier(historyInput, saved.progress, await principalHistoryStageProtection(input.protection, head, saved));
76
+ if (restored.ok && (!saved.complete || restored.value.finish(head).ok)) {
77
+ await validatePublicHistoryAuthority(input, authorityReference);
78
+ return {
79
+ id,
80
+ scopeId,
81
+ verifier: restored.value,
82
+ completedHead: saved.complete ? head : null,
83
+ afterVersion: saved.afterVersion,
84
+ saved,
85
+ cachedPrefix: null,
86
+ authorityReference,
87
+ };
88
+ }
89
+ }
90
+ if (!input.offline)
91
+ await discardPrincipalHistoryStage(input.execSql, saved, current);
92
+ }
93
+ if (allowReuse) {
94
+ const prefix = await restorePublicPrefix(input, scopeId, id, await loadPrincipalHistoryPrefix(input.execSql, scopeId));
95
+ if (prefix)
96
+ return prefix;
97
+ }
98
+ return {
99
+ id,
100
+ scopeId,
101
+ verifier: createPrincipalPolicyHistoryVerifier(historyInput),
102
+ completedHead: null,
103
+ afterVersion: 0,
104
+ saved: null,
105
+ cachedPrefix: null,
106
+ authorityReference: null,
107
+ };
108
+ }
109
+ /** A resumed stage may finish after the reader that rejected the prefix exits. */
110
+ async function rejectedCompletedPrefix(input, progress, history) {
111
+ const candidate = await loadPrincipalHistoryPrefix(input.execSql, progress.scopeId);
112
+ if (!candidate || candidate.version <= history.currentEntry.state.version)
113
+ return null;
114
+ try {
115
+ const cached = await restorePublicPrefix(input, progress.scopeId, progress.id, candidate);
116
+ if (!cached?.completedHead)
117
+ return null;
118
+ const finished = cached.verifier.finish(cached.completedHead);
119
+ if (!finished.ok)
120
+ throw finished.error;
121
+ const proof = await loadPrincipalHistoryReference({
122
+ execSql: input.execSql,
123
+ scopeId: progress.scopeId,
124
+ history: finished.value,
125
+ version: input.source.head.version,
126
+ });
127
+ const verified = await verifyPrincipalPolicyHistoryReferences({
128
+ history: finished.value,
129
+ references: [proof],
130
+ });
131
+ if (!verified.ok)
132
+ throw verified.error;
133
+ return principalHeadMatchesReference(proof.entry.state, input.source.head)
134
+ ? null
135
+ : candidate;
136
+ }
137
+ catch (error) {
138
+ if (error instanceof KeyingVerificationError ||
139
+ error instanceof PublicHistoryAuthorityUnavailableError)
140
+ return candidate;
141
+ throw error;
142
+ }
143
+ }
144
+ export async function publishPublicPrincipalHistoryPrefix(input, progress, history, rejectedPrefix) {
145
+ const state = history.currentEntry.state;
146
+ const head = {
147
+ principalType: state.principalType,
148
+ principalId: state.principalId,
149
+ version: state.version,
150
+ stateHash: state.stateHash,
151
+ keyEpoch: state.keyEpoch,
152
+ keyFingerprint: state.keyFingerprint,
153
+ };
154
+ const prefix = {
155
+ scopeId: progress.scopeId,
156
+ organizationId: input.organizationId,
157
+ version: head.version,
158
+ headJson: serializeKeyingCanonicalJson(head),
159
+ currentJson: publicHistoryAuthorityJson(progress.authorityReference),
160
+ };
161
+ const sealed = await progress.verifier.exportProgress(await principalHistoryPrefixProtection(input.protection, prefix));
162
+ if (!sealed.ok)
163
+ throw sealed.error;
164
+ const rejected = rejectedPrefix ??
165
+ (progress.cachedPrefix
166
+ ? null
167
+ : await rejectedCompletedPrefix(input, progress, history));
168
+ const stillCurrent = () => !input.signal?.aborted && input.stillCurrent();
169
+ await savePrincipalHistoryPrefix({
170
+ execSql: input.execSql,
171
+ prefix: { ...prefix, progress: sealed.value },
172
+ stillCurrent,
173
+ rejectedPrefix: rejected,
174
+ });
175
+ if (progress.saved)
176
+ await discardPrincipalHistoryStage(input.execSql, progress.saved, stillCurrent);
177
+ }
178
+ //# sourceMappingURL=publicPrincipalHistoryProgress.js.map