@tearleads/client-sdk 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +32 -7
  2. package/client/containerContents.js +2 -1
  3. package/client/containerContents.js.map +1 -1
  4. package/data/documents/blob/shared/types.d.ts +4 -0
  5. package/data/documents/blob/shared/types.js.map +1 -1
  6. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js +2 -0
  7. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js.map +1 -1
  8. package/data/keyingProjectionVerification/checkpointContext.d.ts +2 -1
  9. package/data/keyingProjectionVerification/checkpointContext.js +22 -0
  10. package/data/keyingProjectionVerification/checkpointContext.js.map +1 -1
  11. package/data/keyingProjectionVerification/containerDestinationVerification.js +11 -1
  12. package/data/keyingProjectionVerification/containerDestinationVerification.js.map +1 -1
  13. package/data/keyingProjectionVerification/containerManifestVerification.js.map +1 -1
  14. package/data/keyingProjectionVerification/containerPathVerification.js.map +1 -1
  15. package/data/keyingProjectionVerification/containerProjectionVerification.d.ts +3 -2
  16. package/data/keyingProjectionVerification/containerProjectionVerification.js +10 -11
  17. package/data/keyingProjectionVerification/containerProjectionVerification.js.map +1 -1
  18. package/data/keyingProjectionVerification/documentManifestPolicies.js.map +1 -1
  19. package/data/keyingProjectionVerification/documentManifestVerification.js.map +1 -1
  20. package/data/keyingProjectionVerification/documentProjectionVerification.d.ts +2 -3
  21. package/data/keyingProjectionVerification/documentProjectionVerification.js +4 -0
  22. package/data/keyingProjectionVerification/documentProjectionVerification.js.map +1 -1
  23. package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js +14 -12
  24. package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js.map +1 -1
  25. package/data/keyingProjectionVerification/organizationFounderBinding.js.map +1 -1
  26. package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js +33 -6
  27. package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js.map +1 -1
  28. package/data/keyingProjectionVerification/projectionLifetimes.js +13 -0
  29. package/data/keyingProjectionVerification/projectionLifetimes.js.map +1 -0
  30. package/data/keyingProjectionVerification/projectionPolicyEvidence.js +19 -66
  31. package/data/keyingProjectionVerification/projectionPolicyEvidence.js.map +1 -1
  32. package/data/keyingProjectionVerification/types.d.ts +13 -2
  33. package/data/keyingProjectionVerification/types.js +15 -0
  34. package/data/keyingProjectionVerification/types.js.map +1 -1
  35. package/data/persistence/keyingCheckpointAdvancePersistence.js +4 -1
  36. package/data/persistence/keyingCheckpointAdvancePersistence.js.map +1 -1
  37. package/data/persistence/organizationFounderPersistence.js +2 -2
  38. package/data/persistence/organizationFounderPersistence.js.map +1 -1
  39. package/data/persistence/principalAuthorizationCheckpoints.js +29 -0
  40. package/data/persistence/principalAuthorizationCheckpoints.js.map +1 -0
  41. package/data/persistence/principalHistoryEvidencePersistence.d.ts +30 -0
  42. package/data/persistence/principalHistoryPrefixPersistence.d.ts +24 -0
  43. package/data/persistence/principalHistoryPrefixPersistence.js +6 -2
  44. package/data/persistence/principalHistoryPrefixPersistence.js.map +1 -1
  45. package/data/persistence/principalHistoryStagePersistence.d.ts +21 -0
  46. package/data/principals/principalHistoryRuntime.js +12 -0
  47. package/data/principals/principalHistoryRuntime.js.map +1 -0
  48. package/data/principals/principalHistoryStageProtection.js +2 -12
  49. package/data/principals/principalHistoryStageProtection.js.map +1 -1
  50. package/data/principals/principalPolicyEvidence.d.ts +2 -2
  51. package/data/principals/principalPolicyEvidence.js.map +1 -1
  52. package/data/sqlite/principalHistoryEvidenceSchema.d.ts +308 -0
  53. package/data/sqlite/principalHistoryStageSchema.d.ts +119 -0
  54. package/index.d.ts +2 -2
  55. package/index.js +1 -1
  56. package/index.js.map +1 -1
  57. package/internal/api-client/ApiCache.d.ts +54 -0
  58. package/internal/api-client/ApiClient.d.ts +255 -309
  59. package/internal/api-client/ApiClient.js +15 -6
  60. package/internal/api-client/ApiClient.js.map +1 -1
  61. package/internal/api-client/index.d.ts +1 -0
  62. package/internal/api-client/index.js.map +1 -1
  63. package/internal/api-client/principalHistoryDeadline.js +20 -0
  64. package/internal/api-client/principalHistoryDeadline.js.map +1 -0
  65. package/internal/api-client/principalHistoryRequest.js +59 -22
  66. package/internal/api-client/principalHistoryRequest.js.map +1 -1
  67. package/internal/api-client/principalHistoryRequestContext.js +18 -5
  68. package/internal/api-client/principalHistoryRequestContext.js.map +1 -1
  69. package/internal/api-client/principalPolicyRequests.d.ts +799 -0
  70. package/internal/api-client/principalPolicyRequests.js +9 -4
  71. package/internal/api-client/principalPolicyRequests.js.map +1 -1
  72. package/internal/api-client/projectionPolicyHistoryPages.d.ts +9 -0
  73. package/internal/api-client/projectionPolicyHistoryPages.js +88 -0
  74. package/internal/api-client/projectionPolicyHistoryPages.js.map +1 -0
  75. package/internal/api-client/writerProjectionRequests.js +26 -0
  76. package/internal/api-client/writerProjectionRequests.js.map +1 -0
  77. package/internal/crypto/keying/principalPolicyHistory.js +4 -0
  78. package/internal/crypto/keying/principalPolicyHistory.js.map +1 -1
  79. package/internal/crypto/keying/principalPolicyHistoryTypes.d.ts +2 -0
  80. package/internal/crypto/keying/principalPolicyHistoryTypes.js.map +1 -1
  81. package/internal/crypto/projectionHistorySlots.js +0 -4
  82. package/internal/crypto/projectionHistorySlots.js.map +1 -1
  83. package/internal/validators/operation/index.d.ts +1 -0
  84. package/internal/validators/operation/index.js +1 -0
  85. package/internal/validators/operation/index.js.map +1 -1
  86. package/internal/validators/operation/principals.d.ts +38 -16
  87. package/internal/validators/operation/principals.js +11 -5
  88. package/internal/validators/operation/principals.js.map +1 -1
  89. package/internal/validators/operation/projectionPolicyHistory.d.ts +512 -0
  90. package/internal/validators/operation/projectionPolicyHistory.js +37 -0
  91. package/internal/validators/operation/projectionPolicyHistory.js.map +1 -0
  92. package/internal/validators/operation/registry.d.ts +2 -0
  93. package/internal/validators/operation/registry.js +2 -0
  94. package/internal/validators/operation/registry.js.map +1 -1
  95. package/internal/validators/operation/writerProjections.d.ts +178 -1224
  96. package/internal/validators/operation/writerProjections.js +9 -2
  97. package/internal/validators/operation/writerProjections.js.map +1 -1
  98. package/internal/validators/response/container.d.ts +84 -612
  99. package/internal/validators/response/documentMutation.d.ts +84 -612
  100. package/internal/validators/response/index.d.ts +1 -0
  101. package/internal/validators/response/index.js +1 -0
  102. package/internal/validators/response/index.js.map +1 -1
  103. package/internal/validators/response/organizationBilling.d.ts +1 -0
  104. package/internal/validators/response/organizationBilling.js +1 -1
  105. package/internal/validators/response/organizationBilling.js.map +1 -1
  106. package/internal/validators/response/principalHistoryPreparation.js +28 -1
  107. package/internal/validators/response/principalHistoryPreparation.js.map +1 -1
  108. package/internal/validators/response/principalPolicySnapshotPage.d.ts +388 -0
  109. package/internal/validators/response/principalPolicySnapshotPage.js +24 -0
  110. package/internal/validators/response/principalPolicySnapshotPage.js.map +1 -0
  111. package/internal/validators/response/projectionPolicyEvidence.d.ts +85 -613
  112. package/internal/validators/response/projectionPolicyEvidence.js +10 -5
  113. package/internal/validators/response/projectionPolicyEvidence.js.map +1 -1
  114. package/package.json +4 -1
  115. package/sqlite/sqlite3-licenses.md +38 -0
  116. package/sqlite/sqlite3.wasm +0 -0
  117. package/sqlite/worker.js +4 -0
  118. package/stores/documents/documentStore/attachmentHydration.js +3 -0
  119. package/stores/documents/documentStore/attachmentHydration.js.map +1 -1
  120. package/stores/documents/documentStore/syncDetachedAttachments.js +3 -0
  121. package/stores/documents/documentStore/syncDetachedAttachments.js.map +1 -1
  122. package/workflows/blobs/decrypt.d.ts +1 -1
  123. package/workflows/blobs/decrypt.js +3 -1
  124. package/workflows/blobs/decrypt.js.map +1 -1
  125. package/workflows/blobs/detach.js +6 -1
  126. package/workflows/blobs/detach.js.map +1 -1
  127. package/workflows/blobs/hydrate.d.ts +3 -1
  128. package/workflows/blobs/hydrate.js +2 -0
  129. package/workflows/blobs/hydrate.js.map +1 -1
  130. package/workflows/blobs/retainedAttachmentVerification.js +2 -0
  131. package/workflows/blobs/retainedAttachmentVerification.js.map +1 -1
  132. package/workflows/container-contents/container-state/createAdoption.js +2 -0
  133. package/workflows/container-contents/container-state/createAdoption.js.map +1 -1
  134. package/workflows/container-contents/container-state/createWithMetadata.js +7 -39
  135. package/workflows/container-contents/container-state/createWithMetadata.js.map +1 -1
  136. package/workflows/container-contents/container-state/createWithMetadataPlan.js +68 -0
  137. package/workflows/container-contents/container-state/createWithMetadataPlan.js.map +1 -0
  138. package/workflows/container-contents/remoteContainerState.js +3 -1
  139. package/workflows/container-contents/remoteContainerState.js.map +1 -1
  140. package/workflows/container-contents/remoteHydration/verifiedDestination.js +3 -0
  141. package/workflows/container-contents/remoteHydration/verifiedDestination.js.map +1 -1
  142. package/workflows/container-contents/runtime.d.ts +3 -0
  143. package/workflows/container-contents/runtime.js +7 -6
  144. package/workflows/container-contents/runtime.js.map +1 -1
  145. package/workflows/documents/create.d.ts +2 -15
  146. package/workflows/documents/create.js +9 -64
  147. package/workflows/documents/create.js.map +1 -1
  148. package/workflows/documents/createProjection.d.ts +14 -0
  149. package/workflows/documents/createProjection.js +26 -0
  150. package/workflows/documents/createProjection.js.map +1 -0
  151. package/workflows/documents/createResponse.js +49 -0
  152. package/workflows/documents/createResponse.js.map +1 -0
  153. package/workflows/documents/linkSetBlobRewraps.js +2 -0
  154. package/workflows/documents/linkSetBlobRewraps.js.map +1 -1
  155. package/workflows/documents/runtime.d.ts +3 -0
  156. package/workflows/documents/runtime.js +3 -2
  157. package/workflows/documents/runtime.js.map +1 -1
  158. package/workflows/documents/syncFailureClassification.js +3 -1
  159. package/workflows/documents/syncFailureClassification.js.map +1 -1
  160. package/workflows/principals/index.d.ts +2 -0
  161. package/workflows/principals/index.js +1 -0
  162. package/workflows/principals/index.js.map +1 -1
  163. package/workflows/principals/policyVerification.js.map +1 -1
  164. package/workflows/principals/principalHistoryRecoveryAuthority.js +20 -0
  165. package/workflows/principals/principalHistoryRecoveryAuthority.js.map +1 -0
  166. package/workflows/principals/principalHistoryRecoveryStage.js +1 -1
  167. package/workflows/principals/principalHistoryRecoveryStage.js.map +1 -1
  168. package/workflows/principals/principalHistoryRecoveryTypes.d.ts +3 -3
  169. package/workflows/principals/principalHistoryRecoveryTypes.js.map +1 -1
  170. package/workflows/principals/principalHistoryRecoveryVerification.js +6 -1
  171. package/workflows/principals/principalHistoryRecoveryVerification.js.map +1 -1
  172. package/workflows/principals/principalRecoveryOutage.js +1 -1
  173. package/workflows/principals/principalRecoveryOutage.js.map +1 -1
  174. package/workflows/principals/publicPrincipalHistoryAuthority.js +60 -0
  175. package/workflows/principals/publicPrincipalHistoryAuthority.js.map +1 -0
  176. package/workflows/principals/publicPrincipalHistoryPage.js +87 -0
  177. package/workflows/principals/publicPrincipalHistoryPage.js.map +1 -0
  178. package/workflows/principals/publicPrincipalHistoryProgress.js +178 -0
  179. package/workflows/principals/publicPrincipalHistoryProgress.js.map +1 -0
  180. package/workflows/principals/publicPrincipalHistoryTypes.d.ts +39 -0
  181. package/workflows/principals/publicPrincipalHistoryTypes.js +2 -0
  182. package/workflows/principals/publicPrincipalHistoryTypes.js.map +1 -0
  183. package/workflows/principals/publicProjectionDirectory.js +40 -0
  184. package/workflows/principals/publicProjectionDirectory.js.map +1 -0
  185. package/workflows/principals/publicProjectionPrincipal.js +53 -0
  186. package/workflows/principals/publicProjectionPrincipal.js.map +1 -0
  187. package/workflows/principals/recoverPrincipalPolicyHistory.js +4 -1
  188. package/workflows/principals/recoverPrincipalPolicyHistory.js.map +1 -1
  189. package/workflows/principals/recoverProjectionPolicyHistory.d.ts +9 -0
  190. package/workflows/principals/recoverProjectionPolicyHistory.js +98 -0
  191. package/workflows/principals/recoverProjectionPolicyHistory.js.map +1 -0
  192. package/workflows/principals/recoverPublicPrincipalHistory.js +176 -0
  193. package/workflows/principals/recoverPublicPrincipalHistory.js.map +1 -0
  194. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js +2 -5
  195. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js.map +1 -1
  196. package/workflows/principals/runtimePolicyRecovery.js +2 -1
  197. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  198. package/workflows/principals/runtimePolicyWarmer.js +2 -0
  199. package/workflows/principals/runtimePolicyWarmer.js.map +1 -1
  200. package/workflows/principals/runtimeProjectionPolicyRecovery.js +56 -0
  201. package/workflows/principals/runtimeProjectionPolicyRecovery.js.map +1 -0
  202. package/workflows/principals/selectPublicPrincipalHistory.js +90 -0
  203. package/workflows/principals/selectPublicPrincipalHistory.js.map +1 -0
  204. package/workflows/registration/provisioningBootstrapBuilders.d.ts +21 -153
