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

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 (499) hide show
  1. package/CHANGELOG.md +5234 -0
  2. package/codemods/0.4.0-pre.json +699 -0
  3. package/codemods/0.6.0-pre.json +211 -0
  4. package/dist/api-EYNT6KGS.js +20 -0
  5. package/dist/attestation/index.js +19 -19
  6. package/dist/{backup-YYBE5RPC.js → backup-FSC36VWC.js} +36 -18
  7. package/dist/backup-FSC36VWC.js.map +1 -0
  8. package/dist/blobs/index.js +13 -13
  9. package/dist/broker/index.js +12 -12
  10. package/dist/cargo/index.js +33 -33
  11. package/dist/{chunk-35EBKWQU.js → chunk-2LFOMUEA.js} +4 -4
  12. package/dist/{chunk-OF3L2SD6.js → chunk-32B7VCKU.js} +2 -2
  13. package/dist/{chunk-MSWYQLMQ.js → chunk-3B6S6RSI.js} +2 -2
  14. package/dist/{chunk-PJNTR2NV.js → chunk-3ENNPCIW.js} +7 -10
  15. package/dist/chunk-3ENNPCIW.js.map +1 -0
  16. package/dist/{chunk-7F4DBNSP.js → chunk-3O72ZD2E.js} +3 -3
  17. package/dist/{chunk-FNSMZQS4.js → chunk-3PMFMUFX.js} +2 -2
  18. package/dist/{chunk-WQDTCJ6W.js → chunk-45YHJ3GV.js} +11 -3
  19. package/dist/{chunk-WQDTCJ6W.js.map → chunk-45YHJ3GV.js.map} +1 -1
  20. package/dist/{chunk-NIVEDYJZ.js → chunk-4A34KWOU.js} +31 -49
  21. package/dist/chunk-4A34KWOU.js.map +1 -0
  22. package/dist/{chunk-ZJADGNYF.js → chunk-4AOERLTV.js} +1 -1
  23. package/dist/chunk-4AOERLTV.js.map +1 -0
  24. package/dist/{chunk-EDXAQ6JI.js → chunk-4N5Q23KV.js} +87 -34
  25. package/dist/chunk-4N5Q23KV.js.map +1 -0
  26. package/dist/{chunk-VV4NSB7P.js → chunk-4OQZNXQG.js} +15 -24
  27. package/dist/chunk-4OQZNXQG.js.map +1 -0
  28. package/dist/{chunk-FAXZQ5UF.js → chunk-4RAS6HN6.js} +2 -2
  29. package/dist/{chunk-C2OOEM57.js → chunk-4YL2LMXK.js} +92 -35
  30. package/dist/chunk-4YL2LMXK.js.map +1 -0
  31. package/dist/{chunk-EP7VPR7Y.js → chunk-5Q7AJ7DN.js} +11 -8
  32. package/dist/chunk-5Q7AJ7DN.js.map +1 -0
  33. package/dist/{chunk-VMCCGUQB.js → chunk-6JPGVL7X.js} +2 -2
  34. package/dist/{chunk-PRDRGL73.js → chunk-6KTVJ5ZZ.js} +17 -14
  35. package/dist/chunk-6KTVJ5ZZ.js.map +1 -0
  36. package/dist/{chunk-4MC5JRRX.js → chunk-6WO62AJW.js} +14 -15
  37. package/dist/chunk-6WO62AJW.js.map +1 -0
  38. package/dist/{chunk-WLYIROCJ.js → chunk-6YD5SYQS.js} +2 -2
  39. package/dist/{chunk-YAWK6AWF.js → chunk-7KAE7CQ2.js} +2 -2
  40. package/dist/{chunk-MWKDOHEF.js → chunk-7LNE2N2V.js} +17 -10
  41. package/dist/chunk-7LNE2N2V.js.map +1 -0
  42. package/dist/{chunk-5PR33AC4.js → chunk-7PJ3BKHS.js} +20 -17
  43. package/dist/chunk-7PJ3BKHS.js.map +1 -0
  44. package/dist/{chunk-JXIDGFKS.js → chunk-A4TOGAUW.js} +4 -2
  45. package/dist/chunk-A4TOGAUW.js.map +1 -0
  46. package/dist/{chunk-VCETL77O.js → chunk-AU3AUJIZ.js} +27 -7
  47. package/dist/chunk-AU3AUJIZ.js.map +1 -0
  48. package/dist/{chunk-NKH7GSIH.js → chunk-AUPSEJ7O.js} +4 -4
  49. package/dist/{chunk-CCZJJ4I2.js → chunk-B6IYATME.js} +4 -4
  50. package/dist/{chunk-WYZ5MYUA.js → chunk-BAHOV5I5.js} +44 -42
  51. package/dist/chunk-BAHOV5I5.js.map +1 -0
  52. package/dist/{chunk-G5APARUV.js → chunk-BEZDLIDG.js} +13 -15
  53. package/dist/chunk-BEZDLIDG.js.map +1 -0
  54. package/dist/{chunk-ERB6NDDW.js → chunk-CAGI4LLJ.js} +427 -72
  55. package/dist/chunk-CAGI4LLJ.js.map +1 -0
  56. package/dist/{chunk-4UVDI4XE.js → chunk-CLAHBPOI.js} +4 -4
  57. package/dist/{chunk-HNGSV2YC.js → chunk-CWM4GQD2.js} +39 -10
  58. package/dist/chunk-CWM4GQD2.js.map +1 -0
  59. package/dist/{chunk-HVQGCKY4.js → chunk-D3R7Q4QK.js} +2 -2
  60. package/dist/{chunk-I4F6PKUK.js → chunk-DIZ6HM7Q.js} +16 -17
  61. package/dist/chunk-DIZ6HM7Q.js.map +1 -0
  62. package/dist/{chunk-ZNACADFG.js → chunk-DVRZYAGT.js} +4 -4
  63. package/dist/chunk-DVRZYAGT.js.map +1 -0
  64. package/dist/{chunk-P7OG2ETF.js → chunk-DXKLLKME.js} +3 -3
  65. package/dist/{chunk-TDJPS3T2.js → chunk-E5SC6ENM.js} +24 -19
  66. package/dist/chunk-E5SC6ENM.js.map +1 -0
  67. package/dist/{chunk-26JMGSSC.js → chunk-EES37S2V.js} +4 -4
  68. package/dist/chunk-EES37S2V.js.map +1 -0
  69. package/dist/{chunk-JIUVJ4M7.js → chunk-EKEIEJL6.js} +2 -2
  70. package/dist/{chunk-GASWQ3XG.js → chunk-ESKIAXO2.js} +15 -16
  71. package/dist/chunk-ESKIAXO2.js.map +1 -0
  72. package/dist/{chunk-TOAIYQJR.js → chunk-FFSQFH6D.js} +7 -10
  73. package/dist/chunk-FFSQFH6D.js.map +1 -0
  74. package/dist/{chunk-DG27IUVI.js → chunk-FS7NTGCJ.js} +2 -2
  75. package/dist/{chunk-V5KYPBUR.js → chunk-FW7NGYLT.js} +11 -14
  76. package/dist/chunk-FW7NGYLT.js.map +1 -0
  77. package/dist/{chunk-52QYGZHH.js → chunk-GBBDFE6C.js} +2 -2
  78. package/dist/chunk-GBBDFE6C.js.map +1 -0
  79. package/dist/{chunk-HXGUIPQB.js → chunk-GQXFOAYZ.js} +3 -3
  80. package/dist/{chunk-BTVYJWSN.js → chunk-GTHVPVAR.js} +10 -10
  81. package/dist/{chunk-DMQCLZ4Z.js → chunk-GWO2IDAB.js} +2 -2
  82. package/dist/{chunk-6HFM7EIT.js → chunk-H3G4I3PN.js} +2 -2
  83. package/dist/chunk-HK67PX4J.js +27 -0
  84. package/dist/chunk-HK67PX4J.js.map +1 -0
  85. package/dist/{chunk-E7OBCBXS.js → chunk-HQSPF5IY.js} +22 -18
  86. package/dist/chunk-HQSPF5IY.js.map +1 -0
  87. package/dist/{chunk-VJFMXYKP.js → chunk-HR5R5JOM.js} +2 -2
  88. package/dist/{chunk-FDX7OWWI.js → chunk-HYYVT2KZ.js} +2 -2
  89. package/dist/{chunk-JRCYZEHU.js → chunk-I6QKB7MT.js} +2 -2
  90. package/dist/{chunk-MZ5ZFO2D.js → chunk-ICDHUUMQ.js} +84 -112
  91. package/dist/chunk-ICDHUUMQ.js.map +1 -0
  92. package/dist/{chunk-W5W6KHN2.js → chunk-IGNJOJEP.js} +1 -1
  93. package/dist/chunk-IGNJOJEP.js.map +1 -0
  94. package/dist/{chunk-KUDZVJKQ.js → chunk-IJ46VCWD.js} +2 -2
  95. package/dist/{chunk-4HDYQL3J.js → chunk-INMHEMXX.js} +2 -2
  96. package/dist/{chunk-66W5OOCX.js → chunk-JLYQQNY4.js} +52 -65
  97. package/dist/chunk-JLYQQNY4.js.map +1 -0
  98. package/dist/{chunk-UHXCLPGC.js → chunk-JNMTN5D5.js} +2 -2
  99. package/dist/chunk-JNMTN5D5.js.map +1 -0
  100. package/dist/{chunk-I4ZAO7F7.js → chunk-JWMBG5S3.js} +7 -11
  101. package/dist/chunk-JWMBG5S3.js.map +1 -0
  102. package/dist/chunk-KRVS7YWY.js +123 -0
  103. package/dist/chunk-KRVS7YWY.js.map +1 -0
  104. package/dist/{chunk-AR2JDFAE.js → chunk-KV6JM2IA.js} +2 -2
  105. package/dist/{chunk-PVU7LW5L.js → chunk-KX57HODD.js} +6 -6
  106. package/dist/{chunk-PY7CI6L5.js → chunk-LGFTOU27.js} +553 -275
  107. package/dist/chunk-LGFTOU27.js.map +1 -0
  108. package/dist/chunk-LN7P6MZB.js +190 -0
  109. package/dist/chunk-LN7P6MZB.js.map +1 -0
  110. package/dist/{chunk-UIBGXRDD.js → chunk-LX46B56Q.js} +25 -31
  111. package/dist/chunk-LX46B56Q.js.map +1 -0
  112. package/dist/{chunk-CEJWMBXO.js → chunk-LXECF2ZR.js} +2 -2
  113. package/dist/{chunk-7VHY5E3X.js → chunk-MSLPDFK2.js} +7 -7
  114. package/dist/{chunk-I6SDX7WX.js → chunk-MZTUTEHP.js} +16 -22
  115. package/dist/chunk-MZTUTEHP.js.map +1 -0
  116. package/dist/{chunk-VRA4Q7DA.js → chunk-NCCEDL2K.js} +55 -48
  117. package/dist/chunk-NCCEDL2K.js.map +1 -0
  118. package/dist/{chunk-HNHCQ556.js → chunk-NR2SUJ3H.js} +2 -2
  119. package/dist/{chunk-AHLJSVRL.js → chunk-NW4TY6VC.js} +5 -7
  120. package/dist/chunk-NW4TY6VC.js.map +1 -0
  121. package/dist/{chunk-RKKORO4M.js → chunk-O742QBZZ.js} +10 -10
  122. package/dist/chunk-O742QBZZ.js.map +1 -0
  123. package/dist/{chunk-VN45YLWM.js → chunk-OHOKBMTM.js} +343 -132
  124. package/dist/chunk-OHOKBMTM.js.map +1 -0
  125. package/dist/{chunk-W3TVWF6N.js → chunk-OIBEJN5H.js} +2 -2
  126. package/dist/{chunk-QD724WDJ.js → chunk-OMYCSTXL.js} +4 -4
  127. package/dist/{chunk-Z45YRGFO.js → chunk-ONVD6GBY.js} +2 -2
  128. package/dist/{chunk-TAGFGKHP.js → chunk-OTHHO3KI.js} +7 -10
  129. package/dist/chunk-OTHHO3KI.js.map +1 -0
  130. package/dist/{chunk-3737A6EA.js → chunk-P2MR5UNE.js} +75 -18
  131. package/dist/chunk-P2MR5UNE.js.map +1 -0
  132. package/dist/chunk-PENPHA45.js +66 -0
  133. package/dist/chunk-PENPHA45.js.map +1 -0
  134. package/dist/{chunk-3FSX6LDG.js → chunk-PPCOKVFA.js} +8 -3
  135. package/dist/{chunk-3FSX6LDG.js.map → chunk-PPCOKVFA.js.map} +1 -1
  136. package/dist/{chunk-VOQW5LAM.js → chunk-QSIEL6TL.js} +102 -71
  137. package/dist/chunk-QSIEL6TL.js.map +1 -0
  138. package/dist/chunk-RFO4UXKQ.js +201 -0
  139. package/dist/chunk-RFO4UXKQ.js.map +1 -0
  140. package/dist/{chunk-KCQX65FU.js → chunk-RKCRPPNB.js} +3 -3
  141. package/dist/{chunk-7TSYBD3E.js → chunk-RSXQNFGO.js} +2 -2
  142. package/dist/{chunk-SZ2K3MHL.js → chunk-S56VYR4Q.js} +8 -11
  143. package/dist/{chunk-SZ2K3MHL.js.map → chunk-S56VYR4Q.js.map} +1 -1
  144. package/dist/{chunk-7NXHMW6Y.js → chunk-SYS46BL7.js} +2 -2
  145. package/dist/{chunk-55LKVALY.js → chunk-T7IR4N2S.js} +1 -3
  146. package/dist/chunk-T7IR4N2S.js.map +1 -0
  147. package/dist/{chunk-A67356IR.js → chunk-T7JGWTES.js} +33 -8
  148. package/dist/chunk-T7JGWTES.js.map +1 -0
  149. package/dist/{chunk-WHJKIZS7.js → chunk-TDSN2O2V.js} +27 -149
  150. package/dist/chunk-TDSN2O2V.js.map +1 -0
  151. package/dist/{chunk-747LRSOO.js → chunk-TMBSPLUG.js} +2 -2
  152. package/dist/{chunk-LWSJG3LI.js → chunk-TQPASLY4.js} +7 -3
  153. package/dist/chunk-TQPASLY4.js.map +1 -0
  154. package/dist/{chunk-WKPJXWKR.js → chunk-TX5MKAHA.js} +3 -3
  155. package/dist/{chunk-HFQ6LGIO.js → chunk-U27Y4DJZ.js} +12 -10
  156. package/dist/{chunk-HFQ6LGIO.js.map → chunk-U27Y4DJZ.js.map} +1 -1
  157. package/dist/{chunk-E6427JU2.js → chunk-VVSOPRUE.js} +18 -2
  158. package/dist/chunk-VVSOPRUE.js.map +1 -0
  159. package/dist/{chunk-7G6VDWXB.js → chunk-WVE6YKMX.js} +3 -3
  160. package/dist/chunk-WVE6YKMX.js.map +1 -0
  161. package/dist/{chunk-GLKDWWNO.js → chunk-YALD3SST.js} +16 -14
  162. package/dist/chunk-YALD3SST.js.map +1 -0
  163. package/dist/{chunk-NJDQ4YSV.js → chunk-YKXZHUOW.js} +4 -4
  164. package/dist/{chunk-VW6ZZGCG.js → chunk-ZLHHE5XZ.js} +3 -3
  165. package/dist/{chunk-FUHKW252.js → chunk-ZZXLB6AS.js} +2 -2
  166. package/dist/classified/index.js +5 -5
  167. package/dist/{classified-marker-FTOX7Q5L.js → classified-marker-NA6HUV33.js} +3 -3
  168. package/dist/collection-facade-VBM35WAH.js +45 -0
  169. package/dist/{computed-6G5M3UPH.js → computed-GSTLWSY5.js} +3 -3
  170. package/dist/consent/index.js +10 -10
  171. package/dist/cover/index.js +10 -3
  172. package/dist/custody/index.js +11 -11
  173. package/dist/{dead-filter-ENRIOQIE.js → dead-filter-UALP5DJX.js} +2 -2
  174. package/dist/debug/index.js +1 -1
  175. package/dist/{delegation-SSEPLXXO.js → delegation-JLNXM7KH.js} +24 -23
  176. package/dist/delegation-JLNXM7KH.js.map +1 -0
  177. package/dist/derivations/index.js +12 -12
  178. package/dist/derive-YUO3TQYN.js +22 -0
  179. package/dist/directory/index.js +10 -10
  180. package/dist/{dispatch-RE74SH6L.js → dispatch-4ZHLSFZQ.js} +5 -5
  181. package/dist/{dispatch-BDVGYC6X.js → dispatch-77CB75KB.js} +18 -18
  182. package/dist/{enclave-52VUXNRL.js → enclave-O4NOROCJ.js} +27 -9
  183. package/dist/executor-CZDXBXKE.js +29 -0
  184. package/dist/executor-DVJAWN3B.js +9 -0
  185. package/dist/executor-VRLG4TQJ.js +9 -0
  186. package/dist/export-accessible-UXSMG7AB.js +23 -0
  187. package/dist/extract-partition-TVY7AMKH.js +38 -0
  188. package/dist/{fanout-sidecar-DTBIDOWF.js → fanout-sidecar-NLQ7QAYW.js} +18 -27
  189. package/dist/fanout-sidecar-NLQ7QAYW.js.map +1 -0
  190. package/dist/find-WSARMJBW.js +11 -0
  191. package/dist/forget/index.js +9 -9
  192. package/dist/guards/index.js +7 -7
  193. package/dist/history/index.js +23 -20
  194. package/dist/history/index.js.map +1 -1
  195. package/dist/i18n/index.js +14 -14
  196. package/dist/index.d.ts +33 -15
  197. package/dist/index.js +187 -191
  198. package/dist/index.js.map +1 -1
  199. package/dist/indexing/index.js +2 -2
  200. package/dist/introspection/index.js +11 -11
  201. package/dist/issue-3JNJNPT3.js +19 -0
  202. package/dist/kernel/constants.d.ts +18 -0
  203. package/dist/kernel/enclave/crypto.d.ts +24 -4
  204. package/dist/kernel/enclave/index.d.ts +9 -2
  205. package/dist/kernel/enclave/record-aad.d.ts +131 -0
  206. package/dist/kernel/enclave/record-envelope.d.ts +76 -0
  207. package/dist/kernel/enclave/record-keys/envelope-body.d.ts +34 -2
  208. package/dist/kernel/enclave/record-keys/lifecycle.d.ts +22 -5
  209. package/dist/kernel/enclave/record-keys/record-codec.d.ts +47 -14
  210. package/dist/kernel/enclave/record-keys/rekey-blob.d.ts +88 -0
  211. package/dist/kernel/enclave/record-keys/rekey.d.ts +68 -0
  212. package/dist/kernel/enclave/record-keys/tombstone.d.ts +3 -2
  213. package/dist/kernel/errors.d.ts +71 -12
  214. package/dist/kernel/merge-authority.d.ts +25 -0
  215. package/dist/kernel/noydb.d.ts +27 -4
  216. package/dist/kernel/query/builder.d.ts +15 -2
  217. package/dist/kernel/query/join.d.ts +27 -0
  218. package/dist/kernel/sync-policy.d.ts +0 -2
  219. package/dist/kernel/tier-visibility.d.ts +15 -0
  220. package/dist/kernel/types.d.ts +145 -12
  221. package/dist/kernel/vault.d.ts +22 -18
  222. package/dist/kernel/via/index.d.ts +11 -2
  223. package/dist/{ledger-4WJL66BW.js → ledger-MVPNG5OS.js} +11 -11
  224. package/dist/liberate-4LOJOLDT.js +24 -0
  225. package/dist/{link-set-N4ZPV6E6.js → link-set-3POMQR3I.js} +11 -11
  226. package/dist/{managed-secret-OTHS64IF.js → managed-secret-IARIJJ7Q.js} +11 -3
  227. package/dist/materialized-views/index.js +22 -21
  228. package/dist/migrate-cek-XM2ETTZW.js +19 -0
  229. package/dist/migrate-cek-XM2ETTZW.js.map +1 -0
  230. package/dist/money/index.js +12 -8
  231. package/dist/noydb-IRILUDED.js +84 -0
  232. package/dist/overlay-views/index.js +4 -4
  233. package/dist/periods/index.js +22 -12
  234. package/dist/pod/index.js +75 -86
  235. package/dist/pod-handle-MELERCKU.js +41 -0
  236. package/dist/pod-handle-MELERCKU.js.map +1 -0
  237. package/dist/policy/index.js +11 -4
  238. package/dist/port/to/index.d.ts +4 -4
  239. package/dist/port/to/locator.d.ts +54 -8
  240. package/dist/port/with/i18n-strategy.d.ts +4 -1
  241. package/dist/port/with/lookup-strategy.d.ts +4 -1
  242. package/dist/port/with/merge-authority.d.ts +52 -0
  243. package/dist/port/with/service-bus.d.ts +0 -4
  244. package/dist/port/with/strategies.d.ts +2 -0
  245. package/dist/port/with/team-strategy.d.ts +5 -1
  246. package/dist/portability/index.js +8 -8
  247. package/dist/{post-register-ZAG2CAIY.js → post-register-Z5T7FY45.js} +6 -6
  248. package/dist/query/index.js +3 -3
  249. package/dist/reduce/index.js +4 -4
  250. package/dist/register-UZ37QPDB.js +32 -0
  251. package/dist/registry-ETJNA7PO.js +9 -0
  252. package/dist/registry-F7U6KSLX.js +9 -0
  253. package/dist/registry-L4ELKX6C.js +18 -0
  254. package/dist/registry-SDT5LIGO.js +19 -0
  255. package/dist/request-withdrawal-PVFEYX57.js +31 -0
  256. package/dist/{reveal-CMOJY4VO.js → reveal-DQ2E3QAZ.js} +6 -6
  257. package/dist/revoke-YXY6SHUH.js +24 -0
  258. package/dist/satellites/index.js +1 -1
  259. package/dist/schema-update/index.js +2 -2
  260. package/dist/sealed-record/index.js +20 -13
  261. package/dist/sealed-record/index.js.map +1 -1
  262. package/dist/search/index.js +4 -4
  263. package/dist/{seed-UK4QRIUN.js → seed-DZ4ORU5N.js} +19 -22
  264. package/dist/seed-DZ4ORU5N.js.map +1 -0
  265. package/dist/sequence/index.js +9 -9
  266. package/dist/session/index.js +10 -10
  267. package/dist/shadow/index.js +2 -2
  268. package/dist/share-link/index.js +1 -1
  269. package/dist/signer-Q7XQBMPA.js +25 -0
  270. package/dist/snapshots/index.js +10 -10
  271. package/dist/snapshots/index.js.map +1 -1
  272. package/dist/{stale-ZWXSOWJI.js → stale-NI7SAXAZ.js} +10 -10
  273. package/dist/storage-3VNGSHXS.js +23 -0
  274. package/dist/{store-coordination-provider-PB6QZ57W.js → store-coordination-provider-TYKNR3OU.js} +18 -12
  275. package/dist/store-coordination-provider-TYKNR3OU.js.map +1 -0
  276. package/dist/sync/index.js +11 -11
  277. package/dist/team/index.js +15 -14
  278. package/dist/tiers/index.js +11 -10
  279. package/dist/to/index.js +17 -9
  280. package/dist/to/index.js.map +1 -1
  281. package/dist/transactions/index.js +4 -4
  282. package/dist/{ulid-PTAIMDG4.js → ulid-VQW6ERQN.js} +2 -2
  283. package/dist/util/index.js +1 -1
  284. package/dist/vault-head/index.js +115 -0
  285. package/dist/vault-head/index.js.map +1 -0
  286. package/dist/{verify-RO5RTZOJ.js → verify-6J2YLKSO.js} +5 -5
  287. package/dist/via/lookup/handle.d.ts +4 -1
  288. package/dist/via/money/exact.d.ts +44 -0
  289. package/dist/via/money/index.d.ts +2 -0
  290. package/dist/via/money/normalize.d.ts +20 -0
  291. package/dist/walk-WRA7RAPY.js +21 -0
  292. package/dist/with-audit/guards/immutable-guard.d.ts +14 -0
  293. package/dist/with-audit/periods/active.d.ts +28 -1
  294. package/dist/with-audit/periods/index.d.ts +4 -2
  295. package/dist/with-audit/periods/periods.d.ts +161 -6
  296. package/dist/with-audit/periods/strategy.d.ts +14 -5
  297. package/dist/with-audit/periods/vault-facade.d.ts +89 -10
  298. package/dist/with-audit/periods/window.d.ts +10 -0
  299. package/dist/with-audit/sealed-record/index.d.ts +13 -0
  300. package/dist/with-audit/tiers/index.d.ts +17 -2
  301. package/dist/with-cargo/adopt-partition.d.ts +1 -1
  302. package/dist/with-cargo/extract-partition.d.ts +1 -1
  303. package/dist/with-cargo/index.d.ts +2 -2
  304. package/dist/with-commit/history/history.d.ts +26 -0
  305. package/dist/with-commit/history/index.d.ts +2 -1
  306. package/dist/with-commit/history/ledger/store.d.ts +7 -1
  307. package/dist/with-commit/history/strategy.d.ts +11 -1
  308. package/dist/with-commit/numbering/index.d.ts +0 -5
  309. package/dist/with-commit/vault-head/active.d.ts +2 -0
  310. package/dist/with-commit/vault-head/head.d.ts +28 -0
  311. package/dist/with-commit/vault-head/index.d.ts +10 -0
  312. package/dist/with-commit/vault-head/strategy.d.ts +127 -0
  313. package/dist/with-commit/vault-head/verify.d.ts +90 -0
  314. package/dist/with-formula/materialized-views/types.d.ts +52 -0
  315. package/dist/with-party/directory/cover/storage.d.ts +0 -8
  316. package/dist/with-party/directory/storage.d.ts +0 -11
  317. package/dist/with-party/directory/visibility.d.ts +0 -21
  318. package/dist/with-party/policy/storage.d.ts +0 -10
  319. package/dist/with-party/team/index.d.ts +1 -1
  320. package/dist/with-party/team/keyring.d.ts +149 -3
  321. package/dist/with-party/team/noydb-facade.d.ts +5 -1
  322. package/dist/with-party/team/roster-tag.d.ts +101 -0
  323. package/dist/with-party/team/tiers.d.ts +2 -1
  324. package/dist/with-pod/format.d.ts +10 -12
  325. package/dist/with-pod/index.d.ts +10 -10
  326. package/dist/with-pod/open.d.ts +2 -2
  327. package/dist/with-pod/pod-handle.d.ts +19 -0
  328. package/dist/with-pod/pod-store.d.ts +0 -8
  329. package/dist/with-pod/{bundle.d.ts → pod.d.ts} +26 -19
  330. package/dist/with-pod/ulid.d.ts +1 -1
  331. package/dist/with-shape/blobs/blob-set.d.ts +2 -2
  332. package/dist/with-shape/introspection/index.d.ts +1 -0
  333. package/dist/with-sync/engine.d.ts +54 -5
  334. package/dist/with-sync/strategy.d.ts +3 -0
  335. package/dist/withdraw-accessible-4JTDFRFZ.js +28 -0
  336. package/package.json +13 -5
  337. package/dist/api-WVY3H3YH.js +0 -20
  338. package/dist/backup-YYBE5RPC.js.map +0 -1
  339. package/dist/bundle-handle-JEUWU2SJ.js +0 -36
  340. package/dist/bundle-handle-JEUWU2SJ.js.map +0 -1
  341. package/dist/chunk-26JMGSSC.js.map +0 -1
  342. package/dist/chunk-3737A6EA.js.map +0 -1
  343. package/dist/chunk-4MC5JRRX.js.map +0 -1
  344. package/dist/chunk-52QYGZHH.js.map +0 -1
  345. package/dist/chunk-55LKVALY.js.map +0 -1
  346. package/dist/chunk-5PR33AC4.js.map +0 -1
  347. package/dist/chunk-66W5OOCX.js.map +0 -1
  348. package/dist/chunk-7G6VDWXB.js.map +0 -1
  349. package/dist/chunk-A67356IR.js.map +0 -1
  350. package/dist/chunk-AFHQATY4.js +0 -47
  351. package/dist/chunk-AFHQATY4.js.map +0 -1
  352. package/dist/chunk-AHLJSVRL.js.map +0 -1
  353. package/dist/chunk-C2OOEM57.js.map +0 -1
  354. package/dist/chunk-DIMKRG2E.js +0 -131
  355. package/dist/chunk-DIMKRG2E.js.map +0 -1
  356. package/dist/chunk-E6427JU2.js.map +0 -1
  357. package/dist/chunk-E7OBCBXS.js.map +0 -1
  358. package/dist/chunk-EDXAQ6JI.js.map +0 -1
  359. package/dist/chunk-EP7VPR7Y.js.map +0 -1
  360. package/dist/chunk-ERB6NDDW.js.map +0 -1
  361. package/dist/chunk-G5APARUV.js.map +0 -1
  362. package/dist/chunk-GASWQ3XG.js.map +0 -1
  363. package/dist/chunk-GLKDWWNO.js.map +0 -1
  364. package/dist/chunk-HNGSV2YC.js.map +0 -1
  365. package/dist/chunk-I4F6PKUK.js.map +0 -1
  366. package/dist/chunk-I4ZAO7F7.js.map +0 -1
  367. package/dist/chunk-I6SDX7WX.js.map +0 -1
  368. package/dist/chunk-JXIDGFKS.js.map +0 -1
  369. package/dist/chunk-LWSJG3LI.js.map +0 -1
  370. package/dist/chunk-MWKDOHEF.js.map +0 -1
  371. package/dist/chunk-MZ5ZFO2D.js.map +0 -1
  372. package/dist/chunk-NIVEDYJZ.js.map +0 -1
  373. package/dist/chunk-NWCGDAV6.js +0 -45
  374. package/dist/chunk-NWCGDAV6.js.map +0 -1
  375. package/dist/chunk-PJNTR2NV.js.map +0 -1
  376. package/dist/chunk-PRDRGL73.js.map +0 -1
  377. package/dist/chunk-PY7CI6L5.js.map +0 -1
  378. package/dist/chunk-RKKORO4M.js.map +0 -1
  379. package/dist/chunk-TAGFGKHP.js.map +0 -1
  380. package/dist/chunk-TDJPS3T2.js.map +0 -1
  381. package/dist/chunk-TOAIYQJR.js.map +0 -1
  382. package/dist/chunk-UHXCLPGC.js.map +0 -1
  383. package/dist/chunk-UIBGXRDD.js.map +0 -1
  384. package/dist/chunk-V5KYPBUR.js.map +0 -1
  385. package/dist/chunk-VCETL77O.js.map +0 -1
  386. package/dist/chunk-VN45YLWM.js.map +0 -1
  387. package/dist/chunk-VOQW5LAM.js.map +0 -1
  388. package/dist/chunk-VRA4Q7DA.js.map +0 -1
  389. package/dist/chunk-VV4NSB7P.js.map +0 -1
  390. package/dist/chunk-W5W6KHN2.js.map +0 -1
  391. package/dist/chunk-WHJKIZS7.js.map +0 -1
  392. package/dist/chunk-WYZ5MYUA.js.map +0 -1
  393. package/dist/chunk-ZJADGNYF.js.map +0 -1
  394. package/dist/chunk-ZNACADFG.js.map +0 -1
  395. package/dist/collection-facade-QN5ULWYC.js +0 -45
  396. package/dist/delegation-SSEPLXXO.js.map +0 -1
  397. package/dist/derive-6V3PIZF7.js +0 -22
  398. package/dist/executor-CYJQLKKI.js +0 -9
  399. package/dist/executor-FHHLXO4Y.js +0 -28
  400. package/dist/executor-S4QIKEHW.js +0 -9
  401. package/dist/export-accessible-PE5AYKZR.js +0 -23
  402. package/dist/extract-partition-X2L26O6A.js +0 -38
  403. package/dist/fanout-sidecar-DTBIDOWF.js.map +0 -1
  404. package/dist/find-RBBYKXI7.js +0 -11
  405. package/dist/issue-RNU55YOF.js +0 -19
  406. package/dist/liberate-PX4CAT5V.js +0 -24
  407. package/dist/noydb-YPSEGK32.js +0 -83
  408. package/dist/register-TMD6YRCX.js +0 -32
  409. package/dist/registry-CZVINVQH.js +0 -9
  410. package/dist/registry-FVLDWQKT.js +0 -18
  411. package/dist/registry-IKUR2MXD.js +0 -9
  412. package/dist/registry-JET4HBLY.js +0 -19
  413. package/dist/request-withdrawal-RH55LNZL.js +0 -31
  414. package/dist/revoke-R5TBYVA6.js +0 -24
  415. package/dist/seed-UK4QRIUN.js.map +0 -1
  416. package/dist/signer-AGALOXOO.js +0 -25
  417. package/dist/storage-N7LB275C.js +0 -23
  418. package/dist/store-coordination-provider-PB6QZ57W.js.map +0 -1
  419. package/dist/walk-OCUHCYJ6.js +0 -21
  420. package/dist/with-pod/bundle-handle.d.ts +0 -9
  421. package/dist/withdraw-accessible-QQNWM5BO.js +0 -28
  422. /package/dist/{api-WVY3H3YH.js.map → api-EYNT6KGS.js.map} +0 -0
  423. /package/dist/{chunk-35EBKWQU.js.map → chunk-2LFOMUEA.js.map} +0 -0
  424. /package/dist/{chunk-OF3L2SD6.js.map → chunk-32B7VCKU.js.map} +0 -0
  425. /package/dist/{chunk-MSWYQLMQ.js.map → chunk-3B6S6RSI.js.map} +0 -0
  426. /package/dist/{chunk-7F4DBNSP.js.map → chunk-3O72ZD2E.js.map} +0 -0
  427. /package/dist/{chunk-FNSMZQS4.js.map → chunk-3PMFMUFX.js.map} +0 -0
  428. /package/dist/{chunk-FAXZQ5UF.js.map → chunk-4RAS6HN6.js.map} +0 -0
  429. /package/dist/{chunk-VMCCGUQB.js.map → chunk-6JPGVL7X.js.map} +0 -0
  430. /package/dist/{chunk-WLYIROCJ.js.map → chunk-6YD5SYQS.js.map} +0 -0
  431. /package/dist/{chunk-YAWK6AWF.js.map → chunk-7KAE7CQ2.js.map} +0 -0
  432. /package/dist/{chunk-NKH7GSIH.js.map → chunk-AUPSEJ7O.js.map} +0 -0
  433. /package/dist/{chunk-CCZJJ4I2.js.map → chunk-B6IYATME.js.map} +0 -0
  434. /package/dist/{chunk-4UVDI4XE.js.map → chunk-CLAHBPOI.js.map} +0 -0
  435. /package/dist/{chunk-HVQGCKY4.js.map → chunk-D3R7Q4QK.js.map} +0 -0
  436. /package/dist/{chunk-P7OG2ETF.js.map → chunk-DXKLLKME.js.map} +0 -0
  437. /package/dist/{chunk-JIUVJ4M7.js.map → chunk-EKEIEJL6.js.map} +0 -0
  438. /package/dist/{chunk-DG27IUVI.js.map → chunk-FS7NTGCJ.js.map} +0 -0
  439. /package/dist/{chunk-HXGUIPQB.js.map → chunk-GQXFOAYZ.js.map} +0 -0
  440. /package/dist/{chunk-BTVYJWSN.js.map → chunk-GTHVPVAR.js.map} +0 -0
  441. /package/dist/{chunk-DMQCLZ4Z.js.map → chunk-GWO2IDAB.js.map} +0 -0
  442. /package/dist/{chunk-6HFM7EIT.js.map → chunk-H3G4I3PN.js.map} +0 -0
  443. /package/dist/{chunk-VJFMXYKP.js.map → chunk-HR5R5JOM.js.map} +0 -0
  444. /package/dist/{chunk-FDX7OWWI.js.map → chunk-HYYVT2KZ.js.map} +0 -0
  445. /package/dist/{chunk-JRCYZEHU.js.map → chunk-I6QKB7MT.js.map} +0 -0
  446. /package/dist/{chunk-KUDZVJKQ.js.map → chunk-IJ46VCWD.js.map} +0 -0
  447. /package/dist/{chunk-4HDYQL3J.js.map → chunk-INMHEMXX.js.map} +0 -0
  448. /package/dist/{chunk-AR2JDFAE.js.map → chunk-KV6JM2IA.js.map} +0 -0
  449. /package/dist/{chunk-PVU7LW5L.js.map → chunk-KX57HODD.js.map} +0 -0
  450. /package/dist/{chunk-CEJWMBXO.js.map → chunk-LXECF2ZR.js.map} +0 -0
  451. /package/dist/{chunk-7VHY5E3X.js.map → chunk-MSLPDFK2.js.map} +0 -0
  452. /package/dist/{chunk-HNHCQ556.js.map → chunk-NR2SUJ3H.js.map} +0 -0
  453. /package/dist/{chunk-W3TVWF6N.js.map → chunk-OIBEJN5H.js.map} +0 -0
  454. /package/dist/{chunk-QD724WDJ.js.map → chunk-OMYCSTXL.js.map} +0 -0
  455. /package/dist/{chunk-Z45YRGFO.js.map → chunk-ONVD6GBY.js.map} +0 -0
  456. /package/dist/{chunk-KCQX65FU.js.map → chunk-RKCRPPNB.js.map} +0 -0
  457. /package/dist/{chunk-7TSYBD3E.js.map → chunk-RSXQNFGO.js.map} +0 -0
  458. /package/dist/{chunk-7NXHMW6Y.js.map → chunk-SYS46BL7.js.map} +0 -0
  459. /package/dist/{chunk-747LRSOO.js.map → chunk-TMBSPLUG.js.map} +0 -0
  460. /package/dist/{chunk-WKPJXWKR.js.map → chunk-TX5MKAHA.js.map} +0 -0
  461. /package/dist/{chunk-NJDQ4YSV.js.map → chunk-YKXZHUOW.js.map} +0 -0
  462. /package/dist/{chunk-VW6ZZGCG.js.map → chunk-ZLHHE5XZ.js.map} +0 -0
  463. /package/dist/{chunk-FUHKW252.js.map → chunk-ZZXLB6AS.js.map} +0 -0
  464. /package/dist/{classified-marker-FTOX7Q5L.js.map → classified-marker-NA6HUV33.js.map} +0 -0
  465. /package/dist/{collection-facade-QN5ULWYC.js.map → collection-facade-VBM35WAH.js.map} +0 -0
  466. /package/dist/{computed-6G5M3UPH.js.map → computed-GSTLWSY5.js.map} +0 -0
  467. /package/dist/{dead-filter-ENRIOQIE.js.map → dead-filter-UALP5DJX.js.map} +0 -0
  468. /package/dist/{derive-6V3PIZF7.js.map → derive-YUO3TQYN.js.map} +0 -0
  469. /package/dist/{dispatch-RE74SH6L.js.map → dispatch-4ZHLSFZQ.js.map} +0 -0
  470. /package/dist/{dispatch-BDVGYC6X.js.map → dispatch-77CB75KB.js.map} +0 -0
  471. /package/dist/{enclave-52VUXNRL.js.map → enclave-O4NOROCJ.js.map} +0 -0
  472. /package/dist/{executor-CYJQLKKI.js.map → executor-CZDXBXKE.js.map} +0 -0
  473. /package/dist/{executor-FHHLXO4Y.js.map → executor-DVJAWN3B.js.map} +0 -0
  474. /package/dist/{executor-S4QIKEHW.js.map → executor-VRLG4TQJ.js.map} +0 -0
  475. /package/dist/{export-accessible-PE5AYKZR.js.map → export-accessible-UXSMG7AB.js.map} +0 -0
  476. /package/dist/{extract-partition-X2L26O6A.js.map → extract-partition-TVY7AMKH.js.map} +0 -0
  477. /package/dist/{find-RBBYKXI7.js.map → find-WSARMJBW.js.map} +0 -0
  478. /package/dist/{issue-RNU55YOF.js.map → issue-3JNJNPT3.js.map} +0 -0
  479. /package/dist/{ledger-4WJL66BW.js.map → ledger-MVPNG5OS.js.map} +0 -0
  480. /package/dist/{liberate-PX4CAT5V.js.map → liberate-4LOJOLDT.js.map} +0 -0
  481. /package/dist/{link-set-N4ZPV6E6.js.map → link-set-3POMQR3I.js.map} +0 -0
  482. /package/dist/{managed-secret-OTHS64IF.js.map → managed-secret-IARIJJ7Q.js.map} +0 -0
  483. /package/dist/{noydb-YPSEGK32.js.map → noydb-IRILUDED.js.map} +0 -0
  484. /package/dist/{post-register-ZAG2CAIY.js.map → post-register-Z5T7FY45.js.map} +0 -0
  485. /package/dist/{register-TMD6YRCX.js.map → register-UZ37QPDB.js.map} +0 -0
  486. /package/dist/{registry-CZVINVQH.js.map → registry-ETJNA7PO.js.map} +0 -0
  487. /package/dist/{registry-FVLDWQKT.js.map → registry-F7U6KSLX.js.map} +0 -0
  488. /package/dist/{registry-IKUR2MXD.js.map → registry-L4ELKX6C.js.map} +0 -0
  489. /package/dist/{registry-JET4HBLY.js.map → registry-SDT5LIGO.js.map} +0 -0
  490. /package/dist/{request-withdrawal-RH55LNZL.js.map → request-withdrawal-PVFEYX57.js.map} +0 -0
  491. /package/dist/{reveal-CMOJY4VO.js.map → reveal-DQ2E3QAZ.js.map} +0 -0
  492. /package/dist/{revoke-R5TBYVA6.js.map → revoke-YXY6SHUH.js.map} +0 -0
  493. /package/dist/{signer-AGALOXOO.js.map → signer-Q7XQBMPA.js.map} +0 -0
  494. /package/dist/{stale-ZWXSOWJI.js.map → stale-NI7SAXAZ.js.map} +0 -0
  495. /package/dist/{storage-N7LB275C.js.map → storage-3VNGSHXS.js.map} +0 -0
  496. /package/dist/{ulid-PTAIMDG4.js.map → ulid-VQW6ERQN.js.map} +0 -0
  497. /package/dist/{verify-RO5RTZOJ.js.map → verify-6J2YLKSO.js.map} +0 -0
  498. /package/dist/{walk-OCUHCYJ6.js.map → walk-WRA7RAPY.js.map} +0 -0
  499. /package/dist/{withdraw-accessible-QQNWM5BO.js.map → withdraw-accessible-4JTDFRFZ.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-PENPHA45.js";
5
6
  import {
6
7
  blindedEqual,
7
8
  openVdigPayload,
8
9
  sealVdigPayload
9
- } from "./chunk-HXGUIPQB.js";
10
+ } from "./chunk-GQXFOAYZ.js";
10
11
  import {
11
12
  dualReadSealedSlot,
12
13
  parseSealedSlot
13
- } from "./chunk-AR2JDFAE.js";
14
+ } from "./chunk-KV6JM2IA.js";
14
15
  import {
15
16
  mintBidxTag
16
- } from "./chunk-747LRSOO.js";
17
+ } from "./chunk-TMBSPLUG.js";
17
18
  import {
18
19
  VDIG_ITERATIONS,
19
20
  normalizeForVerify,
@@ -23,20 +24,22 @@ import {
23
24
  base64ToBuffer,
24
25
  bufferToBase64,
25
26
  decrypt,
27
+ decryptBytesWithAAD,
26
28
  deriveDeterministicKey,
27
29
  deriveSealedFieldKey,
28
30
  deriveSealedFieldKeyFromCek,
29
31
  encrypt,
32
+ encryptBytesWithAAD,
30
33
  encryptDeterministic,
31
34
  generateDEK,
32
35
  generateSalt,
33
36
  unwrapCek,
34
37
  wrapCek
35
- } from "./chunk-VCETL77O.js";
38
+ } from "./chunk-AU3AUJIZ.js";
36
39
  import {
37
40
  NOYDB_FORMAT_VERSION,
38
41
  SealedHandle
39
- } from "./chunk-W5W6KHN2.js";
42
+ } from "./chunk-IGNJOJEP.js";
40
43
  import {
41
44
  ClassifiedConfigError,
42
45
  ClassifiedRotationError,
@@ -45,7 +48,48 @@ import {
45
48
  SchemaValidationError,
46
49
  TamperedError,
47
50
  ValidationError
48
- } from "./chunk-HNGSV2YC.js";
51
+ } from "./chunk-CWM4GQD2.js";
52
+
53
+ // src/kernel/enclave/record-aad.ts
54
+ var SCHEME = "noydb-aad/2";
55
+ var encoder = new TextEncoder();
56
+ function buildRecordAad(identity) {
57
+ if (!Number.isFinite(identity.version)) {
58
+ throw new TypeError(
59
+ `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.`
60
+ );
61
+ }
62
+ const parts = [encoder.encode(SCHEME)];
63
+ const pushField = (value) => {
64
+ const bytes = encoder.encode(value);
65
+ const len = new Uint8Array(4);
66
+ new DataView(len.buffer).setUint32(0, bytes.length, false);
67
+ parts.push(len, bytes);
68
+ };
69
+ pushField(identity.collection);
70
+ pushField(identity.id);
71
+ pushField(String(identity.tier ?? 0));
72
+ parts.push(new Uint8Array([identity.by === void 0 ? 0 : 1]));
73
+ if (identity.by !== void 0) pushField(identity.by);
74
+ pushField(String(identity.version));
75
+ const total = parts.reduce((n, p) => n + p.length, 0);
76
+ const out = new Uint8Array(total);
77
+ let offset = 0;
78
+ for (const p of parts) {
79
+ out.set(p, offset);
80
+ offset += p.length;
81
+ }
82
+ return out;
83
+ }
84
+ function recordAadFor(ref, envelope) {
85
+ return buildRecordAad({
86
+ collection: ref.collection,
87
+ id: ref.id,
88
+ version: envelope._v,
89
+ tier: envelope._tier,
90
+ by: envelope._by
91
+ });
92
+ }
49
93
 
