@noy-db/hub 0.6.0-pre.2 → 0.6.0-pre.20

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 (490) hide show
  1. package/codemods/0.4.0-pre.json +699 -0
  2. package/codemods/0.6.0-pre.json +211 -0
  3. package/dist/api-Z5VHH24A.js +20 -0
  4. package/dist/attestation/index.js +19 -19
  5. package/dist/{backup-YYBE5RPC.js → backup-K62BFMYK.js} +36 -18
  6. package/dist/backup-K62BFMYK.js.map +1 -0
  7. package/dist/blobs/index.js +13 -13
  8. package/dist/broker/index.js +12 -12
  9. package/dist/cargo/index.js +33 -33
  10. package/dist/{chunk-FDX7OWWI.js → chunk-2E2MKBMI.js} +2 -2
  11. package/dist/{chunk-VOQW5LAM.js → chunk-2IK6AC6A.js} +102 -71
  12. package/dist/chunk-2IK6AC6A.js.map +1 -0
  13. package/dist/{chunk-EDXAQ6JI.js → chunk-32O2N2CH.js} +87 -34
  14. package/dist/chunk-32O2N2CH.js.map +1 -0
  15. package/dist/{chunk-W5W6KHN2.js → chunk-3Y4OFWQJ.js} +1 -1
  16. package/dist/chunk-3Y4OFWQJ.js.map +1 -0
  17. package/dist/{chunk-7G6VDWXB.js → chunk-437FDIHO.js} +3 -3
  18. package/dist/chunk-437FDIHO.js.map +1 -0
  19. package/dist/{chunk-3FSX6LDG.js → chunk-47ZFULEZ.js} +8 -3
  20. package/dist/{chunk-3FSX6LDG.js.map → chunk-47ZFULEZ.js.map} +1 -1
  21. package/dist/{chunk-ZJADGNYF.js → chunk-4AOERLTV.js} +1 -1
  22. package/dist/chunk-4AOERLTV.js.map +1 -0
  23. package/dist/{chunk-MWKDOHEF.js → chunk-4HVTRHSA.js} +17 -10
  24. package/dist/chunk-4HVTRHSA.js.map +1 -0
  25. package/dist/{chunk-V5KYPBUR.js → chunk-5BS6IQZZ.js} +11 -14
  26. package/dist/chunk-5BS6IQZZ.js.map +1 -0
  27. package/dist/{chunk-LWSJG3LI.js → chunk-5EJQNA26.js} +7 -3
  28. package/dist/chunk-5EJQNA26.js.map +1 -0
  29. package/dist/{chunk-7F4DBNSP.js → chunk-5J5TTSGW.js} +3 -3
  30. package/dist/{chunk-BTVYJWSN.js → chunk-5JT4Y5UE.js} +10 -10
  31. package/dist/{chunk-C2OOEM57.js → chunk-6S466CMQ.js} +92 -35
  32. package/dist/chunk-6S466CMQ.js.map +1 -0
  33. package/dist/{chunk-PY7CI6L5.js → chunk-6TXUVKPG.js} +516 -263
  34. package/dist/chunk-6TXUVKPG.js.map +1 -0
  35. package/dist/{chunk-7NXHMW6Y.js → chunk-7RCZ436O.js} +2 -2
  36. package/dist/{chunk-DG27IUVI.js → chunk-A3NTKHDB.js} +2 -2
  37. package/dist/{chunk-CCZJJ4I2.js → chunk-A4K5GLE6.js} +4 -4
  38. package/dist/{chunk-CEJWMBXO.js → chunk-APV42WPR.js} +2 -2
  39. package/dist/{chunk-4HDYQL3J.js → chunk-AQF7JSQR.js} +2 -2
  40. package/dist/{chunk-KUDZVJKQ.js → chunk-BP4I7IBK.js} +2 -2
  41. package/dist/{chunk-4UVDI4XE.js → chunk-BTNKPDZM.js} +4 -4
  42. package/dist/{chunk-HVQGCKY4.js → chunk-C7WJNVJG.js} +2 -2
  43. package/dist/{chunk-WYZ5MYUA.js → chunk-CV7WXCZD.js} +44 -42
  44. package/dist/chunk-CV7WXCZD.js.map +1 -0
  45. package/dist/{chunk-KCQX65FU.js → chunk-CVYXIN5B.js} +3 -3
  46. package/dist/{chunk-VN45YLWM.js → chunk-D5UDZANO.js} +255 -132
  47. package/dist/chunk-D5UDZANO.js.map +1 -0
  48. package/dist/{chunk-AR2JDFAE.js → chunk-DJ23QZIN.js} +2 -2
  49. package/dist/{chunk-PJNTR2NV.js → chunk-DKYEVHZH.js} +7 -10
  50. package/dist/chunk-DKYEVHZH.js.map +1 -0
  51. package/dist/{chunk-SZ2K3MHL.js → chunk-DYASJSKI.js} +8 -11
  52. package/dist/{chunk-SZ2K3MHL.js.map → chunk-DYASJSKI.js.map} +1 -1
  53. package/dist/{chunk-G5APARUV.js → chunk-E6VDPBE3.js} +13 -15
  54. package/dist/chunk-E6VDPBE3.js.map +1 -0
  55. package/dist/{chunk-A67356IR.js → chunk-EG6AQBYW.js} +33 -8
  56. package/dist/chunk-EG6AQBYW.js.map +1 -0
  57. package/dist/{chunk-PVU7LW5L.js → chunk-EJIVFOOQ.js} +6 -6
  58. package/dist/{chunk-VRA4Q7DA.js → chunk-F5AJZC3U.js} +35 -47
  59. package/dist/chunk-F5AJZC3U.js.map +1 -0
  60. package/dist/{chunk-VMCCGUQB.js → chunk-GDGTIWB4.js} +2 -2
  61. package/dist/{chunk-FUHKW252.js → chunk-GILI76SU.js} +2 -2
  62. package/dist/{chunk-35EBKWQU.js → chunk-GT72D4FO.js} +4 -4
  63. package/dist/{chunk-PRDRGL73.js → chunk-GYUCRDAU.js} +17 -14
  64. package/dist/chunk-GYUCRDAU.js.map +1 -0
  65. package/dist/{chunk-JRCYZEHU.js → chunk-HGJC7I5F.js} +2 -2
  66. package/dist/{chunk-TOAIYQJR.js → chunk-HJRTFXAA.js} +7 -10
  67. package/dist/chunk-HJRTFXAA.js.map +1 -0
  68. package/dist/chunk-HK67PX4J.js +27 -0
  69. package/dist/chunk-HK67PX4J.js.map +1 -0
  70. package/dist/{chunk-JXIDGFKS.js → chunk-HTHRCGWP.js} +4 -2
  71. package/dist/chunk-HTHRCGWP.js.map +1 -0
  72. package/dist/{chunk-AHLJSVRL.js → chunk-HTMQBBF3.js} +5 -7
  73. package/dist/chunk-HTMQBBF3.js.map +1 -0
  74. package/dist/{chunk-ZNACADFG.js → chunk-ICCRAPWD.js} +4 -4
  75. package/dist/chunk-ICCRAPWD.js.map +1 -0
  76. package/dist/{chunk-66W5OOCX.js → chunk-IOURTXTM.js} +52 -65
  77. package/dist/chunk-IOURTXTM.js.map +1 -0
  78. package/dist/{chunk-MZ5ZFO2D.js → chunk-IPDS2TYW.js} +84 -112
  79. package/dist/chunk-IPDS2TYW.js.map +1 -0
  80. package/dist/{chunk-UIBGXRDD.js → chunk-JHO6FGZX.js} +25 -31
  81. package/dist/chunk-JHO6FGZX.js.map +1 -0
  82. package/dist/{chunk-YAWK6AWF.js → chunk-JIF3IBRK.js} +2 -2
  83. package/dist/{chunk-HNHCQ556.js → chunk-KBOPY6W2.js} +2 -2
  84. package/dist/{chunk-UHXCLPGC.js → chunk-KDX6VEYV.js} +2 -2
  85. package/dist/chunk-KDX6VEYV.js.map +1 -0
  86. package/dist/{chunk-W3TVWF6N.js → chunk-KM6YR5XF.js} +2 -2
  87. package/dist/{chunk-3737A6EA.js → chunk-KUXTWVAR.js} +75 -18
  88. package/dist/chunk-KUXTWVAR.js.map +1 -0
  89. package/dist/chunk-L2XQ776M.js +123 -0
  90. package/dist/chunk-L2XQ776M.js.map +1 -0
  91. package/dist/{chunk-E6427JU2.js → chunk-L6FSZFG7.js} +18 -2
  92. package/dist/chunk-L6FSZFG7.js.map +1 -0
  93. package/dist/{chunk-5PR33AC4.js → chunk-M4IKEOJS.js} +20 -17
  94. package/dist/chunk-M4IKEOJS.js.map +1 -0
  95. package/dist/{chunk-6HFM7EIT.js → chunk-MNMYHZVU.js} +2 -2
  96. package/dist/{chunk-NIVEDYJZ.js → chunk-MNUTPZRQ.js} +31 -49
  97. package/dist/chunk-MNUTPZRQ.js.map +1 -0
  98. package/dist/{chunk-VV4NSB7P.js → chunk-MQXYR65M.js} +15 -24
  99. package/dist/chunk-MQXYR65M.js.map +1 -0
  100. package/dist/{chunk-QD724WDJ.js → chunk-N2HKBESK.js} +4 -4
  101. package/dist/{chunk-Z45YRGFO.js → chunk-N7YAQKAO.js} +2 -2
  102. package/dist/{chunk-DMQCLZ4Z.js → chunk-NH2MST6J.js} +2 -2
  103. package/dist/{chunk-TAGFGKHP.js → chunk-NRNTXBHT.js} +7 -10
  104. package/dist/chunk-NRNTXBHT.js.map +1 -0
  105. package/dist/{chunk-I6SDX7WX.js → chunk-NYSD43OE.js} +16 -22
  106. package/dist/chunk-NYSD43OE.js.map +1 -0
  107. package/dist/{chunk-I4F6PKUK.js → chunk-ODVIFBAQ.js} +16 -17
  108. package/dist/chunk-ODVIFBAQ.js.map +1 -0
  109. package/dist/{chunk-26JMGSSC.js → chunk-OIIAXFKM.js} +4 -4
  110. package/dist/chunk-OIIAXFKM.js.map +1 -0
  111. package/dist/{chunk-HXGUIPQB.js → chunk-OQLYMBJI.js} +3 -3
  112. package/dist/{chunk-RKKORO4M.js → chunk-OWGEHDT2.js} +10 -10
  113. package/dist/chunk-OWGEHDT2.js.map +1 -0
  114. package/dist/{chunk-HNGSV2YC.js → chunk-P7L3OQLL.js} +25 -10
  115. package/dist/chunk-P7L3OQLL.js.map +1 -0
  116. package/dist/{chunk-MSWYQLMQ.js → chunk-PG6PFMDC.js} +2 -2
  117. package/dist/{chunk-E7OBCBXS.js → chunk-PNAIDIP7.js} +13 -16
  118. package/dist/chunk-PNAIDIP7.js.map +1 -0
  119. package/dist/{chunk-GLKDWWNO.js → chunk-PZSS7MUM.js} +16 -14
  120. package/dist/chunk-PZSS7MUM.js.map +1 -0
  121. package/dist/{chunk-WKPJXWKR.js → chunk-QPIUFRUC.js} +3 -3
  122. package/dist/{chunk-JIUVJ4M7.js → chunk-REL4OLWW.js} +2 -2
  123. package/dist/{chunk-ERB6NDDW.js → chunk-RKDH6L53.js} +134 -33
  124. package/dist/chunk-RKDH6L53.js.map +1 -0
  125. package/dist/{chunk-VW6ZZGCG.js → chunk-RNSC2ARR.js} +3 -3
  126. package/dist/{chunk-WLYIROCJ.js → chunk-RORE2GX2.js} +2 -2
  127. package/dist/{chunk-TDJPS3T2.js → chunk-RQY5UWEL.js} +24 -19
  128. package/dist/chunk-RQY5UWEL.js.map +1 -0
  129. package/dist/{chunk-7TSYBD3E.js → chunk-RSFG7XHM.js} +2 -2
  130. package/dist/{chunk-FAXZQ5UF.js → chunk-S55DBWRC.js} +2 -2
  131. package/dist/{chunk-WHJKIZS7.js → chunk-SA77BQ7F.js} +27 -149
  132. package/dist/chunk-SA77BQ7F.js.map +1 -0
  133. package/dist/{chunk-747LRSOO.js → chunk-SFD2LL7G.js} +2 -2
  134. package/dist/{chunk-P7OG2ETF.js → chunk-SG3OQCRG.js} +3 -3
  135. package/dist/{chunk-55LKVALY.js → chunk-T7IR4N2S.js} +1 -3
  136. package/dist/chunk-T7IR4N2S.js.map +1 -0
  137. package/dist/{chunk-EP7VPR7Y.js → chunk-TC6MBEGH.js} +11 -8
  138. package/dist/chunk-TC6MBEGH.js.map +1 -0
  139. package/dist/{chunk-HFQ6LGIO.js → chunk-TENLCGYD.js} +12 -10
  140. package/dist/{chunk-HFQ6LGIO.js.map → chunk-TENLCGYD.js.map} +1 -1
  141. package/dist/{chunk-WQDTCJ6W.js → chunk-VEX2BQVX.js} +3 -3
  142. package/dist/{chunk-7VHY5E3X.js → chunk-VH2W6BOG.js} +7 -7
  143. package/dist/chunk-VHVMJWM6.js +201 -0
  144. package/dist/chunk-VHVMJWM6.js.map +1 -0
  145. package/dist/{chunk-VCETL77O.js → chunk-VJ4B3ZXY.js} +27 -7
  146. package/dist/chunk-VJ4B3ZXY.js.map +1 -0
  147. package/dist/{chunk-OF3L2SD6.js → chunk-W6NFONOV.js} +2 -2
  148. package/dist/{chunk-NJDQ4YSV.js → chunk-WBNXZU42.js} +4 -4
  149. package/dist/{chunk-FNSMZQS4.js → chunk-WKD5ESK4.js} +2 -2
  150. package/dist/{chunk-NKH7GSIH.js → chunk-XGQGWZ6D.js} +4 -4
  151. package/dist/chunk-YOT7D63X.js +190 -0
  152. package/dist/chunk-YOT7D63X.js.map +1 -0
  153. package/dist/{chunk-4MC5JRRX.js → chunk-YVTADFTC.js} +14 -15
  154. package/dist/chunk-YVTADFTC.js.map +1 -0
  155. package/dist/{chunk-GASWQ3XG.js → chunk-ZBDWKPBW.js} +15 -16
  156. package/dist/chunk-ZBDWKPBW.js.map +1 -0
  157. package/dist/{chunk-52QYGZHH.js → chunk-ZPMXYPBR.js} +2 -2
  158. package/dist/chunk-ZPMXYPBR.js.map +1 -0
  159. package/dist/chunk-ZVAFJQZB.js +66 -0
  160. package/dist/chunk-ZVAFJQZB.js.map +1 -0
  161. package/dist/{chunk-VJFMXYKP.js → chunk-ZWKF3CD3.js} +2 -2
  162. package/dist/{chunk-I4ZAO7F7.js → chunk-ZXW3X3DQ.js} +7 -11
  163. package/dist/chunk-ZXW3X3DQ.js.map +1 -0
  164. package/dist/classified/index.js +5 -5
  165. package/dist/{classified-marker-FTOX7Q5L.js → classified-marker-PMDG3O36.js} +3 -3
  166. package/dist/collection-facade-ZJK5EB33.js +45 -0
  167. package/dist/{computed-6G5M3UPH.js → computed-UHCBRILW.js} +3 -3
  168. package/dist/consent/index.js +10 -10
  169. package/dist/cover/index.js +10 -3
  170. package/dist/custody/index.js +11 -11
  171. package/dist/{dead-filter-ENRIOQIE.js → dead-filter-777VWDER.js} +2 -2
  172. package/dist/debug/index.js +1 -1
  173. package/dist/{delegation-SSEPLXXO.js → delegation-4R5DU23X.js} +24 -23
  174. package/dist/delegation-4R5DU23X.js.map +1 -0
  175. package/dist/derivations/index.js +12 -12
  176. package/dist/derive-3WAS2G5T.js +22 -0
  177. package/dist/directory/index.js +10 -10
  178. package/dist/{dispatch-BDVGYC6X.js → dispatch-3EN6YCCS.js} +18 -18
  179. package/dist/{dispatch-RE74SH6L.js → dispatch-ASL257KG.js} +5 -5
  180. package/dist/{enclave-52VUXNRL.js → enclave-ZJS5R5RH.js} +25 -9
  181. package/dist/executor-GPM6DNWV.js +9 -0
  182. package/dist/executor-LJSMZ4IB.js +9 -0
  183. package/dist/executor-SHUVRZUJ.js +29 -0
  184. package/dist/export-accessible-GNY6DC6U.js +23 -0
  185. package/dist/extract-partition-BG3AF4NZ.js +38 -0
  186. package/dist/{fanout-sidecar-DTBIDOWF.js → fanout-sidecar-TFPWDOME.js} +18 -27
  187. package/dist/fanout-sidecar-TFPWDOME.js.map +1 -0
  188. package/dist/find-KX6OKHDP.js +11 -0
  189. package/dist/forget/index.js +9 -9
  190. package/dist/guards/index.js +4 -4
  191. package/dist/history/index.js +23 -20
  192. package/dist/history/index.js.map +1 -1
  193. package/dist/i18n/index.js +14 -14
  194. package/dist/index.d.ts +32 -15
  195. package/dist/index.js +183 -191
  196. package/dist/index.js.map +1 -1
  197. package/dist/indexing/index.js +2 -2
  198. package/dist/introspection/index.js +11 -11
  199. package/dist/issue-PAUM7NCX.js +19 -0
  200. package/dist/kernel/enclave/crypto.d.ts +24 -4
  201. package/dist/kernel/enclave/index.d.ts +8 -2
  202. package/dist/kernel/enclave/record-aad.d.ts +131 -0
  203. package/dist/kernel/enclave/record-envelope.d.ts +76 -0
  204. package/dist/kernel/enclave/record-keys/envelope-body.d.ts +34 -2
  205. package/dist/kernel/enclave/record-keys/lifecycle.d.ts +22 -5
  206. package/dist/kernel/enclave/record-keys/record-codec.d.ts +47 -14
  207. package/dist/kernel/enclave/record-keys/rekey.d.ts +68 -0
  208. package/dist/kernel/enclave/record-keys/tombstone.d.ts +3 -2
  209. package/dist/kernel/errors.d.ts +23 -11
  210. package/dist/kernel/merge-authority.d.ts +25 -0
  211. package/dist/kernel/noydb.d.ts +9 -3
  212. package/dist/kernel/query/builder.d.ts +15 -2
  213. package/dist/kernel/query/join.d.ts +27 -0
  214. package/dist/kernel/sync-policy.d.ts +0 -2
  215. package/dist/kernel/tier-visibility.d.ts +15 -0
  216. package/dist/kernel/types.d.ts +125 -6
  217. package/dist/kernel/vault.d.ts +21 -17
  218. package/dist/kernel/via/index.d.ts +11 -2
  219. package/dist/{ledger-4WJL66BW.js → ledger-62CEPRPX.js} +11 -11
  220. package/dist/liberate-I6AOLWXW.js +24 -0
  221. package/dist/{link-set-N4ZPV6E6.js → link-set-ZRYNUHN3.js} +11 -11
  222. package/dist/{managed-secret-OTHS64IF.js → managed-secret-T2WB4O47.js} +11 -3
  223. package/dist/materialized-views/index.js +22 -21
  224. package/dist/money/index.js +12 -8
  225. package/dist/noydb-SS6EN7TK.js +84 -0
  226. package/dist/overlay-views/index.js +4 -4
  227. package/dist/periods/index.js +22 -12
  228. package/dist/pod/index.js +75 -86
  229. package/dist/pod-handle-UPLXOGIK.js +41 -0
  230. package/dist/pod-handle-UPLXOGIK.js.map +1 -0
  231. package/dist/policy/index.js +11 -4
  232. package/dist/port/to/index.d.ts +4 -4
  233. package/dist/port/to/locator.d.ts +54 -8
  234. package/dist/port/with/i18n-strategy.d.ts +4 -1
  235. package/dist/port/with/lookup-strategy.d.ts +4 -1
  236. package/dist/port/with/merge-authority.d.ts +52 -0
  237. package/dist/port/with/service-bus.d.ts +0 -4
  238. package/dist/port/with/strategies.d.ts +2 -0
  239. package/dist/portability/index.js +8 -8
  240. package/dist/{post-register-ZAG2CAIY.js → post-register-J4DEVNXK.js} +6 -6
  241. package/dist/query/index.js +3 -3
  242. package/dist/reduce/index.js +4 -4
  243. package/dist/register-UPD4GKBC.js +32 -0
  244. package/dist/registry-7KX2HWFS.js +18 -0
  245. package/dist/registry-PKYYEHEW.js +9 -0
  246. package/dist/registry-XHCYMD34.js +19 -0
  247. package/dist/registry-XIRTZHPC.js +9 -0
  248. package/dist/request-withdrawal-XZSESWZV.js +31 -0
  249. package/dist/{reveal-CMOJY4VO.js → reveal-525XWQU2.js} +6 -6
  250. package/dist/revoke-QI7YHQ2B.js +24 -0
  251. package/dist/satellites/index.js +1 -1
  252. package/dist/schema-update/index.js +2 -2
  253. package/dist/sealed-record/index.js +20 -13
  254. package/dist/sealed-record/index.js.map +1 -1
  255. package/dist/search/index.js +4 -4
  256. package/dist/{seed-UK4QRIUN.js → seed-SGIF3EN4.js} +19 -22
  257. package/dist/seed-SGIF3EN4.js.map +1 -0
  258. package/dist/sequence/index.js +9 -9
  259. package/dist/session/index.js +10 -10
  260. package/dist/shadow/index.js +2 -2
  261. package/dist/share-link/index.js +1 -1
  262. package/dist/signer-BZWDPGGN.js +25 -0
  263. package/dist/snapshots/index.js +10 -10
  264. package/dist/snapshots/index.js.map +1 -1
  265. package/dist/{stale-ZWXSOWJI.js → stale-PQYPVCER.js} +10 -10
  266. package/dist/storage-MJHKNQRO.js +23 -0
  267. package/dist/{store-coordination-provider-PB6QZ57W.js → store-coordination-provider-TFHZLKHG.js} +18 -12
  268. package/dist/store-coordination-provider-TFHZLKHG.js.map +1 -0
  269. package/dist/sync/index.js +11 -11
  270. package/dist/team/index.js +15 -14
  271. package/dist/tiers/index.js +11 -10
  272. package/dist/to/index.js +17 -9
  273. package/dist/to/index.js.map +1 -1
  274. package/dist/transactions/index.js +4 -4
  275. package/dist/{ulid-PTAIMDG4.js → ulid-VQW6ERQN.js} +2 -2
  276. package/dist/util/index.js +1 -1
  277. package/dist/vault-head/index.js +115 -0
  278. package/dist/vault-head/index.js.map +1 -0
  279. package/dist/{verify-RO5RTZOJ.js → verify-J6DEOXP3.js} +5 -5
  280. package/dist/via/lookup/handle.d.ts +4 -1
  281. package/dist/via/money/exact.d.ts +44 -0
  282. package/dist/via/money/index.d.ts +2 -0
  283. package/dist/via/money/normalize.d.ts +20 -0
  284. package/dist/walk-BX4NSB5L.js +21 -0
  285. package/dist/with-audit/guards/immutable-guard.d.ts +14 -0
  286. package/dist/with-audit/periods/active.d.ts +28 -1
  287. package/dist/with-audit/periods/index.d.ts +4 -2
  288. package/dist/with-audit/periods/periods.d.ts +161 -6
  289. package/dist/with-audit/periods/strategy.d.ts +14 -5
  290. package/dist/with-audit/periods/vault-facade.d.ts +89 -10
  291. package/dist/with-audit/periods/window.d.ts +10 -0
  292. package/dist/with-audit/sealed-record/index.d.ts +13 -0
  293. package/dist/with-audit/tiers/index.d.ts +17 -2
  294. package/dist/with-cargo/adopt-partition.d.ts +1 -1
  295. package/dist/with-cargo/extract-partition.d.ts +1 -1
  296. package/dist/with-cargo/index.d.ts +2 -2
  297. package/dist/with-commit/history/history.d.ts +26 -0
  298. package/dist/with-commit/history/index.d.ts +2 -1
  299. package/dist/with-commit/history/ledger/store.d.ts +7 -1
  300. package/dist/with-commit/history/strategy.d.ts +11 -1
  301. package/dist/with-commit/numbering/index.d.ts +0 -5
  302. package/dist/with-commit/vault-head/active.d.ts +2 -0
  303. package/dist/with-commit/vault-head/head.d.ts +28 -0
  304. package/dist/with-commit/vault-head/index.d.ts +10 -0
  305. package/dist/with-commit/vault-head/strategy.d.ts +127 -0
  306. package/dist/with-commit/vault-head/verify.d.ts +90 -0
  307. package/dist/with-formula/materialized-views/types.d.ts +52 -0
  308. package/dist/with-party/directory/cover/storage.d.ts +0 -8
  309. package/dist/with-party/directory/storage.d.ts +0 -11
  310. package/dist/with-party/directory/visibility.d.ts +0 -21
  311. package/dist/with-party/policy/storage.d.ts +0 -10
  312. package/dist/with-party/team/index.d.ts +1 -1
  313. package/dist/with-party/team/keyring.d.ts +17 -3
  314. package/dist/with-party/team/tiers.d.ts +2 -1
  315. package/dist/with-pod/format.d.ts +10 -12
  316. package/dist/with-pod/index.d.ts +10 -10
  317. package/dist/with-pod/open.d.ts +2 -2
  318. package/dist/with-pod/pod-handle.d.ts +19 -0
  319. package/dist/with-pod/pod-store.d.ts +0 -8
  320. package/dist/with-pod/{bundle.d.ts → pod.d.ts} +26 -19
  321. package/dist/with-pod/ulid.d.ts +1 -1
  322. package/dist/with-shape/introspection/index.d.ts +1 -0
  323. package/dist/with-sync/engine.d.ts +54 -5
  324. package/dist/with-sync/strategy.d.ts +3 -0
  325. package/dist/withdraw-accessible-K4CPMH4C.js +28 -0
  326. package/package.json +12 -5
  327. package/dist/api-WVY3H3YH.js +0 -20
  328. package/dist/backup-YYBE5RPC.js.map +0 -1
  329. package/dist/bundle-handle-JEUWU2SJ.js +0 -36
  330. package/dist/bundle-handle-JEUWU2SJ.js.map +0 -1
  331. package/dist/chunk-26JMGSSC.js.map +0 -1
  332. package/dist/chunk-3737A6EA.js.map +0 -1
  333. package/dist/chunk-4MC5JRRX.js.map +0 -1
  334. package/dist/chunk-52QYGZHH.js.map +0 -1
  335. package/dist/chunk-55LKVALY.js.map +0 -1
  336. package/dist/chunk-5PR33AC4.js.map +0 -1
  337. package/dist/chunk-66W5OOCX.js.map +0 -1
  338. package/dist/chunk-7G6VDWXB.js.map +0 -1
  339. package/dist/chunk-A67356IR.js.map +0 -1
  340. package/dist/chunk-AFHQATY4.js +0 -47
  341. package/dist/chunk-AFHQATY4.js.map +0 -1
  342. package/dist/chunk-AHLJSVRL.js.map +0 -1
  343. package/dist/chunk-C2OOEM57.js.map +0 -1
  344. package/dist/chunk-DIMKRG2E.js +0 -131
  345. package/dist/chunk-DIMKRG2E.js.map +0 -1
  346. package/dist/chunk-E6427JU2.js.map +0 -1
  347. package/dist/chunk-E7OBCBXS.js.map +0 -1
  348. package/dist/chunk-EDXAQ6JI.js.map +0 -1
  349. package/dist/chunk-EP7VPR7Y.js.map +0 -1
  350. package/dist/chunk-ERB6NDDW.js.map +0 -1
  351. package/dist/chunk-G5APARUV.js.map +0 -1
  352. package/dist/chunk-GASWQ3XG.js.map +0 -1
  353. package/dist/chunk-GLKDWWNO.js.map +0 -1
  354. package/dist/chunk-HNGSV2YC.js.map +0 -1
  355. package/dist/chunk-I4F6PKUK.js.map +0 -1
  356. package/dist/chunk-I4ZAO7F7.js.map +0 -1
  357. package/dist/chunk-I6SDX7WX.js.map +0 -1
  358. package/dist/chunk-JXIDGFKS.js.map +0 -1
  359. package/dist/chunk-LWSJG3LI.js.map +0 -1
  360. package/dist/chunk-MWKDOHEF.js.map +0 -1
  361. package/dist/chunk-MZ5ZFO2D.js.map +0 -1
  362. package/dist/chunk-NIVEDYJZ.js.map +0 -1
  363. package/dist/chunk-NWCGDAV6.js +0 -45
  364. package/dist/chunk-NWCGDAV6.js.map +0 -1
  365. package/dist/chunk-PJNTR2NV.js.map +0 -1
  366. package/dist/chunk-PRDRGL73.js.map +0 -1
  367. package/dist/chunk-PY7CI6L5.js.map +0 -1
  368. package/dist/chunk-RKKORO4M.js.map +0 -1
  369. package/dist/chunk-TAGFGKHP.js.map +0 -1
  370. package/dist/chunk-TDJPS3T2.js.map +0 -1
  371. package/dist/chunk-TOAIYQJR.js.map +0 -1
  372. package/dist/chunk-UHXCLPGC.js.map +0 -1
  373. package/dist/chunk-UIBGXRDD.js.map +0 -1
  374. package/dist/chunk-V5KYPBUR.js.map +0 -1
  375. package/dist/chunk-VCETL77O.js.map +0 -1
  376. package/dist/chunk-VN45YLWM.js.map +0 -1
  377. package/dist/chunk-VOQW5LAM.js.map +0 -1
  378. package/dist/chunk-VRA4Q7DA.js.map +0 -1
  379. package/dist/chunk-VV4NSB7P.js.map +0 -1
  380. package/dist/chunk-W5W6KHN2.js.map +0 -1
  381. package/dist/chunk-WHJKIZS7.js.map +0 -1
  382. package/dist/chunk-WYZ5MYUA.js.map +0 -1
  383. package/dist/chunk-ZJADGNYF.js.map +0 -1
  384. package/dist/chunk-ZNACADFG.js.map +0 -1
  385. package/dist/collection-facade-QN5ULWYC.js +0 -45
  386. package/dist/delegation-SSEPLXXO.js.map +0 -1
  387. package/dist/derive-6V3PIZF7.js +0 -22
  388. package/dist/executor-CYJQLKKI.js +0 -9
  389. package/dist/executor-FHHLXO4Y.js +0 -28
  390. package/dist/executor-S4QIKEHW.js +0 -9
  391. package/dist/export-accessible-PE5AYKZR.js +0 -23
  392. package/dist/extract-partition-X2L26O6A.js +0 -38
  393. package/dist/fanout-sidecar-DTBIDOWF.js.map +0 -1
  394. package/dist/find-RBBYKXI7.js +0 -11
  395. package/dist/issue-RNU55YOF.js +0 -19
  396. package/dist/liberate-PX4CAT5V.js +0 -24
  397. package/dist/noydb-YPSEGK32.js +0 -83
  398. package/dist/register-TMD6YRCX.js +0 -32
  399. package/dist/registry-CZVINVQH.js +0 -9
  400. package/dist/registry-FVLDWQKT.js +0 -18
  401. package/dist/registry-IKUR2MXD.js +0 -9
  402. package/dist/registry-JET4HBLY.js +0 -19
  403. package/dist/request-withdrawal-RH55LNZL.js +0 -31
  404. package/dist/revoke-R5TBYVA6.js +0 -24
  405. package/dist/seed-UK4QRIUN.js.map +0 -1
  406. package/dist/signer-AGALOXOO.js +0 -25
  407. package/dist/storage-N7LB275C.js +0 -23
  408. package/dist/store-coordination-provider-PB6QZ57W.js.map +0 -1
  409. package/dist/walk-OCUHCYJ6.js +0 -21
  410. package/dist/with-pod/bundle-handle.d.ts +0 -9
  411. package/dist/withdraw-accessible-QQNWM5BO.js +0 -28
  412. /package/dist/{api-WVY3H3YH.js.map → api-Z5VHH24A.js.map} +0 -0
  413. /package/dist/{chunk-FDX7OWWI.js.map → chunk-2E2MKBMI.js.map} +0 -0
  414. /package/dist/{chunk-7F4DBNSP.js.map → chunk-5J5TTSGW.js.map} +0 -0
  415. /package/dist/{chunk-BTVYJWSN.js.map → chunk-5JT4Y5UE.js.map} +0 -0
  416. /package/dist/{chunk-7NXHMW6Y.js.map → chunk-7RCZ436O.js.map} +0 -0
  417. /package/dist/{chunk-DG27IUVI.js.map → chunk-A3NTKHDB.js.map} +0 -0
  418. /package/dist/{chunk-CCZJJ4I2.js.map → chunk-A4K5GLE6.js.map} +0 -0
  419. /package/dist/{chunk-CEJWMBXO.js.map → chunk-APV42WPR.js.map} +0 -0
  420. /package/dist/{chunk-4HDYQL3J.js.map → chunk-AQF7JSQR.js.map} +0 -0
  421. /package/dist/{chunk-KUDZVJKQ.js.map → chunk-BP4I7IBK.js.map} +0 -0
  422. /package/dist/{chunk-4UVDI4XE.js.map → chunk-BTNKPDZM.js.map} +0 -0
  423. /package/dist/{chunk-HVQGCKY4.js.map → chunk-C7WJNVJG.js.map} +0 -0
  424. /package/dist/{chunk-KCQX65FU.js.map → chunk-CVYXIN5B.js.map} +0 -0
  425. /package/dist/{chunk-AR2JDFAE.js.map → chunk-DJ23QZIN.js.map} +0 -0
  426. /package/dist/{chunk-PVU7LW5L.js.map → chunk-EJIVFOOQ.js.map} +0 -0
  427. /package/dist/{chunk-VMCCGUQB.js.map → chunk-GDGTIWB4.js.map} +0 -0
  428. /package/dist/{chunk-FUHKW252.js.map → chunk-GILI76SU.js.map} +0 -0
  429. /package/dist/{chunk-35EBKWQU.js.map → chunk-GT72D4FO.js.map} +0 -0
  430. /package/dist/{chunk-JRCYZEHU.js.map → chunk-HGJC7I5F.js.map} +0 -0
  431. /package/dist/{chunk-YAWK6AWF.js.map → chunk-JIF3IBRK.js.map} +0 -0
  432. /package/dist/{chunk-HNHCQ556.js.map → chunk-KBOPY6W2.js.map} +0 -0
  433. /package/dist/{chunk-W3TVWF6N.js.map → chunk-KM6YR5XF.js.map} +0 -0
  434. /package/dist/{chunk-6HFM7EIT.js.map → chunk-MNMYHZVU.js.map} +0 -0
  435. /package/dist/{chunk-QD724WDJ.js.map → chunk-N2HKBESK.js.map} +0 -0
  436. /package/dist/{chunk-Z45YRGFO.js.map → chunk-N7YAQKAO.js.map} +0 -0
  437. /package/dist/{chunk-DMQCLZ4Z.js.map → chunk-NH2MST6J.js.map} +0 -0
  438. /package/dist/{chunk-HXGUIPQB.js.map → chunk-OQLYMBJI.js.map} +0 -0
  439. /package/dist/{chunk-MSWYQLMQ.js.map → chunk-PG6PFMDC.js.map} +0 -0
  440. /package/dist/{chunk-WKPJXWKR.js.map → chunk-QPIUFRUC.js.map} +0 -0
  441. /package/dist/{chunk-JIUVJ4M7.js.map → chunk-REL4OLWW.js.map} +0 -0
  442. /package/dist/{chunk-VW6ZZGCG.js.map → chunk-RNSC2ARR.js.map} +0 -0
  443. /package/dist/{chunk-WLYIROCJ.js.map → chunk-RORE2GX2.js.map} +0 -0
  444. /package/dist/{chunk-7TSYBD3E.js.map → chunk-RSFG7XHM.js.map} +0 -0
  445. /package/dist/{chunk-FAXZQ5UF.js.map → chunk-S55DBWRC.js.map} +0 -0
  446. /package/dist/{chunk-747LRSOO.js.map → chunk-SFD2LL7G.js.map} +0 -0
  447. /package/dist/{chunk-P7OG2ETF.js.map → chunk-SG3OQCRG.js.map} +0 -0
  448. /package/dist/{chunk-WQDTCJ6W.js.map → chunk-VEX2BQVX.js.map} +0 -0
  449. /package/dist/{chunk-7VHY5E3X.js.map → chunk-VH2W6BOG.js.map} +0 -0
  450. /package/dist/{chunk-OF3L2SD6.js.map → chunk-W6NFONOV.js.map} +0 -0
  451. /package/dist/{chunk-NJDQ4YSV.js.map → chunk-WBNXZU42.js.map} +0 -0
  452. /package/dist/{chunk-FNSMZQS4.js.map → chunk-WKD5ESK4.js.map} +0 -0
  453. /package/dist/{chunk-NKH7GSIH.js.map → chunk-XGQGWZ6D.js.map} +0 -0
  454. /package/dist/{chunk-VJFMXYKP.js.map → chunk-ZWKF3CD3.js.map} +0 -0
  455. /package/dist/{classified-marker-FTOX7Q5L.js.map → classified-marker-PMDG3O36.js.map} +0 -0
  456. /package/dist/{collection-facade-QN5ULWYC.js.map → collection-facade-ZJK5EB33.js.map} +0 -0
  457. /package/dist/{computed-6G5M3UPH.js.map → computed-UHCBRILW.js.map} +0 -0
  458. /package/dist/{dead-filter-ENRIOQIE.js.map → dead-filter-777VWDER.js.map} +0 -0
  459. /package/dist/{derive-6V3PIZF7.js.map → derive-3WAS2G5T.js.map} +0 -0
  460. /package/dist/{dispatch-BDVGYC6X.js.map → dispatch-3EN6YCCS.js.map} +0 -0
  461. /package/dist/{dispatch-RE74SH6L.js.map → dispatch-ASL257KG.js.map} +0 -0
  462. /package/dist/{enclave-52VUXNRL.js.map → enclave-ZJS5R5RH.js.map} +0 -0
  463. /package/dist/{executor-CYJQLKKI.js.map → executor-GPM6DNWV.js.map} +0 -0
  464. /package/dist/{executor-FHHLXO4Y.js.map → executor-LJSMZ4IB.js.map} +0 -0
  465. /package/dist/{executor-S4QIKEHW.js.map → executor-SHUVRZUJ.js.map} +0 -0
  466. /package/dist/{export-accessible-PE5AYKZR.js.map → export-accessible-GNY6DC6U.js.map} +0 -0
  467. /package/dist/{extract-partition-X2L26O6A.js.map → extract-partition-BG3AF4NZ.js.map} +0 -0
  468. /package/dist/{find-RBBYKXI7.js.map → find-KX6OKHDP.js.map} +0 -0
  469. /package/dist/{issue-RNU55YOF.js.map → issue-PAUM7NCX.js.map} +0 -0
  470. /package/dist/{ledger-4WJL66BW.js.map → ledger-62CEPRPX.js.map} +0 -0
  471. /package/dist/{liberate-PX4CAT5V.js.map → liberate-I6AOLWXW.js.map} +0 -0
  472. /package/dist/{link-set-N4ZPV6E6.js.map → link-set-ZRYNUHN3.js.map} +0 -0
  473. /package/dist/{managed-secret-OTHS64IF.js.map → managed-secret-T2WB4O47.js.map} +0 -0
  474. /package/dist/{noydb-YPSEGK32.js.map → noydb-SS6EN7TK.js.map} +0 -0
  475. /package/dist/{post-register-ZAG2CAIY.js.map → post-register-J4DEVNXK.js.map} +0 -0
  476. /package/dist/{register-TMD6YRCX.js.map → register-UPD4GKBC.js.map} +0 -0
  477. /package/dist/{registry-CZVINVQH.js.map → registry-7KX2HWFS.js.map} +0 -0
  478. /package/dist/{registry-FVLDWQKT.js.map → registry-PKYYEHEW.js.map} +0 -0
  479. /package/dist/{registry-IKUR2MXD.js.map → registry-XHCYMD34.js.map} +0 -0
  480. /package/dist/{registry-JET4HBLY.js.map → registry-XIRTZHPC.js.map} +0 -0
  481. /package/dist/{request-withdrawal-RH55LNZL.js.map → request-withdrawal-XZSESWZV.js.map} +0 -0
  482. /package/dist/{reveal-CMOJY4VO.js.map → reveal-525XWQU2.js.map} +0 -0
  483. /package/dist/{revoke-R5TBYVA6.js.map → revoke-QI7YHQ2B.js.map} +0 -0
  484. /package/dist/{signer-AGALOXOO.js.map → signer-BZWDPGGN.js.map} +0 -0
  485. /package/dist/{stale-ZWXSOWJI.js.map → stale-PQYPVCER.js.map} +0 -0
  486. /package/dist/{storage-N7LB275C.js.map → storage-MJHKNQRO.js.map} +0 -0
  487. /package/dist/{ulid-PTAIMDG4.js.map → ulid-VQW6ERQN.js.map} +0 -0
  488. /package/dist/{verify-RO5RTZOJ.js.map → verify-J6DEOXP3.js.map} +0 -0
  489. /package/dist/{walk-OCUHCYJ6.js.map → walk-BX4NSB5L.js.map} +0 -0
  490. /package/dist/{withdraw-accessible-QQNWM5BO.js.map → withdraw-accessible-K4CPMH4C.js.map} +0 -0
