@tearleads/client-sdk 0.1.58 → 0.1.60

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 (477) hide show
  1. package/Tearleads.d.ts +17 -17
  2. package/Tearleads.js +15 -15
  3. package/Tearleads.js.map +1 -1
  4. package/client/{blobs.d.ts → blobs/index.d.ts} +1 -1
  5. package/client/{blobs.js → blobs/index.js} +3 -3
  6. package/client/blobs/index.js.map +1 -0
  7. package/client/{containerDocumentDiscovery.js → containerContents/documentDiscovery.js} +11 -11
  8. package/client/containerContents/documentDiscovery.js.map +1 -0
  9. package/client/{containerContents.d.ts → containerContents/index.d.ts} +13 -13
  10. package/client/{containerContents.js → containerContents/index.js} +18 -18
  11. package/client/containerContents/index.js.map +1 -0
  12. package/client/{containerContentsTypes.d.ts → containerContents/types.d.ts} +14 -14
  13. package/client/containerContents/types.js +2 -0
  14. package/client/containerContents/types.js.map +1 -0
  15. package/client/{deviceFirst.d.ts → deviceFirst/index.d.ts} +7 -7
  16. package/client/{deviceFirst.js → deviceFirst/index.js} +11 -11
  17. package/client/deviceFirst/index.js.map +1 -0
  18. package/client/{reconciledDocumentContentPull.js → deviceFirst/reconciledDocumentContentPull.js} +1 -1
  19. package/client/deviceFirst/reconciledDocumentContentPull.js.map +1 -0
  20. package/client/{documents.d.ts → documents/index.d.ts} +5 -5
  21. package/client/{documents.js → documents/index.js} +5 -5
  22. package/client/documents/index.js.map +1 -0
  23. package/client/{identity.d.ts → identity/index.d.ts} +2 -2
  24. package/client/{identity.js → identity/index.js} +5 -5
  25. package/client/identity/index.js.map +1 -0
  26. package/client/{identityKeyPackage.d.ts → identity/keyPackage.d.ts} +1 -1
  27. package/client/{identityKeyPackage.js → identity/keyPackage.js} +4 -4
  28. package/client/identity/keyPackage.js.map +1 -0
  29. package/client/{userIdentities.d.ts → identity/userIdentities.d.ts} +2 -2
  30. package/client/{userIdentities.js → identity/userIdentities.js} +4 -4
  31. package/client/identity/userIdentities.js.map +1 -0
  32. package/client/index.d.ts +18 -18
  33. package/client/index.js +9 -9
  34. package/client/index.js.map +1 -1
  35. package/client/organizations/currentPrincipalMutations.js.map +1 -1
  36. package/client/organizations/index.d.ts +2 -2
  37. package/client/organizations/index.js.map +1 -1
  38. package/client/organizations/organizationAccessRestoration.js.map +1 -1
  39. package/client/organizations/organizationDataUsage.d.ts +1 -1
  40. package/client/organizations/organizationDataUsage.js.map +1 -1
  41. package/client/organizations/organizationGroupNameHydration.js.map +1 -1
  42. package/client/organizations/organizationGroupPresentation.d.ts +1 -1
  43. package/client/organizations/organizationGroupPresentation.js.map +1 -1
  44. package/client/organizations/organizationMetadataProfileSync.js +1 -1
  45. package/client/organizations/organizationMetadataProfileSync.js.map +1 -1
  46. package/client/organizations/organizationReadModels.d.ts +1 -1
  47. package/client/organizations/organizationReadModels.js.map +1 -1
  48. package/client/organizations/organizationWorkflowRuntime.js.map +1 -1
  49. package/client/organizations/organizationsTypes.d.ts +1 -1
  50. package/client/organizations/organizationsTypes.js.map +1 -1
  51. package/client/organizations/principalContainerMutations.js.map +1 -1
  52. package/client/organizations/principalMutationRecovery.d.ts +1 -1
  53. package/client/organizations/principalMutationRecovery.js.map +1 -1
  54. package/client/organizations/principalMutationScope.js.map +1 -1
  55. package/client/organizations/principalMutations.d.ts +2 -2
  56. package/client/organizations/principalMutations.js.map +1 -1
  57. package/client/root/index.d.ts +1 -1
  58. package/client/root/index.js.map +1 -1
  59. package/client/{database.d.ts → runtime/database.d.ts} +1 -1
  60. package/client/{database.js → runtime/database.js} +1 -1
  61. package/client/runtime/database.js.map +1 -0
  62. package/client/{principalHistoryProtection.d.ts → runtime/principalHistoryProtection.d.ts} +1 -1
  63. package/client/{principalHistoryProtection.js → runtime/principalHistoryProtection.js} +2 -2
  64. package/client/runtime/principalHistoryProtection.js.map +1 -0
  65. package/client/{principalMutationApi.d.ts → runtime/principalMutationApi.d.ts} +4 -4
  66. package/client/{principalMutationApi.js → runtime/principalMutationApi.js} +2 -2
  67. package/client/runtime/principalMutationApi.js.map +1 -0
  68. package/client/{principalMutationDispatch.js → runtime/principalMutationDispatch.js} +2 -2
  69. package/client/runtime/principalMutationDispatch.js.map +1 -0
  70. package/client/runtime/rootContainerAdoption.js.map +1 -0
  71. package/client/{workflowRuntime.d.ts → runtime/workflowRuntime.d.ts} +12 -12
  72. package/client/{workflowRuntime.js → runtime/workflowRuntime.js} +5 -5
  73. package/client/runtime/workflowRuntime.js.map +1 -0
  74. package/client/{securityIncidents.d.ts → securityIncidents/index.d.ts} +3 -3
  75. package/client/{securityIncidents.js → securityIncidents/index.js} +5 -5
  76. package/client/securityIncidents/index.js.map +1 -0
  77. package/client/session/index.js +1 -1
  78. package/client/session/index.js.map +1 -1
  79. package/client/session/sessionIdentityTrust.d.ts +1 -1
  80. package/client/session/sessionLoginRefusal.js.map +1 -1
  81. package/client/session/sessionOrganizationCreation.js.map +1 -1
  82. package/client/session/sessionPurgeRecovery.js.map +1 -1
  83. package/client/session/sessionRootAuthority.js.map +1 -1
  84. package/client/session/sessionTypes.d.ts +3 -3
  85. package/client/session/sessionTypes.js.map +1 -1
  86. package/data/blobs/createBlobStore.d.ts +1 -1
  87. package/data/blobs/createBlobStore.js.map +1 -1
  88. package/data/blobs/encryptedBlobByteSource.js +1 -1
  89. package/data/blobs/encryptedBlobByteSource.js.map +1 -1
  90. package/data/blobs/encryptedBlobEnvelope.d.ts +1 -1
  91. package/data/blobs/encryptedBlobEnvelope.js +2 -2
  92. package/data/blobs/encryptedBlobEnvelope.js.map +1 -1
  93. package/data/blobs/encryptedBlobStore.d.ts +1 -1
  94. package/data/blobs/encryptedBlobStore.js +1 -1
  95. package/data/blobs/encryptedBlobStore.js.map +1 -1
  96. package/data/blobs/memoryBlobStore.d.ts +1 -1
  97. package/data/blobs/memoryBlobStore.js +1 -1
  98. package/data/blobs/memoryBlobStore.js.map +1 -1
  99. package/data/blobs/opfsBlobStore.d.ts +1 -1
  100. package/data/blobs/opfsBlobStore.js +1 -1
  101. package/data/blobs/opfsBlobStore.js.map +1 -1
  102. package/data/containers/containerMetadataDocument.js +1 -1
  103. package/data/containers/containerMetadataDocument.js.map +1 -1
  104. package/data/containers/shared/events.js +1 -1
  105. package/data/containers/shared/events.js.map +1 -1
  106. package/data/containers/shared/heldContainerHeads.js +1 -1
  107. package/data/containers/shared/heldContainerHeads.js.map +1 -1
  108. package/data/containers/shared/mutationAcknowledgement.js +1 -1
  109. package/data/containers/shared/mutationAcknowledgement.js.map +1 -1
  110. package/data/containers/shared/principalPolicies.js +1 -1
  111. package/data/containers/shared/principalPolicies.js.map +1 -1
  112. package/data/containers/shared/readers.js +2 -2
  113. package/data/containers/shared/readers.js.map +1 -1
  114. package/data/documents/attachmentContentIdentity.js +1 -1
  115. package/data/documents/attachmentContentIdentity.js.map +1 -1
  116. package/data/documents/blob/shared/blobEnvelopeStream.js.map +1 -1
  117. package/data/documents/blob/shared/blobSourceSnapshot.d.ts +1 -1
  118. package/data/documents/blob/shared/blobSourceSnapshot.js.map +1 -1
  119. package/data/documents/blob/shared/chunkedBlobCrypto.js.map +1 -1
  120. package/data/documents/blob/shared/encryptedUploadParts.js.map +1 -1
  121. package/data/documents/blob/shared/events.js +1 -1
  122. package/data/documents/blob/shared/events.js.map +1 -1
  123. package/data/documents/blob/shared/types.d.ts +2 -2
  124. package/data/documents/blob/shared/types.js.map +1 -1
  125. package/data/documents/shared/containerKekPathHistory.js +1 -1
  126. package/data/documents/shared/containerKekPathHistory.js.map +1 -1
  127. package/data/documents/shared/containerKekPathVerification.d.ts +1 -1
  128. package/data/documents/shared/containerKekPathVerification.js +1 -1
  129. package/data/documents/shared/events.js +1 -1
  130. package/data/documents/shared/events.js.map +1 -1
  131. package/data/documents/shared/manifestBundleReaders.js +2 -2
  132. package/data/documents/shared/manifestBundleReaders.js.map +1 -1
  133. package/data/documents/shared/projection.d.ts +1 -1
  134. package/data/documents/shared/projection.js +2 -2
  135. package/data/documents/shared/projection.js.map +1 -1
  136. package/data/documents/shared/projectionContentKeys.d.ts +1 -1
  137. package/data/documents/shared/readers.js +3 -3
  138. package/data/documents/shared/readers.js.map +1 -1
  139. package/data/documents/shared/stableDocumentId.js +1 -1
  140. package/data/documents/shared/stableDocumentId.js.map +1 -1
  141. package/data/documents/shared/types.d.ts +1 -1
  142. package/data/documents/shared/types.js +1 -1
  143. package/data/{keyingCanonicalJson.js → keying/canonicalJson.js} +3 -3
  144. package/data/keying/canonicalJson.js.map +1 -0
  145. package/data/keyingProjectionVerification/bundleVerification.js +1 -1
  146. package/data/keyingProjectionVerification/bundleVerification.js.map +1 -1
  147. package/data/keyingProjectionVerification/containerAncestorCitations.js +1 -1
  148. package/data/keyingProjectionVerification/containerAncestorCitations.js.map +1 -1
  149. package/data/keyingProjectionVerification/containerManifestVerification.js +1 -1
  150. package/data/keyingProjectionVerification/containerManifestVerification.js.map +1 -1
  151. package/data/keyingProjectionVerification/documentManifestVerification.js +1 -1
  152. package/data/keyingProjectionVerification/documentManifestVerification.js.map +1 -1
  153. package/data/keyingProjectionVerification/documentPurgeDocumentChainVerification.js +1 -1
  154. package/data/keyingProjectionVerification/documentPurgeDocumentChainVerification.js.map +1 -1
  155. package/data/keyingProjectionVerification/error.js +1 -1
  156. package/data/keyingProjectionVerification/error.js.map +1 -1
  157. package/data/keyingProjectionVerification/index.d.ts +9 -0
  158. package/data/{keyingProjectionVerification.js → keyingProjectionVerification/index.js} +8 -8
  159. package/data/keyingProjectionVerification/index.js.map +1 -0
  160. package/data/keyingProjectionVerification/principalPolicyCache.js +1 -1
  161. package/data/keyingProjectionVerification/principalPolicyCache.js.map +1 -1
  162. package/data/keyingProjectionVerification/principalPolicyVerification.js +1 -1
  163. package/data/keyingProjectionVerification/principalPolicyVerification.js.map +1 -1
  164. package/data/keyingProjectionVerification/readers.d.ts +1 -1
  165. package/data/keyingProjectionVerification/readers.js +3 -3
  166. package/data/keyingProjectionVerification/readers.js.map +1 -1
  167. package/data/keyingProjectionVerification/userKeyResolver.d.ts +1 -1
  168. package/data/keyingProjectionVerification/userKeyResolver.js.map +1 -1
  169. package/data/persistence/containers/containerPersistence.js +1 -1
  170. package/data/persistence/containers/containerPersistence.js.map +1 -1
  171. package/data/persistence/documents/documentDiscoveryCandidate.js +1 -1
  172. package/data/persistence/documents/documentDiscoveryCandidate.js.map +1 -1
  173. package/data/persistence/documents/documentDiscoveryEvidencePersistence.js +1 -1
  174. package/data/persistence/documents/documentDiscoveryEvidencePersistence.js.map +1 -1
  175. package/data/persistence/documents/internal/documentProjectionRows.js +1 -1
  176. package/data/persistence/documents/internal/documentProjectionRows.js.map +1 -1
  177. package/data/persistence/documents/internal/documentRows.js +1 -1
  178. package/data/persistence/documents/internal/documentRows.js.map +1 -1
  179. package/data/persistence/principalPolicyBundleIntegrity.js +1 -1
  180. package/data/persistence/principalPolicyBundleIntegrity.js.map +1 -1
  181. package/data/persistence/principalPolicyReferenceCheckpoint.js +1 -1
  182. package/data/persistence/principalPolicyReferenceCheckpoint.js.map +1 -1
  183. package/data/persistence/principalPolicyReferenceIndexPersistence.js +1 -1
  184. package/data/persistence/principalPolicyReferenceIndexPersistence.js.map +1 -1
  185. package/data/persistence/principalPolicyReferencePersistence.js +1 -1
  186. package/data/persistence/principalPolicyReferencePersistence.js.map +1 -1
  187. package/data/persistence/securityIncidentPersistence.js.map +1 -1
  188. package/data/persistence/verifiedPrincipalPolicyBundle.js +1 -1
  189. package/data/persistence/verifiedPrincipalPolicyBundle.js.map +1 -1
  190. package/data/persistence/verifiedPrincipalPolicyCurrent.js +1 -1
  191. package/data/persistence/verifiedPrincipalPolicyCurrent.js.map +1 -1
  192. package/data/principals/principalMutationJournal.js +1 -1
  193. package/data/principals/principalMutationJournal.js.map +1 -1
  194. package/data/{securityIncidents.d.ts → shared/securityIncidents.d.ts} +1 -1
  195. package/data/sqlite/documentRecordPersistence.js +1 -1
  196. package/data/sqlite/documentRecordPersistence.js.map +1 -1
  197. package/data/sync/crdtPeerSeed.d.ts +18 -0
  198. package/data/sync/originatedDocuments.d.ts +1 -1
  199. package/data/sync/originatedDocuments.js.map +1 -1
  200. package/data/sync/syncCoordinator.d.ts +1 -1
  201. package/data/sync/syncCoordinator.js.map +1 -1
  202. package/package.json +1 -1
  203. package/stores/container-contents/backgroundHydration.js +1 -1
  204. package/stores/container-contents/backgroundHydration.js.map +1 -1
  205. package/stores/container-contents/containerContentsStore.d.ts +1 -1
  206. package/stores/container-contents/containerContentsStore.js.map +1 -1
  207. package/stores/container-contents/localRefresh.js +1 -1
  208. package/stores/container-contents/localRefresh.js.map +1 -1
  209. package/stores/container-contents/remoteContainerIngestion.js +1 -1
  210. package/stores/container-contents/remoteContainerIngestion.js.map +1 -1
  211. package/stores/container-contents/remoteWriteQueue.js +1 -1
  212. package/stores/container-contents/remoteWriteQueue.js.map +1 -1
  213. package/stores/container-contents/systemContainerHydration.js +1 -1
  214. package/stores/container-contents/systemContainerHydration.js.map +1 -1
  215. package/stores/container-contents/utils.js +1 -1
  216. package/stores/container-contents/utils.js.map +1 -1
  217. package/stores/documents/documentStore/attachmentIntents.js +1 -1
  218. package/stores/documents/documentStore/attachmentIntents.js.map +1 -1
  219. package/stores/documents/documentStore/attachmentSourceUpload.js.map +1 -1
  220. package/stores/documents/documentStore/attachmentStaging.js +1 -1
  221. package/stores/documents/documentStore/attachmentStaging.js.map +1 -1
  222. package/stores/documents/documentStore/attachmentUploadLane.js.map +1 -1
  223. package/stores/documents/documentStore/persistence.js +2 -2
  224. package/stores/documents/documentStore/persistence.js.map +1 -1
  225. package/stores/documents/documentStore/state.js +1 -1
  226. package/stores/documents/documentStore/state.js.map +1 -1
  227. package/stores/documents/documentStore/storedDocument.js +1 -1
  228. package/stores/documents/documentStore/storedDocument.js.map +1 -1
  229. package/stores/documents/documentStore/syncAttachments.js.map +1 -1
  230. package/stores/documents/documentStore.d.ts +1 -1
  231. package/stores/documents/documentStore.js.map +1 -1
  232. package/stores/documents/registry.d.ts +1 -1
  233. package/stores/documents/registry.js.map +1 -1
  234. package/stores/documents/types.d.ts +1 -1
  235. package/stores/documents/types.js.map +1 -1
  236. package/stores/local-projection/registry.d.ts +1 -1
  237. package/stores/local-projection/registry.js.map +1 -1
  238. package/sync/reconciliation/serviceTypes.d.ts +1 -1
  239. package/sync/reconciliation/serviceTypes.js.map +1 -1
  240. package/sync/reconciliation/triggers.d.ts +1 -1
  241. package/sync/reconciliation/triggers.js.map +1 -1
  242. package/workflows/blobs/attachmentBindingVerification.js +2 -2
  243. package/workflows/blobs/attachmentBindingVerification.js.map +1 -1
  244. package/workflows/blobs/blobChunkDecryption.js.map +1 -1
  245. package/workflows/blobs/decrypt.d.ts +1 -1
  246. package/workflows/blobs/decrypt.js +2 -2
  247. package/workflows/blobs/decrypt.js.map +1 -1
  248. package/workflows/blobs/detach.js +2 -2
  249. package/workflows/blobs/detach.js.map +1 -1
  250. package/workflows/blobs/hydrate.d.ts +3 -3
  251. package/workflows/blobs/hydrate.js +1 -1
  252. package/workflows/blobs/hydrate.js.map +1 -1
  253. package/workflows/blobs/hydrationResults.js.map +1 -1
  254. package/workflows/blobs/index.d.ts +2 -2
  255. package/workflows/blobs/index.js +1 -1
  256. package/workflows/blobs/index.js.map +1 -1
  257. package/workflows/blobs/multipartFirstParts.js.map +1 -1
  258. package/workflows/blobs/retainedAttachmentVerification.js +1 -1
  259. package/workflows/blobs/upload.js +3 -3
  260. package/workflows/blobs/upload.js.map +1 -1
  261. package/workflows/container-contents/container-state/createAdoption.js +1 -1
  262. package/workflows/container-contents/container-state/createAdoption.js.map +1 -1
  263. package/workflows/container-contents/container-state/createChild.js +1 -1
  264. package/workflows/container-contents/container-state/createChild.js.map +1 -1
  265. package/workflows/container-contents/container-state/createIntentSync.js +1 -1
  266. package/workflows/container-contents/container-state/createIntentSync.js.map +1 -1
  267. package/workflows/container-contents/container-state/groupGrantVerification.js +1 -1
  268. package/workflows/container-contents/container-state/moveIntentSync.js +1 -1
  269. package/workflows/container-contents/container-state/moveIntentSync.js.map +1 -1
  270. package/workflows/container-contents/container-state/purgeTreeScope.js +1 -1
  271. package/workflows/container-contents/container-state/purgeTreeScope.js.map +1 -1
  272. package/workflows/container-contents/container-state/share.js +1 -1
  273. package/workflows/container-contents/documentDiscoveryInputs.js +1 -1
  274. package/workflows/container-contents/documentDiscoveryInputs.js.map +1 -1
  275. package/workflows/container-contents/documentInfo.d.ts +1 -1
  276. package/workflows/container-contents/documentInfo.js.map +1 -1
  277. package/workflows/container-contents/documentLinks.d.ts +1 -1
  278. package/workflows/container-contents/documentLinks.js +1 -1
  279. package/workflows/container-contents/documentLinks.js.map +1 -1
  280. package/workflows/container-contents/documentMoveIntentSync.js +1 -1
  281. package/workflows/container-contents/documentMoveIntentSync.js.map +1 -1
  282. package/workflows/container-contents/documentPurge.d.ts +1 -1
  283. package/workflows/container-contents/documentPurge.js +1 -1
  284. package/workflows/container-contents/documentPurge.js.map +1 -1
  285. package/workflows/container-contents/documentQueries/rows.js +1 -1
  286. package/workflows/container-contents/documentQueries/rows.js.map +1 -1
  287. package/workflows/container-contents/metadata.d.ts +1 -1
  288. package/workflows/container-contents/metadataMutationPreparation.js +1 -1
  289. package/workflows/container-contents/metadataMutationPreparation.js.map +1 -1
  290. package/workflows/container-contents/metadataRemoteSync.d.ts +1 -1
  291. package/workflows/container-contents/metadataSyncErrors.js.map +1 -1
  292. package/workflows/container-contents/projectionKeys.d.ts +1 -1
  293. package/workflows/container-contents/syncLane.d.ts +1 -1
  294. package/workflows/container-contents/syncLane.js.map +1 -1
  295. package/workflows/containers/child/carriedDescendantRekeys.js +1 -1
  296. package/workflows/containers/child/create.d.ts +1 -1
  297. package/workflows/containers/child/create.js +2 -2
  298. package/workflows/containers/child/create.js.map +1 -1
  299. package/workflows/containers/child/createProjection.js +1 -1
  300. package/workflows/containers/child/createProjection.js.map +1 -1
  301. package/workflows/containers/child/createSubmission.d.ts +2 -2
  302. package/workflows/containers/child/createSubmission.js.map +1 -1
  303. package/workflows/containers/child/move.d.ts +2 -2
  304. package/workflows/containers/child/move.js +2 -2
  305. package/workflows/containers/child/move.js.map +1 -1
  306. package/workflows/containers/child/moveWraps.js +1 -1
  307. package/workflows/containers/child/mutationRequestCore.js +1 -1
  308. package/workflows/containers/child/mutationRequestCore.js.map +1 -1
  309. package/workflows/containers/child/mutationSubmit.js.map +1 -1
  310. package/workflows/containers/child/recite.js.map +1 -1
  311. package/workflows/containers/child/recitePlan.js +1 -1
  312. package/workflows/containers/child/recitePlan.js.map +1 -1
  313. package/workflows/containers/child/rekey.d.ts +1 -1
  314. package/workflows/containers/child/rekey.js +2 -2
  315. package/workflows/containers/child/rekey.js.map +1 -1
  316. package/workflows/containers/child/rekeyProjection.js +1 -1
  317. package/workflows/containers/child/rekeyProjection.js.map +1 -1
  318. package/workflows/containers/child/rekeyRemote.d.ts +2 -2
  319. package/workflows/containers/child/rekeyRemote.js.map +1 -1
  320. package/workflows/containers/child/revoke.d.ts +2 -2
  321. package/workflows/containers/child/revoke.js +2 -2
  322. package/workflows/containers/child/revoke.js.map +1 -1
  323. package/workflows/containers/child/rotationPrincipalPolicies.js +1 -1
  324. package/workflows/containers/child/runtimeCurrentGroupShare.js +1 -1
  325. package/workflows/containers/child/share.d.ts +2 -2
  326. package/workflows/containers/child/share.js +1 -1
  327. package/workflows/containers/child/share.js.map +1 -1
  328. package/workflows/containers/child/shareAncestorRepair.js.map +1 -1
  329. package/workflows/containers/child/shareMaterialization.d.ts +1 -1
  330. package/workflows/containers/child/sharePlanCore.d.ts +1 -1
  331. package/workflows/containers/child/sharePlanCore.js +1 -1
  332. package/workflows/containers/root/create.js +1 -1
  333. package/workflows/containers/root/create.js.map +1 -1
  334. package/workflows/containers/root/initialGroupPolicy.js +1 -1
  335. package/workflows/containers/root/initialGroupPolicy.js.map +1 -1
  336. package/workflows/documents/create.d.ts +1 -1
  337. package/workflows/documents/create.js +1 -1
  338. package/workflows/documents/documentMutationPreparation.js +1 -1
  339. package/workflows/documents/documentMutationPreparation.js.map +1 -1
  340. package/workflows/documents/historyContent.js +1 -1
  341. package/workflows/documents/historyContent.js.map +1 -1
  342. package/workflows/documents/linkSet.js +1 -1
  343. package/workflows/documents/linkSet.js.map +1 -1
  344. package/workflows/documents/linkSetAuthority.js +1 -1
  345. package/workflows/documents/linkSetBlobRewraps.js +2 -2
  346. package/workflows/documents/linkSetBlobRewraps.js.map +1 -1
  347. package/workflows/documents/linkSetRemote.d.ts +1 -1
  348. package/workflows/documents/linkSetRemote.js +1 -1
  349. package/workflows/documents/orphanBlobReclaims.js +1 -1
  350. package/workflows/documents/orphanBlobReclaims.js.map +1 -1
  351. package/workflows/documents/projectionKeys.d.ts +1 -1
  352. package/workflows/documents/purge.d.ts +1 -1
  353. package/workflows/documents/purge.js +2 -2
  354. package/workflows/documents/purge.js.map +1 -1
  355. package/workflows/documents/readOnlySync.d.ts +1 -1
  356. package/workflows/documents/readOnlySync.js +1 -1
  357. package/workflows/documents/readOnlySync.js.map +1 -1
  358. package/workflows/documents/sync.js +1 -1
  359. package/workflows/documents/syncContainerRekeyPreparation.js +1 -1
  360. package/workflows/documents/syncLane.d.ts +1 -1
  361. package/workflows/documents/syncLane.js.map +1 -1
  362. package/workflows/documents/syncPlanIdentity.js +1 -1
  363. package/workflows/documents/syncPlanIdentity.js.map +1 -1
  364. package/workflows/documents/syncRepairAccess.js +1 -1
  365. package/workflows/documents/syncSubmittedResult.js +1 -1
  366. package/workflows/organizations/authoredPrincipalPolicyWarmer.js +1 -1
  367. package/workflows/organizations/authoredPrincipalPolicyWarmer.js.map +1 -1
  368. package/workflows/organizations/containerGrantRevocation.d.ts +2 -2
  369. package/workflows/organizations/containerGrantRevocation.js.map +1 -1
  370. package/workflows/organizations/createCurrentOrganizationGroup.js.map +1 -1
  371. package/workflows/organizations/currentOrganizationGroupNames.js.map +1 -1
  372. package/workflows/organizations/currentPolicyMutationAcknowledgement.js +1 -1
  373. package/workflows/organizations/currentPolicyMutationAcknowledgement.js.map +1 -1
  374. package/workflows/organizations/groupCreation.d.ts +1 -1
  375. package/workflows/organizations/groupCreation.js.map +1 -1
  376. package/workflows/organizations/groupMetadataAccess.d.ts +1 -1
  377. package/workflows/organizations/groupMetadataContainerAuthority.js.map +1 -1
  378. package/workflows/organizations/groupMetadataRuntime.js.map +1 -1
  379. package/workflows/organizations/groupNameUniqueness.js.map +1 -1
  380. package/workflows/organizations/groupPolicyMutationAcknowledgement.js +1 -1
  381. package/workflows/organizations/groupPolicyMutationAcknowledgement.js.map +1 -1
  382. package/workflows/organizations/groupPolicyRequests.js.map +1 -1
  383. package/workflows/organizations/loadPolicyHistoryDetails.js.map +1 -1
  384. package/workflows/organizations/organizationGroupDirectory.js.map +1 -1
  385. package/workflows/organizations/organizationProfile.js +1 -1
  386. package/workflows/organizations/organizationProfile.js.map +1 -1
  387. package/workflows/organizations/policyHistoryCache.js.map +1 -1
  388. package/workflows/organizations/principalContainerRematerialization.js +1 -1
  389. package/workflows/organizations/principalContainerRematerializationPlanning.js.map +1 -1
  390. package/workflows/organizations/principalMutationJournalManagement.js +1 -1
  391. package/workflows/organizations/principalMutationJournalManagement.js.map +1 -1
  392. package/workflows/organizations/principalMutationReceipt.js +1 -1
  393. package/workflows/organizations/principalMutationReceipt.js.map +1 -1
  394. package/workflows/organizations/principalPolicy.d.ts +1 -1
  395. package/workflows/organizations/principalPolicy.js.map +1 -1
  396. package/workflows/organizations/principalPolicyReceiptArtifacts.js +1 -1
  397. package/workflows/organizations/principalPolicyReceiptArtifacts.js.map +1 -1
  398. package/workflows/organizations/rosterProfileContainer.js +1 -1
  399. package/workflows/organizations/rosterProfileContainer.js.map +1 -1
  400. package/workflows/principals/policyCache.d.ts +1 -1
  401. package/workflows/principals/policyCache.js +2 -2
  402. package/workflows/principals/policyCache.js.map +1 -1
  403. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  404. package/workflows/principals/runtimePolicyWarmer.js +1 -1
  405. package/workflows/principals/runtimePolicyWarmer.js.map +1 -1
  406. package/workflows/registration/persistRegistrationBootstrap.js +1 -1
  407. package/workflows/registration/persistRegistrationBootstrap.js.map +1 -1
  408. package/workflows/runtimeInput.d.ts +3 -3
  409. package/workflows/runtimeInput.js.map +1 -1
  410. package/workflows/sync/index.d.ts +2 -1
  411. package/workflows/sync/index.js +2 -1
  412. package/workflows/sync/index.js.map +1 -1
  413. package/client/blobs.js.map +0 -1
  414. package/client/containerContents.js.map +0 -1
  415. package/client/containerContentsTypes.js +0 -2
  416. package/client/containerContentsTypes.js.map +0 -1
  417. package/client/containerDocumentDiscovery.js.map +0 -1
  418. package/client/database.js.map +0 -1
  419. package/client/deviceFirst.js.map +0 -1
  420. package/client/documents.js.map +0 -1
  421. package/client/identity.js.map +0 -1
  422. package/client/identityKeyPackage.js.map +0 -1
  423. package/client/principalHistoryProtection.js.map +0 -1
  424. package/client/principalMutationApi.js.map +0 -1
  425. package/client/principalMutationDispatch.js.map +0 -1
  426. package/client/reconciledDocumentContentPull.js.map +0 -1
  427. package/client/rootContainerAdoption.js.map +0 -1
  428. package/client/securityIncidents.js.map +0 -1
  429. package/client/userIdentities.js.map +0 -1
  430. package/client/workflowRuntime.js.map +0 -1
  431. package/data/keyingCanonicalJson.js.map +0 -1
  432. package/data/keyingProjectionVerification.d.ts +0 -9
  433. package/data/keyingProjectionVerification.js.map +0 -1
  434. /package/client/{fileSaver.d.ts → host/fileSaver.d.ts} +0 -0
  435. /package/client/{fileSaver.js → host/fileSaver.js} +0 -0
  436. /package/client/{fileSaver.js.map → host/fileSaver.js.map} +0 -0
  437. /package/client/{logger.d.ts → host/logger.d.ts} +0 -0
  438. /package/client/{logger.js → host/logger.js} +0 -0
  439. /package/client/{logger.js.map → host/logger.js.map} +0 -0
  440. /package/client/{apiVersion.d.ts → runtime/apiVersion.d.ts} +0 -0
  441. /package/client/{apiVersion.js → runtime/apiVersion.js} +0 -0
  442. /package/client/{apiVersion.js.map → runtime/apiVersion.js.map} +0 -0
  443. /package/client/{events.d.ts → runtime/events.d.ts} +0 -0
  444. /package/client/{events.js → runtime/events.js} +0 -0
  445. /package/client/{events.js.map → runtime/events.js.map} +0 -0
  446. /package/client/{listenerSet.js → runtime/listenerSet.js} +0 -0
  447. /package/client/{listenerSet.js.map → runtime/listenerSet.js.map} +0 -0
  448. /package/client/{network.d.ts → runtime/network.d.ts} +0 -0
  449. /package/client/{network.js → runtime/network.js} +0 -0
  450. /package/client/{network.js.map → runtime/network.js.map} +0 -0
  451. /package/client/{principalMutationDeadline.js → runtime/principalMutationDeadline.js} +0 -0
  452. /package/client/{principalMutationDeadline.js.map → runtime/principalMutationDeadline.js.map} +0 -0
  453. /package/client/{rootContainerAdoption.js → runtime/rootContainerAdoption.js} +0 -0
  454. /package/client/{syncBillingGate.d.ts → runtime/syncBillingGate.d.ts} +0 -0
  455. /package/client/{syncBillingGate.js → runtime/syncBillingGate.js} +0 -0
  456. /package/client/{syncBillingGate.js.map → runtime/syncBillingGate.js.map} +0 -0
  457. /package/data/{blobContracts.d.ts → blobs/blobContracts.d.ts} +0 -0
  458. /package/data/{blobContracts.js → blobs/blobContracts.js} +0 -0
  459. /package/data/{blobContracts.js.map → blobs/blobContracts.js.map} +0 -0
  460. /package/data/{accessLevel.js → keying/accessLevel.js} +0 -0
  461. /package/data/{accessLevel.js.map → keying/accessLevel.js.map} +0 -0
  462. /package/data/{stableUuid.js → keying/stableUuid.js} +0 -0
  463. /package/data/{stableUuid.js.map → keying/stableUuid.js.map} +0 -0
  464. /package/data/{principalPolicyStates.js → principals/principalPolicyStates.js} +0 -0
  465. /package/data/{principalPolicyStates.js.map → principals/principalPolicyStates.js.map} +0 -0
  466. /package/data/{domainScope.d.ts → shared/domainScope.d.ts} +0 -0
  467. /package/data/{domainScope.js → shared/domainScope.js} +0 -0
  468. /package/data/{domainScope.js.map → shared/domainScope.js.map} +0 -0
  469. /package/data/{errorMessage.js → shared/errorMessage.js} +0 -0
  470. /package/data/{errorMessage.js.map → shared/errorMessage.js.map} +0 -0
  471. /package/data/{recordReaders.d.ts → shared/recordReaders.d.ts} +0 -0
  472. /package/data/{recordReaders.js → shared/recordReaders.js} +0 -0
  473. /package/data/{recordReaders.js.map → shared/recordReaders.js.map} +0 -0
  474. /package/data/{securityIncidents.js → shared/securityIncidents.js} +0 -0
  475. /package/data/{securityIncidents.js.map → shared/securityIncidents.js.map} +0 -0
  476. /package/data/{crdtPeerSeed.js → sync/crdtPeerSeed.js} +0 -0
  477. /package/data/{crdtPeerSeed.js.map → sync/crdtPeerSeed.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"recite.js","sourceRoot":"","sources":["recite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAEL,iBAAiB,EACjB,qBAAqB,EACrB,iCAAiC,GAClC,MAAM,oDAAoD,CAAC;AAI5D,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EACL,uDAAuD,EACvD,iCAAiC,GAClC,MAAM,oEAAoE,CAAC;AAE5E,OAAO,EAEL,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,oCAAoC,EACpC,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,cAAc,CAAC;AAEtB,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAW9B,KAAK,UAAU,YAAY,CACzB,OAAgB,EAChB,IAAkC;IAElC,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,UAAU,GAAG,MAAM,4BAA4B,CACnD,OAAO,EACP,WAAW,EACX,IAAI,CAAC,KAAK,CAAC,cAAc,EACzB,IAAI,CAAC,KAAK,CAAC,WAAW,CACvB,CAAC;QACF,IAAI,UAAU,EAAE,YAAY,KAAK,IAAI,CAAC,MAAM,CAAC,YAAY;YAAE,OAAO,KAAK,CAAC;IAC1E,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,KAAK,UAAU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AE;QACV,wEAAwE;IAC1E,CAAC,CAAC;SACD,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport {\n type HeldContainerHead,\n heldContainerPath,\n heldContainerSnapshot,\n rememberAcknowledgedContainerHead,\n} from \"../../../data/containers/shared/heldContainerHeads\";\nimport type { AuthoredContainerMutationHead } from \"../../../data/containers/shared/mutationAcknowledgement\";\nimport type { ContainerReciteApi } from \"../../../data/containers/shared/reciteApi\";\nimport type { ContainerMutationAuthor } from \"../../../data/containers/shared/types\";\nimport {\n loadAccessManifestCheckpoint,\n loadPrincipalPolicyCheckpoint,\n} from \"../../../data/persistence/keyingCheckpointPersistence\";\nimport {\n advanceLocallyAcknowledgedAccessManifestHeadsAtomically,\n locallyAuthoredAccessManifestHead,\n} from \"../../../data/persistence/locallyAcknowledgedCheckpointPersistence\";\nimport type { SecurityIncidentReporter } from \"../../../data/securityIncidents\";\nimport {\n type ExecSql,\n resolveCanonicalExecSql,\n} from \"../../../data/sqlite/sqlSchema\";\nimport {\n assertContainerReciteAcknowledgement,\n buildContainerRecitePlan,\n referencedRecitationPolicies,\n} from \"./recitePlan\";\n\nconst MAX_RECITES_PER_PASS = 8;\nconst RECITE_SPACING_MS = 250;\n\ninterface ReciteHeldDescendantsInput {\n readonly apiClient: ContainerReciteApi;\n readonly author: ContainerMutationAuthor;\n readonly ancestorIds: readonly string[];\n readonly execSql: ExecSql;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly stillCurrent?: (() => boolean) | undefined;\n}\n\nasync function pathIsPinned(\n execSql: ExecSql,\n path: readonly HeldContainerHead[],\n): Promise<boolean> {\n for (const head of path) {\n const checkpoint = await loadAccessManifestCheckpoint(\n execSql,\n \"container\",\n head.state.organizationId,\n head.state.containerId,\n );\n if (checkpoint?.manifestHash !== head.bundle.manifestHash) return false;\n }\n return true;\n}\n\nasync function recitePinnedPath(\n input: ReciteHeldDescendantsInput,\n path: readonly HeldContainerHead[],\n policies: ReturnType<typeof heldContainerSnapshot>[\"policies\"],\n): Promise<HeldContainerHead | null> {\n const usedPolicies = referencedRecitationPolicies(path, policies);\n if (!(await policiesArePinned(input.execSql, usedPolicies))) return null;\n const plan = await buildContainerRecitePlan({\n author: input.author,\n path,\n policies: usedPolicies,\n });\n if (!(await policiesArePinned(input.execSql, usedPolicies))) return null;\n if (!(await pathIsPinned(input.execSql, path))) return null;\n if (input.stillCurrent?.() === false) return null;\n const id = plan.state.containerId;\n const response = await input.apiClient.reciteContainer(id, plan.request, {\n reportErrors: false,\n });\n if (!response || input.stillCurrent?.() === false) return null;\n try {\n assertContainerReciteAcknowledgement(plan, response);\n } catch (error) {\n const failure =\n error instanceof KeyingVerificationError\n ? error\n : new KeyingVerificationError(\n \"invalid_shape\",\n \"Malformed re-citation acknowledgement\",\n );\n await input.reportSecurityIncident(failure, {\n operation: \"container.recite.acknowledge\",\n objectKind: \"container\",\n objectId: id,\n organizationId: input.author.organizationId,\n evidenceHashes: { plannedManifestHash: plan.manifestHash },\n });\n return null;\n }\n let acknowledged: boolean;\n try {\n acknowledged =\n await advanceLocallyAcknowledgedAccessManifestHeadsAtomically({\n execSql: input.execSql,\n heads: [locallyAuthoredAccessManifestHead(plan)],\n expectedAccessManifestCheckpoints: path.map((head) => ({\n objectKind: \"container\",\n objectId: head.state.containerId,\n organizationId: head.state.organizationId,\n epoch: head.state.epoch,\n manifestHash: head.bundle.manifestHash,\n })),\n expectedPrincipalPolicyCheckpoints: usedPolicies.map(\n (policy) => policy.checkpoint,\n ),\n stillCurrent: input.stillCurrent,\n });\n } catch (error) {\n if (!(error instanceof KeyingVerificationError)) throw error;\n // Another local operation can advance the durable pin while the request\n // is in flight. Refuse the write, but do not label that local race as a\n // contradictory server response: the exact signed acknowledgement above\n // already passed. Normal projection verification reconciles newer heads.\n return null;\n }\n if (!acknowledged || input.stillCurrent?.() === false) return null;\n return rememberAcknowledgedContainerHead(input.execSql, plan);\n}\n\nasync function policiesArePinned(\n execSql: ExecSql,\n policies: ReturnType<typeof referencedRecitationPolicies>,\n): Promise<boolean> {\n for (const policy of policies) {\n const checkpoint = await loadPrincipalPolicyCheckpoint(\n execSql,\n policy.principalType,\n policy.principalId,\n );\n if (\n checkpoint?.version !== policy.version ||\n checkpoint.stateHash !== policy.stateHash\n )\n return false;\n }\n return true;\n}\n\nasync function waitForPinnedPath(\n input: ReciteHeldDescendantsInput,\n path: readonly HeldContainerHead[],\n attempts: number,\n): Promise<boolean> {\n if (!(await pathIsPinned(input.execSql, path))) return false;\n if (attempts > 0) {\n await new Promise((resolve) => setTimeout(resolve, RECITE_SPACING_MS));\n if (!(await pathIsPinned(input.execSql, path))) return false;\n }\n return input.stillCurrent?.() !== false;\n}\n\n/**\n * Best effort only: never fetches a subtree or policy, never retries conflicts,\n * and never turns an unavailable/missing descendant into an ancestor refusal.\n * The API checks admin authority and exact current paths again at commit time.\n */\nexport async function reciteHeldDescendants(\n input: ReciteHeldDescendantsInput,\n): Promise<void> {\n const snapshot = heldContainerSnapshot(\n input.execSql,\n input.author.organizationId,\n );\n const ancestors = new Set(input.ancestorIds);\n const candidates = [...snapshot.heads.keys()]\n .map((id) => ({ id, path: heldContainerPath(snapshot.heads, id) }))\n .filter(\n ({ id, path }) =>\n !ancestors.has(id) &&\n path?.some((head) => ancestors.has(head.state.containerId)),\n )\n .sort((a, b) => (a.path?.length ?? 0) - (b.path?.length ?? 0));\n let attempts = 0;\n for (const { id } of candidates) {\n if (attempts >= MAX_RECITES_PER_PASS) return;\n if (input.stillCurrent?.() === false) return;\n try {\n const path = heldContainerPath(snapshot.heads, id);\n if (!path) continue;\n // Every held head must still equal its durable pin. A failed projection,\n // concurrent mutation, or verify-without-persist result cannot become an\n // implicit checkpoint advance through this opportunistic path.\n if (!(await waitForPinnedPath(input, path, attempts))) continue;\n attempts += 1;\n const updated = await recitePinnedPath(input, path, snapshot.policies);\n if (updated) snapshot.heads.set(id, updated);\n } catch {\n // A later reconciliation can observe any committed response we lost.\n // Do not retry here or change the result of the acknowledged ancestor.\n }\n }\n}\n\nconst running = new WeakSet<ExecSql>();\n\n/** Called only after exact acknowledgement of the original mutation. */\nexport function scheduleHeldDescendantRecitations(\n input: Omit<ReciteHeldDescendantsInput, \"ancestorIds\"> & {\n readonly plans: readonly AuthoredContainerMutationHead[];\n },\n): void {\n if (input.stillCurrent?.() === false) return;\n try {\n for (const plan of input.plans) {\n rememberAcknowledgedContainerHead(input.execSql, plan);\n }\n } catch {\n return;\n }\n const canonical = resolveCanonicalExecSql(input.execSql);\n if (running.has(canonical)) return;\n running.add(canonical);\n void Promise.resolve()\n .then(() =>\n reciteHeldDescendants({\n apiClient: input.apiClient,\n author: input.author,\n // Background work outlives the caller's lock scope. Use the canonical\n // executor so its checkpoint write acquires a new mutation lock.\n execSql: canonical,\n reportSecurityIncident: input.reportSecurityIncident,\n stillCurrent: input.stillCurrent,\n ancestorIds: input.plans.map((plan) => plan.containerId),\n }),\n )\n .catch(() => {\n // Failure is deliberately independent of the user's completed mutation.\n })\n .finally(() => running.delete(canonical));\n}\n"]}
