@noy-db/hub 0.2.0-pre.16 → 0.2.0-pre.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/dist/aggregate/index.cjs.map +1 -1
  2. package/dist/aggregate/index.d.cts +3 -2
  3. package/dist/aggregate/index.d.ts +3 -2
  4. package/dist/aggregate/index.js +4 -4
  5. package/dist/attestation/index.cjs.map +1 -1
  6. package/dist/attestation/index.d.cts +5 -3
  7. package/dist/attestation/index.d.ts +5 -3
  8. package/dist/attestation/index.js +6 -6
  9. package/dist/blobs/index.cjs +226 -11
  10. package/dist/blobs/index.cjs.map +1 -1
  11. package/dist/blobs/index.d.cts +6 -4
  12. package/dist/blobs/index.d.ts +6 -4
  13. package/dist/blobs/index.js +6 -5
  14. package/dist/blobs/index.js.map +1 -1
  15. package/dist/bundle/index.cjs +1087 -95
  16. package/dist/bundle/index.cjs.map +1 -1
  17. package/dist/bundle/index.d.cts +7 -5
  18. package/dist/bundle/index.d.ts +7 -5
  19. package/dist/bundle/index.js +21 -10
  20. package/dist/bundle/index.js.map +1 -1
  21. package/dist/{chunk-G4SCICH5.js → chunk-2FU2FTXD.js} +2 -2
  22. package/dist/{chunk-JD3OZAI4.js → chunk-3G3W65EQ.js} +2 -2
  23. package/dist/{chunk-XWH4MXIU.js → chunk-5AXTH4QZ.js} +2 -2
  24. package/dist/{chunk-4TBBMHVC.js → chunk-5LIROIDM.js} +2 -2
  25. package/dist/{chunk-L2BNJ6HM.js → chunk-7H2GEJ3O.js} +3 -3
  26. package/dist/{chunk-GNI5STXQ.js → chunk-AEIKD3PP.js} +52 -38
  27. package/dist/chunk-AEIKD3PP.js.map +1 -0
  28. package/dist/{chunk-QSUK7YWK.js → chunk-BH3X5L6A.js} +4 -4
  29. package/dist/{chunk-BQ65SS5A.js → chunk-BJSLBUJ7.js} +2 -2
  30. package/dist/{chunk-FFXM3ZIF.js → chunk-BL5GYANC.js} +3 -3
  31. package/dist/{chunk-6H2ZUNR7.js → chunk-BSZOCSDZ.js} +4 -4
  32. package/dist/{chunk-ZNQYHJXX.js → chunk-C3HYQPV4.js} +2 -2
  33. package/dist/{chunk-E2CDVKMH.js → chunk-CD2AVTEM.js} +5 -5
  34. package/dist/{chunk-667MB6AH.js → chunk-D77ZQSQQ.js} +769 -131
  35. package/dist/chunk-D77ZQSQQ.js.map +1 -0
  36. package/dist/{chunk-BR3AMFGS.js → chunk-DWEBTE2W.js} +5 -5
  37. package/dist/{chunk-Z4DO7YSI.js → chunk-DYYYUW5D.js} +2 -2
  38. package/dist/{chunk-SCJPI4Z5.js → chunk-E77UKJYL.js} +5 -5
  39. package/dist/{chunk-OMAMZKKD.js → chunk-F4G63NTZ.js} +2 -2
  40. package/dist/{chunk-TKIY625R.js → chunk-FEJDVE3Z.js} +2 -2
  41. package/dist/{chunk-7Z7KSVA5.js → chunk-GP3SDSH2.js} +2 -2
  42. package/dist/{chunk-IQLVUT37.js → chunk-H2MRGONI.js} +2 -2
  43. package/dist/{chunk-DUREQF5W.js → chunk-HGVSHKZW.js} +8 -5
  44. package/dist/chunk-HGVSHKZW.js.map +1 -0
  45. package/dist/chunk-I5IUYN7B.js +125 -0
  46. package/dist/chunk-I5IUYN7B.js.map +1 -0
  47. package/dist/{chunk-CJORTUJ2.js → chunk-J7RWBXFY.js} +2 -2
  48. package/dist/{chunk-AAVWKNZW.js → chunk-JDWE6JMX.js} +2 -2
  49. package/dist/{chunk-XL35NSEN.js → chunk-KCEHMDZF.js} +3 -3
  50. package/dist/{chunk-TS26M2SB.js → chunk-M476FOQ7.js} +2 -2
  51. package/dist/{chunk-F4OJZIWQ.js → chunk-NBBMMJ2H.js} +4 -4
  52. package/dist/{chunk-CZI2A4MQ.js → chunk-NYSYPFXJ.js} +3 -3
  53. package/dist/{chunk-OQSRJG6A.js → chunk-PDULVIBY.js} +2 -2
  54. package/dist/{chunk-Z6FNBOTC.js → chunk-PDVP3C2I.js} +1 -1
  55. package/dist/{chunk-Z6FNBOTC.js.map → chunk-PDVP3C2I.js.map} +1 -1
  56. package/dist/{chunk-DLZ2ONOD.js → chunk-QHM6XEAH.js} +6 -6
  57. package/dist/{chunk-HBXJ37ZY.js → chunk-QO6RGLLD.js} +4 -4
  58. package/dist/{chunk-7BQ4QWYX.js → chunk-ROPJVUG3.js} +23 -6
  59. package/dist/chunk-ROPJVUG3.js.map +1 -0
  60. package/dist/{chunk-42FEUPZQ.js → chunk-ROVO6NPJ.js} +2 -2
  61. package/dist/{chunk-6RR3MNMG.js → chunk-SHX5QBCI.js} +3 -3
  62. package/dist/{chunk-F3BPIPLS.js → chunk-SISBMAPO.js} +1 -1
  63. package/dist/chunk-SISBMAPO.js.map +1 -0
  64. package/dist/{chunk-3YWP3WBP.js → chunk-SNMJ7SB3.js} +5 -5
  65. package/dist/{chunk-IXBIFDEW.js → chunk-TIDXB5DF.js} +4 -4
  66. package/dist/chunk-U5QCMH3W.js +151 -0
  67. package/dist/chunk-U5QCMH3W.js.map +1 -0
  68. package/dist/{chunk-YULZKK4F.js → chunk-UNTGHX5A.js} +37 -2
  69. package/dist/chunk-UNTGHX5A.js.map +1 -0
  70. package/dist/{chunk-FWPKCXTN.js → chunk-WIAOUFFB.js} +2 -2
  71. package/dist/{chunk-KABJXG2F.js → chunk-WV7WV6JO.js} +195 -17
  72. package/dist/chunk-WV7WV6JO.js.map +1 -0
  73. package/dist/{chunk-X73VS74Y.js → chunk-XJV6OB4D.js} +2 -2
  74. package/dist/{chunk-VLMPU56Q.js → chunk-XMHUK5PN.js} +2 -2
  75. package/dist/{chunk-BI6ETQPF.js → chunk-XMVHEWF6.js} +4 -4
  76. package/dist/{chunk-HOR4R722.js → chunk-XPIHJ34I.js} +30 -4
  77. package/dist/chunk-XPIHJ34I.js.map +1 -0
  78. package/dist/{chunk-OB2ZJQ2D.js → chunk-YYVZYTWW.js} +3 -3
  79. package/dist/{chunk-535SSHBS.js → chunk-ZEGSDPB7.js} +81 -2
  80. package/dist/chunk-ZEGSDPB7.js.map +1 -0
  81. package/dist/{chunk-QVIEAYTP.js → chunk-ZNGPEV5J.js} +3 -3
  82. package/dist/consent/index.cjs.map +1 -1
  83. package/dist/consent/index.d.cts +6 -4
  84. package/dist/consent/index.d.ts +6 -4
  85. package/dist/consent/index.js +3 -3
  86. package/dist/{crypto-QXQOHMHF.js → crypto-7BN2HDWG.js} +7 -3
  87. package/dist/{delegation-NIQ43IPU.js → delegation-MGH5SODX.js} +5 -5
  88. package/dist/derivations/index.cjs.map +1 -1
  89. package/dist/derivations/index.d.cts +7 -5
  90. package/dist/derivations/index.d.ts +7 -5
  91. package/dist/derivations/index.js +4 -4
  92. package/dist/{dev-unlock-DR3upLd1.d.ts → dev-unlock-CI1ijTML.d.ts} +1 -1
  93. package/dist/{dev-unlock-8XzcD2Z4.d.cts → dev-unlock-iXbYFAWl.d.cts} +1 -1
  94. package/dist/{strategy-BtW8fAjz.d.ts → errors-Dz64FA65.d.cts} +98 -727
  95. package/dist/{strategy-BtW8fAjz.d.cts → errors-Dz64FA65.d.ts} +98 -727
  96. package/dist/executor-3W63Y44O.js +11 -0
  97. package/dist/executor-CFFWPWBJ.js +8 -0
  98. package/dist/executor-VDQQOR4F.js +8 -0
  99. package/dist/{fanout-sidecar-67CMI3UT.js → fanout-sidecar-FIJJ46YG.js} +2 -2
  100. package/dist/forget/index.cjs +43 -0
  101. package/dist/forget/index.cjs.map +1 -0
  102. package/dist/forget/index.d.cts +1 -0
  103. package/dist/forget/index.d.ts +1 -0
  104. package/dist/forget/index.js +14 -0
  105. package/dist/guards/index.cjs.map +1 -1
  106. package/dist/guards/index.d.cts +7 -5
  107. package/dist/guards/index.d.ts +7 -5
  108. package/dist/guards/index.js +6 -6
  109. package/dist/{hash-CDjye9KV.d.ts → hash-blk7Bkes.d.ts} +1 -1
  110. package/dist/{hash-DuQ88_5W.d.cts → hash-tEcM5fnv.d.cts} +1 -1
  111. package/dist/history/index.cjs +27 -4
  112. package/dist/history/index.cjs.map +1 -1
  113. package/dist/history/index.d.cts +7 -5
  114. package/dist/history/index.d.ts +7 -5
  115. package/dist/history/index.js +9 -7
  116. package/dist/history/index.js.map +1 -1
  117. package/dist/i18n/index.cjs +53 -0
  118. package/dist/i18n/index.cjs.map +1 -1
  119. package/dist/i18n/index.d.cts +6 -4
  120. package/dist/i18n/index.d.ts +6 -4
  121. package/dist/i18n/index.js +16 -8
  122. package/dist/i18n/index.js.map +1 -1
  123. package/dist/{immutable-guard-Dov3WvwF.d.ts → immutable-guard-B5M95nbq.d.ts} +1 -1
  124. package/dist/{immutable-guard-CRPvu24K.d.cts → immutable-guard-qN3zF8o1.d.cts} +1 -1
  125. package/dist/index-C-SSRIxP.d.cts +348 -0
  126. package/dist/index-C-SSRIxP.d.ts +348 -0
  127. package/dist/{index-nP99bXLg.d.ts → index-DpU6KWof.d.ts} +9 -1
  128. package/dist/{index-C8Bk3-VF.d.cts → index-u-kWzSrL.d.cts} +9 -1
  129. package/dist/index.cjs +7271 -6079
  130. package/dist/index.cjs.map +1 -1
  131. package/dist/index.d.cts +15 -12
  132. package/dist/index.d.ts +15 -12
  133. package/dist/index.js +130 -106
  134. package/dist/index.js.map +1 -1
  135. package/dist/indexing/index.cjs.map +1 -1
  136. package/dist/indexing/index.js +4 -4
  137. package/dist/issue-TTMGHQ2J.js +12 -0
  138. package/dist/{ledger-A3LL253R.js → ledger-LFVLHE5H.js} +6 -6
  139. package/dist/materialized-views/index.cjs.map +1 -1
  140. package/dist/materialized-views/index.d.cts +7 -5
  141. package/dist/materialized-views/index.d.ts +7 -5
  142. package/dist/materialized-views/index.js +12 -12
  143. package/dist/noydb-36S6GQNC.js +37 -0
  144. package/dist/overlay-views/index.cjs.map +1 -1
  145. package/dist/overlay-views/index.d.cts +7 -5
  146. package/dist/overlay-views/index.d.ts +7 -5
  147. package/dist/overlay-views/index.js +4 -4
  148. package/dist/periods/index.cjs.map +1 -1
  149. package/dist/periods/index.d.cts +6 -4
  150. package/dist/periods/index.d.ts +6 -4
  151. package/dist/periods/index.js +6 -6
  152. package/dist/{public-envelope-YP2UWMLG.js → public-envelope-RXZNP3V6.js} +4 -4
  153. package/dist/query/index.cjs +4 -1
  154. package/dist/query/index.cjs.map +1 -1
  155. package/dist/query/index.d.cts +3 -2
  156. package/dist/query/index.d.ts +3 -2
  157. package/dist/query/index.js +6 -6
  158. package/dist/registry-3YFLZ7WD.js +8 -0
  159. package/dist/{registry-UTA4CLQS.js → registry-SECUWSGY.js} +3 -3
  160. package/dist/registry-TGZISEWC.js +8 -0
  161. package/dist/{revoke-HNMQZSCL.js → revoke-B54H2S2W.js} +6 -6
  162. package/dist/sealed-record/index.cjs +139 -0
  163. package/dist/sealed-record/index.cjs.map +1 -0
  164. package/dist/sealed-record/index.d.cts +123 -0
  165. package/dist/sealed-record/index.d.ts +123 -0
  166. package/dist/sealed-record/index.js +42 -0
  167. package/dist/sealed-record/index.js.map +1 -0
  168. package/dist/session/index.cjs.map +1 -1
  169. package/dist/session/index.d.cts +7 -5
  170. package/dist/session/index.d.ts +7 -5
  171. package/dist/session/index.js +3 -3
  172. package/dist/shadow/index.cjs.map +1 -1
  173. package/dist/shadow/index.d.cts +6 -4
  174. package/dist/shadow/index.d.ts +6 -4
  175. package/dist/shadow/index.js +2 -2
  176. package/dist/{signer-DCMNKXSF.js → signer-YSXZT574.js} +5 -5
  177. package/dist/snapshots/index.cjs.map +1 -1
  178. package/dist/snapshots/index.d.cts +6 -4
  179. package/dist/snapshots/index.d.ts +6 -4
  180. package/dist/snapshots/index.js +4 -4
  181. package/dist/{stale-W5PQTRYH.js → stale-TOA36SRK.js} +2 -2
  182. package/dist/stale-TOA36SRK.js.map +1 -0
  183. package/dist/{state-vault-TMXZRTY5.js → state-vault-W2OEABNO.js} +3 -3
  184. package/dist/store/index.cjs.map +1 -1
  185. package/dist/store/index.d.cts +6 -4
  186. package/dist/store/index.d.ts +6 -4
  187. package/dist/store/index.js +2 -2
  188. package/dist/strategy-4M9jo172.d.ts +739 -0
  189. package/dist/strategy-CLC1j79g.d.cts +739 -0
  190. package/dist/sync/index.cjs.map +1 -1
  191. package/dist/sync/index.d.cts +5 -3
  192. package/dist/sync/index.d.ts +5 -3
  193. package/dist/sync/index.js +4 -4
  194. package/dist/team/index.cjs.map +1 -1
  195. package/dist/team/index.d.cts +6 -4
  196. package/dist/team/index.d.ts +6 -4
  197. package/dist/team/index.js +8 -8
  198. package/dist/tx/index.cjs.map +1 -1
  199. package/dist/tx/index.d.cts +6 -4
  200. package/dist/tx/index.d.ts +6 -4
  201. package/dist/tx/index.js +3 -3
  202. package/dist/{types-DrmBTscX.d.ts → types-CljIHm_J.d.ts} +789 -500
  203. package/dist/{types-Bze6vkwm.d.cts → types-CrSpRDuG.d.cts} +789 -500
  204. package/dist/{ulid-DbBVrNSt.d.ts → ulid-CWfL2Vfv.d.ts} +1 -1
  205. package/dist/{ulid-DfZlAh0u.d.cts → ulid-CrI7PPbA.d.cts} +1 -1
  206. package/dist/util/index.cjs.map +1 -1
  207. package/dist/util/index.js +1 -1
  208. package/dist/{vault-group-DX2HFQMX.js → vault-group-DHAHFX2A.js} +4 -4
  209. package/dist/{with-derivation-_lySGdlm.d.ts → with-derivation-BZ2y4bzF.d.ts} +1 -1
  210. package/dist/{with-derivation-CCqAchD5.d.cts → with-derivation-Bozs8DmD.d.cts} +1 -1
  211. package/dist/{with-materialized-view-QT1Tp7NO.d.ts → with-materialized-view-B892zYZV.d.ts} +1 -1
  212. package/dist/{with-materialized-view--4PsvMDu.d.cts → with-materialized-view-NzF71cG_.d.cts} +1 -1
  213. package/dist/{with-overlayed-view-BEXfpzSb.d.ts → with-overlayed-view-CR6m7CHe.d.ts} +1 -1
  214. package/dist/{with-overlayed-view-DlH5qmeB.d.cts → with-overlayed-view-UI8qSGL4.d.cts} +1 -1
  215. package/package.json +23 -3
  216. package/dist/chunk-535SSHBS.js.map +0 -1
  217. package/dist/chunk-667MB6AH.js.map +0 -1
  218. package/dist/chunk-7BQ4QWYX.js.map +0 -1
  219. package/dist/chunk-DUREQF5W.js.map +0 -1
  220. package/dist/chunk-F3BPIPLS.js.map +0 -1
  221. package/dist/chunk-GNI5STXQ.js.map +0 -1
  222. package/dist/chunk-HOR4R722.js.map +0 -1
  223. package/dist/chunk-KABJXG2F.js.map +0 -1
  224. package/dist/chunk-YULZKK4F.js.map +0 -1
  225. package/dist/executor-6ZDSDZ6V.js +0 -8
  226. package/dist/executor-AZLS3KBK.js +0 -11
  227. package/dist/executor-IDZDAFNH.js +0 -8
  228. package/dist/issue-RZP3VI6O.js +0 -12
  229. package/dist/noydb-WCMY2ZOW.js +0 -35
  230. package/dist/registry-EB6SISTA.js +0 -8
  231. package/dist/registry-IUZQVVBB.js +0 -8
  232. /package/dist/{chunk-G4SCICH5.js.map → chunk-2FU2FTXD.js.map} +0 -0
  233. /package/dist/{chunk-JD3OZAI4.js.map → chunk-3G3W65EQ.js.map} +0 -0
  234. /package/dist/{chunk-XWH4MXIU.js.map → chunk-5AXTH4QZ.js.map} +0 -0
  235. /package/dist/{chunk-4TBBMHVC.js.map → chunk-5LIROIDM.js.map} +0 -0
  236. /package/dist/{chunk-L2BNJ6HM.js.map → chunk-7H2GEJ3O.js.map} +0 -0
  237. /package/dist/{chunk-QSUK7YWK.js.map → chunk-BH3X5L6A.js.map} +0 -0
  238. /package/dist/{chunk-BQ65SS5A.js.map → chunk-BJSLBUJ7.js.map} +0 -0
  239. /package/dist/{chunk-FFXM3ZIF.js.map → chunk-BL5GYANC.js.map} +0 -0
  240. /package/dist/{chunk-6H2ZUNR7.js.map → chunk-BSZOCSDZ.js.map} +0 -0
  241. /package/dist/{chunk-ZNQYHJXX.js.map → chunk-C3HYQPV4.js.map} +0 -0
  242. /package/dist/{chunk-E2CDVKMH.js.map → chunk-CD2AVTEM.js.map} +0 -0
  243. /package/dist/{chunk-BR3AMFGS.js.map → chunk-DWEBTE2W.js.map} +0 -0
  244. /package/dist/{chunk-Z4DO7YSI.js.map → chunk-DYYYUW5D.js.map} +0 -0
  245. /package/dist/{chunk-SCJPI4Z5.js.map → chunk-E77UKJYL.js.map} +0 -0
  246. /package/dist/{chunk-OMAMZKKD.js.map → chunk-F4G63NTZ.js.map} +0 -0
  247. /package/dist/{chunk-TKIY625R.js.map → chunk-FEJDVE3Z.js.map} +0 -0
  248. /package/dist/{chunk-7Z7KSVA5.js.map → chunk-GP3SDSH2.js.map} +0 -0
  249. /package/dist/{chunk-IQLVUT37.js.map → chunk-H2MRGONI.js.map} +0 -0
  250. /package/dist/{chunk-CJORTUJ2.js.map → chunk-J7RWBXFY.js.map} +0 -0
  251. /package/dist/{chunk-AAVWKNZW.js.map → chunk-JDWE6JMX.js.map} +0 -0
  252. /package/dist/{chunk-XL35NSEN.js.map → chunk-KCEHMDZF.js.map} +0 -0
  253. /package/dist/{chunk-TS26M2SB.js.map → chunk-M476FOQ7.js.map} +0 -0
  254. /package/dist/{chunk-F4OJZIWQ.js.map → chunk-NBBMMJ2H.js.map} +0 -0
  255. /package/dist/{chunk-CZI2A4MQ.js.map → chunk-NYSYPFXJ.js.map} +0 -0
  256. /package/dist/{chunk-OQSRJG6A.js.map → chunk-PDULVIBY.js.map} +0 -0
  257. /package/dist/{chunk-DLZ2ONOD.js.map → chunk-QHM6XEAH.js.map} +0 -0
  258. /package/dist/{chunk-HBXJ37ZY.js.map → chunk-QO6RGLLD.js.map} +0 -0
  259. /package/dist/{chunk-42FEUPZQ.js.map → chunk-ROVO6NPJ.js.map} +0 -0
  260. /package/dist/{chunk-6RR3MNMG.js.map → chunk-SHX5QBCI.js.map} +0 -0
  261. /package/dist/{chunk-3YWP3WBP.js.map → chunk-SNMJ7SB3.js.map} +0 -0
  262. /package/dist/{chunk-IXBIFDEW.js.map → chunk-TIDXB5DF.js.map} +0 -0
  263. /package/dist/{chunk-FWPKCXTN.js.map → chunk-WIAOUFFB.js.map} +0 -0
  264. /package/dist/{chunk-X73VS74Y.js.map → chunk-XJV6OB4D.js.map} +0 -0
  265. /package/dist/{chunk-VLMPU56Q.js.map → chunk-XMHUK5PN.js.map} +0 -0
  266. /package/dist/{chunk-BI6ETQPF.js.map → chunk-XMVHEWF6.js.map} +0 -0
  267. /package/dist/{chunk-OB2ZJQ2D.js.map → chunk-YYVZYTWW.js.map} +0 -0
  268. /package/dist/{chunk-QVIEAYTP.js.map → chunk-ZNGPEV5J.js.map} +0 -0
  269. /package/dist/{crypto-QXQOHMHF.js.map → crypto-7BN2HDWG.js.map} +0 -0
  270. /package/dist/{delegation-NIQ43IPU.js.map → delegation-MGH5SODX.js.map} +0 -0
  271. /package/dist/{executor-6ZDSDZ6V.js.map → executor-3W63Y44O.js.map} +0 -0
  272. /package/dist/{executor-AZLS3KBK.js.map → executor-CFFWPWBJ.js.map} +0 -0
  273. /package/dist/{executor-IDZDAFNH.js.map → executor-VDQQOR4F.js.map} +0 -0
  274. /package/dist/{fanout-sidecar-67CMI3UT.js.map → fanout-sidecar-FIJJ46YG.js.map} +0 -0
  275. /package/dist/{issue-RZP3VI6O.js.map → forget/index.js.map} +0 -0
  276. /package/dist/{ledger-A3LL253R.js.map → issue-TTMGHQ2J.js.map} +0 -0
  277. /package/dist/{noydb-WCMY2ZOW.js.map → ledger-LFVLHE5H.js.map} +0 -0
  278. /package/dist/{public-envelope-YP2UWMLG.js.map → noydb-36S6GQNC.js.map} +0 -0
  279. /package/dist/{registry-EB6SISTA.js.map → public-envelope-RXZNP3V6.js.map} +0 -0
  280. /package/dist/{registry-IUZQVVBB.js.map → registry-3YFLZ7WD.js.map} +0 -0
  281. /package/dist/{registry-UTA4CLQS.js.map → registry-SECUWSGY.js.map} +0 -0
  282. /package/dist/{revoke-HNMQZSCL.js.map → registry-TGZISEWC.js.map} +0 -0
  283. /package/dist/{signer-DCMNKXSF.js.map → revoke-B54H2S2W.js.map} +0 -0
  284. /package/dist/{stale-W5PQTRYH.js.map → signer-YSXZT574.js.map} +0 -0
  285. /package/dist/{state-vault-TMXZRTY5.js.map → state-vault-W2OEABNO.js.map} +0 -0
  286. /package/dist/{vault-group-DX2HFQMX.js.map → vault-group-DHAHFX2A.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/record-keys/tombstone.ts","../src/record-keys/lifecycle.ts","../src/record-keys/sealing.ts"],"sourcesContent":["/**\n * Tombstone shape + predicate for the per-record-key (CEK) layer.\n *\n * A *tombstone* is the residue a GDPR crypto-shred (`vault.forget()`, #304)\n * leaves on disk: the live envelope rewritten to `{ _noydb, _v, _ts, _by,\n * _iv:'', _data:'' }`, dropping `_iv`/`_data`/`_cek`/`_det`. With the wrapped\n * per-record CEK gone, the body — and every history version under the same\n * CEK — is permanently undecryptable, while the record KEY survives so the\n * version counter and \"record existed and was erased\" persist for the audit\n * ledger.\n *\n * These two helpers are the pure, collection-independent core of that\n * contract: {@link buildTombstone} mints the shape, {@link isTombstone}\n * recognises it on the read path. The orchestration that *writes* a tombstone\n * (`_writeTombstone`) and drives `vault.forget()` lives with the collection /\n * vault; it calls into these.\n */\nimport { NOYDB_FORMAT_VERSION, type EncryptedEnvelope } from '../types.js'\n\n/**\n * Is this envelope a crypto-shred tombstone?\n *\n * A tombstone carries no body (`_data` empty) and no wrapped CEK (`_cek`\n * absent) — decrypting it would call `decrypt('', '', dek)` → an AES-GCM\n * throw, so every read choke point must short-circuit to `null` instead.\n *\n * `encrypted` is the collection's encryption flag: on an unencrypted\n * collection there are no envelopes to shred, so nothing is ever a tombstone.\n * (Legacy migration envelopes carry non-empty `_iv`/`_data`, so they are not\n * tombstones and stay readable.)\n */\nexport function isTombstone(envelope: EncryptedEnvelope, encrypted: boolean): boolean {\n if (!encrypted) return false\n return !envelope._data && envelope._cek === undefined\n}\n\n/**\n * Mint a tombstone envelope from a record's live version + actor.\n *\n * Keeps `_v` (the displaced version) so the counter is monotonic across the\n * shred, stamps a fresh `_ts`, and records `_by` when an actor is supplied.\n * Deliberately omits `_iv`/`_data`/`_cek`/`_det` — that omission *is* the\n * erasure.\n */\nexport function buildTombstone(version: number, actor: string): EncryptedEnvelope {\n return {\n _noydb: NOYDB_FORMAT_VERSION,\n _v: version,\n _ts: new Date().toISOString(),\n _iv: '',\n _data: '',\n ...(actor ? { _by: actor } : {}),\n }\n}\n","/**\n * Per-record CEK lifecycle helpers for the WRITE path (#356 foundation).\n *\n * These are the collection-coupled CEK operations, lifted off `Collection`\n * behind narrow deps so the kernel file delegates instead of carrying the\n * crypto inline:\n *\n * - {@link resolveStableCek} — the stable-CEK rule: an update or history\n * snapshot reuses the record's existing CEK so a single CEK delete kills\n * the whole version chain; a genuine insert (or legacy record being\n * migrated) mints a fresh one.\n * - {@link rewrapBodyToDek} — move a record body's wrapping from one DEK to\n * another (tier elevate/demote, bundle re-key) WITHOUT changing the body\n * key: unwrap the CEK under the source DEK, re-encrypt the body under the\n * same CEK, re-wrap the CEK under the destination DEK. History-chain\n * identity is preserved because the body key never changes.\n *\n * Both are pure functions over their deps — the `cekCache` ownership stays on\n * the collection (its lifetime is tied to `load()`), so callers cache the\n * returned key themselves.\n */\nimport { encrypt, decrypt, generateDEK, wrapCek, unwrapCek } from '../crypto.js'\nimport type { EncryptedEnvelope } from '../types.js'\nimport type { Lru } from '../cache/index.js'\n\n/** Dependencies {@link resolveStableCek} needs from its collection. */\nexport interface StableCekDeps {\n /** The collection's per-record CEK cache (`null` → no caching). */\n readonly cache: Lru<string, CryptoKey> | null\n /** Read the record's live envelope (to recover an existing `_cek`). */\n getLive(id: string): Promise<EncryptedEnvelope | null>\n /** The DEK the CEK is wrapped under (the collection DEK on the normal path). */\n getDEK(): Promise<CryptoKey>\n}\n\n/**\n * Resolve the stable CEK for a record on the write path. Caches the resolved\n * key under `id` so an update + its history snapshot share one CEK.\n */\nexport async function resolveStableCek(deps: StableCekDeps, id: string): Promise<CryptoKey> {\n const cached = deps.cache?.get(id)\n if (cached) return cached\n\n const live = await deps.getLive(id)\n if (live?._cek !== undefined) {\n const cek = await unwrapCek(live._cek, await deps.getDEK())\n deps.cache?.set(id, cek, 1)\n return cek\n }\n\n const fresh = await generateDEK()\n deps.cache?.set(id, fresh, 1)\n return fresh\n}\n\n/** Re-wrapped body bytes + the (optional) CEK to cache. */\nexport interface RewrappedBody {\n readonly _iv: string\n readonly _data: string\n /** Present iff the source envelope carried a CEK (per-record-key record). */\n readonly _cek?: string\n /** The body key when one exists, so the caller can cache it; `null` for a legacy record. */\n readonly cek: CryptoKey | null\n}\n\n/**\n * Move a record body from `fromDek` to `toDek`.\n *\n * - Per-record-key record (`_cek` present): unwrap the CEK under `fromDek`,\n * re-encrypt the body under the SAME CEK, re-wrap the CEK under `toDek`. The\n * body key is unchanged → history-chain identity preserved.\n * - Legacy record (no `_cek`): decrypt under `fromDek`, re-encrypt under `toDek`\n * directly — byte-for-byte the pre-CEK behaviour.\n */\nexport async function rewrapBodyToDek(\n envelope: Pick<EncryptedEnvelope, '_iv' | '_data' | '_cek'>,\n fromDek: CryptoKey,\n toDek: CryptoKey,\n): Promise<RewrappedBody> {\n if (envelope._cek !== undefined) {\n const cek = await unwrapCek(envelope._cek, fromDek)\n const plaintext = await decrypt(envelope._iv, envelope._data, cek)\n const { iv, data } = await encrypt(plaintext, cek)\n return { _iv: iv, _data: data, _cek: await wrapCek(cek, toDek), cek }\n }\n const plaintext = await decrypt(envelope._iv, envelope._data, fromDek)\n const { iv, data } = await encrypt(plaintext, toDek)\n return { _iv: iv, _data: data, cek: null }\n}\n","/**\n * Record-scoped CEK sealing — grantor side (#306 slices 2-3).\n *\n * The **grantor** holds the collection DEK and seals ONE record's CEK to an\n * `at-*` host so that host — and only that host — can decrypt exactly that\n * record, with no access to the vault DEK and no ability to read any other\n * record. This is the counterpart to the host-side `openSealedRecord`\n * (`@noy-db/hub/sealed-record`), which holds no DEK.\n *\n * These functions are the orchestration behind `vault.sealRecordToHost` /\n * `vault.revokeSealedRecord` / `vault.rotateRecordCek`, lifted off `Vault`\n * behind a narrow {@link SealingContext} so the kernel file delegates. They\n * live in `record-keys/` (the vault-side CEK policy layer), NOT in\n * `sealed-record/`, so the host-side subpath stays DEK-free — they import only\n * the wire *types* from there.\n */\nimport { encrypt, decrypt, generateDEK, wrapCek, unwrapCek, bufferToBase64 } from '../crypto.js'\nimport { NOYDB_FORMAT_VERSION, type EncryptedEnvelope, type NoydbStore } from '../types.js'\nimport { RecordCekNotFoundError, ValidationError } from '../errors.js'\nimport type { RecipientSealer } from '../team/managed-passphrase.js'\nimport type { SealedCekBinding, SealedCekDeliveryEnvelope } from '../sealed-record/types.js'\n\nconst subtle = globalThis.crypto.subtle\n\n/** The `_sealed_cek` delivery namespace (one envelope per `collection/id/pid`). */\nconst SEALED_CEK_NS = '_sealed_cek'\n\n/** What the grantor functions need from their `Vault`. */\nexport interface SealingContext {\n readonly adapter: NoydbStore\n /** Vault id (the adapter's first coordinate). */\n readonly vault: string\n /** Resolve the DEK a record's CEK is wrapped under. */\n getDEK(collection: string): Promise<CryptoKey>\n /** Actor id stamped on `_by` (empty string → omit). */\n readonly actor: string\n /** Evict the per-record CEK cache + decrypted-record cache after a rotation. */\n invalidateRecordCaches(collection: string, id: string): Promise<void>\n}\n\n/**\n * Seal a record's CEK to a host. See `vault.sealRecordToHost` for the contract.\n * Returns `{ pid, envelopeKey }`.\n */\nexport async function sealRecordToHost(\n ctx: SealingContext,\n collection: string,\n id: string,\n hostSealer: RecipientSealer,\n opts: { expiresAt: string },\n): Promise<{ pid: string; envelopeKey: string }> {\n // Guard separators: the `_sealed_cek` id is `collection/id/pid`, so a `/` in\n // any component would make the prefix-delete in rotateRecordCek() (which\n // matches `${collection}/${id}/`) ambiguous and could over- or under-match.\n if (collection.includes('/')) throw new ValidationError(`sealRecordToHost: collection \"${collection}\" must not contain \"/\"`)\n if (id.includes('/')) throw new ValidationError(`sealRecordToHost: id \"${id}\" must not contain \"/\"`)\n\n const live = await ctx.adapter.get(ctx.vault, collection, id)\n if (!live || live._cek === undefined) {\n throw new RecordCekNotFoundError(collection, id)\n }\n\n const dek = await ctx.getDEK(collection)\n const cek = await unwrapCek(live._cek, dek)\n const rawCek = await subtle.exportKey('raw', cek)\n const cekB64 = bufferToBase64(rawCek)\n\n const hint = await hostSealer.publishRecipientHint()\n if (hint.pid.includes('/')) throw new ValidationError(`sealRecordToHost: recipient pid \"${hint.pid}\" must not contain \"/\"`)\n\n const binding: SealedCekBinding = {\n collection,\n id,\n cek: cekB64,\n expiresAt: opts.expiresAt,\n }\n const sealed = await hostSealer.sealForRecipient(\n new TextEncoder().encode(JSON.stringify(binding)),\n hint,\n )\n\n const delivery: SealedCekDeliveryEnvelope = {\n v: 1,\n _noydb_sealed_cek: 1,\n pid: hint.pid,\n payload: bufferToBase64(sealed),\n expiresAt: opts.expiresAt,\n }\n\n const envelopeKey = `${collection}/${id}/${hint.pid}`\n const prior = await ctx.adapter.get(ctx.vault, SEALED_CEK_NS, envelopeKey)\n const env: EncryptedEnvelope = {\n _noydb: NOYDB_FORMAT_VERSION,\n _v: (prior?._v ?? 0) + 1,\n _ts: new Date().toISOString(),\n // AES-GCM bypassed — the sealing layer is the security boundary, exactly\n // like the managed-passphrase `_meta/sealed-passphrase` envelope.\n _iv: '',\n _data: JSON.stringify(delivery),\n ...(ctx.actor ? { _by: ctx.actor } : {}),\n }\n await ctx.adapter.put(ctx.vault, SEALED_CEK_NS, envelopeKey, env)\n\n return { pid: hint.pid, envelopeKey }\n}\n\n/**\n * Soft-revoke one sealed-CEK delivery envelope (delete it from the store). A\n * host that already fetched the envelope keeps whatever it cached; for a hard\n * revocation use {@link rotateRecordCek}.\n */\nexport async function revokeSealedRecord(\n ctx: SealingContext,\n collection: string,\n id: string,\n pid: string,\n): Promise<void> {\n await ctx.adapter.delete(ctx.vault, SEALED_CEK_NS, `${collection}/${id}/${pid}`)\n}\n\n/**\n * HARD-rotate a record's CEK: re-encrypt the live body under a fresh CEK, evict\n * caches, and delete EVERY sealed-CEK delivery envelope for the record. See\n * `vault.rotateRecordCek` for why this bypasses `Collection.put` (no guards, no\n * history bump — a key rotation must not re-encrypt prior history under the new\n * CEK).\n */\nexport async function rotateRecordCek(\n ctx: SealingContext,\n collection: string,\n id: string,\n): Promise<void> {\n const live = await ctx.adapter.get(ctx.vault, collection, id)\n if (!live || live._cek === undefined) {\n throw new RecordCekNotFoundError(collection, id)\n }\n\n const dek = await ctx.getDEK(collection)\n const oldCek = await unwrapCek(live._cek, dek)\n const json = await decrypt(live._iv, live._data, oldCek)\n\n const newCek = await generateDEK()\n const { iv, data } = await encrypt(json, newCek)\n\n const env: EncryptedEnvelope = {\n _noydb: NOYDB_FORMAT_VERSION,\n _v: live._v + 1,\n _ts: new Date().toISOString(),\n _iv: iv,\n _data: data,\n _cek: await wrapCek(newCek, dek),\n ...(ctx.actor ? { _by: ctx.actor } : {}),\n ...(live._tier !== undefined ? { _tier: live._tier } : {}),\n ...(live._det !== undefined ? { _det: live._det } : {}),\n }\n await ctx.adapter.put(ctx.vault, collection, id, env)\n\n // Evict BOTH caches synchronously so no read returns the stale old-CEK record.\n await ctx.invalidateRecordCaches(collection, id)\n\n // Delete every sealed-CEK delivery envelope for this record — all pids.\n const prefix = `${collection}/${id}/`\n const keys = await ctx.adapter.list(ctx.vault, SEALED_CEK_NS)\n for (const key of keys) {\n if (key.startsWith(prefix)) {\n await ctx.adapter.delete(ctx.vault, SEALED_CEK_NS, key)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA+BO,SAAS,YAAY,UAA6B,WAA6B;AACpF,MAAI,CAAC,UAAW,QAAO;AACvB,SAAO,CAAC,SAAS,SAAS,SAAS,SAAS;AAC9C;AAUO,SAAS,eAAe,SAAiB,OAAkC;AAChF,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,IAAI;AAAA,IACJ,MAAK,oBAAI,KAAK,GAAE,YAAY;AAAA,IAC5B,KAAK;AAAA,IACL,OAAO;AAAA,IACP,GAAI,QAAQ,EAAE,KAAK,MAAM,IAAI,CAAC;AAAA,EAChC;AACF;;;ACdA,eAAsB,iBAAiB,MAAqB,IAAgC;AAC1F,QAAM,SAAS,KAAK,OAAO,IAAI,EA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,WAAW,MAAM,GAAG;AAC1B,YAAM,IAAI,QAAQ,OAAO,IAAI,OAAO,eAAe,GAAG;AAAA,IACxD;AAAA,EACF;AACF;","names":["plaintext","iv","data"]}
@@ -2,7 +2,7 @@ import {
2
2
  DecryptionError,
3
3
  InvalidKeyError,
4
4
  TamperedError
5
- } from "./chunk-535SSHBS.js";
5
+ } from "./chunk-ZEGSDPB7.js";
6
6
 
7
7
  // src/crypto.ts
8
8
  var PBKDF2_ITERATIONS = 6e5;
@@ -58,6 +58,39 @@ async function unwrapKey(wrappedBase64, kek) {
58
58
  throw new InvalidKeyError();
59
59
  }
60
60
  }
