@tearleads/client-sdk 0.1.225 → 0.1.230

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 (375) hide show
  1. package/Tearleads.js +1 -1
  2. package/Tearleads.js.map +1 -1
  3. package/client/containerContents/documentDiscovery.js +4 -1
  4. package/client/containerContents/documentDiscovery.js.map +1 -1
  5. package/client/containerContents/index.d.ts +1 -1
  6. package/client/containerContents/index.js +4 -2
  7. package/client/containerContents/index.js.map +1 -1
  8. package/client/deviceFirst/index.js +1 -1
  9. package/client/deviceFirst/index.js.map +1 -1
  10. package/client/documents/index.js +6 -2
  11. package/client/documents/index.js.map +1 -1
  12. package/client/identity/index.js +1 -1
  13. package/client/identity/index.js.map +1 -1
  14. package/client/identity/userIdentities.d.ts +1 -1
  15. package/client/identity/userIdentities.js +1 -1
  16. package/client/identity/userIdentities.js.map +1 -1
  17. package/client/index.d.ts +2 -0
  18. package/client/index.js +2 -0
  19. package/client/index.js.map +1 -1
  20. package/client/organizations/index.js +1 -1
  21. package/client/organizations/index.js.map +1 -1
  22. package/client/organizations/organizationMemberships.d.ts +1 -1
  23. package/client/organizations/organizationMemberships.js +1 -1
  24. package/client/organizations/organizationMemberships.js.map +1 -1
  25. package/client/organizations/principalContainerMutations.js.map +1 -1
  26. package/client/organizations/principalMutations.js +1 -1
  27. package/client/organizations/principalMutations.js.map +1 -1
  28. package/client/organizations/recipientAdmission.d.ts +1 -1
  29. package/client/organizations/recipientAdmission.js +2 -2
  30. package/client/organizations/recipientAdmission.js.map +1 -1
  31. package/client/organizations/rosterAdmissionEvidence.js +1 -1
  32. package/client/organizations/rosterAdmissionEvidence.js.map +1 -1
  33. package/client/runtime/apiVersion.js +1 -1
  34. package/client/runtime/apiVersion.js.map +1 -1
  35. package/client/runtime/containerContentsRuntime.d.ts +8 -0
  36. package/client/runtime/containerContentsRuntime.js +14 -0
  37. package/client/runtime/containerContentsRuntime.js.map +1 -0
  38. package/client/runtime/database.js +1 -1
  39. package/client/runtime/database.js.map +1 -1
  40. package/client/runtime/documentsRuntime.d.ts +5 -0
  41. package/client/runtime/documentsRuntime.js +10 -0
  42. package/client/runtime/documentsRuntime.js.map +1 -0
  43. package/client/runtime/events.js +1 -1
  44. package/client/runtime/events.js.map +1 -1
  45. package/client/runtime/network.js +1 -1
  46. package/client/runtime/network.js.map +1 -1
  47. package/client/runtime/runtimeIdentityResolution.js +1 -1
  48. package/client/runtime/runtimeIdentityResolution.js.map +1 -1
  49. package/client/runtime/syncBillingGate.js +1 -1
  50. package/client/runtime/syncBillingGate.js.map +1 -1
  51. package/client/runtime/workflowRuntime.d.ts +5 -2
  52. package/client/runtime/workflowRuntime.js +6 -2
  53. package/client/runtime/workflowRuntime.js.map +1 -1
  54. package/client/securityIncidents/index.d.ts +1 -1
  55. package/client/securityIncidents/index.js +2 -2
  56. package/client/securityIncidents/index.js.map +1 -1
  57. package/client/session/index.js +1 -1
  58. package/client/session/index.js.map +1 -1
  59. package/client/session/sessionLoginRefusal.js +1 -1
  60. package/client/session/sessionLoginRefusal.js.map +1 -1
  61. package/client/session/sessionRootAuthority.js +1 -1
  62. package/client/session/sessionRootAuthority.js.map +1 -1
  63. package/data/containers/shared/authorAccess.d.ts +1 -1
  64. package/data/containers/shared/authorAccess.js.map +1 -1
  65. package/data/containers/shared/principalPolicies.js.map +1 -1
  66. package/data/containers/shared/types.d.ts +1 -1
  67. package/data/containers/shared/types.js.map +1 -1
  68. package/data/documents/shared/projection/freshProjectionRetry.js +1 -1
  69. package/data/documents/shared/projection/freshProjectionRetry.js.map +1 -1
  70. package/data/keyingProjectionVerification/checkpoints/accessManifestCheckpointEnforcement.js.map +1 -1
  71. package/data/keyingProjectionVerification/checkpoints/checkpointContext.d.ts +1 -1
  72. package/data/keyingProjectionVerification/checkpoints/checkpointContext.js +1 -1
  73. package/data/keyingProjectionVerification/checkpoints/checkpointContext.js.map +1 -1
  74. package/data/keyingProjectionVerification/checkpoints/heldContainerHeads.js.map +1 -0
  75. package/data/keyingProjectionVerification/container/containerProjectionVerification.d.ts +1 -1
  76. package/data/keyingProjectionVerification/container/containerProjectionVerification.js.map +1 -1
  77. package/data/keyingProjectionVerification/documentPurge/documentPurgePrincipalEvidence.js +1 -1
  78. package/data/keyingProjectionVerification/documentPurge/documentPurgePrincipalEvidence.js.map +1 -1
  79. package/data/keyingProjectionVerification/error.js +1 -57
  80. package/data/keyingProjectionVerification/error.js.map +1 -1
  81. package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js +1 -1
  82. package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js.map +1 -1
  83. package/data/keyingProjectionVerification/principalPolicy/principalPolicyCache.js +2 -2
  84. package/data/keyingProjectionVerification/principalPolicy/principalPolicyCache.js.map +1 -1
  85. package/data/keyingProjectionVerification/principalPolicy/principalPolicySigners.js +2 -2
  86. package/data/keyingProjectionVerification/principalPolicy/principalPolicySigners.js.map +1 -1
  87. package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.d.ts +1 -1
  88. package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.js +4 -4
  89. package/data/keyingProjectionVerification/principalPolicy/principalPolicyVerification.js.map +1 -1
  90. package/data/keyingProjectionVerification/types.d.ts +1 -1
  91. package/data/keyingProjectionVerification/types.js.map +1 -1
  92. package/data/persistence/container-contents/documentContainerProjectionPersistence.d.ts +6 -2
  93. package/data/persistence/container-contents/documentContainerProjectionPersistence.js +10 -1
  94. package/data/persistence/container-contents/documentContainerProjectionPersistence.js.map +1 -1
  95. package/data/persistence/documents/documentDeletionPort.d.ts +28 -0
  96. package/data/persistence/documents/documentDeletionPort.js +2 -0
  97. package/data/persistence/documents/documentDeletionPort.js.map +1 -0
  98. package/data/persistence/documents/documentsPersistence.d.ts +1 -0
  99. package/data/persistence/documents/documentsPersistence.js.map +1 -1
  100. package/data/persistence/documents/internal/documentDeletionPersistence.js +7 -7
  101. package/data/persistence/documents/internal/documentDeletionPersistence.js.map +1 -1
  102. package/data/persistence/documents/types.d.ts +2 -15
  103. package/data/persistence/documents/types.js.map +1 -1
  104. package/data/persistence/keyingCheckpoints/keyingCheckpointAdvancePersistence.js +1 -1
  105. package/data/persistence/keyingCheckpoints/keyingCheckpointAdvancePersistence.js.map +1 -1
  106. package/data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.js +1 -1
  107. package/data/persistence/keyingCheckpoints/locallyAcknowledgedCheckpointPersistence.js.map +1 -1
  108. package/data/persistence/keyingCheckpoints/organizationReplacementCheckpointPersistence.js +1 -1
  109. package/data/persistence/keyingCheckpoints/organizationReplacementCheckpointPersistence.js.map +1 -1
  110. package/data/persistence/organizationFounderPersistence.js +1 -1
  111. package/data/persistence/organizationFounderPersistence.js.map +1 -1
  112. package/data/persistence/principalCurrentAcknowledgementPersistence.js +1 -1
  113. package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -1
  114. package/data/persistence/principalPolicy/heldPrincipalState.js +1 -1
  115. package/data/persistence/principalPolicy/heldPrincipalState.js.map +1 -1
  116. package/data/persistence/principalPolicy/locallyAcknowledgedPrincipalPolicyPersistence.js +1 -1
  117. package/data/persistence/principalPolicy/locallyAcknowledgedPrincipalPolicyPersistence.js.map +1 -1
  118. package/data/persistence/principalPolicy/principalPolicyBundleRepository.js.map +1 -1
  119. package/data/persistence/principalPolicy/principalPolicyReferenceCheckpoint.js +1 -1
  120. package/data/persistence/principalPolicy/principalPolicyReferenceCheckpoint.js.map +1 -1
  121. package/data/persistence/principalPolicy/principalPolicyReferenceIndexPersistence.js +1 -1
  122. package/data/persistence/principalPolicy/principalPolicyReferenceIndexPersistence.js.map +1 -1
  123. package/data/persistence/principalPolicy/principalPolicyReferencePersistence.js +1 -1
  124. package/data/persistence/principalPolicy/principalPolicyReferencePersistence.js.map +1 -1
  125. package/data/principals/organizationGroupRoles.js +1 -1
  126. package/data/principals/organizationGroupRoles.js.map +1 -1
  127. package/data/shared/securityIncidents.d.ts +18 -1
  128. package/data/shared/securityIncidents.js +58 -1
  129. package/data/shared/securityIncidents.js.map +1 -1
  130. package/index.d.ts +5 -5
  131. package/index.js +3 -3
  132. package/index.js.map +1 -1
  133. package/package.json +1 -1
  134. package/stores/container-contents/hydration/backgroundHydration.js +1 -1
  135. package/stores/container-contents/hydration/backgroundHydration.js.map +1 -1
  136. package/stores/container-contents/operations/reportShareFailure.js +1 -1
  137. package/stores/container-contents/operations/reportShareFailure.js.map +1 -1
  138. package/stores/container-contents/operations/shareOperations.js +1 -1
  139. package/stores/container-contents/operations/shareOperations.js.map +1 -1
  140. package/stores/container-contents/systemContainers/systemContainerHydration.js +1 -1
  141. package/stores/container-contents/systemContainers/systemContainerHydration.js.map +1 -1
  142. package/stores/documents/documentStore/attachmentUpload/attachmentUploadAttempt.js +1 -1
  143. package/stores/documents/documentStore/attachmentUpload/attachmentUploadAttempt.js.map +1 -1
  144. package/stores/documents/documentStore/persistence.js +1 -0
  145. package/stores/documents/documentStore/persistence.js.map +1 -1
  146. package/stores/documents/documentStore/sync/index.js +1 -1
  147. package/stores/documents/documentStore/sync/index.js.map +1 -1
  148. package/stores/documents/documentStore/sync/syncRequest.js +1 -0
  149. package/stores/documents/documentStore/sync/syncRequest.js.map +1 -1
  150. package/workflows/blobs/hydration/hydrationResults.js +2 -1
  151. package/workflows/blobs/hydration/hydrationResults.js.map +1 -1
  152. package/workflows/blobs/verification/attachmentDecryptor.js +1 -1
  153. package/workflows/blobs/verification/attachmentDecryptor.js.map +1 -1
  154. package/workflows/container-contents/container-state/create/createAdoption.js +1 -1
  155. package/workflows/container-contents/container-state/create/createAdoption.js.map +1 -1
  156. package/workflows/container-contents/container-state/create/createIntentSync.js +1 -1
  157. package/workflows/container-contents/container-state/create/createIntentSync.js.map +1 -1
  158. package/workflows/container-contents/container-state/move/moveIntentSync.js +1 -1
  159. package/workflows/container-contents/container-state/move/moveIntentSync.js.map +1 -1
  160. package/workflows/container-contents/container-state/organizationHost.d.ts +54 -0
  161. package/workflows/container-contents/container-state/organizationHost.js +2 -0
  162. package/workflows/container-contents/container-state/organizationHost.js.map +1 -0
  163. package/workflows/container-contents/container-state/purge/purgeTreeScope.js +1 -1
  164. package/workflows/container-contents/container-state/purge/purgeTreeScope.js.map +1 -1
  165. package/workflows/container-contents/container-state/remote.js +2 -4
  166. package/workflows/container-contents/container-state/remote.js.map +1 -1
  167. package/workflows/container-contents/container-state/share/groupGrantVerification.js +1 -2
  168. package/workflows/container-contents/container-state/share/groupGrantVerification.js.map +1 -1
  169. package/workflows/container-contents/container-state/share/groupShareEpoch.js +1 -2
  170. package/workflows/container-contents/container-state/share/groupShareEpoch.js.map +1 -1
  171. package/workflows/container-contents/container-state/types.js.map +1 -1
  172. package/workflows/container-contents/documentLinks/index.js +1 -1
  173. package/workflows/container-contents/documentLinks/index.js.map +1 -1
  174. package/workflows/container-contents/documentMove/documentMoveIntentSync.js +1 -1
  175. package/workflows/container-contents/documentMove/documentMoveIntentSync.js.map +1 -1
  176. package/workflows/container-contents/index.d.ts +1 -0
  177. package/workflows/container-contents/index.js.map +1 -1
  178. package/workflows/container-contents/info/documentInfo.d.ts +1 -1
  179. package/workflows/container-contents/info/documentInfo.js +1 -1
  180. package/workflows/container-contents/info/documentInfo.js.map +1 -1
  181. package/workflows/container-contents/metadata/metadataSyncErrors.js +1 -1
  182. package/workflows/container-contents/metadata/metadataSyncErrors.js.map +1 -1
  183. package/workflows/container-contents/remoteHydration/destination/destinationRootReload.js +1 -2
  184. package/workflows/container-contents/remoteHydration/destination/destinationRootReload.js.map +1 -1
  185. package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js +3 -4
  186. package/workflows/container-contents/remoteHydration/destination/verifiedDestination.js.map +1 -1
  187. package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js +1 -1
  188. package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map +1 -1
  189. package/workflows/container-contents/remoteHydration/types.d.ts +1 -1
  190. package/workflows/container-contents/remoteHydration/types.js.map +1 -1
  191. package/workflows/container-contents/runtime.d.ts +5 -0
  192. package/workflows/container-contents/runtime.js +3 -0
  193. package/workflows/container-contents/runtime.js.map +1 -1
  194. package/workflows/container-contents/syncPause/documentRemoval.js +2 -0
  195. package/workflows/container-contents/syncPause/documentRemoval.js.map +1 -1
  196. package/workflows/container-contents/tombstones/documentPurge.js +5 -2
  197. package/workflows/container-contents/tombstones/documentPurge.js.map +1 -1
  198. package/workflows/container-contents/tombstones/documentTombstoneEvidence.js +1 -1
  199. package/workflows/container-contents/tombstones/documentTombstoneEvidence.js.map +1 -1
  200. package/workflows/containers/child/create/index.js.map +1 -1
  201. package/workflows/containers/child/move/moveRequest.js.map +1 -1
  202. package/workflows/containers/child/move/moveWraps.js.map +1 -1
  203. package/workflows/containers/child/mutationRequestCore.js.map +1 -1
  204. package/workflows/containers/child/mutationSubmit.d.ts +1 -1
  205. package/workflows/containers/child/mutationSubmit.js +1 -1
  206. package/workflows/containers/child/mutationSubmit.js.map +1 -1
  207. package/workflows/containers/child/recite.js +1 -1
  208. package/workflows/containers/child/recite.js.map +1 -1
  209. package/workflows/containers/child/recitePlan.js.map +1 -1
  210. package/workflows/containers/child/rekey/carriedDescendantRekeys.d.ts +1 -1
  211. package/workflows/containers/child/rekey/carriedDescendantRekeys.js.map +1 -1
  212. package/workflows/containers/child/rekey/index.d.ts +1 -1
  213. package/workflows/containers/child/rekey/index.js.map +1 -1
  214. package/workflows/containers/child/revoke.d.ts +1 -1
  215. package/workflows/containers/child/revoke.js.map +1 -1
  216. package/workflows/containers/child/rotation/replacementPrincipalPolicyReferences.js.map +1 -1
  217. package/workflows/containers/child/rotation/rotationPrincipalPolicies.js.map +1 -1
  218. package/workflows/containers/child/rotation/rotationWraps.js.map +1 -1
  219. package/workflows/containers/child/share/sharePlanCore.d.ts +1 -1
  220. package/workflows/containers/child/share/sharePlanCore.js.map +1 -1
  221. package/workflows/containers/rematerialization/acknowledgePrincipalContainerRematerialization.js +1 -1
  222. package/workflows/containers/rematerialization/acknowledgePrincipalContainerRematerialization.js.map +1 -1
  223. package/workflows/containers/rematerialization/authoredPrincipalPolicyWarmer.js +1 -1
  224. package/workflows/containers/rematerialization/authoredPrincipalPolicyWarmer.js.map +1 -1
  225. package/workflows/containers/rematerialization/principalContainerRematerializationPlanning.js.map +1 -1
  226. package/workflows/containers/rematerialization/principalContainerRematerializationTargets.js.map +1 -1
  227. package/workflows/documents/documentMutationCommit.d.ts +2 -1
  228. package/workflows/documents/documentMutationCommit.js +1 -0
  229. package/workflows/documents/documentMutationCommit.js.map +1 -1
  230. package/workflows/documents/documentPersistGuards.js +2 -1
  231. package/workflows/documents/documentPersistGuards.js.map +1 -1
  232. package/workflows/documents/linkSet/linkSetAuthority.js.map +1 -1
  233. package/workflows/documents/purge/persistedDocumentRemoval.d.ts +2 -1
  234. package/workflows/documents/purge/persistedDocumentRemoval.js +2 -2
  235. package/workflows/documents/purge/persistedDocumentRemoval.js.map +1 -1
  236. package/workflows/documents/runtime.d.ts +5 -0
  237. package/workflows/documents/runtime.js +1 -0
  238. package/workflows/documents/runtime.js.map +1 -1
  239. package/workflows/documents/sync/syncSubmittedResult.js +1 -1
  240. package/workflows/documents/sync/syncSubmittedResult.js.map +1 -1
  241. package/workflows/documents/syncPlan/syncContentKeys.js +1 -1
  242. package/workflows/documents/syncPlan/syncContentKeys.js.map +1 -1
  243. package/workflows/organizations/containerContentsHost.js +14 -0
  244. package/workflows/organizations/containerContentsHost.js.map +1 -0
  245. package/workflows/organizations/currentOrganizationAuthority.d.ts +1 -1
  246. package/workflows/organizations/currentOrganizationAuthority.js +1 -1
  247. package/workflows/organizations/currentOrganizationAuthority.js.map +1 -1
  248. package/workflows/organizations/groupMetadata/currentGroupMetadataAuthority.js +1 -1
  249. package/workflows/organizations/groupMetadata/currentGroupMetadataAuthority.js.map +1 -1
  250. package/workflows/organizations/groupMetadata/groupMetadataBinding.js.map +1 -1
  251. package/workflows/organizations/groupMetadata/groupMetadataContainerAuthority.js +2 -2
  252. package/workflows/organizations/groupMetadata/groupMetadataContainerAuthority.js.map +1 -1
  253. package/workflows/organizations/groupMetadata/groupMetadataRootBinding.js +2 -2
  254. package/workflows/organizations/groupMetadata/groupMetadataRootBinding.js.map +1 -1
  255. package/workflows/organizations/groupNames/groupNameUniqueness.js +2 -2
  256. package/workflows/organizations/groupNames/groupNameUniqueness.js.map +1 -1
  257. package/workflows/organizations/groupNames/organizationGroupNamePolicies.js +2 -2
  258. package/workflows/organizations/groupNames/organizationGroupNamePolicies.js.map +1 -1
  259. package/workflows/organizations/groupPolicy/currentGroupPolicyMutationContext.js +1 -1
  260. package/workflows/organizations/groupPolicy/currentGroupPolicyMutationContext.js.map +1 -1
  261. package/workflows/organizations/groupPolicy/groupPolicyMutationContext.js +1 -1
  262. package/workflows/organizations/groupPolicy/groupPolicyMutationContext.js.map +1 -1
  263. package/workflows/organizations/groupPolicy/groupPolicyRequests.js +1 -1
  264. package/workflows/organizations/groupPolicy/groupPolicyRequests.js.map +1 -1
  265. package/workflows/organizations/groupPolicy/groupPolicyVerification.js +1 -1
  266. package/workflows/organizations/groupPolicy/groupPolicyVerification.js.map +1 -1
  267. package/workflows/organizations/groupShare/currentSharePrincipalPolicy.js +1 -1
  268. package/workflows/organizations/groupShare/currentSharePrincipalPolicy.js.map +1 -1
  269. package/workflows/organizations/groupShare/sharePrincipalPolicy.js +2 -2
  270. package/workflows/organizations/groupShare/sharePrincipalPolicy.js.map +1 -1
  271. package/workflows/organizations/groups/createCurrentOrganizationGroup.js +1 -1
  272. package/workflows/organizations/groups/createCurrentOrganizationGroup.js.map +1 -1
  273. package/workflows/organizations/groups/organizationGroupDirectory.js +1 -1
  274. package/workflows/organizations/groups/organizationGroupDirectory.js.map +1 -1
  275. package/workflows/organizations/memberships/leaveRequestMembersEvidence.js +1 -1
  276. package/workflows/organizations/memberships/leaveRequestMembersEvidence.js.map +1 -1
  277. package/workflows/organizations/policyHistory/loadPolicyHistoryDetails.js +1 -1
  278. package/workflows/organizations/policyHistory/loadPolicyHistoryDetails.js.map +1 -1
  279. package/workflows/organizations/policyHistory/organizationPolicyHistoryDetails.js.map +1 -1
  280. package/workflows/organizations/policyHistory/organizationPolicyHistoryVerification.js +1 -1
  281. package/workflows/organizations/policyHistory/organizationPolicyHistoryVerification.js.map +1 -1
  282. package/workflows/organizations/principalMutations/acknowledgedDirectoryBindings.js +1 -1
  283. package/workflows/organizations/principalMutations/acknowledgedDirectoryBindings.js.map +1 -1
  284. package/workflows/organizations/principalMutations/currentOrganizationMutationAuthority.js +1 -1
  285. package/workflows/organizations/principalMutations/currentOrganizationMutationAuthority.js.map +1 -1
  286. package/workflows/organizations/principalMutations/currentOrganizationMutationRetention.js +1 -1
  287. package/workflows/organizations/principalMutations/currentOrganizationMutationRetention.js.map +1 -1
  288. package/workflows/organizations/principalMutations/runtimeCurrentGroupMutation.js +1 -1
  289. package/workflows/organizations/principalMutations/runtimeCurrentGroupMutation.js.map +1 -1
  290. package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js +1 -1
  291. package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js.map +1 -1
  292. package/workflows/organizations/principalPolicy/principalPolicyRecipients.js +1 -1
  293. package/workflows/organizations/principalPolicy/principalPolicyRecipients.js.map +1 -1
  294. package/workflows/organizations/principalPolicy/principalPolicyRequest.js +1 -1
  295. package/workflows/organizations/principalPolicy/principalPolicyRequest.js.map +1 -1
  296. package/workflows/principals/acknowledgements/acknowledgedPrincipalPredecessor.js +2 -2
  297. package/workflows/principals/acknowledgements/acknowledgedPrincipalPredecessor.js.map +1 -1
  298. package/workflows/principals/acknowledgements/initialPrincipalCurrentPublication.js +1 -1
  299. package/workflows/principals/acknowledgements/initialPrincipalCurrentPublication.js.map +1 -1
  300. package/workflows/principals/acknowledgements/reconcileAcknowledgedPrincipalCurrent.js +1 -1
  301. package/workflows/principals/acknowledgements/reconcileAcknowledgedPrincipalCurrent.js.map +1 -1
  302. package/workflows/principals/externalAdminPolicy.d.ts +1 -1
  303. package/workflows/principals/externalAdminPolicy.js +2 -2
  304. package/workflows/principals/externalAdminPolicy.js.map +1 -1
  305. package/workflows/principals/historyRecovery/principalHistoryRecoveryAuthority.js +1 -1
  306. package/workflows/principals/historyRecovery/principalHistoryRecoveryAuthority.js.map +1 -1
  307. package/workflows/principals/historyRecovery/principalHistoryRecoveryReferences.js +1 -1
  308. package/workflows/principals/historyRecovery/principalHistoryRecoveryReferences.js.map +1 -1
  309. package/workflows/principals/historyRecovery/recoverPrincipalPolicyHistory.js +1 -1
  310. package/workflows/principals/historyRecovery/recoverPrincipalPolicyHistory.js.map +1 -1
  311. package/workflows/principals/historyRecovery/recoverScopedPrincipalPolicyHistory.js +1 -1
  312. package/workflows/principals/historyRecovery/recoverScopedPrincipalPolicyHistory.js.map +1 -1
  313. package/workflows/principals/policyCache/index.d.ts +1 -1
  314. package/workflows/principals/policyCache/index.js +3 -2
  315. package/workflows/principals/policyCache/index.js.map +1 -1
  316. package/workflows/principals/policyCache/principalPolicyCacheValidation.js +1 -1
  317. package/workflows/principals/policyCache/principalPolicyCacheValidation.js.map +1 -1
  318. package/workflows/principals/policyCache/principalPolicyOrganizationScope.js +2 -2
  319. package/workflows/principals/policyCache/principalPolicyOrganizationScope.js.map +1 -1
  320. package/workflows/principals/policyVerification.js +1 -1
  321. package/workflows/principals/policyVerification.js.map +1 -1
  322. package/workflows/principals/principalPolicyService.js +1 -1
  323. package/workflows/principals/principalPolicyService.js.map +1 -1
  324. package/workflows/principals/publicHistory/publicPrincipalHistoryAuthority.js +1 -1
  325. package/workflows/principals/publicHistory/publicPrincipalHistoryAuthority.js.map +1 -1
  326. package/workflows/principals/publicHistory/publicPrincipalHistoryProgress.js +1 -1
  327. package/workflows/principals/publicHistory/publicPrincipalHistoryProgress.js.map +1 -1
  328. package/workflows/principals/publicHistory/publicProjectionDirectory.js +1 -1
  329. package/workflows/principals/publicHistory/publicProjectionDirectory.js.map +1 -1
  330. package/workflows/principals/publicHistory/publicProjectionPrincipal.js +1 -1
  331. package/workflows/principals/publicHistory/publicProjectionPrincipal.js.map +1 -1
  332. package/workflows/principals/publicHistory/recoverProjectionPolicyHistory.js +1 -1
  333. package/workflows/principals/publicHistory/recoverProjectionPolicyHistory.js.map +1 -1
  334. package/workflows/principals/publicHistory/recoverPublicPrincipalHistory.js +2 -2
  335. package/workflows/principals/publicHistory/recoverPublicPrincipalHistory.js.map +1 -1
  336. package/workflows/principals/publicHistory/selectPublicPrincipalHistory.js +1 -1
  337. package/workflows/principals/publicHistory/selectPublicPrincipalHistory.js.map +1 -1
  338. package/workflows/principals/recoveryOperation/principalRecoveryDirectory.d.ts +1 -1
  339. package/workflows/principals/recoveryOperation/principalRecoveryDirectory.js +1 -1
  340. package/workflows/principals/recoveryOperation/principalRecoveryDirectory.js.map +1 -1
  341. package/workflows/principals/recoveryOperation/principalRecoveryLocalPreference.js +1 -1
  342. package/workflows/principals/recoveryOperation/principalRecoveryLocalPreference.js.map +1 -1
  343. package/workflows/principals/recoveryOperation/principalRecoveryMemo.js +1 -1
  344. package/workflows/principals/recoveryOperation/principalRecoveryMemo.js.map +1 -1
  345. package/workflows/principals/runtimePolicyRecovery.d.ts +1 -1
  346. package/workflows/principals/runtimePolicyRecovery.js +1 -1
  347. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  348. package/workflows/principals/runtimeProjectionPolicyRecovery.js +1 -1
  349. package/workflows/principals/runtimeProjectionPolicyRecovery.js.map +1 -1
  350. package/workflows/registration/organizationProvisioning.js +2 -2
  351. package/workflows/registration/organizationProvisioning.js.map +1 -1
  352. package/workflows/registration/persistRegistrationBootstrap.js +2 -0
  353. package/workflows/registration/persistRegistrationBootstrap.js.map +1 -1
  354. package/workflows/registration/provisionedPrincipalHistory.js +1 -1
  355. package/workflows/registration/provisionedPrincipalHistory.js.map +1 -1
  356. package/workflows/registration/registrationAccessHeadPersistence.js +1 -1
  357. package/workflows/registration/registrationAccessHeadPersistence.js.map +1 -1
  358. package/data/containers/shared/heldContainerHeads.js.map +0 -1
  359. /package/data/{containers/shared → keyingProjectionVerification/checkpoints}/heldContainerHeads.js +0 -0
  360. /package/data/persistence/{principalKeys → principalContracts}/principalGrantRetirementPersistence.js +0 -0
  361. /package/data/persistence/{principalKeys → principalContracts}/principalGrantRetirementPersistence.js.map +0 -0
  362. /package/data/{principals → principalContracts}/organizationAuthorityDescriptor.d.ts +0 -0
  363. /package/data/{principals → principalContracts}/organizationAuthorityDescriptor.js +0 -0
  364. /package/data/{principals → principalContracts}/organizationAuthorityDescriptor.js.map +0 -0
  365. /package/data/{principals → principalContracts}/principalIdentityCommitments.js +0 -0
  366. /package/data/{principals → principalContracts}/principalIdentityCommitments.js.map +0 -0
  367. /package/data/{principals → principalContracts}/principalPolicyAdminSigners.js +0 -0
  368. /package/data/{principals → principalContracts}/principalPolicyAdminSigners.js.map +0 -0
  369. /package/data/{principals → principalContracts}/principalPolicyEvidence.d.ts +0 -0
  370. /package/data/{principals → principalContracts}/principalPolicyEvidence.js +0 -0
  371. /package/data/{principals → principalContracts}/principalPolicyEvidence.js.map +0 -0
  372. /package/data/{principals → principalContracts}/principalPolicyStates.js +0 -0
  373. /package/data/{principals → principalContracts}/principalPolicyStates.js.map +0 -0
  374. /package/{client/runtime → data/shared}/listenerSet.js +0 -0
  375. /package/{client/runtime → data/shared}/listenerSet.js.map +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"organizationGroupDirectory.js","sourceRoot":"","sources":["organizationGroupDirectory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,yBAAyB,EACzB,mCAAmC,EAGnC,kBAAkB,EAClB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASpD,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,+BAA+B,EAAE,MAAM,2EAA2E,CAAC;AAC5H,OAAO,EACL,qCAAqC,E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,MAAM,6BAA6B,CAAC;QACvD,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ,EAAE,MAAM,CAAC,KAAK;QACtB,SAAS,EAAE,YAAY,CAAC,SAAS;KAClC,CAAC,CAAC;IACH,MAAM,YAAY,GAAG,MAAM,4BAA4B,CAAC;QACtD,aAAa,EAAE,KAAK,CAAC,mBAAmB,CAAC,MAAM;QAC/C,YAAY,EAAE,MAAM,uBAAuB,CAAC,mBAAmB,CAAC;QAChE,OAAO,EAAE,mBAAmB;QAC5B,QAAQ,EAAE,MAAM,CAAC,kBAAkB;KACpC,CAAC,CAAC;IACH,MAAM,IAAI,+BAA+B,CACvC,KAAK,CAAC,OAAO,CACd,CAAC,gDAAgD,CAAC;QACjD,OAAO,EAAE;YACP,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE;YAC5D,YAAY;SACb;QACD,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAC;IACH,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AACrD,CAAC","sourcesContent":["import {\n buildPrincipalStateSigningInput,\n generateKemSeedAndKeyPair,\n normalizePrincipalProjectionMembers,\n type ReferencedPrincipalHead,\n type SigningKeyPair,\n signPrincipalState,\n toFingerprint,\n} from \"@tearleads/crypto\";\nimport { bytesToBase64 } from \"@tearleads/encoding\";\nimport type {\n PrincipalProjectionMemberRequest,\n PutPrincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n OrganizationGroupSummaryResponse,\n PrincipalPolicyBundleResponse,\n} from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { PrincipalPolicyBundleRepository } from \"../../../data/persistence/principalPolicy/principalPolicyBundleRepository\";\nimport {\n encodeOrganizationAuthorityDescriptor,\n normalizeOrganizationGroupHeads,\n type OrganizationAuthorityDescriptor,\n type OrganizationGroupHead,\n} from \"../../../data/principals/organizationAuthorityDescriptor\";\nimport type { SecurityIncidentReporter } from \"../../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type {\n TrustedUserIdentity,\n TrustedUserIdentityResolver,\n} from \"../../../data/trustedUserIdentity\";\nimport type { loadOrganizationExternalAdminPolicy } from \"../../principals/externalAdminPolicy\";\nimport { assertGroupNameUniqueInDirectory } from \"../groupNames/groupNameUniqueness\";\nimport {\n acknowledgeGroupPolicyBundle,\n acknowledgeInitialGroupPolicy,\n} from \"../groupPolicy/groupPolicyMutationAcknowledgement\";\nimport type { OrganizationPrincipalPolicyApi } from \"../groupPolicy/groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"../groupPolicy/groupPolicyMutationHead\";\nimport { rewrapProjectionMemberEnvelopes } from \"../principalPolicy/principalPolicyRecipients\";\nimport type {\n buildInitialGroupPolicyRequest,\n GroupPolicyNameReader,\n} from \"../principalPolicy/principalPolicyRequest\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"../trustedOrganizationUsers\";\n\nfunction organizationGroupHead(\n head: ReferencedPrincipalHead,\n): OrganizationGroupHead {\n if (head.principalType !== \"group\") {\n throw new Error(\"Organization directory can contain only group heads\");\n }\n return { ...head, principalType: \"group\" };\n}\n\nexport function replaceOrganizationGroupHead(input: {\n readonly descriptor: OrganizationAuthorityDescriptor;\n readonly nextHead: ReferencedPrincipalHead;\n}): OrganizationGroupHead[] {\n const nextHead = organizationGroupHead(input.nextHead);\n return normalizeOrganizationGroupHeads([\n ...input.descriptor.groupHeads.filter(\n (head) => head.principalId !== nextHead.principalId,\n ),\n nextHead,\n ]);\n}\n\nexport function removeOrganizationGroupHead(input: {\n readonly descriptor: OrganizationAuthorityDescriptor;\n readonly groupId: string;\n}): OrganizationGroupHead[] {\n if (\n input.groupId === input.descriptor.adminGroupId ||\n input.groupId === input.descriptor.memberGroupId\n ) {\n throw new Error(\"Built-in groups cannot be removed from the directory\");\n }\n const groupHeads = input.descriptor.groupHeads.filter(\n (head) => head.principalId !== input.groupId,\n );\n if (groupHeads.length === input.descriptor.groupHeads.length) {\n throw new Error(\"Organization directory does not commit the deleted group\");\n }\n return normalizeOrganizationGroupHeads(groupHeads);\n}\n\nexport async function buildOrganizationGroupDirectoryPolicyRequest(input: {\n readonly adminProjection: readonly PrincipalProjectionMemberRequest[];\n readonly adminUsers: readonly TrustedUserIdentity[];\n readonly currentPolicy: Pick<PrincipalPolicyBundleResponse, \"currentState\">;\n readonly descriptor: OrganizationAuthorityDescriptor;\n readonly groupHeads: readonly OrganizationGroupHead[];\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<PutPrincipalPolicyRequest> {\n const projection = normalizePrincipalProjectionMembers(input.adminProjection);\n if (\n projection.length === 0 ||\n projection.some((member) => member.role !== \"admin\")\n ) {\n throw new Error(\"Organization policy must mirror the Admins projection\");\n }\n const organizationKem = generateKemSeedAndKeyPair();\n const memberEnvelopes = await rewrapProjectionMemberEnvelopes({\n projection,\n secretKey: organizationKem.secretKey,\n users: input.adminUsers,\n });\n const payloadCiphertext = encodeOrganizationAuthorityDescriptor({\n ...input.descriptor,\n groupHeads: input.groupHeads,\n });\n const state = await signPrincipalState(\n await buildPrincipalStateSigningInput({\n principalType: \"organization\",\n principalId: input.descriptor.organizationId,\n version: input.currentPolicy.currentState.version + 1,\n prevStateHash: input.currentPolicy.currentState.stateHash,\n keyEpoch: input.currentPolicy.currentState.keyEpoch + 1,\n encapsulationPublicKey: bytesToBase64(organizationKem.publicKey),\n keyFingerprint: await toFingerprint(organizationKem.publicKey),\n members: projection.map((member) => ({ userId: member.userId })),\n memberEnvelopes,\n projection,\n grants: [],\n payloadCiphertext,\n externalAuthority: null,\n signedAt: new Date().toISOString(),\n signerUserId: input.signerUserId,\n signerUserKeyFingerprint: input.signingFingerprint,\n }),\n input.signingKeyPair.signingPrivateKey,\n );\n\n return {\n encryptedPayload: {\n cipherSuite: \"aes-256-gcm\",\n ciphertext: payloadCiphertext,\n ciphertextHash: state.payloadCiphertextHash,\n },\n grants: [],\n memberEnvelopes,\n projection,\n state,\n };\n}\n\nexport async function commitCreatedGroupToDirectory(input: {\n readonly stillCurrent?: (() => boolean) | undefined;\n readonly name: string;\n readonly readEncryptedName?: GroupPolicyNameReader;\n readonly apiClient: OrganizationPrincipalPolicyApi;\n readonly execSql: ExecSql;\n readonly externalAdminPolicy: NonNullable<\n Awaited<ReturnType<typeof loadOrganizationExternalAdminPolicy>>\n >;\n readonly organizationId: string;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly request: Awaited<ReturnType<typeof buildInitialGroupPolicyRequest>>;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<{\n readonly group: OrganizationGroupSummaryResponse;\n readonly head: ReferencedPrincipalHead;\n}> {\n assertProjectionVerificationCurrent(input.stillCurrent);\n // Signed group names are unique per organization; refuse a collision before\n // anything reaches the server.\n await assertGroupNameUniqueInDirectory({\n apiClient: input.apiClient,\n descriptor: input.externalAdminPolicy.descriptor,\n execSql: input.execSql,\n externalAuthority: input.externalAdminPolicy.externalAuthority,\n name: input.name,\n readEncryptedName: input.readEncryptedName,\n organizationId: input.organizationId,\n reportSecurityIncident: input.reportSecurityIncident,\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n stillCurrent: input.stillCurrent,\n });\n const expectedHead = await groupPolicyMutationHead(\n input.request.initialGroupPolicy,\n );\n const adminProjection =\n input.externalAdminPolicy.adminBundle.currentProjection;\n const adminUsers = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n });\n const organizationRequest =\n await buildOrganizationGroupDirectoryPolicyRequest({\n adminProjection,\n adminUsers,\n currentPolicy: input.externalAdminPolicy.bundle,\n descriptor: input.externalAdminPolicy.descriptor,\n groupHeads: [\n ...input.externalAdminPolicy.descriptor.groupHeads,\n organizationGroupHead(expectedHead),\n ],\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n const stored = await input.apiClient.createOrganizationGroup(\n input.organizationId,\n { ...input.request, organizationPolicy: organizationRequest },\n );\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!stored) {\n throw new Error(\"Group could not be created\");\n }\n const acknowledged = await acknowledgeInitialGroupPolicy({\n organizationId: input.organizationId,\n request: input.request,\n response: stored.group,\n stateHash: expectedHead.stateHash,\n });\n const organization = await acknowledgeGroupPolicyBundle({\n currentPolicy: input.externalAdminPolicy.bundle,\n expectedHead: await groupPolicyMutationHead(organizationRequest),\n request: organizationRequest,\n response: stored.organizationPolicy,\n });\n await new PrincipalPolicyBundleRepository(\n input.execSql,\n ).persistLocallyAcknowledgedPrincipalPolicyBundles({\n entries: [\n { bundle: acknowledged.bundle, policy: acknowledged.policy },\n organization,\n ],\n organizationId: input.organizationId,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n return { group: stored.group, head: expectedHead };\n}\n"]}