@@ -1,19 +1,20 @@
1
1
  import {
2
+ buildRecordEnvelope,
2
3
  isDeleteMarker,
3
4
  isTombstone
4
- } from "./chunk-NWCGDAV6.js";
5
+ } from "./chunk-ZVAFJQZB.js";
5
6
  import {
6
7
  blindedEqual,
7
8
  openVdigPayload,
8
9
  sealVdigPayload
9
- } from "./chunk-HXGUIPQB.js";
10
+ } from "./chunk-OQLYMBJI.js";
10
11
  import {
11
12
  dualReadSealedSlot,
12
13
  parseSealedSlot
13
- } from "./chunk-AR2JDFAE.js";
14
+ } from "./chunk-DJ23QZIN.js";
14
15
  import {
15
16
  mintBidxTag
16
- } from "./chunk-747LRSOO.js";
17
+ } from "./chunk-SFD2LL7G.js";
17
18
  import {
18
19
  VDIG_ITERATIONS,
19
20
  normalizeForVerify,
@@ -32,11 +33,11 @@ import {
32
33
  generateSalt,
33
34
  unwrapCek,
34
35
  wrapCek
35
- } from "./chunk-VCETL77O.js";
36
+ } from "./chunk-VJ4B3ZXY.js";
36
37
  import {
37
38
  NOYDB_FORMAT_VERSION,
38
39
  SealedHandle
39
- } from "./chunk-W5W6KHN2.js";
40
+ } from "./chunk-3Y4OFWQJ.js";
40
41
  import {
41
42
  ClassifiedConfigError,
42
43
  ClassifiedRotationError,
@@ -45,7 +46,48 @@ import {
45
46
  SchemaValidationError,
46
47
  TamperedError,
47
48
  ValidationError
48
- } from "./chunk-HNGSV2YC.js";
49
+ } from "./chunk-P7L3OQLL.js";
50
+
51
+ // src/kernel/enclave/record-aad.ts
52
+ var SCHEME = "noydb-aad/2";
53
+ var encoder = new TextEncoder();
54
+ function buildRecordAad(identity) {
55
+ if (!Number.isFinite(identity.version)) {
56
+ throw new TypeError(
57
+ `record AAD: version must be a finite number for "${identity.collection}/${identity.id}", received ${String(identity.version)}. Sealing without one produces a record no reader can open.`
58
+ );
59
+ }
60
+ const parts = [encoder.encode(SCHEME)];
61
+ const pushField = (value) => {
62
+ const bytes = encoder.encode(value);
63
+ const len = new Uint8Array(4);
64
+ new DataView(len.buffer).setUint32(0, bytes.length, false);
65
+ parts.push(len, bytes);
66
+ };
67
+ pushField(identity.collection);
68
+ pushField(identity.id);
69
+ pushField(String(identity.tier ?? 0));
70
+ parts.push(new Uint8Array([identity.by === void 0 ? 0 : 1]));
71
+ if (identity.by !== void 0) pushField(identity.by);
72
+ pushField(String(identity.version));
73
+ const total = parts.reduce((n, p) => n + p.length, 0);
74
+ const out = new Uint8Array(total);
75
+ let offset = 0;
76
+ for (const p of parts) {
77
+ out.set(p, offset);
78
+ offset += p.length;
79
+ }
80
+ return out;
81
+ }
82
+ function recordAadFor(ref, envelope) {
83
+ return buildRecordAad({
84
+ collection: ref.collection,
85
+ id: ref.id,
86
+ version: envelope._v,
87
+ tier: envelope._tier,
88
+ by: envelope._by
89
+ });
90
+ }
49
91
 
