@tearleads/client-sdk 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/client/Tearleads.d.ts +2 -0
  2. package/client/Tearleads.js +1 -0
  3. package/client/Tearleads.js.map +1 -1
  4. package/client/index.d.ts +1 -1
  5. package/client/index.js.map +1 -1
  6. package/client/organizations/currentPrincipalMutations.js +96 -0
  7. package/client/organizations/currentPrincipalMutations.js.map +1 -0
  8. package/client/organizations/index.d.ts +4 -42
  9. package/client/organizations/index.js +17 -3
  10. package/client/organizations/index.js.map +1 -1
  11. package/client/organizations/organizationGroupHistory.js +44 -0
  12. package/client/organizations/organizationGroupHistory.js.map +1 -0
  13. package/client/organizations/organizationGroupNameHydration.js +14 -1
  14. package/client/organizations/organizationGroupNameHydration.js.map +1 -1
  15. package/client/organizations/organizationGroupPresentation.d.ts +1 -0
  16. package/client/organizations/organizationGroupPresentation.js +16 -2
  17. package/client/organizations/organizationGroupPresentation.js.map +1 -1
  18. package/client/organizations/organizationReadModels.d.ts +1 -1
  19. package/client/organizations/organizationReadModels.js +11 -1
  20. package/client/organizations/organizationReadModels.js.map +1 -1
  21. package/client/organizations/organizationsTypes.d.ts +50 -0
  22. package/client/organizations/organizationsTypes.js +2 -0
  23. package/client/organizations/organizationsTypes.js.map +1 -0
  24. package/client/organizations/principalContainerMutations.js +2 -0
  25. package/client/organizations/principalContainerMutations.js.map +1 -1
  26. package/client/organizations/principalMutationRecovery.d.ts +16 -0
  27. package/client/organizations/principalMutationRecovery.js +23 -0
  28. package/client/organizations/principalMutationRecovery.js.map +1 -0
  29. package/client/organizations/principalMutationScope.js +7 -2
  30. package/client/organizations/principalMutationScope.js.map +1 -1
  31. package/client/organizations/principalMutations.d.ts +4 -308
  32. package/client/organizations/principalMutations.js +165 -87
  33. package/client/organizations/principalMutations.js.map +1 -1
  34. package/client/principalMutationApi.d.ts +24 -0
  35. package/client/principalMutationApi.js +108 -0
  36. package/client/principalMutationApi.js.map +1 -0
  37. package/client/principalMutationDeadline.js +23 -0
  38. package/client/principalMutationDeadline.js.map +1 -0
  39. package/client/workflowRuntime.d.ts +3 -1
  40. package/client/workflowRuntime.js +44 -5
  41. package/client/workflowRuntime.js.map +1 -1
  42. package/data/persistence/principalCurrentAcknowledgementPersistence.d.ts +27 -0
  43. package/data/persistence/principalCurrentAcknowledgementPersistence.js +116 -0
  44. package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -0
  45. package/data/persistence/principalGrantRetirementPersistence.d.ts +3 -3
  46. package/data/persistence/principalGrantRetirementPersistence.js +4 -1
  47. package/data/persistence/principalGrantRetirementPersistence.js.map +1 -1
  48. package/data/persistence/principalKeyEnvelopeCandidates.js +12 -1
  49. package/data/persistence/principalKeyEnvelopeCandidates.js.map +1 -1
  50. package/data/persistence/principalMutationJournalPersistence.d.ts +19 -0
  51. package/data/persistence/principalMutationJournalPersistence.js +53 -0
  52. package/data/persistence/principalMutationJournalPersistence.js.map +1 -0
  53. package/data/persistence/verifiedPrincipalPolicyBundle.js +7 -51
  54. package/data/persistence/verifiedPrincipalPolicyBundle.js.map +1 -1
  55. package/data/persistence/verifiedPrincipalPolicyCurrent.js +56 -0
  56. package/data/persistence/verifiedPrincipalPolicyCurrent.js.map +1 -0
  57. package/data/principals/currentPolicyReferenceResolver.js +2 -0
  58. package/data/principals/currentPolicyReferenceResolver.js.map +1 -0
  59. package/data/principals/principalHistoryScopeProtection.js +23 -0
  60. package/data/principals/principalHistoryScopeProtection.js.map +1 -0
  61. package/data/principals/principalMutationJournal.d.ts +26 -0
  62. package/data/principals/principalMutationJournal.js +90 -0
  63. package/data/principals/principalMutationJournal.js.map +1 -0
  64. package/data/principals/principalMutationJournalRecord.d.ts +8 -0
  65. package/data/principals/principalMutationJournalRecord.js +25 -0
  66. package/data/principals/principalMutationJournalRecord.js.map +1 -0
  67. package/data/principals/principalPolicyAdminSigners.js.map +1 -1
  68. package/data/sqlite/principalHistoryStageSchema.js +3 -0
  69. package/data/sqlite/principalHistoryStageSchema.js.map +1 -1
  70. package/data/sqlite/principalMutationJournalSchema.d.ts +85 -0
  71. package/data/sqlite/principalMutationJournalSchema.js +13 -0
  72. package/data/sqlite/principalMutationJournalSchema.js.map +1 -0
  73. package/data/sqlite/schema.d.ts +83 -0
  74. package/data/sqlite/schema.js +3 -0
  75. package/data/sqlite/schema.js.map +1 -1
  76. package/index.d.ts +3 -3
  77. package/index.js +1 -1
  78. package/index.js.map +1 -1
  79. package/internal/crypto/index.d.ts +1 -1
  80. package/internal/crypto/index.js +1 -1
  81. package/internal/crypto/index.js.map +1 -1
  82. package/internal/crypto/keying/index.d.ts +3 -0
  83. package/internal/crypto/keying/index.js +3 -0
  84. package/internal/crypto/keying/index.js.map +1 -1
  85. package/internal/crypto/keying/principalPolicyCurrent.d.ts +1 -1
  86. package/internal/crypto/keying/principalPolicyCurrent.js +3 -3
  87. package/internal/crypto/keying/principalPolicyCurrent.js.map +1 -1
  88. package/internal/crypto/keying/principalPolicyCurrentEvidence.js +16 -0
  89. package/internal/crypto/keying/principalPolicyCurrentEvidence.js.map +1 -0
  90. package/internal/crypto/keying/principalPolicyCurrentMutation.d.ts +10 -0
  91. package/internal/crypto/keying/principalPolicyCurrentMutation.js +51 -0
  92. package/internal/crypto/keying/principalPolicyCurrentMutation.js.map +1 -0
  93. package/internal/crypto/keying/principalPolicyCurrentPredecessorReferences.d.ts +8 -0
  94. package/internal/crypto/keying/principalPolicyCurrentPredecessorReferences.js +46 -0
  95. package/internal/crypto/keying/principalPolicyCurrentPredecessorReferences.js.map +1 -0
  96. package/internal/crypto/keying/principalPolicyCurrentSuccessor.d.ts +10 -0
  97. package/internal/crypto/keying/principalPolicyCurrentSuccessor.js +60 -0
  98. package/internal/crypto/keying/principalPolicyCurrentSuccessor.js.map +1 -0
  99. package/internal/crypto/keying/principalPolicyHistory.js +4 -1
  100. package/internal/crypto/keying/principalPolicyHistory.js.map +1 -1
  101. package/internal/crypto/keying/principalPolicyHistoryReferences.js +1 -1
  102. package/internal/crypto/keying/principalPolicyHistoryReferences.js.map +1 -1
  103. package/internal/crypto/keying/principalPolicyHistoryTypes.d.ts +5 -2
  104. package/internal/crypto/keying/principalPolicyHistoryTypes.js +6 -3
  105. package/internal/crypto/keying/principalPolicyHistoryTypes.js.map +1 -1
  106. package/package.json +1 -1
  107. package/workflows/containers/child/carriedDescendantRekeys.js +9 -1
  108. package/workflows/containers/child/carriedDescendantRekeys.js.map +1 -1
  109. package/workflows/containers/child/replacementPrincipalPolicyReferences.js +19 -0
  110. package/workflows/containers/child/replacementPrincipalPolicyReferences.js.map +1 -0
  111. package/workflows/containers/child/share.js +4 -0
  112. package/workflows/containers/child/share.js.map +1 -1
  113. package/workflows/containers/child/sharePrincipalPolicy.d.ts +1 -0
  114. package/workflows/containers/child/sharePrincipalPolicy.js.map +1 -1
  115. package/workflows/organizations/acknowledgedDirectoryBindings.js +18 -0
  116. package/workflows/organizations/acknowledgedDirectoryBindings.js.map +1 -0
  117. package/workflows/organizations/commitCurrentGroupPolicyMutation.js +72 -0
  118. package/workflows/organizations/commitCurrentGroupPolicyMutation.js.map +1 -0
  119. package/workflows/organizations/createCurrentOrganizationGroup.js +85 -0
  120. package/workflows/organizations/createCurrentOrganizationGroup.js.map +1 -0
  121. package/workflows/organizations/currentGroupMetadataAuthority.js +53 -0
  122. package/workflows/organizations/currentGroupMetadataAuthority.js.map +1 -0
  123. package/workflows/organizations/currentGroupMutationReferences.js +35 -0
  124. package/workflows/organizations/currentGroupMutationReferences.js.map +1 -0
  125. package/workflows/organizations/currentGroupPolicyMutationContext.js +79 -0
  126. package/workflows/organizations/currentGroupPolicyMutationContext.js.map +1 -0
  127. package/workflows/organizations/currentOrganizationAuthority.js +88 -0
  128. package/workflows/organizations/currentOrganizationAuthority.js.map +1 -0
  129. package/workflows/organizations/currentOrganizationGroupNames.js +72 -0
  130. package/workflows/organizations/currentOrganizationGroupNames.js.map +1 -0
  131. package/workflows/organizations/currentOrganizationMutationAuthority.js +16 -0
  132. package/workflows/organizations/currentOrganizationMutationAuthority.js.map +1 -0
  133. package/workflows/organizations/currentOrganizationMutationRetention.js +53 -0
  134. package/workflows/organizations/currentOrganizationMutationRetention.js.map +1 -0
  135. package/workflows/organizations/currentPolicyMutationAcknowledgement.js +65 -0
  136. package/workflows/organizations/currentPolicyMutationAcknowledgement.js.map +1 -0
  137. package/workflows/organizations/currentPrincipalMutationLease.js +38 -0
  138. package/workflows/organizations/currentPrincipalMutationLease.js.map +1 -0
  139. package/workflows/organizations/deleteCurrentOrganizationGroup.js +35 -0
  140. package/workflows/organizations/deleteCurrentOrganizationGroup.js.map +1 -0
  141. package/workflows/organizations/deleteOrganizationGroup.d.ts +1 -0
  142. package/workflows/organizations/deleteOrganizationGroup.js +11 -0
  143. package/workflows/organizations/deleteOrganizationGroup.js.map +1 -1
  144. package/workflows/organizations/groupCreation.d.ts +1 -0
  145. package/workflows/organizations/groupCreation.js +9 -0
  146. package/workflows/organizations/groupCreation.js.map +1 -1
  147. package/workflows/organizations/groupMembershipName.d.ts +1 -1
  148. package/workflows/organizations/groupMembershipName.js.map +1 -1
  149. package/workflows/organizations/groupMetadataAccess.d.ts +2 -2
  150. package/workflows/organizations/groupMetadataAccess.js +1 -1
  151. package/workflows/organizations/groupMetadataAccess.js.map +1 -1
  152. package/workflows/organizations/groupMetadataBinding.js.map +1 -1
  153. package/workflows/organizations/groupMetadataContainerAuthority.js +2 -47
  154. package/workflows/organizations/groupMetadataContainerAuthority.js.map +1 -1
  155. package/workflows/organizations/groupMetadataRootBinding.js +51 -0
  156. package/workflows/organizations/groupMetadataRootBinding.js.map +1 -0
  157. package/workflows/organizations/groupMetadataRuntime.js +26 -10
  158. package/workflows/organizations/groupMetadataRuntime.js.map +1 -1
  159. package/workflows/organizations/groupMutationAuthorization.js.map +1 -1
  160. package/workflows/organizations/groupNameUniqueness.js +1 -1
  161. package/workflows/organizations/groupNameUniqueness.js.map +1 -1
  162. package/workflows/organizations/groupPolicyHistoryPage.js +31 -0
  163. package/workflows/organizations/groupPolicyHistoryPage.js.map +1 -0
  164. package/workflows/organizations/groupPolicyMutationAcknowledgement.js +10 -75
  165. package/workflows/organizations/groupPolicyMutationAcknowledgement.js.map +1 -1
  166. package/workflows/organizations/groupPolicyMutationContext.d.ts +23 -13
  167. package/workflows/organizations/groupPolicyMutationContext.js +2 -1
  168. package/workflows/organizations/groupPolicyMutationContext.js.map +1 -1
  169. package/workflows/organizations/groupPolicyMutationEvidence.d.ts +26 -0
  170. package/workflows/organizations/groupPolicyMutationEvidence.js +64 -0
  171. package/workflows/organizations/groupPolicyMutationEvidence.js.map +1 -0
  172. package/workflows/organizations/groupPolicyMutationHead.js.map +1 -1
  173. package/workflows/organizations/groupPolicyRequests.js +69 -63
  174. package/workflows/organizations/groupPolicyRequests.js.map +1 -1
  175. package/workflows/organizations/index.d.ts +6 -0
  176. package/workflows/organizations/index.js +5 -0
  177. package/workflows/organizations/index.js.map +1 -1
  178. package/workflows/organizations/initialPrincipalCurrentPublication.js +83 -0
  179. package/workflows/organizations/initialPrincipalCurrentPublication.js.map +1 -0
  180. package/workflows/organizations/organizationGroupDirectory.js +6 -0
  181. package/workflows/organizations/organizationGroupDirectory.js.map +1 -1
  182. package/workflows/organizations/organizationGroupNames.js +7 -0
  183. package/workflows/organizations/organizationGroupNames.js.map +1 -1
  184. package/workflows/organizations/policyHistoryTypes.d.ts +2 -0
  185. package/workflows/organizations/policyHistoryTypes.js.map +1 -1
  186. package/workflows/organizations/principalContainerRematerialization.js +12 -2
  187. package/workflows/organizations/principalContainerRematerialization.js.map +1 -1
  188. package/workflows/organizations/principalContainerRematerializationPlanning.js +1 -0
  189. package/workflows/organizations/principalContainerRematerializationPlanning.js.map +1 -1
  190. package/workflows/organizations/principalContainerRematerializationTargets.js.map +1 -1
  191. package/workflows/organizations/principalCurrentPublicationSeal.js +51 -0
  192. package/workflows/organizations/principalCurrentPublicationSeal.js.map +1 -0
  193. package/workflows/organizations/principalMutationJournalLane.js +26 -0
  194. package/workflows/organizations/principalMutationJournalLane.js.map +1 -0
  195. package/workflows/organizations/principalMutationJournalManagement.d.ts +26 -0
  196. package/workflows/organizations/principalMutationJournalManagement.js +104 -0
  197. package/workflows/organizations/principalMutationJournalManagement.js.map +1 -0
  198. package/workflows/organizations/principalMutationJournalSession.d.ts +26 -0
  199. package/workflows/organizations/principalMutationJournalSession.js +85 -0
  200. package/workflows/organizations/principalMutationJournalSession.js.map +1 -0
  201. package/workflows/organizations/principalMutationReceipt.js +21 -0
  202. package/workflows/organizations/principalMutationReceipt.js.map +1 -0
  203. package/workflows/organizations/principalPolicyReceiptArtifacts.js +74 -0
  204. package/workflows/organizations/principalPolicyReceiptArtifacts.js.map +1 -0
  205. package/workflows/organizations/principalPolicyRequest.d.ts +5 -4
  206. package/workflows/organizations/principalPolicyRequest.js.map +1 -1
  207. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.d.ts +23 -0
  208. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js +159 -0
  209. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js.map +1 -0
  210. package/workflows/organizations/runtimeCurrentGroupMutation.js +85 -0
  211. package/workflows/organizations/runtimeCurrentGroupMutation.js.map +1 -0
  212. package/workflows/organizations/runtimeCurrentOrganizationMutation.js +48 -0
  213. package/workflows/organizations/runtimeCurrentOrganizationMutation.js.map +1 -0
  214. package/workflows/principals/loadRecoveredPrincipalHistoryPage.d.ts +11 -0
  215. package/workflows/principals/loadRecoveredPrincipalHistoryPage.js +120 -0
  216. package/workflows/principals/loadRecoveredPrincipalHistoryPage.js.map +1 -0
  217. package/workflows/principals/principalCurrentRecoveryBatch.js +14 -0
  218. package/workflows/principals/principalCurrentRecoveryBatch.js.map +1 -0
  219. package/workflows/principals/principalHistoryRecoveryReferences.js +8 -0
  220. package/workflows/principals/principalHistoryRecoveryReferences.js.map +1 -1
  221. package/workflows/principals/principalRecoveryDirectory.d.ts +1 -1
  222. package/workflows/principals/principalRecoveryDirectory.js +32 -12
  223. package/workflows/principals/principalRecoveryDirectory.js.map +1 -1
  224. package/workflows/principals/principalRecoveryDiscoveryPage.js +36 -0
  225. package/workflows/principals/principalRecoveryDiscoveryPage.js.map +1 -0
  226. package/workflows/principals/principalRecoveryLocalPreference.js +29 -0
  227. package/workflows/principals/principalRecoveryLocalPreference.js.map +1 -0
  228. package/workflows/principals/principalRecoveryMemo.d.ts +16 -0
  229. package/workflows/principals/principalRecoveryMemo.js +88 -16
  230. package/workflows/principals/principalRecoveryMemo.js.map +1 -1
  231. package/workflows/principals/recoverCurrentOrganizationPolicy.js +33 -0
  232. package/workflows/principals/recoverCurrentOrganizationPolicy.js.map +1 -0
  233. package/workflows/principals/recoverPrincipalHistoryPage.js +30 -0
  234. package/workflows/principals/recoverPrincipalHistoryPage.js.map +1 -0
  235. package/workflows/principals/recoverPrincipalPolicyHistory.d.ts +2 -0
  236. package/workflows/principals/recoverPrincipalPolicyHistory.js +14 -2
  237. package/workflows/principals/recoverPrincipalPolicyHistory.js.map +1 -1
  238. package/workflows/principals/recoverScopedPrincipalPolicyHistory.d.ts +8 -1
  239. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js +30 -20
  240. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js.map +1 -1
  241. package/workflows/principals/runtimePolicyRecovery.js +36 -9
  242. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  243. package/workflows/principals/runtimePolicyWarmer.js +2 -2
  244. package/workflows/principals/runtimePolicyWarmer.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAC7F,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,OAAO,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B,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EAClC,gCAAgC,GACjC,MAAM,oBAAoB,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAC7B,cAAc,eAAe,CAAC","sourcesContent":["export * from \"./accessEvent\";\nexport * from \"./accessManifestSnapshot\";\nexport { ACCESS_MANIFEST_VERIFICATION_REVISION } from \"./accessManifestVerificationRevision\";\nexport * from \"./canonical\";\nexport * from \"./checkpoints\";\nexport * from \"./containerAccess\";\nexport { MAX_CONTAINER_RECITATION_EPOCH } from \"./containerAccessReciteBody\";\nexport * from \"./containerKek\";\nexport {\n assertSealedContainerKekKeyringLength,\n CONTAINER_KEK_KEYRING_ENTRY_BYTES,\n CONTAINER_KEK_KEYRING_FORMAT_VERSION,\n CONTAINER_KEK_KEYRING_HEADER_BYTES,\n computeContainerKekKeyringHash,\n expectedSealedContainerKekKeyringBytes,\n normalizeContainerKekKeyring,\n openContainerKekKeyring,\n sealContainerKekKeyring,\n verifyContainerKekKeyringEntry,\n} from \"./containerKekKeyring\";\nexport {\n computeContainerKekPredecessorBridgeHash,\n createContainerKekPredecessorBridge,\n normalizeContainerKekPredecessorBridge,\n unwrapContainerKekPredecessorBridge,\n} from \"./containerKekPredecessor\";\nexport {\n deriveContainerKekWrappingPublicKey,\n unwrapContainerKekParentWrap,\n} from \"./containerKekWrapping\";\nexport { resolveContainerStatePathUserAccessLevel } from \"./containerPathAccess\";\nexport * from \"./documentAccess\";\nexport {\n type DocumentPurgeAccessEventBody,\n normalizeDocumentPurgeAccessEventBody,\n type VerifyDocumentPurgeEventInput,\n verifyDocumentPurgeEvent,\n} from \"./documentPurge\";\nexport * from \"./principalPolicy\";\nexport { verifyPrincipalPolicyBundleAgainstHistory } from \"./principalPolicyBundleHistory\";\nexport {\n type PrincipalPolicyCurrent,\n type VerifiedPrincipalPolicyCurrent,\n verifyPrincipalPolicyCurrent,\n} from \"./principalPolicyCurrent\";\nexport type {\n PrincipalPolicyExternalAuthority,\n PrincipalPolicyExternalAuthorityState,\n} from \"./principalPolicyExternalAuthorityTypes\";\nexport {\n createPrincipalPolicyHistoryVerifier,\n restorePrincipalPolicyHistoryVerifier,\n} from \"./principalPolicyHistory\";\nexport type { PrincipalHistoryIndexNode } from \"./principalPolicyHistoryIndex\";\nexport {\n createPrincipalHistoryIndexProof,\n principalHistoryIndexLeaf,\n resolvePrincipalHistoryIndexProof,\n} from \"./principalPolicyHistoryIndex\";\nexport { PRINCIPAL_HISTORY_VERIFICATION_REVISION } from \"./principalPolicyHistoryPage\";\nexport type { PrincipalPolicyHistoryReferenceProof } from \"./principalPolicyHistoryReferences\";\nexport { verifyPrincipalPolicyHistoryReferences } from \"./principalPolicyHistoryReferences\";\nexport type {\n PrincipalPolicyHistoryInput,\n PrincipalPolicyHistoryPage,\n PrincipalPolicyHistoryProgressOptions,\n PrincipalPolicyHistoryVerifier,\n VerifiedPrincipalPolicyHistory,\n} from \"./principalPolicyHistoryTypes\";\nexport { PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT } from \"./principalPolicyHistoryTypes\";\nexport {\n selectPrincipalPolicyAuthorization,\n type VerifiedPrincipalPolicySelection,\n} from \"./principalPolicySelection\";\nexport type {\n PrincipalPolicyTransitionMismatch,\n PrincipalPolicyTransitionMismatchCode,\n} from \"./principalPolicyTransition\";\nexport {\n getPrincipalPolicyTransitionMismatch,\n getPrincipalPolicyTransitionMismatchReason,\n} from \"./principalPolicyTransition\";\nexport * from \"./transparency\";\nexport {\n type VerifyTransparencyConsistencyProofInput,\n type VerifyTransparencyInclusionProofInput,\n verifyTransparencyConsistencyProof,\n verifyTransparencyInclusionProof,\n} from \"./transparencyProofs\";\nexport {\n computeTransparencyMerkleRoot,\n createTransparencyConsistencyProof,\n createTransparencyInclusionProof,\n} from \"./transparencyTree\";\nexport * from \"./types\";\nexport {\n isKeyingVerificationCode,\n KEYING_VERIFICATION_CODES,\n} from \"./verificationError\";\nexport * from \"./writeHeader\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAC7F,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAC7E,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,qCAAqC,EACrC,iCAAiC,EACjC,oCAAoC,EACpC,kCAAkC,EAClC,8BAA8B,EAC9B,sCAAsC,EACtC,4BAA4B,EAC5B,uBAAuB,EACvB,uBAAuB,EACvB,8BAA8B,GAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,wCAAwC,EACxC,mCAAmC,EACnC,sCAAsC,EACtC,mCAAmC,GACpC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,mCAAmC,EACnC,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,wCAAwC,EAAE,MAAM,uBAAuB,CAAC;AACjF,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAEL,qCAAqC,EAErC,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,yCAAyC,EAAE,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EAGL,4BAA4B,GAC7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oCAAoC,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EAAE,iDAAiD,EAAE,MAAM,+CAA+C,CAAC;AAClH,OAAO,EAAE,qCAAqC,EAAE,MAAM,mCAAmC,CAAC;AAK1F,OAAO,EACL,oCAAoC,EACpC,qCAAqC,GACtC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,gCAAgC,EAChC,yBAAyB,EACzB,iCAAiC,GAClC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,uCAAuC,EAAE,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAE,sCAAsC,EAAE,MAAM,oCAAoC,CAAC;AAQ5F,OAAO,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EACL,kCAAkC,GAEnC,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EACL,oCAAoC,EACpC,0CAA0C,GAC3C,MAAM,6BAA6B,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAGL,kCAAkC,EAClC,gCAAgC,GACjC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EAClC,gCAAgC,GACjC,MAAM,oBAAoB,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAC7B,cAAc,eAAe,CAAC","sourcesContent":["export * from \"./accessEvent\";\nexport * from \"./accessManifestSnapshot\";\nexport { ACCESS_MANIFEST_VERIFICATION_REVISION } from \"./accessManifestVerificationRevision\";\nexport * from \"./canonical\";\nexport * from \"./checkpoints\";\nexport * from \"./containerAccess\";\nexport { MAX_CONTAINER_RECITATION_EPOCH } from \"./containerAccessReciteBody\";\nexport * from \"./containerKek\";\nexport {\n assertSealedContainerKekKeyringLength,\n CONTAINER_KEK_KEYRING_ENTRY_BYTES,\n CONTAINER_KEK_KEYRING_FORMAT_VERSION,\n CONTAINER_KEK_KEYRING_HEADER_BYTES,\n computeContainerKekKeyringHash,\n expectedSealedContainerKekKeyringBytes,\n normalizeContainerKekKeyring,\n openContainerKekKeyring,\n sealContainerKekKeyring,\n verifyContainerKekKeyringEntry,\n} from \"./containerKekKeyring\";\nexport {\n computeContainerKekPredecessorBridgeHash,\n createContainerKekPredecessorBridge,\n normalizeContainerKekPredecessorBridge,\n unwrapContainerKekPredecessorBridge,\n} from \"./containerKekPredecessor\";\nexport {\n deriveContainerKekWrappingPublicKey,\n unwrapContainerKekParentWrap,\n} from \"./containerKekWrapping\";\nexport { resolveContainerStatePathUserAccessLevel } from \"./containerPathAccess\";\nexport * from \"./documentAccess\";\nexport {\n type DocumentPurgeAccessEventBody,\n normalizeDocumentPurgeAccessEventBody,\n type VerifyDocumentPurgeEventInput,\n verifyDocumentPurgeEvent,\n} from \"./documentPurge\";\nexport * from \"./principalPolicy\";\nexport { verifyPrincipalPolicyBundleAgainstHistory } from \"./principalPolicyBundleHistory\";\nexport {\n type PrincipalPolicyCurrent,\n type VerifiedPrincipalPolicyCurrent,\n verifyPrincipalPolicyCurrent,\n} from \"./principalPolicyCurrent\";\nexport { verifyPrincipalPolicyCurrentMutation } from \"./principalPolicyCurrentMutation\";\nexport { selectPrincipalPolicyCurrentPredecessorReferences } from \"./principalPolicyCurrentPredecessorReferences\";\nexport { verifyPrincipalPolicyCurrentSuccessor } from \"./principalPolicyCurrentSuccessor\";\nexport type {\n PrincipalPolicyExternalAuthority,\n PrincipalPolicyExternalAuthorityState,\n} from \"./principalPolicyExternalAuthorityTypes\";\nexport {\n createPrincipalPolicyHistoryVerifier,\n restorePrincipalPolicyHistoryVerifier,\n} from \"./principalPolicyHistory\";\nexport type { PrincipalHistoryIndexNode } from \"./principalPolicyHistoryIndex\";\nexport {\n createPrincipalHistoryIndexProof,\n principalHistoryIndexLeaf,\n resolvePrincipalHistoryIndexProof,\n} from \"./principalPolicyHistoryIndex\";\nexport { PRINCIPAL_HISTORY_VERIFICATION_REVISION } from \"./principalPolicyHistoryPage\";\nexport type { PrincipalPolicyHistoryReferenceProof } from \"./principalPolicyHistoryReferences\";\nexport { verifyPrincipalPolicyHistoryReferences } from \"./principalPolicyHistoryReferences\";\nexport type {\n PrincipalPolicyHistoryInput,\n PrincipalPolicyHistoryPage,\n PrincipalPolicyHistoryProgressOptions,\n PrincipalPolicyHistoryVerifier,\n VerifiedPrincipalPolicyHistory,\n} from \"./principalPolicyHistoryTypes\";\nexport { PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT } from \"./principalPolicyHistoryTypes\";\nexport {\n selectPrincipalPolicyAuthorization,\n type VerifiedPrincipalPolicySelection,\n} from \"./principalPolicySelection\";\nexport type {\n PrincipalPolicyTransitionMismatch,\n PrincipalPolicyTransitionMismatchCode,\n} from \"./principalPolicyTransition\";\nexport {\n getPrincipalPolicyTransitionMismatch,\n getPrincipalPolicyTransitionMismatchReason,\n} from \"./principalPolicyTransition\";\nexport * from \"./transparency\";\nexport {\n type VerifyTransparencyConsistencyProofInput,\n type VerifyTransparencyInclusionProofInput,\n verifyTransparencyConsistencyProof,\n verifyTransparencyInclusionProof,\n} from \"./transparencyProofs\";\nexport {\n computeTransparencyMerkleRoot,\n createTransparencyConsistencyProof,\n createTransparencyInclusionProof,\n} from \"./transparencyTree\";\nexport * from \"./types\";\nexport {\n isKeyingVerificationCode,\n KEYING_VERIFICATION_CODES,\n} from \"./verificationError\";\nexport * from \"./writeHeader\";\n"]}