1
+ {"version":3,"file":"organizationGroupDirectory.js","sourceRoot":"","sources":["organizationGroupDirectory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,yBAAyB,EACzB,mCAAmC,EAGnC,kBAAkB,EAClB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASpD,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,O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M,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,YAAY,GAAG,MAAM,6BAA6B,CAAC;QACvD,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ,EAAE,MAAM,CAAC,KAAK;QACtB,SAAS,EAAE,YAAY,CAAC,SAAS;KAClC,CAAC,CAAC;IACH,MAAM,YAAY,GAAG,MAAM,4BAA4B,CAAC;QACtD,aAAa,EAAE,KAAK,CAAC,mBAAmB,CAAC,MAAM;QAC/C,YAAY,EAAE,MAAM,uBAAuB,CAAC,mBAAmB,CAAC;QAChE,OAAO,EAAE,mBAAmB;QAC5B,QAAQ,EAAE,MAAM,CAAC,kBAAkB;KACpC,CAAC,CAAC;IACH,MAAM,IAAI,+BAA+B,CACvC,KAAK,CAAC,OAAO,CACd,CAAC,gDAAgD,CAAC;QACjD,OAAO,EAAE;YACP,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE;YAC5D,YAAY;SACb;QACD,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAC;IACH,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AACrD,CAAC","sourcesContent":["import {\n buildPrincipalStateSigningInput,\n generateKemSeedAndKeyPair,\n normalizePrincipalProjectionMembers,\n type ReferencedPrincipalHead,\n type SigningKeyPair,\n signPrincipalState,\n toFingerprint,\n} from \"@tearleads/crypto\";\nimport { bytesToBase64 } from \"@tearleads/encoding\";\nimport type {\n PrincipalProjectionMemberRequest,\n PutPrincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n OrganizationGroupSummaryResponse,\n PrincipalPolicyBundleResponse,\n} from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { PrincipalPolicyBundleRepository } from \"../../../data/persistence/principalPolicy/principalPolicyBundleRepository\";\nimport {\n encodeOrganizationAuthorityDescriptor,\n normalizeOrganizationGroupHeads,\n type OrganizationAuthorityDescriptor,\n type OrganizationGroupHead,\n} from \"../../../data/principalContracts/organizationAuthorityDescriptor\";\nimport type { SecurityIncidentReporter } from \"../../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type {\n TrustedUserIdentity,\n TrustedUserIdentityResolver,\n} from \"../../../data/trustedUserIdentity\";\nimport type { loadOrganizationExternalAdminPolicy } from \"../../principals/externalAdminPolicy\";\nimport { assertGroupNameUniqueInDirectory } from \"../groupNames/groupNameUniqueness\";\nimport {\n acknowledgeGroupPolicyBundle,\n acknowledgeInitialGroupPolicy,\n} from \"../groupPolicy/groupPolicyMutationAcknowledgement\";\nimport type { OrganizationPrincipalPolicyApi } from \"../groupPolicy/groupPolicyMutationContext\";\nimport { groupPolicyMutationHead } from \"../groupPolicy/groupPolicyMutationHead\";\nimport { rewrapProjectionMemberEnvelopes } from \"../principalPolicy/principalPolicyRecipients\";\nimport type {\n buildInitialGroupPolicyRequest,\n GroupPolicyNameReader,\n} from \"../principalPolicy/principalPolicyRequest\";\nimport {\n projectionUserIds,\n resolveRequiredUserIdentities,\n} from \"../trustedOrganizationUsers\";\n\nfunction organizationGroupHead(\n head: ReferencedPrincipalHead,\n): OrganizationGroupHead {\n if (head.principalType !== \"group\") {\n throw new Error(\"Organization directory can contain only group heads\");\n }\n return { ...head, principalType: \"group\" };\n}\n\nexport function replaceOrganizationGroupHead(input: {\n readonly descriptor: OrganizationAuthorityDescriptor;\n readonly nextHead: ReferencedPrincipalHead;\n}): OrganizationGroupHead[] {\n const nextHead = organizationGroupHead(input.nextHead);\n return normalizeOrganizationGroupHeads([\n ...input.descriptor.groupHeads.filter(\n (head) => head.principalId !== nextHead.principalId,\n ),\n nextHead,\n ]);\n}\n\nexport function removeOrganizationGroupHead(input: {\n readonly descriptor: OrganizationAuthorityDescriptor;\n readonly groupId: string;\n}): OrganizationGroupHead[] {\n if (\n input.groupId === input.descriptor.adminGroupId ||\n input.groupId === input.descriptor.memberGroupId\n ) {\n throw new Error(\"Built-in groups cannot be removed from the directory\");\n }\n const groupHeads = input.descriptor.groupHeads.filter(\n (head) => head.principalId !== input.groupId,\n );\n if (groupHeads.length === input.descriptor.groupHeads.length) {\n throw new Error(\"Organization directory does not commit the deleted group\");\n }\n return normalizeOrganizationGroupHeads(groupHeads);\n}\n\nexport async function buildOrganizationGroupDirectoryPolicyRequest(input: {\n readonly adminProjection: readonly PrincipalProjectionMemberRequest[];\n readonly adminUsers: readonly TrustedUserIdentity[];\n readonly currentPolicy: Pick<PrincipalPolicyBundleResponse, \"currentState\">;\n readonly descriptor: OrganizationAuthorityDescriptor;\n readonly groupHeads: readonly OrganizationGroupHead[];\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<PutPrincipalPolicyRequest> {\n const projection = normalizePrincipalProjectionMembers(input.adminProjection);\n if (\n projection.length === 0 ||\n projection.some((member) => member.role !== \"admin\")\n ) {\n throw new Error(\"Organization policy must mirror the Admins projection\");\n }\n const organizationKem = generateKemSeedAndKeyPair();\n const memberEnvelopes = await rewrapProjectionMemberEnvelopes({\n projection,\n secretKey: organizationKem.secretKey,\n users: input.adminUsers,\n });\n const payloadCiphertext = encodeOrganizationAuthorityDescriptor({\n ...input.descriptor,\n groupHeads: input.groupHeads,\n });\n const state = await signPrincipalState(\n await buildPrincipalStateSigningInput({\n principalType: \"organization\",\n principalId: input.descriptor.organizationId,\n version: input.currentPolicy.currentState.version + 1,\n prevStateHash: input.currentPolicy.currentState.stateHash,\n keyEpoch: input.currentPolicy.currentState.keyEpoch + 1,\n encapsulationPublicKey: bytesToBase64(organizationKem.publicKey),\n keyFingerprint: await toFingerprint(organizationKem.publicKey),\n members: projection.map((member) => ({ userId: member.userId })),\n memberEnvelopes,\n projection,\n grants: [],\n payloadCiphertext,\n externalAuthority: null,\n signedAt: new Date().toISOString(),\n signerUserId: input.signerUserId,\n signerUserKeyFingerprint: input.signingFingerprint,\n }),\n input.signingKeyPair.signingPrivateKey,\n );\n\n return {\n encryptedPayload: {\n cipherSuite: \"aes-256-gcm\",\n ciphertext: payloadCiphertext,\n ciphertextHash: state.payloadCiphertextHash,\n },\n grants: [],\n memberEnvelopes,\n projection,\n state,\n };\n}\n\nexport async function commitCreatedGroupToDirectory(input: {\n readonly stillCurrent?: (() => boolean) | undefined;\n readonly name: string;\n readonly readEncryptedName?: GroupPolicyNameReader;\n readonly apiClient: OrganizationPrincipalPolicyApi;\n readonly execSql: ExecSql;\n readonly externalAdminPolicy: NonNullable<\n Awaited<ReturnType<typeof loadOrganizationExternalAdminPolicy>>\n >;\n readonly organizationId: string;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly request: Awaited<ReturnType<typeof buildInitialGroupPolicyRequest>>;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<{\n readonly group: OrganizationGroupSummaryResponse;\n readonly head: ReferencedPrincipalHead;\n}> {\n assertProjectionVerificationCurrent(input.stillCurrent);\n // Signed group names are unique per organization; refuse a collision before\n // anything reaches the server.\n await assertGroupNameUniqueInDirectory({\n apiClient: input.apiClient,\n descriptor: input.externalAdminPolicy.descriptor,\n execSql: input.execSql,\n externalAuthority: input.externalAdminPolicy.externalAuthority,\n name: input.name,\n readEncryptedName: input.readEncryptedName,\n organizationId: input.organizationId,\n reportSecurityIncident: input.reportSecurityIncident,\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n stillCurrent: input.stillCurrent,\n });\n const expectedHead = await groupPolicyMutationHead(\n input.request.initialGroupPolicy,\n );\n const adminProjection =\n input.externalAdminPolicy.adminBundle.currentProjection;\n const adminUsers = await resolveRequiredUserIdentities({\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n userIds: projectionUserIds(adminProjection),\n });\n const organizationRequest =\n await buildOrganizationGroupDirectoryPolicyRequest({\n adminProjection,\n adminUsers,\n currentPolicy: input.externalAdminPolicy.bundle,\n descriptor: input.externalAdminPolicy.descriptor,\n groupHeads: [\n ...input.externalAdminPolicy.descriptor.groupHeads,\n organizationGroupHead(expectedHead),\n ],\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n const stored = await input.apiClient.createOrganizationGroup(\n input.organizationId,\n { ...input.request, organizationPolicy: organizationRequest },\n );\n assertProjectionVerificationCurrent(input.stillCurrent);\n if (!stored) {\n throw new Error(\"Group could not be created\");\n }\n const acknowledged = await acknowledgeInitialGroupPolicy({\n organizationId: input.organizationId,\n request: input.request,\n response: stored.group,\n stateHash: expectedHead.stateHash,\n });\n const organization = await acknowledgeGroupPolicyBundle({\n currentPolicy: input.externalAdminPolicy.bundle,\n expectedHead: await groupPolicyMutationHead(organizationRequest),\n request: organizationRequest,\n response: stored.organizationPolicy,\n });\n await new PrincipalPolicyBundleRepository(\n input.execSql,\n ).persistLocallyAcknowledgedPrincipalPolicyBundles({\n entries: [\n { bundle: acknowledged.bundle, policy: acknowledged.policy },\n organization,\n ],\n organizationId: input.organizationId,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(input.stillCurrent);\n return { group: stored.group, head: expectedHead };\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
2
- import { requireOrganizationGroupHead } from "../../../data/principals/organizationAuthorityDescriptor.js";
2
+ import { requireOrganizationGroupHead } from "../../../data/principalContracts/organizationAuthorityDescriptor.js";
3
3
  import { ProjectionDependencyUnavailableError } from "../../../data/shared/dependencyUnavailable.js";
4
4
  import { loadCurrentOrganizationAuthority } from "../currentOrganizationAuthority.js";
5
5
  import { loadLocalOrganizationPolicyReference } from "../readModel/localReadModelDetails.js";
@@ -1 +1 @@
1
- {"version":3,"file":"leaveRequestMembersEvidence.js","sourceRoot":"","sources":["leaveRequestMembersEvidence.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,4BAA4B,EAAE,MAAM,0DAA0D,CAAC;AACxG,OAAO,EAAE,oCAAoC,EAAE,MAAM,4CAA4C,CAAC;AAElG,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,EAAE,oCAAoC,EAAE,MAAM,oCAAoC,CAAC;AAC1F,OAAO,EACL,iCAAiC,GAElC,MAAM,0BAA0B,CAAC;AAQlC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,KAA2B;IAE3B,MAAM,oBAAoB,GACxB,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,2BAA2B,EAAE,CAAC;IAChE,IAAI,CAAC,oBAAoB;QACvB,MAAM,IAAI,oCAAoC,CAC5C,iDAAiD,CAClD,CAAC;IACJ,MAAM,SAAS,GAAG,MAAM,gCAAgC,CAAC;QACvD,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;QACpC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,oBAAoB;QACpB,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAC;IACH,mCAAmC,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,4BAA4B,CACvC,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,CAAC,aAAa,CACnC,CAAC;IACF,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,cAAc,EAAE,IAAI,CAAC,cAAc;QACnC,WAAW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CAAC,cAAc;oBACpC,SAAS,EAAE,IAAI;oBACf,kBAAkB,EAAE,IAAI;oBACxB,YAAY,EAAE,KAAK,CAAC,YAAY;oBAChC,WAAW,EAAE,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE;iBAClE,CAAC,CAAC;gBACH,mCAAmC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;gBAC3D,IAAI,CAAC,QAAQ,CAAC,WAAW;oBACvB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;gBAC9D,OAAO,QAAQ,CAAC,WAAW,CAAC;YAC9B,CAAC;YACH,CAAC,CAAC,SAAS;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { OrganizationLeaveRequestMembersHead } from \"@tearleads/validators/util\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { requireOrganizationGroupHead } from \"../../../data/principals/organizationAuthorityDescriptor\";\nimport { ProjectionDependencyUnavailableError } from \"../../../data/shared/dependencyUnavailable\";\nimport type { PrincipalPolicyRuntime } from \"../../principals/principalPolicyService\";\nimport { loadCurrentOrganizationAuthority } from \"../currentOrganizationAuthority\";\nimport { loadLocalOrganizationPolicyReference } from \"../readModel/localReadModelDetails\";\nimport {\n createLeaveRequestMembershipCheck,\n type LeaveRequestMembershipCheck,\n} from \"./leaveRequestMembership\";\n\ninterface MembersEvidenceInput {\n readonly runtime: PrincipalPolicyRuntime;\n readonly organizationId: string;\n readonly stillCurrent: () => boolean;\n}\n\n/**\n * The organization's current Members head as the member's own device\n * discovers and verifies it now, for a leave request to cite.\n */\nexport async function loadCurrentMembersHead(\n input: MembersEvidenceInput,\n): Promise<OrganizationLeaveRequestMembersHead> {\n const resolveCurrentPolicy =\n input.runtime.principalPolicies.createCurrentPolicyResolver();\n if (!resolveCurrentPolicy)\n throw new ProjectionDependencyUnavailableError(\n \"Asking to leave requires private paged recovery\",\n );\n const authority = await loadCurrentOrganizationAuthority({\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n resolveCurrentPolicy,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(authority.stillCurrent);\n const head = requireOrganizationGroupHead(\n authority.descriptor,\n authority.descriptor.memberGroupId,\n );\n return {\n keyEpoch: head.keyEpoch,\n keyFingerprint: head.keyFingerprint,\n principalId: head.principalId,\n stateHash: head.stateHash,\n version: head.version,\n };\n}\n\n/**\n * Checks leave requests against the Members head in the organization policy\n * this device's read model selected, verified exactly through the private\n * paged verifier (from local evidence when it has it), and walks verified\n * Members history the same way when a request cites an earlier key epoch.\n */\nexport function createRuntimeLeaveRequestMembershipCheck(\n input: MembersEvidenceInput & { readonly currentUserId: string },\n): LeaveRequestMembershipCheck {\n const resolve = input.runtime.principalPolicies.createCurrentPolicyResolver();\n return createLeaveRequestMembershipCheck({\n async loadMembersHead() {\n if (!resolve) return null;\n const organizationReference = await loadLocalOrganizationPolicyReference({\n currentUserId: input.currentUserId,\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n principalId: input.organizationId,\n principalType: \"organization\",\n });\n if (!organizationReference) return null;\n const authority = await loadCurrentOrganizationAuthority({\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n organizationReference,\n resolveCurrentPolicy: resolve,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(authority.stillCurrent);\n return requireOrganizationGroupHead(\n authority.descriptor,\n authority.descriptor.memberGroupId,\n );\n },\n loadHistoryPage: resolve\n ? async (head, beforeVersion) => {\n const resolved = await resolve({\n organizationId: input.organizationId,\n reference: head,\n preferLocalCurrent: true,\n stillCurrent: input.stillCurrent,\n historyPage: beforeVersion === undefined ? {} : { beforeVersion },\n });\n assertProjectionVerificationCurrent(resolved.stillCurrent);\n if (!resolved.historyPage)\n throw new Error(\"Verified Members history page is missing\");\n return resolved.historyPage;\n }\n : undefined,\n });\n}\n"]}
1
+ {"version":3,"file":"le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AC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE;iBAClE,CAAC,CAAC;gBACH,mCAAmC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;gBAC3D,IAAI,CAAC,QAAQ,CAAC,WAAW;oBACvB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;gBAC9D,OAAO,QAAQ,CAAC,WAAW,CAAC;YAC9B,CAAC;YACH,CAAC,CAAC,SAAS;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { OrganizationLeaveRequestMembersHead } from \"@tearleads/validators/util\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { requireOrganizationGroupHead } from \"../../../data/principalContracts/organizationAuthorityDescriptor\";\nimport { ProjectionDependencyUnavailableError } from \"../../../data/shared/dependencyUnavailable\";\nimport type { PrincipalPolicyRuntime } from \"../../principals/principalPolicyService\";\nimport { loadCurrentOrganizationAuthority } from \"../currentOrganizationAuthority\";\nimport { loadLocalOrganizationPolicyReference } from \"../readModel/localReadModelDetails\";\nimport {\n createLeaveRequestMembershipCheck,\n type LeaveRequestMembershipCheck,\n} from \"./leaveRequestMembership\";\n\ninterface MembersEvidenceInput {\n readonly runtime: PrincipalPolicyRuntime;\n readonly organizationId: string;\n readonly stillCurrent: () => boolean;\n}\n\n/**\n * The organization's current Members head as the member's own device\n * discovers and verifies it now, for a leave request to cite.\n */\nexport async function loadCurrentMembersHead(\n input: MembersEvidenceInput,\n): Promise<OrganizationLeaveRequestMembersHead> {\n const resolveCurrentPolicy =\n input.runtime.principalPolicies.createCurrentPolicyResolver();\n if (!resolveCurrentPolicy)\n throw new ProjectionDependencyUnavailableError(\n \"Asking to leave requires private paged recovery\",\n );\n const authority = await loadCurrentOrganizationAuthority({\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n resolveCurrentPolicy,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(authority.stillCurrent);\n const head = requireOrganizationGroupHead(\n authority.descriptor,\n authority.descriptor.memberGroupId,\n );\n return {\n keyEpoch: head.keyEpoch,\n keyFingerprint: head.keyFingerprint,\n principalId: head.principalId,\n stateHash: head.stateHash,\n version: head.version,\n };\n}\n\n/**\n * Checks leave requests against the Members head in the organization policy\n * this device's read model selected, verified exactly through the private\n * paged verifier (from local evidence when it has it), and walks verified\n * Members history the same way when a request cites an earlier key epoch.\n */\nexport function createRuntimeLeaveRequestMembershipCheck(\n input: MembersEvidenceInput & { readonly currentUserId: string },\n): LeaveRequestMembershipCheck {\n const resolve = input.runtime.principalPolicies.createCurrentPolicyResolver();\n return createLeaveRequestMembershipCheck({\n async loadMembersHead() {\n if (!resolve) return null;\n const organizationReference = await loadLocalOrganizationPolicyReference({\n currentUserId: input.currentUserId,\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n principalId: input.organizationId,\n principalType: \"organization\",\n });\n if (!organizationReference) return null;\n const authority = await loadCurrentOrganizationAuthority({\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n organizationReference,\n resolveCurrentPolicy: resolve,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(authority.stillCurrent);\n return requireOrganizationGroupHead(\n authority.descriptor,\n authority.descriptor.memberGroupId,\n );\n },\n loadHistoryPage: resolve\n ? async (head, beforeVersion) => {\n const resolved = await resolve({\n organizationId: input.organizationId,\n reference: head,\n preferLocalCurrent: true,\n stillCurrent: input.stillCurrent,\n historyPage: beforeVersion === undefined ? {} : { beforeVersion },\n });\n assertProjectionVerificationCurrent(resolved.stillCurrent);\n if (!resolved.historyPage)\n throw new Error(\"Verified Members history page is missing\");\n return resolved.historyPage;\n }\n : undefined,\n });\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { reportKeyingVerificationErrorInCauseChain } from "../../../data/keyingProjectionVerification/error.js";
2
1
  import { ProjectionDependencyUnavailableError } from "../../../data/shared/dependencyUnavailable.js";
2
+ import { reportKeyingVerificationErrorInCauseChain, } from "../../../data/shared/securityIncidents.js";
3
3
  import { loadLocalOrganizationPolicyReference } from "../readModel/localReadModelDetails.js";
4
4
  import { captureOrganizationPresentationAccessAttempt, isOrganizationPresentationAccessAttemptCurrent, isOrganizationPresentationAccessReadable, } from "../readModel/organizationPresentationAccessState.js";
5
5
  import { isOrganizationPresentationAccessDeniedFailure } from "../readModel/organizationPresentationFailures.js";
@@ -1 +1 @@
1
- {"version":3,"file":"loadPolicyHistoryDetails.js","sourceRoot":"","sources":["loadPolicyHistoryDetails.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yCAAyC,EAAE,MAAM,kDAAkD,CAAC;AAE7G,OAAO,EAAE,oCAAoC,EAAE,MAAM,4CAA4C,CAAC;AAKlG,OAAO,EAAE,oCAAoC,EAAE,MAAM,oCAAoC,CAAC;AAC1F,OAAO,EACL,4CAA4C,EAC5C,8CAA8C,EAC9C,wCAAwC,GACzC,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,6CAA6C,EAAE,MAAM,+CAA+C,CAAC;AAC9G,OAAO,EAAE,sCAAsC,EAAE,MAAM,oCAAoC,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EACL,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAG9B,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,KAkB9C;IACC,MAAM,MAAM,GAAG,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC;IAClE,MAAM,OAAO,GAAG,4CAA4C,CAC1D,MAAM,EACN,WAAW,CACZ,CAAC;IACF,MAAM,OAAO,GAAG,GAAG,EAAE,CACnB,KAAK,CAAC,YAAY,EAAE;QACpB,8CAA8C,CAAC,MAAM,EAAE,OAAO,CAAC;QAC/D,wCAAwC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAChE,IAAI,CAAC,OAAO,EAAE;QAAE,OAAO,IAAI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C;gBAC5D,MAAM,uBAAuB,CAAC,MAAM,CAAC,CAAC;gBACtC,OAAO,IAAI,CAAC;YACd,CAAC;YACD,QAAQ,CAAC,MAAM,EAAE,CAAC;YAClB,IAAI,KAAK,CAAC,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACvD,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,sCAAsC,CAAC;YAC3D,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,QAAQ,EAAE,QAAQ,CAAC,IAAI;YACvB,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,YAAY,EAAE,OAAO;SACtB,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,QAAQ,KAAK,OAAO;YACtB,kBAAkB,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACrD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,CAAC,KAAK,CAAC,SAAS;YAChB,KAAK,YAAY,oCAAoC;YAErD,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC/B,MAAM,yCAAyC,CAC7C,KAAK,EACL,KAAK,CAAC,sBAAsB,EAC5B;YACE,QAAQ,EAAE,KAAK,CAAC,cAAc;YAC9B,UAAU,EAAE,WAAW;YACvB,SAAS,EAAE,kCAAkC;YAC7C,cAAc,EAAE,KAAK,CAAC,cAAc;SACrC,CACF,CAAC;QACF,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { ApiClient } from \"@tearleads/api-client\";\nimport type { ReferencedPrincipalHead } from \"@tearleads/crypto\";\nimport { reportKeyingVerificationErrorInCauseChain } from \"../../../data/keyingProjectionVerification/error\";\nimport type { ReferencedPrincipalPolicyWarmer } from \"../../../data/keyingProjectionVerification/types\";\nimport { ProjectionDependencyUnavailableError } from \"../../../data/shared/dependencyUnavailable\";\nimport type { DomainScope } from \"../../../data/shared/domainScope\";\nimport type { SecurityIncidentReporter } from \"../../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type { RecoveredPrincipalHistoryPage } from \"../../principals/historyRecovery/loadRecoveredPrincipalHistoryPage\";\nimport { loadLocalOrganizationPolicyReference } from \"../readModel/localReadModelDetails\";\nimport {\n captureOrganizationPresentationAccessAttempt,\n isOrganizationPresentationAccessAttemptCurrent,\n isOrganizationPresentationAccessReadable,\n} from \"../readModel/organizationPresentationAccessState\";\nimport { isOrganizationPresentationAccessDeniedFailure } from \"../readModel/organizationPresentationFailures\";\nimport { buildDetailedOrganizationPolicyHistory } from \"./organizationPolicyHistoryDetails\";\nimport { denyPolicyHistoryAccess } from \"./policyHistoryAccessDenial\";\nimport {\n cachePolicyHistory,\n loadCachedPolicyHistory,\n} from \"./policyHistoryCache\";\nimport type { OrganizationPolicyHistory } from \"./policyHistoryTypes\";\n\nexport async function loadPolicyHistoryDetails(input: {\n apiClient: Pick<ApiClient, \"getOrganizationPolicyHistoryResult\">;\n currentUserId: string;\n domainScope: DomainScope;\n execSql: ExecSql;\n organizationId: string;\n head: ReferencedPrincipalHead;\n page: RecoveredPrincipalHistoryPage;\n history: OrganizationPolicyHistory;\n resolveHistory: NonNullable<\n ReferencedPrincipalPolicyWarmer[\"resolveProjectionHistory\"]\n >;\n stillCurrent: () => boolean;\n online: boolean;\n olderPage: boolean;\n reportSecurityIncident?: SecurityIncidentReporter | undefined;\n // Forwarded to denyPolicyHistoryAccess to report failed durable cleanup.\n logError: (message: string | Error, cause?: unknown) => void;\n}): Promise<OrganizationPolicyHistory | null> {\n const access = { ...input, requesterUserId: input.currentUserId };\n const attempt = captureOrganizationPresentationAccessAttempt(\n access,\n \"readModel\",\n );\n const current = () =>\n input.stillCurrent() &&\n isOrganizationPresentationAccessAttemptCurrent(access, attempt) &&\n isOrganizationPresentationAccessReadable(access, \"readModel\");\n if (!current()) return null;\n const beforeVersion = (input.page.entries.at(-1)?.state.version ?? 0) + 1;\n const cache = {\n domainScope: input.domainScope,\n access,\n stateHash: input.head.stateHash,\n beforeVersion,\n };\n const retain = async (history: OrganizationPolicyHistory) => {\n const latest = await loadLocalOrganizationPolicyReference({\n ...input,\n principalType: \"organization\",\n principalId: input.organizationId,\n });\n return current() && latest?.stateHash === input.head.stateHash\n ? history\n : null;\n };\n const cached = loadCachedPolicyHistory(cache);\n if (cached) return retain(cached);\n if (!input.online) return retain(input.history);\n try {\n const response = await input.apiClient.getOrganizationPolicyHistoryResult(\n input.organizationId,\n input.head.stateHash,\n { beforeVersion, reportErrors: false },\n );\n if (!input.stillCurrent()) return null;\n if (!response.ok) {\n if (isOrganizationPresentationAccessDeniedFailure(response)) {\n await denyPolicyHistoryAccess(access);\n return null;\n }\n response.report();\n if (input.olderPage) throw new Error(response.message);\n return retain(input.history);\n }\n const history = await buildDetailedOrganizationPolicyHistory({\n head: input.head,\n page: input.page,\n evidence: response.data,\n resolveHistory: input.resolveHistory,\n stillCurrent: current,\n });\n const retained = await retain(history);\n if (retained === history)\n cachePolicyHistory({ ...cache, attempt, history });\n return retained;\n } catch (error) {\n if (\n !input.olderPage &&\n error instanceof ProjectionDependencyUnavailableError\n )\n return retain(input.history);\n await reportKeyingVerificationErrorInCauseChain(\n error,\n input.reportSecurityIncident,\n {\n objectId: input.organizationId,\n objectKind: \"principal\",\n operation: \"organization.policy_history.load\",\n organizationId: input.organizationId,\n },\n );\n throw error;\n }\n}\n"]}
1
+ {"version":3,"file":"loadPolicyHistoryDetails.js","sourceRoot":"","sources":["loadPolicyHistoryDetails.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oCAAoC,EAAE,MAAM,4CAA4C,CAAC;AAElG,OAAO,EACL,yCAAyC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,QAAQ,CAAC,IAAI;YACvB,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,YAAY,EAAE,OAAO;SACtB,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,QAAQ,KAAK,OAAO;YACtB,kBAAkB,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACrD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,CAAC,KAAK,CAAC,SAAS;YAChB,KAAK,YAAY,oCAAoC;YAErD,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC/B,MAAM,yCAAyC,CAC7C,KAAK,EACL,KAAK,CAAC,sBAAsB,EAC5B;YACE,QAAQ,EAAE,KAAK,CAAC,cAAc;YAC9B,UAAU,EAAE,WAAW;YACvB,SAAS,EAAE,kCAAkC;YAC7C,cAAc,EAAE,KAAK,CAAC,cAAc;SACrC,CACF,CAAC;QACF,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { ApiClient } from \"@tearleads/api-client\";\nimport type { ReferencedPrincipalHead } from \"@tearleads/crypto\";\nimport type { ReferencedPrincipalPolicyWarmer } from \"../../../data/keyingProjectionVerification/types\";\nimport { ProjectionDependencyUnavailableError } from \"../../../data/shared/dependencyUnavailable\";\nimport type { DomainScope } from \"../../../data/shared/domainScope\";\nimport {\n reportKeyingVerificationErrorInCauseChain,\n type SecurityIncidentReporter,\n} from \"../../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type { RecoveredPrincipalHistoryPage } from \"../../principals/historyRecovery/loadRecoveredPrincipalHistoryPage\";\nimport { loadLocalOrganizationPolicyReference } from \"../readModel/localReadModelDetails\";\nimport {\n captureOrganizationPresentationAccessAttempt,\n isOrganizationPresentationAccessAttemptCurrent,\n isOrganizationPresentationAccessReadable,\n} from \"../readModel/organizationPresentationAccessState\";\nimport { isOrganizationPresentationAccessDeniedFailure } from \"../readModel/organizationPresentationFailures\";\nimport { buildDetailedOrganizationPolicyHistory } from \"./organizationPolicyHistoryDetails\";\nimport { denyPolicyHistoryAccess } from \"./policyHistoryAccessDenial\";\nimport {\n cachePolicyHistory,\n loadCachedPolicyHistory,\n} from \"./policyHistoryCache\";\nimport type { OrganizationPolicyHistory } from \"./policyHistoryTypes\";\n\nexport async function loadPolicyHistoryDetails(input: {\n apiClient: Pick<ApiClient, \"getOrganizationPolicyHistoryResult\">;\n currentUserId: string;\n domainScope: DomainScope;\n execSql: ExecSql;\n organizationId: string;\n head: ReferencedPrincipalHead;\n page: RecoveredPrincipalHistoryPage;\n history: OrganizationPolicyHistory;\n resolveHistory: NonNullable<\n ReferencedPrincipalPolicyWarmer[\"resolveProjectionHistory\"]\n >;\n stillCurrent: () => boolean;\n online: boolean;\n olderPage: boolean;\n reportSecurityIncident?: SecurityIncidentReporter | undefined;\n // Forwarded to denyPolicyHistoryAccess to report failed durable cleanup.\n logError: (message: string | Error, cause?: unknown) => void;\n}): Promise<OrganizationPolicyHistory | null> {\n const access = { ...input, requesterUserId: input.currentUserId };\n const attempt = captureOrganizationPresentationAccessAttempt(\n access,\n \"readModel\",\n );\n const current = () =>\n input.stillCurrent() &&\n isOrganizationPresentationAccessAttemptCurrent(access, attempt) &&\n isOrganizationPresentationAccessReadable(access, \"readModel\");\n if (!current()) return null;\n const beforeVersion = (input.page.entries.at(-1)?.state.version ?? 0) + 1;\n const cache = {\n domainScope: input.domainScope,\n access,\n stateHash: input.head.stateHash,\n beforeVersion,\n };\n const retain = async (history: OrganizationPolicyHistory) => {\n const latest = await loadLocalOrganizationPolicyReference({\n ...input,\n principalType: \"organization\",\n principalId: input.organizationId,\n });\n return current() && latest?.stateHash === input.head.stateHash\n ? history\n : null;\n };\n const cached = loadCachedPolicyHistory(cache);\n if (cached) return retain(cached);\n if (!input.online) return retain(input.history);\n try {\n const response = await input.apiClient.getOrganizationPolicyHistoryResult(\n input.organizationId,\n input.head.stateHash,\n { beforeVersion, reportErrors: false },\n );\n if (!input.stillCurrent()) return null;\n if (!response.ok) {\n if (isOrganizationPresentationAccessDeniedFailure(response)) {\n await denyPolicyHistoryAccess(access);\n return null;\n }\n response.report();\n if (input.olderPage) throw new Error(response.message);\n return retain(input.history);\n }\n const history = await buildDetailedOrganizationPolicyHistory({\n head: input.head,\n page: input.page,\n evidence: response.data,\n resolveHistory: input.resolveHistory,\n stillCurrent: current,\n });\n const retained = await retain(history);\n if (retained === history)\n cachePolicyHistory({ ...cache, attempt, history });\n return retained;\n } catch (error) {\n if (\n !input.olderPage &&\n error instanceof ProjectionDependencyUnavailableError\n )\n return retain(input.history);\n await reportKeyingVerificationErrorInCauseChain(\n error,\n input.reportSecurityIncident,\n {\n objectId: input.organizationId,\n objectKind: \"principal\",\n operation: \"organization.policy_history.load\",\n organizationId: input.organizationId,\n },\n );\n throw error;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"organizationPolicyHistoryDetails.js","sourceRoot":"","sources":["organizationPolicyHistoryDetails.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,+BAA+B,GAChC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,mCAAmC,GAEpC,MAAM,kDAAkD,CAAC;AAE1D,OAAO,EAAE,uCAAuC,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,EACL,8BAA8B,GAE/B,MAAM,0BAA0B,CAAC;AAMlC,SAAS,UAAU,CACjB,QAA4C,EAC5C,OAA2C;IAE3C,MAAM,MAAM,GAAG,IAAI,GAAG,CACpB,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAChE,CAAC;IACF,MAAM,KAAK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W;QACtC,iBAAiB,EAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB;QAC/C,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACrC,GAAG,KAAK;YACR,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE;SACjD,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import {\n type PrincipalContainerGrant,\n type PrincipalPolicyStateChainEntry,\n principalPolicyMatchesReference,\n} from \"@tearleads/crypto\";\nimport {\n assertProjectionVerificationCurrent,\n type ReferencedPrincipalPolicyWarmer,\n} from \"../../../data/keyingProjectionVerification/types\";\nimport type { OrganizationGroupHead } from \"../../../data/principals/organizationAuthorityDescriptor\";\nimport { buildOrganizationGroupPolicyHistoryPage } from \"./groupPolicyHistoryPage\";\nimport { verifyOrganizationPolicyHistory } from \"./organizationPolicyHistoryVerification\";\nimport {\n diffPrincipalProjectionMembers,\n type OrganizationPolicyHistory,\n} from \"./policyHistoryReadModel\";\nimport type {\n OrganizationPolicyGrantChange,\n OrganizationPolicyGroupChange,\n} from \"./policyHistoryTypes\";\n\nfunction diffGrants(\n previous: readonly PrincipalContainerGrant[],\n current: readonly PrincipalContainerGrant[],\n): OrganizationPolicyGrantChange[] {\n const before = new Map(\n previous.map((grant) => [grant.containerId, grant.accessLevel]),\n );\n const after = new Map(\n current.map((grant) => [grant.containerId, grant.accessLevel]),\n );\n return [...new Set([...before.keys(), ...after.keys()])]\n .sort()\n .flatMap((containerId) => {\n const previousAccess = before.get(containerId) ?? null;\n const nextAccess = after.get(containerId) ?? null;\n return previousAccess === nextAccess\n ? []\n : [{ containerId, previousAccess, nextAccess }];\n });\n}\n\nfunction describeGroupChange(\n previous: OrganizationGroupHead | undefined,\n current: OrganizationGroupHead | undefined,\n groupState: (head: OrganizationGroupHead) => PrincipalPolicyStateChainEntry,\n): OrganizationPolicyGroupChange {\n const head = current ?? previous;\n if (!head) throw new Error(\"Group change has no state\");\n const oldEntry = previous ? groupState(previous) : null;\n const newEntry = current ? groupState(current) : null;\n return {\n groupId: head.principalId,\n changeType: !previous ? \"created\" : !current ? \"deleted\" : \"updated\",\n previousVersion: previous?.version ?? null,\n version: head.version,\n previousKeyEpoch: previous?.keyEpoch ?? null,\n keyEpoch: head.keyEpoch,\n changes: newEntry\n ? diffPrincipalProjectionMembers({\n previous: oldEntry?.projection ?? [],\n current: newEntry.projection,\n })\n : [],\n grantChanges: newEntry\n ? diffGrants(oldEntry?.grants ?? [], newEntry.grants)\n : [],\n };\n}\n\nfunction diffGroups(\n previousHeads: readonly OrganizationGroupHead[],\n heads: readonly OrganizationGroupHead[],\n groupState: (head: OrganizationGroupHead) => PrincipalPolicyStateChainEntry,\n): OrganizationPolicyGroupChange[] {\n const before = new Map(previousHeads.map((head) => [head.principalId, head]));\n const after = new Map(heads.map((head) => [head.principalId, head]));\n const changes: OrganizationPolicyGroupChange[] = [];\n for (const groupId of [\n ...new Set([...before.keys(), ...after.keys()]),\n ].sort()) {\n const previous = before.get(groupId);\n const current = after.get(groupId);\n if (previous?.stateHash === current?.stateHash) continue;\n changes.push(describeGroupChange(previous, current, groupState));\n }\n return changes;\n}\n\n/** Display only: historical group selections never advance current checkpoints. */\nexport async function buildDetailedOrganizationPolicyHistory(\n input: Parameters<typeof verifyOrganizationPolicyHistory>[0] & {\n readonly resolveHistory: NonNullable<\n ReferencedPrincipalPolicyWarmer[\"resolveProjectionHistory\"]\n >;\n readonly stillCurrent: () => boolean;\n },\n): Promise<OrganizationPolicyHistory> {\n input = {\n ...input,\n head: structuredClone(input.head),\n page: structuredClone(input.page),\n evidence: structuredClone(input.evidence),\n };\n const { descriptors, references } =\n await verifyOrganizationPolicyHistory(input);\n assertProjectionVerificationCurrent(input.stillCurrent);\n const resolved = await input.resolveHistory({\n organizationId: input.head.principalId,\n evidence: input.evidence.evidence,\n references,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(\n () => input.stillCurrent() && resolved.stillCurrent(),\n );\n const groupState = (\n head: OrganizationGroupHead,\n ): PrincipalPolicyStateChainEntry => {\n const policy = resolved.policies.find((policy) =>\n principalPolicyMatchesReference({ policy, reference: head }),\n );\n const entry = policy?.retainedHistory.find(\n (entry) => entry.state.stateHash === head.stateHash,\n );\n if (!entry) throw new Error(\"Verified group history state is missing\");\n return entry;\n };\n const basic = buildOrganizationGroupPolicyHistoryPage({\n page: input.page,\n groupId: input.head.principalId,\n organizationId: input.head.principalId,\n });\n const byState = new Map<string, OrganizationPolicyGroupChange[]>();\n let previousHeads: readonly OrganizationGroupHead[] = input.page.predecessor\n ? (descriptors.get(input.page.predecessor.state.stateHash)?.groupHeads ??\n [])\n : [];\n for (const { state } of input.page.entries) {\n const heads = descriptors.get(state.stateHash)?.groupHeads;\n if (!heads) throw new Error(\"Verified organization directory is missing\");\n byState.set(state.stateHash, diffGroups(previousHeads, heads, groupState));\n previousHeads = heads;\n }\n return {\n principalId: input.head.principalId,\n principalType: \"organization\",\n organizationId: input.head.principalId,\n nextBeforeVersion: input.page.nextBeforeVersion,\n entries: basic.entries.map((entry) => ({\n ...entry,\n groupChanges: byState.get(entry.stateHash) ?? [],\n })),\n };\n}\n"]}
1
+ {"version":3,"file":"organizationPolicyHistoryDetails.js","sourceRoot":"","sources":["organizationPolicyHistoryDetails.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,+BAA+B,GAChC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,mCAAmC,GAEpC,MAAM,kDAAkD,CAAC;AAE1D,OAAO,EAAE,uCAAuC,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,EACL,8BAA8B,GAE/B,MAAM,0BAA0B,CAAC;AAMlC,SAAS,UAAU,CACjB,QAA4C,EAC5C,OAA2C;IAE3C,MAAM,MAAM,GAAG,IAAI,GAA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AAK,CAAC;IACxB,CAAC;IACD,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW;QACnC,aAAa,EAAE,cAAc;QAC7B,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW;QACtC,iBAAiB,EAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB;QAC/C,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACrC,GAAG,KAAK;YACR,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE;SACjD,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import {\n type PrincipalContainerGrant,\n type PrincipalPolicyStateChainEntry,\n principalPolicyMatchesReference,\n} from \"@tearleads/crypto\";\nimport {\n assertProjectionVerificationCurrent,\n type ReferencedPrincipalPolicyWarmer,\n} from \"../../../data/keyingProjectionVerification/types\";\nimport type { OrganizationGroupHead } from \"../../../data/principalContracts/organizationAuthorityDescriptor\";\nimport { buildOrganizationGroupPolicyHistoryPage } from \"./groupPolicyHistoryPage\";\nimport { verifyOrganizationPolicyHistory } from \"./organizationPolicyHistoryVerification\";\nimport {\n diffPrincipalProjectionMembers,\n type OrganizationPolicyHistory,\n} from \"./policyHistoryReadModel\";\nimport type {\n OrganizationPolicyGrantChange,\n OrganizationPolicyGroupChange,\n} from \"./policyHistoryTypes\";\n\nfunction diffGrants(\n previous: readonly PrincipalContainerGrant[],\n current: readonly PrincipalContainerGrant[],\n): OrganizationPolicyGrantChange[] {\n const before = new Map(\n previous.map((grant) => [grant.containerId, grant.accessLevel]),\n );\n const after = new Map(\n current.map((grant) => [grant.containerId, grant.accessLevel]),\n );\n return [...new Set([...before.keys(), ...after.keys()])]\n .sort()\n .flatMap((containerId) => {\n const previousAccess = before.get(containerId) ?? null;\n const nextAccess = after.get(containerId) ?? null;\n return previousAccess === nextAccess\n ? []\n : [{ containerId, previousAccess, nextAccess }];\n });\n}\n\nfunction describeGroupChange(\n previous: OrganizationGroupHead | undefined,\n current: OrganizationGroupHead | undefined,\n groupState: (head: OrganizationGroupHead) => PrincipalPolicyStateChainEntry,\n): OrganizationPolicyGroupChange {\n const head = current ?? previous;\n if (!head) throw new Error(\"Group change has no state\");\n const oldEntry = previous ? groupState(previous) : null;\n const newEntry = current ? groupState(current) : null;\n return {\n groupId: head.principalId,\n changeType: !previous ? \"created\" : !current ? \"deleted\" : \"updated\",\n previousVersion: previous?.version ?? null,\n version: head.version,\n previousKeyEpoch: previous?.keyEpoch ?? null,\n keyEpoch: head.keyEpoch,\n changes: newEntry\n ? diffPrincipalProjectionMembers({\n previous: oldEntry?.projection ?? [],\n current: newEntry.projection,\n })\n : [],\n grantChanges: newEntry\n ? diffGrants(oldEntry?.grants ?? [], newEntry.grants)\n : [],\n };\n}\n\nfunction diffGroups(\n previousHeads: readonly OrganizationGroupHead[],\n heads: readonly OrganizationGroupHead[],\n groupState: (head: OrganizationGroupHead) => PrincipalPolicyStateChainEntry,\n): OrganizationPolicyGroupChange[] {\n const before = new Map(previousHeads.map((head) => [head.principalId, head]));\n const after = new Map(heads.map((head) => [head.principalId, head]));\n const changes: OrganizationPolicyGroupChange[] = [];\n for (const groupId of [\n ...new Set([...before.keys(), ...after.keys()]),\n ].sort()) {\n const previous = before.get(groupId);\n const current = after.get(groupId);\n if (previous?.stateHash === current?.stateHash) continue;\n changes.push(describeGroupChange(previous, current, groupState));\n }\n return changes;\n}\n\n/** Display only: historical group selections never advance current checkpoints. */\nexport async function buildDetailedOrganizationPolicyHistory(\n input: Parameters<typeof verifyOrganizationPolicyHistory>[0] & {\n readonly resolveHistory: NonNullable<\n ReferencedPrincipalPolicyWarmer[\"resolveProjectionHistory\"]\n >;\n readonly stillCurrent: () => boolean;\n },\n): Promise<OrganizationPolicyHistory> {\n input = {\n ...input,\n head: structuredClone(input.head),\n page: structuredClone(input.page),\n evidence: structuredClone(input.evidence),\n };\n const { descriptors, references } =\n await verifyOrganizationPolicyHistory(input);\n assertProjectionVerificationCurrent(input.stillCurrent);\n const resolved = await input.resolveHistory({\n organizationId: input.head.principalId,\n evidence: input.evidence.evidence,\n references,\n stillCurrent: input.stillCurrent,\n });\n assertProjectionVerificationCurrent(\n () => input.stillCurrent() && resolved.stillCurrent(),\n );\n const groupState = (\n head: OrganizationGroupHead,\n ): PrincipalPolicyStateChainEntry => {\n const policy = resolved.policies.find((policy) =>\n principalPolicyMatchesReference({ policy, reference: head }),\n );\n const entry = policy?.retainedHistory.find(\n (entry) => entry.state.stateHash === head.stateHash,\n );\n if (!entry) throw new Error(\"Verified group history state is missing\");\n return entry;\n };\n const basic = buildOrganizationGroupPolicyHistoryPage({\n page: input.page,\n groupId: input.head.principalId,\n organizationId: input.head.principalId,\n });\n const byState = new Map<string, OrganizationPolicyGroupChange[]>();\n let previousHeads: readonly OrganizationGroupHead[] = input.page.predecessor\n ? (descriptors.get(input.page.predecessor.state.stateHash)?.groupHeads ??\n [])\n : [];\n for (const { state } of input.page.entries) {\n const heads = descriptors.get(state.stateHash)?.groupHeads;\n if (!heads) throw new Error(\"Verified organization directory is missing\");\n byState.set(state.stateHash, diffGroups(previousHeads, heads, groupState));\n previousHeads = heads;\n }\n return {\n principalId: input.head.principalId,\n principalType: \"organization\",\n organizationId: input.head.principalId,\n nextBeforeVersion: input.page.nextBeforeVersion,\n entries: basic.entries.map((entry) => ({\n ...entry,\n groupChanges: byState.get(entry.stateHash) ?? [],\n })),\n };\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { computePrincipalStatePayloadCiphertextHash, KeyingVerificationError, } from "../../../internal/crypto/index.js";
2
- import { parseOrganizationAuthorityDescriptor, principalHeadMatchesReference, } from "../../../data/principals/organizationAuthorityDescriptor.js";
2
+ import { parseOrganizationAuthorityDescriptor, principalHeadMatchesReference, } from "../../../data/principalContracts/organizationAuthorityDescriptor.js";
3
3
  function reject(message) {
4
4
  throw new KeyingVerificationError("hash_mismatch", `Organization policy history: ${message}`);
5
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"organizationPolicyHistoryVerification.js","sourceRoot":"","sources":["organizationPolicyHistoryVerification.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0CAA0C,EAC1C,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,oCAAoC,EACpC,6BAA6B,GAC9B,MAAM,0DAA0D,CAAC;AAGlE,SAAS,MAAM,CAAC,OAAe;IAC7B,MAAM,IAAI,uBAAuB,CAC/B,eAAe,EACf,gCAAgC,OAAO,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAC,KAIrD;IACC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACvC,MAAM,aAAa,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACpE,IACE,IAAI,CAAC,aAAa,KAAK,cAAc;QACrC,QAAQ,CAAC,cAAc,KAAK,IAAI,CAAC,WAAW;QAC5C,QAAQ,CAAC,SAAS,KAAK,IAAI,CAAC,SAAS;QACrC,QAAQ,CAAC,aAAa,KAAK,aAAa;QACxC,QAAQ,CAAC,iBAAiB,KAAK,IAAI,CAAC,iBAAiB;QACrD,CAAC,QAAQ,CAAC,QAAQ,CAAC,YAAY;QAC/B,CAAC,6BAA6B,CAAC,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC;QAEzE,MAAM,CAAC,yDAAyD,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW;QAC9B,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QACrC,CAAC,CAAC,IAAI,CAAC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AAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;AACH,CAAC","sourcesContent":["import {\n computePrincipalStatePayloadCiphertextHash,\n KeyingVerificationError,\n type ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport type { OrganizationPolicyHistoryResponse } from \"@tearleads/validators/response\";\nimport {\n type OrganizationAuthorityDescriptor,\n parseOrganizationAuthorityDescriptor,\n principalHeadMatchesReference,\n} from \"../../../data/principals/organizationAuthorityDescriptor\";\nimport type { RecoveredPrincipalHistoryPage } from \"../../principals/historyRecovery/loadRecoveredPrincipalHistoryPage\";\n\nfunction reject(message: string): never {\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n `Organization policy history: ${message}`,\n );\n}\n\n/** Bind every display payload and public source to the privately verified page. */\nexport async function verifyOrganizationPolicyHistory(input: {\n readonly head: ReferencedPrincipalHead;\n readonly page: RecoveredPrincipalHistoryPage;\n readonly evidence: OrganizationPolicyHistoryResponse;\n}) {\n const { head, page, evidence } = input;\n const beforeVersion = (page.entries.at(-1)?.state.version ?? 0) + 1;\n if (\n head.principalType !== \"organization\" ||\n evidence.organizationId !== head.principalId ||\n evidence.stateHash !== head.stateHash ||\n evidence.beforeVersion !== beforeVersion ||\n evidence.nextBeforeVersion !== page.nextBeforeVersion ||\n !evidence.evidence.organization ||\n !principalHeadMatchesReference(evidence.evidence.organization.head, head)\n )\n reject(\"response does not match the requested organization page\");\n const entries = page.predecessor\n ? [page.predecessor, ...page.entries]\n : page.entries;\n if (evidence.evidence.organizationPayloads.length !== entries.length)\n reject(\"directory page is incomplete\");\n const descriptors = new Map<string, OrganizationAuthorityDescriptor>();\n const references: ReferencedPrincipalHead[] = [head];\n const groups = new Map<string, ReferencedPrincipalHead>();\n for (const [\n index,\n item,\n ] of evidence.evidence.organizationPayloads.entries()) {\n const { reference, payload } = item;\n const entry = entries[index];\n if (\n !entry ||\n !principalHeadMatchesReference(entry.state, reference) ||\n payload.principalType !== \"organization\" ||\n payload.principalId !== head.principalId ||\n payload.stateHash !== reference.stateHash ||\n descriptors.has(reference.stateHash)\n )\n reject(\"directory payload scope or order is invalid\");\n const hash = await computePrincipalStatePayloadCiphertextHash(\n payload.ciphertext,\n );\n if (\n hash !== entry.state.payloadCiphertextHash ||\n hash !== payload.ciphertextHash\n )\n reject(\"directory payload does not match its signed hash\");\n const descriptor = parseOrganizationAuthorityDescriptor(payload.ciphertext);\n if (descriptor.organizationId !== head.principalId)\n reject(\"directory belongs to another organization\");\n descriptors.set(reference.stateHash, descriptor);\n references.push(reference, ...descriptor.groupHeads);\n keepNewestGroupHeads(groups, descriptor.groupHeads);\n }\n verifyGroupSources(evidence, groups);\n return { descriptors, references };\n}\n\nfunction keepNewestGroupHeads(\n groups: Map<string, ReferencedPrincipalHead>,\n groupHeads: readonly ReferencedPrincipalHead[],\n) {\n for (const group of groupHeads) {\n const previous = groups.get(group.principalId);\n if (!previous || group.version > previous.version)\n groups.set(group.principalId, group);\n }\n}\n\nfunction verifyGroupSources(\n evidence: OrganizationPolicyHistoryResponse,\n groups: Map<string, ReferencedPrincipalHead>,\n) {\n if (evidence.evidence.groups.length !== groups.size)\n reject(\"unexpected group source\");\n const seen = new Set<string>();\n for (const source of evidence.evidence.groups) {\n const expected = groups.get(source.head.principalId);\n if (\n !expected ||\n seen.has(source.head.principalId) ||\n !principalHeadMatchesReference(source.head, expected)\n )\n reject(\"group source extends beyond the page's signed directory\");\n seen.add(source.head.principalId);\n }\n}\n"]}
1
+ {"version":3,"file":"organizationPolicyHistoryVerification.js","sourceRoot":"","sources":["organizationPolicyHistoryVerification.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0CAA0C,EAC1C,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,oCAAoC,EACpC,6BAA6B,GAC9B,MAAM,kEAAkE,CAAC;AAG1E,SAAS,MAAM,CAAC,OAAe;IAC7B,MAAM,IAAI,uBAAuB,CAC/B,eA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,UAA8C;IAE9C,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC/C,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO;YAC/C,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CACzB,QAA2C,EAC3C,MAA4C;IAE5C,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI;QACjD,MAAM,CAAC,yBAAyB,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC9C,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACrD,IACE,CAAC,QAAQ;YACT,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;YACjC,CAAC,6BAA6B,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC;YAErD,MAAM,CAAC,yDAAyD,CAAC,CAAC;QACpE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;AACH,CAAC","sourcesContent":["import {\n computePrincipalStatePayloadCiphertextHash,\n KeyingVerificationError,\n type ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport type { OrganizationPolicyHistoryResponse } from \"@tearleads/validators/response\";\nimport {\n type OrganizationAuthorityDescriptor,\n parseOrganizationAuthorityDescriptor,\n principalHeadMatchesReference,\n} from \"../../../data/principalContracts/organizationAuthorityDescriptor\";\nimport type { RecoveredPrincipalHistoryPage } from \"../../principals/historyRecovery/loadRecoveredPrincipalHistoryPage\";\n\nfunction reject(message: string): never {\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n `Organization policy history: ${message}`,\n );\n}\n\n/** Bind every display payload and public source to the privately verified page. */\nexport async function verifyOrganizationPolicyHistory(input: {\n readonly head: ReferencedPrincipalHead;\n readonly page: RecoveredPrincipalHistoryPage;\n readonly evidence: OrganizationPolicyHistoryResponse;\n}) {\n const { head, page, evidence } = input;\n const beforeVersion = (page.entries.at(-1)?.state.version ?? 0) + 1;\n if (\n head.principalType !== \"organization\" ||\n evidence.organizationId !== head.principalId ||\n evidence.stateHash !== head.stateHash ||\n evidence.beforeVersion !== beforeVersion ||\n evidence.nextBeforeVersion !== page.nextBeforeVersion ||\n !evidence.evidence.organization ||\n !principalHeadMatchesReference(evidence.evidence.organization.head, head)\n )\n reject(\"response does not match the requested organization page\");\n const entries = page.predecessor\n ? [page.predecessor, ...page.entries]\n : page.entries;\n if (evidence.evidence.organizationPayloads.length !== entries.length)\n reject(\"directory page is incomplete\");\n const descriptors = new Map<string, OrganizationAuthorityDescriptor>();\n const references: ReferencedPrincipalHead[] = [head];\n const groups = new Map<string, ReferencedPrincipalHead>();\n for (const [\n index,\n item,\n ] of evidence.evidence.organizationPayloads.entries()) {\n const { reference, payload } = item;\n const entry = entries[index];\n if (\n !entry ||\n !principalHeadMatchesReference(entry.state, reference) ||\n payload.principalType !== \"organization\" ||\n payload.principalId !== head.principalId ||\n payload.stateHash !== reference.stateHash ||\n descriptors.has(reference.stateHash)\n )\n reject(\"directory payload scope or order is invalid\");\n const hash = await computePrincipalStatePayloadCiphertextHash(\n payload.ciphertext,\n );\n if (\n hash !== entry.state.payloadCiphertextHash ||\n hash !== payload.ciphertextHash\n )\n reject(\"directory payload does not match its signed hash\");\n const descriptor = parseOrganizationAuthorityDescriptor(payload.ciphertext);\n if (descriptor.organizationId !== head.principalId)\n reject(\"directory belongs to another organization\");\n descriptors.set(reference.stateHash, descriptor);\n references.push(reference, ...descriptor.groupHeads);\n keepNewestGroupHeads(groups, descriptor.groupHeads);\n }\n verifyGroupSources(evidence, groups);\n return { descriptors, references };\n}\n\nfunction keepNewestGroupHeads(\n groups: Map<string, ReferencedPrincipalHead>,\n groupHeads: readonly ReferencedPrincipalHead[],\n) {\n for (const group of groupHeads) {\n const previous = groups.get(group.principalId);\n if (!previous || group.version > previous.version)\n groups.set(group.principalId, group);\n }\n}\n\nfunction verifyGroupSources(\n evidence: OrganizationPolicyHistoryResponse,\n groups: Map<string, ReferencedPrincipalHead>,\n) {\n if (evidence.evidence.groups.length !== groups.size)\n reject(\"unexpected group source\");\n const seen = new Set<string>();\n for (const source of evidence.evidence.groups) {\n const expected = groups.get(source.head.principalId);\n if (\n !expected ||\n seen.has(source.head.principalId) ||\n !principalHeadMatchesReference(source.head, expected)\n )\n reject(\"group source extends beyond the page's signed directory\");\n seen.add(source.head.principalId);\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { KeyingVerificationError } from "../../../internal/crypto/index.js";
2
- import { parseOrganizationAuthorityDescriptor, principalHeadMatchesReference, } from "../../../data/principals/organizationAuthorityDescriptor.js";
2
+ import { parseOrganizationAuthorityDescriptor, principalHeadMatchesReference, } from "../../../data/principalContracts/organizationAuthorityDescriptor.js";
3
3
  /** Couple supplied group receipts to the directory acknowledged in the same batch. */
4
4
  export function assertAcknowledgedDirectoryBindings(organizationId, receipts) {
5
5
  const directories = receipts.filter((receipt) => receipt.currentState.principalType === "organization");
@@ -1 +1 @@
1
- {"version":3,"file":"acknowledgedDirectoryBindings.js","sourceRoot":"","sources":["acknowledgedDirectoryBindings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,oCAAoC,EACpC,6BAA6B,GAC9B,MAAM,0DAA0D,CAAC;AAElE,sFAAsF;AACtF,MAAM,UAAU,mCAAmC,CACjD,cAAsB,EACtB,QAA+C;IAE/C,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CACjC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,aAAa,KAAK,cAAc,CACnE,CAAC;IACF,IACE,WAAW,CAAC,MAAM,KAAK,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,aAAa,KAAK,OAAO,CAAC;QAE1E,MAAM,IAAI,uBAAuB,CAC/B,oBAAoB,EACpB,0DAA0D,CAC3D,CAAC;IACJ,KAAK,MAAM,SAAS,IAAI,WAAW,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,oCAAoC,CACrD,SAAS,CAAC,cAAc,CAAC,UAAU,CACpC,CAAC;QACF,IACE,SAAS,CAAC,YAAY,CAAC,WAAW,KAAK,cAAc;YACrD,UAAU,CAAC,cAAc,KAAK,cAAc;YAC5C,QAAQ,CAAC,IAAI,CACX,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CACnB,YAAY,CAAC,aAAa,KAAK,OAAO;gBACtC,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACnC,6BAA6B,CAAC,IAAI,EAAE,YAAY,CAAC,CAClD,CACJ;YAED,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,2DAA2D,CAC5D,CAAC;IACN,CAAC;AACH,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport { KeyingVerificationError } from \"@tearleads/crypto\";\nimport {\n parseOrganizationAuthorityDescriptor,\n principalHeadMatchesReference,\n} from \"../../../data/principals/organizationAuthorityDescriptor\";\n\n/** Couple supplied group receipts to the directory acknowledged in the same batch. */\nexport function assertAcknowledgedDirectoryBindings(\n organizationId: string,\n receipts: readonly PrincipalPolicyPageCurrent[],\n) {\n const directories = receipts.filter(\n (receipt) => receipt.currentState.principalType === \"organization\",\n );\n if (\n directories.length === 0 &&\n receipts.some((receipt) => receipt.currentState.principalType === \"group\")\n )\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Acknowledged groups require their organization directory\",\n );\n for (const directory of directories) {\n const descriptor = parseOrganizationAuthorityDescriptor(\n directory.currentPayload.ciphertext,\n );\n if (\n directory.currentState.principalId !== organizationId ||\n descriptor.organizationId !== organizationId ||\n receipts.some(\n ({ currentState }) =>\n currentState.principalType === \"group\" &&\n !descriptor.groupHeads.some((head) =>\n principalHeadMatchesReference(head, currentState),\n ),\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Acknowledged organization does not bind its group receipt\",\n );\n }\n}\n"]}
1
+ {"version":3,"file":"acknowledgedDirectoryBindings.js","sourceRoot":"","sources":["acknowledgedDirectoryBindings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,oCAAoC,EACpC,6BAA6B,GAC9B,MAAM,kEAAkE,CAAC;AAE1E,sFAAsF;AACtF,MAAM,UAAU,mCAAmC,CACjD,cAAsB,EACtB,QAA+C;IAE/C,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CACjC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,aAAa,KAAK,cAAc,CACnE,CAAC;IACF,IACE,WAAW,CAAC,MAAM,KAAK,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,aAAa,KAAK,OAAO,CAAC;QAE1E,MAAM,IAAI,uBAAuB,CAC/B,oBAAoB,EACpB,0DAA0D,CAC3D,CAAC;IACJ,KAAK,MAAM,SAAS,IAAI,WAAW,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,oCAAoC,CACrD,SAAS,CAAC,cAAc,CAAC,UAAU,CACpC,CAAC;QACF,IACE,SAAS,CAAC,YAAY,CAAC,WAAW,KAAK,cAAc;YACrD,UAAU,CAAC,cAAc,KAAK,cAAc;YAC5C,QAAQ,CAAC,IAAI,CACX,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CACnB,YAAY,CAAC,aAAa,KAAK,OAAO;gBACtC,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACnC,6BAA6B,CAAC,IAAI,EAAE,YAAY,CAAC,CAClD,CACJ;YAED,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,2DAA2D,CAC5D,CAAC;IACN,CAAC;AACH,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport { KeyingVerificationError } from \"@tearleads/crypto\";\nimport {\n parseOrganizationAuthorityDescriptor,\n principalHeadMatchesReference,\n} from \"../../../data/principalContracts/organizationAuthorityDescriptor\";\n\n/** Couple supplied group receipts to the directory acknowledged in the same batch. */\nexport function assertAcknowledgedDirectoryBindings(\n organizationId: string,\n receipts: readonly PrincipalPolicyPageCurrent[],\n) {\n const directories = receipts.filter(\n (receipt) => receipt.currentState.principalType === \"organization\",\n );\n if (\n directories.length === 0 &&\n receipts.some((receipt) => receipt.currentState.principalType === \"group\")\n )\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Acknowledged groups require their organization directory\",\n );\n for (const directory of directories) {\n const descriptor = parseOrganizationAuthorityDescriptor(\n directory.currentPayload.ciphertext,\n );\n if (\n directory.currentState.principalId !== organizationId ||\n descriptor.organizationId !== organizationId ||\n receipts.some(\n ({ currentState }) =>\n currentState.principalType === \"group\" &&\n !descriptor.groupHeads.some((head) =>\n principalHeadMatchesReference(head, currentState),\n ),\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Acknowledged organization does not bind its group receipt\",\n );\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
2
- import { organizationAdminSignerUserIds } from "../../../data/principals/principalPolicyAdminSigners.js";
2
+ import { organizationAdminSignerUserIds } from "../../../data/principalContracts/principalPolicyAdminSigners.js";
3
3
  import { loadCurrentOrganizationAuthority } from "../currentOrganizationAuthority.js";
4
4
  /** Resolve uncertain work and verify the signing administrator before any mutation pins. */
5
5
  export async function loadCurrentOrganizationMutationAuthority(input) {
@@ -1 +1 @@
1
- {"version":3,"file":"currentOrganizationMutationAuthority.js","sourceRoot":"","sources":["currentOrganizationMutationAuthority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,8BAA8B,EAAE,MAAM,sDAAsD,CAAC;AACtG,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AAEnF,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,wCAAwC,CAC5D,KAQC;IAED,MAAM,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAC3B,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,KAAK,CAAC,+BAA+B,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAClE,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,MAAM,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAChE,MAAM,sBAAsB,GAAG,8BAA8B,CAC3D,SAAS,CAAC,MAAM,CAAC,MAAM,CACxB,CAAC;IACF,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["import { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { organizationAdminSignerUserIds } from \"../../../data/principals/principalPolicyAdminSigners\";\nimport { loadCurrentOrganizationAuthority } from \"../currentOrganizationAuthority\";\n\n/** Resolve uncertain work and verify the signing administrator before any mutation pins. */\nexport async function loadCurrentOrganizationMutationAuthority(\n input: Omit<\n Parameters<typeof loadCurrentOrganizationAuthority>[0],\n \"organizationReference\"\n > & {\n readonly signerUserId: string;\n readonly recoverPendingPrincipalMutation: (\n organizationId: string,\n ) => Promise<void>;\n },\n) {\n const owned = { ...input };\n assertProjectionVerificationCurrent(owned.stillCurrent);\n await owned.recoverPendingPrincipalMutation(owned.organizationId);\n assertProjectionVerificationCurrent(owned.stillCurrent);\n const authority = await loadCurrentOrganizationAuthority(owned);\n const currentOrgAdminUserIds = organizationAdminSignerUserIds(\n authority.admins.policy,\n );\n if (!currentOrgAdminUserIds.includes(owned.signerUserId))\n throw new Error(\"Organization admin authority is required\");\n return { authority, currentOrgAdminUserIds };\n}\n"]}
1
+ {"version":3,"file":"currentOrganizationMutationAuthority.js","sourceRoot":"","sources":["currentOrganizationMutationAuthority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,8BAA8B,EAAE,MAAM,8DAA8D,CAAC;AAC9G,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AAEnF,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,wCAAwC,CAC5D,KAQC;IAED,MAAM,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAC3B,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,KAAK,CAAC,+BAA+B,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAClE,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,MAAM,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAChE,MAAM,sBAAsB,GAAG,8BAA8B,CAC3D,SAAS,CAAC,MAAM,CAAC,MAAM,CACxB,CAAC;IACF,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["import { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { organizationAdminSignerUserIds } from \"../../../data/principalContracts/principalPolicyAdminSigners\";\nimport { loadCurrentOrganizationAuthority } from \"../currentOrganizationAuthority\";\n\n/** Resolve uncertain work and verify the signing administrator before any mutation pins. */\nexport async function loadCurrentOrganizationMutationAuthority(\n input: Omit<\n Parameters<typeof loadCurrentOrganizationAuthority>[0],\n \"organizationReference\"\n > & {\n readonly signerUserId: string;\n readonly recoverPendingPrincipalMutation: (\n organizationId: string,\n ) => Promise<void>;\n },\n) {\n const owned = { ...input };\n assertProjectionVerificationCurrent(owned.stillCurrent);\n await owned.recoverPendingPrincipalMutation(owned.organizationId);\n assertProjectionVerificationCurrent(owned.stillCurrent);\n const authority = await loadCurrentOrganizationAuthority(owned);\n const currentOrgAdminUserIds = organizationAdminSignerUserIds(\n authority.admins.policy,\n );\n if (!currentOrgAdminUserIds.includes(owned.signerUserId))\n throw new Error(\"Organization admin authority is required\");\n return { authority, currentOrgAdminUserIds };\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
2
+ import { principalPolicyReferenceFromBundle } from "../../../data/principalContracts/principalPolicyAdminSigners.js";
2
3
  import { scopedGroupHistoryProtection } from "../../../data/principals/principalHistoryScopeProtection.js";
3
- import { principalPolicyReferenceFromBundle } from "../../../data/principals/principalPolicyAdminSigners.js";
4
4
  import { captureAcknowledgedPrincipalPredecessor } from "../../principals/acknowledgements/acknowledgedPrincipalPredecessor.js";
5
5
  import { retainAcknowledgedPrincipalCurrents, } from "./retainAcknowledgedPrincipalCurrents.js";
6
6
  /** Couple directory acknowledgements to any newly created group under the same lease. */
@@ -1 +1 @@
1
- {"version":3,"file":"currentOrganizationMutationRetention.js","sourceRoot":"","sources":["currentOrganizationMutationRetention.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,4BAA4B,EAAE,MAAM,0DAA0D,CAAC;AACxG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sDAAsD,CAAC;AAG1G,OAAO,EAAE,uCAAuC,EAAE,MAAM,oEAAoE,CAAC;AAG7H,OAAO,EAEL,mCAAmC,GACpC,MAAM,uCAAuC,CAAC;AAE/C,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,0CAA0C,CAAC,KAahE;IACC,MAAM,WAAW,GAAG,MAAM,uCAAuC,CAAC;QAChE,GAAG,KAAK,CAAC,iBAAiB;QAC1B,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;QACpC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,KAAK,EAClB,OAAqD,EACrD,EAAE;QACF,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACxD,MAAM,mCAAmC,CAAC;YACxC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;YACpC,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,OAAO;YACP,YAAY,EAAE,KAAK,CAAC,YAAY;SACjC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,OAAO;QACL,eAAe,EAAE,CACf,OAAkC,EAClC,QAAyC,EACzC,EAAE,CACF,MAAM,CAAC;YACL,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,iBAAiB,EAAE;SACtE,CAAC;QACJ,kBAAkB,EAAE,CAAC,OAKpB,EAAE,EAAE;YACH,MAAM,SAAS,GAAG;gBAChB,GAAG,kCAAkC,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC;gBACrE,aAAa,EAAE,OAAgB;aAChC,CAAC;YACF,OAAO,MAAM,CAAC;gBACZ;oBACE,YAAY,EAAE,IAAI;oBAClB,WAAW,EAAE,IAAI;oBACjB,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,QAAQ,EAAE;wBACR,aAAa,EAAE,KAAK,CAAC,aAAa;wBAClC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;wBACnC,UAAU,EAAE,4BAA4B,CACtC,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,YAAY,CACxC;wBACD,0BAA0B,EACxB,KAAK,CAAC,OAAO,CAAC,0BAA0B;wBAC1C,qBAAqB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;4BAClC,WAAW,EAAE,SAAS;4BACtB,MAAM,EAAE;gCACN;oCACE,IAAI,EAAE,SAAS;oCACf,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU;iCACrD;6BACF;yBACF,CAAC;qBACH;iBACF;gBACD;oBACE,WAAW;oBACX,OAAO,EAAE,OAAO,CAAC,mBAAmB;oBACpC,QAAQ,EAAE,OAAO,CAAC,oBAAoB;oBACtC,QAAQ,EAAE,KAAK,CAAC,iBAAiB;iBAClC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { PrincipalPolicyHistoryProgressOptions } from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyMutationResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { scopedGroupHistoryProtection } from \"../../../data/principals/principalHistoryScopeProtection\";\nimport { principalPolicyReferenceFromBundle } from \"../../../data/principals/principalPolicyAdminSigners\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport { captureAcknowledgedPrincipalPredecessor } from \"../../principals/acknowledgements/acknowledgedPrincipalPredecessor\";\nimport type { PrincipalPolicyPageReader } from \"../../principals/principalPolicyHistoryReader\";\nimport type { loadCurrentOrganizationAuthority } from \"../currentOrganizationAuthority\";\nimport {\n type AcknowledgedPrincipalCurrentInput,\n retainAcknowledgedPrincipalCurrents,\n} from \"./retainAcknowledgedPrincipalCurrents\";\n\n/** Couple directory acknowledgements to any newly created group under the same lease. */\nexport async function createCurrentOrganizationMutationRetention(input: {\n readonly runtime: {\n readonly infra: { readonly execSql: ExecSql };\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n };\n readonly authority: Awaited<\n ReturnType<typeof loadCurrentOrganizationAuthority>\n >;\n readonly protection: PrincipalPolicyHistoryProgressOptions;\n readonly historyReader: PrincipalPolicyPageReader;\n readonly organizationId: string;\n readonly directoryRecovery: AcknowledgedPrincipalCurrentInput[\"recovery\"];\n readonly stillCurrent: () => boolean;\n}) {\n const predecessor = await captureAcknowledgedPrincipalPredecessor({\n ...input.directoryRecovery,\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n stillCurrent: input.stillCurrent,\n });\n const retain = async (\n entries: readonly AcknowledgedPrincipalCurrentInput[],\n ) => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n await retainAcknowledgedPrincipalCurrents({\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n entries,\n stillCurrent: input.stillCurrent,\n });\n };\n return {\n retainDirectory: (\n request: PutPrincipalPolicyRequest,\n response: PrincipalPolicyMutationResponse,\n ) =>\n retain([\n { predecessor, request, response, recovery: input.directoryRecovery },\n ]),\n retainCreatedGroup: (receipt: {\n readonly request: PutPrincipalPolicyRequest;\n readonly response: PrincipalPolicyMutationResponse;\n readonly organizationRequest: PutPrincipalPolicyRequest;\n readonly organizationResponse: PrincipalPolicyMutationResponse;\n }) => {\n const adminHead = {\n ...principalPolicyReferenceFromBundle(input.authority.admins.current),\n principalType: \"group\" as const,\n };\n return retain([\n {\n initialGroup: true,\n predecessor: null,\n request: receipt.request,\n response: receipt.response,\n recovery: {\n historyReader: input.historyReader,\n expectedHead: receipt.response.head,\n protection: scopedGroupHistoryProtection(\n input.protection,\n input.organizationId,\n input.authority.descriptor.adminGroupId,\n ),\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n loadExternalAuthority: async () => ({\n currentHead: adminHead,\n states: [\n {\n head: adminHead,\n projection: input.authority.admins.policy.projection,\n },\n ],\n }),\n },\n },\n {\n predecessor,\n request: receipt.organizationRequest,\n response: receipt.organizationResponse,\n recovery: input.directoryRecovery,\n },\n ]);\n },\n };\n}\n"]}
1
+ {"version":3,"file":"currentOrganizationMutationRetention.js","sourceRoot":"","sources":["currentOrganizationMutationRetention.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AACvG,OAAO,EAAE,kCAAkC,EAAE,MAAM,8DAA8D,CAAC;AAClH,OAAO,EAAE,4BAA4B,EAAE,MAAM,0DAA0D,CAAC;AAGxG,OAAO,EAAE,uCAAuC,EAAE,MAAM,oEAAoE,CAAC;AAG7H,OAAO,EAEL,mCAAmC,GACpC,MAAM,uCAAuC,CAAC;AAE/C,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,0CAA0C,CAAC,KAahE;IACC,MAAM,WAAW,GAAG,MAAM,uCAAuC,CAAC;QAChE,GAAG,KAAK,CAAC,iBAAiB;QAC1B,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;QACpC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG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UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU;iCACrD;6BACF;yBACF,CAAC;qBACH;iBACF;gBACD;oBACE,WAAW;oBACX,OAAO,EAAE,OAAO,CAAC,mBAAmB;oBACpC,QAAQ,EAAE,OAAO,CAAC,oBAAoB;oBACtC,QAAQ,EAAE,KAAK,CAAC,iBAAiB;iBAClC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { PrincipalPolicyHistoryProgressOptions } from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyMutationResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../../data/keyingProjectionVerification/types\";\nimport { principalPolicyReferenceFromBundle } from \"../../../data/principalContracts/principalPolicyAdminSigners\";\nimport { scopedGroupHistoryProtection } from \"../../../data/principals/principalHistoryScopeProtection\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport { captureAcknowledgedPrincipalPredecessor } from \"../../principals/acknowledgements/acknowledgedPrincipalPredecessor\";\nimport type { PrincipalPolicyPageReader } from \"../../principals/principalPolicyHistoryReader\";\nimport type { loadCurrentOrganizationAuthority } from \"../currentOrganizationAuthority\";\nimport {\n type AcknowledgedPrincipalCurrentInput,\n retainAcknowledgedPrincipalCurrents,\n} from \"./retainAcknowledgedPrincipalCurrents\";\n\n/** Couple directory acknowledgements to any newly created group under the same lease. */\nexport async function createCurrentOrganizationMutationRetention(input: {\n readonly runtime: {\n readonly infra: { readonly execSql: ExecSql };\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n };\n readonly authority: Awaited<\n ReturnType<typeof loadCurrentOrganizationAuthority>\n >;\n readonly protection: PrincipalPolicyHistoryProgressOptions;\n readonly historyReader: PrincipalPolicyPageReader;\n readonly organizationId: string;\n readonly directoryRecovery: AcknowledgedPrincipalCurrentInput[\"recovery\"];\n readonly stillCurrent: () => boolean;\n}) {\n const predecessor = await captureAcknowledgedPrincipalPredecessor({\n ...input.directoryRecovery,\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n stillCurrent: input.stillCurrent,\n });\n const retain = async (\n entries: readonly AcknowledgedPrincipalCurrentInput[],\n ) => {\n assertProjectionVerificationCurrent(input.stillCurrent);\n await retainAcknowledgedPrincipalCurrents({\n execSql: input.runtime.infra.execSql,\n organizationId: input.organizationId,\n entries,\n stillCurrent: input.stillCurrent,\n });\n };\n return {\n retainDirectory: (\n request: PutPrincipalPolicyRequest,\n response: PrincipalPolicyMutationResponse,\n ) =>\n retain([\n { predecessor, request, response, recovery: input.directoryRecovery },\n ]),\n retainCreatedGroup: (receipt: {\n readonly request: PutPrincipalPolicyRequest;\n readonly response: PrincipalPolicyMutationResponse;\n readonly organizationRequest: PutPrincipalPolicyRequest;\n readonly organizationResponse: PrincipalPolicyMutationResponse;\n }) => {\n const adminHead = {\n ...principalPolicyReferenceFromBundle(input.authority.admins.current),\n principalType: \"group\" as const,\n };\n return retain([\n {\n initialGroup: true,\n predecessor: null,\n request: receipt.request,\n response: receipt.response,\n recovery: {\n historyReader: input.historyReader,\n expectedHead: receipt.response.head,\n protection: scopedGroupHistoryProtection(\n input.protection,\n input.organizationId,\n input.authority.descriptor.adminGroupId,\n ),\n resolveTrustedUserIdentity:\n input.runtime.resolveTrustedUserIdentity,\n loadExternalAuthority: async () => ({\n currentHead: adminHead,\n states: [\n {\n head: adminHead,\n projection: input.authority.admins.policy.projection,\n },\n ],\n }),\n },\n },\n {\n predecessor,\n request: receipt.organizationRequest,\n response: receipt.organizationResponse,\n recovery: input.directoryRecovery,\n },\n ]);\n },\n };\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { assertProjectionVerificationCurrent } from "../../../data/keyingProjectionVerification/types.js";
2
+ import { principalPolicyReferenceFromBundle } from "../../../data/principalContracts/principalPolicyAdminSigners.js";
2
3
  import { scopedGroupHistoryProtection } from "../../../data/principals/principalHistoryScopeProtection.js";
3
- import { principalPolicyReferenceFromBundle } from "../../../data/principals/principalPolicyAdminSigners.js";
4
4
  import { captureAcknowledgedPrincipalPredecessor } from "../../principals/acknowledgements/acknowledgedPrincipalPredecessor.js";
5
5
  import { createCurrentPrincipalMutationLease, } from "../../principals/principalPolicyService.js";
6
6
  import { loadCurrentGroupPolicyMutationContext } from "../groupPolicy/currentGroupPolicyMutationContext.js";
@@ -1 +1 @@
1
- {"version":3,"file":"runtimeCurrentGroupMutation.js","sourceRoot":"","sources":["runtimeCurrentGroupMutation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mCAAmC,EAAE,MAAM,kDAAkD,CAAC;AAEvG,OAAO,EAAE,4BAA4B,EAAE,MAAM,0DAA0D,CAAC;AACxG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sDAAsD,CAAC;AAE1G,OAAO,EAAE,uCAAuC,EAAE,MAAM,oEAAoE,CAAC;AAE7H,OAAO,EACL,mCAAmC,GAEpC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,qCAAqC,EAAE,MAAM,kDAAkD,CAAC;AACzG,OAAO,EAAE,qCAAqC,EAAE,MAAM,kCAAkC,CAAC;AAEzF,OAAO,EAEL,mCAAmC,GACpC,MAAM,uCAAuC,CAAC;AA+C/C,sFAAsF;AACtF,MAAM,UAAU,iCAAiC,CAAC,OAAwB;IACxE,MAAM,KAAK,GAAG,mCAAmC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7E,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,aA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,CAAC,OAAO,CAAC,gBAAgB,IAAI,EAAE,CAAC;gBACnC;oBACE,QAAQ,EAAE,aAAa;oBACvB,WAAW,EAAE,gBAAgB;oBAC7B,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW;iBACvC;gBACD;oBACE,QAAQ,EAAE,iBAAiB;oBAC3B,WAAW,EAAE,oBAAoB;oBACjC,OAAO,EAAE,OAAO,CAAC,mBAAmB;oBACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,kBAAkB;iBAC9C;aACF;YACD,WAAW,EAAE;gBACX,GAAG,CAAC,OAAO,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBAClD,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW;oBAC5C,aAAa,EAAE,OAAgB;oBAC/B,YAAY,EAAE,KAAK,CAAC,mBAAmB,IAAI,EAAE;iBAC9C,CAAC,CAAC;gBACH;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;IACF,OAAO;QACL,cAAc,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE;QAC1E,kBAAkB;KACnB,CAAC;AACJ,CAAC","sourcesContent":["import 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 { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport { captureAcknowledgedPrincipalPredecessor } from \"../../principals/acknowledgements/acknowledgedPrincipalPredecessor\";\nimport type { PrincipalPolicyPageReader } from \"../../principals/principalPolicyHistoryReader\";\nimport {\n createCurrentPrincipalMutationLease,\n type PrincipalPolicyRuntime,\n} from \"../../principals/principalPolicyService\";\nimport { loadCurrentGroupPolicyMutationContext } from \"../groupPolicy/currentGroupPolicyMutationContext\";\nimport { resolveCurrentGroupMutationReferences } from \"./currentGroupMutationReferences\";\nimport type { PrincipalMutationRecoveryApi } from \"./principalMutationJournalManagement\";\nimport {\n type AcknowledgedPrincipalCurrentInput,\n retainAcknowledgedPrincipalCurrents,\n} from \"./retainAcknowledgedPrincipalCurrents\";\n\ntype MutationRuntime = PrincipalPolicyRuntime & {\n readonly apiClient: Pick<\n PrincipalMutationRecoveryApi,\n \"recoverPendingPrincipalMutation\"\n >;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n};\n\ntype CurrentMutationContext = Awaited<\n ReturnType<typeof loadCurrentGroupPolicyMutationContext>\n>;\n\nexport type RuntimeCurrentGroupMutationContext = CurrentMutationContext & {\n readonly resolveAuthoredPolicyReferences: CurrentPolicyReferenceResolver;\n readonly loadGroup: (\n groupId: string,\n ) => Promise<RuntimeCurrentGroupMutationContext>;\n readonly groupRetention: Pick<\n AcknowledgedPrincipalCurrentInput,\n \"recovery\" | \"predecessor\"\n >;\n readonly retainAcknowledged: (\n receipt: CurrentMutationReceipt,\n ) => Promise<void>;\n};\n\ninterface CurrentMutationReceipt {\n readonly additionalGroups?:\n | readonly (AcknowledgedPrincipalCurrentInput & {\n readonly retiredContainerIds?: readonly string[] | undefined;\n })[]\n | undefined;\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.principalPolicies);\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 historyReader,\n directoryRecovery,\n }) => {\n const loadGroup = async (\n groupId: string,\n ): Promise<RuntimeCurrentGroupMutationContext> => {\n const context = await loadCurrentGroupPolicyMutationContext({\n ...input,\n groupId,\n execSql: runtime.infra.execSql,\n resolveCurrentPolicy,\n recoverPendingPrincipalMutation: (organizationId) =>\n runtime.apiClient.recoverPendingPrincipalMutation(organizationId),\n stillCurrent,\n });\n const retention = await createCurrentMutationRetention(\n runtime,\n { ...input, groupId },\n context,\n protection,\n historyReader,\n directoryRecovery(context.organizationCurrent.current),\n );\n return {\n ...context,\n ...retention,\n loadGroup,\n resolveAuthoredPolicyReferences: (current, references) =>\n resolveCurrentGroupMutationReferences({\n current,\n predecessor: context.verifiedCurrentPolicy,\n references,\n readPredecessorReference: context.readPredecessorReference,\n stillCurrent: context.stillCurrent,\n }),\n };\n };\n const context = await loadGroup(input.groupId);\n const result = await work(context);\n assertProjectionVerificationCurrent(context.stillCurrent);\n return result;\n },\n );\n };\n}\n\nasync function createCurrentMutationRetention(\n runtime: MutationRuntime,\n input: MutationInput,\n context: CurrentMutationContext,\n protection: PrincipalPolicyHistoryProgressOptions,\n historyReader: PrincipalPolicyPageReader,\n directoryRecovery: AcknowledgedPrincipalCurrentInput[\"recovery\"],\n) {\n const common = {\n historyReader,\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 const capture = (recovery: AcknowledgedPrincipalCurrentInput[\"recovery\"]) =>\n captureAcknowledgedPrincipalPredecessor({\n ...recovery,\n execSql: runtime.infra.execSql,\n organizationId: input.organizationId,\n stillCurrent: context.stillCurrent,\n });\n const groupPredecessor = await capture(groupRecovery);\n const directoryPredecessor = await capture(directoryRecovery);\n const retainAcknowledged = async (\n receipt: CurrentMutationReceipt,\n ): Promise<void> => {\n assertProjectionVerificationCurrent(context.stillCurrent);\n await retainAcknowledgedPrincipalCurrents({\n execSql: runtime.infra.execSql,\n organizationId: input.organizationId,\n entries: [\n ...(receipt.additionalGroups ?? []),\n {\n recovery: groupRecovery,\n predecessor: groupPredecessor,\n request: receipt.request,\n response: receipt.response.groupPolicy,\n },\n {\n recovery: directoryRecovery,\n predecessor: directoryPredecessor,\n request: receipt.organizationRequest,\n response: receipt.response.organizationPolicy,\n },\n ],\n retirements: [\n ...(receipt.additionalGroups ?? []).map((entry) => ({\n principalId: entry.request.state.principalId,\n principalType: \"group\" as const,\n containerIds: entry.retiredContainerIds ?? [],\n })),\n {\n principalId: input.groupId,\n principalType: \"group\",\n containerIds: receipt.retiredContainerIds ?? [],\n },\n ],\n stillCurrent: context.stillCurrent,\n });\n };\n return {\n groupRetention: { recovery: groupRecovery, predecessor: groupPredecessor },\n retainAcknowledged,\n };\n}\n"]}
1
+ {"version":3,"file":"runtimeCurrentGroup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C9C;aACF;YACD,WAAW,EAAE;gBACX,GAAG,CAAC,OAAO,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBAClD,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW;oBAC5C,aAAa,EAAE,OAAgB;oBAC/B,YAAY,EAAE,KAAK,CAAC,mBAAmB,IAAI,EAAE;iBAC9C,CAAC,CAAC;gBACH;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;IACF,OAAO;QACL,cAAc,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE;QAC1E,kBAAkB;KACnB,CAAC;AACJ,CAAC","sourcesContent":["import 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 { principalPolicyReferenceFromBundle } from \"../../../data/principalContracts/principalPolicyAdminSigners\";\nimport type { CurrentPolicyReferenceResolver } from \"../../../data/principals/currentPolicyReferenceResolver\";\nimport { scopedGroupHistoryProtection } from \"../../../data/principals/principalHistoryScopeProtection\";\nimport type { TrustedUserIdentityResolver } from \"../../../data/trustedUserIdentity\";\nimport { captureAcknowledgedPrincipalPredecessor } from \"../../principals/acknowledgements/acknowledgedPrincipalPredecessor\";\nimport type { PrincipalPolicyPageReader } from \"../../principals/principalPolicyHistoryReader\";\nimport {\n createCurrentPrincipalMutationLease,\n type PrincipalPolicyRuntime,\n} from \"../../principals/principalPolicyService\";\nimport { loadCurrentGroupPolicyMutationContext } from \"../groupPolicy/currentGroupPolicyMutationContext\";\nimport { resolveCurrentGroupMutationReferences } from \"./currentGroupMutationReferences\";\nimport type { PrincipalMutationRecoveryApi } from \"./principalMutationJournalManagement\";\nimport {\n type AcknowledgedPrincipalCurrentInput,\n retainAcknowledgedPrincipalCurrents,\n} from \"./retainAcknowledgedPrincipalCurrents\";\n\ntype MutationRuntime = PrincipalPolicyRuntime & {\n readonly apiClient: Pick<\n PrincipalMutationRecoveryApi,\n \"recoverPendingPrincipalMutation\"\n >;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n};\n\ntype CurrentMutationContext = Awaited<\n ReturnType<typeof loadCurrentGroupPolicyMutationContext>\n>;\n\nexport type RuntimeCurrentGroupMutationContext = CurrentMutationContext & {\n readonly resolveAuthoredPolicyReferences: CurrentPolicyReferenceResolver;\n readonly loadGroup: (\n groupId: string,\n ) => Promise<RuntimeCurrentGroupMutationContext>;\n readonly groupRetention: Pick<\n AcknowledgedPrincipalCurrentInput,\n \"recovery\" | \"predecessor\"\n >;\n readonly retainAcknowledged: (\n receipt: CurrentMutationReceipt,\n ) => Promise<void>;\n};\n\ninterface CurrentMutationReceipt {\n readonly additionalGroups?:\n | readonly (AcknowledgedPrincipalCurrentInput & {\n readonly retiredContainerIds?: readonly string[] | undefined;\n })[]\n | undefined;\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.principalPolicies);\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 historyReader,\n directoryRecovery,\n }) => {\n const loadGroup = async (\n groupId: string,\n ): Promise<RuntimeCurrentGroupMutationContext> => {\n const context = await loadCurrentGroupPolicyMutationContext({\n ...input,\n groupId,\n execSql: runtime.infra.execSql,\n resolveCurrentPolicy,\n recoverPendingPrincipalMutation: (organizationId) =>\n runtime.apiClient.recoverPendingPrincipalMutation(organizationId),\n stillCurrent,\n });\n const retention = await createCurrentMutationRetention(\n runtime,\n { ...input, groupId },\n context,\n protection,\n historyReader,\n directoryRecovery(context.organizationCurrent.current),\n );\n return {\n ...context,\n ...retention,\n loadGroup,\n resolveAuthoredPolicyReferences: (current, references) =>\n resolveCurrentGroupMutationReferences({\n current,\n predecessor: context.verifiedCurrentPolicy,\n references,\n readPredecessorReference: context.readPredecessorReference,\n stillCurrent: context.stillCurrent,\n }),\n };\n };\n const context = await loadGroup(input.groupId);\n const result = await work(context);\n assertProjectionVerificationCurrent(context.stillCurrent);\n return result;\n },\n );\n };\n}\n\nasync function createCurrentMutationRetention(\n runtime: MutationRuntime,\n input: MutationInput,\n context: CurrentMutationContext,\n protection: PrincipalPolicyHistoryProgressOptions,\n historyReader: PrincipalPolicyPageReader,\n directoryRecovery: AcknowledgedPrincipalCurrentInput[\"recovery\"],\n) {\n const common = {\n historyReader,\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 const capture = (recovery: AcknowledgedPrincipalCurrentInput[\"recovery\"]) =>\n captureAcknowledgedPrincipalPredecessor({\n ...recovery,\n execSql: runtime.infra.execSql,\n organizationId: input.organizationId,\n stillCurrent: context.stillCurrent,\n });\n const groupPredecessor = await capture(groupRecovery);\n const directoryPredecessor = await capture(directoryRecovery);\n const retainAcknowledged = async (\n receipt: CurrentMutationReceipt,\n ): Promise<void> => {\n assertProjectionVerificationCurrent(context.stillCurrent);\n await retainAcknowledgedPrincipalCurrents({\n execSql: runtime.infra.execSql,\n organizationId: input.organizationId,\n entries: [\n ...(receipt.additionalGroups ?? []),\n {\n recovery: groupRecovery,\n predecessor: groupPredecessor,\n request: receipt.request,\n response: receipt.response.groupPolicy,\n },\n {\n recovery: directoryRecovery,\n predecessor: directoryPredecessor,\n request: receipt.organizationRequest,\n response: receipt.response.organizationPolicy,\n },\n ],\n retirements: [\n ...(receipt.additionalGroups ?? []).map((entry) => ({\n principalId: entry.request.state.principalId,\n principalType: \"group\" as const,\n containerIds: entry.retiredContainerIds ?? [],\n })),\n {\n principalId: input.groupId,\n principalType: \"group\",\n containerIds: receipt.retiredContainerIds ?? [],\n },\n ],\n stillCurrent: context.stillCurrent,\n });\n };\n return {\n groupRetention: { recovery: groupRecovery, predecessor: groupPredecessor },\n retainAcknowledged,\n };\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { compareCanonicalStrings, computeContainerKekRecipientTargetHash, computeContainerKeyEpochHash, computePrincipalStateHash, } from "../../../internal/crypto/index.js";
2
2
  import { canonicalKeyingJsonString } from "../../../data/keying/canonicalJson.js";
3
3
  import { readContainerKeyEpoch, readContainerKeyWrap, } from "../../../data/keyingProjectionVerification/readers.js";
4
- import { principalHeadMatchesReference } from "../../../data/principals/organizationAuthorityDescriptor.js";
4
+ import { principalHeadMatchesReference } from "../../../data/principalContracts/organizationAuthorityDescriptor.js";
5
5
  function sortedCanonicalValues(values, label) {
6
6
  return [...values].sort((left, right) => compareCanonicalStrings(canonicalKeyingJsonString(left, label), canonicalKeyingJsonString(right, label)));
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"principalPolicyReceiptArtifacts.js","sourceRoot":"","sources":["principalPolicyReceiptArtifacts.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,sCAAsC,EACtC,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAO3B,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EACL,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0DAA0D,CAAC;AAEzG,SAAS,qBAAqB,CAAI,MAAoB,EAAE,KAAa;IACnE,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACtC,uBAAuB,CACrB,yBAAyB,CAAC,IAAI,EAAE,KAAK,CAAC,EACtC,yBAAyB,CAAC,KAAK,EAAE,KAAK,CAAC,CACxC,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8CAA8C,CAC5D,QAAiD,EACjD,QAAiD;IAEjD,MAAM,UAAU,GAAG,CAAC,KAA8C,EAAE,EAAE,CAAC,CAAC;QACtE,GAAG,KAAK;QACR,SAAS,EAAE,qBAAqB,CAC9B,KAAK,CAAC,SAAS,EACf,2BAA2B,CAC5B;KACF,CAAC,CAAC;IACH,IACE,yBAAyB,CACvB,UAAU,CAAC,QAAQ,CAAC,EACpB,qCAAqC,CACtC;QACD,yBAAyB,CACvB,UAAU,CAAC,QAAQ,CAAC,EACpB,iCAAiC,CAClC,EACD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,uCAAuC,CAAC,KAKtD;IACC,IAAI,CAAC,KAAK,CAAC,SA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C;IACzE,MAAM,uCAAuC,CAAC;QAC5C,QAAQ,EAAE,OAAO,CAAC,kBAAkB,IAAI,EAAE;QAC1C,SAAS,EAAE,QAAQ,CAAC,kBAAkB;KACvC,CAAC,CAAC;IACH,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAC7C,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;IAC/B,OAAO;QACL,YAAY,EAAE,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE;QAChD,cAAc,EAAE;YACd,aAAa;YACb,WAAW;YACX,SAAS;YACT,GAAG,OAAO,CAAC,gBAAgB;YAC3B,SAAS;SACV;QACD,iBAAiB,EAAE,OAAO,CAAC,UAAU;QACrC,aAAa,EAAE,OAAO,CAAC,MAAM;QAC7B,sBAAsB,EAAE;YACtB,aAAa;YACb,WAAW;YACX,SAAS;YACT,KAAK,EAAE,KAAK,CAAC,QAAQ;YACrB,SAAS,EAAE,OAAO,CAAC,eAAe;SACnC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport {\n compareCanonicalStrings,\n computeContainerKekRecipientTargetHash,\n computeContainerKeyEpochHash,\n computePrincipalStateHash,\n} from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerMutationResponse,\n CurrentPrincipalMemberEnvelopesResponse,\n PrincipalPolicyMutationResponse,\n} from \"@tearleads/validators/response\";\nimport { canonicalKeyingJsonString } from \"../../../data/keying/canonicalJson\";\nimport {\n readContainerKeyEpoch,\n readContainerKeyWrap,\n} from \"../../../data/keyingProjectionVerification/readers\";\nimport { principalHeadMatchesReference } from \"../../../data/principals/organizationAuthorityDescriptor\";\n\nfunction sortedCanonicalValues<T>(values: readonly T[], label: string): T[] {\n return [...values].sort((left, right) =>\n compareCanonicalStrings(\n canonicalKeyingJsonString(left, label),\n canonicalKeyingJsonString(right, label),\n ),\n );\n}\n\nexport function assertGroupPolicyEnvelopesMatchAcknowledgement(\n expected: CurrentPrincipalMemberEnvelopesResponse,\n observed: CurrentPrincipalMemberEnvelopesResponse,\n): void {\n const normalized = (value: CurrentPrincipalMemberEnvelopesResponse) => ({\n ...value,\n envelopes: sortedCanonicalValues(\n value.envelopes,\n \"principal member envelope\",\n ),\n });\n if (\n canonicalKeyingJsonString(\n normalized(expected),\n \"acknowledged group member envelopes\",\n ) !==\n canonicalKeyingJsonString(\n normalized(observed),\n \"observed group member envelopes\",\n )\n ) {\n throw new Error(\"Group member envelopes changed after acknowledgement\");\n }\n}\n\n/**\n * Each rematerialized container's acknowledgement names its commit by hash;\n * match every hash against the request this client authored.\n */\nasync function assertContainerMutationAcknowledgements(input: {\n readonly requests: readonly NonNullable<\n PutPrincipalPolicyRequest[\"containerMutations\"]\n >[number][];\n readonly responses: readonly ContainerMutationResponse[] | undefined;\n}): Promise<void> {\n if (!input.responses || input.responses.length !== input.requests.length) {\n throw new Error(\n \"Group policy container acknowledgement batch is incomplete\",\n );\n }\n for (const [index, request] of input.requests.entries()) {\n const response = input.responses[index];\n if (!response) {\n throw new Error(\n \"Group policy container acknowledgement batch is incomplete\",\n );\n }\n const label = \"authored group policy container mutation\";\n const keyEpoch = readContainerKeyEpoch(request.keyEpoch, label);\n const recipientTargets = sortedCanonicalValues(\n request.wraps.map((value) => {\n const wrap = readContainerKeyWrap(value, label);\n return {\n recipientId: wrap.recipientId,\n recipientKeyEpochId: wrap.recipientKeyEpochId,\n recipientKeyFingerprint: wrap.recipientKeyFingerprint,\n recipientKind: wrap.recipientKind,\n };\n }),\n \"authored recipient target\",\n );\n // The request carries this client's own hash of the manifest it signed,\n // and that manifest names its epoch and event by hash. A rotation's signed\n // body commits its keyring hash, so a substituted keyring must refuse\n // here, before journal recovery clears the saved request. A grant that\n // keeps its epoch commits none; the container acknowledgement checks the\n // retained keyring against the epoch's own.\n const committedKeyringHash = Reflect.get(\n Object(request.body),\n \"keyringHash\",\n );\n if (\n response.manifestHead.manifestHash !== request.expectedManifestHash ||\n response.manifestHead.epoch !== Reflect.get(request.manifest, \"epoch\") ||\n response.eventHash !== Reflect.get(request.manifest, \"eventHash\") ||\n response.containerKek.containerKeyEpochId !== keyEpoch.id ||\n response.containerKek.containerKeyEpoch !== keyEpoch.keyEpoch ||\n response.containerKek.keyEpochHash !==\n (await computeContainerKeyEpochHash(keyEpoch)) ||\n (typeof committedKeyringHash === \"string\" &&\n response.containerKek.keyringHash !== committedKeyringHash) ||\n response.containerKek.keyTargetHash !==\n (await computeContainerKekRecipientTargetHash(recipientTargets))\n ) {\n throw new Error(\"Group policy container acknowledgement mismatch\");\n }\n }\n}\n\n/**\n * The current an acknowledgement commits, rebuilt from this client's own\n * signed request: the server returns only the head it stored, the insertion\n * time it assigned to the state and payload, and hash-form container\n * acknowledgements. A head other than the one the request commits to refuses.\n * Nothing here manufactures predecessor history or pins.\n */\nexport async function acknowledgedPrincipalPolicyCurrent(input: {\n readonly request: PutPrincipalPolicyRequest;\n readonly response: PrincipalPolicyMutationResponse;\n}): Promise<PrincipalPolicyPageCurrent> {\n const { request, response } = input;\n const { state } = request;\n const stateHash = await computePrincipalStateHash(state);\n if (\n !principalHeadMatchesReference(response.head, {\n principalType: state.principalType,\n principalId: state.principalId,\n version: state.version,\n keyEpoch: state.keyEpoch,\n stateHash,\n keyFingerprint: state.keyFingerprint,\n })\n )\n throw new Error(\"Principal policy acknowledgement names another head\");\n await assertContainerMutationAcknowledgements({\n requests: request.containerMutations ?? [],\n responses: response.containerMutations,\n });\n const { principalType, principalId } = state;\n const { createdAt } = response;\n return {\n currentState: { ...state, stateHash, createdAt },\n currentPayload: {\n principalType,\n principalId,\n stateHash,\n ...request.encryptedPayload,\n createdAt,\n },\n currentProjection: request.projection,\n currentGrants: request.grants,\n currentMemberEnvelopes: {\n principalType,\n principalId,\n stateHash,\n epoch: state.keyEpoch,\n envelopes: request.memberEnvelopes,\n },\n };\n}\n"]}
1
+ {"version":3,"file":"principalPolicyReceiptArtifacts.js","sourceRoot":"","sources":["principalPolicyReceiptArtifacts.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,sCAAsC,EACtC,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAO3B,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EACL,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,kEAAkE,CAAC;AAEjH,SAAS,qBAAqB,CAAI,MAAoB,EAAE,KAAa;IACnE,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACtC,uBAAuB,CACrB,yBAAyB,CAAC,IAAI,EAAE,KAAK,CAAC,EACtC,yBAAyB,CAAC,KAAK,EAAE,KAAK,CAAC,CACxC,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8CAA8C,CAC5D,QAAiD,EACjD,QAAiD;IAEjD,MAAM,UAAU,GAAG,CAAC,KAA8C,EAAE,EAAE,CAAC,CAAC;QACtE,GAAG,KAAK;QACR,SAAS,EAAE,qBAAqB,CAC9B,KAAK,CAAC,SAAS,EACf,2BAA2B,CAC5B;KACF,CAAC,CAAC;IACH,IACE,yBAAyB,CACvB,UAAU,CAAC,QAAQ,CAAC,EACpB,qCAAqC,CACtC;QACD,yBAAyB,CACvB,UAAU,CAAC,QAAQ,CAAC,EACpB,iCAAiC,CAClC,EACD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,uCAAuC,CAAC,KAKtD;IACC,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,MAAM,KAAK,KAAK,CAAC,QAAQ,CAAC,MAAM,E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AE;QAC1C,SAAS,EAAE,QAAQ,CAAC,kBAAkB;KACvC,CAAC,CAAC;IACH,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAC7C,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;IAC/B,OAAO;QACL,YAAY,EAAE,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE;QAChD,cAAc,EAAE;YACd,aAAa;YACb,WAAW;YACX,SAAS;YACT,GAAG,OAAO,CAAC,gBAAgB;YAC3B,SAAS;SACV;QACD,iBAAiB,EAAE,OAAO,CAAC,UAAU;QACrC,aAAa,EAAE,OAAO,CAAC,MAAM;QAC7B,sBAAsB,EAAE;YACtB,aAAa;YACb,WAAW;YACX,SAAS;YACT,KAAK,EAAE,KAAK,CAAC,QAAQ;YACrB,SAAS,EAAE,OAAO,CAAC,eAAe;SACnC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport {\n compareCanonicalStrings,\n computeContainerKekRecipientTargetHash,\n computeContainerKeyEpochHash,\n computePrincipalStateHash,\n} from \"@tearleads/crypto\";\nimport type { PutPrincipalPolicyRequest } from \"@tearleads/validators/request\";\nimport type {\n ContainerMutationResponse,\n CurrentPrincipalMemberEnvelopesResponse,\n PrincipalPolicyMutationResponse,\n} from \"@tearleads/validators/response\";\nimport { canonicalKeyingJsonString } from \"../../../data/keying/canonicalJson\";\nimport {\n readContainerKeyEpoch,\n readContainerKeyWrap,\n} from \"../../../data/keyingProjectionVerification/readers\";\nimport { principalHeadMatchesReference } from \"../../../data/principalContracts/organizationAuthorityDescriptor\";\n\nfunction sortedCanonicalValues<T>(values: readonly T[], label: string): T[] {\n return [...values].sort((left, right) =>\n compareCanonicalStrings(\n canonicalKeyingJsonString(left, label),\n canonicalKeyingJsonString(right, label),\n ),\n );\n}\n\nexport function assertGroupPolicyEnvelopesMatchAcknowledgement(\n expected: CurrentPrincipalMemberEnvelopesResponse,\n observed: CurrentPrincipalMemberEnvelopesResponse,\n): void {\n const normalized = (value: CurrentPrincipalMemberEnvelopesResponse) => ({\n ...value,\n envelopes: sortedCanonicalValues(\n value.envelopes,\n \"principal member envelope\",\n ),\n });\n if (\n canonicalKeyingJsonString(\n normalized(expected),\n \"acknowledged group member envelopes\",\n ) !==\n canonicalKeyingJsonString(\n normalized(observed),\n \"observed group member envelopes\",\n )\n ) {\n throw new Error(\"Group member envelopes changed after acknowledgement\");\n }\n}\n\n/**\n * Each rematerialized container's acknowledgement names its commit by hash;\n * match every hash against the request this client authored.\n */\nasync function assertContainerMutationAcknowledgements(input: {\n readonly requests: readonly NonNullable<\n PutPrincipalPolicyRequest[\"containerMutations\"]\n >[number][];\n readonly responses: readonly ContainerMutationResponse[] | undefined;\n}): Promise<void> {\n if (!input.responses || input.responses.length !== input.requests.length) {\n throw new Error(\n \"Group policy container acknowledgement batch is incomplete\",\n );\n }\n for (const [index, request] of input.requests.entries()) {\n const response = input.responses[index];\n if (!response) {\n throw new Error(\n \"Group policy container acknowledgement batch is incomplete\",\n );\n }\n const label = \"authored group policy container mutation\";\n const keyEpoch = readContainerKeyEpoch(request.keyEpoch, label);\n const recipientTargets = sortedCanonicalValues(\n request.wraps.map((value) => {\n const wrap = readContainerKeyWrap(value, label);\n return {\n recipientId: wrap.recipientId,\n recipientKeyEpochId: wrap.recipientKeyEpochId,\n recipientKeyFingerprint: wrap.recipientKeyFingerprint,\n recipientKind: wrap.recipientKind,\n };\n }),\n \"authored recipient target\",\n );\n // The request carries this client's own hash of the manifest it signed,\n // and that manifest names its epoch and event by hash. A rotation's signed\n // body commits its keyring hash, so a substituted keyring must refuse\n // here, before journal recovery clears the saved request. A grant that\n // keeps its epoch commits none; the container acknowledgement checks the\n // retained keyring against the epoch's own.\n const committedKeyringHash = Reflect.get(\n Object(request.body),\n \"keyringHash\",\n );\n if (\n response.manifestHead.manifestHash !== request.expectedManifestHash ||\n response.manifestHead.epoch !== Reflect.get(request.manifest, \"epoch\") ||\n response.eventHash !== Reflect.get(request.manifest, \"eventHash\") ||\n response.containerKek.containerKeyEpochId !== keyEpoch.id ||\n response.containerKek.containerKeyEpoch !== keyEpoch.keyEpoch ||\n response.containerKek.keyEpochHash !==\n (await computeContainerKeyEpochHash(keyEpoch)) ||\n (typeof committedKeyringHash === \"string\" &&\n response.containerKek.keyringHash !== committedKeyringHash) ||\n response.containerKek.keyTargetHash !==\n (await computeContainerKekRecipientTargetHash(recipientTargets))\n ) {\n throw new Error(\"Group policy container acknowledgement mismatch\");\n }\n }\n}\n\n/**\n * The current an acknowledgement commits, rebuilt from this client's own\n * signed request: the server returns only the head it stored, the insertion\n * time it assigned to the state and payload, and hash-form container\n * acknowledgements. A head other than the one the request commits to refuses.\n * Nothing here manufactures predecessor history or pins.\n */\nexport async function acknowledgedPrincipalPolicyCurrent(input: {\n readonly request: PutPrincipalPolicyRequest;\n readonly response: PrincipalPolicyMutationResponse;\n}): Promise<PrincipalPolicyPageCurrent> {\n const { request, response } = input;\n const { state } = request;\n const stateHash = await computePrincipalStateHash(state);\n if (\n !principalHeadMatchesReference(response.head, {\n principalType: state.principalType,\n principalId: state.principalId,\n version: state.version,\n keyEpoch: state.keyEpoch,\n stateHash,\n keyFingerprint: state.keyFingerprint,\n })\n )\n throw new Error(\"Principal policy acknowledgement names another head\");\n await assertContainerMutationAcknowledgements({\n requests: request.containerMutations ?? [],\n responses: response.containerMutations,\n });\n const { principalType, principalId } = state;\n const { createdAt } = response;\n return {\n currentState: { ...state, stateHash, createdAt },\n currentPayload: {\n principalType,\n principalId,\n stateHash,\n ...request.encryptedPayload,\n createdAt,\n },\n currentProjection: request.projection,\n currentGrants: request.grants,\n currentMemberEnvelopes: {\n principalType,\n principalId,\n stateHash,\n epoch: state.keyEpoch,\n envelopes: request.memberEnvelopes,\n },\n };\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { wrapDekForRecipients } from "../../../internal/crypto/index.js";
2
2
  import { base64ToBytes, bytesToBase64 } from "../../../internal/encoding/index.js";
3
- import { assertPrincipalIdentityCommitments } from "../../../data/principals/principalIdentityCommitments.js";
3
+ import { assertPrincipalIdentityCommitments } from "../../../data/principalContracts/principalIdentityCommitments.js";
4
4
  function toPrincipalMemberEnvelopeRequest(input) {
5
5
  return {
6
6
  userId: input.userId,
@@ -1 +1 @@
1
- {"version":3,"file":"principalPolicyRecipients.js","sourceRoot":"","sources":["principalPolicyRecipients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMnE,OAAO,EAAE,kCAAkC,EAAE,MAAM,uDAAuD,CAAC;AAQ3G,SAAS,gCAAgC,CAAC,KAOzC;IACC,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,oBAAoB,EAAE,KAAK,CAAC,QAAQ,CAAC,cAAc;QACnD,aAAa,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC;QAC1D,UAAU,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC;KACrD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,SAAyD;IAEzD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAClC,cAAc,EAAE,QAAQ,CAAC,oBAAoB;QAC7C,aAAa,EAAE,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC;QACpD,UAAU,EAAE,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC;KAC/C,CAAC,CAAC,CAAC;AACN,CAAC;AAED,+EAA+E;AAC/E,SAAS,uBAAuB,CAAC,KAGhC;IACC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,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AAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAC/C,gCAAgC,CAAC;QAC/B,QAAQ;QACR,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,IAAI,EAAE;KACxC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { wrapDekForRecipients } from \"@tearleads/crypto\";\nimport { base64ToBytes, bytesToBase64 } from \"@tearleads/encoding\";\nimport type {\n PrincipalMemberEnvelopeRequest,\n PrincipalProjectionMemberRequest,\n} from \"@tearleads/validators/request\";\nimport type { PrincipalMemberEnvelopeResponse } from \"@tearleads/validators/response\";\nimport { assertPrincipalIdentityCommitments } from \"../../../data/principals/principalIdentityCommitments\";\nimport type { TrustedUserIdentity } from \"../../../data/trustedUserIdentity\";\n\ntype PrincipalRekeyRecipient = {\n readonly encapsulationPublicKey: Uint8Array;\n readonly userId: string;\n};\n\nfunction toPrincipalMemberEnvelopeRequest(input: {\n readonly envelope: {\n readonly keyFingerprint: string;\n readonly kemCipherText: Uint8Array;\n readonly wrappedKey: Uint8Array;\n };\n readonly userId: string;\n}): PrincipalMemberEnvelopeRequest {\n return {\n userId: input.userId,\n memberKeyFingerprint: input.envelope.keyFingerprint,\n kemCipherText: bytesToBase64(input.envelope.kemCipherText),\n wrappedKey: bytesToBase64(input.envelope.wrappedKey),\n };\n}\n\nexport function toRecipientEntries(\n envelopes: ReadonlyArray<PrincipalMemberEnvelopeResponse>,\n) {\n return envelopes.map((envelope) => ({\n keyFingerprint: envelope.memberKeyFingerprint,\n kemCipherText: base64ToBytes(envelope.kemCipherText),\n wrappedKey: base64ToBytes(envelope.wrappedKey),\n }));\n}\n\n/** Every projected member is a user, so there is no group recipient branch. */\nfunction toRekeyRecipientEntries(input: {\n readonly projection: ReadonlyArray<PrincipalProjectionMemberRequest>;\n readonly users: ReadonlyArray<TrustedUserIdentity>;\n}): PrincipalRekeyRecipient[] {\n const usersById = new Map(input.users.map((user) => [user.userId, user]));\n\n return input.projection.map((member) => {\n const user = usersById.get(member.userId);\n if (!user) {\n throw new Error(`Missing recipient key for user ${member.userId}`);\n }\n\n return {\n encapsulationPublicKey: user.encapsulationPublicKey,\n userId: user.userId,\n };\n });\n}\n\nexport async function rewrapProjectionMemberEnvelopes(input: {\n readonly projection: ReadonlyArray<PrincipalProjectionMemberRequest>;\n readonly secretKey: Uint8Array;\n readonly users: ReadonlyArray<TrustedUserIdentity>;\n}): Promise<PrincipalMemberEnvelopeRequest[]> {\n const users = new Map(input.users.map((user) => [user.userId, user]));\n await assertPrincipalIdentityCommitments({\n authenticated: false,\n projections: [input.projection],\n resolveTrustedUserIdentity: async (userId) => users.get(userId) ?? null,\n });\n const recipients = toRekeyRecipientEntries(input);\n if (recipients.length === 0) {\n return [];\n }\n const wrappedRecipients = await wrapDekForRecipients(\n input.secretKey,\n recipients.map((recipient) => recipient.encapsulationPublicKey),\n );\n\n return wrappedRecipients.map((envelope, index) =>\n toPrincipalMemberEnvelopeRequest({\n envelope,\n userId: recipients[index]?.userId ?? \"\",\n }),\n );\n}\n"]}
1
+ {"version":3,"file":"principalPolicyRecipients.js","sourceRoot":"","sources":["principalPolicyRecipients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMnE,OAAO,EAAE,kCAAkC,EAAE,MAAM,+DAA+D,CAAC;AAQnH,SAAS,gCAAgC,CAAC,KAOzC;IACC,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,oBAAoB,EAAE,KAAK,CAAC,QAAQ,CAAC,cAAc;QACnD,aAAa,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC;QAC1D,UAAU,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC;KACrD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC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KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI;KACxE,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAClD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,iBAAiB,GAAG,MAAM,oBAAoB,CAClD,KAAK,CAAC,SAAS,EACf,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAChE,CAAC;IAEF,OAAO,iBAAiB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAC/C,gCAAgC,CAAC;QAC/B,QAAQ;QACR,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,IAAI,EAAE;KACxC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { wrapDekForRecipients } from \"@tearleads/crypto\";\nimport { base64ToBytes, bytesToBase64 } from \"@tearleads/encoding\";\nimport type {\n PrincipalMemberEnvelopeRequest,\n PrincipalProjectionMemberRequest,\n} from \"@tearleads/validators/request\";\nimport type { PrincipalMemberEnvelopeResponse } from \"@tearleads/validators/response\";\nimport { assertPrincipalIdentityCommitments } from \"../../../data/principalContracts/principalIdentityCommitments\";\nimport type { TrustedUserIdentity } from \"../../../data/trustedUserIdentity\";\n\ntype PrincipalRekeyRecipient = {\n readonly encapsulationPublicKey: Uint8Array;\n readonly userId: string;\n};\n\nfunction toPrincipalMemberEnvelopeRequest(input: {\n readonly envelope: {\n readonly keyFingerprint: string;\n readonly kemCipherText: Uint8Array;\n readonly wrappedKey: Uint8Array;\n };\n readonly userId: string;\n}): PrincipalMemberEnvelopeRequest {\n return {\n userId: input.userId,\n memberKeyFingerprint: input.envelope.keyFingerprint,\n kemCipherText: bytesToBase64(input.envelope.kemCipherText),\n wrappedKey: bytesToBase64(input.envelope.wrappedKey),\n };\n}\n\nexport function toRecipientEntries(\n envelopes: ReadonlyArray<PrincipalMemberEnvelopeResponse>,\n) {\n return envelopes.map((envelope) => ({\n keyFingerprint: envelope.memberKeyFingerprint,\n kemCipherText: base64ToBytes(envelope.kemCipherText),\n wrappedKey: base64ToBytes(envelope.wrappedKey),\n }));\n}\n\n/** Every projected member is a user, so there is no group recipient branch. */\nfunction toRekeyRecipientEntries(input: {\n readonly projection: ReadonlyArray<PrincipalProjectionMemberRequest>;\n readonly users: ReadonlyArray<TrustedUserIdentity>;\n}): PrincipalRekeyRecipient[] {\n const usersById = new Map(input.users.map((user) => [user.userId, user]));\n\n return input.projection.map((member) => {\n const user = usersById.get(member.userId);\n if (!user) {\n throw new Error(`Missing recipient key for user ${member.userId}`);\n }\n\n return {\n encapsulationPublicKey: user.encapsulationPublicKey,\n userId: user.userId,\n };\n });\n}\n\nexport async function rewrapProjectionMemberEnvelopes(input: {\n readonly projection: ReadonlyArray<PrincipalProjectionMemberRequest>;\n readonly secretKey: Uint8Array;\n readonly users: ReadonlyArray<TrustedUserIdentity>;\n}): Promise<PrincipalMemberEnvelopeRequest[]> {\n const users = new Map(input.users.map((user) => [user.userId, user]));\n await assertPrincipalIdentityCommitments({\n authenticated: false,\n projections: [input.projection],\n resolveTrustedUserIdentity: async (userId) => users.get(userId) ?? null,\n });\n const recipients = toRekeyRecipientEntries(input);\n if (recipients.length === 0) {\n return [];\n }\n const wrappedRecipients = await wrapDekForRecipients(\n input.secretKey,\n recipients.map((recipient) => recipient.encapsulationPublicKey),\n );\n\n return wrappedRecipients.map((envelope, index) =>\n toPrincipalMemberEnvelopeRequest({\n envelope,\n userId: recipients[index]?.userId ?? \"\",\n }),\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { buildPrincipalStateSigningInput, encodeBuiltinGroupMetadata, encryptGroupMetadata, generateKemSeedAndKeyPair, normalizePrincipalContainerGrants, normalizePrincipalProjectionMembers, readGroupMetadata, signPrincipalState, toFingerprint, wrapDekForRecipients, } from "../../../internal/crypto/index.js";
2
2
  import { bytesToBase64 } from "../../../internal/encoding/index.js";
3
- import { createPrincipalProjectionMember } from "../../../data/principals/principalIdentityCommitments.js";
3
+ import { createPrincipalProjectionMember } from "../../../data/principalContracts/principalIdentityCommitments.js";
4
4
  function projectionToStateMembers(projection) {
5
5
  return projection.map((member) => ({ userId: member.userId }));
6
6
  }