50
92
  // src/kernel/enclave/record-keys/lifecycle.ts
51
93
  async function resolveStableCek(deps, id) {
@@ -61,15 +103,17 @@ async function resolveStableCek(deps, id) {
61
103
  deps.cache?.set(id, fresh, 1);
62
104
  return fresh;
63
105
  }
64
- async function rewrapBodyToDek(envelope, fromDek, toDek) {
106
+ async function rewrapBodyToDek(from, to, envelope, fromDek, toDek) {
107
+ const openAad = buildRecordAad(from);
108
+ const sealAad = buildRecordAad(to);
65
109
  if (envelope._cek !== void 0) {
66
110
  const cek = await unwrapCek(envelope._cek, fromDek);
67
- const plaintext2 = await decrypt(envelope._iv, envelope._data, cek);
68
- const { iv: iv2, data: data2 } = await encrypt(plaintext2, cek);
111
+ const plaintext2 = await decrypt(envelope._iv, envelope._data, cek, openAad);
112
+ const { iv: iv2, data: data2 } = await encrypt(plaintext2, cek, sealAad);
69
113
  return { _iv: iv2, _data: data2, _cek: await wrapCek(cek, toDek), cek };
70
114
  }
71
- const plaintext = await decrypt(envelope._iv, envelope._data, fromDek);
72
- const { iv, data } = await encrypt(plaintext, toDek);
115
+ const plaintext = await decrypt(envelope._iv, envelope._data, fromDek, openAad);
116
+ const { iv, data } = await encrypt(plaintext, toDek, sealAad);
73
117
  return { _iv: iv, _data: data, cek: null };
74
118
  }
75
119
  function applyRewrappedBody(envelope, body) {
@@ -84,15 +128,15 @@ function applyRewrappedBody(envelope, body) {
84
128
  }
85
129
  return next;
86
130
  }
87
- async function rewrapEnvelope(envelope, fromDek, toDek) {
88
- return applyRewrappedBody(envelope, await rewrapBodyToDek(envelope, fromDek, toDek));
131
+ async function rewrapEnvelope(identity, envelope, fromDek, toDek) {
132
+ return applyRewrappedBody(envelope, await rewrapBodyToDek(identity, identity, envelope, fromDek, toDek));
89
133
  }
90
- async function isRewrappedUnder(envelope, dek) {
134
+ async function isRewrappedUnder(identity, envelope, dek) {
91
135
  try {
92
136
  if (envelope._cek !== void 0) {
93
137
  await unwrapCek(envelope._cek, dek);
94
138
  } else {
95
- await decrypt(envelope._iv, envelope._data, dek);
139
+ await decrypt(envelope._iv, envelope._data, dek, buildRecordAad(identity));
96
140
  }
97
141
  return true;
98
142
  } catch {
@@ -100,6 +144,33 @@ async function isRewrappedUnder(envelope, dek) {
100
144
  }
101
145
  }
102
146
 
147
+ // src/kernel/enclave/record-keys/rekey.ts
148
+ async function rekeyEnvelopeToDek(ref, envelope, oldDek, newDek) {
149
+ const aad = recordAadFor(ref, envelope);
150
+ const { _bidx, ...carried } = envelope;
151
+ void _bidx;
152
+ if (envelope._cek !== void 0) {
153
+ const cek = await unwrapCek(envelope._cek, oldDek);
154
+ return { ...carried, _cek: await wrapCek(cek, newDek) };
155
+ }
156
+ const plaintext = await decrypt(envelope._iv, envelope._data, oldDek, aad);
157
+ const { iv, data } = await encrypt(plaintext, newDek, aad);
158
+ return { ...carried, _ts: (/* @__PURE__ */ new Date()).toISOString(), _iv: iv, _data: data };
159
+ }
160
+ async function rekeyEnvelopeIfNeeded(ref, envelope, oldDek, newDek) {
161
+ try {
162
+ return await rekeyEnvelopeToDek(ref, envelope, oldDek, newDek);
163
+ } catch (errUnderOld) {
164
+ try {
165
+ if (envelope._cek !== void 0) await unwrapCek(envelope._cek, newDek);
166
+ else await decrypt(envelope._iv, envelope._data, newDek, recordAadFor(ref, envelope));
167
+ return null;
168
+ } catch {
169
+ throw errUnderOld;
170
+ }
171
+ }
172
+ }
173
+
103
174
  // src/kernel/enclave/record-keys/sealed-slots.ts
104
175
  async function sealOneFieldWithDek(field, value, dek, keyMaterial) {
105
176
  const fieldKey = keyMaterial.cek !== void 0 ? await deriveSealedFieldKeyFromCek(keyMaterial.cek, keyMaterial.collection, field) : await deriveSealedFieldKey(dek, keyMaterial.collection, field);
@@ -175,22 +246,17 @@ function makeReservedEnvelopes(dekResolver, declaredPrefixes) {
175
246
  );
176
247
  }
177
248
  };
178
- const encryptForPrefix = async (collection, json, v) => {
179
- assertPrefixed(collection, "encrypt");
180
- const dek = await dekResolver(collection);
181
- const { iv, data } = await encrypt(json, dek);
182
- return {
183
- _noydb: NOYDB_FORMAT_VERSION,
184
- _v: v,
185
- _ts: (/* @__PURE__ */ new Date()).toISOString(),
186
- _iv: iv,
187
- _data: data
188
- };
249
+ const encryptForPrefix = async (ref, json, v) => {
250
+ assertPrefixed(ref.collection, "encrypt");
251
+ const dek = await dekResolver(ref.collection);
252
+ const identity = { ...ref, version: v };
253
+ const { iv, data } = await encrypt(json, dek, buildRecordAad(identity));
254
+ return buildRecordEnvelope(identity, { iv, data });
189
255
  };
190
- const decryptForPrefix = async (collection, env) => {
256
+ const decryptForPrefix = async (collection, id, env) => {
191
257
  assertPrefixed(collection, "decrypt");
192
258
  const dek = await dekResolver(collection);
193
- return decrypt(env._iv, env._data, dek);
259
+ return decrypt(env._iv, env._data, dek, recordAadFor({ collection, id }, env));
194
260
  };
195
261
  return { encrypt: encryptForPrefix, decrypt: decryptForPrefix };
196
262
  };
@@ -320,30 +386,12 @@ var RecordCodec = class _RecordCodec {
320
386
  * parts. Pure, no crypto. Each call stamps its own `_ts` — provenance carries
321
387
  * a SEPARATE timestamp (computed by the caller), so the two never share one.
322
388
  */
323
- static buildEnvelope(p) {
324
- return {
325
- _noydb: NOYDB_FORMAT_VERSION,
326
- _v: p.version,
327
- _ts: (/* @__PURE__ */ new Date()).toISOString(),
328
- _iv: p.iv,
329
- _data: p.data,
330
- ...p.by !== void 0 ? { _by: p.by } : {},
331
- ...p.cek !== void 0 ? { _cek: p.cek } : {},
332
- ...p.provenance !== void 0 ? { _source: p.provenance.source, _sourceTs: p.provenance.sourceTs } : {},
333
- ...p.extra ?? {}
334
- };
389
+ static buildEnvelope(identity, p) {
390
+ return buildRecordEnvelope(identity, p);
335
391
  }
336
392
  /** Plaintext (`_iv:''`) body envelope — the `!storeCiphertext` shape. */
337
- static buildPlaintextEnvelope(p) {
338
- return {
339
- _noydb: NOYDB_FORMAT_VERSION,
340
- _v: p.version,
341
- _ts: (/* @__PURE__ */ new Date()).toISOString(),
342
- _iv: "",
343
- _data: p.data,
344
- ...p.by !== void 0 ? { _by: p.by } : {},
345
- ...p.provenance !== void 0 ? { _source: p.provenance.source, _sourceTs: p.provenance.sourceTs } : {}
346
- };
393
+ static buildPlaintextEnvelope(identity, p) {
394
+ return buildRecordEnvelope(identity, { ...p, iv: "" });
347
395
  }
348
396
  // ──────────────────────────────────────────────────────────────────────
349
397
  // Write path
@@ -356,22 +404,20 @@ var RecordCodec = class _RecordCodec {
356
404
  * (see {@link encryptRecord}). Rejects `_`-prefixed record fields, which
357
405
  * would collide with the reserved metadata namespace.
358
406
  */
359
- buildDebugEnvelope(record, version, source, sourceTs) {
407
+ buildDebugEnvelope(id, record, version, source, sourceTs) {
360
408
  const rec = record;
361
409
  for (const key of Object.keys(rec)) {
362
410
  if (key.startsWith("_")) throw new DebugReservedFieldError(this.ctx.name, key);
363
411
  }
364
- return {
365
- _noydb: NOYDB_FORMAT_VERSION,
366
- _v: version,
367
- _ts: (/* @__PURE__ */ new Date()).toISOString(),
368
- _iv: "",
369
- _data: "",
370
- _by: this.ctx.actor,
371
- _debug: NOYDB_FORMAT_VERSION,
372
- ...this.ctx.provenance && source !== void 0 ? { _source: source, _sourceTs: sourceTs ?? (/* @__PURE__ */ new Date()).toISOString() } : {},
373
- ...rec
374
- };
412
+ const base = buildRecordEnvelope(
413
+ { collection: this.ctx.name, id, by: this.ctx.actor, version },
414
+ {
415
+ iv: "",
416
+ data: "",
417
+ ...this.ctx.provenance && source !== void 0 ? { provenance: { source, sourceTs: sourceTs ?? (/* @__PURE__ */ new Date()).toISOString() } } : {}
418
+ }
419
+ );
420
+ return { ...base, _debug: NOYDB_FORMAT_VERSION, ...rec };
375
421
  }
376
422
  /**
377
423
  * Encrypt a JSON body into an envelope.
@@ -382,24 +428,56 @@ var RecordCodec = class _RecordCodec {
382
428
  * path encrypts the body directly under the collection DEK — byte-identical
383
429
  * to pre-CEK behaviour, so non-adopting collections pay nothing.
384
430
  */
385
- async encryptJsonString(json, version, cek, source, sourceTs) {
386
- const by = this.ctx.actor;
431
+ /**
432
+ * `ref` is the identity the envelope is sealed against, and it is **the
433
+ * location the bytes are stored at** — not necessarily this codec's own
434
+ * collection (#1051).
435
+ *
436
+ * That distinction was discovered here rather than assumed. Several callers
437
+ * put the result somewhere else entirely: search's vector sidecar lands in
438
+ * `_vec` under `encodeVecId(name, id)`, the lexical index under `_ft/<name>`,
439
+ * indexing's entries under a synthetic `idxId`. A codec that supplied
440
+ * `this.ctx.name` for those would seal them against a collection they are not
441
+ * in, and once AAD binds identity every one of them would fail to verify.
442
+ *
443
+ * ⚠️ **`_history` is the open case, and it is #1041's to settle.** Snapshots
444
+ * are produced with the LIVE record's identity here and then re-homed by
445
+ * `saveHistory` into `_history/<historyId(collection,id,_v)>`. Both readings
446
+ * are defensible — bind where it lives, or bind what it is a copy of — and
447
+ * the choice must be made before AAD is switched on, not inferred from this
448
+ * migration.
449
+ */
450
+ async encryptJsonString(ref, json, version, cek, source, sourceTs) {
451
+ const identity = { ...ref, version, by: this.ctx.actor };
387
452
  const provenance = this.ctx.provenance && source !== void 0 ? { source, sourceTs: sourceTs ?? (/* @__PURE__ */ new Date()).toISOString() } : void 0;
388
453
  if (!this.ctx.storeCiphertext) {
389
- return _RecordCodec.buildPlaintextEnvelope({ version, data: json, by, provenance });
454
+ return _RecordCodec.buildPlaintextEnvelope(identity, { data: json, provenance });
390
455
  }
391
456
  const dek = await this.ctx.getDEK();
457
+ const aad = buildRecordAad(identity);
392
458
  if (cek !== void 0) {
393
- const { iv: iv2, data: data2 } = await encrypt(json, cek);
459
+ const { iv: iv2, data: data2 } = await encrypt(json, cek, aad);
394
460
  const wrapped = await wrapCek(cek, dek);
395
- return _RecordCodec.buildEnvelope({ version, iv: iv2, data: data2, by, cek: wrapped, provenance });
461
+ return _RecordCodec.buildEnvelope(identity, { iv: iv2, data: data2, cek: wrapped, provenance });
396
462
  }
397
- const { iv, data } = await encrypt(json, dek);
398
- return _RecordCodec.buildEnvelope({ version, iv, data, by, provenance });
463
+ const { iv, data } = await encrypt(json, dek, aad);
464
+ return _RecordCodec.buildEnvelope(identity, { iv, data, provenance });
399
465
  }
400
- async encryptRecord(record, version, cek, source, sourceTs, vdig, id) {
466
+ /**
467
+ * `ref` is FIRST and required (#1051). It was previously a trailing optional
468
+ * `id?: string`, which TypeScript cannot promote to required because it sits
469
+ * after other optionals — so the migration would have needed an `id ?? ''`
470
+ * fallback. That is exactly the silent default this issue exists to remove:
471
+ * once identity is bound into the AEAD, every record written with an empty id
472
+ * binds to the SAME identity and becomes interchangeable with the others.
473
+ * An object, not a bare string, so a swap with `version`/`source` cannot
474
+ * compile on the hottest write path. Carries the collection too — see
475
+ * {@link encryptJsonString} for why the codec must not assume its own.
476
+ */
477
+ async encryptRecord(ref, record, version, cek, source, sourceTs, vdig) {
478
+ const id = ref.id;
401
479
  if (!this.ctx.storeCiphertext && this.ctx.debugPlaintext && !this.ctx.name.startsWith("_")) {
402
- return this.buildDebugEnvelope(record, version, source, sourceTs);
480
+ return this.buildDebugEnvelope(id, record, version, source, sourceTs);
403
481
  }
404
482
  if (this.ctx.storeCiphertext) {
405
483
  const declared = this.ctx.vdigFields;
@@ -426,9 +504,9 @@ var RecordCodec = class _RecordCodec {
426
504
  let openRecord = record;
427
505
  let sealed;
428
506
  if (this.ctx.storeCiphertext && this.ctx.via?.hasAtRestHooks) {
429
- if (id === void 0) {
507
+ if (id === "") {
430
508
  throw new Error(
431
- `RecordCodec.encryptRecord: collection "${this.ctx.name}" has via at-rest hooks but this write path supplied no record id (needed to scope the sealed-slot capability) \u2014 caller bug.`
509
+ `RecordCodec.encryptRecord: collection "${this.ctx.name}" has via at-rest hooks but this write path supplied an empty record id (needed to scope the sealed-slot capability) \u2014 caller bug.`
432
510
  );
433
511
  }
434
512
  const src = record;
@@ -436,7 +514,7 @@ var RecordCodec = class _RecordCodec {
436
514
  openRecord = result.record;
437
515
  if (result.sealed !== void 0) {
438
516
  sealed = {};
439
- for (const [field, ref] of Object.entries(result.sealed)) sealed[field] = `${ref.iv}:${ref.data}`;
517
+ for (const [field, ref2] of Object.entries(result.sealed)) sealed[field] = `${ref2.iv}:${ref2.data}`;
440
518
  }
441
519
  } else if (this.ctx.storeCiphertext && this.ctx.sensitiveFields.size > 0) {
442
520
  const src = record;
@@ -501,7 +579,7 @@ var RecordCodec = class _RecordCodec {
501
579
  if (Object.keys(out).length > 0) vdigOut = out;
502
580
  if (Object.keys(bidxOut).length > 0) bidxOutMap = bidxOut;
503
581
  }
504
- const base = await this.encryptJsonString(JSON.stringify(openRecord), version, cek, source, sourceTs);
582
+ const base = await this.encryptJsonString(ref, JSON.stringify(openRecord), version, cek, source, sourceTs);
505
583
  const withSealed = sealed ? { ...base, _sealed: sealed } : base;
506
584
  const withVdig = vdigOut ? { ...withSealed, _vdig: vdigOut } : withSealed;
507
585
  const withBidx = bidxOutMap ? { ...withVdig, _bidx: bidxOutMap } : withVdig;
@@ -556,7 +634,15 @@ var RecordCodec = class _RecordCodec {
556
634
  * The optional `id` lets reads populate the CEK cache; it is omitted by
557
635
  * callers (history, conflict merge) that have only the envelope.
558
636
  */
559
- async decryptJsonString(envelope, id) {
637
+ /**
638
+ * `ref` must be the SAME identity the writer sealed against — which is the
639
+ * storage address, not necessarily this codec's own collection. Search's
640
+ * vector sidecar lives in `_vec`, its lexical index in `_ft`; passing
641
+ * `this.ctx.name` for those would recompute the wrong AAD and fail to open a
642
+ * perfectly good record (#1041).
643
+ */
644
+ async decryptJsonString(ref, envelope) {
645
+ const id = ref.id;
560
646
  if (isTombstone(envelope, this.ctx.storeCiphertext) || isDeleteMarker(envelope)) return null;
561
647
  if (!this.ctx.storeCiphertext) {
562
648
  if (envelope._debug !== void 0) {
@@ -568,10 +654,11 @@ var RecordCodec = class _RecordCodec {
568
654
  }
569
655
  return envelope._data === "" ? null : envelope._data;
570
656
  }
657
+ const aad = recordAadFor(ref, envelope);
571
658
  const cek = await this.resolveEnvelopeCek(envelope, id);
572
- if (cek !== void 0) return decrypt(envelope._iv, envelope._data, cek);
659
+ if (cek !== void 0) return decrypt(envelope._iv, envelope._data, cek, aad);
573
660
  const dek = await this.ctx.getDEK();
574
- return decrypt(envelope._iv, envelope._data, dek);
661
+ return decrypt(envelope._iv, envelope._data, dek, aad);
575
662
  }
576
663
  /**
577
664
  * Unseal a single `_sealed[field]` slot to its plaintext value: derive the
@@ -695,7 +782,7 @@ var RecordCodec = class _RecordCodec {
695
782
  */
696
783
  async applySealedSlots(record, sealed, cek, opts = {}) {
697
784
  if (this.ctx.via?.hasAtRestHooks) {
698
- if (opts.id === void 0) {
785
+ if (opts.id === void 0 || opts.id === "") {
699
786
  throw new Error(
700
787
  `RecordCodec.decryptRecord: collection "${this.ctx.name}" has via at-rest hooks but this read path supplied no record id (needed to scope the sealed-slot capability) \u2014 caller bug.`
701
788
  );
@@ -745,15 +832,17 @@ var RecordCodec = class _RecordCodec {
745
832
  * output-recompute path, not the public per-record read surface schema
746
833
  * validation guards.
747
834
  */
748
- async decryptRecordAtDek(envelope, dek, id) {
835
+ async decryptRecordAtDek(ref, envelope, dek) {
836
+ const id = ref.id;
749
837
  if (isTombstone(envelope, this.ctx.storeCiphertext) || isDeleteMarker(envelope)) return null;
750
838
  let plaintext;
751
839
  let cek;
840
+ const aad = recordAadFor(ref, envelope);
752
841
  if (envelope._cek !== void 0) {
753
842
  cek = await unwrapCek(envelope._cek, dek);
754
- plaintext = await decrypt(envelope._iv, envelope._data, cek);
843
+ plaintext = await decrypt(envelope._iv, envelope._data, cek, aad);
755
844
  } else {
756
- plaintext = await decrypt(envelope._iv, envelope._data, dek);
845
+ plaintext = await decrypt(envelope._iv, envelope._data, dek, aad);
757
846
  }
758
847
  let record = JSON.parse(plaintext);
759
848
  if (envelope._sealed !== void 0 && this.ctx.storeCiphertext) {
@@ -776,8 +865,8 @@ var RecordCodec = class _RecordCodec {
776
865
  * that may predate a schema change, so validating it would be a
777
866
  * false positive. Every non-history read leaves this flag `false`.
778
867
  */
779
- async decryptRecord(envelope, opts = {}) {
780
- const json = await this.decryptJsonString(envelope, opts.id);
868
+ async decryptRecord(ref, envelope, opts = {}) {
869
+ const json = await this.decryptJsonString(ref, envelope);
781
870
  if (json === null) return null;
782
871
  let parsed = JSON.parse(json);
783
872
  if (this.ctx.crdtMode && parsed !== null && typeof parsed === "object" && "_crdt" in parsed) {
@@ -785,9 +874,9 @@ var RecordCodec = class _RecordCodec {
785
874
  }
786
875
  let record = parsed;
787
876
  if (envelope._sealed !== void 0 && this.ctx.storeCiphertext) {
788
- const sealedCek = await this.resolveEnvelopeCek(envelope, opts.id);
877
+ const sealedCek = await this.resolveEnvelopeCek(envelope, ref.id);
789
878
  record = await this.applySealedSlots(record, envelope._sealed, sealedCek, {
790
- ...opts.id !== void 0 ? { id: opts.id } : {},
879
+ id: ref.id,
791
880
  ...opts.sealedAsHandles !== void 0 ? { sealedAsHandles: opts.sealedAsHandles } : {}
792
881
  });
793
882
  }
@@ -841,16 +930,16 @@ async function sealRecordToHost(ctx, collection, id, hostSealer, opts) {
841
930
  };
842
931
  const envelopeKey = `${collection}/${id}/${hint.pid}`;
843
932
  const prior = await ctx.adapter.get(ctx.vault, SEALED_CEK_NS, envelopeKey);
844
- const env = {
845
- _noydb: NOYDB_FORMAT_VERSION,
846
- _v: (prior?._v ?? 0) + 1,
847
- _ts: (/* @__PURE__ */ new Date()).toISOString(),
848
- // AES-GCM bypassed — the sealing layer is the security boundary, exactly
849
- // like the managed-secret `_meta/sealed-secret` envelope.
850
- _iv: "",
851
- _data: JSON.stringify(delivery),
852
- ...ctx.actor ? { _by: ctx.actor } : {}
853
- };
933
+ const env = buildRecordEnvelope(
934
+ { collection: SEALED_CEK_NS, id: envelopeKey, version: (prior?._v ?? 0) + 1 },
935
+ {
936
+ // AES-GCM bypassed — the sealing layer is the security boundary, exactly
937
+ // like the managed-secret `_meta/sealed-secret` envelope.
938
+ iv: "",
939
+ data: JSON.stringify(delivery),
940
+ ...ctx.actor ? { by: ctx.actor } : {}
941
+ }
942
+ );
854
943
  await ctx.adapter.put(ctx.vault, SEALED_CEK_NS, envelopeKey, env);
855
944
  return { pid: hint.pid, envelopeKey };
856
945
  }
@@ -868,9 +957,26 @@ async function rotateRecordCek(ctx, collection, id) {
868
957
  }
869
958
  const dek = await ctx.getDEK(collection);
870
959
  const oldCek = await unwrapCek(live._cek, dek);
871
- const json = await decrypt(live._iv, live._data, oldCek);
960
+ const openAad = recordAadFor({ collection, id }, live);
961
+ const json = await decrypt(live._iv, live._data, oldCek, openAad);
962
+ const rotatedIdentity = {
963
+ // A CEK rotation DOES bump `_v` (asserted in `record-scoped-cek-sealing`:
964
+ // "the live envelope was re-keyed — new `_cek`, bumped `_v`"), so it seals
965
+ // at the new version, not the one it just opened.
966
+ //
967
+ // ⚠️ Do not confuse this with `rekeyEnvelopeToDek`, the DEK-rotation helper,
968
+ // which PRESERVES `_v` (#1074) because it re-keys a record without writing
969
+ // one. Two rotations, opposite answers — and with `_v` bound (#1093) getting
970
+ // it backwards no longer produces a wrong number, it produces an
971
+ // unreadable record.
972
+ collection,
973
+ id,
974
+ version: live._v + 1,
975
+ ...live._tier !== void 0 ? { tier: live._tier } : {},
976
+ ...ctx.actor ? { by: ctx.actor } : live._by !== void 0 ? { by: live._by } : {}
977
+ };
872
978
  const newCek = await generateDEK();
873
- const { iv, data } = await encrypt(json, newCek);
979
+ const { iv, data } = await encrypt(json, newCek, buildRecordAad(rotatedIdentity));
874
980
  let sealedOut;
875
981
  if (live._sealed !== void 0) {
876
982
  const out = {};
@@ -890,30 +996,27 @@ async function rotateRecordCek(ctx, collection, id) {
890
996
  }
891
997
  vdigOut = out;
892
998
  }
893
- const env = {
894
- _noydb: NOYDB_FORMAT_VERSION,
895
- _v: live._v + 1,
896
- _ts: (/* @__PURE__ */ new Date()).toISOString(),
897
- _iv: iv,
898
- _data: data,
899
- _cek: await wrapCek(newCek, dek),
900
- ...ctx.actor ? { _by: ctx.actor } : {},
901
- ...live._tier !== void 0 ? { _tier: live._tier } : {},
902
- ...live._det !== void 0 ? { _det: live._det } : {},
903
- // `_bidx` (equality-index tag) is DEK-rooted and CEK-independent, so it is
904
- // carried forward VERBATIM — not recomputed — unlike `_vdig`/`_sealed`
905
- // below, which are CEK-bound and must be re-sealed under the new CEK.
906
- // Dropping this line would silently orphan the equality index on rotation
907
- // (the #306 Slice-A data-loss bug, replayed on the index).
908
- ...live._bidx !== void 0 ? { _bidx: live._bidx } : {},
909
- // Re-encrypt sealed (`sensitive`) fields under the new CEK. Sealed
910
- // keys derive off the per-record CEK, so the rotated record's old CEK is
911
- // destroyed here — carrying the old `_sealed` slots forward verbatim would
912
- // orphan them (unreadable under the new CEK). `sealedOut` holds the slots
913
- // dual-read from the old CEK (or the legacy DEK) and re-sealed under newCek.
914
- ...sealedOut !== void 0 ? { _sealed: sealedOut } : {},
915
- ...vdigOut !== void 0 ? { _vdig: vdigOut } : {}
916
- };
999
+ const env = buildRecordEnvelope(rotatedIdentity, {
1000
+ iv,
1001
+ data,
1002
+ cek: await wrapCek(newCek, dek),
1003
+ extra: {
1004
+ ...live._det !== void 0 ? { _det: live._det } : {},
1005
+ // `_bidx` (equality-index tag) is DEK-rooted and CEK-independent, so it is
1006
+ // carried forward VERBATIM — not recomputed — unlike `_vdig`/`_sealed`
1007
+ // below, which are CEK-bound and must be re-sealed under the new CEK.
1008
+ // Dropping this line would silently orphan the equality index on rotation
1009
+ // (the #306 Slice-A data-loss bug, replayed on the index).
1010
+ ...live._bidx !== void 0 ? { _bidx: live._bidx } : {},
1011
+ // Re-encrypt sealed (`sensitive`) fields under the new CEK. Sealed
1012
+ // keys derive off the per-record CEK, so the rotated record's old CEK is
1013
+ // destroyed here — carrying the old `_sealed` slots forward verbatim would
1014
+ // orphan them (unreadable under the new CEK). `sealedOut` holds the slots
1015
+ // dual-read from the old CEK (or the legacy DEK) and re-sealed under newCek.
1016
+ ...sealedOut !== void 0 ? { _sealed: sealedOut } : {},
1017
+ ...vdigOut !== void 0 ? { _vdig: vdigOut } : {}
1018
+ }
1019
+ });
917
1020
  await ctx.adapter.put(ctx.vault, collection, id, env);
918
1021
  await ctx.invalidateRecordCaches(collection, id);
919
1022
  const prefix = `${collection}/${id}/`;
@@ -957,7 +1060,7 @@ async function findByDet(ctx, field, value) {
957
1060
  const env = await ctx.adapter.get(ctx.vault, ctx.name, id);
958
1061
  if (!env || !env._det || (env._tier ?? 0) > 0) continue;
959
1062
  if (env._det[field] === target || env._det[field] === legacyTarget) {
960
- return ctx.codec.decryptRecord(env, { id });
1063
+ return ctx.codec.decryptRecord({ collection: ctx.name, id }, env);
961
1064
  }
962
1065
  }
963
1066
  return null;
@@ -971,7 +1074,7 @@ async function queryByDet(ctx, field, value) {
971
1074
  const env = await ctx.adapter.get(ctx.vault, ctx.name, id);
972
1075
  if (!env || !env._det || (env._tier ?? 0) > 0) continue;
973
1076
  if (env._det[field] === target || env._det[field] === legacyTarget) {
974
- const rec = await ctx.codec.decryptRecord(env, { id });
1077
+ const rec = await ctx.codec.decryptRecord({ collection: ctx.name, id }, env);
975
1078
  if (rec !== null) matches.push(rec);
976
1079
  }
977
1080
  }
@@ -979,23 +1082,25 @@ async function queryByDet(ctx, field, value) {
979
1082
  }
980
1083
 
981
1084
  // src/kernel/enclave/record-keys/envelope-body.ts
982
- async function openEnvelopeJson(env, key, opts) {
1085
+ async function openEnvelopeJson(ref, env, key, opts) {
983
1086
  if (opts?.encrypted === false) return env._data;
1087
+ const aad = recordAadFor(ref, env);
984
1088
  if (env._cek !== void 0) {
985
1089
  const cek = await unwrapCek(env._cek, key);
986
- return decrypt(env._iv, env._data, cek);
1090
+ return decrypt(env._iv, env._data, cek, aad);
987
1091
  }
988
- return decrypt(env._iv, env._data, key);
1092
+ return decrypt(env._iv, env._data, key, aad);
989
1093
  }
990
- async function writeEnvelopeBody(json, key, opts) {
1094
+ async function writeEnvelopeBody(identity, json, key, opts) {
991
1095
  if (opts?.encrypted === false) return { _iv: "", _data: json };
1096
+ const aad = buildRecordAad(identity);
992
1097
  if (opts?.perRecordKey === true) {
993
1098
  const cek = await generateDEK();
994
- const { iv: iv2, data: data2 } = await encrypt(json, cek);
1099
+ const { iv: iv2, data: data2 } = await encrypt(json, cek, aad);
995
1100
  const wrapped = await wrapCek(cek, key);
996
1101
  return { _iv: iv2, _data: data2, _cek: wrapped };
997
1102
  }
998
- const { iv, data } = await encrypt(json, key);
1103
+ const { iv, data } = await encrypt(json, key, aad);
999
1104
  return { _iv: iv, _data: data };
1000
1105
  }
1001
1106
  function envelopeBodySize(env) {
@@ -1018,6 +1123,18 @@ function envelopeBodyForHash(env) {
1018
1123
  if (env._bidx !== void 0) segments.push(mapPart("_bidx", env._bidx));
1019
1124
  return `{${segments.join(",")}}`;
1020
1125
  }
1126
+ function hasSealedBody(env) {
1127
+ return env._iv !== "";
1128
+ }
1129
+ async function verifyRecordIdentity(ref, env, key) {
1130
+ if (!hasSealedBody(env)) return true;
1131
+ try {
1132
+ await openEnvelopeJson(ref, env, key);
1133
+ return true;
1134
+ } catch {
1135
+ return false;
1136
+ }
1137
+ }
1021
1138
 
1022
1139
  // src/kernel/enclave/broker/proof.ts
1023
1140
  var subtle2 = globalThis.crypto.subtle;
@@ -1103,11 +1220,15 @@ async function verifyBrokerProof(args) {
1103
1220
  }
1104
1221
 
1105
1222
  export {
1223
+ buildRecordAad,
1224
+ recordAadFor,
1106
1225
  resolveStableCek,
1107
1226
  rewrapBodyToDek,
1108
1227
  applyRewrappedBody,
1109
1228
  rewrapEnvelope,
1110
1229
  isRewrappedUnder,
1230
+ rekeyEnvelopeToDek,
1231
+ rekeyEnvelopeIfNeeded,
1111
1232
  makeReservedEnvelopes,
1112
1233
  validateSchemaInput,
1113
1234
  validateSchemaOutput,
@@ -1123,10 +1244,12 @@ export {
1123
1244
  envelopeBodySize,
1124
1245
  hasPerRecordKey,
1125
1246
  envelopeBodyForHash,
1247
+ hasSealedBody,
1248
+ verifyRecordIdentity,
1126
1249
  deriveBrokerProofBits,
1127
1250
  deriveBrokerProofKey,
1128
1251
  computeBrokerProof,
1129
1252
  issueChallenge,
1130
1253
  verifyBrokerProof
1131
1254
  };
1132
- //# sourceMappingURL=chunk-VN45YLWM.js.map
1255
+ //# sourceMappingURL=chunk-D5UDZANO.js.map