1
+ {"version":3,"file":"recite.js","sourceRoot":"","sources":["recite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAEL,iBAAiB,EACjB,qBAAqB,EACrB,iCAAiC,GAClC,MAAM,oDAAoD,CAAC;AAI5D,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EACL,uDAAuD,EACvD,iCAAiC,GAClC,MAAM,oEAAoE,CAAC;AAE5E,OAAO,EAEL,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,oCAAoC,EACpC,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,cAAc,CAAC;AAEtB,MAAM,oBAAoB,GAAG,CAAC,CA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IACvB,KAAK,OAAO,CAAC,OAAO,EAAE;SACnB,IAAI,CAAC,GAAG,EAAE,CACT,qBAAqB,CAAC;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,sEAAsE;QACtE,iEAAiE;QACjE,OAAO,EAAE,SAAS;QAClB,sBAAsB,EAAE,KAAK,CAAC,sBAAsB;QACpD,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC;KACzD,CAAC,CACH;SACA,KAAK,CAAC,GAAG,EAAE;QACV,wEAAwE;IAC1E,CAAC,CAAC;SACD,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport {\n type HeldContainerHead,\n heldContainerPath,\n heldContainerSnapshot,\n rememberAcknowledgedContainerHead,\n} from \"../../../data/containers/shared/heldContainerHeads\";\nimport type { AuthoredContainerMutationHead } from \"../../../data/containers/shared/mutationAcknowledgement\";\nimport type { ContainerReciteApi } from \"../../../data/containers/shared/reciteApi\";\nimport type { ContainerMutationAuthor } from \"../../../data/containers/shared/types\";\nimport {\n loadAccessManifestCheckpoint,\n loadPrincipalPolicyCheckpoint,\n} from \"../../../data/persistence/keyingCheckpointPersistence\";\nimport {\n advanceLocallyAcknowledgedAccessManifestHeadsAtomically,\n locallyAuthoredAccessManifestHead,\n} from \"../../../data/persistence/locallyAcknowledgedCheckpointPersistence\";\nimport type { SecurityIncidentReporter } from \"../../../data/shared/securityIncidents\";\nimport {\n type ExecSql,\n resolveCanonicalExecSql,\n} from \"../../../data/sqlite/sqlSchema\";\nimport {\n assertContainerReciteAcknowledgement,\n buildContainerRecitePlan,\n referencedRecitationPolicies,\n} from \"./recitePlan\";\n\nconst MAX_RECITES_PER_PASS = 8;\nconst RECITE_SPACING_MS = 250;\n\ninterface ReciteHeldDescendantsInput {\n readonly apiClient: ContainerReciteApi;\n readonly author: ContainerMutationAuthor;\n readonly ancestorIds: readonly string[];\n readonly execSql: ExecSql;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n readonly stillCurrent?: (() => boolean) | undefined;\n}\n\nasync function pathIsPinned(\n execSql: ExecSql,\n path: readonly HeldContainerHead[],\n): Promise<boolean> {\n for (const head of path) {\n const checkpoint = await loadAccessManifestCheckpoint(\n execSql,\n \"container\",\n head.state.organizationId,\n head.state.containerId,\n );\n if (checkpoint?.manifestHash !== head.bundle.manifestHash) return false;\n }\n return true;\n}\n\nasync function recitePinnedPath(\n input: ReciteHeldDescendantsInput,\n path: readonly HeldContainerHead[],\n policies: ReturnType<typeof heldContainerSnapshot>[\"policies\"],\n): Promise<HeldContainerHead | null> {\n const usedPolicies = referencedRecitationPolicies(path, policies);\n if (!(await policiesArePinned(input.execSql, usedPolicies))) return null;\n const plan = await buildContainerRecitePlan({\n author: input.author,\n path,\n policies: usedPolicies,\n });\n if (!(await policiesArePinned(input.execSql, usedPolicies))) return null;\n if (!(await pathIsPinned(input.execSql, path))) return null;\n if (input.stillCurrent?.() === false) return null;\n const id = plan.state.containerId;\n const response = await input.apiClient.reciteContainer(id, plan.request, {\n reportErrors: false,\n });\n if (!response || input.stillCurrent?.() === false) return null;\n try {\n assertContainerReciteAcknowledgement(plan, response);\n } catch (error) {\n const failure =\n error instanceof KeyingVerificationError\n ? error\n : new KeyingVerificationError(\n \"invalid_shape\",\n \"Malformed re-citation acknowledgement\",\n );\n await input.reportSecurityIncident(failure, {\n operation: \"container.recite.acknowledge\",\n objectKind: \"container\",\n objectId: id,\n organizationId: input.author.organizationId,\n evidenceHashes: { plannedManifestHash: plan.manifestHash },\n });\n return null;\n }\n let acknowledged: boolean;\n try {\n acknowledged =\n await advanceLocallyAcknowledgedAccessManifestHeadsAtomically({\n execSql: input.execSql,\n heads: [locallyAuthoredAccessManifestHead(plan)],\n expectedAccessManifestCheckpoints: path.map((head) => ({\n objectKind: \"container\",\n objectId: head.state.containerId,\n organizationId: head.state.organizationId,\n epoch: head.state.epoch,\n manifestHash: head.bundle.manifestHash,\n })),\n expectedPrincipalPolicyCheckpoints: usedPolicies.map(\n (policy) => policy.checkpoint,\n ),\n stillCurrent: input.stillCurrent,\n });\n } catch (error) {\n if (!(error instanceof KeyingVerificationError)) throw error;\n // Another local operation can advance the durable pin while the request\n // is in flight. Refuse the write, but do not label that local race as a\n // contradictory server response: the exact signed acknowledgement above\n // already passed. Normal projection verification reconciles newer heads.\n return null;\n }\n if (!acknowledged || input.stillCurrent?.() === false) return null;\n return rememberAcknowledgedContainerHead(input.execSql, plan);\n}\n\nasync function policiesArePinned(\n execSql: ExecSql,\n policies: ReturnType<typeof referencedRecitationPolicies>,\n): Promise<boolean> {\n for (const policy of policies) {\n const checkpoint = await loadPrincipalPolicyCheckpoint(\n execSql,\n policy.principalType,\n policy.principalId,\n );\n if (\n checkpoint?.version !== policy.version ||\n checkpoint.stateHash !== policy.stateHash\n )\n return false;\n }\n return true;\n}\n\nasync function waitForPinnedPath(\n input: ReciteHeldDescendantsInput,\n path: readonly HeldContainerHead[],\n attempts: number,\n): Promise<boolean> {\n if (!(await pathIsPinned(input.execSql, path))) return false;\n if (attempts > 0) {\n await new Promise((resolve) => setTimeout(resolve, RECITE_SPACING_MS));\n if (!(await pathIsPinned(input.execSql, path))) return false;\n }\n return input.stillCurrent?.() !== false;\n}\n\n/**\n * Best effort only: never fetches a subtree or policy, never retries conflicts,\n * and never turns an unavailable/missing descendant into an ancestor refusal.\n * The API checks admin authority and exact current paths again at commit time.\n */\nexport async function reciteHeldDescendants(\n input: ReciteHeldDescendantsInput,\n): Promise<void> {\n const snapshot = heldContainerSnapshot(\n input.execSql,\n input.author.organizationId,\n );\n const ancestors = new Set(input.ancestorIds);\n const candidates = [...snapshot.heads.keys()]\n .map((id) => ({ id, path: heldContainerPath(snapshot.heads, id) }))\n .filter(\n ({ id, path }) =>\n !ancestors.has(id) &&\n path?.some((head) => ancestors.has(head.state.containerId)),\n )\n .sort((a, b) => (a.path?.length ?? 0) - (b.path?.length ?? 0));\n let attempts = 0;\n for (const { id } of candidates) {\n if (attempts >= MAX_RECITES_PER_PASS) return;\n if (input.stillCurrent?.() === false) return;\n try {\n const path = heldContainerPath(snapshot.heads, id);\n if (!path) continue;\n // Every held head must still equal its durable pin. A failed projection,\n // concurrent mutation, or verify-without-persist result cannot become an\n // implicit checkpoint advance through this opportunistic path.\n if (!(await waitForPinnedPath(input, path, attempts))) continue;\n attempts += 1;\n const updated = await recitePinnedPath(input, path, snapshot.policies);\n if (updated) snapshot.heads.set(id, updated);\n } catch {\n // A later reconciliation can observe any committed response we lost.\n // Do not retry here or change the result of the acknowledged ancestor.\n }\n }\n}\n\nconst running = new WeakSet<ExecSql>();\n\n/** Called only after exact acknowledgement of the original mutation. */\nexport function scheduleHeldDescendantRecitations(\n input: Omit<ReciteHeldDescendantsInput, \"ancestorIds\"> & {\n readonly plans: readonly AuthoredContainerMutationHead[];\n },\n): void {\n if (input.stillCurrent?.() === false) return;\n try {\n for (const plan of input.plans) {\n rememberAcknowledgedContainerHead(input.execSql, plan);\n }\n } catch {\n return;\n }\n const canonical = resolveCanonicalExecSql(input.execSql);\n if (running.has(canonical)) return;\n running.add(canonical);\n void Promise.resolve()\n .then(() =>\n reciteHeldDescendants({\n apiClient: input.apiClient,\n author: input.author,\n // Background work outlives the caller's lock scope. Use the canonical\n // executor so its checkpoint write acquires a new mutation lock.\n execSql: canonical,\n reportSecurityIncident: input.reportSecurityIncident,\n stillCurrent: input.stillCurrent,\n ancestorIds: input.plans.map((plan) => plan.containerId),\n }),\n )\n .catch(() => {\n // Failure is deliberately independent of the user's completed mutation.\n })\n .finally(() => running.delete(canonical));\n}\n"]}
@@ -2,7 +2,7 @@ import { computeAccessManifestHash, deriveContainerAccessManifest, KeyingVerific
2
2
  import { signContainerMutationEvent } from "../../../data/containers/shared/events.js";
3
3
  import { principalPolicyRequestRecord } from "../../../data/containers/shared/principalPolicies.js";
4
4
  import { containerManifestRef } from "../../../data/containers/shared/projection.js";
5
- import { canonicalKeyingJsonString, readCanonicalRecord, } from "../../../data/keyingCanonicalJson.js";
5
+ import { canonicalKeyingJsonString, readCanonicalRecord, } from "../../../data/keying/canonicalJson.js";
6
6
  export function referencedRecitationPolicies(path, policies) {
7
7
  const referencedIds = new Set(path.flatMap((head) => head.state.referencedPrincipalHeads.map((ref) => `${ref.principalType}:${ref.principalId}`)));
8
8
  return policies.filter((policy) => referencedIds.has(`${policy.principalType}:${policy.principalId}`));
@@ -1 +1 @@
1
- {"version":3,"file":"recitePlan.js","sourceRoot":"","sources":["recitePlan.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,EACvB,8BAA8B,EAC9B,wCAAwC,GACzC,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAEpF,OAAO,EAAE,4BAA4B,EAAE,MAAM,mDAAmD,CAAC;AACjG,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAElF,OAAO,EACL,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,mCAAmC,CAAC;AAG3C,MAAM,UAAU,4BAA4B,CAC1C,IAAkC,EAClC,QAAsD;IAEtD,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACpB,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,GAAG,CACrC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,WAAW,EAAE,CACnD,CACF,CACF,CAAC;IACF,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAChC,aAAa,CAA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C,uBAAuB,CACxB;YACC,yBAAyB,CACvB,IAAI,CAAC,QAAQ,CAAC,wBAAwB,EACtC,+BAA+B,CAChC;QAEH,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,8DAA8D,CAC/D,CAAC;AACN,CAAC","sourcesContent":["import {\n computeAccessManifestHash,\n deriveContainerAccessManifest,\n KeyingVerificationError,\n MAX_CONTAINER_RECITATION_EPOCH,\n resolveContainerStatePathUserAccessLevel,\n} from \"@tearleads/crypto\";\nimport type { ContainerReciteRequest } from \"@tearleads/validators/request\";\nimport type { ContainerReciteResponse } from \"@tearleads/validators/response\";\nimport { signContainerMutationEvent } from \"../../../data/containers/shared/events\";\nimport type { HeldContainerHead } from \"../../../data/containers/shared/heldContainerHeads\";\nimport { principalPolicyRequestRecord } from \"../../../data/containers/shared/principalPolicies\";\nimport { containerManifestRef } from \"../../../data/containers/shared/projection\";\nimport type { ContainerMutationAuthor } from \"../../../data/containers/shared/types\";\nimport {\n canonicalKeyingJsonString,\n readCanonicalRecord,\n} from \"../../../data/keyingCanonicalJson\";\nimport type { PrincipalPolicyCheckpointEvidence } from \"../../../data/principals/principalPolicyEvidence\";\n\nexport function referencedRecitationPolicies(\n path: readonly HeldContainerHead[],\n policies: readonly PrincipalPolicyCheckpointEvidence[],\n): readonly PrincipalPolicyCheckpointEvidence[] {\n const referencedIds = new Set(\n path.flatMap((head) =>\n head.state.referencedPrincipalHeads.map(\n (ref) => `${ref.principalType}:${ref.principalId}`,\n ),\n ),\n );\n return policies.filter((policy) =>\n referencedIds.has(`${policy.principalType}:${policy.principalId}`),\n );\n}\n\nexport async function buildContainerRecitePlan(input: {\n readonly author: ContainerMutationAuthor;\n readonly path: readonly HeldContainerHead[];\n readonly policies: readonly PrincipalPolicyCheckpointEvidence[];\n}) {\n const previous = input.path.at(-1);\n if (!previous) throw new Error(\"Recitation requires a held container path\");\n if (previous.state.epoch >= MAX_CONTAINER_RECITATION_EPOCH) {\n throw new Error(\"Container re-citation history budget is exhausted\");\n }\n if (\n input.path.some(\n (head) => head.state.organizationId !== input.author.organizationId,\n )\n ) {\n throw new Error(\"Recitation cannot cross organizations\");\n }\n if (\n resolveContainerStatePathUserAccessLevel({\n states: input.path.map((head) => head.state),\n principalPolicies: input.policies,\n userId: input.author.signerUserId,\n }) !== \"admin\"\n ) {\n throw new KeyingVerificationError(\n \"unauthorized\",\n \"Container re-citation signer lacks admin access on the held path\",\n );\n }\n const body = {\n eventType: \"container.recite\" as const,\n containerKeyEpochId: previous.state.containerKeyEpochId,\n containerKeyPublicKey: previous.state.containerKeyPublicKey,\n };\n const { event, eventHash } = await signContainerMutationEvent({\n author: input.author,\n body,\n containerId: previous.state.containerId,\n dependencyManifestHashes: input.path.map(\n (head) => head.bundle.manifestHash,\n ),\n eventId: crypto.randomUUID(),\n previousManifestHash: previous.bundle.manifestHash,\n signedAt: new Date().toISOString(),\n });\n const state = {\n ...previous.state,\n epoch: previous.state.epoch + 1,\n eventHash,\n previousManifestHash: previous.bundle.manifestHash,\n };\n const manifest = await deriveContainerAccessManifest(state);\n const manifestHash = await computeAccessManifestHash(manifest);\n const request: ContainerReciteRequest = {\n body,\n event: readCanonicalRecord(event, \"Recitation event\"),\n manifest: readCanonicalRecord(manifest, \"Recitation manifest\"),\n expectedManifestHash: manifestHash,\n previousManifestRef: containerManifestRef(previous.bundle),\n previousContainerPathRefs: input.path.map((head) =>\n containerManifestRef(head.bundle),\n ),\n principalPolicies: referencedRecitationPolicies(\n input.path,\n input.policies,\n ).map((policy) => principalPolicyRequestRecord(policy)),\n };\n return { body, event, eventHash, manifest, manifestHash, state, request };\n}\n\nexport function assertContainerReciteAcknowledgement(\n plan: Awaited<ReturnType<typeof buildContainerRecitePlan>>,\n response: ContainerReciteResponse,\n): void {\n const bundle = response.accessManifest;\n const signedFieldsMatch = [\n [bundle.event.event, plan.event],\n [bundle.event.body, plan.body],\n [bundle.manifest, plan.manifest],\n [bundle.state, plan.state],\n ].every(\n ([actual, expected]) =>\n canonicalKeyingJsonString(actual, \"Recitation response\") ===\n canonicalKeyingJsonString(expected, \"Recitation plan\"),\n );\n if (\n response.containerId !== plan.state.containerId ||\n response.organizationId !== plan.state.organizationId ||\n response.parentId !== plan.state.parentContainerId ||\n response.manifestHead.epoch !== plan.state.epoch ||\n response.manifestHead.manifestHash !== plan.manifestHash ||\n bundle.manifestHash !== plan.manifestHash ||\n bundle.event.eventHash !== plan.eventHash ||\n !signedFieldsMatch ||\n canonicalKeyingJsonString(\n response.referencedPrincipalHeads,\n \"Recitation references\",\n ) !==\n canonicalKeyingJsonString(\n plan.manifest.referencedPrincipalHeads,\n \"Recitation planned references\",\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Container recitation response does not match the signed plan\",\n );\n}\n"]}
1
+ {"version":3,"file":"recitePlan.js","sourceRoot":"","sources":["recitePlan.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,EACvB,8BAA8B,EAC9B,wCAAwC,GACzC,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAEpF,OAAO,EAAE,4BAA4B,EAAE,MAAM,mDAAmD,CAAC;AACjG,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAElF,OAAO,EACL,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,oCAAoC,CAAC;AAG5C,MAAM,UAAU,4BAA4B,CAC1C,IAAkC,EAClC,QAAsD;IAEtD,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACpB,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,GAAG,CACrC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,WAAW,EAAE,CACnD,CACF,CACF,CAAC;IACF,OAAO,QAAQ,CAAC,MAAM,CAAC,CA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AAyB,CACvB,QAAQ,CAAC,wBAAwB,EACjC,uBAAuB,CACxB;YACC,yBAAyB,CACvB,IAAI,CAAC,QAAQ,CAAC,wBAAwB,EACtC,+BAA+B,CAChC;QAEH,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,8DAA8D,CAC/D,CAAC;AACN,CAAC","sourcesContent":["import {\n computeAccessManifestHash,\n deriveContainerAccessManifest,\n KeyingVerificationError,\n MAX_CONTAINER_RECITATION_EPOCH,\n resolveContainerStatePathUserAccessLevel,\n} from \"@tearleads/crypto\";\nimport type { ContainerReciteRequest } from \"@tearleads/validators/request\";\nimport type { ContainerReciteResponse } from \"@tearleads/validators/response\";\nimport { signContainerMutationEvent } from \"../../../data/containers/shared/events\";\nimport type { HeldContainerHead } from \"../../../data/containers/shared/heldContainerHeads\";\nimport { principalPolicyRequestRecord } from \"../../../data/containers/shared/principalPolicies\";\nimport { containerManifestRef } from \"../../../data/containers/shared/projection\";\nimport type { ContainerMutationAuthor } from \"../../../data/containers/shared/types\";\nimport {\n canonicalKeyingJsonString,\n readCanonicalRecord,\n} from \"../../../data/keying/canonicalJson\";\nimport type { PrincipalPolicyCheckpointEvidence } from \"../../../data/principals/principalPolicyEvidence\";\n\nexport function referencedRecitationPolicies(\n path: readonly HeldContainerHead[],\n policies: readonly PrincipalPolicyCheckpointEvidence[],\n): readonly PrincipalPolicyCheckpointEvidence[] {\n const referencedIds = new Set(\n path.flatMap((head) =>\n head.state.referencedPrincipalHeads.map(\n (ref) => `${ref.principalType}:${ref.principalId}`,\n ),\n ),\n );\n return policies.filter((policy) =>\n referencedIds.has(`${policy.principalType}:${policy.principalId}`),\n );\n}\n\nexport async function buildContainerRecitePlan(input: {\n readonly author: ContainerMutationAuthor;\n readonly path: readonly HeldContainerHead[];\n readonly policies: readonly PrincipalPolicyCheckpointEvidence[];\n}) {\n const previous = input.path.at(-1);\n if (!previous) throw new Error(\"Recitation requires a held container path\");\n if (previous.state.epoch >= MAX_CONTAINER_RECITATION_EPOCH) {\n throw new Error(\"Container re-citation history budget is exhausted\");\n }\n if (\n input.path.some(\n (head) => head.state.organizationId !== input.author.organizationId,\n )\n ) {\n throw new Error(\"Recitation cannot cross organizations\");\n }\n if (\n resolveContainerStatePathUserAccessLevel({\n states: input.path.map((head) => head.state),\n principalPolicies: input.policies,\n userId: input.author.signerUserId,\n }) !== \"admin\"\n ) {\n throw new KeyingVerificationError(\n \"unauthorized\",\n \"Container re-citation signer lacks admin access on the held path\",\n );\n }\n const body = {\n eventType: \"container.recite\" as const,\n containerKeyEpochId: previous.state.containerKeyEpochId,\n containerKeyPublicKey: previous.state.containerKeyPublicKey,\n };\n const { event, eventHash } = await signContainerMutationEvent({\n author: input.author,\n body,\n containerId: previous.state.containerId,\n dependencyManifestHashes: input.path.map(\n (head) => head.bundle.manifestHash,\n ),\n eventId: crypto.randomUUID(),\n previousManifestHash: previous.bundle.manifestHash,\n signedAt: new Date().toISOString(),\n });\n const state = {\n ...previous.state,\n epoch: previous.state.epoch + 1,\n eventHash,\n previousManifestHash: previous.bundle.manifestHash,\n };\n const manifest = await deriveContainerAccessManifest(state);\n const manifestHash = await computeAccessManifestHash(manifest);\n const request: ContainerReciteRequest = {\n body,\n event: readCanonicalRecord(event, \"Recitation event\"),\n manifest: readCanonicalRecord(manifest, \"Recitation manifest\"),\n expectedManifestHash: manifestHash,\n previousManifestRef: containerManifestRef(previous.bundle),\n previousContainerPathRefs: input.path.map((head) =>\n containerManifestRef(head.bundle),\n ),\n principalPolicies: referencedRecitationPolicies(\n input.path,\n input.policies,\n ).map((policy) => principalPolicyRequestRecord(policy)),\n };\n return { body, event, eventHash, manifest, manifestHash, state, request };\n}\n\nexport function assertContainerReciteAcknowledgement(\n plan: Awaited<ReturnType<typeof buildContainerRecitePlan>>,\n response: ContainerReciteResponse,\n): void {\n const bundle = response.accessManifest;\n const signedFieldsMatch = [\n [bundle.event.event, plan.event],\n [bundle.event.body, plan.body],\n [bundle.manifest, plan.manifest],\n [bundle.state, plan.state],\n ].every(\n ([actual, expected]) =>\n canonicalKeyingJsonString(actual, \"Recitation response\") ===\n canonicalKeyingJsonString(expected, \"Recitation plan\"),\n );\n if (\n response.containerId !== plan.state.containerId ||\n response.organizationId !== plan.state.organizationId ||\n response.parentId !== plan.state.parentContainerId ||\n response.manifestHead.epoch !== plan.state.epoch ||\n response.manifestHead.manifestHash !== plan.manifestHash ||\n bundle.manifestHash !== plan.manifestHash ||\n bundle.event.eventHash !== plan.eventHash ||\n !signedFieldsMatch ||\n canonicalKeyingJsonString(\n response.referencedPrincipalHeads,\n \"Recitation references\",\n ) !==\n canonicalKeyingJsonString(\n plan.manifest.referencedPrincipalHeads,\n \"Recitation planned references\",\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Container recitation response does not match the signed plan\",\n );\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { ContainerKekKeyringEntry } from "../../../internal/crypto/index.js";
2
2
  import type { ContainerWriterProjectionResponse } from "../../../internal/validators/response/index.js";
3
3
  import type { ContainerMutationAuthor, MaterializedContainerRekeyPlan } from "../../../data/containers/shared/types.js";
4
- import { type PrincipalPolicyCache, type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../data/keyingProjectionVerification.js";
4
+ import { type PrincipalPolicyCache, type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../data/keyingProjectionVerification/index.js";
5
5
  import type { PrincipalPolicyCurrentEvidence } from "../../../data/principals/principalPolicyEvidence.js";
6
6
  import type { ExecSql } from "../../../data/sqlite/sqlSchema.js";
7
7
  /**
@@ -2,8 +2,8 @@ import { computeAccessManifestHash, computeContainerKekKeyringHash, computeConta
2
2
  import { assertContainerAuthorAccess } from "../../../data/containers/shared/authorAccess.js";
3
3
  import { buildContainerCreateKeyEpoch, resolveContainerKekEpochId, signContainerMutationEvent, } from "../../../data/containers/shared/events.js";
4
4
  import { asContainerManifestBundle, uniqueSortedManifestHashes, } from "../../../data/containers/shared/projection.js";
5
- import { readCanonicalRecord } from "../../../data/keyingCanonicalJson.js";
6
- import { requireProjectionUserKeyResolver, } from "../../../data/keyingProjectionVerification.js";
5
+ import { readCanonicalRecord } from "../../../data/keying/canonicalJson.js";
6
+ import { requireProjectionUserKeyResolver, } from "../../../data/keyingProjectionVerification/index.js";
7
7
  import { assertOverrideMatchesSignedLineage } from "./keyringOverrideLineage.js";
8
8
  import { sealRotationKeyring, verifyKeyringEntriesForSeal, } from "./moveRotation.js";
9
9
  import { containerMutationRequestCore, previousPathRequestFields, readCanonicalRecordOrNull, } from "./mutationRequestCore.js";
@@ -1 +1 @@
1
- {"version":3,"file":"rekey.js","sourceRoot":"","sources":["rekey.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,wCAAwC,EACxC,mCAAmC,EACnC,6BAA6B,EAC7B,mCAAmC,EACnC,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,yBAAyB,EAIzB,0BAA0B,GAC3B,MAAM,4CAA4C,CAAC;AAMpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAIL,gCAAgC,GACjC,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EAAE,kCAAkC,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EACL,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,sBAAsB,GAEvB,MAAM,mBAAmB,CAAC;A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kB,CACzB;YACD,iBAAiB,EAAE,mBAAmB,CACpC,KAAK,CAAC,iBAAiB,EACvB,oCAAoC,CACrC;YACD,OAAO,EAAE,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,yBAAyB,CAAC;YACtE,cAAc,EAAE,yBAAyB,CACvC,KAAK,CAAC,SAAS,EACf,kCAAkC,CACnC;SACF;QACD,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ContainerGrantPrincipalHead,\n ContainerKekKeyring,\n ContainerKekKeyringEntry,\n ContainerRekeyAccessEventBody,\n} from \"@tearleads/crypto\";\nimport {\n computeAccessManifestHash,\n computeContainerKekKeyringHash,\n computeContainerKekPredecessorBridgeHash,\n createContainerKekPredecessorBridge,\n deriveContainerAccessManifest,\n deriveContainerKekWrappingPublicKey,\n sealContainerKekKeyring,\n} from \"@tearleads/crypto\";\nimport type { ContainerWriterProjectionResponse } from \"@tearleads/validators/response\";\nimport { assertContainerAuthorAccess } from \"../../../data/containers/shared/authorAccess\";\nimport {\n buildContainerCreateKeyEpoch,\n resolveContainerKekEpochId,\n signContainerMutationEvent,\n} from \"../../../data/containers/shared/events\";\nimport {\n asContainerManifestBundle,\n type getParentKekForTarget,\n type getTargetContainerContext,\n type readContainerState,\n uniqueSortedManifestHashes,\n} from \"../../../data/containers/shared/projection\";\nimport type {\n ContainerMutationAuthor,\n ContainerRekeyPlan,\n MaterializedContainerRekeyPlan,\n} from \"../../../data/containers/shared/types\";\nimport { readCanonicalRecord } from \"../../../data/keyingCanonicalJson\";\nimport {\n type PrincipalPolicyCache,\n type ProjectionUserKeyResolver,\n type ReferencedPrincipalPolicyWarmer,\n requireProjectionUserKeyResolver,\n} from \"../../../data/keyingProjectionVerification\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../../data/principals/principalPolicyEvidence\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport { assertOverrideMatchesSignedLineage } from \"./keyringOverrideLineage\";\nimport {\n sealRotationKeyring,\n verifyKeyringEntriesForSeal,\n} from \"./moveRotation\";\nimport {\n containerMutationRequestCore,\n previousPathRequestFields,\n readCanonicalRecordOrNull,\n} from \"./mutationRequestCore\";\nimport {\n containerWriterProjectionFromRekeyPlan,\n isSpeculativeContainerWriterProjection,\n} from \"./rekeyProjection\";\nimport {\n resolveRotationContext,\n type SignedRotationTarget,\n} from \"./rotationContext\";\nimport { collectContainerRevokePrincipalPolicies } from \"./rotationPrincipalPolicies\";\nimport { buildContainerRotationWraps } from \"./rotationWraps\";\nimport {\n refreshedPrincipalPolicies,\n refreshedPrincipalReferences,\n} from \"./sharePlanCore\";\n\nasync function buildRekeyRotationArtifacts(input: {\n containerKey: Uint8Array;\n keyringEntriesOverride: readonly ContainerKekKeyringEntry[] | undefined;\n nextContainerKeyEpoch: number;\n predecessorContainerKey: Uint8Array;\n previousContainerId: string;\n target: SignedRotationTarget;\n}): Promise<{\n containerKeyEpochId: string;\n keyring: ContainerKekKeyring;\n predecessorBridge: Awaited<\n ReturnType<typeof createContainerKekPredecessorBridge>\n >;\n}> {\n const containerKeyEpochId = await resolveContainerKekEpochId({\n containerId: input.previousContainerId,\n keyEpoch: input.nextContainerKeyEpoch,\n keyMaterial: input.containerKey,\n });\n const predecessorBridge = await createContainerKekPredecessorBridge({\n containerId: input.previousContainerId,\n predecessorContainerKey: input.predecessorContainerKey,\n predecessorContainerKeyEpochId: input.target.kek.containerKeyEpochId,\n successorContainerKey: input.containerKey,\n successorContainerKeyEpochId: containerKeyEpochId,\n });\n if (input.keyringEntriesOverride) {\n // A rebuilt override still has to agree with the epochs the projection's\n // signed history commits to; otherwise a repair could seal a forgery.\n // Exact match first, for distinct errors; the seal check below then adds\n // only the per-entry material check for an override.\n assertOverrideMatchesSignedLineage(\n input.keyringEntriesOverride,\n input.target.signedEpochIds,\n );\n await verifyKeyringEntriesForSeal(\n input.previousContainerId,\n input.keyringEntriesOverride,\n input.target.signedEpochIds,\n );\n }\n const keyring: ContainerKekKeyring = input.keyringEntriesOverride\n ? await sealContainerKekKeyring({\n containerId: input.previousContainerId,\n entries: [\n ...input.keyringEntriesOverride,\n {\n containerKeyEpochId: input.target.kek.containerKeyEpochId,\n keyMaterial: input.predecessorContainerKey,\n },\n ],\n keyEpoch: input.nextContainerKeyEpoch,\n successorContainerKey: input.containerKey,\n successorContainerKeyEpochId: containerKeyEpochId,\n })\n : await sealRotationKeyring({\n containerId: input.previousContainerId,\n currentKek: input.target.kek,\n currentKeyMaterial: input.predecessorContainerKey,\n keyEpoch: input.nextContainerKeyEpoch,\n signedEpochIds: input.target.signedEpochIds,\n successorContainerKey: input.containerKey,\n successorContainerKeyEpochId: containerKeyEpochId,\n });\n return { containerKeyEpochId, keyring, predecessorBridge };\n}\n\nasync function deriveRekeyManifestArtifacts(input: {\n containerKey: Uint8Array;\n author: ContainerMutationAuthor;\n containerKeyEpochId: string;\n eventId: string | undefined;\n keyring: ContainerKekKeyring;\n parentKek: ReturnType<typeof getParentKekForTarget>;\n predecessorBridge: Awaited<\n ReturnType<typeof createContainerKekPredecessorBridge>\n >;\n previousProjection: ContainerWriterProjectionResponse;\n previousState: ReturnType<typeof readContainerState>;\n referencedPrincipalHeads: readonly ContainerGrantPrincipalHead[];\n signedAt: string | undefined;\n target: ReturnType<typeof getTargetContainerContext>;\n}) {\n const body: ContainerRekeyAccessEventBody = {\n eventType: \"container.rekey\",\n parentManifestHash:\n input.previousProjection.path.at(-2)?.manifestHash ?? null,\n containerKeyPublicKey: await deriveContainerKekWrappingPublicKey({\n containerId: input.previousState.containerId,\n keyMaterial: input.containerKey,\n }),\n containerKeyEpochId: input.containerKeyEpochId,\n keyringHash: await computeContainerKekKeyringHash(input.keyring),\n predecessorBridgeHash: await computeContainerKekPredecessorBridgeHash(\n input.predecessorBridge,\n ),\n referencedPrincipalHeads: [...input.referencedPrincipalHeads],\n };\n const { event, eventHash } = await signContainerMutationEvent({\n author: input.author,\n body,\n containerId: input.previousState.containerId,\n dependencyManifestHashes: uniqueSortedManifestHashes(\n input.previousProjection.path,\n ),\n eventId: input.eventId ?? crypto.randomUUID(),\n previousManifestHash: input.target.manifest.manifestHash,\n signedAt: input.signedAt ?? new Date().toISOString(),\n });\n const state = {\n ...input.previousState,\n parentManifestHash: body.parentManifestHash,\n containerKeyPublicKey: body.containerKeyPublicKey,\n epoch: input.previousState.epoch + 1,\n previousManifestHash: input.target.manifest.manifestHash,\n eventHash,\n containerKeyEpochId: input.containerKeyEpochId,\n referencedPrincipalHeads: [...input.referencedPrincipalHeads],\n };\n const manifest = await deriveContainerAccessManifest(state);\n const manifestHash = await computeAccessManifestHash(manifest);\n const keyEpoch = buildContainerCreateKeyEpoch({\n containerId: input.previousState.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n eventHash,\n keyEpoch: input.target.kek.containerKeyEpoch + 1,\n manifestHash,\n parentContainerKeyEpochId: input.parentKek?.containerKeyEpochId ?? null,\n });\n return { body, event, eventHash, keyEpoch, manifest, manifestHash, state };\n}\n\n/**\n * An explicit container KEK rotation with no membership change. Doubles as\n * the repair operation: passing `keyringEntriesOverride` seals a keyring\n * rebuilt from the bridge log instead of re-opening the served one, so a\n * poisoned snapshot is replaced by ground truth.\n */\ninterface RekeyPlanInput {\n author: ContainerMutationAuthor;\n eventId?: string | undefined;\n execSql: ExecSql;\n keyringEntriesOverride?: readonly ContainerKekKeyringEntry[] | undefined;\n /** Keys a batch minted above this container and has yet to commit. */\n knownContainerKeks?: ReadonlyMap<string, Uint8Array> | undefined;\n persistVerificationCheckpoints?: boolean | undefined;\n previousProjection: ContainerWriterProjectionResponse;\n /** Verified policies the path may cite before they are stored locally. */\n principalPolicyCache?: PrincipalPolicyCache | undefined;\n replacementPrincipalPolicy?: PrincipalPolicyCurrentEvidence | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n targetSecretKey: Uint8Array;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}\n\nfunction speculativeSafeRekeyInput(input: RekeyPlanInput): RekeyPlanInput {\n return isSpeculativeContainerWriterProjection(input.previousProjection)\n ? { ...input, persistVerificationCheckpoints: false }\n : input;\n}\n\nasync function collectRekeyPrincipalPolicies(\n input: RekeyPlanInput,\n resolveUserKey: ProjectionUserKeyResolver,\n): Promise<PrincipalPolicyCurrentEvidence[]> {\n const previousPolicies = await collectContainerRevokePrincipalPolicies({\n execSql: input.execSql,\n persistVerificationCheckpoints: input.persistVerificationCheckpoints,\n previousProjection: input.previousProjection,\n principalPolicyCache: input.principalPolicyCache,\n resolveUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n const principalPolicies = refreshedPrincipalPolicies({\n previousPolicies,\n replacementPrincipalPolicy: input.replacementPrincipalPolicy,\n });\n assertContainerAuthorAccess({\n author: input.author,\n projection: input.previousProjection,\n principalPolicies,\n minimumAccess: \"write\",\n });\n return principalPolicies;\n}\n\nexport async function buildMaterializedContainerRekeyPlan(\n input: RekeyPlanInput,\n): Promise<MaterializedContainerRekeyPlan> {\n const resolveProjectionUserKey = requireProjectionUserKeyResolver(\n input.resolveProjectionUserKey,\n \"Remote container rekey\",\n );\n const planningInput = speculativeSafeRekeyInput(input);\n const containerKey = crypto.getRandomValues(new Uint8Array(32));\n const {\n parentKek,\n parentPublicKey,\n predecessorContainerKey,\n previousState,\n target,\n } = await resolveRotationContext(planningInput, \"rekey\");\n const { containerKeyEpochId, keyring, predecessorBridge } =\n await buildRekeyRotationArtifacts({\n containerKey,\n keyringEntriesOverride: input.keyringEntriesOverride,\n nextContainerKeyEpoch: target.kek.containerKeyEpoch + 1,\n predecessorContainerKey,\n previousContainerId: previousState.containerId,\n target,\n });\n const principalPolicies = await collectRekeyPrincipalPolicies(\n planningInput,\n resolveProjectionUserKey,\n );\n\n const referencedPrincipalHeads = refreshedPrincipalReferences({\n previousState,\n replacementPrincipalPolicy: input.replacementPrincipalPolicy,\n });\n const { body, event, eventHash, keyEpoch, manifest, manifestHash, state } =\n await deriveRekeyManifestArtifacts({\n containerKey,\n author: input.author,\n containerKeyEpochId,\n eventId: input.eventId,\n keyring,\n parentKek,\n predecessorBridge,\n previousProjection: input.previousProjection,\n previousState,\n referencedPrincipalHeads,\n signedAt: input.signedAt,\n target,\n });\n const { userRecipientKeys, wraps } = await buildContainerRotationWraps({\n containerKey,\n containerKeyEpochId,\n manifestHash,\n operationLabel: \"Container rekey\",\n parentKek,\n parentPublicKey,\n principalPolicies,\n resolveUserKey: resolveProjectionUserKey,\n state,\n });\n\n const plan = buildContainerRekeyPlan({\n body,\n containerId: previousState.containerId,\n containerKeyEpochId,\n event,\n eventHash,\n keyEpoch,\n keyring,\n manifest,\n manifestHash,\n parentKek,\n predecessorBridge,\n previousManifest: asContainerManifestBundle(target.manifest),\n previousProjection: input.previousProjection,\n principalPolicies,\n state,\n userRecipientKeys,\n wraps,\n });\n const materializedPlan = { containerKey, plan };\n return {\n ...materializedPlan,\n writerProjection: await containerWriterProjectionFromRekeyPlan({\n materializedPlan,\n previousProjection: input.previousProjection,\n }),\n };\n}\n\nfunction buildContainerRekeyPlan(input: {\n body: ContainerRekeyAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: ContainerRekeyPlan[\"event\"];\n eventHash: string;\n keyEpoch: ContainerRekeyPlan[\"keyEpoch\"];\n keyring: ContainerKekKeyring;\n manifest: ContainerRekeyPlan[\"manifest\"];\n manifestHash: string;\n parentKek: ReturnType<typeof getParentKekForTarget>;\n predecessorBridge: Awaited<\n ReturnType<typeof createContainerKekPredecessorBridge>\n >;\n previousManifest: ContainerRekeyPlan[\"previousManifest\"];\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n state: ContainerRekeyPlan[\"state\"];\n userRecipientKeys: ContainerRekeyPlan[\"userRecipientKeys\"];\n wraps: ContainerRekeyPlan[\"wraps\"];\n}): ContainerRekeyPlan {\n return {\n body: input.body,\n containerId: input.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n event: input.event,\n eventHash: input.eventHash,\n keyEpoch: input.keyEpoch,\n keyring: input.keyring,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n previousManifest: input.previousManifest,\n request: {\n ...containerMutationRequestCore(\"rekey\", input),\n ...previousPathRequestFields(\n input.previousManifest,\n input.previousProjection,\n ),\n predecessorBridge: readCanonicalRecord(\n input.predecessorBridge,\n \"Container rekey predecessor bridge\",\n ),\n keyring: readCanonicalRecord(input.keyring, \"Container rekey keyring\"),\n parentKekState: readCanonicalRecordOrNull(\n input.parentKek,\n \"Container rekey parent KEK state\",\n ),\n },\n state: input.state,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n };\n}\n"]}
1
+ {"version":3,"file":"rekey.js","sourceRoot":"","sources":["rekey.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,wCAAwC,EACxC,mCAAmC,EACnC,6BAA6B,EAC7B,mCAAmC,EACnC,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,yBAAyB,EAIzB,0BAA0B,GAC3B,MAAM,4CAA4C,CAAC;AAMpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAIL,gCAAgC,GACjC,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EAAE,kCAAkC,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EACL,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB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E,KAAK,CAAC,YAAY;QAChC,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,OAAO,EAAE;YACP,GAAG,4BAA4B,CAAC,OAAO,EAAE,KAAK,CAAC;YAC/C,GAAG,yBAAyB,CAC1B,KAAK,CAAC,gBAAgB,EACtB,KAAK,CAAC,kBAAkB,CACzB;YACD,iBAAiB,EAAE,mBAAmB,CACpC,KAAK,CAAC,iBAAiB,EACvB,oCAAoC,CACrC;YACD,OAAO,EAAE,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,yBAAyB,CAAC;YACtE,cAAc,EAAE,yBAAyB,CACvC,KAAK,CAAC,SAAS,EACf,kCAAkC,CACnC;SACF;QACD,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ContainerGrantPrincipalHead,\n ContainerKekKeyring,\n ContainerKekKeyringEntry,\n ContainerRekeyAccessEventBody,\n} from \"@tearleads/crypto\";\nimport {\n computeAccessManifestHash,\n computeContainerKekKeyringHash,\n computeContainerKekPredecessorBridgeHash,\n createContainerKekPredecessorBridge,\n deriveContainerAccessManifest,\n deriveContainerKekWrappingPublicKey,\n sealContainerKekKeyring,\n} from \"@tearleads/crypto\";\nimport type { ContainerWriterProjectionResponse } from \"@tearleads/validators/response\";\nimport { assertContainerAuthorAccess } from \"../../../data/containers/shared/authorAccess\";\nimport {\n buildContainerCreateKeyEpoch,\n resolveContainerKekEpochId,\n signContainerMutationEvent,\n} from \"../../../data/containers/shared/events\";\nimport {\n asContainerManifestBundle,\n type getParentKekForTarget,\n type getTargetContainerContext,\n type readContainerState,\n uniqueSortedManifestHashes,\n} from \"../../../data/containers/shared/projection\";\nimport type {\n ContainerMutationAuthor,\n ContainerRekeyPlan,\n MaterializedContainerRekeyPlan,\n} from \"../../../data/containers/shared/types\";\nimport { readCanonicalRecord } from \"../../../data/keying/canonicalJson\";\nimport {\n type PrincipalPolicyCache,\n type ProjectionUserKeyResolver,\n type ReferencedPrincipalPolicyWarmer,\n requireProjectionUserKeyResolver,\n} from \"../../../data/keyingProjectionVerification\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../../data/principals/principalPolicyEvidence\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport { assertOverrideMatchesSignedLineage } from \"./keyringOverrideLineage\";\nimport {\n sealRotationKeyring,\n verifyKeyringEntriesForSeal,\n} from \"./moveRotation\";\nimport {\n containerMutationRequestCore,\n previousPathRequestFields,\n readCanonicalRecordOrNull,\n} from \"./mutationRequestCore\";\nimport {\n containerWriterProjectionFromRekeyPlan,\n isSpeculativeContainerWriterProjection,\n} from \"./rekeyProjection\";\nimport {\n resolveRotationContext,\n type SignedRotationTarget,\n} from \"./rotationContext\";\nimport { collectContainerRevokePrincipalPolicies } from \"./rotationPrincipalPolicies\";\nimport { buildContainerRotationWraps } from \"./rotationWraps\";\nimport {\n refreshedPrincipalPolicies,\n refreshedPrincipalReferences,\n} from \"./sharePlanCore\";\n\nasync function buildRekeyRotationArtifacts(input: {\n containerKey: Uint8Array;\n keyringEntriesOverride: readonly ContainerKekKeyringEntry[] | undefined;\n nextContainerKeyEpoch: number;\n predecessorContainerKey: Uint8Array;\n previousContainerId: string;\n target: SignedRotationTarget;\n}): Promise<{\n containerKeyEpochId: string;\n keyring: ContainerKekKeyring;\n predecessorBridge: Awaited<\n ReturnType<typeof createContainerKekPredecessorBridge>\n >;\n}> {\n const containerKeyEpochId = await resolveContainerKekEpochId({\n containerId: input.previousContainerId,\n keyEpoch: input.nextContainerKeyEpoch,\n keyMaterial: input.containerKey,\n });\n const predecessorBridge = await createContainerKekPredecessorBridge({\n containerId: input.previousContainerId,\n predecessorContainerKey: input.predecessorContainerKey,\n predecessorContainerKeyEpochId: input.target.kek.containerKeyEpochId,\n successorContainerKey: input.containerKey,\n successorContainerKeyEpochId: containerKeyEpochId,\n });\n if (input.keyringEntriesOverride) {\n // A rebuilt override still has to agree with the epochs the projection's\n // signed history commits to; otherwise a repair could seal a forgery.\n // Exact match first, for distinct errors; the seal check below then adds\n // only the per-entry material check for an override.\n assertOverrideMatchesSignedLineage(\n input.keyringEntriesOverride,\n input.target.signedEpochIds,\n );\n await verifyKeyringEntriesForSeal(\n input.previousContainerId,\n input.keyringEntriesOverride,\n input.target.signedEpochIds,\n );\n }\n const keyring: ContainerKekKeyring = input.keyringEntriesOverride\n ? await sealContainerKekKeyring({\n containerId: input.previousContainerId,\n entries: [\n ...input.keyringEntriesOverride,\n {\n containerKeyEpochId: input.target.kek.containerKeyEpochId,\n keyMaterial: input.predecessorContainerKey,\n },\n ],\n keyEpoch: input.nextContainerKeyEpoch,\n successorContainerKey: input.containerKey,\n successorContainerKeyEpochId: containerKeyEpochId,\n })\n : await sealRotationKeyring({\n containerId: input.previousContainerId,\n currentKek: input.target.kek,\n currentKeyMaterial: input.predecessorContainerKey,\n keyEpoch: input.nextContainerKeyEpoch,\n signedEpochIds: input.target.signedEpochIds,\n successorContainerKey: input.containerKey,\n successorContainerKeyEpochId: containerKeyEpochId,\n });\n return { containerKeyEpochId, keyring, predecessorBridge };\n}\n\nasync function deriveRekeyManifestArtifacts(input: {\n containerKey: Uint8Array;\n author: ContainerMutationAuthor;\n containerKeyEpochId: string;\n eventId: string | undefined;\n keyring: ContainerKekKeyring;\n parentKek: ReturnType<typeof getParentKekForTarget>;\n predecessorBridge: Awaited<\n ReturnType<typeof createContainerKekPredecessorBridge>\n >;\n previousProjection: ContainerWriterProjectionResponse;\n previousState: ReturnType<typeof readContainerState>;\n referencedPrincipalHeads: readonly ContainerGrantPrincipalHead[];\n signedAt: string | undefined;\n target: ReturnType<typeof getTargetContainerContext>;\n}) {\n const body: ContainerRekeyAccessEventBody = {\n eventType: \"container.rekey\",\n parentManifestHash:\n input.previousProjection.path.at(-2)?.manifestHash ?? null,\n containerKeyPublicKey: await deriveContainerKekWrappingPublicKey({\n containerId: input.previousState.containerId,\n keyMaterial: input.containerKey,\n }),\n containerKeyEpochId: input.containerKeyEpochId,\n keyringHash: await computeContainerKekKeyringHash(input.keyring),\n predecessorBridgeHash: await computeContainerKekPredecessorBridgeHash(\n input.predecessorBridge,\n ),\n referencedPrincipalHeads: [...input.referencedPrincipalHeads],\n };\n const { event, eventHash } = await signContainerMutationEvent({\n author: input.author,\n body,\n containerId: input.previousState.containerId,\n dependencyManifestHashes: uniqueSortedManifestHashes(\n input.previousProjection.path,\n ),\n eventId: input.eventId ?? crypto.randomUUID(),\n previousManifestHash: input.target.manifest.manifestHash,\n signedAt: input.signedAt ?? new Date().toISOString(),\n });\n const state = {\n ...input.previousState,\n parentManifestHash: body.parentManifestHash,\n containerKeyPublicKey: body.containerKeyPublicKey,\n epoch: input.previousState.epoch + 1,\n previousManifestHash: input.target.manifest.manifestHash,\n eventHash,\n containerKeyEpochId: input.containerKeyEpochId,\n referencedPrincipalHeads: [...input.referencedPrincipalHeads],\n };\n const manifest = await deriveContainerAccessManifest(state);\n const manifestHash = await computeAccessManifestHash(manifest);\n const keyEpoch = buildContainerCreateKeyEpoch({\n containerId: input.previousState.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n eventHash,\n keyEpoch: input.target.kek.containerKeyEpoch + 1,\n manifestHash,\n parentContainerKeyEpochId: input.parentKek?.containerKeyEpochId ?? null,\n });\n return { body, event, eventHash, keyEpoch, manifest, manifestHash, state };\n}\n\n/**\n * An explicit container KEK rotation with no membership change. Doubles as\n * the repair operation: passing `keyringEntriesOverride` seals a keyring\n * rebuilt from the bridge log instead of re-opening the served one, so a\n * poisoned snapshot is replaced by ground truth.\n */\ninterface RekeyPlanInput {\n author: ContainerMutationAuthor;\n eventId?: string | undefined;\n execSql: ExecSql;\n keyringEntriesOverride?: readonly ContainerKekKeyringEntry[] | undefined;\n /** Keys a batch minted above this container and has yet to commit. */\n knownContainerKeks?: ReadonlyMap<string, Uint8Array> | undefined;\n persistVerificationCheckpoints?: boolean | undefined;\n previousProjection: ContainerWriterProjectionResponse;\n /** Verified policies the path may cite before they are stored locally. */\n principalPolicyCache?: PrincipalPolicyCache | undefined;\n replacementPrincipalPolicy?: PrincipalPolicyCurrentEvidence | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n targetSecretKey: Uint8Array;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}\n\nfunction speculativeSafeRekeyInput(input: RekeyPlanInput): RekeyPlanInput {\n return isSpeculativeContainerWriterProjection(input.previousProjection)\n ? { ...input, persistVerificationCheckpoints: false }\n : input;\n}\n\nasync function collectRekeyPrincipalPolicies(\n input: RekeyPlanInput,\n resolveUserKey: ProjectionUserKeyResolver,\n): Promise<PrincipalPolicyCurrentEvidence[]> {\n const previousPolicies = await collectContainerRevokePrincipalPolicies({\n execSql: input.execSql,\n persistVerificationCheckpoints: input.persistVerificationCheckpoints,\n previousProjection: input.previousProjection,\n principalPolicyCache: input.principalPolicyCache,\n resolveUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n const principalPolicies = refreshedPrincipalPolicies({\n previousPolicies,\n replacementPrincipalPolicy: input.replacementPrincipalPolicy,\n });\n assertContainerAuthorAccess({\n author: input.author,\n projection: input.previousProjection,\n principalPolicies,\n minimumAccess: \"write\",\n });\n return principalPolicies;\n}\n\nexport async function buildMaterializedContainerRekeyPlan(\n input: RekeyPlanInput,\n): Promise<MaterializedContainerRekeyPlan> {\n const resolveProjectionUserKey = requireProjectionUserKeyResolver(\n input.resolveProjectionUserKey,\n \"Remote container rekey\",\n );\n const planningInput = speculativeSafeRekeyInput(input);\n const containerKey = crypto.getRandomValues(new Uint8Array(32));\n const {\n parentKek,\n parentPublicKey,\n predecessorContainerKey,\n previousState,\n target,\n } = await resolveRotationContext(planningInput, \"rekey\");\n const { containerKeyEpochId, keyring, predecessorBridge } =\n await buildRekeyRotationArtifacts({\n containerKey,\n keyringEntriesOverride: input.keyringEntriesOverride,\n nextContainerKeyEpoch: target.kek.containerKeyEpoch + 1,\n predecessorContainerKey,\n previousContainerId: previousState.containerId,\n target,\n });\n const principalPolicies = await collectRekeyPrincipalPolicies(\n planningInput,\n resolveProjectionUserKey,\n );\n\n const referencedPrincipalHeads = refreshedPrincipalReferences({\n previousState,\n replacementPrincipalPolicy: input.replacementPrincipalPolicy,\n });\n const { body, event, eventHash, keyEpoch, manifest, manifestHash, state } =\n await deriveRekeyManifestArtifacts({\n containerKey,\n author: input.author,\n containerKeyEpochId,\n eventId: input.eventId,\n keyring,\n parentKek,\n predecessorBridge,\n previousProjection: input.previousProjection,\n previousState,\n referencedPrincipalHeads,\n signedAt: input.signedAt,\n target,\n });\n const { userRecipientKeys, wraps } = await buildContainerRotationWraps({\n containerKey,\n containerKeyEpochId,\n manifestHash,\n operationLabel: \"Container rekey\",\n parentKek,\n parentPublicKey,\n principalPolicies,\n resolveUserKey: resolveProjectionUserKey,\n state,\n });\n\n const plan = buildContainerRekeyPlan({\n body,\n containerId: previousState.containerId,\n containerKeyEpochId,\n event,\n eventHash,\n keyEpoch,\n keyring,\n manifest,\n manifestHash,\n parentKek,\n predecessorBridge,\n previousManifest: asContainerManifestBundle(target.manifest),\n previousProjection: input.previousProjection,\n principalPolicies,\n state,\n userRecipientKeys,\n wraps,\n });\n const materializedPlan = { containerKey, plan };\n return {\n ...materializedPlan,\n writerProjection: await containerWriterProjectionFromRekeyPlan({\n materializedPlan,\n previousProjection: input.previousProjection,\n }),\n };\n}\n\nfunction buildContainerRekeyPlan(input: {\n body: ContainerRekeyAccessEventBody;\n containerId: string;\n containerKeyEpochId: string;\n event: ContainerRekeyPlan[\"event\"];\n eventHash: string;\n keyEpoch: ContainerRekeyPlan[\"keyEpoch\"];\n keyring: ContainerKekKeyring;\n manifest: ContainerRekeyPlan[\"manifest\"];\n manifestHash: string;\n parentKek: ReturnType<typeof getParentKekForTarget>;\n predecessorBridge: Awaited<\n ReturnType<typeof createContainerKekPredecessorBridge>\n >;\n previousManifest: ContainerRekeyPlan[\"previousManifest\"];\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n state: ContainerRekeyPlan[\"state\"];\n userRecipientKeys: ContainerRekeyPlan[\"userRecipientKeys\"];\n wraps: ContainerRekeyPlan[\"wraps\"];\n}): ContainerRekeyPlan {\n return {\n body: input.body,\n containerId: input.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n event: input.event,\n eventHash: input.eventHash,\n keyEpoch: input.keyEpoch,\n keyring: input.keyring,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n previousManifest: input.previousManifest,\n request: {\n ...containerMutationRequestCore(\"rekey\", input),\n ...previousPathRequestFields(\n input.previousManifest,\n input.previousProjection,\n ),\n predecessorBridge: readCanonicalRecord(\n input.predecessorBridge,\n \"Container rekey predecessor bridge\",\n ),\n keyring: readCanonicalRecord(input.keyring, \"Container rekey keyring\"),\n parentKekState: readCanonicalRecordOrNull(\n input.parentKek,\n \"Container rekey parent KEK state\",\n ),\n },\n state: input.state,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n };\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { computeContainerKekRecipientTargetHash, computeContainerKeyEpochHash, } from "../../../internal/crypto/index.js";
2
- import { canonicalKeyingJsonString, readCanonicalRecord, readCanonicalRecords, } from "../../../data/keyingCanonicalJson.js";
2
+ import { canonicalKeyingJsonString, readCanonicalRecord, readCanonicalRecords, } from "../../../data/keying/canonicalJson.js";
3
3
  import { mergeProjectionPolicyEvidence } from "../../../data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js";
4
4
  const speculativeProjections = new WeakSet();
5
5
  export function isSpeculativeContainerWriterProjection(projection) {
@@ -1 +1 @@
1
- {"version":3,"file":"rekeyProjection.js","sourceRoot":"","sources":["rekeyProjection.ts"],"names":[],"mapp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ContainerKekRecipientTarget,\n computeContainerKekRecipientTargetHash,\n computeContainerKeyEpochHash,\n} from \"@tearleads/crypto\";\nimport type { ContainerWriterProjectionResponse } from \"@tearleads/validators/response\";\nimport type {\n MaterializedContainerRekeyPlan,\n MaterializedContainerSharePlan,\n} from \"../../../data/containers/shared/types\";\nimport {\n canonicalKeyingJsonString,\n readCanonicalRecord,\n readCanonicalRecords,\n} from \"../../../data/keyingCanonicalJson\";\nimport { mergeProjectionPolicyEvidence } from \"../../../data/keyingProjectionVerification/mergeProjectionPolicyEvidence\";\n\nconst speculativeProjections = new WeakSet<ContainerWriterProjectionResponse>();\n\nexport function isSpeculativeContainerWriterProjection(\n projection: ContainerWriterProjectionResponse,\n): boolean {\n return speculativeProjections.has(projection);\n}\n\n/**\n * What any rotation plan (rekey, revoke, move) holds in common: enough to say\n * what its container's path entry will be once the server accepts it.\n */\nexport interface RotationPlanArtifacts {\n readonly body: object;\n readonly containerId: string;\n readonly containerKeyEpochId: string;\n readonly event: MaterializedContainerRekeyPlan[\"plan\"][\"event\"];\n readonly eventHash: string;\n readonly keyEpoch: MaterializedContainerRekeyPlan[\"plan\"][\"keyEpoch\"];\n readonly manifest: MaterializedContainerRekeyPlan[\"plan\"][\"manifest\"];\n readonly manifestHash: string;\n readonly previousManifest: MaterializedContainerRekeyPlan[\"plan\"][\"previousManifest\"];\n readonly keyring: MaterializedContainerRekeyPlan[\"plan\"][\"keyring\"];\n readonly state: MaterializedContainerRekeyPlan[\"plan\"][\"state\"];\n readonly wraps: MaterializedContainerRekeyPlan[\"plan\"][\"wraps\"];\n}\n\nfunction recipientTargets(\n plan: Pick<RotationPlanArtifacts, \"wraps\">,\n): ContainerKekRecipientTarget[] {\n return plan.wraps\n .map((wrap) => ({\n recipientId: wrap.recipientId,\n recipientKeyEpochId: wrap.recipientKeyEpochId,\n recipientKeyFingerprint: wrap.recipientKeyFingerprint,\n recipientKind: wrap.recipientKind,\n }))\n .sort((left, right) =>\n canonicalKeyingJsonString(\n left,\n \"Container rekey recipient\",\n ).localeCompare(\n canonicalKeyingJsonString(right, \"Container rekey recipient\"),\n ),\n );\n}\n\n/**\n * The projection a rotation will leave behind, before the server has accepted\n * it. `ancestors` is the path above the container afterwards: unchanged for a\n * rekey or revoke, the destination parent's path for a move.\n */\nexport async function containerWriterProjectionFromRotationPlan(input: {\n ancestors?: Pick<\n ContainerWriterProjectionResponse,\n \"containerKeks\" | \"path\" | \"policyEvidence\"\n >;\n plan: RotationPlanArtifacts;\n previousProjection: ContainerWriterProjectionResponse;\n}): Promise<ContainerWriterProjectionResponse> {\n const { plan } = input;\n const previousManifest = input.previousProjection.path.at(-1);\n const previousKek = input.previousProjection.containerKeks.at(-1);\n if (\n !previousManifest ||\n !previousKek ||\n previousManifest.manifestHash !== plan.previousManifest.manifestHash ||\n previousKek.containerId !== plan.containerId\n ) {\n throw new Error(\"Container rekey projection predecessor mismatch\");\n }\n const targets = recipientTargets(plan);\n const nextManifest = {\n event: {\n body: readCanonicalRecord(plan.body, \"Container rekey body\"),\n event: readCanonicalRecord(plan.event, \"Container rekey event\"),\n eventHash: plan.eventHash,\n },\n manifest: readCanonicalRecord(plan.manifest, \"Container rekey manifest\"),\n manifestHash: plan.manifestHash,\n state: readCanonicalRecord(plan.state, \"Container rekey state\"),\n };\n const nextKek = {\n accessManifestHash: plan.manifestHash,\n containerId: plan.containerId,\n containerKeyEpoch: plan.keyEpoch.keyEpoch,\n containerKeyEpochId: plan.containerKeyEpochId,\n containerManifestHistory: [\n previousManifest,\n ...previousKek.containerManifestHistory,\n ],\n keyEpoch: readCanonicalRecord(plan.keyEpoch, \"Container rekey key epoch\"),\n keyEpochHash: await computeContainerKeyEpochHash(plan.keyEpoch),\n keyring: { ...plan.keyring },\n keyTargetHash: await computeContainerKekRecipientTargetHash(targets),\n parentContainerKeyEpochId: plan.keyEpoch.parentContainerKeyEpochId,\n recipientTargets: readCanonicalRecords(\n targets,\n \"Container rekey recipient targets\",\n ),\n wraps: readCanonicalRecords(plan.wraps, \"Container rekey wraps\"),\n };\n const ancestors = input.ancestors ?? {\n containerKeks: input.previousProjection.containerKeks.slice(0, -1),\n path: input.previousProjection.path.slice(0, -1),\n };\n const projection = {\n ...input.previousProjection,\n policyEvidence: mergeProjectionPolicyEvidence([\n input.previousProjection.policyEvidence,\n ...(input.ancestors ? [input.ancestors.policyEvidence] : []),\n ]),\n path: [...ancestors.path, nextManifest],\n containerKeks: [...ancestors.containerKeks, nextKek],\n };\n speculativeProjections.add(projection);\n return projection;\n}\n\nexport function containerWriterProjectionFromRekeyPlan(input: {\n materializedPlan: Pick<\n MaterializedContainerRekeyPlan,\n \"containerKey\" | \"plan\"\n >;\n previousProjection: ContainerWriterProjectionResponse;\n}): Promise<ContainerWriterProjectionResponse> {\n return containerWriterProjectionFromRotationPlan({\n plan: input.materializedPlan.plan,\n previousProjection: input.previousProjection,\n });\n}\n\n/**\n * A descendant's served projection, re-rooted on rotations the server has not\n * accepted yet: `rotated` replaces the path down to and including its own\n * container. Null when the descendant does not sit below that container.\n */\nexport function rebaseContainerWriterProjection(\n descendant: ContainerWriterProjectionResponse,\n rotated: Pick<\n ContainerWriterProjectionResponse,\n \"containerKeks\" | \"path\" | \"policyEvidence\"\n >,\n): ContainerWriterProjectionResponse | null {\n const rotatedId = rotated.containerKeks.at(-1)?.containerId;\n const index = descendant.containerKeks.findIndex(\n (kek) => kek.containerId === rotatedId,\n );\n if (rotatedId === undefined || index < 0) return null;\n if (index === descendant.containerKeks.length - 1) return null;\n const projection = {\n ...descendant,\n policyEvidence: mergeProjectionPolicyEvidence([\n descendant.policyEvidence,\n rotated.policyEvidence,\n ]),\n path: [...rotated.path, ...descendant.path.slice(index + 1)],\n containerKeks: [\n ...rotated.containerKeks,\n ...descendant.containerKeks.slice(index + 1),\n ],\n };\n speculativeProjections.add(projection);\n return projection;\n}\n\n/** A grant keeps its key epoch while advancing the manifest and recipient wraps. */\nexport async function containerWriterProjectionFromSharePlan(input: {\n plan: MaterializedContainerSharePlan[\"plan\"];\n previousProjection: ContainerWriterProjectionResponse;\n}): Promise<ContainerWriterProjectionResponse> {\n const { plan, previousProjection } = input;\n const previous = previousProjection.path.at(-1);\n const kek = previousProjection.containerKeks.at(-1);\n if (\n !previous ||\n !kek ||\n previous.manifestHash !== plan.previousManifest.manifestHash ||\n kek.containerId !== plan.containerId\n )\n throw new Error(\"Container grant projection predecessor mismatch\");\n const targets = recipientTargets({ wraps: plan.wraps });\n const projection = {\n ...previousProjection,\n path: [\n ...previousProjection.path.slice(0, -1),\n {\n event: {\n body: readCanonicalRecord(plan.body, \"Container grant body\"),\n event: readCanonicalRecord(plan.event, \"Container grant event\"),\n eventHash: plan.eventHash,\n },\n manifest: readCanonicalRecord(\n plan.manifest,\n \"Container grant manifest\",\n ),\n manifestHash: plan.manifestHash,\n state: readCanonicalRecord(plan.state, \"Container grant state\"),\n },\n ],\n containerKeks: [\n ...previousProjection.containerKeks.slice(0, -1),\n {\n ...kek,\n accessManifestHash: plan.manifestHash,\n containerManifestHistory: [previous, ...kek.containerManifestHistory],\n keyTargetHash: await computeContainerKekRecipientTargetHash(targets),\n recipientTargets: readCanonicalRecords(\n targets,\n \"Container grant targets\",\n ),\n wraps: readCanonicalRecords(plan.wraps, \"Container grant wraps\"),\n },\n ],\n };\n speculativeProjections.add(projection);\n return projection;\n}\n"]}
1
+ {"version":3,"file":"rekeyProjection.js","sourceRoot":"","sources":["rekeyProjection.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sCAAsC,EACtC,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,0EAA0E,CAAC;AAEzH,MAAM,sBAAsB,GAAG,IAAI,OAAO,EAAqC,CAAC;AAEhF,MAAM,UAAU,sCAAsC,CACpD,UAA6C;IAE7C,OAAO,sBAAsB,CAAC,GAAG,C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,IAAI,CAAC,IAAI,EAAE,sBAAsB,CAAC;oBAC5D,KAAK,EAAE,mBAAmB,CAAC,IAAI,CAAC,KAAK,EAAE,uBAAuB,CAAC;oBAC/D,SAAS,EAAE,IAAI,CAAC,SAAS;iBAC1B;gBACD,QAAQ,EAAE,mBAAmB,CAC3B,IAAI,CAAC,QAAQ,EACb,0BAA0B,CAC3B;gBACD,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,KAAK,EAAE,mBAAmB,CAAC,IAAI,CAAC,KAAK,EAAE,uBAAuB,CAAC;aAChE;SACF;QACD,aAAa,EAAE;YACb,GAAG,kBAAkB,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAChD;gBACE,GAAG,GAAG;gBACN,kBAAkB,EAAE,IAAI,CAAC,YAAY;gBACrC,wBAAwB,EAAE,CAAC,QAAQ,EAAE,GAAG,GAAG,CAAC,wBAAwB,CAAC;gBACrE,aAAa,EAAE,MAAM,sCAAsC,CAAC,OAAO,CAAC;gBACpE,gBAAgB,EAAE,oBAAoB,CACpC,OAAO,EACP,yBAAyB,CAC1B;gBACD,KAAK,EAAE,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,uBAAuB,CAAC;aACjE;SACF;KACF,CAAC;IACF,sBAAsB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACvC,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import {\n type ContainerKekRecipientTarget,\n computeContainerKekRecipientTargetHash,\n computeContainerKeyEpochHash,\n} from \"@tearleads/crypto\";\nimport type { ContainerWriterProjectionResponse } from \"@tearleads/validators/response\";\nimport type {\n MaterializedContainerRekeyPlan,\n MaterializedContainerSharePlan,\n} from \"../../../data/containers/shared/types\";\nimport {\n canonicalKeyingJsonString,\n readCanonicalRecord,\n readCanonicalRecords,\n} from \"../../../data/keying/canonicalJson\";\nimport { mergeProjectionPolicyEvidence } from \"../../../data/keyingProjectionVerification/mergeProjectionPolicyEvidence\";\n\nconst speculativeProjections = new WeakSet<ContainerWriterProjectionResponse>();\n\nexport function isSpeculativeContainerWriterProjection(\n projection: ContainerWriterProjectionResponse,\n): boolean {\n return speculativeProjections.has(projection);\n}\n\n/**\n * What any rotation plan (rekey, revoke, move) holds in common: enough to say\n * what its container's path entry will be once the server accepts it.\n */\nexport interface RotationPlanArtifacts {\n readonly body: object;\n readonly containerId: string;\n readonly containerKeyEpochId: string;\n readonly event: MaterializedContainerRekeyPlan[\"plan\"][\"event\"];\n readonly eventHash: string;\n readonly keyEpoch: MaterializedContainerRekeyPlan[\"plan\"][\"keyEpoch\"];\n readonly manifest: MaterializedContainerRekeyPlan[\"plan\"][\"manifest\"];\n readonly manifestHash: string;\n readonly previousManifest: MaterializedContainerRekeyPlan[\"plan\"][\"previousManifest\"];\n readonly keyring: MaterializedContainerRekeyPlan[\"plan\"][\"keyring\"];\n readonly state: MaterializedContainerRekeyPlan[\"plan\"][\"state\"];\n readonly wraps: MaterializedContainerRekeyPlan[\"plan\"][\"wraps\"];\n}\n\nfunction recipientTargets(\n plan: Pick<RotationPlanArtifacts, \"wraps\">,\n): ContainerKekRecipientTarget[] {\n return plan.wraps\n .map((wrap) => ({\n recipientId: wrap.recipientId,\n recipientKeyEpochId: wrap.recipientKeyEpochId,\n recipientKeyFingerprint: wrap.recipientKeyFingerprint,\n recipientKind: wrap.recipientKind,\n }))\n .sort((left, right) =>\n canonicalKeyingJsonString(\n left,\n \"Container rekey recipient\",\n ).localeCompare(\n canonicalKeyingJsonString(right, \"Container rekey recipient\"),\n ),\n );\n}\n\n/**\n * The projection a rotation will leave behind, before the server has accepted\n * it. `ancestors` is the path above the container afterwards: unchanged for a\n * rekey or revoke, the destination parent's path for a move.\n */\nexport async function containerWriterProjectionFromRotationPlan(input: {\n ancestors?: Pick<\n ContainerWriterProjectionResponse,\n \"containerKeks\" | \"path\" | \"policyEvidence\"\n >;\n plan: RotationPlanArtifacts;\n previousProjection: ContainerWriterProjectionResponse;\n}): Promise<ContainerWriterProjectionResponse> {\n const { plan } = input;\n const previousManifest = input.previousProjection.path.at(-1);\n const previousKek = input.previousProjection.containerKeks.at(-1);\n if (\n !previousManifest ||\n !previousKek ||\n previousManifest.manifestHash !== plan.previousManifest.manifestHash ||\n previousKek.containerId !== plan.containerId\n ) {\n throw new Error(\"Container rekey projection predecessor mismatch\");\n }\n const targets = recipientTargets(plan);\n const nextManifest = {\n event: {\n body: readCanonicalRecord(plan.body, \"Container rekey body\"),\n event: readCanonicalRecord(plan.event, \"Container rekey event\"),\n eventHash: plan.eventHash,\n },\n manifest: readCanonicalRecord(plan.manifest, \"Container rekey manifest\"),\n manifestHash: plan.manifestHash,\n state: readCanonicalRecord(plan.state, \"Container rekey state\"),\n };\n const nextKek = {\n accessManifestHash: plan.manifestHash,\n containerId: plan.containerId,\n containerKeyEpoch: plan.keyEpoch.keyEpoch,\n containerKeyEpochId: plan.containerKeyEpochId,\n containerManifestHistory: [\n previousManifest,\n ...previousKek.containerManifestHistory,\n ],\n keyEpoch: readCanonicalRecord(plan.keyEpoch, \"Container rekey key epoch\"),\n keyEpochHash: await computeContainerKeyEpochHash(plan.keyEpoch),\n keyring: { ...plan.keyring },\n keyTargetHash: await computeContainerKekRecipientTargetHash(targets),\n parentContainerKeyEpochId: plan.keyEpoch.parentContainerKeyEpochId,\n recipientTargets: readCanonicalRecords(\n targets,\n \"Container rekey recipient targets\",\n ),\n wraps: readCanonicalRecords(plan.wraps, \"Container rekey wraps\"),\n };\n const ancestors = input.ancestors ?? {\n containerKeks: input.previousProjection.containerKeks.slice(0, -1),\n path: input.previousProjection.path.slice(0, -1),\n };\n const projection = {\n ...input.previousProjection,\n policyEvidence: mergeProjectionPolicyEvidence([\n input.previousProjection.policyEvidence,\n ...(input.ancestors ? [input.ancestors.policyEvidence] : []),\n ]),\n path: [...ancestors.path, nextManifest],\n containerKeks: [...ancestors.containerKeks, nextKek],\n };\n speculativeProjections.add(projection);\n return projection;\n}\n\nexport function containerWriterProjectionFromRekeyPlan(input: {\n materializedPlan: Pick<\n MaterializedContainerRekeyPlan,\n \"containerKey\" | \"plan\"\n >;\n previousProjection: ContainerWriterProjectionResponse;\n}): Promise<ContainerWriterProjectionResponse> {\n return containerWriterProjectionFromRotationPlan({\n plan: input.materializedPlan.plan,\n previousProjection: input.previousProjection,\n });\n}\n\n/**\n * A descendant's served projection, re-rooted on rotations the server has not\n * accepted yet: `rotated` replaces the path down to and including its own\n * container. Null when the descendant does not sit below that container.\n */\nexport function rebaseContainerWriterProjection(\n descendant: ContainerWriterProjectionResponse,\n rotated: Pick<\n ContainerWriterProjectionResponse,\n \"containerKeks\" | \"path\" | \"policyEvidence\"\n >,\n): ContainerWriterProjectionResponse | null {\n const rotatedId = rotated.containerKeks.at(-1)?.containerId;\n const index = descendant.containerKeks.findIndex(\n (kek) => kek.containerId === rotatedId,\n );\n if (rotatedId === undefined || index < 0) return null;\n if (index === descendant.containerKeks.length - 1) return null;\n const projection = {\n ...descendant,\n policyEvidence: mergeProjectionPolicyEvidence([\n descendant.policyEvidence,\n rotated.policyEvidence,\n ]),\n path: [...rotated.path, ...descendant.path.slice(index + 1)],\n containerKeks: [\n ...rotated.containerKeks,\n ...descendant.containerKeks.slice(index + 1),\n ],\n };\n speculativeProjections.add(projection);\n return projection;\n}\n\n/** A grant keeps its key epoch while advancing the manifest and recipient wraps. */\nexport async function containerWriterProjectionFromSharePlan(input: {\n plan: MaterializedContainerSharePlan[\"plan\"];\n previousProjection: ContainerWriterProjectionResponse;\n}): Promise<ContainerWriterProjectionResponse> {\n const { plan, previousProjection } = input;\n const previous = previousProjection.path.at(-1);\n const kek = previousProjection.containerKeks.at(-1);\n if (\n !previous ||\n !kek ||\n previous.manifestHash !== plan.previousManifest.manifestHash ||\n kek.containerId !== plan.containerId\n )\n throw new Error(\"Container grant projection predecessor mismatch\");\n const targets = recipientTargets({ wraps: plan.wraps });\n const projection = {\n ...previousProjection,\n path: [\n ...previousProjection.path.slice(0, -1),\n {\n event: {\n body: readCanonicalRecord(plan.body, \"Container grant body\"),\n event: readCanonicalRecord(plan.event, \"Container grant event\"),\n eventHash: plan.eventHash,\n },\n manifest: readCanonicalRecord(\n plan.manifest,\n \"Container grant manifest\",\n ),\n manifestHash: plan.manifestHash,\n state: readCanonicalRecord(plan.state, \"Container grant state\"),\n },\n ],\n containerKeks: [\n ...previousProjection.containerKeks.slice(0, -1),\n {\n ...kek,\n accessManifestHash: plan.manifestHash,\n containerManifestHistory: [previous, ...kek.containerManifestHistory],\n keyTargetHash: await computeContainerKekRecipientTargetHash(targets),\n recipientTargets: readCanonicalRecords(\n targets,\n \"Container grant targets\",\n ),\n wraps: readCanonicalRecords(plan.wraps, \"Container grant wraps\"),\n },\n ],\n };\n speculativeProjections.add(projection);\n return projection;\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import type { ContainerKekKeyringEntry } from "../../../internal/crypto/index.js";
2
2
  import type { ContainerRotationResponse } from "../../../internal/validators/response/index.js";
3
3
  import type { ContainerMutationAuthor, ContainerRekeyApi, ContainerRekeyPlan } from "../../../data/containers/shared/types.js";
4
- import type { ProjectionUserKeyResolver, ReferencedPrincipalPolicyWarmer } from "../../../data/keyingProjectionVerification.js";
5
- import type { SecurityIncidentReporter } from "../../../data/securityIncidents.js";
4
+ import type { ProjectionUserKeyResolver, ReferencedPrincipalPolicyWarmer } from "../../../data/keyingProjectionVerification/index.js";
5
+ import type { SecurityIncidentReporter } from "../../../data/shared/securityIncidents.js";
6
6
  import type { ExecSql } from "../../../data/sqlite/sqlSchema.js";
7
7
  export declare function rekeyRemoteContainer(input: {
8
8
  reportSecurityIncident: SecurityIncidentReporter;
@@ -1 +1 @@
1
- {"version":3,"file":"rekeyRemote.js","sourceRoot":"","sources":["rekeyRemote.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,mCAAmC,EACnC,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AAE9D,MAAM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AC,+BAA+B;aACvE;YACD,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,gBAAgB,CAAC,gBAAgB;SACvD;QACD,YAAY,EAAE,gBAAgB,CAAC,YAAY;QAC3C,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,gBAAgB,CAAC,IAAI;QAC3B,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;YAClB,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM;gBAC5B,CAAC,CAAC,EAAE,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE;gBACrE,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC;YAClC,MAAM,OAAO,GAAG;gBACd,qCAAqC,EAAE,KAAK,CAAC,MAAM,CAAC,cAAc;aACnE,CAAC;YACF,MAAM,EAAE,oBAAoB,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;YACjD,OAAO,uBAAuB,CAAC;gBAC7B,KAAK,EAAE,GAAG,EAAE,CACV,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC;gBACrE,MAAM,EAAE,oBAAoB;oBAC1B,CAAC,CAAC,GAAG,EAAE,CACH,oBAAoB,CAAC,IAAI,CACvB,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,WAAW,EACjB,OAAO,EACP,EAAE,GAAG,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CACpC;oBACL,CAAC,CAAC,SAAS;aACd,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ContainerKekKeyringEntry } from \"@tearleads/crypto\";\nimport type { ContainerRotationResponse } from \"@tearleads/validators/response\";\nimport type {\n ContainerMutationAuthor,\n ContainerRekeyApi,\n ContainerRekeyPlan,\n} from \"../../../data/containers/shared/types\";\nimport type {\n ProjectionUserKeyResolver,\n ReferencedPrincipalPolicyWarmer,\n} from \"../../../data/keyingProjectionVerification\";\nimport type { SecurityIncidentReporter } from \"../../../data/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n submitAcknowledgedContainerMutation,\n submitContainerRotation,\n} from \"./mutationSubmit\";\nimport { buildMaterializedContainerRekeyPlan } from \"./rekey\";\n\nexport async function rekeyRemoteContainer(input: {\n reportSecurityIncident: SecurityIncidentReporter;\n apiClient: ContainerRekeyApi;\n author: ContainerMutationAuthor;\n containerId: string;\n eventId?: string | undefined;\n execSql: ExecSql;\n keyringEntriesOverride?: readonly ContainerKekKeyringEntry[] | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n targetSecretKey: Uint8Array;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<{\n containerKey: Uint8Array;\n plan: ContainerRekeyPlan;\n response: ContainerRotationResponse;\n} | null> {\n const previousProjection = await input.apiClient.getContainerWriterProjection(\n input.containerId,\n );\n if (!previousProjection) {\n return null;\n }\n\n const materializedPlan = await buildMaterializedContainerRekeyPlan({\n author: input.author,\n eventId: input.eventId,\n execSql: input.execSql,\n keyringEntriesOverride: input.keyringEntriesOverride,\n previousProjection,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n signedAt: input.signedAt,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n return submitAcknowledgedContainerMutation({\n reportSecurityIncident: input.reportSecurityIncident,\n recitationPolicies: [],\n apiClient: input.apiClient,\n author: input.author,\n carriedRekeys: {\n planning: {\n apiClient: input.apiClient,\n author: input.author,\n execSql: input.execSql,\n knownContainerKeks: new Map([\n [\n materializedPlan.plan.containerKeyEpochId,\n materializedPlan.containerKey,\n ],\n ]),\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n },\n rotated: async () => materializedPlan.writerProjection,\n },\n containerKey: materializedPlan.containerKey,\n execSql: input.execSql,\n plan: materializedPlan.plan,\n stillCurrent: input.stillCurrent,\n submit: (carried) => {\n const request = carried.length\n ? { ...materializedPlan.plan.request, containerRekeys: [...carried] }\n : materializedPlan.plan.request;\n const options = {\n expectedPaymentRequiredOrganizationId: input.author.organizationId,\n };\n const { rekeyContainerResult } = input.apiClient;\n return submitContainerRotation({\n plain: () =>\n input.apiClient.rekeyContainer(input.containerId, request, options),\n result: rekeyContainerResult\n ? () =>\n rekeyContainerResult.call(\n input.apiClient,\n input.containerId,\n request,\n { ...options, reportErrors: false },\n )\n : undefined,\n });\n },\n });\n}\n"]}
1
+ {"version":3,"file":"rekeyRemote.js","sourceRoot":"","sources":["rekeyRemote.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,mCAAmC,EACnC,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AAE9D,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,KAa1C;IAKC,MAAM,kBAAkB,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,4BAA4B,CAC3E,KAAK,CAAC,WAAW,CAClB,CAAC;IACF,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,gBAAgB,GAAG,MAAM,mCAAmC,CAAC;QACjE,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,sBAAsB,EAAE,KAAK,CAAC,sBAAsB;QACpD,kBAAkB;QAClB,wBAAwB,EAAE,KAAK,CAAC,wBAAwB;QACxD,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AI,CAAC,OAAO,CAAC;YAClC,MAAM,OAAO,GAAG;gBACd,qCAAqC,EAAE,KAAK,CAAC,MAAM,CAAC,cAAc;aACnE,CAAC;YACF,MAAM,EAAE,oBAAoB,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;YACjD,OAAO,uBAAuB,CAAC;gBAC7B,KAAK,EAAE,GAAG,EAAE,CACV,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC;gBACrE,MAAM,EAAE,oBAAoB;oBAC1B,CAAC,CAAC,GAAG,EAAE,CACH,oBAAoB,CAAC,IAAI,CACvB,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,WAAW,EACjB,OAAO,EACP,EAAE,GAAG,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CACpC;oBACL,CAAC,CAAC,SAAS;aACd,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ContainerKekKeyringEntry } from \"@tearleads/crypto\";\nimport type { ContainerRotationResponse } from \"@tearleads/validators/response\";\nimport type {\n ContainerMutationAuthor,\n ContainerRekeyApi,\n ContainerRekeyPlan,\n} from \"../../../data/containers/shared/types\";\nimport type {\n ProjectionUserKeyResolver,\n ReferencedPrincipalPolicyWarmer,\n} from \"../../../data/keyingProjectionVerification\";\nimport type { SecurityIncidentReporter } from \"../../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n submitAcknowledgedContainerMutation,\n submitContainerRotation,\n} from \"./mutationSubmit\";\nimport { buildMaterializedContainerRekeyPlan } from \"./rekey\";\n\nexport async function rekeyRemoteContainer(input: {\n reportSecurityIncident: SecurityIncidentReporter;\n apiClient: ContainerRekeyApi;\n author: ContainerMutationAuthor;\n containerId: string;\n eventId?: string | undefined;\n execSql: ExecSql;\n keyringEntriesOverride?: readonly ContainerKekKeyringEntry[] | undefined;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n targetSecretKey: Uint8Array;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<{\n containerKey: Uint8Array;\n plan: ContainerRekeyPlan;\n response: ContainerRotationResponse;\n} | null> {\n const previousProjection = await input.apiClient.getContainerWriterProjection(\n input.containerId,\n );\n if (!previousProjection) {\n return null;\n }\n\n const materializedPlan = await buildMaterializedContainerRekeyPlan({\n author: input.author,\n eventId: input.eventId,\n execSql: input.execSql,\n keyringEntriesOverride: input.keyringEntriesOverride,\n previousProjection,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n signedAt: input.signedAt,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n return submitAcknowledgedContainerMutation({\n reportSecurityIncident: input.reportSecurityIncident,\n recitationPolicies: [],\n apiClient: input.apiClient,\n author: input.author,\n carriedRekeys: {\n planning: {\n apiClient: input.apiClient,\n author: input.author,\n execSql: input.execSql,\n knownContainerKeks: new Map([\n [\n materializedPlan.plan.containerKeyEpochId,\n materializedPlan.containerKey,\n ],\n ]),\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n },\n rotated: async () => materializedPlan.writerProjection,\n },\n containerKey: materializedPlan.containerKey,\n execSql: input.execSql,\n plan: materializedPlan.plan,\n stillCurrent: input.stillCurrent,\n submit: (carried) => {\n const request = carried.length\n ? { ...materializedPlan.plan.request, containerRekeys: [...carried] }\n : materializedPlan.plan.request;\n const options = {\n expectedPaymentRequiredOrganizationId: input.author.organizationId,\n };\n const { rekeyContainerResult } = input.apiClient;\n return submitContainerRotation({\n plain: () =>\n input.apiClient.rekeyContainer(input.containerId, request, options),\n result: rekeyContainerResult\n ? () =>\n rekeyContainerResult.call(\n input.apiClient,\n input.containerId,\n request,\n { ...options, reportErrors: false },\n )\n : undefined,\n });\n },\n });\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import type { ContainerRotationResponse, ContainerWriterProjectionResponse } from "../../../internal/validators/response/index.js";
2
2
  import type { ContainerMutationAuthor, ContainerRevokeApi, ContainerRevokePlan, MaterializedContainerRevokePlan } from "../../../data/containers/shared/types.js";
3
- import { type PrincipalPolicyCache, type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../data/keyingProjectionVerification.js";
3
+ import { type PrincipalPolicyCache, type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../data/keyingProjectionVerification/index.js";
4
4
  import type { PrincipalPolicyCurrentEvidence } from "../../../data/principals/principalPolicyEvidence.js";
5
- import type { SecurityIncidentReporter } from "../../../data/securityIncidents.js";
5
+ import type { SecurityIncidentReporter } from "../../../data/shared/securityIncidents.js";
6
6
  import type { ExecSql } from "../../../data/sqlite/sqlSchema.js";
7
7
  import { type ContainerRevokeSubject } from "./revokeManifest.js";
8
8
  export declare function buildMaterializedContainerRevokePlan(input: {
@@ -2,8 +2,8 @@ import { computeContainerKekKeyringHash, computeContainerKekPredecessorBridgeHas
2
2
  import { assertContainerAuthorAccess } from "../../../data/containers/shared/authorAccess.js";
3
3
  import { buildContainerCreateKeyEpoch, signContainerMutationEvent, } from "../../../data/containers/shared/events.js";
4
4
  import { asContainerManifestBundle, uniqueSortedManifestHashes, } from "../../../data/containers/shared/projection.js";
5
- import { readCanonicalRecord } from "../../../data/keyingCanonicalJson.js";
6
- import { requireProjectionUserKeyResolver, } from "../../../data/keyingProjectionVerification.js";
5
+ import { readCanonicalRecord } from "../../../data/keying/canonicalJson.js";
6
+ import { requireProjectionUserKeyResolver, } from "../../../data/keyingProjectionVerification/index.js";
7
7
  import { buildContainerRotationArtifacts } from "./moveRotation.js";
8
8
  import { containerMutationRequestCore, previousPathRequestFields, readCanonicalRecordOrNull, } from "./mutationRequestCore.js";
9
9
  import { submitAcknowledgedContainerMutation, submitContainerRotation, } from "./mutationSubmit.js";
@@ -1 +1 @@
1
- {"version":3,"file":"revoke.js","sourceRoot":"","sources":["revoke.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,8BAA8B,EAC9B,wCAAwC,EACxC,mCAAmC,GACpC,MAAM,mBAAmB,CAAC;AAU3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,4CAA4C,CAAC;AAOpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAIL,gCAAgC,GACjC,MAAM,4CAA4C,CAAC;AAIpD,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,mCAAmC,EACnC,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,yCAAyC,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAEL,6BAA6B,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,uCAAuC,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAE9D,SAAS,2BAA2B,CAAC,KAcpC;IACC,OAAO;QACL,GAAG,4BAA4B,CAAC,QAAQ,EAAE,KAAK,CAAC;QAChD,GAAG,yBAAyB,CAC1B,KAAK,CAAC,gBAAgB,EACtB,KAAK,CAAC,kBAAkB,CACzB;QACD,iBAAiB,EAAE,mBAAmB,CACpC,KAAK,CAAC,iB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AK,EAAE,CACpC;oBACL,CAAC,CAAC,SAAS;aACd,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n AccessEvent,\n AccessManifest,\n ContainerAccessManifestState,\n ContainerKekKeyring,\n ContainerKekPredecessorBridge,\n ContainerKeyEpoch,\n ContainerKeyWrap,\n ContainerRevokeAccessEventBody,\n ContainerUserRecipientKey,\n} from \"@tearleads/crypto\";\nimport {\n computeContainerKekKeyringHash,\n computeContainerKekPredecessorBridgeHash,\n deriveContainerKekWrappingPublicKey,\n} from \"@tearleads/crypto\";\nimport type {\n AccessManifestBundleWire,\n ContainerMutationRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerKekResponse,\n ContainerRotationResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { assertContainerAuthorAccess } from \"../../../data/containers/shared/authorAccess\";\nimport {\n buildContainerCreateKeyEpoch,\n signContainerMutationEvent,\n} from \"../../../data/containers/shared/events\";\nimport {\n asContainerManifestBundle,\n uniqueSortedManifestHashes,\n} from \"../../../data/containers/shared/projection\";\nimport type {\n ContainerMutationAuthor,\n ContainerRevokeApi,\n ContainerRevokePlan,\n MaterializedContainerRevokePlan,\n} from \"../../../data/containers/shared/types\";\nimport { readCanonicalRecord } from \"../../../data/keyingCanonicalJson\";\nimport {\n type PrincipalPolicyCache,\n type ProjectionUserKeyResolver,\n type ReferencedPrincipalPolicyWarmer,\n requireProjectionUserKeyResolver,\n} from \"../../../data/keyingProjectionVerification\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../../data/principals/principalPolicyEvidence\";\nimport type { SecurityIncidentReporter } from \"../../../data/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport { buildContainerRotationArtifacts } from \"./moveRotation\";\nimport {\n containerMutationRequestCore,\n previousPathRequestFields,\n readCanonicalRecordOrNull,\n} from \"./mutationRequestCore\";\nimport {\n submitAcknowledgedContainerMutation,\n submitContainerRotation,\n} from \"./mutationSubmit\";\nimport { containerWriterProjectionFromRotationPlan } from \"./rekeyProjection\";\nimport {\n type ContainerRevokeSubject,\n deriveContainerRevokeManifest,\n} from \"./revokeManifest\";\nimport { resolveRotationContext } from \"./rotationContext\";\nimport { collectContainerRevokePrincipalPolicies } from \"./rotationPrincipalPolicies\";\nimport { buildContainerRotationWraps } from \"./rotationWraps\";\n\nfunction buildContainerRevokeRequest(input: {\n body: ContainerRevokeAccessEventBody;\n event: AccessEvent;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n parentKek: ContainerKekResponse | null;\n predecessorBridge: ContainerKekPredecessorBridge;\n previousManifest: AccessManifestBundleWire;\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n userRecipientKeys: readonly ContainerUserRecipientKey[];\n wraps: readonly ContainerKeyWrap[];\n}): ContainerMutationRequest {\n return {\n ...containerMutationRequestCore(\"revoke\", input),\n ...previousPathRequestFields(\n input.previousManifest,\n input.previousProjection,\n ),\n predecessorBridge: readCanonicalRecord(\n input.predecessorBridge,\n \"Container revoke predecessor bridge\",\n ),\n keyring: readCanonicalRecord(input.keyring, \"Container revoke keyring\"),\n parentKekState: readCanonicalRecordOrNull(\n input.parentKek,\n \"Container revoke parent KEK state\",\n ),\n };\n}\n\nfunction buildContainerRevokePlanResult(input: {\n body: ContainerRevokeAccessEventBody;\n containerId: string;\n containerKey: Uint8Array;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n parentKek: ContainerKekResponse | null;\n predecessorBridge: ContainerKekPredecessorBridge;\n previousManifest: AccessManifestBundleWire;\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n state: ContainerAccessManifestState;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}): MaterializedContainerRevokePlan {\n const plan: ContainerRevokePlan = {\n body: input.body,\n containerId: input.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n event: input.event,\n eventHash: input.eventHash,\n keyEpoch: input.keyEpoch,\n keyring: input.keyring,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n previousManifest: input.previousManifest,\n request: buildContainerRevokeRequest({\n body: input.body,\n event: input.event,\n keyEpoch: input.keyEpoch,\n keyring: input.keyring,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n parentKek: input.parentKek,\n predecessorBridge: input.predecessorBridge,\n previousManifest: input.previousManifest,\n previousProjection: input.previousProjection,\n principalPolicies: input.principalPolicies,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n }),\n state: input.state,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n };\n\n return { containerKey: input.containerKey, plan };\n}\n\n// biome-ignore lint/complexity/noExcessiveLinesPerFunction: Revoke planning has to keep the manifest, KEK, wraps, and signed event in one auditable transition.\nexport async function buildMaterializedContainerRevokePlan(input: {\n author: ContainerMutationAuthor;\n eventId?: string | undefined;\n execSql: ExecSql;\n /** Keys a batch minted above this container and has yet to commit. */\n knownContainerKeks?: ReadonlyMap<string, Uint8Array> | undefined;\n /** False for a projection re-rooted on rotations not yet acknowledged. */\n persistVerificationCheckpoints?: boolean | undefined;\n previousProjection: ContainerWriterProjectionResponse;\n /** Verified policies the path may cite before they are stored locally. */\n principalPolicyCache?: PrincipalPolicyCache | undefined;\n replacementPrincipalPolicy?: PrincipalPolicyCurrentEvidence | undefined;\n revokedSubject: ContainerRevokeSubject;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n targetSecretKey: Uint8Array;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<MaterializedContainerRevokePlan> {\n const resolveProjectionUserKey = requireProjectionUserKeyResolver(\n input.resolveProjectionUserKey,\n \"Remote container revoke\",\n );\n const {\n parentKek,\n parentPublicKey,\n predecessorContainerKey,\n previousState,\n target,\n } = await resolveRotationContext(input, \"revoke\");\n const principalPolicies = await collectContainerRevokePrincipalPolicies({\n execSql: input.execSql,\n persistVerificationCheckpoints: input.persistVerificationCheckpoints,\n previousProjection: input.previousProjection,\n principalPolicyCache: input.principalPolicyCache,\n resolveUserKey: resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n assertContainerAuthorAccess({\n author: input.author,\n projection: input.previousProjection,\n principalPolicies,\n minimumAccess: \"admin\",\n });\n const nextContainerKeyEpoch = target.kek.containerKeyEpoch + 1;\n const { containerKey, containerKeyEpochId, keyring, predecessorBridge } =\n await buildContainerRotationArtifacts({\n containerId: previousState.containerId,\n currentKek: target.kek,\n currentKeyMaterial: predecessorContainerKey,\n keyEpoch: nextContainerKeyEpoch,\n signedEpochIds: target.signedEpochIds,\n });\n const body: ContainerRevokeAccessEventBody = {\n eventType: \"container.revoke\",\n parentManifestHash:\n input.previousProjection.path.at(-2)?.manifestHash ?? null,\n containerKeyPublicKey: await deriveContainerKekWrappingPublicKey({\n containerId: previousState.containerId,\n keyMaterial: containerKey,\n }),\n containerKeyEpochId,\n keyringHash: await computeContainerKekKeyringHash(keyring),\n predecessorBridgeHash:\n await computeContainerKekPredecessorBridgeHash(predecessorBridge),\n subjectId: input.revokedSubject.subjectId,\n subjectType: input.revokedSubject.subjectType,\n };\n const { event, eventHash } = await signContainerMutationEvent({\n author: input.author,\n body,\n containerId: previousState.containerId,\n dependencyManifestHashes: uniqueSortedManifestHashes(\n input.previousProjection.path,\n ),\n eventId: input.eventId ?? crypto.randomUUID(),\n previousManifestHash: target.manifest.manifestHash,\n signedAt: input.signedAt ?? new Date().toISOString(),\n });\n const { manifest, manifestHash, state } = await deriveContainerRevokeManifest(\n {\n containerKeyPublicKey: body.containerKeyPublicKey,\n parentManifestHash: body.parentManifestHash,\n containerKeyEpochId,\n eventHash,\n previousManifest: target.manifest,\n revokedSubject: input.revokedSubject,\n },\n );\n const keyEpoch = buildContainerCreateKeyEpoch({\n containerId: previousState.containerId,\n containerKeyEpochId,\n eventHash,\n keyEpoch: nextContainerKeyEpoch,\n manifestHash,\n parentContainerKeyEpochId: parentKek?.containerKeyEpochId ?? null,\n });\n\n const replacementPrincipalPolicy = input.replacementPrincipalPolicy;\n if (\n replacementPrincipalPolicy &&\n (replacementPrincipalPolicy.principalType !==\n input.revokedSubject.subjectType ||\n replacementPrincipalPolicy.principalId !== input.revokedSubject.subjectId)\n ) {\n throw new Error(\"Container revoke replacement principal does not match\");\n }\n const currentPrincipalPolicies = replacementPrincipalPolicy\n ? principalPolicies.filter(\n (policy) =>\n policy.principalType !== replacementPrincipalPolicy.principalType ||\n policy.principalId !== replacementPrincipalPolicy.principalId,\n )\n : principalPolicies;\n const { userRecipientKeys, wraps } = await buildContainerRotationWraps({\n containerKey,\n containerKeyEpochId,\n manifestHash,\n operationLabel: \"Container revoke\",\n parentKek,\n parentPublicKey,\n principalPolicies: currentPrincipalPolicies,\n resolveUserKey: resolveProjectionUserKey,\n state,\n });\n\n return buildContainerRevokePlanResult({\n body,\n containerId: previousState.containerId,\n containerKey,\n containerKeyEpochId,\n event,\n eventHash,\n keyEpoch,\n keyring,\n manifest,\n manifestHash,\n parentKek,\n predecessorBridge,\n previousManifest: asContainerManifestBundle(target.manifest),\n previousProjection: input.previousProjection,\n principalPolicies: currentPrincipalPolicies,\n state,\n userRecipientKeys,\n wraps,\n });\n}\n\nexport async function revokeRemoteContainer(input: {\n reportSecurityIncident: SecurityIncidentReporter;\n apiClient: ContainerRevokeApi;\n author: ContainerMutationAuthor;\n containerId: string;\n eventId?: string | undefined;\n execSql: ExecSql;\n revokedSubject: ContainerRevokeSubject;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n targetSecretKey: Uint8Array;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<{\n containerKey: Uint8Array;\n plan: ContainerRevokePlan;\n response: ContainerRotationResponse;\n} | null> {\n const previousProjection = await input.apiClient.getContainerWriterProjection(\n input.containerId,\n );\n if (!previousProjection) {\n return null;\n }\n\n const materializedPlan = await buildMaterializedContainerRevokePlan({\n author: input.author,\n eventId: input.eventId,\n execSql: input.execSql,\n previousProjection,\n revokedSubject: input.revokedSubject,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n signedAt: input.signedAt,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n return submitAcknowledgedContainerMutation({\n reportSecurityIncident: input.reportSecurityIncident,\n recitationPolicies: [],\n apiClient: input.apiClient,\n author: input.author,\n carriedRekeys: {\n planning: {\n apiClient: input.apiClient,\n author: input.author,\n execSql: input.execSql,\n knownContainerKeks: new Map([\n [\n materializedPlan.plan.containerKeyEpochId,\n materializedPlan.containerKey,\n ],\n ]),\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n },\n rotated: () =>\n containerWriterProjectionFromRotationPlan({\n plan: materializedPlan.plan,\n previousProjection,\n }),\n },\n containerKey: materializedPlan.containerKey,\n execSql: input.execSql,\n plan: materializedPlan.plan,\n stillCurrent: input.stillCurrent,\n submit: (carried) => {\n const request = carried.length\n ? { ...materializedPlan.plan.request, containerRekeys: [...carried] }\n : materializedPlan.plan.request;\n const options = {\n expectedPaymentRequiredOrganizationId: input.author.organizationId,\n };\n const { revokeContainerResult } = input.apiClient;\n return submitContainerRotation({\n plain: () =>\n input.apiClient.revokeContainer(input.containerId, request, options),\n result: revokeContainerResult\n ? () =>\n revokeContainerResult.call(\n input.apiClient,\n input.containerId,\n request,\n { ...options, reportErrors: false },\n )\n : undefined,\n });\n },\n });\n}\n"]}
1
+ {"version":3,"file":"revoke.js","sourceRoot":"","sources":["revoke.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,8BAA8B,EAC9B,wCAAwC,EACxC,mCAAmC,GACpC,MAAM,mBAAmB,CAAC;AAU3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,4CAA4C,CAAC;AAOpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAIL,gCAAgC,GACjC,MAAM,4CAA4C,CAAC;AAIpD,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,mCAAmC,EACnC,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,yCAAyC,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAEL,6BAA6B,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,uCAAuC,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAE9D,SAAS,2BAA2B,CAAC,KAcpC;IACC,OAAO;QACL,GAAG,4BAA4B,CAAC,QAAQ,EAAE,KAAK,CAAC;QAChD,GAAG,yBAAyB,CAC1B,KAAK,CAAC,gBAAgB,EACtB,KAAK,CAAC,kBAAkB,CACzB;QACD,iBAAiB,EAAE,mBAAmB,CACpC,KAAK,CAAC,iBAAiB,EACv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CACpC;oBACL,CAAC,CAAC,SAAS;aACd,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n AccessEvent,\n AccessManifest,\n ContainerAccessManifestState,\n ContainerKekKeyring,\n ContainerKekPredecessorBridge,\n ContainerKeyEpoch,\n ContainerKeyWrap,\n ContainerRevokeAccessEventBody,\n ContainerUserRecipientKey,\n} from \"@tearleads/crypto\";\nimport {\n computeContainerKekKeyringHash,\n computeContainerKekPredecessorBridgeHash,\n deriveContainerKekWrappingPublicKey,\n} from \"@tearleads/crypto\";\nimport type {\n AccessManifestBundleWire,\n ContainerMutationRequest,\n} from \"@tearleads/validators/request\";\nimport type {\n ContainerKekResponse,\n ContainerRotationResponse,\n ContainerWriterProjectionResponse,\n} from \"@tearleads/validators/response\";\nimport { assertContainerAuthorAccess } from \"../../../data/containers/shared/authorAccess\";\nimport {\n buildContainerCreateKeyEpoch,\n signContainerMutationEvent,\n} from \"../../../data/containers/shared/events\";\nimport {\n asContainerManifestBundle,\n uniqueSortedManifestHashes,\n} from \"../../../data/containers/shared/projection\";\nimport type {\n ContainerMutationAuthor,\n ContainerRevokeApi,\n ContainerRevokePlan,\n MaterializedContainerRevokePlan,\n} from \"../../../data/containers/shared/types\";\nimport { readCanonicalRecord } from \"../../../data/keying/canonicalJson\";\nimport {\n type PrincipalPolicyCache,\n type ProjectionUserKeyResolver,\n type ReferencedPrincipalPolicyWarmer,\n requireProjectionUserKeyResolver,\n} from \"../../../data/keyingProjectionVerification\";\nimport type { PrincipalPolicyCurrentEvidence } from \"../../../data/principals/principalPolicyEvidence\";\nimport type { SecurityIncidentReporter } from \"../../../data/shared/securityIncidents\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport { buildContainerRotationArtifacts } from \"./moveRotation\";\nimport {\n containerMutationRequestCore,\n previousPathRequestFields,\n readCanonicalRecordOrNull,\n} from \"./mutationRequestCore\";\nimport {\n submitAcknowledgedContainerMutation,\n submitContainerRotation,\n} from \"./mutationSubmit\";\nimport { containerWriterProjectionFromRotationPlan } from \"./rekeyProjection\";\nimport {\n type ContainerRevokeSubject,\n deriveContainerRevokeManifest,\n} from \"./revokeManifest\";\nimport { resolveRotationContext } from \"./rotationContext\";\nimport { collectContainerRevokePrincipalPolicies } from \"./rotationPrincipalPolicies\";\nimport { buildContainerRotationWraps } from \"./rotationWraps\";\n\nfunction buildContainerRevokeRequest(input: {\n body: ContainerRevokeAccessEventBody;\n event: AccessEvent;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n parentKek: ContainerKekResponse | null;\n predecessorBridge: ContainerKekPredecessorBridge;\n previousManifest: AccessManifestBundleWire;\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n userRecipientKeys: readonly ContainerUserRecipientKey[];\n wraps: readonly ContainerKeyWrap[];\n}): ContainerMutationRequest {\n return {\n ...containerMutationRequestCore(\"revoke\", input),\n ...previousPathRequestFields(\n input.previousManifest,\n input.previousProjection,\n ),\n predecessorBridge: readCanonicalRecord(\n input.predecessorBridge,\n \"Container revoke predecessor bridge\",\n ),\n keyring: readCanonicalRecord(input.keyring, \"Container revoke keyring\"),\n parentKekState: readCanonicalRecordOrNull(\n input.parentKek,\n \"Container revoke parent KEK state\",\n ),\n };\n}\n\nfunction buildContainerRevokePlanResult(input: {\n body: ContainerRevokeAccessEventBody;\n containerId: string;\n containerKey: Uint8Array;\n containerKeyEpochId: string;\n event: AccessEvent;\n eventHash: string;\n keyEpoch: ContainerKeyEpoch;\n keyring: ContainerKekKeyring;\n manifest: AccessManifest;\n manifestHash: string;\n parentKek: ContainerKekResponse | null;\n predecessorBridge: ContainerKekPredecessorBridge;\n previousManifest: AccessManifestBundleWire;\n previousProjection: ContainerWriterProjectionResponse;\n principalPolicies: readonly PrincipalPolicyCurrentEvidence[];\n state: ContainerAccessManifestState;\n userRecipientKeys: ContainerUserRecipientKey[];\n wraps: ContainerKeyWrap[];\n}): MaterializedContainerRevokePlan {\n const plan: ContainerRevokePlan = {\n body: input.body,\n containerId: input.containerId,\n containerKeyEpochId: input.containerKeyEpochId,\n event: input.event,\n eventHash: input.eventHash,\n keyEpoch: input.keyEpoch,\n keyring: input.keyring,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n previousManifest: input.previousManifest,\n request: buildContainerRevokeRequest({\n body: input.body,\n event: input.event,\n keyEpoch: input.keyEpoch,\n keyring: input.keyring,\n manifest: input.manifest,\n manifestHash: input.manifestHash,\n parentKek: input.parentKek,\n predecessorBridge: input.predecessorBridge,\n previousManifest: input.previousManifest,\n previousProjection: input.previousProjection,\n principalPolicies: input.principalPolicies,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n }),\n state: input.state,\n userRecipientKeys: input.userRecipientKeys,\n wraps: input.wraps,\n };\n\n return { containerKey: input.containerKey, plan };\n}\n\n// biome-ignore lint/complexity/noExcessiveLinesPerFunction: Revoke planning has to keep the manifest, KEK, wraps, and signed event in one auditable transition.\nexport async function buildMaterializedContainerRevokePlan(input: {\n author: ContainerMutationAuthor;\n eventId?: string | undefined;\n execSql: ExecSql;\n /** Keys a batch minted above this container and has yet to commit. */\n knownContainerKeks?: ReadonlyMap<string, Uint8Array> | undefined;\n /** False for a projection re-rooted on rotations not yet acknowledged. */\n persistVerificationCheckpoints?: boolean | undefined;\n previousProjection: ContainerWriterProjectionResponse;\n /** Verified policies the path may cite before they are stored locally. */\n principalPolicyCache?: PrincipalPolicyCache | undefined;\n replacementPrincipalPolicy?: PrincipalPolicyCurrentEvidence | undefined;\n revokedSubject: ContainerRevokeSubject;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n targetSecretKey: Uint8Array;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<MaterializedContainerRevokePlan> {\n const resolveProjectionUserKey = requireProjectionUserKeyResolver(\n input.resolveProjectionUserKey,\n \"Remote container revoke\",\n );\n const {\n parentKek,\n parentPublicKey,\n predecessorContainerKey,\n previousState,\n target,\n } = await resolveRotationContext(input, \"revoke\");\n const principalPolicies = await collectContainerRevokePrincipalPolicies({\n execSql: input.execSql,\n persistVerificationCheckpoints: input.persistVerificationCheckpoints,\n previousProjection: input.previousProjection,\n principalPolicyCache: input.principalPolicyCache,\n resolveUserKey: resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n assertContainerAuthorAccess({\n author: input.author,\n projection: input.previousProjection,\n principalPolicies,\n minimumAccess: \"admin\",\n });\n const nextContainerKeyEpoch = target.kek.containerKeyEpoch + 1;\n const { containerKey, containerKeyEpochId, keyring, predecessorBridge } =\n await buildContainerRotationArtifacts({\n containerId: previousState.containerId,\n currentKek: target.kek,\n currentKeyMaterial: predecessorContainerKey,\n keyEpoch: nextContainerKeyEpoch,\n signedEpochIds: target.signedEpochIds,\n });\n const body: ContainerRevokeAccessEventBody = {\n eventType: \"container.revoke\",\n parentManifestHash:\n input.previousProjection.path.at(-2)?.manifestHash ?? null,\n containerKeyPublicKey: await deriveContainerKekWrappingPublicKey({\n containerId: previousState.containerId,\n keyMaterial: containerKey,\n }),\n containerKeyEpochId,\n keyringHash: await computeContainerKekKeyringHash(keyring),\n predecessorBridgeHash:\n await computeContainerKekPredecessorBridgeHash(predecessorBridge),\n subjectId: input.revokedSubject.subjectId,\n subjectType: input.revokedSubject.subjectType,\n };\n const { event, eventHash } = await signContainerMutationEvent({\n author: input.author,\n body,\n containerId: previousState.containerId,\n dependencyManifestHashes: uniqueSortedManifestHashes(\n input.previousProjection.path,\n ),\n eventId: input.eventId ?? crypto.randomUUID(),\n previousManifestHash: target.manifest.manifestHash,\n signedAt: input.signedAt ?? new Date().toISOString(),\n });\n const { manifest, manifestHash, state } = await deriveContainerRevokeManifest(\n {\n containerKeyPublicKey: body.containerKeyPublicKey,\n parentManifestHash: body.parentManifestHash,\n containerKeyEpochId,\n eventHash,\n previousManifest: target.manifest,\n revokedSubject: input.revokedSubject,\n },\n );\n const keyEpoch = buildContainerCreateKeyEpoch({\n containerId: previousState.containerId,\n containerKeyEpochId,\n eventHash,\n keyEpoch: nextContainerKeyEpoch,\n manifestHash,\n parentContainerKeyEpochId: parentKek?.containerKeyEpochId ?? null,\n });\n\n const replacementPrincipalPolicy = input.replacementPrincipalPolicy;\n if (\n replacementPrincipalPolicy &&\n (replacementPrincipalPolicy.principalType !==\n input.revokedSubject.subjectType ||\n replacementPrincipalPolicy.principalId !== input.revokedSubject.subjectId)\n ) {\n throw new Error(\"Container revoke replacement principal does not match\");\n }\n const currentPrincipalPolicies = replacementPrincipalPolicy\n ? principalPolicies.filter(\n (policy) =>\n policy.principalType !== replacementPrincipalPolicy.principalType ||\n policy.principalId !== replacementPrincipalPolicy.principalId,\n )\n : principalPolicies;\n const { userRecipientKeys, wraps } = await buildContainerRotationWraps({\n containerKey,\n containerKeyEpochId,\n manifestHash,\n operationLabel: \"Container revoke\",\n parentKek,\n parentPublicKey,\n principalPolicies: currentPrincipalPolicies,\n resolveUserKey: resolveProjectionUserKey,\n state,\n });\n\n return buildContainerRevokePlanResult({\n body,\n containerId: previousState.containerId,\n containerKey,\n containerKeyEpochId,\n event,\n eventHash,\n keyEpoch,\n keyring,\n manifest,\n manifestHash,\n parentKek,\n predecessorBridge,\n previousManifest: asContainerManifestBundle(target.manifest),\n previousProjection: input.previousProjection,\n principalPolicies: currentPrincipalPolicies,\n state,\n userRecipientKeys,\n wraps,\n });\n}\n\nexport async function revokeRemoteContainer(input: {\n reportSecurityIncident: SecurityIncidentReporter;\n apiClient: ContainerRevokeApi;\n author: ContainerMutationAuthor;\n containerId: string;\n eventId?: string | undefined;\n execSql: ExecSql;\n revokedSubject: ContainerRevokeSubject;\n resolveProjectionUserKey: ProjectionUserKeyResolver;\n signedAt?: string | undefined;\n stillCurrent?: (() => boolean) | undefined;\n targetSecretKey: Uint8Array;\n warmReferencedPrincipalPolicies?: ReferencedPrincipalPolicyWarmer | undefined;\n}): Promise<{\n containerKey: Uint8Array;\n plan: ContainerRevokePlan;\n response: ContainerRotationResponse;\n} | null> {\n const previousProjection = await input.apiClient.getContainerWriterProjection(\n input.containerId,\n );\n if (!previousProjection) {\n return null;\n }\n\n const materializedPlan = await buildMaterializedContainerRevokePlan({\n author: input.author,\n eventId: input.eventId,\n execSql: input.execSql,\n previousProjection,\n revokedSubject: input.revokedSubject,\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n signedAt: input.signedAt,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n });\n return submitAcknowledgedContainerMutation({\n reportSecurityIncident: input.reportSecurityIncident,\n recitationPolicies: [],\n apiClient: input.apiClient,\n author: input.author,\n carriedRekeys: {\n planning: {\n apiClient: input.apiClient,\n author: input.author,\n execSql: input.execSql,\n knownContainerKeks: new Map([\n [\n materializedPlan.plan.containerKeyEpochId,\n materializedPlan.containerKey,\n ],\n ]),\n resolveProjectionUserKey: input.resolveProjectionUserKey,\n stillCurrent: input.stillCurrent,\n targetSecretKey: input.targetSecretKey,\n warmReferencedPrincipalPolicies: input.warmReferencedPrincipalPolicies,\n },\n rotated: () =>\n containerWriterProjectionFromRotationPlan({\n plan: materializedPlan.plan,\n previousProjection,\n }),\n },\n containerKey: materializedPlan.containerKey,\n execSql: input.execSql,\n plan: materializedPlan.plan,\n stillCurrent: input.stillCurrent,\n submit: (carried) => {\n const request = carried.length\n ? { ...materializedPlan.plan.request, containerRekeys: [...carried] }\n : materializedPlan.plan.request;\n const options = {\n expectedPaymentRequiredOrganizationId: input.author.organizationId,\n };\n const { revokeContainerResult } = input.apiClient;\n return submitContainerRotation({\n plain: () =>\n input.apiClient.revokeContainer(input.containerId, request, options),\n result: revokeContainerResult\n ? () =>\n revokeContainerResult.call(\n input.apiClient,\n input.containerId,\n request,\n { ...options, reportErrors: false },\n )\n : undefined,\n });\n },\n });\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { uniquePrincipalPolicies } from "../../../data/containers/shared/principalPolicies.js";
2
- import { collectContainerWriterProjectionPrincipalPolicies, } from "../../../data/keyingProjectionVerification.js";
2
+ import { collectContainerWriterProjectionPrincipalPolicies, } from "../../../data/keyingProjectionVerification/index.js";
3
3
  /**
4
4
  * Shared by rekey and revoke. Lives apart from both: background descendant
5
5
  * repair imports the rekey planner, and revoke schedules that repair, so
@@ -1,4 +1,4 @@
1
- import { nullOnProjectionVerificationCancellation, requireProjectionUserKeyResolver, } from "../../../data/keyingProjectionVerification.js";
1
+ import { nullOnProjectionVerificationCancellation, requireProjectionUserKeyResolver, } from "../../../data/keyingProjectionVerification/index.js";
2
2
  import { principalPolicyCacheForVerifiedPolicies } from "../../../data/keyingProjectionVerification/principalPolicyCache.js";
3
3
  import { inheritPrincipalHistoryProtection } from "../../../data/principals/principalHistoryRuntime.js";
4
4
  import { createRuntimeCurrentGroupMutation } from "../../organizations/runtimeCurrentGroupMutation.js";
@@ -1,8 +1,8 @@
1
1
  import type { ContainerAccessLevel, SigningKeyPair } from "../../../internal/crypto/index.js";
2
2
  import type { ContainerMutationResponse, ContainerWriterProjectionResponse } from "../../../internal/validators/response/index.js";
3
3
  import type { ContainerMutationAuthor, ContainerShareApi, ContainerSharePlan } from "../../../data/containers/shared/types.js";
4
- import { type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../data/keyingProjectionVerification.js";
5
- import type { SecurityIncidentReporter } from "../../../data/securityIncidents.js";
4
+ import { type ProjectionUserKeyResolver, type ReferencedPrincipalPolicyWarmer } from "../../../data/keyingProjectionVerification/index.js";
5
+ import type { SecurityIncidentReporter } from "../../../data/shared/securityIncidents.js";
6
6
  import type { ExecSql } from "../../../data/sqlite/sqlSchema.js";
7
7
  import { type TrustedUserIdentityResolver } from "../../../data/trustedUserIdentity/index.js";
8
8
  import type { GroupPolicyNameReader } from "../../organizations/principalPolicyRequest.js";
@@ -1,4 +1,4 @@
1
- import { isProjectionVerificationCancelledError, nullOnProjectionVerificationCancellation, requireProjectionUserKeyResolver, } from "../../../data/keyingProjectionVerification.js";
1
+ import { isProjectionVerificationCancelledError, nullOnProjectionVerificationCancellation, requireProjectionUserKeyResolver, } from "../../../data/keyingProjectionVerification/index.js";
2
2
  import { principalPolicyCacheForVerifiedPolicies } from "../../../data/keyingProjectionVerification/principalPolicyCache.js";
3
3
  import { savePrincipalPolicyBundle } from "../../../data/persistence/principalPolicyPersistence.js";
4
4
  import { requireTrustedUserIdentityResolver, } from "../../../data/trustedUserIdentity/index.js";