@tearleads/client-sdk 0.1.116 → 0.1.118

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 (87) hide show
  1. package/data/keyingProjectionVerification/checkpoints/checkpointContext.d.ts +8 -1
  2. package/data/keyingProjectionVerification/checkpoints/checkpointContext.js +15 -0
  3. package/data/keyingProjectionVerification/checkpoints/checkpointContext.js.map +1 -1
  4. package/data/keyingProjectionVerification/container/containerProjectionVerification.js +3 -1
  5. package/data/keyingProjectionVerification/container/containerProjectionVerification.js.map +1 -1
  6. package/data/keyingProjectionVerification/document/documentProjectionVerification.js +2 -1
  7. package/data/keyingProjectionVerification/document/documentProjectionVerification.js.map +1 -1
  8. package/data/persistence/container-contents/containerContentsPersistence.js +14 -13
  9. package/data/persistence/container-contents/containerContentsPersistence.js.map +1 -1
  10. package/data/persistence/documents/internal/ensureDocumentsSchema.js +10 -12
  11. package/data/persistence/documents/internal/ensureDocumentsSchema.js.map +1 -1
  12. package/data/persistence/verifiedCitations/citationScope.js +121 -0
  13. package/data/persistence/verifiedCitations/citationScope.js.map +1 -0
  14. package/data/persistence/verifiedCitations/kekLevelCitations.d.ts +33 -0
  15. package/data/persistence/verifiedCitations/kekLevelCitations.js +44 -0
  16. package/data/persistence/verifiedCitations/kekLevelCitations.js.map +1 -0
  17. package/data/persistence/verifiedManifestBundlePersistence.d.ts +17 -12
  18. package/data/persistence/verifiedManifestBundlePersistence.js +75 -104
  19. package/data/persistence/verifiedManifestBundlePersistence.js.map +1 -1
  20. package/data/sqlite/schema/containerSchema.d.ts +1 -0
  21. package/data/sqlite/schema/containerSchema.js +8 -1
  22. package/data/sqlite/schema/containerSchema.js.map +1 -1
  23. package/data/sqlite/schema/documentAttachmentSchema.d.ts +0 -2
  24. package/data/sqlite/schema/documentAttachmentSchema.js +0 -4
  25. package/data/sqlite/schema/documentAttachmentSchema.js.map +1 -1
  26. package/data/sqlite/schema/index.d.ts +2 -0
  27. package/data/sqlite/schema/index.js +10 -1
  28. package/data/sqlite/schema/index.js.map +1 -1
  29. package/data/sqlite/schema/principalPolicySchema.js +0 -1
  30. package/data/sqlite/schema/principalPolicySchema.js.map +1 -1
  31. package/data/sqlite/schema/verifiedManifestBundleSchema.d.ts +7 -2
  32. package/data/sqlite/schema/verifiedManifestBundleSchema.js +11 -4
  33. package/data/sqlite/schema/verifiedManifestBundleSchema.js.map +1 -1
  34. package/data/sqlite/sqlExec.d.ts +12 -0
  35. package/data/sqlite/sqlExec.js +47 -3
  36. package/data/sqlite/sqlExec.js.map +1 -1
  37. package/data/sqlite/sqlTableSchema.js +40 -15
  38. package/data/sqlite/sqlTableSchema.js.map +1 -1
  39. package/data/sqlite/sqlitePersistenceRuntime.js +18 -10
  40. package/data/sqlite/sqlitePersistenceRuntime.js.map +1 -1
  41. package/internal/api-client/ApiClient.d.ts +3 -2
  42. package/internal/api-client/ApiClient.js +3 -2
  43. package/internal/api-client/ApiClient.js.map +1 -1
  44. package/internal/api-client/index.d.ts +1 -1
  45. package/internal/api-client/index.js.map +1 -1
  46. package/internal/api-client/types.d.ts +7 -0
  47. package/internal/api-client/types.js.map +1 -1
  48. package/internal/api-client/verifiedManifestCitations.d.ts +26 -9
  49. package/internal/api-client/verifiedManifestCitations.js +44 -25
  50. package/internal/api-client/verifiedManifestCitations.js.map +1 -1
  51. package/internal/api-client/writerProjectionRequests.js +21 -10
  52. package/internal/api-client/writerProjectionRequests.js.map +1 -1
  53. package/internal/crypto/index.d.ts +1 -1
  54. package/internal/crypto/index.js +1 -1
  55. package/internal/crypto/index.js.map +1 -1
  56. package/internal/crypto/keying/canonicalJsonGuard.d.ts +7 -0
  57. package/internal/crypto/keying/canonicalJsonGuard.js +20 -0
  58. package/internal/crypto/keying/canonicalJsonGuard.js.map +1 -1
  59. package/internal/crypto/keying/index.d.ts +1 -1
  60. package/internal/crypto/keying/index.js +1 -1
  61. package/internal/crypto/keying/index.js.map +1 -1
  62. package/internal/validators/knownManifestsRefinements.js +1 -1
  63. package/internal/validators/knownManifestsRefinements.js.map +1 -1
  64. package/internal/validators/operation/writerProjections.d.ts +42 -18
  65. package/internal/validators/response/container.d.ts +137 -16
  66. package/internal/validators/response/container.js +23 -2
  67. package/internal/validators/response/container.js.map +1 -1
  68. package/internal/validators/response/documentMutation.d.ts +20 -8
  69. package/internal/validators/response/index.d.ts +2 -2
  70. package/internal/validators/response/index.js +2 -2
  71. package/internal/validators/response/index.js.map +1 -1
  72. package/internal/validators/response/writerProjectionWire.d.ts +19 -8
  73. package/internal/validators/response/writerProjectionWire.js +78 -20
  74. package/internal/validators/response/writerProjectionWire.js.map +1 -1
  75. package/internal/validators/util/index.d.ts +1 -1
  76. package/internal/validators/util/index.js +1 -1
  77. package/internal/validators/util/index.js.map +1 -1
  78. package/internal/validators/util/knownManifestWire.d.ts +13 -3
  79. package/internal/validators/util/knownManifestWire.js +37 -10
  80. package/internal/validators/util/knownManifestWire.js.map +1 -1
  81. package/package.json +1 -1
  82. package/workflows/container-contents/remoteHydration/destination/destinationPrefetch.js +10 -5
  83. package/workflows/container-contents/remoteHydration/destination/destinationPrefetch.js.map +1 -1
  84. package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js +4 -6
  85. package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -1
  86. package/workflows/container-contents/remoteHydration/types.d.ts +2 -2
  87. package/workflows/container-contents/remoteHydration/types.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"knownManifestsRefinements.js","sourceRoot":"","sources":["knownManifestsRefinements.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,EAAE,EAAE,8BAA8B;IAClC,WAAW,EACT,iFAAiF;CAC3E,CAAC","sourcesContent":["export const knownManifestsHeaderRefinement = {\n id: \"request.known-manifest-hints\",\n description:\n \"x-known-manifests must list at most 48 unique lowercase SHA-256 manifest hashes\",\n} as const;\n"]}
1
+ {"version":3,"file":"knownManifestsRefinements.js","sourceRoot":"","sources":["knownManifestsRefinements.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,EAAE,EAAE,8BAA8B;IAClC,WAAW,EACT,uHAAuH;CACjH,CAAC","sourcesContent":["export const knownManifestsHeaderRefinement = {\n id: \"request.known-manifest-hints\",\n description:\n \"x-known-manifests must list at most 48 unique typed digests, each m: or k: followed by a lowercase SHA-256 hex digest\",\n} as const;\n"]}
@@ -125,7 +125,7 @@ export declare const getContainerWriterProjectionOperation: Omit<{
125
125
  }[];
126
126
  };