@@ -1,5 +1,5 @@
1
1
  import { type VerifiedPrincipalPolicyHistory } from "./principalPolicyHistoryTypes.js";
2
- import { type PrincipalPolicyCurrent, type VerifiedPrincipalPolicyCurrent } from "./principalPolicyTypes.js";
2
+ import type { PrincipalPolicyCurrent, VerifiedPrincipalPolicyCurrent } from "./principalPolicyTypes.js";
3
3
  import type { KeyingVerificationResult } from "./types.js";
4
4
  export type { PrincipalPolicyCurrent, VerifiedPrincipalPolicyCurrent, } from "./principalPolicyTypes.js";
5
5
  /**
@@ -1,9 +1,9 @@
1
1
  import { normalizePrincipalPolicyStateChainEntry } from "./principalPolicyChainEntry.js";
2
+ import { issueVerifiedPrincipalPolicyCurrent } from "./principalPolicyCurrentEvidence.js";
2
3
  import { ownVerifiedPrincipalPolicyHistory, } from "./principalPolicyHistoryTypes.js";
3
4
  import { verifyPrincipalPolicyMemberEnvelopes } from "./principalPolicyMemberEnvelopes.js";
4
5
  import { verifyPrincipalPolicyPayload } from "./principalPolicyPayload.js";
5
6
  import { principalPolicyStateMatchesReference } from "./principalPolicyReference.js";
6
- import { makeVerifiedPrincipalPolicyCurrent, } from "./principalPolicyTypes.js";
7
7
  import { runVerifier, throwVerification } from "./shared.js";
8
8
  // Adapt owned readonly evidence to the mutable arrays in policy result types.
9
9
  function mutableEntry(entry) {
@@ -35,7 +35,7 @@ export function verifyPrincipalPolicyCurrent(input) {
35
35
  throwVerification("hash_mismatch", "current principal policy does not match verified history");
36
36
  await verifyPrincipalPolicyPayload({ bundle: current });
37
37
  await verifyPrincipalPolicyMemberEnvelopes({ bundle: current });
38
- return makeVerifiedPrincipalPolicyCurrent({
38
+ return issueVerifiedPrincipalPolicyCurrent({
39
39
  principalType: entry.state.principalType,
40
40
  principalId: entry.state.principalId,
41
41
  version: entry.state.version,
@@ -51,7 +51,7 @@ export function verifyPrincipalPolicyCurrent(input) {
51
51
  version: entry.state.version,
52
52
  stateHash: entry.state.stateHash,
53
53
  },
54
- });
54
+ }, history.latestAuthority);
55
55
  });
56
56
  }
57
57
  //# sourceMappingURL=principalPolicyCurrent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"principalPolicyCurrent.js","sourceRoot":"","sources":["principalPolicyCurrent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EACL,iCAAiC,GAElC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,oCAAoC,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,oCAAoC,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EACL,kCAAkC,GAGnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAW1D,8EAA8E;AAC9E,SAAS,YAAY,CAAC,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AE,OAAO,EAAE,CAAC,CAAC;QAChE,OAAO,kCAAkC,CAAC;YACxC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,aAAa;YACxC,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW;YACpC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;YAC5B,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ;YAC9B,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;YAChC,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,eAAe,EAAE,QAAQ;YACzB,UAAU,EAAE;gBACV,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,aAAa;gBACxC,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW;gBACpC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;gBAC5B,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;aACjC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { normalizePrincipalPolicyStateChainEntry } from \"./principalPolicyChainEntry\";\nimport {\n ownVerifiedPrincipalPolicyHistory,\n type VerifiedPrincipalPolicyHistory,\n} from \"./principalPolicyHistoryTypes\";\nimport { verifyPrincipalPolicyMemberEnvelopes } from \"./principalPolicyMemberEnvelopes\";\nimport { verifyPrincipalPolicyPayload } from \"./principalPolicyPayload\";\nimport { principalPolicyStateMatchesReference } from \"./principalPolicyReference\";\nimport {\n makeVerifiedPrincipalPolicyCurrent,\n type PrincipalPolicyCurrent,\n type VerifiedPrincipalPolicyCurrent,\n} from \"./principalPolicyTypes\";\nimport { runVerifier, throwVerification } from \"./shared\";\nimport type {\n KeyingVerificationResult,\n PrincipalPolicyStateChainEntry,\n} from \"./types\";\n\nexport type {\n PrincipalPolicyCurrent,\n VerifiedPrincipalPolicyCurrent,\n} from \"./principalPolicyTypes\";\n\n// Adapt owned readonly evidence to the mutable arrays in policy result types.\nfunction mutableEntry(entry: PrincipalPolicyStateChainEntry) {\n return {\n state: structuredClone(entry.state),\n projection: entry.projection.map((member) => ({ ...member })),\n grants: entry.grants.map((grant) => ({ ...grant })),\n };\n}\n\n/**\n * Authenticate current keying artifacts against a prefix already verified by\n * this runtime. The returned history contains only explicitly retained entries.\n */\nexport function verifyPrincipalPolicyCurrent(input: {\n readonly current: PrincipalPolicyCurrent;\n readonly history: VerifiedPrincipalPolicyHistory;\n}): Promise<KeyingVerificationResult<VerifiedPrincipalPolicyCurrent>> {\n return runVerifier(async () => {\n const current = structuredClone(input.current);\n const history = ownVerifiedPrincipalPolicyHistory(input.history);\n const expected = history.currentEntry;\n const retained = history.retainedEntries.map(mutableEntry);\n const entry = await normalizePrincipalPolicyStateChainEntry({\n state: current.currentState,\n projection: current.currentProjection,\n grants: current.currentGrants,\n });\n // The state hash commits the signed header, not its signature bytes. Keep\n // both tied to the accepted entry when validating rows read from storage.\n if (\n !principalPolicyStateMatchesReference(entry.state, expected.state) ||\n entry.state.signature !== expected.state.signature\n )\n throwVerification(\n \"hash_mismatch\",\n \"current principal policy does not match verified history\",\n );\n await verifyPrincipalPolicyPayload({ bundle: current });\n await verifyPrincipalPolicyMemberEnvelopes({ bundle: current });\n return makeVerifiedPrincipalPolicyCurrent({\n principalType: entry.state.principalType,\n principalId: entry.state.principalId,\n version: entry.state.version,\n keyEpoch: entry.state.keyEpoch,\n stateHash: entry.state.stateHash,\n state: entry.state,\n projection: entry.projection,\n grants: entry.grants,\n retainedHistory: retained,\n checkpoint: {\n principalType: entry.state.principalType,\n principalId: entry.state.principalId,\n version: entry.state.version,\n stateHash: entry.state.stateHash,\n },\n });\n });\n}\n"]}
1
+ {"version":3,"file":"principalPolicyCurrent.js","sourceRoot":"","sources":["principalPolicyCurrent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,6BAA6B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AAC,aAAa;SAC9B,CAAC,CAAC;QACH,0EAA0E;QAC1E,0EAA0E;QAC1E,IACE,CAAC,oCAAoC,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC;YAClE,KAAK,CAAC,KAAK,CAAC,SAAS,KAAK,QAAQ,CAAC,KAAK,CAAC,SAAS;YAElD,iBAAiB,CACf,eAAe,EACf,0DAA0D,CAC3D,CAAC;QACJ,MAAM,4BAA4B,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,MAAM,oCAAoC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAChE,OAAO,mCAAmC,CACxC;YACE,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,aAAa;YACxC,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW;YACpC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;YAC5B,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ;YAC9B,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;YAChC,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,eAAe,EAAE,QAAQ;YACzB,UAAU,EAAE;gBACV,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,aAAa;gBACxC,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW;gBACpC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;gBAC5B,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;aACjC;SACF,EACD,OAAO,CAAC,eAAe,CACxB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { normalizePrincipalPolicyStateChainEntry } from \"./principalPolicyChainEntry\";\nimport { issueVerifiedPrincipalPolicyCurrent } from \"./principalPolicyCurrentEvidence\";\nimport {\n ownVerifiedPrincipalPolicyHistory,\n type VerifiedPrincipalPolicyHistory,\n} from \"./principalPolicyHistoryTypes\";\nimport { verifyPrincipalPolicyMemberEnvelopes } from \"./principalPolicyMemberEnvelopes\";\nimport { verifyPrincipalPolicyPayload } from \"./principalPolicyPayload\";\nimport { principalPolicyStateMatchesReference } from \"./principalPolicyReference\";\nimport type {\n PrincipalPolicyCurrent,\n VerifiedPrincipalPolicyCurrent,\n} from \"./principalPolicyTypes\";\nimport { runVerifier, throwVerification } from \"./shared\";\nimport type {\n KeyingVerificationResult,\n PrincipalPolicyStateChainEntry,\n} from \"./types\";\n\nexport type {\n PrincipalPolicyCurrent,\n VerifiedPrincipalPolicyCurrent,\n} from \"./principalPolicyTypes\";\n\n// Adapt owned readonly evidence to the mutable arrays in policy result types.\nfunction mutableEntry(entry: PrincipalPolicyStateChainEntry) {\n return {\n state: structuredClone(entry.state),\n projection: entry.projection.map((member) => ({ ...member })),\n grants: entry.grants.map((grant) => ({ ...grant })),\n };\n}\n\n/**\n * Authenticate current keying artifacts against a prefix already verified by\n * this runtime. The returned history contains only explicitly retained entries.\n */\nexport function verifyPrincipalPolicyCurrent(input: {\n readonly current: PrincipalPolicyCurrent;\n readonly history: VerifiedPrincipalPolicyHistory;\n}): Promise<KeyingVerificationResult<VerifiedPrincipalPolicyCurrent>> {\n return runVerifier(async () => {\n const current = structuredClone(input.current);\n const history = ownVerifiedPrincipalPolicyHistory(input.history);\n const expected = history.currentEntry;\n const retained = history.retainedEntries.map(mutableEntry);\n const entry = await normalizePrincipalPolicyStateChainEntry({\n state: current.currentState,\n projection: current.currentProjection,\n grants: current.currentGrants,\n });\n // The state hash commits the signed header, not its signature bytes. Keep\n // both tied to the accepted entry when validating rows read from storage.\n if (\n !principalPolicyStateMatchesReference(entry.state, expected.state) ||\n entry.state.signature !== expected.state.signature\n )\n throwVerification(\n \"hash_mismatch\",\n \"current principal policy does not match verified history\",\n );\n await verifyPrincipalPolicyPayload({ bundle: current });\n await verifyPrincipalPolicyMemberEnvelopes({ bundle: current });\n return issueVerifiedPrincipalPolicyCurrent(\n {\n principalType: entry.state.principalType,\n principalId: entry.state.principalId,\n version: entry.state.version,\n keyEpoch: entry.state.keyEpoch,\n stateHash: entry.state.stateHash,\n state: entry.state,\n projection: entry.projection,\n grants: entry.grants,\n retainedHistory: retained,\n checkpoint: {\n principalType: entry.state.principalType,\n principalId: entry.state.principalId,\n version: entry.state.version,\n stateHash: entry.state.stateHash,\n },\n },\n history.latestAuthority,\n );\n });\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { makeVerifiedPrincipalPolicyCurrent, } from "./principalPolicyTypes.js";
2
+ import { throwVerification } from "./shared.js";
3
+ const issued = new WeakMap();
4
+ /** Keep the verified predecessor and historical authority cursor private. */
5
+ export function issueVerifiedPrincipalPolicyCurrent(value, latestAuthority) {
6
+ const result = makeVerifiedPrincipalPolicyCurrent(value);
7
+ issued.set(result, structuredClone({ policy: value, latestAuthority }));
8
+ return result;
9
+ }
10
+ export function ownVerifiedPrincipalPolicyCurrent(policy) {
11
+ const snapshot = issued.get(policy);
12
+ if (!snapshot)
13
+ throwVerification("invalid_shape", "current policy must come from a local verifier");
14
+ return structuredClone(snapshot);
15
+ }
16
+ //# sourceMappingURL=principalPolicyCurrentEvidence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"principalPolicyCurrentEvidence.js","sourceRoot":"","sources":["principalPolicyCurrentEvidence.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kCAAkC,GAEnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG7C,MAAM,MAAM,GAAG,IAAI,OAAO,EAMvB,CAAC;AAEJ,6EAA6E;AAC7E,MAAM,UAAU,mCAAmC,CACjD,KAAmB,EACnB,eAAuD;IAEvD,MAAM,MAAM,GAAG,kCAAkC,CAAC,KAAK,CAAC,CAAC;IACzD,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,MAAsC;IAEtC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,CAAC,QAAQ;QACX,iBAAiB,CACf,eAAe,EACf,gDAAgD,CACjD,CAAC;IACJ,OAAO,eAAe,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type { PrincipalStateExternalAuthority } from \"../principalState\";\nimport {\n makeVerifiedPrincipalPolicyCurrent,\n type VerifiedPrincipalPolicyCurrent,\n} from \"./principalPolicyTypes\";\nimport { throwVerification } from \"./shared\";\n\ntype CurrentValue = Parameters<typeof makeVerifiedPrincipalPolicyCurrent>[0];\nconst issued = new WeakMap<\n VerifiedPrincipalPolicyCurrent,\n {\n policy: CurrentValue;\n latestAuthority: PrincipalStateExternalAuthority | null;\n }\n>();\n\n/** Keep the verified predecessor and historical authority cursor private. */\nexport function issueVerifiedPrincipalPolicyCurrent(\n value: CurrentValue,\n latestAuthority: PrincipalStateExternalAuthority | null,\n): VerifiedPrincipalPolicyCurrent {\n const result = makeVerifiedPrincipalPolicyCurrent(value);\n issued.set(result, structuredClone({ policy: value, latestAuthority }));\n return result;\n}\n\nexport function ownVerifiedPrincipalPolicyCurrent(\n policy: VerifiedPrincipalPolicyCurrent,\n) {\n const snapshot = issued.get(policy);\n if (!snapshot)\n throwVerification(\n \"invalid_shape\",\n \"current policy must come from a local verifier\",\n );\n return structuredClone(snapshot);\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { PrincipalPolicyExternalAuthority } from "./principalPolicyExternalAuthorityTypes.js";
2
+ import type { PrincipalPolicyCurrent, VerifiedPrincipalPolicyCurrent } from "./principalPolicyTypes.js";
3
+ import type { KeyingVerificationResult } from "./types.js";
4
+ /** Bind a group's current artifacts and next signer to privately issued evidence. */
5
+ export declare function verifyPrincipalPolicyCurrentMutation(input: {
6
+ readonly current: PrincipalPolicyCurrent;
7
+ readonly policy: VerifiedPrincipalPolicyCurrent;
8
+ readonly signerUserId: string;
9
+ readonly externalAuthority?: PrincipalPolicyExternalAuthority | undefined;
10
+ }): Promise<KeyingVerificationResult<VerifiedPrincipalPolicyCurrent>>;
@@ -0,0 +1,51 @@
1
+ import { normalizePrincipalPolicyStateChainEntry } from "./principalPolicyChainEntry.js";
2
+ import { issueVerifiedPrincipalPolicyCurrent, ownVerifiedPrincipalPolicyCurrent, } from "./principalPolicyCurrentEvidence.js";
3
+ import { createPrincipalPolicyExternalAuthorityVerifier, externalAuthorityIncludesAdminSigner, verifyPrincipalPolicyExternalAuthorityProgress, } from "./principalPolicyExternalAuthority.js";
4
+ import { verifyPrincipalPolicyMemberEnvelopes } from "./principalPolicyMemberEnvelopes.js";
5
+ import { verifyPrincipalPolicyPayload } from "./principalPolicyPayload.js";
6
+ import { principalPolicyStateMatchesReference } from "./principalPolicyReference.js";
7
+ import { runVerifier, throwVerification } from "./shared.js";
8
+ /** Bind a group's current artifacts and next signer to privately issued evidence. */
9
+ export function verifyPrincipalPolicyCurrentMutation(input) {
10
+ return runVerifier(async () => {
11
+ const prior = ownVerifiedPrincipalPolicyCurrent(input.policy);
12
+ const current = structuredClone(input.current);
13
+ const externalAuthority = structuredClone(input.externalAuthority);
14
+ const signerUserId = input.signerUserId;
15
+ const entry = await normalizePrincipalPolicyStateChainEntry({
16
+ state: current.currentState,
17
+ projection: current.currentProjection,
18
+ grants: current.currentGrants,
19
+ });
20
+ if (!principalPolicyStateMatchesReference(entry.state, prior.policy.state) ||
21
+ entry.state.signature !== prior.policy.state.signature)
22
+ throwVerification("hash_mismatch", "current artifacts differ from issued policy evidence");
23
+ if (entry.state.principalType !== "group")
24
+ throwVerification("object_mismatch", "group mutation requires a group policy");
25
+ await verifyPrincipalPolicyPayload({ bundle: current });
26
+ await verifyPrincipalPolicyMemberEnvelopes({ bundle: current });
27
+ if (!entry.projection.some((member) => member.userId === signerUserId && member.role === "admin")) {
28
+ const authority = createPrincipalPolicyExternalAuthorityVerifier({
29
+ authority: externalAuthority,
30
+ });
31
+ authority.latestReference = prior.latestAuthority;
32
+ const next = {
33
+ state: {
34
+ signerUserId,
35
+ externalAuthority: externalAuthority?.currentHead ?? null,
36
+ },
37
+ };
38
+ verifyPrincipalPolicyExternalAuthorityProgress({
39
+ entry: next,
40
+ verifier: authority,
41
+ });
42
+ if (!externalAuthorityIncludesAdminSigner({
43
+ entry: next,
44
+ verifier: authority,
45
+ }))
46
+ throwVerification("unauthorized", "group mutation signer is not an authority admin");
47
+ }
48
+ return issueVerifiedPrincipalPolicyCurrent(prior.policy, prior.latestAuthority);
49
+ });
50
+ }
51
+ //# sourceMappingURL=principalPolicyCurrentMutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"principalPolicyCurrentMutation.js","sourceRoot":"","sources":["principalPolicyCurrentMutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EACL,mCAAmC,EACnC,iCAAiC,GAClC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,8CAA8C,EAC9C,oCAAoC,EACpC,8CAA8C,GAC/C,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,oCAAoC,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,oCAAoC,EAAE,MAAM,4BAA4B,CAAC;AAKlF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG1D,qFAAqF;AACrF,MAAM,UAAU,oCAAoC,CAAC,KAKpD;IACC,OAAO,WAAW,CAAC,KAAK,IAAI,EAAE;QAC5B,MAAM,KAAK,GAAG,iCAAiC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9D,MAAM,OAA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iBAC1D;aACF,CAAC;YACF,8CAA8C,CAAC;gBAC7C,KAAK,EAAE,IAAI;gBACX,QAAQ,EAAE,SAAS;aACpB,CAAC,CAAC;YACH,IACE,CAAC,oCAAoC,CAAC;gBACpC,KAAK,EAAE,IAAI;gBACX,QAAQ,EAAE,SAAS;aACpB,CAAC;gBAEF,iBAAiB,CACf,cAAc,EACd,iDAAiD,CAClD,CAAC;QACN,CAAC;QACD,OAAO,mCAAmC,CACxC,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,eAAe,CACtB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { normalizePrincipalPolicyStateChainEntry } from \"./principalPolicyChainEntry\";\nimport {\n issueVerifiedPrincipalPolicyCurrent,\n ownVerifiedPrincipalPolicyCurrent,\n} from \"./principalPolicyCurrentEvidence\";\nimport {\n createPrincipalPolicyExternalAuthorityVerifier,\n externalAuthorityIncludesAdminSigner,\n verifyPrincipalPolicyExternalAuthorityProgress,\n} from \"./principalPolicyExternalAuthority\";\nimport type { PrincipalPolicyExternalAuthority } from \"./principalPolicyExternalAuthorityTypes\";\nimport { verifyPrincipalPolicyMemberEnvelopes } from \"./principalPolicyMemberEnvelopes\";\nimport { verifyPrincipalPolicyPayload } from \"./principalPolicyPayload\";\nimport { principalPolicyStateMatchesReference } from \"./principalPolicyReference\";\nimport type {\n PrincipalPolicyCurrent,\n VerifiedPrincipalPolicyCurrent,\n} from \"./principalPolicyTypes\";\nimport { runVerifier, throwVerification } from \"./shared\";\nimport type { KeyingVerificationResult } from \"./types\";\n\n/** Bind a group's current artifacts and next signer to privately issued evidence. */\nexport function verifyPrincipalPolicyCurrentMutation(input: {\n readonly current: PrincipalPolicyCurrent;\n readonly policy: VerifiedPrincipalPolicyCurrent;\n readonly signerUserId: string;\n readonly externalAuthority?: PrincipalPolicyExternalAuthority | undefined;\n}): Promise<KeyingVerificationResult<VerifiedPrincipalPolicyCurrent>> {\n return runVerifier(async () => {\n const prior = ownVerifiedPrincipalPolicyCurrent(input.policy);\n const current = structuredClone(input.current);\n const externalAuthority = structuredClone(input.externalAuthority);\n const signerUserId = input.signerUserId;\n const entry = await normalizePrincipalPolicyStateChainEntry({\n state: current.currentState,\n projection: current.currentProjection,\n grants: current.currentGrants,\n });\n if (\n !principalPolicyStateMatchesReference(entry.state, prior.policy.state) ||\n entry.state.signature !== prior.policy.state.signature\n )\n throwVerification(\n \"hash_mismatch\",\n \"current artifacts differ from issued policy evidence\",\n );\n if (entry.state.principalType !== \"group\")\n throwVerification(\n \"object_mismatch\",\n \"group mutation requires a group policy\",\n );\n await verifyPrincipalPolicyPayload({ bundle: current });\n await verifyPrincipalPolicyMemberEnvelopes({ bundle: current });\n if (\n !entry.projection.some(\n (member) => member.userId === signerUserId && member.role === \"admin\",\n )\n ) {\n const authority = createPrincipalPolicyExternalAuthorityVerifier({\n authority: externalAuthority,\n });\n authority.latestReference = prior.latestAuthority;\n const next = {\n state: {\n signerUserId,\n externalAuthority: externalAuthority?.currentHead ?? null,\n },\n };\n verifyPrincipalPolicyExternalAuthorityProgress({\n entry: next,\n verifier: authority,\n });\n if (\n !externalAuthorityIncludesAdminSigner({\n entry: next,\n verifier: authority,\n })\n )\n throwVerification(\n \"unauthorized\",\n \"group mutation signer is not an authority admin\",\n );\n }\n return issueVerifiedPrincipalPolicyCurrent(\n prior.policy,\n prior.latestAuthority,\n );\n });\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { VerifiedPrincipalPolicyCurrent } from "./principalPolicyTypes.js";
2
+ import type { KeyingVerificationResult, ReferencedPrincipalHead } from "./types.js";
3
+ /** Carry selected authenticated citations across one privately verified successor. */
4
+ export declare function selectPrincipalPolicyCurrentPredecessorReferences(input: {
5
+ readonly current: VerifiedPrincipalPolicyCurrent;
6
+ readonly predecessor: VerifiedPrincipalPolicyCurrent;
7
+ readonly references: readonly ReferencedPrincipalHead[];
8
+ }): KeyingVerificationResult<VerifiedPrincipalPolicyCurrent>;
@@ -0,0 +1,46 @@
1
+ import { issueVerifiedPrincipalPolicyCurrent, ownVerifiedPrincipalPolicyCurrent, } from "./principalPolicyCurrentEvidence.js";
2
+ import { normalizePrincipalHistoryInput } from "./principalPolicyHistoryChecks.js";
3
+ import { principalPolicyStateMatchesReference } from "./principalPolicyReference.js";
4
+ import { ok, throwVerification, toVerificationResult } from "./shared.js";
5
+ /** Carry selected authenticated citations across one privately verified successor. */
6
+ export function selectPrincipalPolicyCurrentPredecessorReferences(input) {
7
+ try {
8
+ const current = ownVerifiedPrincipalPolicyCurrent(input.current);
9
+ const predecessor = ownVerifiedPrincipalPolicyCurrent(input.predecessor);
10
+ const { references } = normalizePrincipalHistoryInput({
11
+ principalId: current.policy.principalId,
12
+ principalType: current.policy.principalType,
13
+ retainedReferences: input.references,
14
+ });
15
+ if (predecessor.policy.principalType !== current.policy.principalType ||
16
+ predecessor.policy.principalId !== current.policy.principalId ||
17
+ predecessor.policy.version + 1 !== current.policy.version ||
18
+ predecessor.policy.stateHash !== current.policy.state.prevStateHash)
19
+ throwVerification("stale_predecessor", "Selected history must belong to the exact verified predecessor");
20
+ const retained = new Map();
21
+ for (const policy of [predecessor.policy, current.policy])
22
+ retained.set(policy.version, {
23
+ state: policy.state,
24
+ projection: policy.projection,
25
+ grants: policy.grants,
26
+ });
27
+ for (const reference of references) {
28
+ const entry = [
29
+ ...current.policy.retainedHistory,
30
+ ...predecessor.policy.retainedHistory,
31
+ ].find(({ state }) => principalPolicyStateMatchesReference(state, reference));
32
+ if (!entry)
33
+ throwVerification("missing_dependency", "Requested predecessor citation was not privately verified");
34
+ retained.set(entry.state.version, entry);
35
+ }
36
+ // At most the history reference budget plus the predecessor/successor pair.
37
+ return ok(issueVerifiedPrincipalPolicyCurrent({
38
+ ...current.policy,
39
+ retainedHistory: [...retained.values()].sort((left, right) => left.state.version - right.state.version),
40
+ }, current.latestAuthority));
41
+ }
42
+ catch (error) {
43
+ return toVerificationResult(error);
44
+ }
45
+ }
46
+ //# sourceMappingURL=principalPolicyCurrentPredecessorReferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"principalPolicyCurrentPredecessorReferences.js","sourceRoot":"","sources":["principalPolicyCurrentPredecessorReferences.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EACnC,iCAAiC,GAClC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,oCAAoC,EAAE,MAAM,4BAA4B,CAAC;AAElF,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAOvE,sFAAsF;AACtF,MAAM,UAAU,iDAAiD,CAAC,KAIjE;IACC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,iCAAiC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjE,MAAM,WAAW,GAAG,iCAAiC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACzE,MAAM,EAAE,UAAU,EAAE,GAAG,8BAA8B,CAAC;YACpD,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW;YACvC,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa;YAC3C,kBAAkB,EAAE,KAAK,CAAC,UAAU;SACrC,CAAC,CAAC;QACH,IACE,WAAW,CAAC,MAAM,CAAC,aAAa,KAAK,OAAO,CAAC,MAAM,CAAC,aAAa;YACjE,WAAW,CAAC,MAAM,CAAC,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,WAAW;YAC7D,WAAW,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,OAAO;YACzD,WAAW,CAAC,MAAM,CAAC,SAAS,KAAK,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa;YAEnE,iBAAiB,CACf,mBAAmB,EACnB,gEAAgE,CACjE,CAAC;QACJ,MAAM,QAAQ,GAAG,IAAI,GAAG,EAGrB,CAAC;QACJ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CurrentEvidence\";\nimport { normalizePrincipalHistoryInput } from \"./principalPolicyHistoryChecks\";\nimport { principalPolicyStateMatchesReference } from \"./principalPolicyReference\";\nimport type { VerifiedPrincipalPolicyCurrent } from \"./principalPolicyTypes\";\nimport { ok, throwVerification, toVerificationResult } from \"./shared\";\nimport type {\n KeyingVerificationResult,\n NormalizedPrincipalPolicyStateChainEntry,\n ReferencedPrincipalHead,\n} from \"./types\";\n\n/** Carry selected authenticated citations across one privately verified successor. */\nexport function selectPrincipalPolicyCurrentPredecessorReferences(input: {\n readonly current: VerifiedPrincipalPolicyCurrent;\n readonly predecessor: VerifiedPrincipalPolicyCurrent;\n readonly references: readonly ReferencedPrincipalHead[];\n}): KeyingVerificationResult<VerifiedPrincipalPolicyCurrent> {\n try {\n const current = ownVerifiedPrincipalPolicyCurrent(input.current);\n const predecessor = ownVerifiedPrincipalPolicyCurrent(input.predecessor);\n const { references } = normalizePrincipalHistoryInput({\n principalId: current.policy.principalId,\n principalType: current.policy.principalType,\n retainedReferences: input.references,\n });\n if (\n predecessor.policy.principalType !== current.policy.principalType ||\n predecessor.policy.principalId !== current.policy.principalId ||\n predecessor.policy.version + 1 !== current.policy.version ||\n predecessor.policy.stateHash !== current.policy.state.prevStateHash\n )\n throwVerification(\n \"stale_predecessor\",\n \"Selected history must belong to the exact verified predecessor\",\n );\n const retained = new Map<\n number,\n NormalizedPrincipalPolicyStateChainEntry\n >();\n for (const policy of [predecessor.policy, current.policy])\n retained.set(policy.version, {\n state: policy.state,\n projection: policy.projection,\n grants: policy.grants,\n });\n for (const reference of references) {\n const entry = [\n ...current.policy.retainedHistory,\n ...predecessor.policy.retainedHistory,\n ].find(({ state }) =>\n principalPolicyStateMatchesReference(state, reference),\n );\n if (!entry)\n throwVerification(\n \"missing_dependency\",\n \"Requested predecessor citation was not privately verified\",\n );\n retained.set(entry.state.version, entry);\n }\n // At most the history reference budget plus the predecessor/successor pair.\n return ok(\n issueVerifiedPrincipalPolicyCurrent(\n {\n ...current.policy,\n retainedHistory: [...retained.values()].sort(\n (left, right) => left.state.version - right.state.version,\n ),\n },\n current.latestAuthority,\n ),\n );\n } catch (error) {\n return toVerificationResult(error);\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { PrincipalPolicyExternalAuthority } from "./principalPolicyExternalAuthorityTypes.js";
2
+ import type { PrincipalPolicyCurrent, VerifiedPrincipalPolicyCurrent } from "./principalPolicyTypes.js";
3
+ import type { KeyingVerificationResult, PrincipalPolicySignerPublicKey } from "./types.js";
4
+ /** Verify one successor of locally verified current evidence, retaining only that pair. */
5
+ export declare function verifyPrincipalPolicyCurrentSuccessor(input: {
6
+ readonly previous: VerifiedPrincipalPolicyCurrent;
7
+ readonly current: PrincipalPolicyCurrent;
8
+ readonly signerPublicKeys: readonly PrincipalPolicySignerPublicKey[];
9
+ readonly externalAuthority?: PrincipalPolicyExternalAuthority | undefined;
10
+ }): Promise<KeyingVerificationResult<VerifiedPrincipalPolicyCurrent>>;
@@ -0,0 +1,60 @@
1
+ import { normalizePrincipalPolicyStateChainEntry } from "./principalPolicyChainEntry.js";
2
+ import { issueVerifiedPrincipalPolicyCurrent, ownVerifiedPrincipalPolicyCurrent, } from "./principalPolicyCurrentEvidence.js";
3
+ import { verifyPrincipalHistoryPage } from "./principalPolicyHistoryPage.js";
4
+ import { verifyPrincipalPolicyMemberEnvelopes } from "./principalPolicyMemberEnvelopes.js";
5
+ import { verifyPrincipalPolicyPayload } from "./principalPolicyPayload.js";
6
+ import { runVerifier } from "./shared.js";
7
+ /** Verify one successor of locally verified current evidence, retaining only that pair. */
8
+ export function verifyPrincipalPolicyCurrentSuccessor(input) {
9
+ return runVerifier(async () => {
10
+ const prior = ownVerifiedPrincipalPolicyCurrent(input.previous);
11
+ const current = structuredClone(input.current);
12
+ const signerPublicKeys = structuredClone(input.signerPublicKeys);
13
+ const externalAuthority = structuredClone(input.externalAuthority);
14
+ const previous = await normalizePrincipalPolicyStateChainEntry({
15
+ state: prior.policy.state,
16
+ projection: prior.policy.projection,
17
+ grants: prior.policy.grants,
18
+ });
19
+ const checked = await verifyPrincipalHistoryPage({
20
+ principalId: prior.policy.principalId,
21
+ principalType: prior.policy.principalType,
22
+ previous,
23
+ latestAuthority: prior.latestAuthority,
24
+ references: [],
25
+ checkpoint: null,
26
+ page: {
27
+ entries: [
28
+ {
29
+ state: current.currentState,
30
+ projection: current.currentProjection,
31
+ grants: current.currentGrants,
32
+ },
33
+ ],
34
+ signerPublicKeys,
35
+ ...(externalAuthority ? { externalAuthority } : {}),
36
+ },
37
+ });
38
+ await verifyPrincipalPolicyPayload({ bundle: current });
39
+ await verifyPrincipalPolicyMemberEnvelopes({ bundle: current });
40
+ const { state, projection, grants } = checked.last;
41
+ return issueVerifiedPrincipalPolicyCurrent({
42
+ principalId: state.principalId,
43
+ principalType: state.principalType,
44
+ version: state.version,
45
+ keyEpoch: state.keyEpoch,
46
+ stateHash: state.stateHash,
47
+ state,
48
+ projection,
49
+ grants,
50
+ retainedHistory: [previous, checked.last],
51
+ checkpoint: {
52
+ principalId: state.principalId,
53
+ principalType: state.principalType,
54
+ version: state.version,
55
+ stateHash: state.stateHash,
56
+ },
57
+ }, checked.latestAuthority);
58
+ });
59
+ }
60
+ //# sourceMappingURL=principalPolicyCurrentSuccessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"principalPolicyCurrentSuccessor.js","sourceRoot":"","sources":["principalPolicyCurrentSuccessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EACL,mCAAmC,EACnC,iCAAiC,GAClC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,oCAAoC,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAKxE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAA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MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAChE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;QACnD,OAAO,mCAAmC,CACxC;YACE,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,aAAa,EAAE,KAAK,CAAC,aAAa;YAClC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,KAAK;YACL,UAAU;YACV,MAAM;YACN,eAAe,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC;YACzC,UAAU,EAAE;gBACV,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,aAAa,EAAE,KAAK,CAAC,aAAa;gBAClC,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,SAAS,EAAE,KAAK,CAAC,SAAS;aAC3B;SACF,EACD,OAAO,CAAC,eAAe,CACxB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { normalizePrincipalPolicyStateChainEntry } from \"./principalPolicyChainEntry\";\nimport {\n issueVerifiedPrincipalPolicyCurrent,\n ownVerifiedPrincipalPolicyCurrent,\n} from \"./principalPolicyCurrentEvidence\";\nimport type { PrincipalPolicyExternalAuthority } from \"./principalPolicyExternalAuthorityTypes\";\nimport { verifyPrincipalHistoryPage } from \"./principalPolicyHistoryPage\";\nimport { verifyPrincipalPolicyMemberEnvelopes } from \"./principalPolicyMemberEnvelopes\";\nimport { verifyPrincipalPolicyPayload } from \"./principalPolicyPayload\";\nimport type {\n PrincipalPolicyCurrent,\n VerifiedPrincipalPolicyCurrent,\n} from \"./principalPolicyTypes\";\nimport { runVerifier } from \"./shared\";\nimport type {\n KeyingVerificationResult,\n PrincipalPolicySignerPublicKey,\n} from \"./types\";\n\n/** Verify one successor of locally verified current evidence, retaining only that pair. */\nexport function verifyPrincipalPolicyCurrentSuccessor(input: {\n readonly previous: VerifiedPrincipalPolicyCurrent;\n readonly current: PrincipalPolicyCurrent;\n readonly signerPublicKeys: readonly PrincipalPolicySignerPublicKey[];\n readonly externalAuthority?: PrincipalPolicyExternalAuthority | undefined;\n}): Promise<KeyingVerificationResult<VerifiedPrincipalPolicyCurrent>> {\n return runVerifier(async () => {\n const prior = ownVerifiedPrincipalPolicyCurrent(input.previous);\n const current = structuredClone(input.current);\n const signerPublicKeys = structuredClone(input.signerPublicKeys);\n const externalAuthority = structuredClone(input.externalAuthority);\n const previous = await normalizePrincipalPolicyStateChainEntry({\n state: prior.policy.state,\n projection: prior.policy.projection,\n grants: prior.policy.grants,\n });\n const checked = await verifyPrincipalHistoryPage({\n principalId: prior.policy.principalId,\n principalType: prior.policy.principalType,\n previous,\n latestAuthority: prior.latestAuthority,\n references: [],\n checkpoint: null,\n page: {\n entries: [\n {\n state: current.currentState,\n projection: current.currentProjection,\n grants: current.currentGrants,\n },\n ],\n signerPublicKeys,\n ...(externalAuthority ? { externalAuthority } : {}),\n },\n });\n await verifyPrincipalPolicyPayload({ bundle: current });\n await verifyPrincipalPolicyMemberEnvelopes({ bundle: current });\n const { state, projection, grants } = checked.last;\n return issueVerifiedPrincipalPolicyCurrent(\n {\n principalId: state.principalId,\n principalType: state.principalType,\n version: state.version,\n keyEpoch: state.keyEpoch,\n stateHash: state.stateHash,\n state,\n projection,\n grants,\n retainedHistory: [previous, checked.last],\n checkpoint: {\n principalId: state.principalId,\n principalType: state.principalType,\n version: state.version,\n stateHash: state.stateHash,\n },\n },\n checked.latestAuthority,\n );\n });\n}\n"]}
@@ -118,7 +118,10 @@ class PrincipalPolicyHistoryVerifierImpl {
118
118
  stateHash: state.stateHash,
119
119
  },
120
120
  });
121
- return { ok: true, value: makeVerifiedPrincipalPolicyHistory(owned) };
121
+ return {
122
+ ok: true,
123
+ value: makeVerifiedPrincipalPolicyHistory(owned, this.#latestAuthority),
124
+ };
122
125
  }
123
126
  catch (error) {
124
127
  return toVerificationResult(error);
@@ -1 +1 @@
1
- {"version":3,"file":"principalPolicyHistory.js","sourceRoot":"","sources":["principalPolicyHistory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,GACjC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EACL,8CAA8C,GAE/C,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,gCAAgC,EAChC,oCAAoC,GACrC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,4BAA4B,EAC5B,qCAAqC,EACrC,4BAA4B,GAC7B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACL,kCAAkC,GAMnC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,oCAAoC,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAOhF,MAAM,kCAAkC;IAG7B,MAAM,CAAoD;IACnE,SAAS,CAAuD;IAChE,gBAAgB,GAA2C,IAAI,CAAC;IAChE,eAAe,CAAqB;IACpC,cAAc,GAA+B,EAAE,CAAC;IAChD,cAAc,GAAkB,IAAI,CAAC;IAC5B,SAAS,GAAG,IAAI,GAAG,EAGzB,CAAC;IACJ,UAAU,GAAG,KAAK,CAAC;IAEnB,YACE,KAAkC,EAClC,QAAmC;QAEnC,IAAI,CAAC,MAAM,GAAG,8BAA8B,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,QAAQ,IAAI,SAAS,C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A6B,EAAE;QAC1C,MAAM,EAAE,CAAC,IAAgC,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;QACnE,MAAM,EAAE,CAAC,YAAqC,EAAE,EAAE,CAChD,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC;QAC/B,cAAc,EAAE,CAAC,OAA8C,EAAE,EAAE,CACjE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;KACnC,CAAC;AACJ,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,qCAAqC,CACnD,KAAkC,EAClC,QAAgB,EAChB,UAAiD;IAEjD,OAAO,WAAW,CAAC,KAAK,IAAI,EAAE;QAC5B,MAAM,UAAU,GAAG,8BAA8B,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,UAAU,GAAgC;YAC9C,WAAW,EAAE,UAAU,CAAC,WAAW;YACnC,aAAa,EAAE,UAAU,CAAC,aAAa;YACvC,eAAe,EAAE,UAAU,CAAC,UAAU;YACtC,kBAAkB,EAAE,UAAU,CAAC,UAAU;SAC1C,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,4BAA4B,CAChD,QAAQ,EACR,qCAAqC,CAAC,UAAU,EAAE,UAAU,CAAC,CAC9D,CAAC;QACF,MAAM,aAAa,GAAG,MAAM,8CAA8C,CACxE,OAAO,EACP,UAAU,CACX,CAAC;QACF,OAAO,cAAc,CACnB,IAAI,kCAAkC,CAAC,UAAU,EAAE,aAAa,CAAC,CAClE,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { PrincipalStateExternalAuthority } from \"../principalState\";\nimport { normalizeReferencedPrincipalHead } from \"./accessEvent\";\nimport {\n normalizeCanonicalJsonValue,\n serializeKeyingCanonicalJson,\n} from \"./canonical\";\nimport {\n normalizePrincipalHistoryInput,\n verifyPrincipalHistoryCheckpoint,\n} from \"./principalPolicyHistoryChecks\";\nimport { appendPrincipalHistoryIndex } from \"./principalPolicyHistoryIndex\";\nimport { verifyPrincipalHistoryPage } from \"./principalPolicyHistoryPage\";\nimport {\n normalizeAuthenticatedPrincipalHistoryProgress,\n type PrincipalHistoryProgress,\n} from \"./principalPolicyHistoryProgress\";\nimport {\n capturePrincipalHistoryAuthority,\n capturePrincipalHistoryProgressEntry,\n} from \"./principalPolicyHistoryProgressEntry\";\nimport {\n openPrincipalHistoryProgress,\n ownPrincipalHistoryProgressProtection,\n sealPrincipalHistoryProgress,\n} from \"./principalPolicyHistoryProgressProtection\";\nimport {\n makeVerifiedPrincipalPolicyHistory,\n type PrincipalPolicyHistoryInput,\n type PrincipalPolicyHistoryPage,\n type PrincipalPolicyHistoryProgressOptions,\n type PrincipalPolicyHistoryVerifier,\n type VerifiedPrincipalPolicyHistory,\n} from \"./principalPolicyHistoryTypes\";\nimport { principalPolicyStateMatchesReference } from \"./principalPolicyReference\";\nimport { runVerifier, throwVerification, toVerificationResult } from \"./shared\";\nimport type {\n KeyingVerificationResult,\n NormalizedPrincipalPolicyStateChainEntry,\n ReferencedPrincipalHead,\n} from \"./types\";\n\nclass PrincipalPolicyHistoryVerifierImpl\n implements PrincipalPolicyHistoryVerifier\n{\n readonly #input: ReturnType<typeof normalizePrincipalHistoryInput>;\n #previous: NormalizedPrincipalPolicyStateChainEntry | undefined;\n #latestAuthority: PrincipalStateExternalAuthority | null = null;\n #checkpointHash: string | undefined;\n #indexFrontier: readonly (string | null)[] = [];\n #indexRootHash: string | null = null;\n readonly #retained = new Map<\n number,\n NormalizedPrincipalPolicyStateChainEntry\n >();\n #appending = false;\n\n constructor(\n input: PrincipalPolicyHistoryInput,\n progress?: PrincipalHistoryProgress,\n ) {\n this.#input = normalizePrincipalHistoryInput(input);\n if (progress) {\n this.#previous = progress.previous ?? undefined;\n this.#latestAuthority = progress.latestAuthority;\n this.#checkpointHash = progress.checkpointHash ?? undefined;\n this.#indexFrontier = progress.indexFrontier;\n this.#indexRootHash = progress.indexRootHash;\n for (const entry of progress.retained)\n this.#retained.set(entry.state.version, entry);\n }\n }\n\n getExternalAuthorityReference(): ReferencedPrincipalHead | null {\n return this.#latestAuthority ? { ...this.#latestAuthority } : null;\n }\n\n append(page: PrincipalPolicyHistoryPage) {\n return runVerifier(async () => {\n this.#assertIdle();\n this.#appending = true;\n try {\n const verified = await verifyPrincipalHistoryPage({\n page,\n principalId: this.#input.principalId,\n principalType: this.#input.principalType,\n previous: this.#previous,\n latestAuthority: this.#latestAuthority,\n references: this.#input.references,\n checkpoint: this.#input.checkpoint,\n });\n const index = await appendPrincipalHistoryIndex(\n this.#indexFrontier,\n verified.entries.map((entry) => entry.state),\n );\n // Publish only after every check, including the final signature, passes.\n for (const entry of verified.entries) {\n if (entry.state.version === this.#input.checkpoint?.version)\n this.#checkpointHash = entry.state.stateHash;\n if (\n entry.state.version === this.#input.checkpoint?.version ||\n this.#input.references.some(\n (reference) => reference.version === entry.state.version,\n )\n )\n this.#retained.set(entry.state.version, entry);\n }\n this.#previous = verified.last;\n this.#latestAuthority = verified.latestAuthority;\n this.#indexFrontier = index.frontier;\n this.#indexRootHash = index.rootHash;\n return {\n throughVersion: verified.last.state.version,\n indexNodes: index.nodes,\n };\n } finally {\n this.#appending = false;\n }\n });\n }\n\n #assertIdle(): void {\n if (this.#appending)\n throwVerification(\n \"invalid_shape\",\n \"principal history append in progress\",\n );\n }\n\n exportProgress(options: PrincipalPolicyHistoryProgressOptions) {\n return runVerifier(async () => {\n this.#assertIdle();\n // Capture a complete accepted prefix before the first yield. A later\n // append cannot change this snapshot or publish a partial page into it.\n const plaintext = serializeKeyingCanonicalJson(\n normalizeCanonicalJsonValue(\n {\n previous: this.#previous\n ? capturePrincipalHistoryProgressEntry(this.#previous)\n : null,\n latestAuthority: this.#latestAuthority\n ? capturePrincipalHistoryAuthority(this.#latestAuthority)\n : null,\n checkpointHash: this.#checkpointHash ?? null,\n indexFrontier: this.#indexFrontier,\n retained: [...this.#retained.values()].map(\n capturePrincipalHistoryProgressEntry,\n ),\n },\n \"principal history progress\",\n ),\n );\n return sealPrincipalHistoryProgress(\n plaintext,\n ownPrincipalHistoryProgressProtection(this.#input, options),\n );\n });\n }\n\n finish(\n expectedHead: ReferencedPrincipalHead,\n ): KeyingVerificationResult<VerifiedPrincipalPolicyHistory> {\n try {\n this.#assertIdle();\n const reference = normalizeReferencedPrincipalHead(expectedHead);\n const previous = this.#previous;\n if (\n !previous ||\n !this.#indexRootHash ||\n !principalPolicyStateMatchesReference(previous.state, reference)\n )\n throwVerification(\n \"missing_dependency\",\n \"principal history has not reached the requested head\",\n );\n verifyPrincipalHistoryCheckpoint(\n previous.state,\n this.#input.checkpoint,\n this.#checkpointHash,\n );\n const history = new Map(this.#retained);\n history.set(previous.state.version, previous);\n const { state, projection, grants } = previous;\n const { principalId, principalType } = this.#input;\n const owned = structuredClone({\n indexRootHash: this.#indexRootHash,\n currentEntry: { state, projection, grants },\n retainedEntries: [...history.values()].sort(\n (left, right) => left.state.version - right.state.version,\n ),\n checkpoint: {\n principalId,\n principalType,\n version: state.version,\n stateHash: state.stateHash,\n },\n });\n return { ok: true, value: makeVerifiedPrincipalPolicyHistory(owned) };\n } catch (error) {\n return toVerificationResult(error);\n }\n }\n}\n\n/**\n * Verify from genesis with bounded retained state. A rejected page cannot\n * advance authorization or continuity. Progress is local to this verifier;\n * a remote cursor/checkpoint is never accepted as verified history.\n * Callers bound serialized page bytes and authenticate external authority.\n * Throws KeyingVerificationError for invalid local scope, checkpoint or references.\n */\nexport function createPrincipalPolicyHistoryVerifier(\n input: PrincipalPolicyHistoryInput,\n): PrincipalPolicyHistoryVerifier {\n const verifier = new PrincipalPolicyHistoryVerifierImpl(input);\n return publicVerifier(verifier);\n}\n\nfunction publicVerifier(\n verifier: PrincipalPolicyHistoryVerifierImpl,\n): PrincipalPolicyHistoryVerifier {\n return {\n getExternalAuthorityReference: () =>\n verifier.getExternalAuthorityReference(),\n append: (page: PrincipalPolicyHistoryPage) => verifier.append(page),\n finish: (expectedHead: ReferencedPrincipalHead) =>\n verifier.finish(expectedHead),\n exportProgress: (options: PrincipalPolicyHistoryProgressOptions) =>\n verifier.exportProgress(options),\n };\n}\n\n/** Restore only progress authenticated by this verifier's own local key. */\nexport function restorePrincipalPolicyHistoryVerifier(\n input: PrincipalPolicyHistoryInput,\n progress: string,\n protection: PrincipalPolicyHistoryProgressOptions,\n): Promise<KeyingVerificationResult<PrincipalPolicyHistoryVerifier>> {\n return runVerifier(async () => {\n const normalized = normalizePrincipalHistoryInput(input);\n const ownedInput: PrincipalPolicyHistoryInput = {\n principalId: normalized.principalId,\n principalType: normalized.principalType,\n localCheckpoint: normalized.checkpoint,\n retainedReferences: normalized.references,\n };\n const decoded = await openPrincipalHistoryProgress(\n progress,\n ownPrincipalHistoryProgressProtection(normalized, protection),\n );\n const authenticated = await normalizeAuthenticatedPrincipalHistoryProgress(\n decoded,\n normalized,\n );\n return publicVerifier(\n new PrincipalPolicyHistoryVerifierImpl(ownedInput, authenticated),\n );\n });\n}\n"]}
1
+ {"version":3,"file":"principalPolicyHistory.js","sourceRoot":"","sources":["principalPolicyHistory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,GACjC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EACL,8CAA8C,GAE/C,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,gCAAgC,EAChC,oCAAoC,GACrC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,4BAA4B,EAC5B,qCAAqC,EACrC,4BAA4B,GAC7B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACL,kCAAkC,GAMnC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,o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AC1C,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,4BAA4B,CAChD,QAAQ,EACR,qCAAqC,CAAC,UAAU,EAAE,UAAU,CAAC,CAC9D,CAAC;QACF,MAAM,aAAa,GAAG,MAAM,8CAA8C,CACxE,OAAO,EACP,UAAU,CACX,CAAC;QACF,OAAO,cAAc,CACnB,IAAI,kCAAkC,CAAC,UAAU,EAAE,aAAa,CAAC,CAClE,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { PrincipalStateExternalAuthority } from \"../principalState\";\nimport { normalizeReferencedPrincipalHead } from \"./accessEvent\";\nimport {\n normalizeCanonicalJsonValue,\n serializeKeyingCanonicalJson,\n} from \"./canonical\";\nimport {\n normalizePrincipalHistoryInput,\n verifyPrincipalHistoryCheckpoint,\n} from \"./principalPolicyHistoryChecks\";\nimport { appendPrincipalHistoryIndex } from \"./principalPolicyHistoryIndex\";\nimport { verifyPrincipalHistoryPage } from \"./principalPolicyHistoryPage\";\nimport {\n normalizeAuthenticatedPrincipalHistoryProgress,\n type PrincipalHistoryProgress,\n} from \"./principalPolicyHistoryProgress\";\nimport {\n capturePrincipalHistoryAuthority,\n capturePrincipalHistoryProgressEntry,\n} from \"./principalPolicyHistoryProgressEntry\";\nimport {\n openPrincipalHistoryProgress,\n ownPrincipalHistoryProgressProtection,\n sealPrincipalHistoryProgress,\n} from \"./principalPolicyHistoryProgressProtection\";\nimport {\n makeVerifiedPrincipalPolicyHistory,\n type PrincipalPolicyHistoryInput,\n type PrincipalPolicyHistoryPage,\n type PrincipalPolicyHistoryProgressOptions,\n type PrincipalPolicyHistoryVerifier,\n type VerifiedPrincipalPolicyHistory,\n} from \"./principalPolicyHistoryTypes\";\nimport { principalPolicyStateMatchesReference } from \"./principalPolicyReference\";\nimport { runVerifier, throwVerification, toVerificationResult } from \"./shared\";\nimport type {\n KeyingVerificationResult,\n NormalizedPrincipalPolicyStateChainEntry,\n ReferencedPrincipalHead,\n} from \"./types\";\n\nclass PrincipalPolicyHistoryVerifierImpl\n implements PrincipalPolicyHistoryVerifier\n{\n readonly #input: ReturnType<typeof normalizePrincipalHistoryInput>;\n #previous: NormalizedPrincipalPolicyStateChainEntry | undefined;\n #latestAuthority: PrincipalStateExternalAuthority | null = null;\n #checkpointHash: string | undefined;\n #indexFrontier: readonly (string | null)[] = [];\n #indexRootHash: string | null = null;\n readonly #retained = new Map<\n number,\n NormalizedPrincipalPolicyStateChainEntry\n >();\n #appending = false;\n\n constructor(\n input: PrincipalPolicyHistoryInput,\n progress?: PrincipalHistoryProgress,\n ) {\n this.#input = normalizePrincipalHistoryInput(input);\n if (progress) {\n this.#previous = progress.previous ?? undefined;\n this.#latestAuthority = progress.latestAuthority;\n this.#checkpointHash = progress.checkpointHash ?? undefined;\n this.#indexFrontier = progress.indexFrontier;\n this.#indexRootHash = progress.indexRootHash;\n for (const entry of progress.retained)\n this.#retained.set(entry.state.version, entry);\n }\n }\n\n getExternalAuthorityReference(): ReferencedPrincipalHead | null {\n return this.#latestAuthority ? { ...this.#latestAuthority } : null;\n }\n\n append(page: PrincipalPolicyHistoryPage) {\n return runVerifier(async () => {\n this.#assertIdle();\n this.#appending = true;\n try {\n const verified = await verifyPrincipalHistoryPage({\n page,\n principalId: this.#input.principalId,\n principalType: this.#input.principalType,\n previous: this.#previous,\n latestAuthority: this.#latestAuthority,\n references: this.#input.references,\n checkpoint: this.#input.checkpoint,\n });\n const index = await appendPrincipalHistoryIndex(\n this.#indexFrontier,\n verified.entries.map((entry) => entry.state),\n );\n // Publish only after every check, including the final signature, passes.\n for (const entry of verified.entries) {\n if (entry.state.version === this.#input.checkpoint?.version)\n this.#checkpointHash = entry.state.stateHash;\n if (\n entry.state.version === this.#input.checkpoint?.version ||\n this.#input.references.some(\n (reference) => reference.version === entry.state.version,\n )\n )\n this.#retained.set(entry.state.version, entry);\n }\n this.#previous = verified.last;\n this.#latestAuthority = verified.latestAuthority;\n this.#indexFrontier = index.frontier;\n this.#indexRootHash = index.rootHash;\n return {\n throughVersion: verified.last.state.version,\n indexNodes: index.nodes,\n };\n } finally {\n this.#appending = false;\n }\n });\n }\n\n #assertIdle(): void {\n if (this.#appending)\n throwVerification(\n \"invalid_shape\",\n \"principal history append in progress\",\n );\n }\n\n exportProgress(options: PrincipalPolicyHistoryProgressOptions) {\n return runVerifier(async () => {\n this.#assertIdle();\n // Capture a complete accepted prefix before the first yield. A later\n // append cannot change this snapshot or publish a partial page into it.\n const plaintext = serializeKeyingCanonicalJson(\n normalizeCanonicalJsonValue(\n {\n previous: this.#previous\n ? capturePrincipalHistoryProgressEntry(this.#previous)\n : null,\n latestAuthority: this.#latestAuthority\n ? capturePrincipalHistoryAuthority(this.#latestAuthority)\n : null,\n checkpointHash: this.#checkpointHash ?? null,\n indexFrontier: this.#indexFrontier,\n retained: [...this.#retained.values()].map(\n capturePrincipalHistoryProgressEntry,\n ),\n },\n \"principal history progress\",\n ),\n );\n return sealPrincipalHistoryProgress(\n plaintext,\n ownPrincipalHistoryProgressProtection(this.#input, options),\n );\n });\n }\n\n finish(\n expectedHead: ReferencedPrincipalHead,\n ): KeyingVerificationResult<VerifiedPrincipalPolicyHistory> {\n try {\n this.#assertIdle();\n const reference = normalizeReferencedPrincipalHead(expectedHead);\n const previous = this.#previous;\n if (\n !previous ||\n !this.#indexRootHash ||\n !principalPolicyStateMatchesReference(previous.state, reference)\n )\n throwVerification(\n \"missing_dependency\",\n \"principal history has not reached the requested head\",\n );\n verifyPrincipalHistoryCheckpoint(\n previous.state,\n this.#input.checkpoint,\n this.#checkpointHash,\n );\n const history = new Map(this.#retained);\n history.set(previous.state.version, previous);\n const { state, projection, grants } = previous;\n const { principalId, principalType } = this.#input;\n const owned = structuredClone({\n indexRootHash: this.#indexRootHash,\n currentEntry: { state, projection, grants },\n retainedEntries: [...history.values()].sort(\n (left, right) => left.state.version - right.state.version,\n ),\n checkpoint: {\n principalId,\n principalType,\n version: state.version,\n stateHash: state.stateHash,\n },\n });\n return {\n ok: true,\n value: makeVerifiedPrincipalPolicyHistory(owned, this.#latestAuthority),\n };\n } catch (error) {\n return toVerificationResult(error);\n }\n }\n}\n\n/**\n * Verify from genesis with bounded retained state. A rejected page cannot\n * advance authorization or continuity. Progress is local to this verifier;\n * a remote cursor/checkpoint is never accepted as verified history.\n * Callers bound serialized page bytes and authenticate external authority.\n * Throws KeyingVerificationError for invalid local scope, checkpoint or references.\n */\nexport function createPrincipalPolicyHistoryVerifier(\n input: PrincipalPolicyHistoryInput,\n): PrincipalPolicyHistoryVerifier {\n const verifier = new PrincipalPolicyHistoryVerifierImpl(input);\n return publicVerifier(verifier);\n}\n\nfunction publicVerifier(\n verifier: PrincipalPolicyHistoryVerifierImpl,\n): PrincipalPolicyHistoryVerifier {\n return {\n getExternalAuthorityReference: () =>\n verifier.getExternalAuthorityReference(),\n append: (page: PrincipalPolicyHistoryPage) => verifier.append(page),\n finish: (expectedHead: ReferencedPrincipalHead) =>\n verifier.finish(expectedHead),\n exportProgress: (options: PrincipalPolicyHistoryProgressOptions) =>\n verifier.exportProgress(options),\n };\n}\n\n/** Restore only progress authenticated by this verifier's own local key. */\nexport function restorePrincipalPolicyHistoryVerifier(\n input: PrincipalPolicyHistoryInput,\n progress: string,\n protection: PrincipalPolicyHistoryProgressOptions,\n): Promise<KeyingVerificationResult<PrincipalPolicyHistoryVerifier>> {\n return runVerifier(async () => {\n const normalized = normalizePrincipalHistoryInput(input);\n const ownedInput: PrincipalPolicyHistoryInput = {\n principalId: normalized.principalId,\n principalType: normalized.principalType,\n localCheckpoint: normalized.checkpoint,\n retainedReferences: normalized.references,\n };\n const decoded = await openPrincipalHistoryProgress(\n progress,\n ownPrincipalHistoryProgressProtection(normalized, protection),\n );\n const authenticated = await normalizeAuthenticatedPrincipalHistoryProgress(\n decoded,\n normalized,\n );\n return publicVerifier(\n new PrincipalPolicyHistoryVerifierImpl(ownedInput, authenticated),\n );\n });\n}\n"]}
@@ -75,7 +75,7 @@ export function verifyPrincipalPolicyHistoryReferences(input) {
75
75
  return makeVerifiedPrincipalPolicyHistory({
76
76
  ...history,
77
77
  retainedEntries: [...entries.values()].sort((left, right) => left.state.version - right.state.version),
78
- });
78
+ }, history.latestAuthority);
79
79
  });
80
80
  }
