@tearleads/client-sdk 0.1.14 → 0.1.15

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 (200) hide show
  1. package/client/containerContents.js +2 -1
  2. package/client/containerContents.js.map +1 -1
  3. package/data/documents/blob/shared/types.d.ts +4 -0
  4. package/data/documents/blob/shared/types.js.map +1 -1
  5. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js +2 -0
  6. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js.map +1 -1
  7. package/data/keyingProjectionVerification/checkpointContext.d.ts +2 -1
  8. package/data/keyingProjectionVerification/checkpointContext.js +22 -0
  9. package/data/keyingProjectionVerification/checkpointContext.js.map +1 -1
  10. package/data/keyingProjectionVerification/containerDestinationVerification.js +11 -1
  11. package/data/keyingProjectionVerification/containerDestinationVerification.js.map +1 -1
  12. package/data/keyingProjectionVerification/containerManifestVerification.js.map +1 -1
  13. package/data/keyingProjectionVerification/containerPathVerification.js.map +1 -1
  14. package/data/keyingProjectionVerification/containerProjectionVerification.d.ts +3 -2
  15. package/data/keyingProjectionVerification/containerProjectionVerification.js +10 -11
  16. package/data/keyingProjectionVerification/containerProjectionVerification.js.map +1 -1
  17. package/data/keyingProjectionVerification/documentManifestPolicies.js.map +1 -1
  18. package/data/keyingProjectionVerification/documentManifestVerification.js.map +1 -1
  19. package/data/keyingProjectionVerification/documentProjectionVerification.d.ts +2 -3
  20. package/data/keyingProjectionVerification/documentProjectionVerification.js +4 -0
  21. package/data/keyingProjectionVerification/documentProjectionVerification.js.map +1 -1
  22. package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js +14 -12
  23. package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js.map +1 -1
  24. package/data/keyingProjectionVerification/organizationFounderBinding.js.map +1 -1
  25. package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js +33 -6
  26. package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js.map +1 -1
  27. package/data/keyingProjectionVerification/projectionLifetimes.js +13 -0
  28. package/data/keyingProjectionVerification/projectionLifetimes.js.map +1 -0
  29. package/data/keyingProjectionVerification/projectionPolicyEvidence.js +19 -66
  30. package/data/keyingProjectionVerification/projectionPolicyEvidence.js.map +1 -1
  31. package/data/keyingProjectionVerification/types.d.ts +13 -2
  32. package/data/keyingProjectionVerification/types.js +15 -0
  33. package/data/keyingProjectionVerification/types.js.map +1 -1
  34. package/data/persistence/keyingCheckpointAdvancePersistence.js +4 -1
  35. package/data/persistence/keyingCheckpointAdvancePersistence.js.map +1 -1
  36. package/data/persistence/organizationFounderPersistence.js +2 -2
  37. package/data/persistence/organizationFounderPersistence.js.map +1 -1
  38. package/data/persistence/principalAuthorizationCheckpoints.js +29 -0
  39. package/data/persistence/principalAuthorizationCheckpoints.js.map +1 -0
  40. package/data/persistence/principalHistoryEvidencePersistence.d.ts +30 -0
  41. package/data/persistence/principalHistoryPrefixPersistence.d.ts +24 -0
  42. package/data/persistence/principalHistoryPrefixPersistence.js +6 -2
  43. package/data/persistence/principalHistoryPrefixPersistence.js.map +1 -1
  44. package/data/persistence/principalHistoryStagePersistence.d.ts +21 -0
  45. package/data/principals/principalHistoryRuntime.js +12 -0
  46. package/data/principals/principalHistoryRuntime.js.map +1 -0
  47. package/data/principals/principalHistoryStageProtection.js +2 -12
  48. package/data/principals/principalHistoryStageProtection.js.map +1 -1
  49. package/data/principals/principalPolicyEvidence.d.ts +2 -2
  50. package/data/principals/principalPolicyEvidence.js.map +1 -1
  51. package/data/sqlite/principalHistoryEvidenceSchema.d.ts +308 -0
  52. package/data/sqlite/principalHistoryStageSchema.d.ts +119 -0
  53. package/index.d.ts +2 -2
  54. package/index.js +1 -1
  55. package/index.js.map +1 -1
  56. package/internal/api-client/ApiCache.d.ts +54 -0
  57. package/internal/api-client/ApiClient.d.ts +255 -309
  58. package/internal/api-client/ApiClient.js +15 -6
  59. package/internal/api-client/ApiClient.js.map +1 -1
  60. package/internal/api-client/index.d.ts +1 -0
  61. package/internal/api-client/index.js.map +1 -1
  62. package/internal/api-client/principalHistoryDeadline.js +20 -0
  63. package/internal/api-client/principalHistoryDeadline.js.map +1 -0
  64. package/internal/api-client/principalHistoryRequest.js +59 -22
  65. package/internal/api-client/principalHistoryRequest.js.map +1 -1
  66. package/internal/api-client/principalHistoryRequestContext.js +18 -5
  67. package/internal/api-client/principalHistoryRequestContext.js.map +1 -1
  68. package/internal/api-client/principalPolicyRequests.d.ts +799 -0
  69. package/internal/api-client/principalPolicyRequests.js +9 -4
  70. package/internal/api-client/principalPolicyRequests.js.map +1 -1
  71. package/internal/api-client/projectionPolicyHistoryPages.d.ts +9 -0
  72. package/internal/api-client/projectionPolicyHistoryPages.js +88 -0
  73. package/internal/api-client/projectionPolicyHistoryPages.js.map +1 -0
  74. package/internal/api-client/writerProjectionRequests.js +26 -0
  75. package/internal/api-client/writerProjectionRequests.js.map +1 -0
  76. package/internal/crypto/keying/principalPolicyHistory.js +4 -0
  77. package/internal/crypto/keying/principalPolicyHistory.js.map +1 -1
  78. package/internal/crypto/keying/principalPolicyHistoryTypes.d.ts +2 -0
  79. package/internal/crypto/keying/principalPolicyHistoryTypes.js.map +1 -1
  80. package/internal/crypto/projectionHistorySlots.js +0 -4
  81. package/internal/crypto/projectionHistorySlots.js.map +1 -1
  82. package/internal/validators/operation/index.d.ts +1 -0
  83. package/internal/validators/operation/index.js +1 -0
  84. package/internal/validators/operation/index.js.map +1 -1
  85. package/internal/validators/operation/principals.d.ts +38 -16
  86. package/internal/validators/operation/principals.js +11 -5
  87. package/internal/validators/operation/principals.js.map +1 -1
  88. package/internal/validators/operation/projectionPolicyHistory.d.ts +512 -0
  89. package/internal/validators/operation/projectionPolicyHistory.js +37 -0
  90. package/internal/validators/operation/projectionPolicyHistory.js.map +1 -0
  91. package/internal/validators/operation/registry.d.ts +2 -0
  92. package/internal/validators/operation/registry.js +2 -0
  93. package/internal/validators/operation/registry.js.map +1 -1
  94. package/internal/validators/operation/writerProjections.d.ts +178 -1224
  95. package/internal/validators/operation/writerProjections.js +9 -2
  96. package/internal/validators/operation/writerProjections.js.map +1 -1
  97. package/internal/validators/response/container.d.ts +84 -612
  98. package/internal/validators/response/documentMutation.d.ts +84 -612
  99. package/internal/validators/response/index.d.ts +1 -0
  100. package/internal/validators/response/index.js +1 -0
  101. package/internal/validators/response/index.js.map +1 -1
  102. package/internal/validators/response/organizationBilling.d.ts +1 -0
  103. package/internal/validators/response/organizationBilling.js +1 -1
  104. package/internal/validators/response/organizationBilling.js.map +1 -1
  105. package/internal/validators/response/principalHistoryPreparation.js +28 -1
  106. package/internal/validators/response/principalHistoryPreparation.js.map +1 -1
  107. package/internal/validators/response/principalPolicySnapshotPage.d.ts +388 -0
  108. package/internal/validators/response/principalPolicySnapshotPage.js +24 -0
  109. package/internal/validators/response/principalPolicySnapshotPage.js.map +1 -0
  110. package/internal/validators/response/projectionPolicyEvidence.d.ts +85 -613
  111. package/internal/validators/response/projectionPolicyEvidence.js +10 -5
  112. package/internal/validators/response/projectionPolicyEvidence.js.map +1 -1
  113. package/package.json +1 -1
  114. package/stores/documents/documentStore/attachmentHydration.js +3 -0
  115. package/stores/documents/documentStore/attachmentHydration.js.map +1 -1
  116. package/stores/documents/documentStore/syncDetachedAttachments.js +3 -0
  117. package/stores/documents/documentStore/syncDetachedAttachments.js.map +1 -1
  118. package/workflows/blobs/decrypt.d.ts +1 -1
  119. package/workflows/blobs/decrypt.js +3 -1
  120. package/workflows/blobs/decrypt.js.map +1 -1
  121. package/workflows/blobs/detach.js +6 -1
  122. package/workflows/blobs/detach.js.map +1 -1
  123. package/workflows/blobs/hydrate.d.ts +3 -1
  124. package/workflows/blobs/hydrate.js +2 -0
  125. package/workflows/blobs/hydrate.js.map +1 -1
  126. package/workflows/blobs/retainedAttachmentVerification.js +2 -0
  127. package/workflows/blobs/retainedAttachmentVerification.js.map +1 -1
  128. package/workflows/container-contents/container-state/createAdoption.js +2 -0
  129. package/workflows/container-contents/container-state/createAdoption.js.map +1 -1
  130. package/workflows/container-contents/container-state/createWithMetadata.js +7 -39
  131. package/workflows/container-contents/container-state/createWithMetadata.js.map +1 -1
  132. package/workflows/container-contents/container-state/createWithMetadataPlan.js +68 -0
  133. package/workflows/container-contents/container-state/createWithMetadataPlan.js.map +1 -0
  134. package/workflows/container-contents/remoteContainerState.js +3 -1
  135. package/workflows/container-contents/remoteContainerState.js.map +1 -1
  136. package/workflows/container-contents/remoteHydration/verifiedDestination.js +3 -0
  137. package/workflows/container-contents/remoteHydration/verifiedDestination.js.map +1 -1
  138. package/workflows/container-contents/runtime.d.ts +3 -0
  139. package/workflows/container-contents/runtime.js +7 -6
  140. package/workflows/container-contents/runtime.js.map +1 -1
  141. package/workflows/documents/create.d.ts +2 -15
  142. package/workflows/documents/create.js +9 -64
  143. package/workflows/documents/create.js.map +1 -1
  144. package/workflows/documents/createProjection.d.ts +14 -0
  145. package/workflows/documents/createProjection.js +26 -0
  146. package/workflows/documents/createProjection.js.map +1 -0
  147. package/workflows/documents/createResponse.js +49 -0
  148. package/workflows/documents/createResponse.js.map +1 -0
  149. package/workflows/documents/linkSetBlobRewraps.js +2 -0
  150. package/workflows/documents/linkSetBlobRewraps.js.map +1 -1
  151. package/workflows/documents/runtime.d.ts +3 -0
  152. package/workflows/documents/runtime.js +3 -2
  153. package/workflows/documents/runtime.js.map +1 -1
  154. package/workflows/documents/syncFailureClassification.js +3 -1
  155. package/workflows/documents/syncFailureClassification.js.map +1 -1
  156. package/workflows/principals/index.d.ts +2 -0
  157. package/workflows/principals/index.js +1 -0
  158. package/workflows/principals/index.js.map +1 -1
  159. package/workflows/principals/policyVerification.js.map +1 -1
  160. package/workflows/principals/principalHistoryRecoveryAuthority.js +20 -0
  161. package/workflows/principals/principalHistoryRecoveryAuthority.js.map +1 -0
  162. package/workflows/principals/principalHistoryRecoveryStage.js +1 -1
  163. package/workflows/principals/principalHistoryRecoveryStage.js.map +1 -1
  164. package/workflows/principals/principalHistoryRecoveryTypes.d.ts +3 -3
  165. package/workflows/principals/principalHistoryRecoveryTypes.js.map +1 -1
  166. package/workflows/principals/principalHistoryRecoveryVerification.js +6 -1
  167. package/workflows/principals/principalHistoryRecoveryVerification.js.map +1 -1
  168. package/workflows/principals/principalRecoveryOutage.js +1 -1
  169. package/workflows/principals/principalRecoveryOutage.js.map +1 -1
  170. package/workflows/principals/publicPrincipalHistoryAuthority.js +60 -0
  171. package/workflows/principals/publicPrincipalHistoryAuthority.js.map +1 -0
  172. package/workflows/principals/publicPrincipalHistoryPage.js +87 -0
  173. package/workflows/principals/publicPrincipalHistoryPage.js.map +1 -0
  174. package/workflows/principals/publicPrincipalHistoryProgress.js +178 -0
  175. package/workflows/principals/publicPrincipalHistoryProgress.js.map +1 -0
  176. package/workflows/principals/publicPrincipalHistoryTypes.d.ts +39 -0
  177. package/workflows/principals/publicPrincipalHistoryTypes.js +2 -0
  178. package/workflows/principals/publicPrincipalHistoryTypes.js.map +1 -0
  179. package/workflows/principals/publicProjectionDirectory.js +40 -0
  180. package/workflows/principals/publicProjectionDirectory.js.map +1 -0
  181. package/workflows/principals/publicProjectionPrincipal.js +53 -0
  182. package/workflows/principals/publicProjectionPrincipal.js.map +1 -0
  183. package/workflows/principals/recoverPrincipalPolicyHistory.js +4 -1
  184. package/workflows/principals/recoverPrincipalPolicyHistory.js.map +1 -1
  185. package/workflows/principals/recoverProjectionPolicyHistory.d.ts +9 -0
  186. package/workflows/principals/recoverProjectionPolicyHistory.js +98 -0
  187. package/workflows/principals/recoverProjectionPolicyHistory.js.map +1 -0
  188. package/workflows/principals/recoverPublicPrincipalHistory.js +176 -0
  189. package/workflows/principals/recoverPublicPrincipalHistory.js.map +1 -0
  190. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js +2 -5
  191. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js.map +1 -1
  192. package/workflows/principals/runtimePolicyRecovery.js +2 -1
  193. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  194. package/workflows/principals/runtimePolicyWarmer.js +2 -0
  195. package/workflows/principals/runtimePolicyWarmer.js.map +1 -1
  196. package/workflows/principals/runtimeProjectionPolicyRecovery.js +56 -0
  197. package/workflows/principals/runtimeProjectionPolicyRecovery.js.map +1 -0
  198. package/workflows/principals/selectPublicPrincipalHistory.js +90 -0
  199. package/workflows/principals/selectPublicPrincipalHistory.js.map +1 -0
  200. package/workflows/registration/provisioningBootstrapBuilders.d.ts +21 -153