127
127
  containerId: string;
128
- containerKeks: {
128
+ containerKeks: ({
129
129
  containerManifestHistory: string[];
130
130
  accessManifestHash: string;
131
131
  containerId: string;
@@ -145,7 +145,10 @@ export declare const getContainerWriterProjectionOperation: Omit<{
145
145
  parentContainerKeyEpochId: string | null;
146
146
  recipientTargets: Record<string, unknown>[];
147
147
  wraps: Record<string, unknown>[];
148
- }[];
148
+ } | {
149
+ levelDigest: string;
150
+ containerManifestHistory: string[];
151
+ })[];
149
152
  organizationId: string;
150
153
  path: string[];
151
154
  bundles: Record<string, {
@@ -204,7 +207,7 @@ export declare const getContainerWriterProjectionOperation: Omit<{
204
207
  }[];
205
208
  };
206
209
  containerId: string;
207
- containerKeks: {
210
+ containerKeks: ({
208
211
  containerManifestHistory: string[];
209
212
  accessManifestHash: string;
210
213
  containerId: string;
@@ -224,7 +227,10 @@ export declare const getContainerWriterProjectionOperation: Omit<{
224
227
  parentContainerKeyEpochId: string | null;
225
228
  recipientTargets: Record<string, unknown>[];
226
229
  wraps: Record<string, unknown>[];
227
- }[];
230
+ } | {
231
+ levelDigest: string;
232
+ containerManifestHistory: string[];
233
+ })[];
228
234
  organizationId: string;
229
235
  path: string[];
230
236
  bundles: Record<string, {
@@ -283,7 +289,7 @@ export declare const getContainerWriterProjectionOperation: Omit<{
283
289
  }[];
284
290
  };
285
291
  containerId: string;
286
- containerKeks: {
292
+ containerKeks: ({
287
293
  containerManifestHistory: string[];
288
294
  accessManifestHash: string;
289
295
  containerId: string;
@@ -303,7 +309,10 @@ export declare const getContainerWriterProjectionOperation: Omit<{
303
309
  parentContainerKeyEpochId: string | null;
304
310
  recipientTargets: Record<string, unknown>[];
305
311
  wraps: Record<string, unknown>[];
306
- }[];
312
+ } | {
313
+ levelDigest: string;
314
+ containerManifestHistory: string[];
315
+ })[];
307
316
  organizationId: string;
308
317
  path: string[];
309
318
  bundles: Record<string, {
@@ -362,7 +371,7 @@ export declare const getContainerWriterProjectionOperation: Omit<{
362
371
  }[];
363
372
  };
364
373
  containerId: string;
365
- containerKeks: {
374
+ containerKeks: ({
366
375
  containerManifestHistory: string[];
367
376
  accessManifestHash: string;
368
377
  containerId: string;
@@ -382,7 +391,10 @@ export declare const getContainerWriterProjectionOperation: Omit<{
382
391
  parentContainerKeyEpochId: string | null;
383
392
  recipientTargets: Record<string, unknown>[];
384
393
  wraps: Record<string, unknown>[];
385
- }[];
394
+ } | {
395
+ levelDigest: string;
396
+ containerManifestHistory: string[];
397
+ })[];
386
398
  organizationId: string;
387
399
  path: string[];
388
400
  bundles: Record<string, {
@@ -414,7 +426,7 @@ export declare const getContainerWriterProjectionOperation: Omit<{
414
426
  readonly id: "response.writer-projection-manifest-bundles";
415
427
  }, {
416
428
  readonly id: "request.known-manifest-hints";
417
- readonly description: "x-known-manifests must list at most 48 unique lowercase SHA-256 manifest hashes";
429
+ readonly description: "x-known-manifests must list at most 48 unique typed digests, each m: or k: followed by a lowercase SHA-256 hex digest";
418
430
  }];
419
431
  }, "failureResponses" | "failureStatuses"> & {
420
432
  readonly failureResponses: {
@@ -600,7 +612,7 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
600
612
  };
601
613
  authorizingContainerPaths: {
602
614
  containerId: string;
603
- containerKeks: {
615
+ containerKeks: ({
604
616
  containerManifestHistory: string[];
605
617
  accessManifestHash: string;
606
618
  containerId: string;
@@ -620,7 +632,10 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
620
632
  parentContainerKeyEpochId: string | null;
621
633
  recipientTargets: Record<string, unknown>[];
622
634
  wraps: Record<string, unknown>[];
623
- }[];
635
+ } | {
636
+ levelDigest: string;
637
+ containerManifestHistory: string[];
638
+ })[];
624
639
  organizationId: string;
625
640
  path: string[];
626
641
  }[];
@@ -709,7 +724,7 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
709
724
  };
710
725
  authorizingContainerPaths: {
711
726
  containerId: string;
712
- containerKeks: {
727
+ containerKeks: ({
713
728
  containerManifestHistory: string[];
714
729
  accessManifestHash: string;
715
730
  containerId: string;
@@ -729,7 +744,10 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
729
744
  parentContainerKeyEpochId: string | null;
730
745
  recipientTargets: Record<string, unknown>[];
731
746
  wraps: Record<string, unknown>[];
732
- }[];
747
+ } | {
748
+ levelDigest: string;
749
+ containerManifestHistory: string[];
750
+ })[];
733
751
  organizationId: string;
734
752
  path: string[];
735
753
  }[];
@@ -818,7 +836,7 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
818
836
  };
819
837
  authorizingContainerPaths: {
820
838
  containerId: string;
821
- containerKeks: {
839
+ containerKeks: ({
822
840
  containerManifestHistory: string[];
823
841
  accessManifestHash: string;
824
842
  containerId: string;
@@ -838,7 +856,10 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
838
856
  parentContainerKeyEpochId: string | null;
839
857
  recipientTargets: Record<string, unknown>[];
840
858
  wraps: Record<string, unknown>[];
841
- }[];
859
+ } | {
860
+ levelDigest: string;
861
+ containerManifestHistory: string[];
862
+ })[];
842
863
  organizationId: string;
843
864
  path: string[];
844
865
  }[];
@@ -927,7 +948,7 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
927
948
  };
928
949
  authorizingContainerPaths: {
929
950
  containerId: string;
930
- containerKeks: {
951
+ containerKeks: ({
931
952
  containerManifestHistory: string[];
932
953
  accessManifestHash: string;
933
954
  containerId: string;
@@ -947,7 +968,10 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
947
968
  parentContainerKeyEpochId: string | null;
948
969
  recipientTargets: Record<string, unknown>[];
949
970
  wraps: Record<string, unknown>[];
950
- }[];
971
+ } | {
972
+ levelDigest: string;
973
+ containerManifestHistory: string[];
974
+ })[];
951
975
  organizationId: string;
952
976
  path: string[];
953
977
  }[];
@@ -997,7 +1021,7 @@ export declare const getDocumentWriterProjectionOperation: Omit<{
997
1021
  readonly id: "response.writer-projection-manifest-bundles";
998
1022
  }, {
999
1023
  readonly id: "request.known-manifest-hints";
1000
- readonly description: "x-known-manifests must list at most 48 unique lowercase SHA-256 manifest hashes";
1024
+ readonly description: "x-known-manifests must list at most 48 unique typed digests, each m: or k: followed by a lowercase SHA-256 hex digest";
1001
1025
  }];