50
94
  // src/kernel/enclave/record-keys/lifecycle.ts
51
95
  async function resolveStableCek(deps, id) {
@@ -61,15 +105,17 @@ async function resolveStableCek(deps, id) {
61
105
  deps.cache?.set(id, fresh, 1);
62
106
  return fresh;
63
107
  }
64
- async function rewrapBodyToDek(envelope, fromDek, toDek) {
108
+ async function rewrapBodyToDek(from, to, envelope, fromDek, toDek) {
109
+ const openAad = buildRecordAad(from);
110
+ const sealAad = buildRecordAad(to);
65
111
  if (envelope._cek !== void 0) {
66
112
  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);
113
+ const plaintext2 = await decrypt(envelope._iv, envelope._data, cek, openAad);
114
+ const { iv: iv2, data: data2 } = await encrypt(plaintext2, cek, sealAad);
69
115
  return { _iv: iv2, _data: data2, _cek: await wrapCek(cek, toDek), cek };
70
116
  }
71
- const plaintext = await decrypt(envelope._iv, envelope._data, fromDek);
72
- const { iv, data } = await encrypt(plaintext, toDek);
117
+ const plaintext = await decrypt(envelope._iv, envelope._data, fromDek, openAad);
118
+ const { iv, data } = await encrypt(plaintext, toDek, sealAad);
73
119
  return { _iv: iv, _data: data, cek: null };
74
120
  }
75
121
  function applyRewrappedBody(envelope, body) {
@@ -84,15 +130,15 @@ function applyRewrappedBody(envelope, body) {
84
130
  }
85
131
  return next;
86
132
  }
87
- async function rewrapEnvelope(envelope, fromDek, toDek) {
88
- return applyRewrappedBody(envelope, await rewrapBodyToDek(envelope, fromDek, toDek));
133
+ async function rewrapEnvelope(identity, envelope, fromDek, toDek) {
134
+ return applyRewrappedBody(envelope, await rewrapBodyToDek(identity, identity, envelope, fromDek, toDek));
89
135
  }
90
- async function isRewrappedUnder(envelope, dek) {
136
+ async function isRewrappedUnder(identity, envelope, dek) {
91
137
  try {
92
138
  if (envelope._cek !== void 0) {
93
139
  await unwrapCek(envelope._cek, dek);
94
140
  } else {
95
- await decrypt(envelope._iv, envelope._data, dek);
141
+ await decrypt(envelope._iv, envelope._data, dek, buildRecordAad(identity));
96
142
  }
97
143
  return true;
98
144
  } catch {
@@ -100,6 +146,118 @@ async function isRewrappedUnder(envelope, dek) {
100
146
  }
101
147
  }
102
148
 
149
+ // src/kernel/enclave/record-keys/rekey.ts
150
+ async function rekeyEnvelopeToDek(ref, envelope, oldDek, newDek) {
151
+ const aad = recordAadFor(ref, envelope);
152
+ const { _bidx, ...carried } = envelope;
153
+ void _bidx;
154
+ if (envelope._cek !== void 0) {
155
+ const cek = await unwrapCek(envelope._cek, oldDek);
156
+ return { ...carried, _cek: await wrapCek(cek, newDek) };
157
+ }
158
+ const plaintext = await decrypt(envelope._iv, envelope._data, oldDek, aad);
159
+ const { iv, data } = await encrypt(plaintext, newDek, aad);
160
+ return { ...carried, _ts: (/* @__PURE__ */ new Date()).toISOString(), _iv: iv, _data: data };
161
+ }
162
+ async function rekeyEnvelopeIfNeeded(ref, envelope, oldDek, newDek) {
163
+ try {
164
+ return await rekeyEnvelopeToDek(ref, envelope, oldDek, newDek);
165
+ } catch (errUnderOld) {
166
+ try {
167
+ if (envelope._cek !== void 0) await unwrapCek(envelope._cek, newDek);
168
+ else await decrypt(envelope._iv, envelope._data, newDek, recordAadFor(ref, envelope));
169
+ return null;
170
+ } catch {
171
+ throw errUnderOld;
172
+ }
173
+ }
174
+ }
175
+
176
+ // src/kernel/enclave/record-keys/rekey-blob.ts
177
+ var BLOB_INDEX_COLLECTION = "_blob_index";
178
+ var BLOB_CHUNKS_COLLECTION = "_blob_chunks";
179
+ function chunkAad(eTag, index, chunkCount) {
180
+ return new TextEncoder().encode(`${eTag}:${index}:${chunkCount}`);
181
+ }
182
+ async function opensJson(ref, env, key) {
183
+ try {
184
+ return await decrypt(env._iv, env._data, key, recordAadFor(ref, env));
185
+ } catch {
186
+ return null;
187
+ }
188
+ }
189
+ async function rekeyBlobSet(adapter, vault, oldDek, newDek, otherDeks = []) {
190
+ let blobs = 0;
191
+ let chunks = 0;
192
+ let foreign = 0;
193
+ let alreadyMoved = 0;
194
+ let eTags;
195
+ try {
196
+ eTags = await adapter.list(vault, BLOB_INDEX_COLLECTION);
197
+ } catch {
198
+ return { blobs, chunks, foreign, alreadyMoved };
199
+ }
200
+ for (const eTag of eTags) {
201
+ const idxEnv = await adapter.get(vault, BLOB_INDEX_COLLECTION, eTag);
202
+ if (!idxEnv || !idxEnv._iv) continue;
203
+ const ref = { collection: BLOB_INDEX_COLLECTION, id: eTag };
204
+ const json = await opensJson(ref, idxEnv, oldDek);
205
+ if (json === null) {
206
+ if (await opensJson(ref, idxEnv, newDek) !== null) {
207
+ alreadyMoved++;
208
+ continue;
209
+ }
210
+ let claimed = false;
211
+ for (const key of otherDeks) {
212
+ if (await opensJson(ref, idxEnv, key) !== null) {
213
+ claimed = true;
214
+ break;
215
+ }
216
+ }
217
+ if (claimed) {
218
+ foreign++;
219
+ continue;
220
+ }
221
+ throw new Error(
222
+ `[noy-db] rotateKeys: blob index entry "${eTag}" opens under neither the retiring nor the new \`_blob\` DEK, nor any other key this keyring holds. Rotation stopped rather than leaving it unreadable and unreported.`
223
+ );
224
+ }
225
+ const blob = JSON.parse(json);
226
+ for (let i = 0; i < blob.chunkCount; i++) {
227
+ const id = `${eTag}_${i}`;
228
+ const chunkEnv = await adapter.get(vault, BLOB_CHUNKS_COLLECTION, id);
229
+ if (!chunkEnv || !chunkEnv._iv) continue;
230
+ const aad = chunkAad(eTag, i, blob.chunkCount);
231
+ let plain;
232
+ try {
233
+ plain = await decryptBytesWithAAD(chunkEnv._iv, chunkEnv._data, oldDek, aad);
234
+ } catch {
235
+ if (blob._cek !== void 0 || blob._cekPending !== void 0) continue;
236
+ try {
237
+ await decryptBytesWithAAD(chunkEnv._iv, chunkEnv._data, newDek, aad);
238
+ continue;
239
+ } catch {
240
+ throw new Error(
241
+ `[noy-db] rotateKeys: blob chunk "${id}" (${i + 1}/${blob.chunkCount} of eTag "${eTag}") opens under neither the retiring nor the new \`_blob\` DEK, and its blob holds no content CEK that could explain it. Rotation stopped rather than leaving it unreadable and unreported.`
242
+ );
243
+ }
244
+ }
245
+ const { iv: iv2, data: data2 } = await encryptBytesWithAAD(plain, newDek, aad);
246
+ await adapter.put(vault, BLOB_CHUNKS_COLLECTION, id, { ...chunkEnv, _iv: iv2, _data: data2 });
247
+ chunks++;
248
+ }
249
+ const rewrapped = {
250
+ ...blob,
251
+ ...blob._cek !== void 0 ? { _cek: await wrapCek(await unwrapCek(blob._cek, oldDek), newDek) } : {},
252
+ ...blob._cekPending !== void 0 ? { _cekPending: await wrapCek(await unwrapCek(blob._cekPending, oldDek), newDek) } : {}
253
+ };
254
+ const { iv, data } = await encrypt(JSON.stringify(rewrapped), newDek, recordAadFor(ref, idxEnv));
255
+ await adapter.put(vault, BLOB_INDEX_COLLECTION, eTag, { ...idxEnv, _iv: iv, _data: data });
256
+ blobs++;
257
+ }
258
+ return { blobs, chunks, foreign, alreadyMoved };
259
+ }
260
+
103
261
  // src/kernel/enclave/record-keys/sealed-slots.ts
104
262
  async function sealOneFieldWithDek(field, value, dek, keyMaterial) {
105
263
  const fieldKey = keyMaterial.cek !== void 0 ? await deriveSealedFieldKeyFromCek(keyMaterial.cek, keyMaterial.collection, field) : await deriveSealedFieldKey(dek, keyMaterial.collection, field);
@@ -175,22 +333,17 @@ function makeReservedEnvelopes(dekResolver, declaredPrefixes) {
175
333
  );
176
334
  }
177
335
  };
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
- };
336
+ const encryptForPrefix = async (ref, json, v) => {
337
+ assertPrefixed(ref.collection, "encrypt");
338
+ const dek = await dekResolver(ref.collection);
339
+ const identity = { ...ref, version: v };
340
+ const { iv, data } = await encrypt(json, dek, buildRecordAad(identity));
341
+ return buildRecordEnvelope(identity, { iv, data });
189
342
  };
190
- const decryptForPrefix = async (collection, env) => {
343
+ const decryptForPrefix = async (collection, id, env) => {
191
344
  assertPrefixed(collection, "decrypt");
192
345
  const dek = await dekResolver(collection);
193
- return decrypt(env._iv, env._data, dek);
346
+ return decrypt(env._iv, env._data, dek, recordAadFor({ collection, id }, env));
194
347
  };
195
348
  return { encrypt: encryptForPrefix, decrypt: decryptForPrefix };
196
349
  };
@@ -320,30 +473,12 @@ var RecordCodec = class _RecordCodec {
320
473
  * parts. Pure, no crypto. Each call stamps its own `_ts` — provenance carries
321
474
  * a SEPARATE timestamp (computed by the caller), so the two never share one.
322
475
  */
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
- };
476
+ static buildEnvelope(identity, p) {
477
+ return buildRecordEnvelope(identity, p);
335
478
  }
336
479
  /** 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
- };
480
+ static buildPlaintextEnvelope(identity, p) {
481
+ return buildRecordEnvelope(identity, { ...p, iv: "" });
347
482
  }
348
483
  // ──────────────────────────────────────────────────────────────────────
349
484
  // Write path
@@ -356,22 +491,20 @@ var RecordCodec = class _RecordCodec {
356
491
  * (see {@link encryptRecord}). Rejects `_`-prefixed record fields, which
357
492
  * would collide with the reserved metadata namespace.
358
493
  */
359
- buildDebugEnvelope(record, version, source, sourceTs) {
494
+ buildDebugEnvelope(id, record, version, source, sourceTs) {
360
495
  const rec = record;
361
496
  for (const key of Object.keys(rec)) {
362
497
  if (key.startsWith("_")) throw new DebugReservedFieldError(this.ctx.name, key);
363
498
  }
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
- };
499
+ const base = buildRecordEnvelope(
500
+ { collection: this.ctx.name, id, by: this.ctx.actor, version },
501
+ {
502
+ iv: "",
503
+ data: "",
504
+ ...this.ctx.provenance && source !== void 0 ? { provenance: { source, sourceTs: sourceTs ?? (/* @__PURE__ */ new Date()).toISOString() } } : {}
505
+ }
506
+ );
507
+ return { ...base, _debug: NOYDB_FORMAT_VERSION, ...rec };
375
508
  }
376
509
  /**
377
510
  * Encrypt a JSON body into an envelope.
@@ -382,24 +515,56 @@ var RecordCodec = class _RecordCodec {
382
515
  * path encrypts the body directly under the collection DEK — byte-identical
383
516
  * to pre-CEK behaviour, so non-adopting collections pay nothing.
384
517
  */
385
- async encryptJsonString(json, version, cek, source, sourceTs) {
386
- const by = this.ctx.actor;
518
+ /**
519
+ * `ref` is the identity the envelope is sealed against, and it is **the
520
+ * location the bytes are stored at** — not necessarily this codec's own
521
+ * collection (#1051).
522
+ *
523
+ * That distinction was discovered here rather than assumed. Several callers
524
+ * put the result somewhere else entirely: search's vector sidecar lands in
525
+ * `_vec` under `encodeVecId(name, id)`, the lexical index under `_ft/<name>`,
526
+ * indexing's entries under a synthetic `idxId`. A codec that supplied
527
+ * `this.ctx.name` for those would seal them against a collection they are not
528
+ * in, and once AAD binds identity every one of them would fail to verify.
529
+ *
530
+ * ⚠️ **`_history` is the open case, and it is #1041's to settle.** Snapshots
531
+ * are produced with the LIVE record's identity here and then re-homed by
532
+ * `saveHistory` into `_history/<historyId(collection,id,_v)>`. Both readings
533
+ * are defensible — bind where it lives, or bind what it is a copy of — and
534
+ * the choice must be made before AAD is switched on, not inferred from this
535
+ * migration.
536
+ */
537
+ async encryptJsonString(ref, json, version, cek, source, sourceTs) {
538
+ const identity = { ...ref, version, by: this.ctx.actor };
387
539
  const provenance = this.ctx.provenance && source !== void 0 ? { source, sourceTs: sourceTs ?? (/* @__PURE__ */ new Date()).toISOString() } : void 0;
388
540
  if (!this.ctx.storeCiphertext) {
389
- return _RecordCodec.buildPlaintextEnvelope({ version, data: json, by, provenance });
541
+ return _RecordCodec.buildPlaintextEnvelope(identity, { data: json, provenance });
390
542
  }
391
543
  const dek = await this.ctx.getDEK();
544
+ const aad = buildRecordAad(identity);
392
545
  if (cek !== void 0) {
393
- const { iv: iv2, data: data2 } = await encrypt(json, cek);
546
+ const { iv: iv2, data: data2 } = await encrypt(json, cek, aad);
394
547
  const wrapped = await wrapCek(cek, dek);
395
- return _RecordCodec.buildEnvelope({ version, iv: iv2, data: data2, by, cek: wrapped, provenance });
548
+ return _RecordCodec.buildEnvelope(identity, { iv: iv2, data: data2, cek: wrapped, provenance });
396
549
  }
397
- const { iv, data } = await encrypt(json, dek);
398
- return _RecordCodec.buildEnvelope({ version, iv, data, by, provenance });
550
+ const { iv, data } = await encrypt(json, dek, aad);
551
+ return _RecordCodec.buildEnvelope(identity, { iv, data, provenance });
399
552
  }
400
- async encryptRecord(record, version, cek, source, sourceTs, vdig, id) {
553
+ /**
554
+ * `ref` is FIRST and required (#1051). It was previously a trailing optional
555
+ * `id?: string`, which TypeScript cannot promote to required because it sits
556
+ * after other optionals — so the migration would have needed an `id ?? ''`
557
+ * fallback. That is exactly the silent default this issue exists to remove:
558
+ * once identity is bound into the AEAD, every record written with an empty id
559
+ * binds to the SAME identity and becomes interchangeable with the others.
560
+ * An object, not a bare string, so a swap with `version`/`source` cannot
561
+ * compile on the hottest write path. Carries the collection too — see
562
+ * {@link encryptJsonString} for why the codec must not assume its own.
563
+ */
564
+ async encryptRecord(ref, record, version, cek, source, sourceTs, vdig) {
565
+ const id = ref.id;
401
566
  if (!this.ctx.storeCiphertext && this.ctx.debugPlaintext && !this.ctx.name.startsWith("_")) {
402
- return this.buildDebugEnvelope(record, version, source, sourceTs);
567
+ return this.buildDebugEnvelope(id, record, version, source, sourceTs);
403
568
  }
404
569
  if (this.ctx.storeCiphertext) {
405
570
  const declared = this.ctx.vdigFields;
@@ -426,9 +591,9 @@ var RecordCodec = class _RecordCodec {
426
591
  let openRecord = record;
427
592
  let sealed;
428
593
  if (this.ctx.storeCiphertext && this.ctx.via?.hasAtRestHooks) {
429
- if (id === void 0) {
594
+ if (id === "") {
430
595
  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.`
596
+ `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
597
  );
433
598
  }
434
599
  const src = record;
@@ -436,7 +601,7 @@ var RecordCodec = class _RecordCodec {
436
601
  openRecord = result.record;
437
602
  if (result.sealed !== void 0) {
438
603
  sealed = {};
439
- for (const [field, ref] of Object.entries(result.sealed)) sealed[field] = `${ref.iv}:${ref.data}`;
604
+ for (const [field, ref2] of Object.entries(result.sealed)) sealed[field] = `${ref2.iv}:${ref2.data}`;
440
605
  }
441
606
  } else if (this.ctx.storeCiphertext && this.ctx.sensitiveFields.size > 0) {
442
607
  const src = record;
@@ -501,7 +666,7 @@ var RecordCodec = class _RecordCodec {
501
666
  if (Object.keys(out).length > 0) vdigOut = out;
502
667
  if (Object.keys(bidxOut).length > 0) bidxOutMap = bidxOut;
503
668
  }
504
- const base = await this.encryptJsonString(JSON.stringify(openRecord), version, cek, source, sourceTs);
669
+ const base = await this.encryptJsonString(ref, JSON.stringify(openRecord), version, cek, source, sourceTs);
505
670
  const withSealed = sealed ? { ...base, _sealed: sealed } : base;
506
671
  const withVdig = vdigOut ? { ...withSealed, _vdig: vdigOut } : withSealed;
507
672
  const withBidx = bidxOutMap ? { ...withVdig, _bidx: bidxOutMap } : withVdig;
@@ -556,7 +721,15 @@ var RecordCodec = class _RecordCodec {
556
721
  * The optional `id` lets reads populate the CEK cache; it is omitted by
557
722
  * callers (history, conflict merge) that have only the envelope.
558
723
  */
559
- async decryptJsonString(envelope, id) {
724
+ /**
725
+ * `ref` must be the SAME identity the writer sealed against — which is the
726
+ * storage address, not necessarily this codec's own collection. Search's
727
+ * vector sidecar lives in `_vec`, its lexical index in `_ft`; passing
728
+ * `this.ctx.name` for those would recompute the wrong AAD and fail to open a
729
+ * perfectly good record (#1041).
730
+ */
731
+ async decryptJsonString(ref, envelope) {
732
+ const id = ref.id;
560
733
  if (isTombstone(envelope, this.ctx.storeCiphertext) || isDeleteMarker(envelope)) return null;
561
734
  if (!this.ctx.storeCiphertext) {
562
735
  if (envelope._debug !== void 0) {
@@ -568,10 +741,11 @@ var RecordCodec = class _RecordCodec {
568
741
  }
569
742
  return envelope._data === "" ? null : envelope._data;
570
743
  }
744
+ const aad = recordAadFor(ref, envelope);
571
745
  const cek = await this.resolveEnvelopeCek(envelope, id);
572
- if (cek !== void 0) return decrypt(envelope._iv, envelope._data, cek);
746
+ if (cek !== void 0) return decrypt(envelope._iv, envelope._data, cek, aad);
573
747
  const dek = await this.ctx.getDEK();
574
- return decrypt(envelope._iv, envelope._data, dek);
748
+ return decrypt(envelope._iv, envelope._data, dek, aad);
575
749
  }
576
750
  /**
577
751
  * Unseal a single `_sealed[field]` slot to its plaintext value: derive the
@@ -695,7 +869,7 @@ var RecordCodec = class _RecordCodec {
695
869
  */
696
870
  async applySealedSlots(record, sealed, cek, opts = {}) {
697
871
  if (this.ctx.via?.hasAtRestHooks) {
698
- if (opts.id === void 0) {
872
+ if (opts.id === void 0 || opts.id === "") {
699
873
  throw new Error(
700
874
  `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
875
  );
@@ -745,15 +919,17 @@ var RecordCodec = class _RecordCodec {
745
919
  * output-recompute path, not the public per-record read surface schema
746
920
  * validation guards.
747
921
  */
748
- async decryptRecordAtDek(envelope, dek, id) {
922
+ async decryptRecordAtDek(ref, envelope, dek) {
923
+ const id = ref.id;
749
924
  if (isTombstone(envelope, this.ctx.storeCiphertext) || isDeleteMarker(envelope)) return null;
750
925
  let plaintext;
751
926
  let cek;
927
+ const aad = recordAadFor(ref, envelope);
752
928
  if (envelope._cek !== void 0) {
753
929
  cek = await unwrapCek(envelope._cek, dek);
754
- plaintext = await decrypt(envelope._iv, envelope._data, cek);
930
+ plaintext = await decrypt(envelope._iv, envelope._data, cek, aad);
755
931
  } else {
756
- plaintext = await decrypt(envelope._iv, envelope._data, dek);
932
+ plaintext = await decrypt(envelope._iv, envelope._data, dek, aad);
757
933
  }
758
934
  let record = JSON.parse(plaintext);
759
935
  if (envelope._sealed !== void 0 && this.ctx.storeCiphertext) {
@@ -776,8 +952,8 @@ var RecordCodec = class _RecordCodec {
776
952
  * that may predate a schema change, so validating it would be a
777
953
  * false positive. Every non-history read leaves this flag `false`.
778
954
  */
779
- async decryptRecord(envelope, opts = {}) {
780
- const json = await this.decryptJsonString(envelope, opts.id);
955
+ async decryptRecord(ref, envelope, opts = {}) {
956
+ const json = await this.decryptJsonString(ref, envelope);
781
957
  if (json === null) return null;
782
958
  let parsed = JSON.parse(json);
783
959
  if (this.ctx.crdtMode && parsed !== null && typeof parsed === "object" && "_crdt" in parsed) {
@@ -785,9 +961,9 @@ var RecordCodec = class _RecordCodec {
785
961
  }
786
962
  let record = parsed;
787
963
  if (envelope._sealed !== void 0 && this.ctx.storeCiphertext) {
788
- const sealedCek = await this.resolveEnvelopeCek(envelope, opts.id);
964
+ const sealedCek = await this.resolveEnvelopeCek(envelope, ref.id);
789
965
  record = await this.applySealedSlots(record, envelope._sealed, sealedCek, {
790
- ...opts.id !== void 0 ? { id: opts.id } : {},
966
+ id: ref.id,
791
967
  ...opts.sealedAsHandles !== void 0 ? { sealedAsHandles: opts.sealedAsHandles } : {}
792
968
  });
793
969
  }
@@ -841,16 +1017,16 @@ async function sealRecordToHost(ctx, collection, id, hostSealer, opts) {
841
1017
  };
842
1018
  const envelopeKey = `${collection}/${id}/${hint.pid}`;
843
1019
  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
- };
1020
+ const env = buildRecordEnvelope(
1021
+ { collection: SEALED_CEK_NS, id: envelopeKey, version: (prior?._v ?? 0) + 1 },
1022
+ {
1023
+ // AES-GCM bypassed the sealing layer is the security boundary, exactly
1024
+ // like the managed-secret `_meta/sealed-secret` envelope.
1025
+ iv: "",
1026
+ data: JSON.stringify(delivery),
1027
+ ...ctx.actor ? { by: ctx.actor } : {}
1028
+ }
1029
+ );
854
1030
  await ctx.adapter.put(ctx.vault, SEALED_CEK_NS, envelopeKey, env);
855
1031
  return { pid: hint.pid, envelopeKey };
856
1032
  }
@@ -868,9 +1044,26 @@ async function rotateRecordCek(ctx, collection, id) {
868
1044
  }
869
1045
  const dek = await ctx.getDEK(collection);
870
1046
  const oldCek = await unwrapCek(live._cek, dek);
871
- const json = await decrypt(live._iv, live._data, oldCek);
1047
+ const openAad = recordAadFor({ collection, id }, live);
1048
+ const json = await decrypt(live._iv, live._data, oldCek, openAad);
1049
+ const rotatedIdentity = {
1050
+ // A CEK rotation DOES bump `_v` (asserted in `record-scoped-cek-sealing`:
1051
+ // "the live envelope was re-keyed — new `_cek`, bumped `_v`"), so it seals
1052
+ // at the new version, not the one it just opened.
1053
+ //
1054
+ // ⚠️ Do not confuse this with `rekeyEnvelopeToDek`, the DEK-rotation helper,
1055
+ // which PRESERVES `_v` (#1074) because it re-keys a record without writing
1056
+ // one. Two rotations, opposite answers — and with `_v` bound (#1093) getting
1057
+ // it backwards no longer produces a wrong number, it produces an
1058
+ // unreadable record.
1059
+ collection,
1060
+ id,
1061
+ version: live._v + 1,
1062
+ ...live._tier !== void 0 ? { tier: live._tier } : {},
1063
+ ...ctx.actor ? { by: ctx.actor } : live._by !== void 0 ? { by: live._by } : {}
1064
+ };
872
1065
  const newCek = await generateDEK();
873
- const { iv, data } = await encrypt(json, newCek);
1066
+ const { iv, data } = await encrypt(json, newCek, buildRecordAad(rotatedIdentity));
874
1067
  let sealedOut;
875
1068
  if (live._sealed !== void 0) {
876
1069
  const out = {};
@@ -890,30 +1083,27 @@ async function rotateRecordCek(ctx, collection, id) {
890
1083
  }
891
1084
  vdigOut = out;
892
1085
  }
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
- };
1086
+ const env = buildRecordEnvelope(rotatedIdentity, {
1087
+ iv,
1088
+ data,
1089
+ cek: await wrapCek(newCek, dek),
1090
+ extra: {
1091
+ ...live._det !== void 0 ? { _det: live._det } : {},
1092
+ // `_bidx` (equality-index tag) is DEK-rooted and CEK-independent, so it is
1093
+ // carried forward VERBATIM not recomputed — unlike `_vdig`/`_sealed`
1094
+ // below, which are CEK-bound and must be re-sealed under the new CEK.
1095
+ // Dropping this line would silently orphan the equality index on rotation
1096
+ // (the #306 Slice-A data-loss bug, replayed on the index).
1097
+ ...live._bidx !== void 0 ? { _bidx: live._bidx } : {},
1098
+ // Re-encrypt sealed (`sensitive`) fields under the new CEK. Sealed
1099
+ // keys derive off the per-record CEK, so the rotated record's old CEK is
1100
+ // destroyed here carrying the old `_sealed` slots forward verbatim would
1101
+ // orphan them (unreadable under the new CEK). `sealedOut` holds the slots
1102
+ // dual-read from the old CEK (or the legacy DEK) and re-sealed under newCek.
1103
+ ...sealedOut !== void 0 ? { _sealed: sealedOut } : {},
1104
+ ...vdigOut !== void 0 ? { _vdig: vdigOut } : {}
1105
+ }
1106
+ });
917
1107
  await ctx.adapter.put(ctx.vault, collection, id, env);
918
1108
  await ctx.invalidateRecordCaches(collection, id);
919
1109
  const prefix = `${collection}/${id}/`;
@@ -957,7 +1147,7 @@ async function findByDet(ctx, field, value) {
957
1147
  const env = await ctx.adapter.get(ctx.vault, ctx.name, id);
958
1148
  if (!env || !env._det || (env._tier ?? 0) > 0) continue;
959
1149
  if (env._det[field] === target || env._det[field] === legacyTarget) {
960
- return ctx.codec.decryptRecord(env, { id });
1150
+ return ctx.codec.decryptRecord({ collection: ctx.name, id }, env);
961
1151
  }
962
1152
  }
963
1153
  return null;
@@ -971,7 +1161,7 @@ async function queryByDet(ctx, field, value) {
971
1161
  const env = await ctx.adapter.get(ctx.vault, ctx.name, id);
972
1162
  if (!env || !env._det || (env._tier ?? 0) > 0) continue;
973
1163
  if (env._det[field] === target || env._det[field] === legacyTarget) {
974
- const rec = await ctx.codec.decryptRecord(env, { id });
1164
+ const rec = await ctx.codec.decryptRecord({ collection: ctx.name, id }, env);
975
1165
  if (rec !== null) matches.push(rec);
976
1166
  }
977
1167
  }
@@ -979,23 +1169,25 @@ async function queryByDet(ctx, field, value) {
979
1169
  }
980
1170
 
981
1171
  // src/kernel/enclave/record-keys/envelope-body.ts
982
- async function openEnvelopeJson(env, key, opts) {
1172
+ async function openEnvelopeJson(ref, env, key, opts) {
983
1173
  if (opts?.encrypted === false) return env._data;
1174
+ const aad = recordAadFor(ref, env);
984
1175
  if (env._cek !== void 0) {
985
1176
  const cek = await unwrapCek(env._cek, key);
986
- return decrypt(env._iv, env._data, cek);
1177
+ return decrypt(env._iv, env._data, cek, aad);
987
1178
  }
988
- return decrypt(env._iv, env._data, key);
1179
+ return decrypt(env._iv, env._data, key, aad);
989
1180
  }
990
- async function writeEnvelopeBody(json, key, opts) {
1181
+ async function writeEnvelopeBody(identity, json, key, opts) {
991
1182
  if (opts?.encrypted === false) return { _iv: "", _data: json };
1183
+ const aad = buildRecordAad(identity);
992
1184
  if (opts?.perRecordKey === true) {
993
1185
  const cek = await generateDEK();
994
- const { iv: iv2, data: data2 } = await encrypt(json, cek);
1186
+ const { iv: iv2, data: data2 } = await encrypt(json, cek, aad);
995
1187
  const wrapped = await wrapCek(cek, key);
996
1188
  return { _iv: iv2, _data: data2, _cek: wrapped };
997
1189
  }
998
- const { iv, data } = await encrypt(json, key);
1190
+ const { iv, data } = await encrypt(json, key, aad);
999
1191
  return { _iv: iv, _data: data };
1000
1192
  }
1001
1193
  function envelopeBodySize(env) {
@@ -1018,6 +1210,18 @@ function envelopeBodyForHash(env) {
1018
1210
  if (env._bidx !== void 0) segments.push(mapPart("_bidx", env._bidx));
1019
1211
  return `{${segments.join(",")}}`;
1020
1212
  }
1213
+ function hasSealedBody(env) {
1214
+ return env._iv !== "";
1215
+ }
1216
+ async function verifyRecordIdentity(ref, env, key) {
1217
+ if (!hasSealedBody(env)) return true;
1218
+ try {
1219
+ await openEnvelopeJson(ref, env, key);
1220
+ return true;
1221
+ } catch {
1222
+ return false;
1223
+ }
1224
+ }
1021
1225
 
1022
1226
  // src/kernel/enclave/broker/proof.ts
1023
1227
  var subtle2 = globalThis.crypto.subtle;
@@ -1103,11 +1307,16 @@ async function verifyBrokerProof(args) {
1103
1307
  }
1104
1308
 
1105
1309
  export {
1310
+ buildRecordAad,
1311
+ recordAadFor,
1106
1312
  resolveStableCek,
1107
1313
  rewrapBodyToDek,
1108
1314
  applyRewrappedBody,
1109
1315
  rewrapEnvelope,
1110
1316
  isRewrappedUnder,
1317
+ rekeyEnvelopeToDek,
1318
+ rekeyEnvelopeIfNeeded,
1319
+ rekeyBlobSet,
1111
1320
  makeReservedEnvelopes,
1112
1321
  validateSchemaInput,
1113
1322
  validateSchemaOutput,
@@ -1123,10 +1332,12 @@ export {
1123
1332
  envelopeBodySize,
1124
1333
  hasPerRecordKey,
1125
1334
  envelopeBodyForHash,
1335
+ hasSealedBody,
1336
+ verifyRecordIdentity,
1126
1337
  deriveBrokerProofBits,
1127
1338
  deriveBrokerProofKey,
1128
1339
  computeBrokerProof,
1129
1340
  issueChallenge,
1130
1341
  verifyBrokerProof
1131
1342
  };
1132
- //# sourceMappingURL=chunk-VN45YLWM.js.map
1343
+ //# sourceMappingURL=chunk-OHOKBMTM.js.map