@@ -1,5 +1,6 @@
1
1
  import { cachePrincipalPolicyBundles, cacheReferencedPrincipalPolicies, } from "./policyCache.js";
2
2
  import { createRuntimePrincipalPolicyResolver, } from "./runtimePolicyRecovery.js";
3
+ import { createRuntimeProjectionPolicyResolver } from "./runtimeProjectionPolicyRecovery.js";
3
4
  export function createRuntimePrincipalPolicyWarmer(runtime) {
4
5
  const policyInput = ({ organizationId, references, stillCurrent, }) => {
5
6
  const input = {
@@ -28,6 +29,7 @@ export function createRuntimePrincipalPolicyWarmer(runtime) {
28
29
  return Object.assign(warmer, {
29
30
  cacheBundles,
30
31
  resolveReference: createRuntimePrincipalPolicyResolver(runtime),
32
+ resolveProjectionHistory: createRuntimeProjectionPolicyResolver(runtime),
31
33
  });
32
34
  }
33
35
  //# sourceMappingURL=runtimePolicyWarmer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtimePolicyWarmer.js","sourceRoot":"","sources":["runtimePolicyWarmer.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,GACjC,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oCAAoC,GAErC,MAAM,yBAAyB,CAAC;AAiBjC,MAAM,UAAU,kCAAkC,CAChD,OAAmC;IAEnC,MAAM,WAAW,GAAG,CAAC,EACnB,cAAc,EACd,UAAU,EACV,YAAY,GACmC,EAAE,EAAE;QACnD,MAAM,KAAK,GAA2D;YACpE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;YAC9B,yBAAyB,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,EAAE,CACxD,OAAO,CAAC,SAAS,CAAC,yBAAyB,CAAC,aAAa,EAAE,WAAW,CAAC;YACzE,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;YACrB,cAAc;YACd,sBAAsB,EAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB;YAC3D,UAAU;YACV,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;YAC9D,YAAY;SACb,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,KAAK,EAClB,KAAqD,EACrD,EAAE,CAAC,gCAAgC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,MAAM,YAAY,GAAG,CAAC,KAAwC,EAAE,EAAE,CAChE,2BAA2B,CAAC;QAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;QAC9B,yBAAyB,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,EAAE,CACxD,OAAO,CAAC,SAAS,CAAC,yBAAyB,CAAC,aAAa,EAAE,WAAW,CAAC;QACzE,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;QACrB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,sBAAsB,EAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB;QAC3D,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;QAC9D,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAC;IACL,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QAC3B,YAAY;QACZ,gBAAgB,EAAE,oCAAoC,CAAC,OAAO,CAAC;KAChE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport type {\n PrincipalPolicyBundleCacheRequest,\n ReferencedPrincipalPolicyWarmer,\n} from \"../../data/keyingProjectionVerification\";\nimport type { SecurityIncidentReporter } from \"../../data/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport {\n cachePrincipalPolicyBundles,\n cacheReferencedPrincipalPolicies,\n} from \"./policyCache\";\nimport {\n createRuntimePrincipalPolicyResolver,\n type PrincipalPolicyRecoveryRuntime,\n} from \"./runtimePolicyRecovery\";\n\ninterface PrincipalPolicyWarmRuntime extends PrincipalPolicyRecoveryRuntime {\n readonly apiClient: PrincipalPolicyRecoveryRuntime[\"apiClient\"] & {\n getCurrentPrincipalPolicy(\n principalType: \"group\" | \"organization\",\n principalId: string,\n ): Promise<PrincipalPolicyBundleResponse | null>;\n };\n readonly infra: { readonly execSql: ExecSql };\n readonly util: {\n readonly log: (message: string) => void;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n };\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\nexport function createRuntimePrincipalPolicyWarmer(\n runtime: PrincipalPolicyWarmRuntime,\n): ReferencedPrincipalPolicyWarmer {\n const policyInput = ({\n organizationId,\n references,\n stillCurrent,\n }: Parameters<ReferencedPrincipalPolicyWarmer>[0]) => {\n const input: Parameters<typeof cacheReferencedPrincipalPolicies>[0] = {\n execSql: runtime.infra.execSql,\n getCurrentPrincipalPolicy: (principalType, principalId) =>\n runtime.apiClient.getCurrentPrincipalPolicy(principalType, principalId),\n log: runtime.util.log,\n organizationId,\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n references,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n stillCurrent,\n };\n return input;\n };\n const warmer = async (\n input: Parameters<ReferencedPrincipalPolicyWarmer>[0],\n ) => cacheReferencedPrincipalPolicies(policyInput(input));\n const cacheBundles = (input: PrincipalPolicyBundleCacheRequest) =>\n cachePrincipalPolicyBundles({\n bundles: input.bundles,\n execSql: runtime.infra.execSql,\n getCurrentPrincipalPolicy: (principalType, principalId) =>\n runtime.apiClient.getCurrentPrincipalPolicy(principalType, principalId),\n log: runtime.util.log,\n organizationId: input.organizationId,\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n stillCurrent: input.stillCurrent,\n });\n return Object.assign(warmer, {\n cacheBundles,\n resolveReference: createRuntimePrincipalPolicyResolver(runtime),\n });\n}\n"]}
1
+ {"version":3,"file":"runtimePolicyWarmer.js","sourceRoot":"","sources":["runtimePolicyWarmer.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,GACjC,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oCAAoC,GAErC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qCAAqC,EAAE,MAAM,mCAAmC,CAAC;AAiB1F,MAAM,UAAU,kCAAkC,CAChD,OAAmC;IAEnC,MAAM,WAAW,GAAG,CAAC,EACnB,cAAc,EACd,UAAU,EACV,YAAY,GACmC,EAAE,EAAE;QACnD,MAAM,KAAK,GAA2D;YACpE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;YAC9B,yBAAyB,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,EAAE,CACxD,OAAO,CAAC,SAAS,CAAC,yBAAyB,CAAC,aAAa,EAAE,WAAW,CAAC;YACzE,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;YACrB,cAAc;YACd,sBAAsB,EAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB;YAC3D,UAAU;YACV,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;YAC9D,YAAY;SACb,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,KAAK,EAClB,KAAqD,EACrD,EAAE,CAAC,gCAAgC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,MAAM,YAAY,GAAG,CAAC,KAAwC,EAAE,EAAE,CAChE,2BAA2B,CAAC;QAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;QAC9B,yBAAyB,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,EAAE,CACxD,OAAO,CAAC,SAAS,CAAC,yBAAyB,CAAC,aAAa,EAAE,WAAW,CAAC;QACzE,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;QACrB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,sBAAsB,EAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB;QAC3D,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;QAC9D,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAC;IACL,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QAC3B,YAAY;QACZ,gBAAgB,EAAE,oCAAoC,CAAC,OAAO,CAAC;QAC/D,wBAAwB,EAAE,qCAAqC,CAAC,OAAO,CAAC;KACzE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport type {\n PrincipalPolicyBundleCacheRequest,\n ReferencedPrincipalPolicyWarmer,\n} from \"../../data/keyingProjectionVerification\";\nimport type { SecurityIncidentReporter } from \"../../data/securityIncidents\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\nimport {\n cachePrincipalPolicyBundles,\n cacheReferencedPrincipalPolicies,\n} from \"./policyCache\";\nimport {\n createRuntimePrincipalPolicyResolver,\n type PrincipalPolicyRecoveryRuntime,\n} from \"./runtimePolicyRecovery\";\nimport { createRuntimeProjectionPolicyResolver } from \"./runtimeProjectionPolicyRecovery\";\n\ninterface PrincipalPolicyWarmRuntime extends PrincipalPolicyRecoveryRuntime {\n readonly apiClient: PrincipalPolicyRecoveryRuntime[\"apiClient\"] & {\n getCurrentPrincipalPolicy(\n principalType: \"group\" | \"organization\",\n principalId: string,\n ): Promise<PrincipalPolicyBundleResponse | null>;\n };\n readonly infra: { readonly execSql: ExecSql };\n readonly util: {\n readonly log: (message: string) => void;\n readonly reportSecurityIncident: SecurityIncidentReporter;\n };\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n}\n\nexport function createRuntimePrincipalPolicyWarmer(\n runtime: PrincipalPolicyWarmRuntime,\n): ReferencedPrincipalPolicyWarmer {\n const policyInput = ({\n organizationId,\n references,\n stillCurrent,\n }: Parameters<ReferencedPrincipalPolicyWarmer>[0]) => {\n const input: Parameters<typeof cacheReferencedPrincipalPolicies>[0] = {\n execSql: runtime.infra.execSql,\n getCurrentPrincipalPolicy: (principalType, principalId) =>\n runtime.apiClient.getCurrentPrincipalPolicy(principalType, principalId),\n log: runtime.util.log,\n organizationId,\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n references,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n stillCurrent,\n };\n return input;\n };\n const warmer = async (\n input: Parameters<ReferencedPrincipalPolicyWarmer>[0],\n ) => cacheReferencedPrincipalPolicies(policyInput(input));\n const cacheBundles = (input: PrincipalPolicyBundleCacheRequest) =>\n cachePrincipalPolicyBundles({\n bundles: input.bundles,\n execSql: runtime.infra.execSql,\n getCurrentPrincipalPolicy: (principalType, principalId) =>\n runtime.apiClient.getCurrentPrincipalPolicy(principalType, principalId),\n log: runtime.util.log,\n organizationId: input.organizationId,\n reportSecurityIncident: runtime.util.reportSecurityIncident,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n stillCurrent: input.stillCurrent,\n });\n return Object.assign(warmer, {\n cacheBundles,\n resolveReference: createRuntimePrincipalPolicyResolver(runtime),\n resolveProjectionHistory: createRuntimeProjectionPolicyResolver(runtime),\n });\n}\n"]}
@@ -0,0 +1,56 @@
1
+ import { KeyingVerificationError } from "../../internal/crypto/index.js";
2
+ import { ProjectionDependencyUnavailableError } from "../../data/keyingProjectionVerification/dependencyUnavailable.js";
3
+ import { runWithSecurityIncidentReporting } from "../../data/keyingProjectionVerification/error.js";
4
+ import { assertProjectionVerificationCurrent, } from "../../data/keyingProjectionVerification/types.js";
5
+ import { readPrincipalHistoryProtection } from "../../data/principals/principalHistoryRuntime.js";
6
+ import { PrincipalPolicyHistoryReadError } from "./principalHistoryRecoveryTypes.js";
7
+ import { isPrincipalRecoveryOutage } from "./principalRecoveryOutage.js";
8
+ import { queuePrincipalRecovery } from "./principalRecoveryQueue.js";
9
+ import { recoverProjectionPolicyHistory, } from "./recoverProjectionPolicyHistory.js";
10
+ async function recoverWithOutageFallback(options) {
11
+ try {
12
+ return await recoverProjectionPolicyHistory(options);
13
+ }
14
+ catch (error) {
15
+ assertProjectionVerificationCurrent(options.stillCurrent);
16
+ if (options.offline || !isPrincipalRecoveryOutage(error))
17
+ throw error;
18
+ return recoverProjectionPolicyHistory({ ...options, offline: true });
19
+ }
20
+ }
21
+ export function createRuntimeProjectionPolicyResolver(runtime) {
22
+ const lease = readPrincipalHistoryProtection(runtime);
23
+ const readPages = runtime.apiClient.getProjectionPolicyHistoryPages?.bind(runtime.apiClient);
24
+ if (!lease || !readPages)
25
+ return undefined;
26
+ return (input) => queuePrincipalRecovery(runtime.infra.execSql, input.organizationId, () => runWithSecurityIncidentReporting(runtime.util.reportSecurityIncident, {
27
+ objectId: input.organizationId,
28
+ objectKind: "principal",
29
+ operation: "principal.projection.recover",
30
+ organizationId: input.organizationId,
31
+ }, () => lease(async ({ protection, stillCurrent: leaseCurrent }) => {
32
+ const stillCurrent = () => leaseCurrent() && input.stillCurrent?.() !== false;
33
+ assertProjectionVerificationCurrent(stillCurrent);
34
+ try {
35
+ const policies = await recoverWithOutageFallback({
36
+ ...input,
37
+ apiClient: { getProjectionPolicyHistoryPages: readPages },
38
+ execSql: runtime.infra.execSql,
39
+ protection,
40
+ stillCurrent,
41
+ offline: runtime.state?.online === false,
42
+ resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,
43
+ });
44
+ return { policies, stillCurrent };
45
+ }
46
+ catch (error) {
47
+ assertProjectionVerificationCurrent(stillCurrent);
48
+ if (error instanceof PrincipalPolicyHistoryReadError ||
49
+ (error instanceof KeyingVerificationError &&
50
+ error.code === "missing_dependency"))
51
+ throw new ProjectionDependencyUnavailableError(error.message);
52
+ throw error;
53
+ }
54
+ })));
55
+ }
56
+ //# sourceMappingURL=runtimeProjectionPolicyRecovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeProjectionPolicyRecovery.js","sourceRoot":"","sources":["runtimeProjectionPolicyRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,oCAAoC,EAAE,MAAM,+DAA+D,CAAC;AACrH,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EACL,mCAAmC,GAEpC,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAEL,8BAA8B,GAC/B,MAAM,kCAAkC,CAAC;AAG1C,KAAK,UAAU,yBAAyB,CACtC,OAA+C;IAE/C,IAAI,CAAC;QACH,OAAO,MAAM,8BAA8B,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mCAAmC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC1D,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,yBAAyB,CAAC,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QACtE,OAAO,8BAA8B,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,CAAC;AACH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AAC,OAAO,KAAK,EAAE,CAAC;YACf,mCAAmC,CAAC,YAAY,CAAC,CAAC;YAClD,IACE,KAAK,YAAY,+BAA+B;gBAChD,CAAC,KAAK,YAAY,uBAAuB;oBACvC,KAAK,CAAC,IAAI,KAAK,oBAAoB,CAAC;gBAEtC,MAAM,IAAI,oCAAoC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAChE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CACL,CACF,CAAC;AACN,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport { ProjectionDependencyUnavailableError } from \"../../data/keyingProjectionVerification/dependencyUnavailable\";\nimport { runWithSecurityIncidentReporting } from \"../../data/keyingProjectionVerification/error\";\nimport {\n assertProjectionVerificationCurrent,\n type ReferencedPrincipalPolicyWarmer,\n} from \"../../data/keyingProjectionVerification/types\";\nimport { readPrincipalHistoryProtection } from \"../../data/principals/principalHistoryRuntime\";\nimport { PrincipalPolicyHistoryReadError } from \"./principalHistoryRecoveryTypes\";\nimport { isPrincipalRecoveryOutage } from \"./principalRecoveryOutage\";\nimport { queuePrincipalRecovery } from \"./principalRecoveryQueue\";\nimport {\n type ProjectionPolicyHistoryRecoveryOptions,\n recoverProjectionPolicyHistory,\n} from \"./recoverProjectionPolicyHistory\";\nimport type { PrincipalPolicyRecoveryRuntime } from \"./runtimePolicyRecovery\";\n\nasync function recoverWithOutageFallback(\n options: ProjectionPolicyHistoryRecoveryOptions,\n) {\n try {\n return await recoverProjectionPolicyHistory(options);\n } catch (error) {\n assertProjectionVerificationCurrent(options.stillCurrent);\n if (options.offline || !isPrincipalRecoveryOutage(error)) throw error;\n return recoverProjectionPolicyHistory({ ...options, offline: true });\n }\n}\n\nexport function createRuntimeProjectionPolicyResolver(\n runtime: PrincipalPolicyRecoveryRuntime,\n): ReferencedPrincipalPolicyWarmer[\"resolveProjectionHistory\"] {\n const lease = readPrincipalHistoryProtection(runtime);\n const readPages = runtime.apiClient.getProjectionPolicyHistoryPages?.bind(\n runtime.apiClient,\n );\n if (!lease || !readPages) return undefined;\n return (input) =>\n queuePrincipalRecovery(runtime.infra.execSql, input.organizationId, () =>\n runWithSecurityIncidentReporting(\n runtime.util.reportSecurityIncident,\n {\n objectId: input.organizationId,\n objectKind: \"principal\",\n operation: \"principal.projection.recover\",\n organizationId: input.organizationId,\n },\n () =>\n lease(async ({ protection, stillCurrent: leaseCurrent }) => {\n const stillCurrent = () =>\n leaseCurrent() && input.stillCurrent?.() !== false;\n assertProjectionVerificationCurrent(stillCurrent);\n try {\n const policies = await recoverWithOutageFallback({\n ...input,\n apiClient: { getProjectionPolicyHistoryPages: readPages },\n execSql: runtime.infra.execSql,\n protection,\n stillCurrent,\n offline: runtime.state?.online === false,\n resolveTrustedUserIdentity: runtime.resolveTrustedUserIdentity,\n });\n return { policies, stillCurrent };\n } catch (error) {\n assertProjectionVerificationCurrent(stillCurrent);\n if (\n error instanceof PrincipalPolicyHistoryReadError ||\n (error instanceof KeyingVerificationError &&\n error.code === \"missing_dependency\")\n )\n throw new ProjectionDependencyUnavailableError(error.message);\n throw error;\n }\n }),\n ),\n );\n}\n"]}
@@ -0,0 +1,90 @@
1
+ import { KeyingVerificationError, PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT, selectPrincipalPolicyAuthorization, verifyPrincipalPolicyCheckpoint, verifyPrincipalPolicyHistoryReferences, } from "../../internal/crypto/index.js";
2
+ import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
3
+ import { loadPrincipalHistoryReference } from "../../data/persistence/principalHistoryEvidencePersistence.js";
4
+ import { principalHeadMatchesReference } from "../../data/principals/organizationAuthorityDescriptor.js";
5
+ import { PrincipalHistoryEvidenceUnavailableError } from "./principalHistoryRecoveryReferences.js";
6
+ async function selectBatch(input, versions, checkpointReference) {
7
+ const proofs = [];
8
+ for (const version of versions) {
9
+ assertProjectionVerificationCurrent(input.stillCurrent);
10
+ proofs.push(await loadPrincipalHistoryReference({
11
+ execSql: input.execSql,
12
+ ...input.recovered,
13
+ version,
14
+ }));
15
+ }
16
+ const selected = await verifyPrincipalPolicyHistoryReferences({
17
+ history: input.recovered.history,
18
+ references: proofs,
19
+ checkpointReference,
20
+ });
21
+ if (!selected.ok)
22
+ throw selected.error;
23
+ return selected.value;
24
+ }
25
+ async function loadCheckpointProof(input, checkpoint) {
26
+ let checkpointReference;
27
+ try {
28
+ if (checkpoint)
29
+ checkpointReference = await loadPrincipalHistoryReference({
30
+ execSql: input.execSql,
31
+ ...input.recovered,
32
+ version: checkpoint.version,
33
+ });
34
+ }
35
+ catch (error) {
36
+ if (error instanceof KeyingVerificationError)
37
+ throw new PrincipalHistoryEvidenceUnavailableError(error);
38
+ throw error;
39
+ }
40
+ return checkpointReference;
41
+ }
42
+ /** Select bounded proof batches without admitting or advancing durable pins. */
43
+ export async function selectPublicPrincipalHistory(input) {
44
+ const references = structuredClone(input.references);
45
+ const checkpoint = input.checkpoint && { ...input.checkpoint };
46
+ const head = input.recovered.history.currentEntry.state;
47
+ if (checkpoint && checkpoint.version > head.version)
48
+ throw new KeyingVerificationError("missing_dependency", "Public history cannot connect to the newer durable checkpoint");
49
+ if (references.some((reference) => reference.principalType !== head.principalType ||
50
+ reference.principalId !== head.principalId ||
51
+ reference.version > head.version))
52
+ throw new KeyingVerificationError("object_mismatch", "Public history reference is outside the verified prefix");
53
+ const versions = [
54
+ ...new Set([
55
+ ...(input.includeGenesis ? [1] : []),
56
+ ...references.map(({ version }) => version),
57
+ head.version,
58
+ ]),
59
+ ];
60
+ const policies = [];
61
+ const checkpointReference = await loadCheckpointProof(input, checkpoint);
62
+ for (let offset = 0; offset < versions.length; offset += PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT) {
63
+ const batch = versions.slice(offset, offset + PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT);
64
+ const selected = await selectBatch(input, batch, checkpointReference).catch((error) => {
65
+ if (error instanceof KeyingVerificationError)
66
+ throw new PrincipalHistoryEvidenceUnavailableError(error);
67
+ throw error;
68
+ });
69
+ // Authenticate the disposable proof before comparing caller citations or pins.
70
+ for (const reference of references.filter(({ version }) => batch.includes(version)))
71
+ if (!selected.retainedEntries.some(({ state }) => principalHeadMatchesReference(state, reference)))
72
+ throw new KeyingVerificationError("object_mismatch", "Public history citation differs from its verified entry");
73
+ verifyPrincipalPolicyCheckpoint({
74
+ chain: selected.retainedEntries.map((entry) => ({
75
+ ...entry,
76
+ projection: [...entry.projection],
77
+ grants: [...entry.grants],
78
+ })),
79
+ currentState: selected.currentEntry.state,
80
+ localCheckpoint: checkpoint,
81
+ });
82
+ const policy = await selectPrincipalPolicyAuthorization(selected);
83
+ if (!policy.ok)
84
+ throw policy.error;
85
+ policies.push(policy.value);
86
+ }
87
+ assertProjectionVerificationCurrent(input.stillCurrent);
88
+ return policies;
89
+ }
90
+ //# sourceMappingURL=selectPublicPrincipalHistory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectPublicPrincipalHistory.js","sourceRoot":"","sources":["selectPublicPrincipalHistory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,kCAAkC,EAIlC,kCAAkC,EAElC,+BAA+B,EAC/B,sCAAsC,GACvC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAC;AAC3G,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AAEtG,OAAO,EAAE,wCAAwC,EAAE,MAAM,sCAAsC,CAAC;AAYhG,KAAK,UAAU,WAAW,CACxB,KAAkC,EAClC,QAA2B,EAC3B,mBAAqE;IAErE,MAAM,MAAM,GAA2C,EAAE,CAAC;IAC1D,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACxD,MAAM,CAAC,IAA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AAC,CACF,CAAC;QACF,+EAA+E;QAC/E,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CACxD,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CACxB;YACC,IACE,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAC3C,6BAA6B,CAAC,KAAK,EAAE,SAAS,CAAC,CAChD;gBAED,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,yDAAyD,CAC1D,CAAC;QACN,+BAA+B,CAAC;YAC9B,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBAC9C,GAAG,KAAK;gBACR,UAAU,EAAE,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC;gBACjC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;aAC1B,CAAC,CAAC;YACH,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC,KAAK;YACzC,eAAe,EAAE,UAAU;SAC5B,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,kCAAkC,CAAC,QAAQ,CAAC,CAAC;QAClE,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,MAAM,MAAM,CAAC,KAAK,CAAC;QACnC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,mCAAmC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT,\n type PrincipalPolicyCheckpoint,\n type PrincipalPolicyHistoryReferenceProof,\n type ReferencedPrincipalHead,\n selectPrincipalPolicyAuthorization,\n type VerifiedPrincipalPolicySelection,\n verifyPrincipalPolicyCheckpoint,\n verifyPrincipalPolicyHistoryReferences,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalHistoryReference } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport { PrincipalHistoryEvidenceUnavailableError } from \"./principalHistoryRecoveryReferences\";\nimport type { RecoveredPublicPrincipalHistory } from \"./publicPrincipalHistoryTypes\";\n\ninterface PublicHistorySelectionInput {\n readonly execSql: ExecSql;\n readonly recovered: RecoveredPublicPrincipalHistory;\n readonly references: readonly ReferencedPrincipalHead[];\n readonly checkpoint: PrincipalPolicyCheckpoint | null;\n readonly includeGenesis?: boolean;\n readonly stillCurrent: () => boolean;\n}\n\nasync function selectBatch(\n input: PublicHistorySelectionInput,\n versions: readonly number[],\n checkpointReference: PrincipalPolicyHistoryReferenceProof | undefined,\n) {\n const proofs: PrincipalPolicyHistoryReferenceProof[] = [];\n for (const version of versions) {\n assertProjectionVerificationCurrent(input.stillCurrent);\n proofs.push(\n await loadPrincipalHistoryReference({\n execSql: input.execSql,\n ...input.recovered,\n version,\n }),\n );\n }\n const selected = await verifyPrincipalPolicyHistoryReferences({\n history: input.recovered.history,\n references: proofs,\n checkpointReference,\n });\n if (!selected.ok) throw selected.error;\n return selected.value;\n}\n\nasync function loadCheckpointProof(\n input: PublicHistorySelectionInput,\n checkpoint: PrincipalPolicyCheckpoint | null,\n): Promise<PrincipalPolicyHistoryReferenceProof | undefined> {\n let checkpointReference: PrincipalPolicyHistoryReferenceProof | undefined;\n try {\n if (checkpoint)\n checkpointReference = await loadPrincipalHistoryReference({\n execSql: input.execSql,\n ...input.recovered,\n version: checkpoint.version,\n });\n } catch (error) {\n if (error instanceof KeyingVerificationError)\n throw new PrincipalHistoryEvidenceUnavailableError(error);\n throw error;\n }\n return checkpointReference;\n}\n\n/** Select bounded proof batches without admitting or advancing durable pins. */\nexport async function selectPublicPrincipalHistory(\n input: PublicHistorySelectionInput,\n): Promise<VerifiedPrincipalPolicySelection[]> {\n const references = structuredClone(input.references);\n const checkpoint = input.checkpoint && { ...input.checkpoint };\n const head = input.recovered.history.currentEntry.state;\n if (checkpoint && checkpoint.version > head.version)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Public history cannot connect to the newer durable checkpoint\",\n );\n if (\n references.some(\n (reference) =>\n reference.principalType !== head.principalType ||\n reference.principalId !== head.principalId ||\n reference.version > head.version,\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Public history reference is outside the verified prefix\",\n );\n const versions = [\n ...new Set([\n ...(input.includeGenesis ? [1] : []),\n ...references.map(({ version }) => version),\n head.version,\n ]),\n ];\n const policies: VerifiedPrincipalPolicySelection[] = [];\n const checkpointReference = await loadCheckpointProof(input, checkpoint);\n for (\n let offset = 0;\n offset < versions.length;\n offset += PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT\n ) {\n const batch = versions.slice(\n offset,\n offset + PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT,\n );\n const selected = await selectBatch(input, batch, checkpointReference).catch(\n (error: unknown) => {\n if (error instanceof KeyingVerificationError)\n throw new PrincipalHistoryEvidenceUnavailableError(error);\n throw error;\n },\n );\n // Authenticate the disposable proof before comparing caller citations or pins.\n for (const reference of references.filter(({ version }) =>\n batch.includes(version),\n ))\n if (\n !selected.retainedEntries.some(({ state }) =>\n principalHeadMatchesReference(state, reference),\n )\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Public history citation differs from its verified entry\",\n );\n verifyPrincipalPolicyCheckpoint({\n chain: selected.retainedEntries.map((entry) => ({\n ...entry,\n projection: [...entry.projection],\n grants: [...entry.grants],\n })),\n currentState: selected.currentEntry.state,\n localCheckpoint: checkpoint,\n });\n const policy = await selectPrincipalPolicyAuthorization(selected);\n if (!policy.ok) throw policy.error;\n policies.push(policy.value);\n }\n assertProjectionVerificationCurrent(input.stillCurrent);\n return policies;\n}\n"]}
@@ -66,177 +66,45 @@ export declare function buildInitialRootProvisioning(input: {
66
66
  rootContainerProjection: {
67
67
  policyEvidence: {
68
68
  organization: {
69
- currentGrants: {
70
- accessLevel: "admin" | "read" | "write";
71
- containerId: string;
72
- }[];
73
- currentProjection: {
74
- role: "member" | "admin";
75
- userId: string;
76
- }[];
77
- currentState: {
78
- createdAt: string;
79
- encapsulationPublicKey: string;
80
- externalAuthority: {
81
- keyEpoch: number;
82
- keyFingerprint: string;
83
- principalId: string;
84
- principalType: "group";
85
- stateHash: string;
86
- version: number;
87
- } | null;
88
- grantCount: number;
89
- grantRoot: string;
69
+ head: {
90
70
  keyEpoch: number;
91
71
  keyFingerprint: string;
92
- memberCount: number;
93
- memberEnvelopesRoot: string;
94
- membershipMode: "projection";
95
- membershipRoot: string;
96
- payloadCiphertextHash: string;
97
- prevStateHash: string | null;
98
72
  principalId: string;
99
73
  principalType: "group" | "organization";
100
- projectionRoot: string;
101
- signature: string;
102
- signedAt: string;
103
- signerUserId: string;
104
- signerUserKeyFingerprint: string;
105
74
  stateHash: string;
106
75
  version: number;
107
76
  };
108
- previousStates: {
109
- grants: {
110
- accessLevel: "admin" | "read" | "write";
111
- containerId: string;
112
- }[];
113
- projection: {
114
- role: "member" | "admin";
115
- userId: string;
116
- }[];
117
- state: {
118
- createdAt: string;
119
- encapsulationPublicKey: string;
120
- externalAuthority: {
121
- keyEpoch: number;
122
- keyFingerprint: string;
123
- principalId: string;
124
- principalType: "group";
125
- stateHash: string;
126
- version: number;
127
- } | null;
128
- grantCount: number;
129
- grantRoot: string;
130
- keyEpoch: number;
131
- keyFingerprint: string;
132
- memberCount: number;
133
- memberEnvelopesRoot: string;
134
- membershipMode: "projection";
135
- membershipRoot: string;
136
- payloadCiphertextHash: string;
137
- prevStateHash: string | null;
138
- principalId: string;
139
- principalType: "group" | "organization";
140
- projectionRoot: string;
141
- signature: string;
142
- signedAt: string;
143
- signerUserId: string;
144
- signerUserKeyFingerprint: string;
145
- stateHash: string;
146
- version: number;
147
- };
148
- }[];
77
+ grant: string;
149
78
  } | null;
150
79
  organizationPayloads: {
151
- cipherSuite: "aes-256-gcm";
152
- ciphertext: string;
153
- ciphertextHash: string;
154
- createdAt: string;
155
- principalId: string;
156
- principalType: "group" | "organization";
157
- stateHash: string;
80
+ reference: {
81
+ keyEpoch: number;
82
+ keyFingerprint: string;
83
+ principalId: string;
84
+ principalType: "group" | "organization";
85
+ stateHash: string;
86
+ version: number;
87
+ };
88
+ payload: {
89
+ cipherSuite: "aes-256-gcm";
90
+ ciphertext: string;
91
+ ciphertextHash: string;
92
+ createdAt: string;
93
+ principalId: string;
94
+ principalType: "group" | "organization";
95
+ stateHash: string;
96
+ };
158
97
  }[];
159
98
  groups: {
160
- currentGrants: {
161
- accessLevel: "admin" | "read" | "write";
162
- containerId: string;
163
- }[];
164
- currentProjection: {
165
- role: "member" | "admin";
166
- userId: string;
167
- }[];
168
- currentState: {
169
- createdAt: string;
170
- encapsulationPublicKey: string;
171
- externalAuthority: {
172
- keyEpoch: number;
173
- keyFingerprint: string;
174
- principalId: string;
175
- principalType: "group";
176
- stateHash: string;
177
- version: number;
178
- } | null;
179
- grantCount: number;
180
- grantRoot: string;
99
+ head: {
181
100
  keyEpoch: number;
182
101
  keyFingerprint: string;
183
- memberCount: number;
184
- memberEnvelopesRoot: string;
185
- membershipMode: "projection";
186
- membershipRoot: string;
187
- payloadCiphertextHash: string;
188
- prevStateHash: string | null;
189
102
  principalId: string;
190
103
  principalType: "group" | "organization";
191
- projectionRoot: string;
192
- signature: string;
193
- signedAt: string;
194
- signerUserId: string;
195
- signerUserKeyFingerprint: string;
196
104
  stateHash: string;
197
105
  version: number;
198
106
  };
199
- previousStates: {
200
- grants: {
201
- accessLevel: "admin" | "read" | "write";
202
- containerId: string;
203
- }[];
204
- projection: {
205
- role: "member" | "admin";
206
- userId: string;
207
- }[];
208
- state: {
209
- createdAt: string;
210
- encapsulationPublicKey: string;
211
- externalAuthority: {
212
- keyEpoch: number;
213
- keyFingerprint: string;
214
- principalId: string;
215
- principalType: "group";
216
- stateHash: string;
217
- version: number;
218
- } | null;
219
- grantCount: number;
220
- grantRoot: string;
221
- keyEpoch: number;
222
- keyFingerprint: string;
223
- memberCount: number;
224
- memberEnvelopesRoot: string;
225
- membershipMode: "projection";
226
- membershipRoot: string;
227
- payloadCiphertextHash: string;
228
- prevStateHash: string | null;
229
- principalId: string;
230
- principalType: "group" | "organization";
231
- projectionRoot: string;
232
- signature: string;
233
- signedAt: string;
234
- signerUserId: string;
235
- signerUserKeyFingerprint: string;
236
- stateHash: string;
237
- version: number;
238
- };
239
- }[];
107
+ grant: string;
240
108
  }[];
241
109
  };
242
110
  containerId: string;