61
+ async function asKwKey(dek) {
62
+ const rawDek = await subtle.exportKey("raw", dek);
63
+ const hkdfKey = await subtle.importKey("raw", rawDek, "HKDF", false, ["deriveBits"]);
64
+ const salt = new TextEncoder().encode("noydb-cek-wrap");
65
+ const info = new TextEncoder().encode("v1");
66
+ const bits = await subtle.deriveBits(
67
+ { name: "HKDF", hash: "SHA-256", salt, info },
68
+ hkdfKey,
69
+ KEY_BITS
70
+ );
71
+ return subtle.importKey("raw", bits, "AES-KW", false, ["wrapKey", "unwrapKey"]);
72
+ }
73
+ async function wrapCek(cek, dek) {
74
+ const kw = await asKwKey(dek);
75
+ const wrapped = await subtle.wrapKey("raw", cek, kw, "AES-KW");
76
+ return bufferToBase64(wrapped);
77
+ }
78
+ async function unwrapCek(wrappedBase64, dek) {
79
+ const kw = await asKwKey(dek);
80
+ try {
81
+ return await subtle.unwrapKey(
82
+ "raw",
83
+ base64ToBuffer(wrappedBase64),
84
+ kw,
85
+ "AES-KW",
86
+ { name: "AES-GCM", length: KEY_BITS },
87
+ true,
88
+ ["encrypt", "decrypt"]
89
+ );
90
+ } catch {
91
+ throw new InvalidKeyError();
92
+ }
93
+ }
61
94
  async function encrypt(plaintext, dek) {
62
95
  const iv = generateIV();
63
96
  const encoded = new TextEncoder().encode(plaintext);
@@ -256,6 +289,8 @@ export {
256
289
  generateDEK,
257
290
  wrapKey,
258
291
  unwrapKey,
292
+ wrapCek,
293
+ unwrapCek,
259
294
  encrypt,
260
295
  decrypt,
261
296
  encryptBytes,
@@ -272,4 +307,4 @@ export {
272
307
  bufferToBase64,
273
308
  base64ToBuffer
274
309
  };
275
- //# sourceMappingURL=chunk-YULZKK4F.js.map
310
+ //# sourceMappingURL=chunk-UNTGHX5A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/crypto.ts"],"sourcesContent":["/**\n * Cryptographic primitives — thin wrappers around the Web Crypto API.\n *\n * ## Design principle\n *\n * **Zero npm crypto dependencies.** Every operation uses `globalThis.crypto.subtle`,\n * which is available natively in Node.js ≥ 18, all modern browsers, and\n * Deno/Bun. This avoids supply-chain risk from third-party crypto packages and\n * ensures the library stays auditable.\n *\n * ## Algorithms\n *\n * | Use case | Algorithm | Parameters |\n * |----------|-----------|------------|\n * | Key derivation | PBKDF2-SHA256 | 600,000 iterations, 32-byte salt |\n * | Record encryption | AES-256-GCM | 12-byte random IV per operation |\n * | DEK wrapping | AES-KW (RFC 3394) | 256-bit KEK |\n * | Binary encrypt | AES-256-GCM | same as record encryption |\n * | Integrity | HMAC-SHA256 | for presence channels |\n * | Content hash | SHA-256 | for ledger and bundle integrity |\n *\n * ## Key lifecycle\n *\n * ```\n * passphrase + salt\n * └─► deriveKey() → KEK (CryptoKey, extractable: false)\n * └─► wrapKey() → wrapped DEK bytes [stored in keyring]\n * └─► unwrapKey() → DEK (CryptoKey) [memory only during session]\n * └─► encrypt() / decrypt() → ciphertext / plaintext\n * ```\n *\n * IVs are generated fresh by {@link generateIV} on every encrypt call.\n * Reusing an IV with the same key would break GCM's authentication guarantee —\n * this function should be the only place IVs are produced.\n *\n * @module\n */\n\nimport { DecryptionError, InvalidKeyError, TamperedError } from './errors.js'\n\nconst PBKDF2_ITERATIONS = 600_000\nconst SALT_BYTES = 32\nconst IV_BYTES = 12\nconst KEY_BITS = 256\n\nconst subtle = globalThis.crypto.subtle\n\n// ─── Key Derivation ────────────────────────────────────────────────────\n\n/** Derive a KEK from a passphrase and salt using PBKDF2-SHA256. */\nexport async function deriveKey(\n passphrase: string,\n salt: Uint8Array,\n): Promise<CryptoKey> {\n const keyMaterial = await subtle.importKey(\n 'raw',\n new TextEncoder().encode(passphrase),\n 'PBKDF2',\n false,\n ['deriveKey'],\n )\n\n return subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt: salt as BufferSource,\n iterations: PBKDF2_ITERATIONS,\n hash: 'SHA-256',\n },\n keyMaterial,\n { name: 'AES-KW', length: KEY_BITS },\n false,\n ['wrapKey', 'unwrapKey'],\n )\n}\n\n// ─── DEK Generation ────────────────────────────────────────────────────\n\n/** Generate a random AES-256-GCM data encryption key. */\nexport async function generateDEK(): Promise<CryptoKey> {\n return subtle.generateKey(\n { name: 'AES-GCM', length: KEY_BITS },\n true, // extractable — needed for AES-KW wrapping\n ['encrypt', 'decrypt'],\n )\n}\n\n// ─── Key Wrapping ──────────────────────────────────────────────────────\n\n/** Wrap (encrypt) a DEK with a KEK using AES-KW. Returns base64 string. */\nexport async function wrapKey(dek: CryptoKey, kek: CryptoKey): Promise<string> {\n const wrapped = await subtle.wrapKey('raw', dek, kek, 'AES-KW')\n return bufferToBase64(wrapped)\n}\n\n/** Unwrap (decrypt) a DEK from base64 string using a KEK. */\nexport async function unwrapKey(\n wrappedBase64: string,\n kek: CryptoKey,\n): Promise<CryptoKey> {\n try {\n return await subtle.unwrapKey(\n 'raw',\n base64ToBuffer(wrappedBase64) as BufferSource,\n kek,\n 'AES-KW',\n { name: 'AES-GCM', length: KEY_BITS },\n true,\n ['encrypt', 'decrypt'],\n )\n } catch {\n throw new InvalidKeyError()\n }\n}\n\n// ─── Per-record CEK wrapping ───────────────────────────────────────────\n\n/**\n * Derive a **dedicated** AES-KW wrapping key from a collection/tier DEK via\n * HKDF-SHA256, used to wrap/unwrap a per-record CEK.\n *\n * The collection/tier DEKs are AES-256-**GCM** keys (usages\n * `encrypt`/`decrypt`) and cannot themselves act as an AES-KW KEK. We do NOT\n * re-import the raw DEK bytes directly as an AES-KW key — that would reuse one\n * key across two primitives (AES-GCM for `_det`/presence, AES-KW for CEK\n * wrapping), violating key separation. Instead we HKDF-derive a domain-\n * separated KW key (salt `noydb-cek-wrap`), exactly as `derivePresenceKey`\n * derives a separate presence key. The derivation is deterministic, so\n * wrapping the same CEK under the same DEK always yields identical ciphertext\n * — which is what lets an update reuse a record's stable CEK and produce a\n * byte-identical `_cek`. The KW key is independent of the DEK's GCM key.\n *\n * The DEK must be extractable (it is — `generateDEK`/`unwrapKey` mint\n * extractable keys).\n */\nasync function asKwKey(dek: CryptoKey): Promise<CryptoKey> {\n const rawDek = await subtle.exportKey('raw', dek)\n const hkdfKey = await subtle.importKey('raw', rawDek, 'HKDF', false, ['deriveBits'])\n const salt = new TextEncoder().encode('noydb-cek-wrap')\n const info = new TextEncoder().encode('v1')\n const bits = await subtle.deriveBits(\n { name: 'HKDF', hash: 'SHA-256', salt, info },\n hkdfKey,\n KEY_BITS,\n )\n return subtle.importKey('raw', bits, 'AES-KW', false, ['wrapKey', 'unwrapKey'])\n}\n\n/**\n * AES-KW-wrap a per-record CEK under a collection/tier DEK. Returns base64.\n * Deterministic over `(cek, dek)`.\n */\nexport async function wrapCek(cek: CryptoKey, dek: CryptoKey): Promise<string> {\n const kw = await asKwKey(dek)\n const wrapped = await subtle.wrapKey('raw', cek, kw, 'AES-KW')\n return bufferToBase64(wrapped)\n}\n\n/**\n * Unwrap a per-record CEK from base64 under a collection/tier DEK. Throws\n * `InvalidKeyError` if the wrapped bytes do not authenticate under the DEK.\n */\nexport async function unwrapCek(wrappedBase64: string, dek: CryptoKey): Promise<CryptoKey> {\n const kw = await asKwKey(dek)\n try {\n return await subtle.unwrapKey(\n 'raw',\n base64ToBuffer(wrappedBase64) as BufferSource,\n kw,\n 'AES-KW',\n { name: 'AES-GCM', length: KEY_BITS },\n true,\n ['encrypt', 'decrypt'],\n )\n } catch {\n throw new InvalidKeyError()\n }\n}\n\n// ─── Encrypt / Decrypt ─────────────────────────────────────────────────\n\nexport interface EncryptResult {\n iv: string // base64\n data: string // base64\n}\n\n/** Encrypt plaintext JSON string with AES-256-GCM. Fresh IV per call. */\nexport async function encrypt(\n plaintext: string,\n dek: CryptoKey,\n): Promise<EncryptResult> {\n const iv = generateIV()\n const encoded = new TextEncoder().encode(plaintext)\n\n const ciphertext = await subtle.encrypt(\n { name: 'AES-GCM', iv: iv as BufferSource },\n dek,\n encoded,\n )\n\n return {\n iv: bufferToBase64(iv),\n data: bufferToBase64(ciphertext),\n }\n}\n\n/** Decrypt AES-256-GCM ciphertext. Throws on wrong key or tampered data. */\nexport async function decrypt(\n ivBase64: string,\n dataBase64: string,\n dek: CryptoKey,\n): Promise<string> {\n const iv = base64ToBuffer(ivBase64)\n const ciphertext = base64ToBuffer(dataBase64)\n\n try {\n const plaintext = await subtle.decrypt(\n { name: 'AES-GCM', iv: iv as BufferSource },\n dek,\n ciphertext as BufferSource,\n )\n return new TextDecoder().decode(plaintext)\n } catch (err) {\n if (err instanceof Error && err.name === 'OperationError') {\n throw new TamperedError()\n }\n throw new DecryptionError(\n err instanceof Error ? err.message : 'Decryption failed',\n )\n }\n}\n\n// ─── Binary Encrypt / Decrypt ────────\n\n/**\n * Encrypt raw bytes with AES-256-GCM using a fresh random IV.\n * Used by the attachment store so binary blobs avoid double base64 encoding\n * (the existing `encrypt()` function calls `TextEncoder` on a string — here\n * we pass the `Uint8Array` directly to `subtle.encrypt`).\n */\nexport async function encryptBytes(\n data: Uint8Array,\n dek: CryptoKey,\n): Promise<EncryptResult> {\n const iv = generateIV()\n const ciphertext = await subtle.encrypt(\n { name: 'AES-GCM', iv: iv as BufferSource },\n dek,\n data as unknown as BufferSource,\n )\n return {\n iv: bufferToBase64(iv),\n data: bufferToBase64(ciphertext),\n }\n}\n\n/**\n * Decrypt AES-256-GCM ciphertext back to raw bytes.\n * Counterpart to `encryptBytes`. Throws `TamperedError` on auth-tag failure.\n */\nexport async function decryptBytes(\n ivBase64: string,\n dataBase64: string,\n dek: CryptoKey,\n): Promise<Uint8Array> {\n const iv = base64ToBuffer(ivBase64)\n const ciphertext = base64ToBuffer(dataBase64)\n try {\n const plaintext = await subtle.decrypt(\n { name: 'AES-GCM', iv: iv as BufferSource },\n dek,\n ciphertext as BufferSource,\n )\n return new Uint8Array(plaintext)\n } catch (err) {\n if (err instanceof Error && err.name === 'OperationError') {\n throw new TamperedError()\n }\n throw new DecryptionError(\n err instanceof Error ? err.message : 'Decryption failed',\n )\n }\n}\n\n/**\n * SHA-256 hex digest of raw bytes. Used to derive content-addressed\n * eTags for blob deduplication. Computed on plaintext bytes\n * before compression and encryption so the eTag identifies content, not\n * ciphertext, and survives re-encryption (key rotation, re-upload).\n */\nexport async function sha256Hex(data: Uint8Array): Promise<string> {\n const hash = await subtle.digest('SHA-256', data as unknown as BufferSource)\n return Array.from(new Uint8Array(hash))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n}\n\n// ─── HMAC-SHA-256 ─────────────────────────────\n\n/**\n * Compute HMAC-SHA-256(key, data) and return hex string.\n *\n * Used to derive content-addressed eTags that are opaque to the store:\n * ```\n * eTag = hmacSha256Hex(blobDEK, plaintext)\n * ```\n *\n * Unlike a plain SHA-256, the HMAC is keyed by the vault-shared `_blob` DEK,\n * so an attacker with store access cannot pre-compute eTags for known files.\n * Deduplication still works within a vault (same key + same content = same eTag).\n */\nexport async function hmacSha256Hex(key: CryptoKey, data: Uint8Array): Promise<string> {\n // Export AES-GCM DEK raw bytes → import as HMAC key\n const rawKey = await subtle.exportKey('raw', key)\n const hmacKey = await subtle.importKey(\n 'raw',\n rawKey,\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign'],\n )\n const sig = await subtle.sign('HMAC', hmacKey, data as unknown as BufferSource)\n return Array.from(new Uint8Array(sig))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n}\n\n// ─── AAD-aware Binary Encrypt / Decrypt ──\n\n/**\n * Encrypt raw bytes with AES-256-GCM using Additional Authenticated Data.\n *\n * The AAD binds each chunk to its parent blob and position, preventing\n * chunk reorder, substitution, and truncation attacks:\n * ```\n * AAD = UTF-8(\"{eTag}:{chunkIndex}:{chunkCount}\")\n * ```\n *\n * The AAD is NOT stored — the reader reconstructs it from `BlobObject`\n * metadata and passes it to `decryptBytesWithAAD`.\n */\nexport async function encryptBytesWithAAD(\n data: Uint8Array,\n dek: CryptoKey,\n aad: Uint8Array,\n): Promise<EncryptResult> {\n const iv = generateIV()\n const ciphertext = await subtle.encrypt(\n {\n name: 'AES-GCM',\n iv: iv as BufferSource,\n additionalData: aad as BufferSource,\n },\n dek,\n data as unknown as BufferSource,\n )\n return {\n iv: bufferToBase64(iv),\n data: bufferToBase64(ciphertext),\n }\n}\n\n/**\n * Decrypt AES-256-GCM ciphertext with AAD verification.\n *\n * If the AAD does not match the one used at encryption time (e.g. because\n * a chunk was reordered or substituted from another blob), the GCM auth\n * tag fails and this throws `TamperedError`.\n */\nexport async function decryptBytesWithAAD(\n ivBase64: string,\n dataBase64: string,\n dek: CryptoKey,\n aad: Uint8Array,\n): Promise<Uint8Array> {\n const iv = base64ToBuffer(ivBase64)\n const ciphertext = base64ToBuffer(dataBase64)\n try {\n const plaintext = await subtle.decrypt(\n {\n name: 'AES-GCM',\n iv: iv as BufferSource,\n additionalData: aad as BufferSource,\n },\n dek,\n ciphertext as BufferSource,\n )\n return new Uint8Array(plaintext)\n } catch (err) {\n if (err instanceof Error && err.name === 'OperationError') {\n throw new TamperedError()\n }\n throw new DecryptionError(\n err instanceof Error ? err.message : 'Decryption failed',\n )\n }\n}\n\n// ─── Presence Key Derivation ──────────────────────────────\n\n/**\n * Derive an AES-256-GCM presence key from a collection DEK using HKDF-SHA256.\n *\n * The presence key is domain-separated from the data DEK by the fixed salt\n * `'noydb-presence'` and the `info` = collection name. This means:\n * - The adapter never sees the presence key.\n * - Presence payloads rotate automatically when the collection DEK is rotated.\n * - Revoked users cannot derive the new presence key after a DEK rotation.\n *\n * @param dek The collection's AES-256-GCM DEK (extractable).\n * @param collectionName Used as the HKDF `info` parameter for domain separation.\n * @returns A non-extractable AES-256-GCM key suitable for presence payload encryption.\n */\nexport async function derivePresenceKey(dek: CryptoKey, collectionName: string): Promise<CryptoKey> {\n // Step 1: export DEK raw bytes\n const rawDek = await subtle.exportKey('raw', dek)\n\n // Step 2: import as HKDF key material\n const hkdfKey = await subtle.importKey(\n 'raw',\n rawDek,\n 'HKDF',\n false,\n ['deriveBits'],\n )\n\n // Step 3: derive 256 bits with salt='noydb-presence' and info=collectionName\n const salt = new TextEncoder().encode('noydb-presence')\n const info = new TextEncoder().encode(collectionName)\n const bits = await subtle.deriveBits(\n { name: 'HKDF', hash: 'SHA-256', salt, info },\n hkdfKey,\n KEY_BITS,\n )\n\n // Step 4: import derived bits as AES-GCM key\n return subtle.importKey(\n 'raw',\n bits,\n { name: 'AES-GCM', length: KEY_BITS },\n false,\n ['encrypt', 'decrypt'],\n )\n}\n\n// ─── Deterministic Encryption ────────────────────────────\n\n/**\n * Derive a deterministic 12-byte IV from `{ DEK, context, plaintext }`\n * via HKDF-SHA256. Given the same three inputs, the IV is identical, so\n * `encryptDeterministic` produces the same ciphertext on every call —\n * which is precisely what enables blind equality search on encrypted\n * fields.\n *\n * **The side channel this opens.** Two records whose field value is the\n * same produce the same ciphertext. An observer with store access can\n * therefore tell which records share a value — not *what* the value is,\n * but the equivalence class. This is the well-known trade-off of\n * deterministic encryption and is why the feature is strictly opt-in\n * per field, guarded by `acknowledgeDeterministicRisk: true` at\n * collection creation.\n *\n * The context string MUST include the collection name and field name,\n * so:\n * - The same plaintext in two different fields encrypts differently\n * (no cross-field equality leak).\n * - The same plaintext in two different collections (different DEKs)\n * encrypts differently by virtue of the key, even before HKDF\n * domain separation kicks in.\n */\nasync function deriveDeterministicIV(\n dek: CryptoKey,\n context: string,\n plaintext: string,\n): Promise<Uint8Array> {\n const rawDek = await subtle.exportKey('raw', dek)\n const hkdfKey = await subtle.importKey('raw', rawDek, 'HKDF', false, ['deriveBits'])\n const salt = new TextEncoder().encode('noydb-deterministic-v1')\n const info = new TextEncoder().encode(`${context}\\x00${plaintext}`)\n const bits = await subtle.deriveBits(\n { name: 'HKDF', hash: 'SHA-256', salt, info },\n hkdfKey,\n IV_BYTES * 8,\n )\n return new Uint8Array(bits)\n}\n\n/**\n * Encrypt a plaintext string with AES-256-GCM and a deterministic,\n * HKDF-derived IV.\n *\n * The same `{ dek, context, plaintext }` triple always produces the\n * same `{ iv, data }` — call this twice and you can string-compare the\n * ciphertexts to check equality of the inputs without decrypting them.\n *\n * @param context Domain-separation string — by convention\n * `'<collection>/<field>'`. Different contexts encrypt\n * the same plaintext to different ciphertexts, so\n * `email` in collection `users` does not collide with\n * `email` in collection `customers`.\n */\nexport async function encryptDeterministic(\n plaintext: string,\n dek: CryptoKey,\n context: string,\n): Promise<EncryptResult> {\n const iv = await deriveDeterministicIV(dek, context, plaintext)\n const encoded = new TextEncoder().encode(plaintext)\n const ciphertext = await subtle.encrypt(\n { name: 'AES-GCM', iv: iv as BufferSource },\n dek,\n encoded,\n )\n return {\n iv: bufferToBase64(iv),\n data: bufferToBase64(ciphertext),\n }\n}\n\n/**\n * Counterpart to {@link encryptDeterministic}. The IV is stored\n * alongside the ciphertext (exactly like the randomized path), so\n * decrypt uses the stored IV and verifies the GCM auth tag — a tampered\n * ciphertext throws `TamperedError` just like randomized AES-GCM.\n */\nexport async function decryptDeterministic(\n ivBase64: string,\n dataBase64: string,\n dek: CryptoKey,\n): Promise<string> {\n return decrypt(ivBase64, dataBase64, dek)\n}\n\n// ─── Random Generation ─────────────────────────────────────────────────\n\n/** Generate a random 12-byte IV for AES-GCM. */\nexport function generateIV(): Uint8Array {\n return globalThis.crypto.getRandomValues(new Uint8Array(IV_BYTES))\n}\n\n/** Generate a random 32-byte salt for PBKDF2. */\nexport function generateSalt(): Uint8Array {\n return globalThis.crypto.getRandomValues(new Uint8Array(SALT_BYTES))\n}\n\n// ─── Base64 Helpers ────────────────────────────────────────────────────\n\nexport function bufferToBase64(buffer: ArrayBuffer | Uint8Array): string {\n const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer)\n let binary = ''\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!)\n }\n return btoa(binary)\n}\n\nexport function base64ToBuffer(base64: string): Uint8Array<ArrayBuffer> {\n const binary = atob(base64)\n const bytes = new Uint8Array(binary.length)\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i)\n }\n return bytes\n}\n"],"mappings":";;;;;;;AAwCA,IAAM,oBAAoB;AAC1B,IAAM,aAAa;AACnB,IAAM,WAAW;AACjB,IAAM,WAAW;AAEjB,IAAM,SAAS,WAAW,OAAO;AAKjC,eAAsB,UACpB,YACA,MACoB;AACpB,QAAM,cAAc,MAAM,OAAO;AAAA,IAC/B;AAAA,IACA,IAAI,YAAY,EAAE,OAAO,UAAU;AAAA,IACnC;AAAA,IACA;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAEA,SAAO,OAAO;AAAA,IACZ;AAAA,MACE,MAAM;AAAA,MACN;AAAA,MACA,YAAY;AAAA,MACZ,MAAM;AAAA,IACR;AAAA,IACA;AAAA,IACA,EAAE,MAAM,UAAU,QAAQ,SAAS;AAAA,IACnC;AAAA,IACA,CAAC,WAAW,WAAW;AAAA,EACzB;AACF;AAKA,eAAsB,cAAkC;AACtD,SAAO,OAAO;AAAA,IACZ,EAAE,MAAM,WAAW,QAAQ,SAAS;AAAA,IACpC;AAAA;AAAA,IACA,CAAC,WAAW,SAAS;AAAA,EACvB;AACF;AAKA,eAAsB,QAAQ,KAAgB,KAAiC;AAC7E,QAAM,UAAU,MAAM,OAAO,QAAQ,OAAO,KAAK,KAAK,QAAQ;AAC9D,SAAO,eAAe,OAAO;AAC/B;AAGA,eAAsB,UACpB,eACA,KACoB;AACpB,MAAI;AACF,WAAO,MAAM,OAAO;AAAA,MAClB;AAAA,MACA,eAAe,aAAa;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AC5B;AAgBA,eAAsB,qBACpB,WACA,KACA,SACwB;AACxB,QAAM,KAAK,MAAM,sBAAsB,KAAK,SAAS,SAAS;AAC9D,QAAM,UAAU,IAAI,YAAY,EAAE,OAAO,SAAS;AAClD,QAAM,aAAa,MAAM,OAAO;AAAA,IAC9B,EAAE,MAAM,WAAW,GAAuB;AAAA,IAC1C;AAAA,IACA;AAAA,EACF;AACA,SAAO;AAAA,IACL,IAAI,eAAe,EAAE;AAAA,IACrB,MAAM,eAAe,UAAU;AAAA,EACjC;AACF;AAQA,eAAsB,qBACpB,UACA,YACA,KACiB;AACjB,SAAO,QAAQ,UAAU,YAAY,GAAG;AAC1C;AAKO,SAAS,aAAyB;AACvC,SAAO,WAAW,OAAO,gBAAgB,IAAI,WAAW,QAAQ,CAAC;AACnE;AAGO,SAAS,eAA2B;AACzC,SAAO,WAAW,OAAO,gBAAgB,IAAI,WAAW,UAAU,CAAC;AACrE;AAIO,SAAS,eAAe,QAA0C;AACvE,QAAM,QAAQ,kBAAkB,aAAa,SAAS,IAAI,WAAW,MAAM;AAC3E,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAU,OAAO,aAAa,MAAM,CAAC,CAAE;AAAA,EACzC;AACA,SAAO,KAAK,MAAM;AACpB;AAEO,SAAS,eAAe,QAAyC;AACtE,QAAM,SAAS,KAAK,MAAM;AAC1B,QAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;AAC1C,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,EAChC;AACA,SAAO;AACT;","names":[]}
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  decrypt,
6
6
  encrypt
7
- } from "./chunk-YULZKK4F.js";
7
+ } from "./chunk-UNTGHX5A.js";
8
8
 