1002
1026
  }, "failureResponses" | "failureStatuses"> & {
1003
1027
  readonly failureResponses: {
@@ -151,7 +151,104 @@ declare const ContainerKekResponseSchema: z.ZodType<{
151
151
  recipientTargets: Record<string, unknown>[];
152
152
  wraps: Record<string, unknown>[];
153
153
  }>>;
154
+ /** On the writer-projection wire, KEK history cites manifests by hash. */
155
+ declare const ContainerKekWireResponseSchema: z.ZodType<{
156
+ containerManifestHistory: string[];
157
+ accessManifestHash: string;
158
+ containerId: string;
159
+ containerKeyEpoch: number;
160
+ containerKeyEpochId: string;
161
+ keyEpoch: Record<string, unknown>;
162
+ keyEpochHash: string;
163
+ keyring: {
164
+ containerId: string;
165
+ containerKeyEpochId: string;
166
+ iv: string;
167
+ sealed: string;
168
+ sealingSuite: string;
169
+ version: number;
170
+ } | null;
171
+ keyTargetHash: string;
172
+ parentContainerKeyEpochId: string | null;
173
+ recipientTargets: Record<string, unknown>[];
174
+ wraps: Record<string, unknown>[];
175
+ }, {
176
+ containerManifestHistory: string[];
177
+ accessManifestHash: string;
178
+ containerId: string;
179
+ containerKeyEpoch: number;
180
+ containerKeyEpochId: string;
181
+ keyEpoch: Record<string, unknown>;
182
+ keyEpochHash: string;
183
+ keyring: {
184
+ containerId: string;
185
+ containerKeyEpochId: string;
186
+ iv: string;
187
+ sealed: string;
188
+ sealingSuite: string;
189
+ version: number;
190
+ } | null;
191
+ keyTargetHash: string;
192
+ parentContainerKeyEpochId: string | null;
193
+ recipientTargets: Record<string, unknown>[];
194
+ wraps: Record<string, unknown>[];
195
+ }, z.core.$ZodTypeInternals<{
196
+ containerManifestHistory: string[];
197
+ accessManifestHash: string;
198
+ containerId: string;
199
+ containerKeyEpoch: number;
200
+ containerKeyEpochId: string;
201
+ keyEpoch: Record<string, unknown>;
202
+ keyEpochHash: string;
203
+ keyring: {
204
+ containerId: string;
205
+ containerKeyEpochId: string;
206
+ iv: string;
207
+ sealed: string;
208
+ sealingSuite: string;
209
+ version: number;
210
+ } | null;
211
+ keyTargetHash: string;
212
+ parentContainerKeyEpochId: string | null;
213
+ recipientTargets: Record<string, unknown>[];
214
+ wraps: Record<string, unknown>[];
215
+ }, {
216
+ containerManifestHistory: string[];
217
+ accessManifestHash: string;
218
+ containerId: string;
219
+ containerKeyEpoch: number;
220
+ containerKeyEpochId: string;
221
+ keyEpoch: Record<string, unknown>;
222
+ keyEpochHash: string;
223
+ keyring: {
224
+ containerId: string;
225
+ containerKeyEpochId: string;
226
+ iv: string;
227
+ sealed: string;
228
+ sealingSuite: string;
229
+ version: number;
230
+ } | null;
231
+ keyTargetHash: string;
232
+ parentContainerKeyEpochId: string | null;
233
+ recipientTargets: Record<string, unknown>[];
234
+ wraps: Record<string, unknown>[];
235
+ }>>;
154
236
  export type ContainerKekResponse = z.infer<typeof ContainerKekResponseSchema>;
237
+ /** One KEK level as served in full, its manifest history cited by hash. */
238
+ export type ContainerKekWireLevel = z.infer<typeof ContainerKekWireResponseSchema>;
239
+ export declare function isContainerKekWireLevel(value: unknown): value is ContainerKekWireLevel;
240
+ /**
241
+ * A KEK level the request declared held (`k:` hint), replaced by the digest
242
+ * of its canonical wire bytes. It keeps the level's manifest citations, so
243
+ * the response's bundle bookkeeping stays exact; the client refills the
244
+ * level from those exact held bytes before anything reads it.
245
+ */
246
+ export declare const CitedContainerKekLevelSchema: z.ZodObject<{
247
+ levelDigest: z.ZodCustom<string, string>;
248
+ containerManifestHistory: z.ZodCustom<string[], string[]>;
249
+ }, z.core.$strict>;
250
+ export type CitedContainerKekLevel = z.infer<typeof CitedContainerKekLevelSchema>;
251
+ export declare function isCitedContainerKekLevel(value: unknown): value is CitedContainerKekLevel;
155
252
  /**
156
253
  * The append-only rotation log for one container: every epoch with its
157
254
  * write-once bridge and sealed keyring. This is the rebuild/repair read
@@ -1689,7 +1786,7 @@ export declare const ContainerWriterProjectionResponseSchema: z.ZodType<{
1689
1786
  export type ContainerWriterProjectionResponse = z.infer<typeof ContainerWriterProjectionResponseSchema>;
1690
1787
  export declare const ContainerKeyingPathWireResponseSchema: z.ZodType<{
1691
1788
  containerId: string;
1692
- containerKeks: {
1789
+ containerKeks: ({
1693
1790
  containerManifestHistory: string[];
1694
1791
  accessManifestHash: string;
1695
1792
  containerId: string;
@@ -1709,12 +1806,15 @@ export declare const ContainerKeyingPathWireResponseSchema: z.ZodType<{
1709
1806
  parentContainerKeyEpochId: string | null;
1710
1807
  recipientTargets: Record<string, unknown>[];
1711
1808
  wraps: Record<string, unknown>[];
1712
- }[];
1809
+ } | {
1810
+ levelDigest: string;
1811
+ containerManifestHistory: string[];
1812
+ })[];
1713
1813
  organizationId: string;
1714
1814
  path: string[];
1715
1815
  }, {
1716
1816
  containerId: string;
1717
- containerKeks: {
1817
+ containerKeks: ({
1718
1818
  containerManifestHistory: string[];
1719
1819
  accessManifestHash: string;
1720
1820
  containerId: string;
@@ -1734,12 +1834,15 @@ export declare const ContainerKeyingPathWireResponseSchema: z.ZodType<{
1734
1834
  parentContainerKeyEpochId: string | null;
1735
1835
  recipientTargets: Record<string, unknown>[];
1736
1836
  wraps: Record<string, unknown>[];
1737
- }[];
1837
+ } | {
1838
+ levelDigest: string;
1839
+ containerManifestHistory: string[];
1840
+ })[];
1738
1841
  organizationId: string;
1739
1842
  path: string[];
1740
1843
  }, z.core.$ZodTypeInternals<{
1741
1844
  containerId: string;
1742
- containerKeks: {
1845
+ containerKeks: ({
1743
1846
  containerManifestHistory: string[];
1744
1847
  accessManifestHash: string;
1745
1848
  containerId: string;
@@ -1759,12 +1862,15 @@ export declare const ContainerKeyingPathWireResponseSchema: z.ZodType<{
1759
1862
  parentContainerKeyEpochId: string | null;
1760
1863
  recipientTargets: Record<string, unknown>[];
1761
1864
  wraps: Record<string, unknown>[];
1762
- }[];
1865
+ } | {
1866
+ levelDigest: string;
1867
+ containerManifestHistory: string[];
1868
+ })[];
1763
1869
  organizationId: string;
1764
1870
  path: string[];
1765
1871
  }, {
1766
1872
  containerId: string;
1767
- containerKeks: {
1873
+ containerKeks: ({
1768
1874
  containerManifestHistory: string[];
1769
1875
  accessManifestHash: string;
1770
1876
  containerId: string;
@@ -1784,7 +1890,10 @@ export declare const ContainerKeyingPathWireResponseSchema: z.ZodType<{
1784
1890
  parentContainerKeyEpochId: string | null;
1785
1891
  recipientTargets: Record<string, unknown>[];
1786
1892
  wraps: Record<string, unknown>[];
1787
- }[];
1893
+ } | {
1894
+ levelDigest: string;
1895
+ containerManifestHistory: string[];
1896
+ })[];
1788
1897
  organizationId: string;
1789
1898
  path: string[];
1790
1899
  }>>;
@@ -1838,7 +1947,7 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
1838
1947
  }[];
1839
1948
  };
1840
1949
  containerId: string;
1841
- containerKeks: {
1950
+ containerKeks: ({
1842
1951
  containerManifestHistory: string[];
1843
1952
  accessManifestHash: string;
1844
1953
  containerId: string;
@@ -1858,7 +1967,10 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
1858
1967
  parentContainerKeyEpochId: string | null;
1859
1968
  recipientTargets: Record<string, unknown>[];
1860
1969
  wraps: Record<string, unknown>[];
1861
- }[];
1970
+ } | {
1971
+ levelDigest: string;
1972
+ containerManifestHistory: string[];
1973
+ })[];
1862
1974
  organizationId: string;
1863
1975
  path: string[];
1864
1976
  bundles: Record<string, {
@@ -1917,7 +2029,7 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
1917
2029
  }[];
1918
2030
  };
1919
2031
  containerId: string;
1920
- containerKeks: {
2032
+ containerKeks: ({
1921
2033
  containerManifestHistory: string[];
1922
2034
  accessManifestHash: string;
1923
2035
  containerId: string;
@@ -1937,7 +2049,10 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
1937
2049
  parentContainerKeyEpochId: string | null;
1938
2050
  recipientTargets: Record<string, unknown>[];
1939
2051
  wraps: Record<string, unknown>[];
1940
- }[];
2052
+ } | {
2053
+ levelDigest: string;
2054
+ containerManifestHistory: string[];
2055
+ })[];
1941
2056
  organizationId: string;
1942
2057
  path: string[];
1943
2058
  bundles: Record<string, {
@@ -1996,7 +2111,7 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
1996
2111
  }[];
1997
2112
  };
1998
2113
  containerId: string;
1999
- containerKeks: {
2114
+ containerKeks: ({
2000
2115
  containerManifestHistory: string[];
2001
2116
  accessManifestHash: string;
2002
2117
  containerId: string;
@@ -2016,7 +2131,10 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
2016
2131
  parentContainerKeyEpochId: string | null;
2017
2132
  recipientTargets: Record<string, unknown>[];
2018
2133
  wraps: Record<string, unknown>[];
2019
- }[];
2134
+ } | {
2135
+ levelDigest: string;
2136
+ containerManifestHistory: string[];
2137
+ })[];
2020
2138
  organizationId: string;
2021
2139
  path: string[];
2022
2140
  bundles: Record<string, {
@@ -2075,7 +2193,7 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
2075
2193
  }[];
2076
2194
  };
2077
2195
  containerId: string;
2078
- containerKeks: {
2196
+ containerKeks: ({
2079
2197
  containerManifestHistory: string[];
2080
2198
  accessManifestHash: string;
2081
2199
  containerId: string;
@@ -2095,7 +2213,10 @@ export declare const ContainerWriterProjectionWireResponseSchema: z.ZodType<{
2095
2213
  parentContainerKeyEpochId: string | null;
2096
2214
  recipientTargets: Record<string, unknown>[];
2097
2215
  wraps: Record<string, unknown>[];
2098
- }[];
2216
+ } | {
2217
+ levelDigest: string;
2218
+ containerManifestHistory: string[];
2219
+ })[];
2099
2220
  organizationId: string;
2100
2221
  path: string[];
2101
2222
  bundles: Record<string, {
@@ -3,7 +3,7 @@ import { containerKekLogSingleKeyringRefinement } from "../containerReadRefineme
3
3
  import { ContainerSystemSlotSchema } from "../containerSystemSlot.js";
4
4
  import { registerJsonSchemaRuntimeRefinements } from "../jsonSchema.js";
5
5
  import { organizationProvisioningContainerKeyringRefinement } from "../organizationProvisioningRefinements.js";
6
- import { arraySchema, loosePlainObject, nonEmptyArraySchema, nonEmptyStringSchema, nonNegativeIntegerSchema, plainObjectSchema, positiveIntegerSchema, } from "../schema.js";
6
+ import { arraySchema, loosePlainObject, nonEmptyArraySchema, nonEmptyStringSchema, nonNegativeIntegerSchema, plainObjectSchema, positiveIntegerSchema, sha256HexStringSchema, } from "../schema.js";
7
7
  import { AccessManifestBundleWireResponseSchema, CONTAINER_KEK_LOG_PAGE_LIMIT, CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT, ContainerKekKeyringWireRecordSchema, } from "../util/index.js";
8
8
  import { containerWriterProjectionPathKekCountRefinement, writerProjectionManifestBundlesRefinement, } from "../writerProjectionRefinements.js";
9
9
  import { EffectiveAccessLevelSchema } from "./accessLevel.js";
@@ -50,6 +50,27 @@ const ContainerKekWireResponseSchema = registerJsonSchemaRuntimeRefinements(loos
50
50
  ...containerKekResponseShape,
51
51
  containerManifestHistory: arraySchema(ManifestHashReferenceSchema),
52
52
  }).superRefine(refineContainerKekKeyring), [organizationProvisioningContainerKeyringRefinement]);
53
+ export function isContainerKekWireLevel(value) {
54
+ return (ContainerKekWireResponseSchema.safeParse(value).success &&
55
+ !Object.hasOwn(Object(value), "levelDigest"));
56
+ }
57
+ /**
58
+ * A KEK level the request declared held (`k:` hint), replaced by the digest
59
+ * of its canonical wire bytes. It keeps the level's manifest citations, so
60
+ * the response's bundle bookkeeping stays exact; the client refills the
61
+ * level from those exact held bytes before anything reads it.
62
+ */
63
+ export const CitedContainerKekLevelSchema = z.strictObject({
64
+ levelDigest: sha256HexStringSchema,
65
+ containerManifestHistory: arraySchema(ManifestHashReferenceSchema),
66
+ });
67
+ export function isCitedContainerKekLevel(value) {
68
+ return CitedContainerKekLevelSchema.safeParse(value).success;
69
+ }
70
+ const ServedContainerKekLevelSchema = z.union([
71
+ CitedContainerKekLevelSchema,
72
+ ContainerKekWireResponseSchema,
73
+ ]);
53
74
  /**
54
75
  * The append-only rotation log for one container: every epoch with its
55
76
  * write-once bridge and sealed keyring. This is the rebuild/repair read
@@ -157,7 +178,7 @@ export const ContainerWriterProjectionResponseSchema = registerJsonSchemaRuntime
157
178
  }).superRefine(refineContainerKeyingPath), [containerWriterProjectionPathKekCountRefinement]);
158
179
  const containerKeyingPathWireShape = {
159
180
  containerId: z.string(),
160
- containerKeks: arraySchema(ContainerKekWireResponseSchema),
181
+ containerKeks: arraySchema(ServedContainerKekLevelSchema),
161
182
  organizationId: z.string(),
162
183
  path: nonEmptyArraySchema(ManifestHashReferenceSchema),
163
184
  };
@@ -1 +1 @@
1
- {"version":3,"file":"container.js","sourceRoot":"","sources":["container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,sCAAsC,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,kDAAkD,EAAE,MAAM,wCAAwC,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,sC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AAE;CACtB,CAAC,CAAC;AAMH,MAAM,CAAC,MAAM,4BAA4B,GAAG,gBAAgB,CAAC;IAC3D,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,KAAK,EAAE,WAAW,CAAC,8BAA8B,CAAC;IAClD,aAAa,EAAE,mBAAmB,CAAC,QAAQ,EAAE;IAC7C,UAAU,EAAE,WAAW,CAAC,oCAAoC,CAAC;CAC9D,CAAC,CAAC;AAMH,MAAM,UAAU,wBAAwB,CACtC,KAAc;IAEd,OAAO,4BAA4B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,KAAc;IAEd,OAAO,+BAA+B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,KAAc;IAEd,OAAO,6BAA6B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,KAAc;IAEd,OAAO,uCAAuC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,uCAAuC,CACrD,KAAc;IAEd,OAAO,2CAA2C,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC9E,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { containerKekLogSingleKeyringRefinement } from \"../containerReadRefinements\";\nimport { ContainerSystemSlotSchema } from \"../containerSystemSlot\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport { organizationProvisioningContainerKeyringRefinement } from \"../organizationProvisioningRefinements\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n nonNegativeIntegerSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n} from \"../schema\";\nimport {\n AccessManifestBundleWireResponseSchema,\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT,\n ContainerKekKeyringWireRecordSchema,\n} from \"../util\";\nimport {\n containerWriterProjectionPathKekCountRefinement,\n writerProjectionManifestBundlesRefinement,\n} from \"../writerProjectionRefinements\";\nimport { EffectiveAccessLevelSchema } from \"./accessLevel\";\nimport {\n containerKeyingPathReferences,\n ManifestBundlesSchema,\n ManifestHashReferenceSchema,\n OmittedManifestBundlesSchema,\n refineManifestBundleReferences,\n} from \"./manifestBundleReferences\";\nimport {\n ReferencedPrincipalStateResponseSchema,\n ReferencedPrincipalStateResponseShape,\n} from \"./principalReference\";\nimport { ProjectionPolicyEvidenceResponseSchema } from \"./projectionPolicyEvidence\";\nimport { SyncWatermarkSchema } from \"./syncWatermark\";\n\nconst ContainerGrantPrincipalStateResponseSchema = loosePlainObject({\n ...ReferencedPrincipalStateResponseShape,\n principalType: z.literal(\"group\"),\n});\n\n/**\n * The container's sealed predecessor key history. Opening it under the\n * current KEK yields every retained historical KEK in one decrypt; the\n * bridge log behind it is served only by the rebuild read path.\n */\nconst ContainerKekKeyringWireResponseSchema =\n ContainerKekKeyringWireRecordSchema;\n\nexport type ContainerKekKeyringWireResponse = z.infer<\n typeof ContainerKekKeyringWireResponseSchema\n>;\n\nconst containerKekResponseShape = {\n accessManifestHash: nonEmptyStringSchema,\n containerId: z.string(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHistory: arraySchema(AccessManifestBundleWireResponseSchema),\n keyEpoch: plainObjectSchema,\n keyEpochHash: nonEmptyStringSchema,\n keyring: ContainerKekKeyringWireResponseSchema.nullable(),\n keyTargetHash: nonEmptyStringSchema,\n parentContainerKeyEpochId: z.string().nullable(),\n recipientTargets: nonEmptyArraySchema(plainObjectSchema),\n wraps: nonEmptyArraySchema(plainObjectSchema),\n};\n\nfunction refineContainerKekKeyring(\n value: { readonly containerKeyEpoch: number; readonly keyring: unknown },\n context: z.RefinementCtx,\n) {\n if ((value.keyring === null) !== (value.containerKeyEpoch === 1)) {\n context.addIssue({\n code: \"custom\",\n message: \"container keyring must be null exactly at epoch 1\",\n path: [\"keyring\"],\n });\n }\n}\n\nconst ContainerKekResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKekResponseShape).superRefine(\n refineContainerKekKeyring,\n ),\n [organizationProvisioningContainerKeyringRefinement],\n);\n\n/** On the writer-projection wire, KEK history cites manifests by hash. */\nconst ContainerKekWireResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n ...containerKekResponseShape,\n containerManifestHistory: arraySchema(ManifestHashReferenceSchema),\n }).superRefine(refineContainerKekKeyring),\n [organizationProvisioningContainerKeyringRefinement],\n);\n\nexport type ContainerKekResponse = z.infer<typeof ContainerKekResponseSchema>;\n\n/**\n * The append-only rotation log for one container: every epoch with its\n * write-once bridge and sealed keyring. This is the rebuild/repair read\n * path — hot reads use the projection keyring instead.\n */\nexport const ContainerKekLogEpochResponseSchema = loosePlainObject({\n accessManifestHash: nonEmptyStringSchema,\n bridge: plainObjectSchema.nullable(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n keyring: ContainerKekKeyringWireResponseSchema.nullable(),\n parentContainerKeyEpochId: z.string().nullable(),\n /**\n * Retained recipient envelopes are the recovery backstop when a bridge is\n * severed. The server and response guard apply this bound per epoch.\n */\n wraps: arraySchema(plainObjectSchema, CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT),\n});\n\nexport type ContainerKekLogEpochResponse = z.infer<\n typeof ContainerKekLogEpochResponseSchema\n>;\n\nexport const ContainerKekLogResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n containerId: nonEmptyStringSchema,\n epochs: arraySchema(\n ContainerKekLogEpochResponseSchema,\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n ),\n /** True when epochs above this page's last remain unserved. */\n hasMore: z.boolean(),\n }).superRefine(({ epochs }, context) => {\n if (epochs.filter((epoch) => epoch.keyring !== null).length > 1) {\n context.addIssue({\n code: \"custom\",\n message: \"container KEK log pages contain at most one keyring\",\n path: [\"epochs\"],\n });\n }\n }),\n [containerKekLogSingleKeyringRefinement],\n );\n\nexport type ContainerKekLogResponse = z.infer<\n typeof ContainerKekLogResponseSchema\n>;\n\nexport function isContainerKekLogResponse(\n value: unknown,\n): value is ContainerKekLogResponse {\n return ContainerKekLogResponseSchema.safeParse(value).success;\n}\n\nconst ContainerManifestMutationResponseShape = {\n accessManifest: AccessManifestBundleWireResponseSchema,\n containerId: z.string(),\n createdAt: z.string(),\n manifestHead: loosePlainObject({\n epoch: z.number(),\n manifestHash: z.string(),\n }),\n organizationId: z.string(),\n parentId: z.string().nullable(),\n referencedPrincipalHeads: arraySchema(\n ContainerGrantPrincipalStateResponseSchema,\n ),\n systemSlot: ContainerSystemSlotSchema.nullable().optional(),\n updatedAt: z.string(),\n};\n\n// Preserve the canonical generated field order while sharing the signed-head shape.\nconst { accessManifest, containerId, ...containerMutationResponseFields } =\n ContainerManifestMutationResponseShape;\n\nconst containerMutationResponseShape = {\n accessManifest,\n containerId,\n containerKek: ContainerKekResponseSchema,\n ...containerMutationResponseFields,\n};\n\nexport const ContainerMutationResponseSchema = loosePlainObject(\n containerMutationResponseShape,\n);\n\nexport type ContainerMutationResponse = z.infer<\n typeof ContainerMutationResponseSchema\n>;\n\n/** A rotation's acknowledgement, plus one per carried rekey in request order. */\nexport const ContainerRotationResponseSchema = loosePlainObject({\n ...containerMutationResponseShape,\n containerRekeys: arraySchema(ContainerMutationResponseSchema).optional(),\n});\n\nexport type ContainerRotationResponse = z.infer<\n typeof ContainerRotationResponseSchema\n>;\n\nexport function isContainerRotationResponse(\n value: unknown,\n): value is ContainerRotationResponse {\n return ContainerRotationResponseSchema.safeParse(value).success;\n}\n\nexport const ContainerReciteResponseSchema = loosePlainObject(\n ContainerManifestMutationResponseShape,\n);\nexport type ContainerReciteResponse = z.infer<\n typeof ContainerReciteResponseSchema\n>;\n\nexport function isContainerReciteResponse(\n value: unknown,\n): value is ContainerReciteResponse {\n return ContainerReciteResponseSchema.safeParse(value).success;\n}\n\nexport const ContainerDeleteResponseSchema = loosePlainObject({\n containerId: z.string(),\n deletedAt: z.string(),\n});\n\nexport type ContainerDeleteResponse = z.infer<\n typeof ContainerDeleteResponseSchema\n>;\n\nexport const CONTAINER_PROJECTION_STATE_INVALID_ERROR_CODE =\n \"container_projection_state_invalid\";\nexport const ContainerWriterProjectionErrorResponseSchema = loosePlainObject({\n code: z.literal(CONTAINER_PROJECTION_STATE_INVALID_ERROR_CODE),\n error: z.string(),\n});\n\nconst containerKeyingPathShape = {\n containerId: z.string(),\n containerKeks: arraySchema(ContainerKekResponseSchema),\n organizationId: z.string(),\n path: nonEmptyArraySchema(AccessManifestBundleWireResponseSchema),\n};\nfunction refineContainerKeyingPath(\n projection: { containerKeks: unknown[]; path: unknown[] },\n context: z.RefinementCtx,\n) {\n // loosePlainObject can continue refinements after reporting malformed fields.\n if (\n Array.isArray(projection.containerKeks) &&\n Array.isArray(projection.path) &&\n projection.containerKeks.length !== projection.path.length\n )\n context.addIssue({\n code: \"custom\",\n message: \"container KEK count must match the manifest path length\",\n path: [\"containerKeks\"],\n });\n}\nexport const ContainerKeyingPathResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKeyingPathShape).superRefine(\n refineContainerKeyingPath,\n ),\n [containerWriterProjectionPathKekCountRefinement],\n );\nexport type ContainerKeyingPathResponse = z.infer<\n typeof ContainerKeyingPathResponseSchema\n>;\n/**\n * The decoded projection a client verifies: every manifest position holds\n * its bundle. `decodeContainerWriterProjection` builds it from the wire.\n */\nexport const ContainerWriterProjectionResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n ...containerKeyingPathShape,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n }).superRefine(refineContainerKeyingPath),\n [containerWriterProjectionPathKekCountRefinement],\n );\n\nexport type ContainerWriterProjectionResponse = z.infer<\n typeof ContainerWriterProjectionResponseSchema\n>;\n\nconst containerKeyingPathWireShape = {\n containerId: z.string(),\n containerKeks: arraySchema(ContainerKekWireResponseSchema),\n organizationId: z.string(),\n path: nonEmptyArraySchema(ManifestHashReferenceSchema),\n};\nexport const ContainerKeyingPathWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKeyingPathWireShape).superRefine(\n refineContainerKeyingPath,\n ),\n [containerWriterProjectionPathKekCountRefinement],\n );\nexport type ContainerKeyingPathWireResponse = z.infer<\n typeof ContainerKeyingPathWireResponseSchema\n>;\n\n/**\n * The served shape: manifest positions cite `bundles` by hash, except hashes\n * the request declared already held, which `omittedBundles` lists instead.\n */\nexport const ContainerWriterProjectionWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n bundles: ManifestBundlesSchema,\n omittedBundles: OmittedManifestBundlesSchema,\n ...containerKeyingPathWireShape,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n }).superRefine((projection, context) => {\n refineContainerKeyingPath(projection, context);\n refineManifestBundleReferences(\n projection,\n containerKeyingPathReferences(projection),\n context,\n );\n }),\n [\n containerWriterProjectionPathKekCountRefinement,\n writerProjectionManifestBundlesRefinement,\n ],\n );\n\nexport type ContainerWriterProjectionWireResponse = z.infer<\n typeof ContainerWriterProjectionWireResponseSchema\n>;\n\nexport const ContainerSummaryResponseSchema = loosePlainObject({\n createdAt: z.string(),\n depth: nonNegativeIntegerSchema,\n effectiveAccessLevel: EffectiveAccessLevelSchema,\n id: z.string(),\n metadataAccessEpoch: z.number(),\n metadataAccessStateHash: nonEmptyStringSchema,\n metadataDocumentId: z.string(),\n metadataReferencedPrincipals: arraySchema(\n ReferencedPrincipalStateResponseSchema,\n ),\n organizationId: z.string(),\n parentId: z.string().nullable(),\n systemSlot: ContainerSystemSlotSchema.nullable().optional(),\n updatedAt: z.string(),\n});\n\nexport type ContainerSummary = z.infer<typeof ContainerSummaryResponseSchema>;\n\nexport const ContainerSyncTombstoneResponseSchema = loosePlainObject({\n containerId: z.string(),\n depth: nonNegativeIntegerSchema,\n parentId: z.string().nullable(),\n reason: z.literal([\"access_revoked\", \"deleted\"]),\n updatedAt: z.string(),\n});\n\nexport type ContainerSyncTombstone = z.infer<\n typeof ContainerSyncTombstoneResponseSchema\n>;\n\nexport const ListContainersResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n items: arraySchema(ContainerSummaryResponseSchema),\n nextWatermark: SyncWatermarkSchema.nullable(),\n tombstones: arraySchema(ContainerSyncTombstoneResponseSchema),\n});\n\nexport type ListContainersResponse = z.infer<\n typeof ListContainersResponseSchema\n>;\n\nexport function isListContainersResponse(\n value: unknown,\n): value is ListContainersResponse {\n return ListContainersResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerMutationResponse(\n value: unknown,\n): value is ContainerMutationResponse {\n return ContainerMutationResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerDeleteResponse(\n value: unknown,\n): value is ContainerDeleteResponse {\n return ContainerDeleteResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerWriterProjectionResponse(\n value: unknown,\n): value is ContainerWriterProjectionResponse {\n return ContainerWriterProjectionResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerWriterProjectionWireResponse(\n value: unknown,\n): value is ContainerWriterProjectionWireResponse {\n return ContainerWriterProjectionWireResponseSchema.safeParse(value).success;\n}\n"]}
1
+ {"version":3,"file":"container.js","sourceRoot":"","sources":["container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,sCAAsC,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,kDAAkD,EAAE,MAAM,wCAAwC,CAAC;AAC5G,OAAO,EACL,W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OAAO,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,KAAc;IAEd,OAAO,6BAA6B,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,KAAc;IAEd,OAAO,uCAAuC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,uCAAuC,CACrD,KAAc;IAEd,OAAO,2CAA2C,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC9E,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { containerKekLogSingleKeyringRefinement } from \"../containerReadRefinements\";\nimport { ContainerSystemSlotSchema } from \"../containerSystemSlot\";\nimport { registerJsonSchemaRuntimeRefinements } from \"../jsonSchema\";\nimport { organizationProvisioningContainerKeyringRefinement } from \"../organizationProvisioningRefinements\";\nimport {\n arraySchema,\n loosePlainObject,\n nonEmptyArraySchema,\n nonEmptyStringSchema,\n nonNegativeIntegerSchema,\n plainObjectSchema,\n positiveIntegerSchema,\n sha256HexStringSchema,\n} from \"../schema\";\nimport {\n AccessManifestBundleWireResponseSchema,\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT,\n ContainerKekKeyringWireRecordSchema,\n} from \"../util\";\nimport {\n containerWriterProjectionPathKekCountRefinement,\n writerProjectionManifestBundlesRefinement,\n} from \"../writerProjectionRefinements\";\nimport { EffectiveAccessLevelSchema } from \"./accessLevel\";\nimport {\n containerKeyingPathReferences,\n ManifestBundlesSchema,\n ManifestHashReferenceSchema,\n OmittedManifestBundlesSchema,\n refineManifestBundleReferences,\n} from \"./manifestBundleReferences\";\nimport {\n ReferencedPrincipalStateResponseSchema,\n ReferencedPrincipalStateResponseShape,\n} from \"./principalReference\";\nimport { ProjectionPolicyEvidenceResponseSchema } from \"./projectionPolicyEvidence\";\nimport { SyncWatermarkSchema } from \"./syncWatermark\";\n\nconst ContainerGrantPrincipalStateResponseSchema = loosePlainObject({\n ...ReferencedPrincipalStateResponseShape,\n principalType: z.literal(\"group\"),\n});\n\n/**\n * The container's sealed predecessor key history. Opening it under the\n * current KEK yields every retained historical KEK in one decrypt; the\n * bridge log behind it is served only by the rebuild read path.\n */\nconst ContainerKekKeyringWireResponseSchema =\n ContainerKekKeyringWireRecordSchema;\n\nexport type ContainerKekKeyringWireResponse = z.infer<\n typeof ContainerKekKeyringWireResponseSchema\n>;\n\nconst containerKekResponseShape = {\n accessManifestHash: nonEmptyStringSchema,\n containerId: z.string(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n containerManifestHistory: arraySchema(AccessManifestBundleWireResponseSchema),\n keyEpoch: plainObjectSchema,\n keyEpochHash: nonEmptyStringSchema,\n keyring: ContainerKekKeyringWireResponseSchema.nullable(),\n keyTargetHash: nonEmptyStringSchema,\n parentContainerKeyEpochId: z.string().nullable(),\n recipientTargets: nonEmptyArraySchema(plainObjectSchema),\n wraps: nonEmptyArraySchema(plainObjectSchema),\n};\n\nfunction refineContainerKekKeyring(\n value: { readonly containerKeyEpoch: number; readonly keyring: unknown },\n context: z.RefinementCtx,\n) {\n if ((value.keyring === null) !== (value.containerKeyEpoch === 1)) {\n context.addIssue({\n code: \"custom\",\n message: \"container keyring must be null exactly at epoch 1\",\n path: [\"keyring\"],\n });\n }\n}\n\nconst ContainerKekResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKekResponseShape).superRefine(\n refineContainerKekKeyring,\n ),\n [organizationProvisioningContainerKeyringRefinement],\n);\n\n/** On the writer-projection wire, KEK history cites manifests by hash. */\nconst ContainerKekWireResponseSchema = registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n ...containerKekResponseShape,\n containerManifestHistory: arraySchema(ManifestHashReferenceSchema),\n }).superRefine(refineContainerKekKeyring),\n [organizationProvisioningContainerKeyringRefinement],\n);\n\nexport type ContainerKekResponse = z.infer<typeof ContainerKekResponseSchema>;\n\n/** One KEK level as served in full, its manifest history cited by hash. */\nexport type ContainerKekWireLevel = z.infer<\n typeof ContainerKekWireResponseSchema\n>;\n\nexport function isContainerKekWireLevel(\n value: unknown,\n): value is ContainerKekWireLevel {\n return (\n ContainerKekWireResponseSchema.safeParse(value).success &&\n !Object.hasOwn(Object(value), \"levelDigest\")\n );\n}\n\n/**\n * A KEK level the request declared held (`k:` hint), replaced by the digest\n * of its canonical wire bytes. It keeps the level's manifest citations, so\n * the response's bundle bookkeeping stays exact; the client refills the\n * level from those exact held bytes before anything reads it.\n */\nexport const CitedContainerKekLevelSchema = z.strictObject({\n levelDigest: sha256HexStringSchema,\n containerManifestHistory: arraySchema(ManifestHashReferenceSchema),\n});\n\nexport type CitedContainerKekLevel = z.infer<\n typeof CitedContainerKekLevelSchema\n>;\n\nexport function isCitedContainerKekLevel(\n value: unknown,\n): value is CitedContainerKekLevel {\n return CitedContainerKekLevelSchema.safeParse(value).success;\n}\n\nconst ServedContainerKekLevelSchema = z.union([\n CitedContainerKekLevelSchema,\n ContainerKekWireResponseSchema,\n]);\n\n/**\n * The append-only rotation log for one container: every epoch with its\n * write-once bridge and sealed keyring. This is the rebuild/repair read\n * path — hot reads use the projection keyring instead.\n */\nexport const ContainerKekLogEpochResponseSchema = loosePlainObject({\n accessManifestHash: nonEmptyStringSchema,\n bridge: plainObjectSchema.nullable(),\n containerKeyEpoch: positiveIntegerSchema,\n containerKeyEpochId: nonEmptyStringSchema,\n keyring: ContainerKekKeyringWireResponseSchema.nullable(),\n parentContainerKeyEpochId: z.string().nullable(),\n /**\n * Retained recipient envelopes are the recovery backstop when a bridge is\n * severed. The server and response guard apply this bound per epoch.\n */\n wraps: arraySchema(plainObjectSchema, CONTAINER_KEK_WRAPS_PER_EPOCH_LIMIT),\n});\n\nexport type ContainerKekLogEpochResponse = z.infer<\n typeof ContainerKekLogEpochResponseSchema\n>;\n\nexport const ContainerKekLogResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n containerId: nonEmptyStringSchema,\n epochs: arraySchema(\n ContainerKekLogEpochResponseSchema,\n CONTAINER_KEK_LOG_PAGE_LIMIT,\n ),\n /** True when epochs above this page's last remain unserved. */\n hasMore: z.boolean(),\n }).superRefine(({ epochs }, context) => {\n if (epochs.filter((epoch) => epoch.keyring !== null).length > 1) {\n context.addIssue({\n code: \"custom\",\n message: \"container KEK log pages contain at most one keyring\",\n path: [\"epochs\"],\n });\n }\n }),\n [containerKekLogSingleKeyringRefinement],\n );\n\nexport type ContainerKekLogResponse = z.infer<\n typeof ContainerKekLogResponseSchema\n>;\n\nexport function isContainerKekLogResponse(\n value: unknown,\n): value is ContainerKekLogResponse {\n return ContainerKekLogResponseSchema.safeParse(value).success;\n}\n\nconst ContainerManifestMutationResponseShape = {\n accessManifest: AccessManifestBundleWireResponseSchema,\n containerId: z.string(),\n createdAt: z.string(),\n manifestHead: loosePlainObject({\n epoch: z.number(),\n manifestHash: z.string(),\n }),\n organizationId: z.string(),\n parentId: z.string().nullable(),\n referencedPrincipalHeads: arraySchema(\n ContainerGrantPrincipalStateResponseSchema,\n ),\n systemSlot: ContainerSystemSlotSchema.nullable().optional(),\n updatedAt: z.string(),\n};\n\n// Preserve the canonical generated field order while sharing the signed-head shape.\nconst { accessManifest, containerId, ...containerMutationResponseFields } =\n ContainerManifestMutationResponseShape;\n\nconst containerMutationResponseShape = {\n accessManifest,\n containerId,\n containerKek: ContainerKekResponseSchema,\n ...containerMutationResponseFields,\n};\n\nexport const ContainerMutationResponseSchema = loosePlainObject(\n containerMutationResponseShape,\n);\n\nexport type ContainerMutationResponse = z.infer<\n typeof ContainerMutationResponseSchema\n>;\n\n/** A rotation's acknowledgement, plus one per carried rekey in request order. */\nexport const ContainerRotationResponseSchema = loosePlainObject({\n ...containerMutationResponseShape,\n containerRekeys: arraySchema(ContainerMutationResponseSchema).optional(),\n});\n\nexport type ContainerRotationResponse = z.infer<\n typeof ContainerRotationResponseSchema\n>;\n\nexport function isContainerRotationResponse(\n value: unknown,\n): value is ContainerRotationResponse {\n return ContainerRotationResponseSchema.safeParse(value).success;\n}\n\nexport const ContainerReciteResponseSchema = loosePlainObject(\n ContainerManifestMutationResponseShape,\n);\nexport type ContainerReciteResponse = z.infer<\n typeof ContainerReciteResponseSchema\n>;\n\nexport function isContainerReciteResponse(\n value: unknown,\n): value is ContainerReciteResponse {\n return ContainerReciteResponseSchema.safeParse(value).success;\n}\n\nexport const ContainerDeleteResponseSchema = loosePlainObject({\n containerId: z.string(),\n deletedAt: z.string(),\n});\n\nexport type ContainerDeleteResponse = z.infer<\n typeof ContainerDeleteResponseSchema\n>;\n\nexport const CONTAINER_PROJECTION_STATE_INVALID_ERROR_CODE =\n \"container_projection_state_invalid\";\nexport const ContainerWriterProjectionErrorResponseSchema = loosePlainObject({\n code: z.literal(CONTAINER_PROJECTION_STATE_INVALID_ERROR_CODE),\n error: z.string(),\n});\n\nconst containerKeyingPathShape = {\n containerId: z.string(),\n containerKeks: arraySchema(ContainerKekResponseSchema),\n organizationId: z.string(),\n path: nonEmptyArraySchema(AccessManifestBundleWireResponseSchema),\n};\nfunction refineContainerKeyingPath(\n projection: { containerKeks: unknown[]; path: unknown[] },\n context: z.RefinementCtx,\n) {\n // loosePlainObject can continue refinements after reporting malformed fields.\n if (\n Array.isArray(projection.containerKeks) &&\n Array.isArray(projection.path) &&\n projection.containerKeks.length !== projection.path.length\n )\n context.addIssue({\n code: \"custom\",\n message: \"container KEK count must match the manifest path length\",\n path: [\"containerKeks\"],\n });\n}\nexport const ContainerKeyingPathResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKeyingPathShape).superRefine(\n refineContainerKeyingPath,\n ),\n [containerWriterProjectionPathKekCountRefinement],\n );\nexport type ContainerKeyingPathResponse = z.infer<\n typeof ContainerKeyingPathResponseSchema\n>;\n/**\n * The decoded projection a client verifies: every manifest position holds\n * its bundle. `decodeContainerWriterProjection` builds it from the wire.\n */\nexport const ContainerWriterProjectionResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n ...containerKeyingPathShape,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n }).superRefine(refineContainerKeyingPath),\n [containerWriterProjectionPathKekCountRefinement],\n );\n\nexport type ContainerWriterProjectionResponse = z.infer<\n typeof ContainerWriterProjectionResponseSchema\n>;\n\nconst containerKeyingPathWireShape = {\n containerId: z.string(),\n containerKeks: arraySchema(ServedContainerKekLevelSchema),\n organizationId: z.string(),\n path: nonEmptyArraySchema(ManifestHashReferenceSchema),\n};\nexport const ContainerKeyingPathWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject(containerKeyingPathWireShape).superRefine(\n refineContainerKeyingPath,\n ),\n [containerWriterProjectionPathKekCountRefinement],\n );\nexport type ContainerKeyingPathWireResponse = z.infer<\n typeof ContainerKeyingPathWireResponseSchema\n>;\n\n/**\n * The served shape: manifest positions cite `bundles` by hash, except hashes\n * the request declared already held, which `omittedBundles` lists instead.\n */\nexport const ContainerWriterProjectionWireResponseSchema =\n registerJsonSchemaRuntimeRefinements(\n loosePlainObject({\n bundles: ManifestBundlesSchema,\n omittedBundles: OmittedManifestBundlesSchema,\n ...containerKeyingPathWireShape,\n policyEvidence: ProjectionPolicyEvidenceResponseSchema,\n }).superRefine((projection, context) => {\n refineContainerKeyingPath(projection, context);\n refineManifestBundleReferences(\n projection,\n containerKeyingPathReferences(projection),\n context,\n );\n }),\n [\n containerWriterProjectionPathKekCountRefinement,\n writerProjectionManifestBundlesRefinement,\n ],\n );\n\nexport type ContainerWriterProjectionWireResponse = z.infer<\n typeof ContainerWriterProjectionWireResponseSchema\n>;\n\nexport const ContainerSummaryResponseSchema = loosePlainObject({\n createdAt: z.string(),\n depth: nonNegativeIntegerSchema,\n effectiveAccessLevel: EffectiveAccessLevelSchema,\n id: z.string(),\n metadataAccessEpoch: z.number(),\n metadataAccessStateHash: nonEmptyStringSchema,\n metadataDocumentId: z.string(),\n metadataReferencedPrincipals: arraySchema(\n ReferencedPrincipalStateResponseSchema,\n ),\n organizationId: z.string(),\n parentId: z.string().nullable(),\n systemSlot: ContainerSystemSlotSchema.nullable().optional(),\n updatedAt: z.string(),\n});\n\nexport type ContainerSummary = z.infer<typeof ContainerSummaryResponseSchema>;\n\nexport const ContainerSyncTombstoneResponseSchema = loosePlainObject({\n containerId: z.string(),\n depth: nonNegativeIntegerSchema,\n parentId: z.string().nullable(),\n reason: z.literal([\"access_revoked\", \"deleted\"]),\n updatedAt: z.string(),\n});\n\nexport type ContainerSyncTombstone = z.infer<\n typeof ContainerSyncTombstoneResponseSchema\n>;\n\nexport const ListContainersResponseSchema = loosePlainObject({\n hasMore: z.boolean(),\n items: arraySchema(ContainerSummaryResponseSchema),\n nextWatermark: SyncWatermarkSchema.nullable(),\n tombstones: arraySchema(ContainerSyncTombstoneResponseSchema),\n});\n\nexport type ListContainersResponse = z.infer<\n typeof ListContainersResponseSchema\n>;\n\nexport function isListContainersResponse(\n value: unknown,\n): value is ListContainersResponse {\n return ListContainersResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerMutationResponse(\n value: unknown,\n): value is ContainerMutationResponse {\n return ContainerMutationResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerDeleteResponse(\n value: unknown,\n): value is ContainerDeleteResponse {\n return ContainerDeleteResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerWriterProjectionResponse(\n value: unknown,\n): value is ContainerWriterProjectionResponse {\n return ContainerWriterProjectionResponseSchema.safeParse(value).success;\n}\n\nexport function isContainerWriterProjectionWireResponse(\n value: unknown,\n): value is ContainerWriterProjectionWireResponse {\n return ContainerWriterProjectionWireResponseSchema.safeParse(value).success;\n}\n"]}