@@ -0,0 +1,178 @@
1
+ import { createPrincipalPolicyHistoryVerifier, KeyingVerificationError, restorePrincipalPolicyHistoryVerifier, serializeKeyingCanonicalJson, verifyPrincipalPolicyHistoryReferences, } from "../../internal/crypto/index.js";
2
+ import { isReferencedPrincipalStateResponse } from "../../internal/validators/response/index.js";
3
+ import { loadPrincipalHistoryReference } from "../../data/persistence/principalHistoryEvidencePersistence.js";
4
+ import { discardPrincipalHistoryPrefix, loadPrincipalHistoryPrefix, savePrincipalHistoryPrefix, } from "../../data/persistence/principalHistoryPrefixPersistence.js";
5
+ import { discardPrincipalHistoryStage, loadPrincipalHistoryStage, } from "../../data/persistence/principalHistoryStagePersistence.js";
6
+ import { principalHeadMatchesReference } from "../../data/principals/organizationAuthorityDescriptor.js";
7
+ import { principalHistoryEvidenceScopeId, principalHistoryPrefixProtection, } from "../../data/principals/principalHistoryPrefixProtection.js";
8
+ import { principalHistoryStageId, principalHistoryStageProtection, } from "../../data/principals/principalHistoryStageProtection.js";
9
+ import { PublicHistoryAuthorityUnavailableError, parsePublicHistoryAuthority, publicHistoryAuthorityJson, validatePublicHistoryAuthority, } from "./publicPrincipalHistoryAuthority.js";
10
+ async function restorePublicPrefix(input, scopeId, id, prefix) {
11
+ const head = input.source.head;
12
+ const historyInput = {
13
+ principalType: head.principalType,
14
+ principalId: head.principalId,
15
+ };
16
+ const current = () => !input.signal?.aborted && input.stillCurrent();
17
+ if (prefix) {
18
+ const authorityReference = parsePublicHistoryAuthority(input, prefix.currentJson);
19
+ let prefixHead;
20
+ try {
21
+ prefixHead = JSON.parse(prefix.headJson);
22
+ }
23
+ catch {
24
+ prefixHead = null;
25
+ }
26
+ if (prefix.organizationId === input.organizationId &&
27
+ authorityReference !== undefined &&
28
+ isReferencedPrincipalStateResponse(prefixHead) &&
29
+ prefixHead.principalId === head.principalId &&
30
+ prefixHead.principalType === head.principalType &&
31
+ prefixHead.version === prefix.version) {
32
+ const restored = await restorePrincipalPolicyHistoryVerifier(historyInput, prefix.progress, await principalHistoryPrefixProtection(input.protection, prefix));
33
+ if (restored.ok && restored.value.finish(prefixHead).ok) {
34
+ await validatePublicHistoryAuthority(input, authorityReference, prefix);
35
+ return {
36
+ id,
37
+ scopeId,
38
+ verifier: restored.value,
39
+ completedHead: prefixHead.version >= head.version ? prefixHead : null,
40
+ afterVersion: Math.min(prefixHead.version, head.version - 1),
41
+ saved: null,
42
+ cachedPrefix: prefix,
43
+ authorityReference,
44
+ };
45
+ }
46
+ }
47
+ if (!input.offline)
48
+ await discardPrincipalHistoryPrefix({
49
+ execSql: input.execSql,
50
+ prefix,
51
+ stillCurrent: current,
52
+ });
53
+ }
54
+ return null;
55
+ }
56
+ export async function restorePublicPrincipalHistoryProgress(input, allowReuse) {
57
+ const head = input.source.head;
58
+ const historyInput = {
59
+ principalType: head.principalType,
60
+ principalId: head.principalId,
61
+ };
62
+ const scopeId = await principalHistoryEvidenceScopeId({
63
+ organizationId: input.organizationId,
64
+ head,
65
+ protection: input.protection,
66
+ });
67
+ const id = await principalHistoryStageId(input.organizationId, head, input.protection.context);
68
+ const current = () => !input.signal?.aborted && input.stillCurrent();
69
+ const saved = await loadPrincipalHistoryStage(input.execSql, id);
70
+ if (saved) {
71
+ const authorityReference = parsePublicHistoryAuthority(input, saved.currentJson);
72
+ if (allowReuse &&
73
+ saved.organizationId === input.organizationId &&
74
+ authorityReference !== undefined) {
75
+ const restored = await restorePrincipalPolicyHistoryVerifier(historyInput, saved.progress, await principalHistoryStageProtection(input.protection, head, saved));
76
+ if (restored.ok && (!saved.complete || restored.value.finish(head).ok)) {
77
+ await validatePublicHistoryAuthority(input, authorityReference);
78
+ return {
79
+ id,
80
+ scopeId,
81
+ verifier: restored.value,
82
+ completedHead: saved.complete ? head : null,
83
+ afterVersion: saved.afterVersion,
84
+ saved,
85
+ cachedPrefix: null,
86
+ authorityReference,
87
+ };
88
+ }
89
+ }
90
+ if (!input.offline)
91
+ await discardPrincipalHistoryStage(input.execSql, saved, current);
92
+ }
93
+ if (allowReuse) {
94
+ const prefix = await restorePublicPrefix(input, scopeId, id, await loadPrincipalHistoryPrefix(input.execSql, scopeId));
95
+ if (prefix)
96
+ return prefix;
97
+ }
98
+ return {
99
+ id,
100
+ scopeId,
101
+ verifier: createPrincipalPolicyHistoryVerifier(historyInput),
102
+ completedHead: null,
103
+ afterVersion: 0,
104
+ saved: null,
105
+ cachedPrefix: null,
106
+ authorityReference: null,
107
+ };
108
+ }
109
+ /** A resumed stage may finish after the reader that rejected the prefix exits. */
110
+ async function rejectedCompletedPrefix(input, progress, history) {
111
+ const candidate = await loadPrincipalHistoryPrefix(input.execSql, progress.scopeId);
112
+ if (!candidate || candidate.version <= history.currentEntry.state.version)
113
+ return null;
114
+ try {
115
+ const cached = await restorePublicPrefix(input, progress.scopeId, progress.id, candidate);
116
+ if (!cached?.completedHead)
117
+ return null;
118
+ const finished = cached.verifier.finish(cached.completedHead);
119
+ if (!finished.ok)
120
+ throw finished.error;
121
+ const proof = await loadPrincipalHistoryReference({
122
+ execSql: input.execSql,
123
+ scopeId: progress.scopeId,
124
+ history: finished.value,
125
+ version: input.source.head.version,
126
+ });
127
+ const verified = await verifyPrincipalPolicyHistoryReferences({
128
+ history: finished.value,
129
+ references: [proof],
130
+ });
131
+ if (!verified.ok)
132
+ throw verified.error;
133
+ return principalHeadMatchesReference(proof.entry.state, input.source.head)
134
+ ? null
135
+ : candidate;
136
+ }
137
+ catch (error) {
138
+ if (error instanceof KeyingVerificationError ||
139
+ error instanceof PublicHistoryAuthorityUnavailableError)
140
+ return candidate;
141
+ throw error;
142
+ }
143
+ }
144
+ export async function publishPublicPrincipalHistoryPrefix(input, progress, history, rejectedPrefix) {
145
+ const state = history.currentEntry.state;
146
+ const head = {
147
+ principalType: state.principalType,
148
+ principalId: state.principalId,
149
+ version: state.version,
150
+ stateHash: state.stateHash,
151
+ keyEpoch: state.keyEpoch,
152
+ keyFingerprint: state.keyFingerprint,
153
+ };
154
+ const prefix = {
155
+ scopeId: progress.scopeId,
156
+ organizationId: input.organizationId,
157
+ version: head.version,
158
+ headJson: serializeKeyingCanonicalJson(head),
159
+ currentJson: publicHistoryAuthorityJson(progress.authorityReference),
160
+ };
161
+ const sealed = await progress.verifier.exportProgress(await principalHistoryPrefixProtection(input.protection, prefix));
162
+ if (!sealed.ok)
163
+ throw sealed.error;
164
+ const rejected = rejectedPrefix ??
165
+ (progress.cachedPrefix
166
+ ? null
167
+ : await rejectedCompletedPrefix(input, progress, history));
168
+ const stillCurrent = () => !input.signal?.aborted && input.stillCurrent();
169
+ await savePrincipalHistoryPrefix({
170
+ execSql: input.execSql,
171
+ prefix: { ...prefix, progress: sealed.value },
172
+ stillCurrent,
173
+ rejectedPrefix: rejected,
174
+ });
175
+ if (progress.saved)
176
+ await discardPrincipalHistoryStage(input.execSql, progress.saved, stillCurrent);
177
+ }
178
+ //# sourceMappingURL=publicPrincipalHistoryProgress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicPrincipalHistoryProgress.js","sourceRoot":"","sources":["publicPrincipalHistoryProgress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oCAAoC,EACpC,uBAAuB,EACvB,qCAAqC,EACrC,4BAA4B,EAE5B,sCAAsC,GACvC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kCAAkC,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,6BAA6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sourcesContent":["import {\n createPrincipalPolicyHistoryVerifier,\n KeyingVerificationError,\n restorePrincipalPolicyHistoryVerifier,\n serializeKeyingCanonicalJson,\n type VerifiedPrincipalPolicyHistory,\n verifyPrincipalPolicyHistoryReferences,\n} from \"@tearleads/crypto\";\nimport { isReferencedPrincipalStateResponse } from \"@tearleads/validators/response\";\nimport { loadPrincipalHistoryReference } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport {\n discardPrincipalHistoryPrefix,\n loadPrincipalHistoryPrefix,\n type PrincipalHistoryPrefix,\n savePrincipalHistoryPrefix,\n} from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport {\n discardPrincipalHistoryStage,\n loadPrincipalHistoryStage,\n} from \"../../data/persistence/principalHistoryStagePersistence\";\nimport { principalHeadMatchesReference } from \"../../data/principals/organizationAuthorityDescriptor\";\nimport {\n principalHistoryEvidenceScopeId,\n principalHistoryPrefixProtection,\n} from \"../../data/principals/principalHistoryPrefixProtection\";\nimport {\n principalHistoryStageId,\n principalHistoryStageProtection,\n} from \"../../data/principals/principalHistoryStageProtection\";\nimport {\n PublicHistoryAuthorityUnavailableError,\n parsePublicHistoryAuthority,\n publicHistoryAuthorityJson,\n validatePublicHistoryAuthority,\n} from \"./publicPrincipalHistoryAuthority\";\nimport type {\n PublicPrincipalHistoryOptions,\n PublicPrincipalHistoryProgress,\n} from \"./publicPrincipalHistoryTypes\";\n\nasync function restorePublicPrefix(\n input: PublicPrincipalHistoryOptions,\n scopeId: string,\n id: string,\n prefix: PrincipalHistoryPrefix | null,\n): Promise<PublicPrincipalHistoryProgress | null> {\n const head = input.source.head;\n const historyInput = {\n principalType: head.principalType,\n principalId: head.principalId,\n };\n const current = () => !input.signal?.aborted && input.stillCurrent();\n if (prefix) {\n const authorityReference = parsePublicHistoryAuthority(\n input,\n prefix.currentJson,\n );\n let prefixHead: unknown;\n try {\n prefixHead = JSON.parse(prefix.headJson);\n } catch {\n prefixHead = null;\n }\n if (\n prefix.organizationId === input.organizationId &&\n authorityReference !== undefined &&\n isReferencedPrincipalStateResponse(prefixHead) &&\n prefixHead.principalId === head.principalId &&\n prefixHead.principalType === head.principalType &&\n prefixHead.version === prefix.version\n ) {\n const restored = await restorePrincipalPolicyHistoryVerifier(\n historyInput,\n prefix.progress,\n await principalHistoryPrefixProtection(input.protection, prefix),\n );\n if (restored.ok && restored.value.finish(prefixHead).ok) {\n await validatePublicHistoryAuthority(input, authorityReference, prefix);\n return {\n id,\n scopeId,\n verifier: restored.value,\n completedHead: prefixHead.version >= head.version ? prefixHead : null,\n afterVersion: Math.min(prefixHead.version, head.version - 1),\n saved: null,\n cachedPrefix: prefix,\n authorityReference,\n };\n }\n }\n if (!input.offline)\n await discardPrincipalHistoryPrefix({\n execSql: input.execSql,\n prefix,\n stillCurrent: current,\n });\n }\n return null;\n}\n\nexport async function restorePublicPrincipalHistoryProgress(\n input: PublicPrincipalHistoryOptions,\n allowReuse: boolean,\n): Promise<PublicPrincipalHistoryProgress> {\n const head = input.source.head;\n const historyInput = {\n principalType: head.principalType,\n principalId: head.principalId,\n };\n const scopeId = await principalHistoryEvidenceScopeId({\n organizationId: input.organizationId,\n head,\n protection: input.protection,\n });\n const id = await principalHistoryStageId(\n input.organizationId,\n head,\n input.protection.context,\n );\n const current = () => !input.signal?.aborted && input.stillCurrent();\n const saved = await loadPrincipalHistoryStage(input.execSql, id);\n if (saved) {\n const authorityReference = parsePublicHistoryAuthority(\n input,\n saved.currentJson,\n );\n if (\n allowReuse &&\n saved.organizationId === input.organizationId &&\n authorityReference !== undefined\n ) {\n const restored = await restorePrincipalPolicyHistoryVerifier(\n historyInput,\n saved.progress,\n await principalHistoryStageProtection(input.protection, head, saved),\n );\n if (restored.ok && (!saved.complete || restored.value.finish(head).ok)) {\n await validatePublicHistoryAuthority(input, authorityReference);\n return {\n id,\n scopeId,\n verifier: restored.value,\n completedHead: saved.complete ? head : null,\n afterVersion: saved.afterVersion,\n saved,\n cachedPrefix: null,\n authorityReference,\n };\n }\n }\n if (!input.offline)\n await discardPrincipalHistoryStage(input.execSql, saved, current);\n }\n if (allowReuse) {\n const prefix = await restorePublicPrefix(\n input,\n scopeId,\n id,\n await loadPrincipalHistoryPrefix(input.execSql, scopeId),\n );\n if (prefix) return prefix;\n }\n return {\n id,\n scopeId,\n verifier: createPrincipalPolicyHistoryVerifier(historyInput),\n completedHead: null,\n afterVersion: 0,\n saved: null,\n cachedPrefix: null,\n authorityReference: null,\n };\n}\n\n/** A resumed stage may finish after the reader that rejected the prefix exits. */\nasync function rejectedCompletedPrefix(\n input: PublicPrincipalHistoryOptions,\n progress: PublicPrincipalHistoryProgress,\n history: VerifiedPrincipalPolicyHistory,\n): Promise<PrincipalHistoryPrefix | null> {\n const candidate = await loadPrincipalHistoryPrefix(\n input.execSql,\n progress.scopeId,\n );\n if (!candidate || candidate.version <= history.currentEntry.state.version)\n return null;\n try {\n const cached = await restorePublicPrefix(\n input,\n progress.scopeId,\n progress.id,\n candidate,\n );\n if (!cached?.completedHead) return null;\n const finished = cached.verifier.finish(cached.completedHead);\n if (!finished.ok) throw finished.error;\n const proof = await loadPrincipalHistoryReference({\n execSql: input.execSql,\n scopeId: progress.scopeId,\n history: finished.value,\n version: input.source.head.version,\n });\n const verified = await verifyPrincipalPolicyHistoryReferences({\n history: finished.value,\n references: [proof],\n });\n if (!verified.ok) throw verified.error;\n return principalHeadMatchesReference(proof.entry.state, input.source.head)\n ? null\n : candidate;\n } catch (error) {\n if (\n error instanceof KeyingVerificationError ||\n error instanceof PublicHistoryAuthorityUnavailableError\n )\n return candidate;\n throw error;\n }\n}\n\nexport async function publishPublicPrincipalHistoryPrefix(\n input: PublicPrincipalHistoryOptions,\n progress: PublicPrincipalHistoryProgress,\n history: VerifiedPrincipalPolicyHistory,\n rejectedPrefix: PrincipalHistoryPrefix | null,\n): Promise<void> {\n const state = history.currentEntry.state;\n const head = {\n principalType: state.principalType,\n principalId: state.principalId,\n version: state.version,\n stateHash: state.stateHash,\n keyEpoch: state.keyEpoch,\n keyFingerprint: state.keyFingerprint,\n };\n const prefix = {\n scopeId: progress.scopeId,\n organizationId: input.organizationId,\n version: head.version,\n headJson: serializeKeyingCanonicalJson(head),\n currentJson: publicHistoryAuthorityJson(progress.authorityReference),\n };\n const sealed = await progress.verifier.exportProgress(\n await principalHistoryPrefixProtection(input.protection, prefix),\n );\n if (!sealed.ok) throw sealed.error;\n const rejected =\n rejectedPrefix ??\n (progress.cachedPrefix\n ? null\n : await rejectedCompletedPrefix(input, progress, history));\n const stillCurrent = () => !input.signal?.aborted && input.stillCurrent();\n await savePrincipalHistoryPrefix({\n execSql: input.execSql,\n prefix: { ...prefix, progress: sealed.value },\n stillCurrent,\n rejectedPrefix: rejected,\n });\n if (progress.saved)\n await discardPrincipalHistoryStage(\n input.execSql,\n progress.saved,\n stillCurrent,\n );\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import type { ApiClient } from "../../internal/api-client/index.js";
2
+ import type { PrincipalPolicyExternalAuthority, PrincipalPolicyHistoryProgressOptions, PrincipalPolicyHistoryVerifier, ReferencedPrincipalHead, VerifiedPrincipalPolicyHistory } from "../../internal/crypto/index.js";
3
+ import type { PrincipalPolicyHistorySourceResponse } from "../../internal/validators/response/index.js";
4
+ import type { PrincipalHistoryPrefix } from "../../data/persistence/principalHistoryPrefixPersistence.js";
5
+ import type { PrincipalHistoryStage } from "../../data/persistence/principalHistoryStagePersistence.js";
6
+ import type { ExecSql } from "../../data/sqlite/sqlSchema.js";
7
+ import type { TrustedUserIdentityResolver } from "../../data/trustedUserIdentity/index.js";
8
+ export interface PublicPrincipalHistoryOptions {
9
+ readonly apiClient: Pick<ApiClient, "getProjectionPolicyHistoryPages">;
10
+ readonly source: PrincipalPolicyHistorySourceResponse;
11
+ readonly organizationId: string;
12
+ readonly execSql: ExecSql;
13
+ readonly protection: PrincipalPolicyHistoryProgressOptions;
14
+ readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;
15
+ readonly stillCurrent: () => boolean;
16
+ readonly signal?: AbortSignal | undefined;
17
+ readonly offline?: boolean | undefined;
18
+ /** Retry disposable evidence loss once from signatures, without reusing hints. */
19
+ readonly replay?: boolean | undefined;
20
+ readonly strictAdmins?: boolean | undefined;
21
+ /** Already verified organization binding; included in the protected cache scope. */
22
+ readonly authorityGroupId?: string | undefined;
23
+ readonly loadExternalAuthority?: ((references: readonly ReferencedPrincipalHead[], cachedPrefix?: boolean) => Promise<PrincipalPolicyExternalAuthority | undefined>) | undefined;
24
+ }
25
+ export interface PublicPrincipalHistoryProgress {
26
+ readonly id: string;
27
+ readonly scopeId: string;
28
+ readonly verifier: PrincipalPolicyHistoryVerifier;
29
+ readonly completedHead: ReferencedPrincipalHead | null;
30
+ readonly afterVersion: number;
31
+ readonly saved: PrincipalHistoryStage | null;
32
+ readonly cachedPrefix: PrincipalHistoryPrefix | null;
33
+ readonly authorityReference: ReferencedPrincipalHead | null;
34
+ }
35
+ /** Public authorization only; caller must check directory binding and local pins. */
36
+ export interface RecoveredPublicPrincipalHistory {
37
+ readonly scopeId: string;
38
+ readonly history: VerifiedPrincipalPolicyHistory;
39
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=publicPrincipalHistoryTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicPrincipalHistoryTypes.js","sourceRoot":"","sources":["publicPrincipalHistoryTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { ApiClient } from \"@tearleads/api-client\";\nimport type {\n PrincipalPolicyExternalAuthority,\n PrincipalPolicyHistoryProgressOptions,\n PrincipalPolicyHistoryVerifier,\n ReferencedPrincipalHead,\n VerifiedPrincipalPolicyHistory,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyHistorySourceResponse } from \"@tearleads/validators/response\";\nimport type { PrincipalHistoryPrefix } from \"../../data/persistence/principalHistoryPrefixPersistence\";\nimport type { PrincipalHistoryStage } from \"../../data/persistence/principalHistoryStagePersistence\";\nimport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nimport type { TrustedUserIdentityResolver } from \"../../data/trustedUserIdentity\";\n\nexport interface PublicPrincipalHistoryOptions {\n readonly apiClient: Pick<ApiClient, \"getProjectionPolicyHistoryPages\">;\n readonly source: PrincipalPolicyHistorySourceResponse;\n readonly organizationId: string;\n readonly execSql: ExecSql;\n readonly protection: PrincipalPolicyHistoryProgressOptions;\n readonly resolveTrustedUserIdentity: TrustedUserIdentityResolver;\n readonly stillCurrent: () => boolean;\n readonly signal?: AbortSignal | undefined;\n readonly offline?: boolean | undefined;\n /** Retry disposable evidence loss once from signatures, without reusing hints. */\n readonly replay?: boolean | undefined;\n readonly strictAdmins?: boolean | undefined;\n /** Already verified organization binding; included in the protected cache scope. */\n readonly authorityGroupId?: string | undefined;\n readonly loadExternalAuthority?:\n | ((\n references: readonly ReferencedPrincipalHead[],\n cachedPrefix?: boolean,\n ) => Promise<PrincipalPolicyExternalAuthority | undefined>)\n | undefined;\n}\n\nexport interface PublicPrincipalHistoryProgress {\n readonly id: string;\n readonly scopeId: string;\n readonly verifier: PrincipalPolicyHistoryVerifier;\n readonly completedHead: ReferencedPrincipalHead | null;\n readonly afterVersion: number;\n readonly saved: PrincipalHistoryStage | null;\n readonly cachedPrefix: PrincipalHistoryPrefix | null;\n readonly authorityReference: ReferencedPrincipalHead | null;\n}\n\n/** Public authorization only; caller must check directory binding and local pins. */\nexport interface RecoveredPublicPrincipalHistory {\n readonly scopeId: string;\n readonly history: VerifiedPrincipalPolicyHistory;\n}\n"]}
@@ -0,0 +1,40 @@
1
+ import { computePrincipalStatePayloadCiphertextHash, } from "../../internal/crypto/index.js";
2
+ import { parseOrganizationAuthorityDescriptor, principalHeadMatchesReference, } from "../../data/principals/organizationAuthorityDescriptor.js";
3
+ import { rejectPublicProjection, selectPublicProjectionPrincipal, } from "./publicProjectionPrincipal.js";
4
+ export async function publicProjectionDirectoryBindings(evidence, organization) {
5
+ const policies = await selectPublicProjectionPrincipal(organization);
6
+ const entries = policies.flatMap((policy) => policy.retainedHistory);
7
+ const descriptors = [];
8
+ const seen = new Set();
9
+ for (const { reference, payload } of evidence.organizationPayloads) {
10
+ const state = entries.find(({ state }) => principalHeadMatchesReference(state, reference))?.state;
11
+ if (!state ||
12
+ reference.version > organization.options.source.head.version ||
13
+ payload.principalType !== "organization" ||
14
+ payload.principalId !== organization.options.organizationId ||
15
+ payload.stateHash !== state.stateHash ||
16
+ seen.has(state.stateHash))
17
+ rejectPublicProjection("directory payload scope is invalid");
18
+ seen.add(state.stateHash);
19
+ const hash = await computePrincipalStatePayloadCiphertextHash(payload.ciphertext);
20
+ if (hash !== payload.ciphertextHash || hash !== state.payloadCiphertextHash)
21
+ rejectPublicProjection("directory payload differs from its signed hash");
22
+ const descriptor = parseOrganizationAuthorityDescriptor(payload.ciphertext);
23
+ if (descriptor.organizationId !== organization.options.organizationId)
24
+ rejectPublicProjection("directory belongs to another organization");
25
+ descriptors.push(descriptor);
26
+ }
27
+ const bindings = new Map();
28
+ for (const source of evidence.groups) {
29
+ if (source.head.principalType !== "group" ||
30
+ bindings.has(source.head.principalId))
31
+ rejectPublicProjection("group sources have invalid or repeated scopes");
32
+ const directory = descriptors.find((candidate) => candidate.groupHeads.some((head) => principalHeadMatchesReference(head, source.head)));
33
+ const adminHead = directory?.groupHeads.find((head) => head.principalId === directory.adminGroupId);
34
+ if (!adminHead)
35
+ rejectPublicProjection("group source lacks its signed directory binding");
36
+ bindings.set(source.head.principalId, { adminHead });
37
+ }
38
+ return bindings;
39
+ }
40
+ //# sourceMappingURL=publicProjectionDirectory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicProjectionDirectory.js","sourceRoot":"","sources":["publicProjectionDirectory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0CAA0C,GAE3C,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,oCAAoC,EACpC,6BAA6B,GAC9B,MAAM,uDAAuD,CAAC;AAC/D,OAAO,EAEL,sBAAsB,EACtB,+BAA+B,GAChC,MAA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AO,CAAC,UAAU,CAAC,CAAC;QAC5E,IAAI,UAAU,CAAC,cAAc,KAAK,YAAY,CAAC,OAAO,CAAC,cAAc;YACnE,sBAAsB,CAAC,2CAA2C,CAAC,CAAC;QACtE,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkD,CAAC;IAC3E,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrC,IACE,MAAM,CAAC,IAAI,CAAC,aAAa,KAAK,OAAO;YACrC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;YAErC,sBAAsB,CAAC,+CAA+C,CAAC,CAAC;QAC1E,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAC/C,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACjC,6BAA6B,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CACjD,CACF,CAAC;QACF,MAAM,SAAS,GAAG,SAAS,EAAE,UAAU,CAAC,IAAI,CAC1C,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,YAAY,CACtD,CAAC;QACF,IAAI,CAAC,SAAS;YACZ,sBAAsB,CAAC,iDAAiD,CAAC,CAAC;QAC5E,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {\n computePrincipalStatePayloadCiphertextHash,\n type ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport type { ProjectionPolicyEvidenceResponse } from \"@tearleads/validators/response\";\nimport {\n parseOrganizationAuthorityDescriptor,\n principalHeadMatchesReference,\n} from \"../../data/principals/organizationAuthorityDescriptor\";\nimport {\n type PublicProjectionPrincipal,\n rejectPublicProjection,\n selectPublicProjectionPrincipal,\n} from \"./publicProjectionPrincipal\";\n\nexport async function publicProjectionDirectoryBindings(\n evidence: ProjectionPolicyEvidenceResponse,\n organization: PublicProjectionPrincipal,\n) {\n const policies = await selectPublicProjectionPrincipal(organization);\n const entries = policies.flatMap((policy) => policy.retainedHistory);\n const descriptors = [];\n const seen = new Set<string>();\n for (const { reference, payload } of evidence.organizationPayloads) {\n const state = entries.find(({ state }) =>\n principalHeadMatchesReference(state, reference),\n )?.state;\n if (\n !state ||\n reference.version > organization.options.source.head.version ||\n payload.principalType !== \"organization\" ||\n payload.principalId !== organization.options.organizationId ||\n payload.stateHash !== state.stateHash ||\n seen.has(state.stateHash)\n )\n rejectPublicProjection(\"directory payload scope is invalid\");\n seen.add(state.stateHash);\n const hash = await computePrincipalStatePayloadCiphertextHash(\n payload.ciphertext,\n );\n if (hash !== payload.ciphertextHash || hash !== state.payloadCiphertextHash)\n rejectPublicProjection(\"directory payload differs from its signed hash\");\n const descriptor = parseOrganizationAuthorityDescriptor(payload.ciphertext);\n if (descriptor.organizationId !== organization.options.organizationId)\n rejectPublicProjection(\"directory belongs to another organization\");\n descriptors.push(descriptor);\n }\n const bindings = new Map<string, { adminHead: ReferencedPrincipalHead }>();\n for (const source of evidence.groups) {\n if (\n source.head.principalType !== \"group\" ||\n bindings.has(source.head.principalId)\n )\n rejectPublicProjection(\"group sources have invalid or repeated scopes\");\n const directory = descriptors.find((candidate) =>\n candidate.groupHeads.some((head) =>\n principalHeadMatchesReference(head, source.head),\n ),\n );\n const adminHead = directory?.groupHeads.find(\n (head) => head.principalId === directory.adminGroupId,\n );\n if (!adminHead)\n rejectPublicProjection(\"group source lacks its signed directory binding\");\n bindings.set(source.head.principalId, { adminHead });\n }\n return bindings;\n}\n"]}
@@ -0,0 +1,53 @@
1
+ import { KeyingVerificationError, } from "../../internal/crypto/index.js";
2
+ import { assertProjectionVerificationCurrent } from "../../data/keyingProjectionVerification/types.js";
3
+ import { loadPrincipalPolicyCheckpoint } from "../../data/persistence/keyingCheckpointPersistence.js";
4
+ import { PrincipalHistoryEvidenceUnavailableError } from "./principalHistoryRecoveryReferences.js";
5
+ import { recoverPublicPrincipalHistory } from "./recoverPublicPrincipalHistory.js";
6
+ import { selectPublicPrincipalHistory } from "./selectPublicPrincipalHistory.js";
7
+ /** The source head and every citation remain bound independently of a newer prefix. */
8
+ export async function selectPublicProjectionPrincipal(principal, references = principal.references) {
9
+ const { options } = principal;
10
+ const current = () => !options.signal?.aborted && options.stillCurrent();
11
+ assertProjectionVerificationCurrent(current);
12
+ const checkpoint = await loadPrincipalPolicyCheckpoint(options.execSql, options.source.head.principalType, options.source.head.principalId);
13
+ try {
14
+ return await selectPublicPrincipalHistory({
15
+ execSql: options.execSql,
16
+ recovered: principal.recovered,
17
+ references: [options.source.head, ...references],
18
+ checkpoint,
19
+ includeGenesis: options.source.head.principalType === "organization",
20
+ stillCurrent: current,
21
+ });
22
+ }
23
+ catch (error) {
24
+ if (!(error instanceof PrincipalHistoryEvidenceUnavailableError))
25
+ throw error;
26
+ if (options.offline || principal.replayed)
27
+ throw error.verificationError;
28
+ principal.replayed = true;
29
+ principal.recovered = await recoverPublicPrincipalHistory({
30
+ ...options,
31
+ replay: true,
32
+ });
33
+ return selectPublicProjectionPrincipal(principal, references);
34
+ }
35
+ }
36
+ export async function recoverPublicProjectionPrincipal(options, references) {
37
+ const selected = references.filter((head) => head.principalType === options.source.head.principalType &&
38
+ head.principalId === options.source.head.principalId);
39
+ if (selected.some((head) => head.version > options.source.head.version))
40
+ rejectPublicProjection("citation exceeds its supplied source head");
41
+ const principal = {
42
+ options,
43
+ references: structuredClone(selected),
44
+ recovered: await recoverPublicPrincipalHistory(options),
45
+ replayed: false,
46
+ };
47
+ await selectPublicProjectionPrincipal(principal);
48
+ return principal;
49
+ }
50
+ export function rejectPublicProjection(message) {
51
+ throw new KeyingVerificationError("object_mismatch", `Public projection history: ${message}`);
52
+ }
53
+ //# sourceMappingURL=publicProjectionPrincipal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicProjectionPrincipal.js","sourceRoot":"","sources":["publicProjectionPrincipal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,wCAAwC,EAAE,MAAM,sCAAsC,CAAC;AAKhG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAS9E,uFAAuF;AACvF,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,SAAoC,EACpC,aAAiD,SAAS,CAAC,UAAU;IAErE,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;IAC9B,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IACzE,mCAAmC,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,MAAM,6BAA6B,CACpD,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EACjC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAChC,CAAC;IACF,IAAI,CAAC;QACH,OAAO,MAAM,4BAA4B,CAAC;YACxC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,UAAU,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,UAAU,CAAC;YAChD,UAAU;YACV,cAAc,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,KAAK,cAAc;YACpE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IACpD,MAAM,IAAI,uBAAuB,CAC/B,iBAAiB,EACjB,8BAA8B,OAAO,EAAE,CACxC,CAAC;AACJ,CAAC","sourcesContent":["import {\n KeyingVerificationError,\n type ReferencedPrincipalHead,\n} from \"@tearleads/crypto\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalPolicyCheckpoint } from \"../../data/persistence/keyingCheckpointPersistence\";\nimport { PrincipalHistoryEvidenceUnavailableError } from \"./principalHistoryRecoveryReferences\";\nimport type {\n PublicPrincipalHistoryOptions,\n RecoveredPublicPrincipalHistory,\n} from \"./publicPrincipalHistoryTypes\";\nimport { recoverPublicPrincipalHistory } from \"./recoverPublicPrincipalHistory\";\nimport { selectPublicPrincipalHistory } from \"./selectPublicPrincipalHistory\";\n\nexport interface PublicProjectionPrincipal {\n readonly options: PublicPrincipalHistoryOptions;\n readonly references: readonly ReferencedPrincipalHead[];\n recovered: RecoveredPublicPrincipalHistory;\n replayed: boolean;\n}\n\n/** The source head and every citation remain bound independently of a newer prefix. */\nexport async function selectPublicProjectionPrincipal(\n principal: PublicProjectionPrincipal,\n references: readonly ReferencedPrincipalHead[] = principal.references,\n) {\n const { options } = principal;\n const current = () => !options.signal?.aborted && options.stillCurrent();\n assertProjectionVerificationCurrent(current);\n const checkpoint = await loadPrincipalPolicyCheckpoint(\n options.execSql,\n options.source.head.principalType,\n options.source.head.principalId,\n );\n try {\n return await selectPublicPrincipalHistory({\n execSql: options.execSql,\n recovered: principal.recovered,\n references: [options.source.head, ...references],\n checkpoint,\n includeGenesis: options.source.head.principalType === \"organization\",\n stillCurrent: current,\n });\n } catch (error) {\n if (!(error instanceof PrincipalHistoryEvidenceUnavailableError))\n throw error;\n if (options.offline || principal.replayed) throw error.verificationError;\n principal.replayed = true;\n principal.recovered = await recoverPublicPrincipalHistory({\n ...options,\n replay: true,\n });\n return selectPublicProjectionPrincipal(principal, references);\n }\n}\n\nexport async function recoverPublicProjectionPrincipal(\n options: PublicPrincipalHistoryOptions,\n references: readonly ReferencedPrincipalHead[],\n): Promise<PublicProjectionPrincipal> {\n const selected = references.filter(\n (head) =>\n head.principalType === options.source.head.principalType &&\n head.principalId === options.source.head.principalId,\n );\n if (selected.some((head) => head.version > options.source.head.version))\n rejectPublicProjection(\"citation exceeds its supplied source head\");\n const principal = {\n options,\n references: structuredClone(selected),\n recovered: await recoverPublicPrincipalHistory(options),\n replayed: false,\n };\n await selectPublicProjectionPrincipal(principal);\n return principal;\n}\n\nexport function rejectPublicProjection(message: string): never {\n throw new KeyingVerificationError(\n \"object_mismatch\",\n `Public projection history: ${message}`,\n );\n}\n"]}
@@ -6,6 +6,7 @@ import { discardPrincipalHistoryStage, savePrincipalHistoryStage, } from "../../
6
6
  import { ownPrincipalHistoryProtection } from "../../data/principals/principalHistoryProtection.js";