9
9
  // src/consent/consent.ts
10
10
  var CONSENT_AUDIT_COLLECTION = "_consent_audit";
@@ -69,4 +69,4 @@ export {
69
69
  writeConsentEntry,
70
70
  loadConsentEntries
71
71
  };
72
- //# sourceMappingURL=chunk-FWPKCXTN.js.map
72
+ //# sourceMappingURL=chunk-WIAOUFFB.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  NOYDB_FORMAT_VERSION
3
- } from "./chunk-F3BPIPLS.js";
3
+ } from "./chunk-SISBMAPO.js";
4
4
  import {
5
5
  base64ToBuffer,
6
6
  bufferToBase64,
@@ -8,13 +8,16 @@ import {
8
8
  decryptBytesWithAAD,
9
9
  encrypt,
10
10
  encryptBytesWithAAD,
11
+ generateDEK,
11
12
  hmacSha256Hex,
12
- sha256Hex
13
- } from "./chunk-YULZKK4F.js";
13
+ sha256Hex,
14
+ unwrapCek,
15
+ wrapCek
16
+ } from "./chunk-UNTGHX5A.js";
14
17
  import {
15
18
  ConflictError,
16
19
  NotFoundError
17
- } from "./chunk-535SSHBS.js";
20
+ } from "./chunk-ZEGSDPB7.js";
18
21
 