81
81
  //# sourceMappingURL=principalPolicyHistoryReferences.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"principalPolicyHistoryReferences.js","sourceRoot":"","sources":["principalPolicyHistoryReferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,kCAAkC,EAClC,iCAAiC,EACjC,kCAAkC,GAEnC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,oCAAoC,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EACL,2BAA2B,EAC3B,mCAAmC,GACpC,MAAM,sBAAsB,CAAC;AAe9B,SAAS,iBAAiB,CACxB,UAA2D;IAE3D,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QAC1B,UAAU,CAAC,MAAM,GAAG,kCAAkC;QAEtD,iBAAiB,CAAC,eAAe,EAAE,mCAAmC,CAAC,CAAC;IAC1E,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC;IAChC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;QAChD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE;YAC1C,iBAAiB,CACf,eAAe,E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AC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { normalizePrincipalPolicyStateChainEntry } from \"./principalPolicyChainEntry\";\nimport { normalizePrincipalHistoryInput } from \"./principalPolicyHistoryChecks\";\nimport { principalHistoryIndexLeaf } from \"./principalPolicyHistoryIndex\";\nimport {\n makeVerifiedPrincipalPolicyHistory,\n ownVerifiedPrincipalPolicyHistory,\n PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT,\n type VerifiedPrincipalPolicyHistory,\n} from \"./principalPolicyHistoryTypes\";\nimport { principalPolicyStateMatchesReference } from \"./principalPolicyReference\";\nimport { runVerifier, throwVerification } from \"./shared\";\nimport {\n assertTransparencyInclusion,\n normalizeTransparencyInclusionProof,\n} from \"./transparencyProofs\";\nimport type {\n KeyingVerificationResult,\n PrincipalPolicyStateChainEntry,\n ReferencedPrincipalHead,\n TransparencyInclusionProof,\n} from \"./types\";\n\n/** Untrusted material to select an entry from a locally verified prefix. */\nexport interface PrincipalPolicyHistoryReferenceProof {\n readonly reference: ReferencedPrincipalHead;\n readonly entry: PrincipalPolicyStateChainEntry;\n readonly proof: TransparencyInclusionProof;\n}\n\nfunction assertProofBudget(\n references: readonly PrincipalPolicyHistoryReferenceProof[],\n): void {\n if (\n !Array.isArray(references) ||\n references.length > PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT\n )\n throwVerification(\"invalid_shape\", \"too many principal history proofs\");\n const count = references.length;\n for (let index = 0; index < count; index += 1) {\n const path = references[index]?.proof.auditPath;\n if (!Array.isArray(path) || path.length > 53)\n throwVerification(\n \"invalid_shape\",\n \"principal history proof exceeds its budget\",\n );\n }\n}\n\n/**\n * Select new retained references without replaying signatures. Inclusion is\n * checked against the private root owned by a local verifier, never a peer's\n * claimed root. Each leaf commits to the exact signed entry already accepted.\n * Replaces the retained selection; the current entry is always included.\n * A separate checkpoint proof preserves the full 128-citation selection budget.\n */\nexport function verifyPrincipalPolicyHistoryReferences(input: {\n readonly history: VerifiedPrincipalPolicyHistory;\n readonly references: readonly PrincipalPolicyHistoryReferenceProof[];\n readonly checkpointReference?:\n | PrincipalPolicyHistoryReferenceProof\n | undefined;\n}): Promise<KeyingVerificationResult<VerifiedPrincipalPolicyHistory>> {\n return runVerifier(async () => {\n const history = ownVerifiedPrincipalPolicyHistory(input.history);\n const supplied = input.references;\n const suppliedCheckpoint = input.checkpointReference;\n assertProofBudget(supplied);\n if (suppliedCheckpoint !== undefined)\n assertProofBudget([suppliedCheckpoint]);\n const references = structuredClone(supplied);\n const checkpoint = structuredClone(suppliedCheckpoint);\n assertProofBudget(references);\n const scope = {\n principalId: history.currentEntry.state.principalId,\n principalType: history.currentEntry.state.principalType,\n };\n normalizePrincipalHistoryInput({\n ...scope,\n retainedReferences: references.map((item) => item.reference),\n });\n const selected = [...references];\n if (checkpoint !== undefined) {\n assertProofBudget([checkpoint]);\n normalizePrincipalHistoryInput({\n ...scope,\n retainedReferences: [checkpoint.reference],\n });\n selected.push(checkpoint);\n }\n const entries = new Map<number, PrincipalPolicyStateChainEntry>();\n const treeSize = history.currentEntry.state.version;\n for (const item of selected) {\n const entry = await normalizePrincipalPolicyStateChainEntry(item.entry);\n const proof = normalizeTransparencyInclusionProof(item.proof);\n if (\n !principalPolicyStateMatchesReference(entry.state, item.reference) ||\n entry.state.version > treeSize ||\n proof.leafIndex !== entry.state.version - 1\n )\n throwVerification(\n \"object_mismatch\",\n \"principal history proof reference mismatch\",\n );\n await assertTransparencyInclusion({\n leafHash: await principalHistoryIndexLeaf(entry.state),\n checkpoint: {\n logId: \"principal-history\",\n rootHash: history.indexRootHash,\n treeSize,\n },\n proof,\n });\n entries.set(entry.state.version, entry);\n }\n entries.set(treeSize, history.currentEntry);\n return makeVerifiedPrincipalPolicyHistory({\n ...history,\n retainedEntries: [...entries.values()].sort(\n (left, right) => left.state.version - right.state.version,\n ),\n });\n });\n}\n"]}