7
7
  import { principalHistoryStageProtection } from "../../data/principals/principalHistoryStageProtection.js";
8
8
  import { collectPrincipalPolicySignerPublicKeys } from "./policyVerification.js";
9
+ import { validatePrincipalHistoryRecoveryAuthority } from "./principalHistoryRecoveryAuthority.js";
9
10
  import { publishReusablePrincipalHistoryPrefix } from "./principalHistoryRecoveryPrefix.js";
10
11
  import { PrincipalHistoryEvidenceUnavailableError, selectRecoveredPrincipalHistory, } from "./principalHistoryRecoveryReferences.js";
11
12
  import { restorePrincipalHistoryRecoveryStage, } from "./principalHistoryRecoveryStage.js";
@@ -74,7 +75,7 @@ async function acceptPage(input, stage, response) {
74
75
  });
75
76
  if ("error" in keys)
76
77
  throw new KeyingVerificationError(keys.error === "not-found" ? "missing_dependency" : "signer_mismatch", "Principal history signer identity could not be authenticated");
77
- const externalAuthority = await input.loadExternalAuthority?.(entries);
78
+ const externalAuthority = await input.loadExternalAuthority?.(entries.flatMap(({ state }) => state.externalAuthority ? [state.externalAuthority] : []));
78
79
  const appended = await stage.verifier.append({
79
80
  entries,
80
81
  signerPublicKeys: keys.signerPublicKeys,
@@ -196,6 +197,8 @@ async function recover(input, allowEvidenceRebuild = true) {
196
197
  };
197
198
  const stage = await restorePrincipalHistoryRecoveryStage(input, historyInput, allowEvidenceRebuild);
198
199
  try {
200
+ if (stage.fromCache)
201
+ await validatePrincipalHistoryRecoveryAuthority(input, stage.verifier);
199
202
  await readRecoveryPages(input, stage);
200
203
  return await finishRecovery(input, stage, checkpoint);
201
204
  }
@@ -1 +1 @@
1
- {"version":3,"file":"recoverPrincipalPolicyHistory.js","sourceRoot":"","sources":["recoverPrincipalPolicyHistory.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oCAAoC,EACpC,uBAAuB,EAGvB,+BAA+B,EAC/B,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,mCAAmC,EAAE,MAAM,4DAA4D,CAAC;AACjH,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,yDAAyD,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,kDAAkD,CAAC;AACjG,OAAO,EAAE,+BAA+B,EAAE,MAAM,uDAAuD,CAAC;AACxG,OAAO,EAAE,sCAAsC,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,qCAAqC,EAAE,MAAM,kCAAkC,CAAC;AACzF,OAAO,EACL,wCAAwC,EACxC,+BAA+B,GAChC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAEL,oCAAoC,GACrC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,iCAAiC,EACjC,+BAA+B,GAGhC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,sCAAsC,EACtC,mCAAmC,GACpC,MAAM,wCAAwC,CAAC;AAEhD,MAAM,uCAAwC,SAAQ,KAAK;IACpC;IAArB,YAAqB,iBAA0C;QAC7D,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QADd,sBAA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pC,CAAC;AACH,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport {\n createPrincipalPolicyHistoryVerifier,\n KeyingVerificationError,\n type PrincipalPolicyCheckpoint,\n type PrincipalPolicyHistoryInput,\n verifyPrincipalPolicyCheckpoint,\n verifyPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyPageResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalPolicyCheckpoint } from \"../../data/persistence/keyingCheckpointPersistence\";\nimport { preparePrincipalHistoryEvidencePage } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport {\n discardPrincipalHistoryStage,\n savePrincipalHistoryStage,\n} from \"../../data/persistence/principalHistoryStagePersistence\";\nimport { ownPrincipalHistoryProtection } from \"../../data/principals/principalHistoryProtection\";\nimport { principalHistoryStageProtection } from \"../../data/principals/principalHistoryStageProtection\";\nimport { collectPrincipalPolicySignerPublicKeys } from \"./policyVerification\";\nimport { publishReusablePrincipalHistoryPrefix } from \"./principalHistoryRecoveryPrefix\";\nimport {\n PrincipalHistoryEvidenceUnavailableError,\n selectRecoveredPrincipalHistory,\n} from \"./principalHistoryRecoveryReferences\";\nimport {\n type PrincipalHistoryRecoveryStage,\n restorePrincipalHistoryRecoveryStage,\n} from \"./principalHistoryRecoveryStage\";\nimport {\n PrincipalHistoryRecoveryRaceError,\n PrincipalPolicyHistoryReadError,\n type RecoveredPrincipalPolicyHistory,\n type RecoverPrincipalPolicyHistoryOptions,\n} from \"./principalHistoryRecoveryTypes\";\nimport {\n assertPrincipalHistoryVerificationMode,\n principalHistoryVerificationContext,\n} from \"./principalHistoryRecoveryVerification\";\n\nclass PrincipalHistoryPrefixDisconnectedError extends Error {\n constructor(readonly verificationError: KeyingVerificationError) {\n super(verificationError.message);\n this.name = \"PrincipalHistoryPrefixDisconnectedError\";\n }\n}\n\nfunction currentArtifacts(\n page: PrincipalPolicyPageResponse,\n): PrincipalPolicyPageCurrent {\n return {\n currentState: page.currentState,\n currentPayload: page.currentPayload,\n currentProjection: page.currentProjection,\n currentGrants: page.currentGrants,\n currentMemberEnvelopes: page.currentMemberEnvelopes,\n };\n}\n\nfunction recoveryIsCurrent(\n input: RecoverPrincipalPolicyHistoryOptions,\n): boolean {\n return !input.signal?.aborted && input.stillCurrent();\n}\n\nfunction assertCurrent(input: RecoverPrincipalPolicyHistoryOptions): void {\n assertProjectionVerificationCurrent(() => recoveryIsCurrent(input));\n}\n\nfunction assertExpectedHead(\n current: PrincipalPolicyPageCurrent,\n expectedHead: RecoverPrincipalPolicyHistoryOptions[\"expectedHead\"],\n): void {\n for (const field of [\n \"principalType\",\n \"principalId\",\n \"version\",\n \"stateHash\",\n \"keyEpoch\",\n \"keyFingerprint\",\n ] as const) {\n if (current.currentState[field] !== expectedHead[field])\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Principal history page does not match its requested head\",\n );\n }\n}\n\nasync function acceptPage(\n input: RecoverPrincipalPolicyHistoryOptions,\n stage: PrincipalHistoryRecoveryStage,\n response: PrincipalPolicyPageResponse,\n): Promise<void> {\n const page = structuredClone(response);\n assertCurrent(input);\n assertExpectedHead(page, input.expectedHead);\n if (stage.complete) {\n if (\n page.previousStates.length !== 0 ||\n page.historyPage.nextAfterVersion !== null\n )\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"Completed history returned additional entries\",\n );\n stage.current = currentArtifacts(page);\n return;\n }\n const complete = page.historyPage.nextAfterVersion === null;\n const current = currentArtifacts(page);\n const entries = [...page.previousStates];\n if (complete)\n entries.push({\n state: current.currentState,\n projection: current.currentProjection,\n grants: current.currentGrants,\n });\n assertPrincipalHistoryVerificationMode(input, entries);\n const keys = await collectPrincipalPolicySignerPublicKeys({\n bundle: { ...current, previousStates: page.previousStates },\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n });\n if (\"error\" in keys)\n throw new KeyingVerificationError(\n keys.error === \"not-found\" ? \"missing_dependency\" : \"signer_mismatch\",\n \"Principal history signer identity could not be authenticated\",\n );\n const externalAuthority = await input.loadExternalAuthority?.(entries);\n const appended = await stage.verifier.append({\n entries,\n signerPublicKeys: keys.signerPublicKeys,\n ...(externalAuthority ? { externalAuthority } : {}),\n });\n if (!appended.ok) {\n if (appended.error.code === \"stale_predecessor\")\n throw new PrincipalHistoryPrefixDisconnectedError(appended.error);\n throw appended.error;\n }\n const next = {\n id: stage.id,\n organizationId: input.organizationId,\n currentJson: JSON.stringify(current),\n afterVersion: appended.value.throughVersion - (complete ? 1 : 0),\n complete,\n };\n const protectedProgress = await stage.verifier.exportProgress(\n await principalHistoryStageProtection(\n input.protection,\n input.expectedHead,\n next,\n ),\n );\n if (!protectedProgress.ok) throw protectedProgress.error;\n const saved = { ...next, progress: protectedProgress.value };\n await savePrincipalHistoryStage({\n execSql: input.execSql,\n stage: saved,\n evidence: await preparePrincipalHistoryEvidencePage({\n scopeId: stage.scopeId,\n organizationId: input.organizationId,\n entries,\n nodes: appended.value.indexNodes,\n }),\n previousProgress: stage.saved?.progress ?? null,\n stillCurrent: () => recoveryIsCurrent(input),\n });\n stage.current = current;\n stage.saved = saved;\n stage.complete = complete;\n}\n\nasync function finishRecovery(\n input: RecoverPrincipalPolicyHistoryOptions,\n stage: PrincipalHistoryRecoveryStage,\n checkpoint: PrincipalPolicyCheckpoint | null,\n): Promise<RecoveredPrincipalPolicyHistory> {\n if (!stage.current || !stage.complete)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Principal history ended before its pinned head\",\n );\n const history = stage.verifier.finish(input.expectedHead);\n if (!history.ok) throw history.error;\n const selected = await selectRecoveredPrincipalHistory({\n options: input,\n scopeId: stage.scopeId,\n history: history.value,\n checkpoint,\n });\n const current = await verifyPrincipalPolicyCurrent({\n current: stage.current,\n history: selected,\n });\n if (!current.ok) throw current.error;\n verifyPrincipalPolicyCheckpoint({\n chain: current.value.retainedHistory,\n currentState: current.value.state,\n localCheckpoint: checkpoint,\n });\n const latest = await loadPrincipalPolicyCheckpoint(\n input.execSql,\n input.expectedHead.principalType,\n input.expectedHead.principalId,\n );\n if (\n latest?.version !== checkpoint?.version ||\n latest?.stateHash !== checkpoint?.stateHash\n )\n throw new PrincipalHistoryRecoveryRaceError(\n \"Local principal checkpoint changed during history recovery\",\n );\n assertCurrent(input);\n if (!input.offline)\n await publishReusablePrincipalHistoryPrefix(\n input,\n stage.scopeId,\n stage.verifier,\n stage.current,\n );\n assertCurrent(input);\n return { current: stage.current, policy: current.value };\n}\n\nasync function readRecoveryPages(\n input: RecoverPrincipalPolicyHistoryOptions,\n stage: PrincipalHistoryRecoveryStage,\n): Promise<void> {\n if (input.offline) {\n if (!stage.complete || !stage.current)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Completed principal history is unavailable offline\",\n );\n assertExpectedHead(stage.current, input.expectedHead);\n return;\n }\n let receivedFinalPage = false;\n for await (const result of input.apiClient.getPrincipalPolicyPages(\n input.expectedHead.principalType,\n input.expectedHead.principalId,\n {\n signal: input.signal,\n stateHash: input.expectedHead.stateHash,\n ...(stage.saved && stage.current\n ? {\n resume: {\n current: stage.current,\n afterVersion: stage.saved.afterVersion,\n },\n }\n : { afterVersion: stage.initialAfterVersion }),\n },\n )) {\n if (!result.ok) {\n // A rejected transport pin cannot justify skipping history on retry.\n // Discard only this operation's progress, then let a new call replay it.\n if (result.kind === \"shape\" && stage.saved)\n await discardPrincipalHistoryStage(input.execSql, stage.saved, () =>\n recoveryIsCurrent(input),\n );\n throw new PrincipalPolicyHistoryReadError(result);\n }\n await acceptPage(input, stage, result.data);\n receivedFinalPage = result.data.historyPage.nextAfterVersion === null;\n }\n if (!receivedFinalPage)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Principal history transport did not complete\",\n );\n}\n\nasync function recover(\n input: RecoverPrincipalPolicyHistoryOptions,\n allowEvidenceRebuild = true,\n): Promise<RecoveredPrincipalPolicyHistory> {\n assertCurrent(input);\n const checkpoint = await loadPrincipalPolicyCheckpoint(\n input.execSql,\n input.expectedHead.principalType,\n input.expectedHead.principalId,\n );\n if (checkpoint && input.expectedHead.version < checkpoint.version)\n throw new KeyingVerificationError(\n input.offline ? \"missing_dependency\" : \"rollback\",\n \"Requested principal history predates the local checkpoint\",\n );\n // Validate the requested pin/selection before creating any disposable caches.\n createPrincipalPolicyHistoryVerifier({\n principalType: input.expectedHead.principalType,\n principalId: input.expectedHead.principalId,\n localCheckpoint: checkpoint,\n retainedReferences: input.retainedReferences ?? [],\n });\n const historyInput: PrincipalPolicyHistoryInput = {\n principalType: input.expectedHead.principalType,\n principalId: input.expectedHead.principalId,\n };\n const stage = await restorePrincipalHistoryRecoveryStage(\n input,\n historyInput,\n allowEvidenceRebuild,\n );\n try {\n await readRecoveryPages(input, stage);\n return await finishRecovery(input, stage, checkpoint);\n } catch (error) {\n const lostEvidence =\n error instanceof PrincipalHistoryEvidenceUnavailableError;\n const disconnected =\n error instanceof PrincipalHistoryPrefixDisconnectedError;\n if (!lostEvidence && !disconnected) throw error;\n if (stage.saved)\n await discardPrincipalHistoryStage(input.execSql, stage.saved, () =>\n recoveryIsCurrent(input),\n );\n if (\n !input.offline &&\n allowEvidenceRebuild &&\n (lostEvidence || stage.fromCache)\n )\n return recover(input, false);\n throw lostEvidence || disconnected ? error.verificationError : error;\n }\n}\n\n/**\n * Recover one exact head with bounded retained history and durable checked progress.\n * The result is a sparse current-policy capability; this does not advance app checkpoints.\n * Retain organization version 1 when the result will establish founder binding.\n */\nexport async function recoverPrincipalPolicyHistory(\n options: RecoverPrincipalPolicyHistoryOptions,\n): Promise<RecoveredPrincipalPolicyHistory> {\n if (options.offline !== undefined && typeof options.offline !== \"boolean\")\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"Invalid principal history transport mode\",\n );\n if (\n !options.organizationId ||\n (options.expectedHead.principalType === \"organization\" &&\n options.expectedHead.principalId !== options.organizationId)\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Principal history organization scope is invalid\",\n );\n if (\n options.retainedReferences?.some(\n (reference) => reference.version > options.expectedHead.version,\n )\n )\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Requested history reference is beyond the recovery head\",\n );\n const input = {\n ...options,\n historyVerification: options.historyVerification ?? \"standard\",\n expectedHead: structuredClone(options.expectedHead),\n retainedReferences: structuredClone(options.retainedReferences ?? []),\n protection: ownPrincipalHistoryProtection(options.protection),\n };\n try {\n input.protection.context = principalHistoryVerificationContext(input);\n return await recover(input);\n } finally {\n input.protection.localKey.fill(0);\n }\n}\n"]}
1
+ {"version":3,"file":"recoverPrincipalPolicyHistory.js","sourceRoot":"","sources":["recoverPrincipalPolicyHistory.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oCAAoC,EACpC,uBAAuB,EAGvB,+BAA+B,EAC/B,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,mCAAmC,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,mCAAmC,EAAE,MAAM,4DAA4D,CAAC;AACjH,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,yDAAyD,CAAC;AACjE,OAAO,EAAE,6BAA6B,EAAE,MAAM,kDAAkD,CAAC;AACjG,OAAO,EAAE,+BAA+B,EAAE,MAAM,uDAAuD,CAAC;AACxG,OAAO,EAAE,sCAAsC,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,yCAAyC,EAAE,MAAM,qCAAqC,CAAC;AAChG,OAAO,EAAE,qCAAqC,EAAE,MAAM,kCAAkC,CAAC;AACzF,OAAO,EACL,wCAAwC,EACxC,+BAA+B,GAChC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAEL,oCAAoC,GACrC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,iCAAiC,EACjC,+BAA+B,GAGhC,MAAM,iCAAiC,CA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mBAAmB,IAAI,UAAU;QAC9D,YAAY,EAAE,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC;QACnD,kBAAkB,EAAE,eAAe,CAAC,OAAO,CAAC,kBAAkB,IAAI,EAAE,CAAC;QACrE,UAAU,EAAE,6BAA6B,CAAC,OAAO,CAAC,UAAU,CAAC;KAC9D,CAAC;IACF,IAAI,CAAC;QACH,KAAK,CAAC,UAAU,CAAC,OAAO,GAAG,mCAAmC,CAAC,KAAK,CAAC,CAAC;QACtE,OAAO,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;AACH,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport {\n createPrincipalPolicyHistoryVerifier,\n KeyingVerificationError,\n type PrincipalPolicyCheckpoint,\n type PrincipalPolicyHistoryInput,\n verifyPrincipalPolicyCheckpoint,\n verifyPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyPageResponse } from \"@tearleads/validators/response\";\nimport { assertProjectionVerificationCurrent } from \"../../data/keyingProjectionVerification/types\";\nimport { loadPrincipalPolicyCheckpoint } from \"../../data/persistence/keyingCheckpointPersistence\";\nimport { preparePrincipalHistoryEvidencePage } from \"../../data/persistence/principalHistoryEvidencePersistence\";\nimport {\n discardPrincipalHistoryStage,\n savePrincipalHistoryStage,\n} from \"../../data/persistence/principalHistoryStagePersistence\";\nimport { ownPrincipalHistoryProtection } from \"../../data/principals/principalHistoryProtection\";\nimport { principalHistoryStageProtection } from \"../../data/principals/principalHistoryStageProtection\";\nimport { collectPrincipalPolicySignerPublicKeys } from \"./policyVerification\";\nimport { validatePrincipalHistoryRecoveryAuthority } from \"./principalHistoryRecoveryAuthority\";\nimport { publishReusablePrincipalHistoryPrefix } from \"./principalHistoryRecoveryPrefix\";\nimport {\n PrincipalHistoryEvidenceUnavailableError,\n selectRecoveredPrincipalHistory,\n} from \"./principalHistoryRecoveryReferences\";\nimport {\n type PrincipalHistoryRecoveryStage,\n restorePrincipalHistoryRecoveryStage,\n} from \"./principalHistoryRecoveryStage\";\nimport {\n PrincipalHistoryRecoveryRaceError,\n PrincipalPolicyHistoryReadError,\n type RecoveredPrincipalPolicyHistory,\n type RecoverPrincipalPolicyHistoryOptions,\n} from \"./principalHistoryRecoveryTypes\";\nimport {\n assertPrincipalHistoryVerificationMode,\n principalHistoryVerificationContext,\n} from \"./principalHistoryRecoveryVerification\";\n\nclass PrincipalHistoryPrefixDisconnectedError extends Error {\n constructor(readonly verificationError: KeyingVerificationError) {\n super(verificationError.message);\n this.name = \"PrincipalHistoryPrefixDisconnectedError\";\n }\n}\n\nfunction currentArtifacts(\n page: PrincipalPolicyPageResponse,\n): PrincipalPolicyPageCurrent {\n return {\n currentState: page.currentState,\n currentPayload: page.currentPayload,\n currentProjection: page.currentProjection,\n currentGrants: page.currentGrants,\n currentMemberEnvelopes: page.currentMemberEnvelopes,\n };\n}\n\nfunction recoveryIsCurrent(\n input: RecoverPrincipalPolicyHistoryOptions,\n): boolean {\n return !input.signal?.aborted && input.stillCurrent();\n}\n\nfunction assertCurrent(input: RecoverPrincipalPolicyHistoryOptions): void {\n assertProjectionVerificationCurrent(() => recoveryIsCurrent(input));\n}\n\nfunction assertExpectedHead(\n current: PrincipalPolicyPageCurrent,\n expectedHead: RecoverPrincipalPolicyHistoryOptions[\"expectedHead\"],\n): void {\n for (const field of [\n \"principalType\",\n \"principalId\",\n \"version\",\n \"stateHash\",\n \"keyEpoch\",\n \"keyFingerprint\",\n ] as const) {\n if (current.currentState[field] !== expectedHead[field])\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Principal history page does not match its requested head\",\n );\n }\n}\n\nasync function acceptPage(\n input: RecoverPrincipalPolicyHistoryOptions,\n stage: PrincipalHistoryRecoveryStage,\n response: PrincipalPolicyPageResponse,\n): Promise<void> {\n const page = structuredClone(response);\n assertCurrent(input);\n assertExpectedHead(page, input.expectedHead);\n if (stage.complete) {\n if (\n page.previousStates.length !== 0 ||\n page.historyPage.nextAfterVersion !== null\n )\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"Completed history returned additional entries\",\n );\n stage.current = currentArtifacts(page);\n return;\n }\n const complete = page.historyPage.nextAfterVersion === null;\n const current = currentArtifacts(page);\n const entries = [...page.previousStates];\n if (complete)\n entries.push({\n state: current.currentState,\n projection: current.currentProjection,\n grants: current.currentGrants,\n });\n assertPrincipalHistoryVerificationMode(input, entries);\n const keys = await collectPrincipalPolicySignerPublicKeys({\n bundle: { ...current, previousStates: page.previousStates },\n resolveTrustedUserIdentity: input.resolveTrustedUserIdentity,\n });\n if (\"error\" in keys)\n throw new KeyingVerificationError(\n keys.error === \"not-found\" ? \"missing_dependency\" : \"signer_mismatch\",\n \"Principal history signer identity could not be authenticated\",\n );\n const externalAuthority = await input.loadExternalAuthority?.(\n entries.flatMap(({ state }) =>\n state.externalAuthority ? [state.externalAuthority] : [],\n ),\n );\n const appended = await stage.verifier.append({\n entries,\n signerPublicKeys: keys.signerPublicKeys,\n ...(externalAuthority ? { externalAuthority } : {}),\n });\n if (!appended.ok) {\n if (appended.error.code === \"stale_predecessor\")\n throw new PrincipalHistoryPrefixDisconnectedError(appended.error);\n throw appended.error;\n }\n const next = {\n id: stage.id,\n organizationId: input.organizationId,\n currentJson: JSON.stringify(current),\n afterVersion: appended.value.throughVersion - (complete ? 1 : 0),\n complete,\n };\n const protectedProgress = await stage.verifier.exportProgress(\n await principalHistoryStageProtection(\n input.protection,\n input.expectedHead,\n next,\n ),\n );\n if (!protectedProgress.ok) throw protectedProgress.error;\n const saved = { ...next, progress: protectedProgress.value };\n await savePrincipalHistoryStage({\n execSql: input.execSql,\n stage: saved,\n evidence: await preparePrincipalHistoryEvidencePage({\n scopeId: stage.scopeId,\n organizationId: input.organizationId,\n entries,\n nodes: appended.value.indexNodes,\n }),\n previousProgress: stage.saved?.progress ?? null,\n stillCurrent: () => recoveryIsCurrent(input),\n });\n stage.current = current;\n stage.saved = saved;\n stage.complete = complete;\n}\n\nasync function finishRecovery(\n input: RecoverPrincipalPolicyHistoryOptions,\n stage: PrincipalHistoryRecoveryStage,\n checkpoint: PrincipalPolicyCheckpoint | null,\n): Promise<RecoveredPrincipalPolicyHistory> {\n if (!stage.current || !stage.complete)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Principal history ended before its pinned head\",\n );\n const history = stage.verifier.finish(input.expectedHead);\n if (!history.ok) throw history.error;\n const selected = await selectRecoveredPrincipalHistory({\n options: input,\n scopeId: stage.scopeId,\n history: history.value,\n checkpoint,\n });\n const current = await verifyPrincipalPolicyCurrent({\n current: stage.current,\n history: selected,\n });\n if (!current.ok) throw current.error;\n verifyPrincipalPolicyCheckpoint({\n chain: current.value.retainedHistory,\n currentState: current.value.state,\n localCheckpoint: checkpoint,\n });\n const latest = await loadPrincipalPolicyCheckpoint(\n input.execSql,\n input.expectedHead.principalType,\n input.expectedHead.principalId,\n );\n if (\n latest?.version !== checkpoint?.version ||\n latest?.stateHash !== checkpoint?.stateHash\n )\n throw new PrincipalHistoryRecoveryRaceError(\n \"Local principal checkpoint changed during history recovery\",\n );\n assertCurrent(input);\n if (!input.offline)\n await publishReusablePrincipalHistoryPrefix(\n input,\n stage.scopeId,\n stage.verifier,\n stage.current,\n );\n assertCurrent(input);\n return { current: stage.current, policy: current.value };\n}\n\nasync function readRecoveryPages(\n input: RecoverPrincipalPolicyHistoryOptions,\n stage: PrincipalHistoryRecoveryStage,\n): Promise<void> {\n if (input.offline) {\n if (!stage.complete || !stage.current)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Completed principal history is unavailable offline\",\n );\n assertExpectedHead(stage.current, input.expectedHead);\n return;\n }\n let receivedFinalPage = false;\n for await (const result of input.apiClient.getPrincipalPolicyPages(\n input.expectedHead.principalType,\n input.expectedHead.principalId,\n {\n signal: input.signal,\n stateHash: input.expectedHead.stateHash,\n ...(stage.saved && stage.current\n ? {\n resume: {\n current: stage.current,\n afterVersion: stage.saved.afterVersion,\n },\n }\n : { afterVersion: stage.initialAfterVersion }),\n },\n )) {\n if (!result.ok) {\n // A rejected transport pin cannot justify skipping history on retry.\n // Discard only this operation's progress, then let a new call replay it.\n if (result.kind === \"shape\" && stage.saved)\n await discardPrincipalHistoryStage(input.execSql, stage.saved, () =>\n recoveryIsCurrent(input),\n );\n throw new PrincipalPolicyHistoryReadError(result);\n }\n await acceptPage(input, stage, result.data);\n receivedFinalPage = result.data.historyPage.nextAfterVersion === null;\n }\n if (!receivedFinalPage)\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Principal history transport did not complete\",\n );\n}\n\nasync function recover(\n input: RecoverPrincipalPolicyHistoryOptions,\n allowEvidenceRebuild = true,\n): Promise<RecoveredPrincipalPolicyHistory> {\n assertCurrent(input);\n const checkpoint = await loadPrincipalPolicyCheckpoint(\n input.execSql,\n input.expectedHead.principalType,\n input.expectedHead.principalId,\n );\n if (checkpoint && input.expectedHead.version < checkpoint.version)\n throw new KeyingVerificationError(\n input.offline ? \"missing_dependency\" : \"rollback\",\n \"Requested principal history predates the local checkpoint\",\n );\n // Validate the requested pin/selection before creating any disposable caches.\n createPrincipalPolicyHistoryVerifier({\n principalType: input.expectedHead.principalType,\n principalId: input.expectedHead.principalId,\n localCheckpoint: checkpoint,\n retainedReferences: input.retainedReferences ?? [],\n });\n const historyInput: PrincipalPolicyHistoryInput = {\n principalType: input.expectedHead.principalType,\n principalId: input.expectedHead.principalId,\n };\n const stage = await restorePrincipalHistoryRecoveryStage(\n input,\n historyInput,\n allowEvidenceRebuild,\n );\n try {\n if (stage.fromCache)\n await validatePrincipalHistoryRecoveryAuthority(input, stage.verifier);\n await readRecoveryPages(input, stage);\n return await finishRecovery(input, stage, checkpoint);\n } catch (error) {\n const lostEvidence =\n error instanceof PrincipalHistoryEvidenceUnavailableError;\n const disconnected =\n error instanceof PrincipalHistoryPrefixDisconnectedError;\n if (!lostEvidence && !disconnected) throw error;\n if (stage.saved)\n await discardPrincipalHistoryStage(input.execSql, stage.saved, () =>\n recoveryIsCurrent(input),\n );\n if (\n !input.offline &&\n allowEvidenceRebuild &&\n (lostEvidence || stage.fromCache)\n )\n return recover(input, false);\n throw lostEvidence || disconnected ? error.verificationError : error;\n }\n}\n\n/**\n * Recover one exact head with bounded retained history and durable checked progress.\n * The result is a sparse current-policy capability; this does not advance app checkpoints.\n * Retain organization version 1 when the result will establish founder binding.\n */\nexport async function recoverPrincipalPolicyHistory(\n options: RecoverPrincipalPolicyHistoryOptions,\n): Promise<RecoveredPrincipalPolicyHistory> {\n if (options.offline !== undefined && typeof options.offline !== \"boolean\")\n throw new KeyingVerificationError(\n \"invalid_shape\",\n \"Invalid principal history transport mode\",\n );\n if (\n !options.organizationId ||\n (options.expectedHead.principalType === \"organization\" &&\n options.expectedHead.principalId !== options.organizationId)\n )\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Principal history organization scope is invalid\",\n );\n if (\n options.retainedReferences?.some(\n (reference) => reference.version > options.expectedHead.version,\n )\n )\n throw new KeyingVerificationError(\n \"missing_dependency\",\n \"Requested history reference is beyond the recovery head\",\n );\n const input = {\n ...options,\n historyVerification: options.historyVerification ?? \"standard\",\n expectedHead: structuredClone(options.expectedHead),\n retainedReferences: structuredClone(options.retainedReferences ?? []),\n protection: ownPrincipalHistoryProtection(options.protection),\n };\n try {\n input.protection.context = principalHistoryVerificationContext(input);\n return await recover(input);\n } finally {\n input.protection.localKey.fill(0);\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { type ReferencedPrincipalHead, type VerifiedPrincipalPolicySelection } from "../../internal/crypto/index.js";
2
+ import type { ProjectionPolicyEvidenceResponse } from "../../internal/validators/response/index.js";
3
+ import type { PublicPrincipalHistoryOptions } from "./publicPrincipalHistoryTypes.js";
4
+ export interface ProjectionPolicyHistoryRecoveryOptions extends Omit<PublicPrincipalHistoryOptions, "source" | "loadExternalAuthority" | "strictAdmins" | "authorityGroupId" | "replay"> {
5
+ readonly evidence: ProjectionPolicyEvidenceResponse;
6
+ readonly references: readonly ReferencedPrincipalHead[];
7
+ }
8
+ /** Public authorization only; no current-policy cache or checkpoint is written. */
9
+ export declare function recoverProjectionPolicyHistory(input: ProjectionPolicyHistoryRecoveryOptions): Promise<VerifiedPrincipalPolicySelection[]>;