19
22
  // src/blobs/mime-magic.ts
20
23
  function hex(s) {
@@ -282,6 +285,7 @@ var BlobSet = class {
282
285
  encrypted;
283
286
  userId;
284
287
  maxBlobBytes;
288
+ erasableBlobs;
285
289
  constructor(opts) {
286
290
  this.store = opts.store;
287
291
  this.vault = opts.vault;
@@ -291,6 +295,21 @@ var BlobSet = class {
291
295
  this.encrypted = opts.encrypted;
292
296
  this.userId = opts.userId;
293
297
  this.maxBlobBytes = opts.maxBlobBytes;
298
+ this.erasableBlobs = opts.erasableBlobs === true;
299
+ }
300
+ /**
301
+ * Resolve the key the blob's CHUNKS are encrypted under.
302
+ *
303
+ * - `_cek` present (erasable blob) → unwrap the per-blob content CEK under
304
+ * the `_blob` DEK. Deleting the BlobObject (at `refCount → 0`) makes this
305
+ * key unrecoverable → the chunks are crypto-shredded.
306
+ * - `_cek` absent (legacy) → the `_blob` DEK encrypts chunks directly.
307
+ * - unencrypted vault → `null` (chunks stored as plaintext base64).
308
+ */
309
+ async resolveChunkKey(blob) {
310
+ if (!this.encrypted) return null;
311
+ const blobDEK = await this.getDEK(BLOB_COLLECTION);
312
+ return blob._cek !== void 0 ? await unwrapCek(blob._cek, blobDEK) : blobDEK;
294
313
  }
295
314
  /** The internal collection that holds slot metadata for this collection's blobs. */
296
315
  get slotsCollection() {
@@ -408,12 +427,163 @@ var BlobSet = class {
408
427
  const updated = { ...blob, refCount: blob.refCount + delta };
409
428
  try {
410
429
  await this.writeBlobObject(updated, version);
430
+ return updated.refCount;
431
+ } catch (err) {
432
+ if (err instanceof ConflictError && attempt < MAX_CAS_RETRIES - 1) continue;
433
+ throw err;
434
+ }
435
+ }
436
+ throw new ConflictError(-1);
437
+ }
438
+ /**
439
+ * Release `n` references to a blob and reclaim it at refCount 0 (#365 slice 4).
440
+ *
441
+ * The single reclaim choke point for every reference-drop path — slot
442
+ * delete/overwrite, published-version delete, and `forget()` shred — so the
443
+ * refCount-0 policy is uniform:
444
+ * - **erasable blob** (`_cek` present) → delete the `BlobObject` (the SOLE
445
+ * copy of the wrapped content CEK → chunks permanently undecryptable) and
446
+ * reclaim the chunks. The crypto-shred is EAGER on every path: GDPR erasure
447
+ * must not wait on orphan retention.
448
+ * - **legacy blob** (no `_cek`) → reclaimed only when `reclaimLegacy` (the
449
+ * `forget()` erasure path); otherwise left for deferred GC so the existing
450
+ * `BlobLifecyclePolicy.orphanRetentionDays` semantics are preserved.
451
+ *
452
+ * @returns `'shredded'` (erasable, refCount 0, chunks dead) · `'retainedShared'`
453
+ * (erasable, still referenced) · `'residue'` (legacy — not a crypto-shred).
454
+ */
455
+ async releaseRef(eTag, n, reclaimLegacy) {
456
+ const loaded = await this.loadBlobObject(eTag);
457
+ if (!loaded) return "shredded";
458
+ const erasable = loaded.blob._cek !== void 0;
459
+ const remaining = await this.casUpdateRefCount(eTag, -n);
460
+ if (remaining > 0) return erasable ? "retainedShared" : "residue";
461
+ if (erasable || reclaimLegacy) {
462
+ await this.store.delete(this.vault, BLOB_INDEX_COLLECTION, eTag);
463
+ for (let i = 0; i < loaded.blob.chunkCount; i++) {
464
+ await this.store.delete(this.vault, BLOB_CHUNKS_COLLECTION, `${eTag}_${i}`);
465
+ }
466
+ }
467
+ return erasable ? "shredded" : "residue";
468
+ }
469
+ /**
470
+ * Crypto-shred this record's blob attachments (#365 slice 2) — called by
471
+ * `vault.forget()`.
472
+ *
473
+ * For each distinct eTag the record references (a record may attach the same
474
+ * content under several slot names → several refCount holds): decrement the
475
+ * blob's refCount by that many. When it reaches 0:
476
+ * - **erasable blob** (`_cek` present) → delete the `BlobObject` (the SOLE
477
+ * recoverable copy of the wrapped content CEK → chunks permanently
478
+ * undecryptable) and reclaim the chunk bytes. This is the crypto-shred.
479
+ * - **legacy blob** (no `_cek`) → chunks are under the shared `_blob` DEK and
480
+ * stay decryptable until byte-deleted; we delete the orphaned chunks +
481
+ * index but report it as residue, not a cryptographic erasure.
482
+ * When refCount stays > 0 the content legitimately persists for its other
483
+ * owner — reported as `retainedShared` (or `residue` if legacy).
484
+ *
485
+ * Finally drops the record's slot map, severing the subject's link.
486
+ */
487
+ async shredAllForRecord() {
488
+ const { slots } = await this.loadSlots();
489
+ const slotNames = Object.keys(slots);
490
+ const shredded = [];
491
+ const retainedShared = [];
492
+ const residue = [];
493
+ if (slotNames.length === 0) return { shredded, retainedShared, residue };
494
+ const holds = /* @__PURE__ */ new Map();
495
+ for (const name of slotNames) {
496
+ const eTag = slots[name].eTag;
497
+ holds.set(eTag, (holds.get(eTag) ?? 0) + 1);
498
+ }
499
+ for (const [eTag, n] of holds) {
500
+ const outcome = await this.releaseRef(eTag, n, true);
501
+ if (outcome === "shredded") shredded.push(eTag);
502
+ else if (outcome === "retainedShared") retainedShared.push(eTag);
503
+ else residue.push(eTag);
504
+ }
505
+ await this.store.delete(this.vault, this.slotsCollection, this.recordId);
506
+ return { shredded, retainedShared, residue };
507
+ }
508
+ /** CAS retry loop for an arbitrary BlobObject mutation. */
509
+ async casUpdateBlobObject(eTag, mutate) {
510
+ for (let attempt = 0; attempt < MAX_CAS_RETRIES; attempt++) {
511
+ const result = await this.loadBlobObject(eTag);
512
+ if (!result) throw new NotFoundError(`BlobObject ${eTag} not found`);
513
+ try {
514
+ await this.writeBlobObject(mutate(result.blob), result.version);
411
515
  return;
412
516
  } catch (err) {
413
517
  if (err instanceof ConflictError && attempt < MAX_CAS_RETRIES - 1) continue;
414
518
  throw err;
415
519
  }
416
520
  }
521
+ throw new ConflictError(-1);
522
+ }
523
+ /**
524
+ * Migrate this record's LEGACY blobs (no `_cek`, chunks under the shared
525
+ * `_blob` DEK) to per-blob content CEKs so they become crypto-shreddable
526
+ * (#365 slice 3). Returns the eTags migrated vs. already-erasable.
527
+ *
528
+ * **Explicit maintenance pass** (mirrors the record-CEK migration posture):
529
+ * re-encrypts the existing compressed chunks IN PLACE under a fresh content
530
+ * CEK — preserving the eTag, chunkCount, chunkSize, and compression — then
531
+ * flips the `_cek` discriminant. Crash-safe + idempotent via `_cekPending`:
532
+ * 1. persist the wrapped content CEK in `_cekPending` (readers ignore it →
533
+ * the blob stays readable under the `_blob` DEK; the key survives a crash);
534
+ * 2. re-encrypt each chunk under the content CEK (a resume reads an
535
+ * already-migrated chunk under the content CEK, else under the `_blob` DEK);
536
+ * 3. promote `_cekPending` → `_cek` (atomic flip). Reads now use the CEK.
537
+ * A re-run after a crash resumes from whichever phase was reached.
538
+ *
539
+ * Dedup-safe: migrating a shared blob (refCount > 1) re-keys it for every
540
+ * referencer at once; a non-erasable collection still reads it (it unwraps
541
+ * `_cek` under the `_blob` DEK it holds).
542
+ */
543
+ async migrate() {
544
+ const migrated = [];
545
+ const alreadyErasable = [];
546
+ if (!this.encrypted) return { migrated, alreadyErasable };
547
+ const blobDEK = await this.getDEK(BLOB_COLLECTION);
548
+ const { slots } = await this.loadSlots();
549
+ const eTags = new Set(Object.values(slots).map((s) => s.eTag));
550
+ for (const eTag of eTags) {
551
+ const loaded = await this.loadBlobObject(eTag);
552
+ if (!loaded) continue;
553
+ const blob = loaded.blob;
554
+ if (blob._cek !== void 0) {
555
+ alreadyErasable.push(eTag);
556
+ continue;
557
+ }
558
+ let contentCek;
559
+ if (blob._cekPending !== void 0) {
560
+ contentCek = await unwrapCek(blob._cekPending, blobDEK);
561
+ } else {
562
+ contentCek = await generateDEK();
563
+ const wrapped = await wrapCek(contentCek, blobDEK);
564
+ await this.casUpdateBlobObject(eTag, (b) => ({ ...b, _cekPending: wrapped }));
565
+ }
566
+ for (let i = 0; i < blob.chunkCount; i++) {
567
+ let raw;
568
+ try {
569
+ raw = await this.readChunk(eTag, i, blob.chunkCount, blobDEK);
570
+ } catch {
571
+ raw = await this.readChunk(eTag, i, blob.chunkCount, contentCek);
572
+ }
573
+ if (!raw) {
574
+ throw new NotFoundError(
575
+ `Blob chunk ${i}/${blob.chunkCount} missing for eTag "${eTag}" during migration`
576
+ );
577
+ }
578
+ await this.writeChunk(eTag, i, blob.chunkCount, raw, contentCek);
579
+ }
580
+ await this.casUpdateBlobObject(eTag, (b) => {
581
+ const { _cekPending, ...rest } = b;
582
+ return _cekPending === void 0 ? b : { ...rest, _cek: _cekPending };
583
+ });
584
+ migrated.push(eTag);
585
+ }
586
+ return { migrated, alreadyErasable };
417
587
  }
418
588
  // ─── Chunk I/O (with AAD binding) ─────────────────────────────────
419
589
  async writeChunk(eTag, index, chunkCount, chunk, dek) {
@@ -485,10 +655,10 @@ var BlobSet = class {
485
655
  }
486
656
  // ─── Fetch all chunks for a blob ──────────────────────────────────
487
657
  async fetchAllChunks(blob) {
488
- const blobDEK = this.encrypted ? await this.getDEK(BLOB_COLLECTION) : null;
658
+ const chunkKey = await this.resolveChunkKey(blob);
489
659
  const chunks = [];
490
660
  for (let i = 0; i < blob.chunkCount; i++) {
491
- const chunk = await this.readChunk(blob.eTag, i, blob.chunkCount, blobDEK);
661
+ const chunk = await this.readChunk(blob.eTag, i, blob.chunkCount, chunkKey);
492
662
  if (!chunk) {
493
663
  throw new NotFoundError(
494
664
  `Blob chunk ${i}/${blob.chunkCount} missing for eTag "${blob.eTag}" on record "${this.recordId}"`
@@ -535,6 +705,13 @@ var BlobSet = class {
535
705
  const { bytes: compressed, algorithm } = shouldCompress ? await compressBytes(data) : { bytes: data, algorithm: "none" };
536
706
  const chunkSize = this.effectiveChunkSize(opts);
537
707
  const chunkCount = Math.max(1, Math.ceil(compressed.byteLength / chunkSize));
708
+ let chunkKey = blobDEK;
709
+ let wrappedCek;
710
+ if (blobDEK && this.erasableBlobs) {
711
+ const contentCek = await generateDEK();
712
+ wrappedCek = await wrapCek(contentCek, blobDEK);
713
+ chunkKey = contentCek;
714
+ }
538
715
  for (let i = 0; i < chunkCount; i++) {
539
716
  const start = i * chunkSize;
540
717
  await this.writeChunk(
@@ -542,7 +719,7 @@ var BlobSet = class {
542
719
  i,
543
720
  chunkCount,
544
721
  compressed.subarray(start, start + chunkSize),
545
- blobDEK
722
+ chunkKey
546
723
  );
547
724
  }
548
725
  await this.writeBlobObject({
@@ -554,7 +731,8 @@ var BlobSet = class {
554
731
  chunkCount,
555
732
  ...mimeType !== void 0 ? { mimeType } : {},
556
733
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
557
- refCount: 1
734
+ refCount: 1,
735
+ ...wrappedCek !== void 0 ? { _cek: wrappedCek } : {}
558
736
  });
559
737
  }
560
738
  const uploaderUserId = opts?.uploadedBy ?? this.userId;
@@ -576,7 +754,7 @@ var BlobSet = class {
576
754
  if (this._deferredRefDecrement) {
577
755
  const oldETag = this._deferredRefDecrement;
578
756
  this._deferredRefDecrement = void 0;
579
- await this.casUpdateRefCount(oldETag, -1).catch(() => {
757
+ await this.releaseRef(oldETag, 1, false).catch(() => {
580
758
  });
581
759
  }
582
760
  }
@@ -607,15 +785,15 @@ var BlobSet = class {
607
785
  * Decrements refCount on the blob. Chunks are GC'd by `vault.blobGC()`.
608
786
  */
609
787
  async delete(slotName) {
610
- let eTagToDecrement;
788
+ let eTagToRelease;
611
789
  await this.casUpdateSlots((slots) => {
612
790
  if (!(slotName in slots)) return null;
613
- eTagToDecrement = slots[slotName].eTag;
791
+ eTagToRelease = slots[slotName].eTag;
614
792
  delete slots[slotName];
615
793
  return slots;
616
794
  });
617
- if (eTagToDecrement) {
618
- await this.casUpdateRefCount(eTagToDecrement, -1).catch(() => {
795
+ if (eTagToRelease) {
796
+ await this.releaseRef(eTagToRelease, 1, false).catch(() => {
619
797
  });
620
798
  }
621
799
  }
@@ -698,7 +876,7 @@ var BlobSet = class {
698
876
  await this.writeVersionRecord(slotName, record);
699
877
  await this.casUpdateRefCount(slot.eTag, 1);
700
878
  if (existing && existing.eTag !== slot.eTag) {
701
- await this.casUpdateRefCount(existing.eTag, -1).catch(() => {
879
+ await this.releaseRef(existing.eTag, 1, false).catch(() => {
702
880
  });
703
881
  }
704
882
  }
@@ -741,7 +919,7 @@ var BlobSet = class {
741
919
  const record = await this.loadVersionRecord(slotName, label);
742
920
  if (!record) return;
743
921
  await this.deleteVersionRecord(slotName, label);
744
- await this.casUpdateRefCount(record.eTag, -1).catch(() => {
922
+ await this.releaseRef(record.eTag, 1, false).catch(() => {
745
923
  });
746
924
  }
747
925
  /**
@@ -820,7 +998,7 @@ var BlobSet = class {
820
998
  return this.buildResponse(slot, result.blob, { inline: true });
821
999
  }
822
1000
  const aad = chunkAAD(slot.eTag, 0, result.blob.chunkCount);
823
- const { decryptBytesWithAAD: decryptAAD } = await import("./crypto-QXQOHMHF.js");
1001
+ const { decryptBytesWithAAD: decryptAAD } = await import("./crypto-7BN2HDWG.js");
824
1002
  const decrypted = await decryptAAD(envelope._iv, envelope._data, blobDEK, aad);
825
1003
  const plaintext = result.blob.compression === "gzip" ? await decompressBytes(decrypted) : decrypted;
826
1004
  const body = new ReadableStream({
@@ -883,4 +1061,4 @@ export {
883
1061
  DEFAULT_CHUNK_SIZE,
884
1062
  BlobSet
885
1063
  };
886
- //# sourceMappingURL=chunk-KABJXG2F.js.map
1064
+ //# sourceMappingURL=chunk-WV7WV6JO.js.map