1
+ {"version":3,"file":"principalPolicyHistoryReferences.js","sourceRoot":"","sources":["principalPolicyHistoryReferences.ts"],"names":[],"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CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9D,IACE,CAAC,oCAAoC,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC;gBAClE,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,QAAQ;gBAC9B,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC;gBAE3C,iBAAiB,CACf,iBAAiB,EACjB,4CAA4C,CAC7C,CAAC;YACJ,MAAM,2BAA2B,CAAC;gBAChC,QAAQ,EAAE,MAAM,yBAAyB,CAAC,KAAK,CAAC,KAAK,CAAC;gBACtD,UAAU,EAAE;oBACV,KAAK,EAAE,mBAAmB;oBAC1B,QAAQ,EAAE,OAAO,CAAC,aAAa;oBAC/B,QAAQ;iBACT;gBACD,KAAK;aACN,CAAC,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;QAC5C,OAAO,kCAAkC,CACvC;YACE,GAAG,OAAO;YACV,eAAe,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CACzC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAC1D;SACF,EACD,OAAO,CAAC,eAAe,CACxB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { normalizePrincipalPolicyStateChainEntry } from \"./principalPolicyChainEntry\";\nimport { normalizePrincipalHistoryInput } from \"./principalPolicyHistoryChecks\";\nimport { principalHistoryIndexLeaf } from \"./principalPolicyHistoryIndex\";\nimport {\n makeVerifiedPrincipalPolicyHistory,\n ownVerifiedPrincipalPolicyHistory,\n PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT,\n type VerifiedPrincipalPolicyHistory,\n} from \"./principalPolicyHistoryTypes\";\nimport { principalPolicyStateMatchesReference } from \"./principalPolicyReference\";\nimport { runVerifier, throwVerification } from \"./shared\";\nimport {\n assertTransparencyInclusion,\n normalizeTransparencyInclusionProof,\n} from \"./transparencyProofs\";\nimport type {\n KeyingVerificationResult,\n PrincipalPolicyStateChainEntry,\n ReferencedPrincipalHead,\n TransparencyInclusionProof,\n} from \"./types\";\n\n/** Untrusted material to select an entry from a locally verified prefix. */\nexport interface PrincipalPolicyHistoryReferenceProof {\n readonly reference: ReferencedPrincipalHead;\n readonly entry: PrincipalPolicyStateChainEntry;\n readonly proof: TransparencyInclusionProof;\n}\n\nfunction assertProofBudget(\n references: readonly PrincipalPolicyHistoryReferenceProof[],\n): void {\n if (\n !Array.isArray(references) ||\n references.length > PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT\n )\n throwVerification(\"invalid_shape\", \"too many principal history proofs\");\n const count = references.length;\n for (let index = 0; index < count; index += 1) {\n const path = references[index]?.proof.auditPath;\n if (!Array.isArray(path) || path.length > 53)\n throwVerification(\n \"invalid_shape\",\n \"principal history proof exceeds its budget\",\n );\n }\n}\n\n/**\n * Select new retained references without replaying signatures. Inclusion is\n * checked against the private root owned by a local verifier, never a peer's\n * claimed root. Each leaf commits to the exact signed entry already accepted.\n * Replaces the retained selection; the current entry is always included.\n * A separate checkpoint proof preserves the full 128-citation selection budget.\n */\nexport function verifyPrincipalPolicyHistoryReferences(input: {\n readonly history: VerifiedPrincipalPolicyHistory;\n readonly references: readonly PrincipalPolicyHistoryReferenceProof[];\n readonly checkpointReference?:\n | PrincipalPolicyHistoryReferenceProof\n | undefined;\n}): Promise<KeyingVerificationResult<VerifiedPrincipalPolicyHistory>> {\n return runVerifier(async () => {\n const history = ownVerifiedPrincipalPolicyHistory(input.history);\n const supplied = input.references;\n const suppliedCheckpoint = input.checkpointReference;\n assertProofBudget(supplied);\n if (suppliedCheckpoint !== undefined)\n assertProofBudget([suppliedCheckpoint]);\n const references = structuredClone(supplied);\n const checkpoint = structuredClone(suppliedCheckpoint);\n assertProofBudget(references);\n const scope = {\n principalId: history.currentEntry.state.principalId,\n principalType: history.currentEntry.state.principalType,\n };\n normalizePrincipalHistoryInput({\n ...scope,\n retainedReferences: references.map((item) => item.reference),\n });\n const selected = [...references];\n if (checkpoint !== undefined) {\n assertProofBudget([checkpoint]);\n normalizePrincipalHistoryInput({\n ...scope,\n retainedReferences: [checkpoint.reference],\n });\n selected.push(checkpoint);\n }\n const entries = new Map<number, PrincipalPolicyStateChainEntry>();\n const treeSize = history.currentEntry.state.version;\n for (const item of selected) {\n const entry = await normalizePrincipalPolicyStateChainEntry(item.entry);\n const proof = normalizeTransparencyInclusionProof(item.proof);\n if (\n !principalPolicyStateMatchesReference(entry.state, item.reference) ||\n entry.state.version > treeSize ||\n proof.leafIndex !== entry.state.version - 1\n )\n throwVerification(\n \"object_mismatch\",\n \"principal history proof reference mismatch\",\n );\n await assertTransparencyInclusion({\n leafHash: await principalHistoryIndexLeaf(entry.state),\n checkpoint: {\n logId: \"principal-history\",\n rootHash: history.indexRootHash,\n treeSize,\n },\n proof,\n });\n entries.set(entry.state.version, entry);\n }\n entries.set(treeSize, history.currentEntry);\n return makeVerifiedPrincipalPolicyHistory(\n {\n ...history,\n retainedEntries: [...entries.values()].sort(\n (left, right) => left.state.version - right.state.version,\n ),\n },\n history.latestAuthority,\n );\n });\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { PrincipalStateExternalAuthority } from "../principalState.js";
1
2
  import type { PrincipalPolicyExternalAuthority } from "./principalPolicyExternalAuthorityTypes.js";
2
3
  import type { PrincipalHistoryIndexNode } from "./principalPolicyHistoryIndex.js";
3
4
  import type { KeyingVerificationResult, PrincipalPolicyCheckpoint, PrincipalPolicySignerPublicKey, PrincipalPolicyStateChainEntry, ReferencedPrincipalHead } from "./types.js";
@@ -32,8 +33,10 @@ export interface VerifiedPrincipalPolicyHistory {
32
33
  /** Computed only from locally accepted entries; never supplied by a peer. */
33
34
  readonly indexRootHash: string;
34
35
  }
35
- type HistorySnapshot = Omit<VerifiedPrincipalPolicyHistory, typeof verifiedHistoryBrand>;
36
- export declare function makeVerifiedPrincipalPolicyHistory(value: Omit<VerifiedPrincipalPolicyHistory, typeof verifiedHistoryBrand>): VerifiedPrincipalPolicyHistory;
36
+ type HistorySnapshot = Omit<VerifiedPrincipalPolicyHistory, typeof verifiedHistoryBrand> & {
37
+ readonly latestAuthority: PrincipalStateExternalAuthority | null;
38
+ };
39
+ export declare function makeVerifiedPrincipalPolicyHistory(value: Omit<VerifiedPrincipalPolicyHistory, typeof verifiedHistoryBrand>, latestAuthority: PrincipalStateExternalAuthority | null): VerifiedPrincipalPolicyHistory;
37
40
  export declare function ownVerifiedPrincipalPolicyHistory(history: VerifiedPrincipalPolicyHistory): HistorySnapshot;
38
41
  export interface PrincipalPolicyHistoryVerifier {
39
42
  /** Owned copy of the latest accepted citation, including across uncited pages. */
@@ -4,12 +4,15 @@ const verifiedHistoryBrand = Symbol("verifiedPrincipalPolicyHistory");
4
4
  // Public copies are useful for inspection, but their fields are not authority.
5
5
  // A later verifier consumes the privately held snapshot issued by finish().
6
6
  const issuedHistories = new WeakMap();
7
- export function makeVerifiedPrincipalPolicyHistory(value) {
7
+ export function makeVerifiedPrincipalPolicyHistory(value, latestAuthority) {
8
8
  const result = {
9
- ...value,
9
+ currentEntry: value.currentEntry,
10
+ retainedEntries: value.retainedEntries,
11
+ checkpoint: value.checkpoint,
12
+ indexRootHash: value.indexRootHash,
10
13
  [verifiedHistoryBrand]: true,
11
14
  };
12
- issuedHistories.set(result, structuredClone(value));
15
+ issuedHistories.set(result, structuredClone({ ...value, latestAuthority }));
13
16
  return result;
14
17
  }
15
18
  export function ownVerifiedPrincipalPolicyHistory(history) {
@@ -1 +1 @@
1
- {"version":3,"file":"principalPolicyHistoryTypes.js","sourceRoot":"","sources":["principalPolicyHistoryTypes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAS7C,MAAM,CAAC,MAAM,kCAAkC,GAAG,GAAG,CAAC;AAyBtD,MAAM,oBAAoB,GAAkB,MAAM,CAChD,gCAAgC,CACjC,CAAC;AAiBF,+EAA+E;AAC/E,4EAA4E;AAC5E,MAAM,eAAe,GAAG,IAAI,OAAO,EAGhC,CAAC;AAEJ,MAAM,UAAU,kCAAkC,CAChD,KAAwE;IAExE,MAAM,MAAM,GAAmC;QAC7C,GAAG,KAAK;QACR,CAAC,oBAAoB,CAAC,EAAE,IAAI;KAC7B,CAAC;IACF,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,OAAuC;IAEvC,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ;QACX,iBAAiB,CACf,eAAe,EACf,mDAAmD,CACpD,CAAC;IACJ,OAAO,eAAe,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type { PrincipalPolicyExternalAuthority } from \"./principalPolicyExternalAuthorityTypes\";\nimport type { PrincipalHistoryIndexNode } from \"./principalPolicyHistoryIndex\";\nimport { throwVerification } from \"./shared\";\nimport type {\n KeyingVerificationResult,\n PrincipalPolicyCheckpoint,\n PrincipalPolicySignerPublicKey,\n PrincipalPolicyStateChainEntry,\n ReferencedPrincipalHead,\n} from \"./types\";\n\nexport const PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT = 128;\n\n/** A crypto verification batch, not a wire-response DTO. */\nexport interface PrincipalPolicyHistoryPage {\n readonly entries: readonly PrincipalPolicyStateChainEntry[];\n /** Keys resolved through the caller's trusted user-identity mechanism. */\n readonly signerPublicKeys: readonly PrincipalPolicySignerPublicKey[];\n /** Already authenticated authority; never trust a server page directly. */\n readonly externalAuthority?: PrincipalPolicyExternalAuthority;\n}\n\nexport interface PrincipalPolicyHistoryInput {\n readonly principalId: string;\n readonly principalType: ReferencedPrincipalHead[\"principalType\"];\n readonly localCheckpoint?: PrincipalPolicyCheckpoint | null;\n readonly retainedReferences?: readonly ReferencedPrincipalHead[];\n}\n\n/** Local verifier protection; never obtain this key from a remote API. */\nexport interface PrincipalPolicyHistoryProgressOptions {\n readonly localKey: Uint8Array;\n /** Stable local operation identity, bound into authenticated progress. */\n readonly context: string;\n}\n\nconst verifiedHistoryBrand: unique symbol = Symbol(\n \"verifiedPrincipalPolicyHistory\",\n);\n\n/** A verified prefix with explicitly retained references, not a full snapshot. */\nexport interface VerifiedPrincipalPolicyHistory {\n readonly [verifiedHistoryBrand]: true;\n readonly currentEntry: PrincipalPolicyStateChainEntry;\n readonly retainedEntries: readonly PrincipalPolicyStateChainEntry[];\n readonly checkpoint: PrincipalPolicyCheckpoint;\n /** Computed only from locally accepted entries; never supplied by a peer. */\n readonly indexRootHash: string;\n}\n\ntype HistorySnapshot = Omit<\n VerifiedPrincipalPolicyHistory,\n typeof verifiedHistoryBrand\n>;\n\n// Public copies are useful for inspection, but their fields are not authority.\n// A later verifier consumes the privately held snapshot issued by finish().\nconst issuedHistories = new WeakMap<\n VerifiedPrincipalPolicyHistory,\n HistorySnapshot\n>();\n\nexport function makeVerifiedPrincipalPolicyHistory(\n value: Omit<VerifiedPrincipalPolicyHistory, typeof verifiedHistoryBrand>,\n): VerifiedPrincipalPolicyHistory {\n const result: VerifiedPrincipalPolicyHistory = {\n ...value,\n [verifiedHistoryBrand]: true,\n };\n issuedHistories.set(result, structuredClone(value));\n return result;\n}\n\nexport function ownVerifiedPrincipalPolicyHistory(\n history: VerifiedPrincipalPolicyHistory,\n): HistorySnapshot {\n const snapshot = issuedHistories.get(history);\n if (!snapshot)\n throwVerification(\n \"invalid_shape\",\n \"principal history must come from a local verifier\",\n );\n return structuredClone(snapshot);\n}\n\nexport interface PrincipalPolicyHistoryVerifier {\n /** Owned copy of the latest accepted citation, including across uncited pages. */\n getExternalAuthorityReference(): ReferencedPrincipalHead | null;\n append(page: PrincipalPolicyHistoryPage): Promise<\n KeyingVerificationResult<{\n readonly throughVersion: number;\n readonly indexNodes: readonly PrincipalHistoryIndexNode[];\n }>\n >;\n finish(\n expectedHead: ReferencedPrincipalHead,\n ): KeyingVerificationResult<VerifiedPrincipalPolicyHistory>;\n exportProgress(\n options: PrincipalPolicyHistoryProgressOptions,\n ): Promise<KeyingVerificationResult<string>>;\n}\n"]}
1
+ {"version":3,"file":"principalPolicyHistoryTypes.js","sourceRoot":"","sources":["principalPolicyHistoryTypes.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAS7C,MAAM,CAAC,MAAM,kCAAkC,GAAG,GAAG,CAAC;AAyBtD,MAAM,oBAAoB,GAAkB,MAAM,CAChD,gCAAgC,CACjC,CAAC;AAiBF,+EAA+E;AAC/E,4EAA4E;AAC5E,MAAM,eAAe,GAAG,IAAI,OAAO,EAGhC,CAAC;AAEJ,MAAM,UAAU,kCAAkC,CAChD,KAAwE,EACxE,eAAuD;IAEvD,MAAM,MAAM,GAAmC;QAC7C,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,CAAC,oBAAoB,CAAC,EAAE,IAAI;KAC7B,CAAC;IACF,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IAC5E,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,OAAuC;IAEvC,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ;QACX,iBAAiB,CACf,eAAe,EACf,mDAAmD,CACpD,CAAC;IACJ,OAAO,eAAe,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type { PrincipalStateExternalAuthority } from \"../principalState\";\nimport type { PrincipalPolicyExternalAuthority } from \"./principalPolicyExternalAuthorityTypes\";\nimport type { PrincipalHistoryIndexNode } from \"./principalPolicyHistoryIndex\";\nimport { throwVerification } from \"./shared\";\nimport type {\n KeyingVerificationResult,\n PrincipalPolicyCheckpoint,\n PrincipalPolicySignerPublicKey,\n PrincipalPolicyStateChainEntry,\n ReferencedPrincipalHead,\n} from \"./types\";\n\nexport const PRINCIPAL_HISTORY_PAGE_ENTRY_LIMIT = 128;\n\n/** A crypto verification batch, not a wire-response DTO. */\nexport interface PrincipalPolicyHistoryPage {\n readonly entries: readonly PrincipalPolicyStateChainEntry[];\n /** Keys resolved through the caller's trusted user-identity mechanism. */\n readonly signerPublicKeys: readonly PrincipalPolicySignerPublicKey[];\n /** Already authenticated authority; never trust a server page directly. */\n readonly externalAuthority?: PrincipalPolicyExternalAuthority;\n}\n\nexport interface PrincipalPolicyHistoryInput {\n readonly principalId: string;\n readonly principalType: ReferencedPrincipalHead[\"principalType\"];\n readonly localCheckpoint?: PrincipalPolicyCheckpoint | null;\n readonly retainedReferences?: readonly ReferencedPrincipalHead[];\n}\n\n/** Local verifier protection; never obtain this key from a remote API. */\nexport interface PrincipalPolicyHistoryProgressOptions {\n readonly localKey: Uint8Array;\n /** Stable local operation identity, bound into authenticated progress. */\n readonly context: string;\n}\n\nconst verifiedHistoryBrand: unique symbol = Symbol(\n \"verifiedPrincipalPolicyHistory\",\n);\n\n/** A verified prefix with explicitly retained references, not a full snapshot. */\nexport interface VerifiedPrincipalPolicyHistory {\n readonly [verifiedHistoryBrand]: true;\n readonly currentEntry: PrincipalPolicyStateChainEntry;\n readonly retainedEntries: readonly PrincipalPolicyStateChainEntry[];\n readonly checkpoint: PrincipalPolicyCheckpoint;\n /** Computed only from locally accepted entries; never supplied by a peer. */\n readonly indexRootHash: string;\n}\n\ntype HistorySnapshot = Omit<\n VerifiedPrincipalPolicyHistory,\n typeof verifiedHistoryBrand\n> & { readonly latestAuthority: PrincipalStateExternalAuthority | null };\n\n// Public copies are useful for inspection, but their fields are not authority.\n// A later verifier consumes the privately held snapshot issued by finish().\nconst issuedHistories = new WeakMap<\n VerifiedPrincipalPolicyHistory,\n HistorySnapshot\n>();\n\nexport function makeVerifiedPrincipalPolicyHistory(\n value: Omit<VerifiedPrincipalPolicyHistory, typeof verifiedHistoryBrand>,\n latestAuthority: PrincipalStateExternalAuthority | null,\n): VerifiedPrincipalPolicyHistory {\n const result: VerifiedPrincipalPolicyHistory = {\n currentEntry: value.currentEntry,\n retainedEntries: value.retainedEntries,\n checkpoint: value.checkpoint,\n indexRootHash: value.indexRootHash,\n [verifiedHistoryBrand]: true,\n };\n issuedHistories.set(result, structuredClone({ ...value, latestAuthority }));\n return result;\n}\n\nexport function ownVerifiedPrincipalPolicyHistory(\n history: VerifiedPrincipalPolicyHistory,\n): HistorySnapshot {\n const snapshot = issuedHistories.get(history);\n if (!snapshot)\n throwVerification(\n \"invalid_shape\",\n \"principal history must come from a local verifier\",\n );\n return structuredClone(snapshot);\n}\n\nexport interface PrincipalPolicyHistoryVerifier {\n /** Owned copy of the latest accepted citation, including across uncited pages. */\n getExternalAuthorityReference(): ReferencedPrincipalHead | null;\n append(page: PrincipalPolicyHistoryPage): Promise<\n KeyingVerificationResult<{\n readonly throughVersion: number;\n readonly indexNodes: readonly PrincipalHistoryIndexNode[];\n }>\n >;\n finish(\n expectedHead: ReferencedPrincipalHead,\n ): KeyingVerificationResult<VerifiedPrincipalPolicyHistory>;\n exportProgress(\n options: PrincipalPolicyHistoryProgressOptions,\n ): Promise<KeyingVerificationResult<string>>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/client-sdk",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "React-free Tearleads client runtime: local SQLite persistence, keys, sync, encrypted blobs, and domain workflows.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -2,6 +2,7 @@ import { MAX_ROTATION_CONTAINER_REKEYS } from "../../../internal/validators/util
2
2
  import { verifyContainerWriterProjection, } from "../../../data/keyingProjectionVerification.js";
3
3
  import { buildMaterializedContainerRekeyPlan } from "./rekey.js";
4
4
  import { rebaseContainerWriterProjection } from "./rekeyProjection.js";
5
+ import { selectReplacementPrincipalPolicyReferences } from "./replacementPrincipalPolicyReferences.js";
5
6
  /**
6
7
  * Re-root a served projection on the deepest not-yet-accepted proper ancestor
7
8
  * among `speculativePaths`. Each carried plan's own path was built the same
@@ -67,7 +68,14 @@ export async function planCarriedDescendantRekey(input) {
67
68
  persistVerificationCheckpoints: false,
68
69
  previousProjection: rebased.projection,
69
70
  principalPolicyCache: input.principalPolicyCache,
70
- replacementPrincipalPolicy: input.replacementPrincipalPolicy,
71
+ replacementPrincipalPolicy: input.replacementPrincipalPolicy
72
+ ? await selectReplacementPrincipalPolicyReferences({
73
+ policy: input.replacementPrincipalPolicy,
74
+ projection: rebased.projection,
75
+ principalPolicyCache: input.principalPolicyCache,
76
+ resolveAuthoredPolicyReferences: input.resolveAuthoredPolicyReferences,
77
+ })
78
+ : undefined,
71
79
  resolveProjectionUserKey: input.resolveProjectionUserKey,
72
80
  stillCurrent: input.stillCurrent,
73
81
  targetSecretKey: input.targetSecretKey,