@aztec/pxe 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54

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 (427) hide show
  1. package/dest/bin/check_oracle_version.js +107 -17
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +49 -0
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  4. package/dest/block_synchronizer/block_synchronizer.js +171 -0
  5. package/dest/block_synchronizer/index.d.ts +2 -0
  6. package/dest/block_synchronizer/index.d.ts.map +1 -0
  7. package/dest/block_synchronizer/index.js +1 -0
  8. package/dest/config/index.d.ts +7 -5
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +12 -2
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  13. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +84 -24
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +252 -82
  18. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  19. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  20. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  21. package/dest/contract_function_simulator/execution_note_cache.d.ts +21 -11
  22. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/execution_note_cache.js +49 -31
  24. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  25. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  27. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  28. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/index.d.ts +3 -2
  30. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/index.js +2 -1
  32. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +7 -8
  33. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +12 -11
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +6 -5
  36. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +8 -7
  38. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
  39. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +3 -5
  41. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +7 -9
  42. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +10 -12
  44. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  45. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  47. package/dest/contract_function_simulator/oracle/interfaces.d.ts +73 -50
  48. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  50. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  51. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  52. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +4 -2
  53. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  55. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +11 -7
  56. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  57. package/dest/contract_function_simulator/oracle/note_packing_utils.js +14 -10
  58. package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -42
  59. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  60. package/dest/contract_function_simulator/oracle/oracle.js +340 -120
  61. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -27
  62. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  63. package/dest/contract_function_simulator/oracle/private_execution.js +6 -40
  64. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +66 -82
  65. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  66. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +145 -119
  67. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +168 -58
  68. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  69. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +402 -108
  70. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  71. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  72. package/dest/contract_function_simulator/pick_notes.js +21 -4
  73. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  74. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  75. package/dest/contract_function_simulator/proxied_contract_data_source.js +26 -5
  76. package/dest/contract_logging.d.ts +27 -0
  77. package/dest/contract_logging.d.ts.map +1 -0
  78. package/dest/contract_logging.js +38 -0
  79. package/dest/contract_sync/contract_sync_service.d.ts +44 -0
  80. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  81. package/dest/contract_sync/contract_sync_service.js +116 -0
  82. package/dest/contract_sync/helpers.d.ts +28 -0
  83. package/dest/contract_sync/helpers.d.ts.map +1 -0
  84. package/dest/contract_sync/helpers.js +60 -0
  85. package/dest/debug/pxe_debug_utils.d.ts +45 -0
  86. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  87. package/dest/debug/pxe_debug_utils.js +48 -0
  88. package/dest/entrypoints/client/bundle/index.d.ts +3 -2
  89. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  90. package/dest/entrypoints/client/bundle/index.js +2 -1
  91. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  92. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  93. package/dest/entrypoints/client/bundle/utils.js +32 -9
  94. package/dest/entrypoints/client/lazy/index.d.ts +3 -2
  95. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  96. package/dest/entrypoints/client/lazy/index.js +2 -1
  97. package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
  98. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  99. package/dest/entrypoints/client/lazy/utils.js +33 -10
  100. package/dest/entrypoints/pxe_creation_options.d.ts +9 -3
  101. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  102. package/dest/entrypoints/pxe_creation_options.js +3 -1
  103. package/dest/entrypoints/server/index.d.ts +6 -3
  104. package/dest/entrypoints/server/index.d.ts.map +1 -1
  105. package/dest/entrypoints/server/index.js +5 -2
  106. package/dest/entrypoints/server/utils.d.ts +2 -2
  107. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  108. package/dest/entrypoints/server/utils.js +39 -16
  109. package/dest/error_enriching.d.ts +4 -4
  110. package/dest/error_enriching.d.ts.map +1 -1
  111. package/dest/error_enriching.js +6 -6
  112. package/dest/events/event_service.d.ts +16 -0
  113. package/dest/events/event_service.d.ts.map +1 -0
  114. package/dest/events/event_service.js +65 -0
  115. package/dest/events/index.d.ts +2 -0
  116. package/dest/events/index.d.ts.map +1 -0
  117. package/dest/events/index.js +1 -0
  118. package/dest/events/private_event_filter_validator.d.ts +10 -0
  119. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  120. package/dest/events/private_event_filter_validator.js +53 -0
  121. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  122. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  123. package/dest/job_coordinator/job_coordinator.js +94 -0
  124. package/dest/logs/log_service.d.ts +28 -0
  125. package/dest/logs/log_service.d.ts.map +1 -0
  126. package/dest/logs/log_service.js +108 -0
  127. package/dest/messages/message_context_service.d.ts +17 -0
  128. package/dest/messages/message_context_service.d.ts.map +1 -0
  129. package/dest/messages/message_context_service.js +36 -0
  130. package/dest/notes/index.d.ts +2 -0
  131. package/dest/notes/index.d.ts.map +1 -0
  132. package/dest/notes/index.js +1 -0
  133. package/dest/notes/note_service.d.ts +48 -0
  134. package/dest/notes/note_service.d.ts.map +1 -0
  135. package/dest/notes/note_service.js +157 -0
  136. package/dest/notes_filter.d.ts +24 -0
  137. package/dest/notes_filter.d.ts.map +1 -0
  138. package/dest/notes_filter.js +4 -0
  139. package/dest/oracle_version.d.ts +4 -3
  140. package/dest/oracle_version.d.ts.map +1 -1
  141. package/dest/oracle_version.js +20 -9
  142. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  143. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  144. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  145. package/dest/private_kernel/hints/index.d.ts +3 -3
  146. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  147. package/dest/private_kernel/hints/index.js +2 -2
  148. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
  149. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  150. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +141 -74
  151. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  152. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  153. package/dest/private_kernel/hints/test_utils.js +203 -0
  154. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  155. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  156. package/dest/private_kernel/private_kernel_execution_prover.js +27 -23
  157. package/dest/private_kernel/private_kernel_oracle.d.ts +27 -26
  158. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  159. package/dest/private_kernel/private_kernel_oracle.js +91 -2
  160. package/dest/pxe.d.ts +117 -103
  161. package/dest/pxe.d.ts.map +1 -1
  162. package/dest/pxe.js +291 -262
  163. package/dest/storage/address_store/address_store.d.ts +11 -0
  164. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  165. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +13 -12
  166. package/dest/storage/address_store/index.d.ts +2 -0
  167. package/dest/storage/address_store/index.d.ts.map +1 -0
  168. package/dest/storage/address_store/index.js +1 -0
  169. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +17 -0
  170. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  171. package/dest/storage/anchor_block_store/anchor_block_store.js +26 -0
  172. package/dest/storage/{sync_data_provider → anchor_block_store}/index.d.ts +2 -2
  173. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  174. package/dest/storage/anchor_block_store/index.js +1 -0
  175. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  176. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  177. package/dest/storage/capsule_store/capsule_service.js +50 -0
  178. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  179. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  180. package/dest/storage/capsule_store/capsule_store.js +261 -0
  181. package/dest/storage/capsule_store/index.d.ts +3 -0
  182. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  183. package/dest/storage/capsule_store/index.js +2 -0
  184. package/dest/storage/contract_store/contract_store.d.ts +93 -0
  185. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  186. package/dest/storage/contract_store/contract_store.js +311 -0
  187. package/dest/storage/contract_store/index.d.ts +2 -0
  188. package/dest/storage/contract_store/index.d.ts.map +1 -0
  189. package/dest/storage/contract_store/index.js +1 -0
  190. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  191. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  192. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  193. package/dest/storage/index.d.ts +8 -8
  194. package/dest/storage/index.d.ts.map +1 -1
  195. package/dest/storage/index.js +7 -7
  196. package/dest/storage/metadata.d.ts +1 -1
  197. package/dest/storage/metadata.js +1 -1
  198. package/dest/storage/note_store/index.d.ts +3 -0
  199. package/dest/storage/note_store/index.d.ts.map +1 -0
  200. package/dest/storage/note_store/index.js +2 -0
  201. package/dest/storage/note_store/note_store.d.ts +83 -0
  202. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  203. package/dest/storage/note_store/note_store.js +343 -0
  204. package/dest/storage/note_store/stored_note.d.ts +16 -0
  205. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  206. package/dest/storage/note_store/stored_note.js +43 -0
  207. package/dest/storage/private_event_store/private_event_store.d.ts +91 -0
  208. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  209. package/dest/storage/private_event_store/private_event_store.js +276 -0
  210. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  211. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  212. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  213. package/dest/storage/tagging_store/index.d.ts +4 -0
  214. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  215. package/dest/storage/tagging_store/index.js +3 -0
  216. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
  217. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  218. package/dest/storage/tagging_store/recipient_tagging_store.js +111 -0
  219. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  220. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  221. package/dest/storage/tagging_store/sender_address_book_store.js +36 -0
  222. package/dest/storage/tagging_store/sender_tagging_store.d.ts +78 -0
  223. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  224. package/dest/storage/tagging_store/sender_tagging_store.js +374 -0
  225. package/dest/tagging/constants.d.ts +2 -2
  226. package/dest/tagging/constants.d.ts.map +1 -1
  227. package/dest/tagging/constants.js +10 -2
  228. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  229. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  230. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  231. package/dest/tagging/index.d.ts +17 -7
  232. package/dest/tagging/index.d.ts.map +1 -1
  233. package/dest/tagging/index.js +15 -5
  234. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  235. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  236. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +85 -0
  237. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  238. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  239. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  240. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  241. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  242. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +33 -0
  243. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +17 -0
  244. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  245. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +80 -0
  246. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +12 -0
  247. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  248. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +39 -0
  249. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +19 -0
  250. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  251. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +72 -0
  252. package/package.json +28 -19
  253. package/src/bin/check_oracle_version.ts +133 -22
  254. package/src/block_synchronizer/block_synchronizer.ts +198 -0
  255. package/src/block_synchronizer/index.ts +1 -0
  256. package/src/config/index.ts +12 -4
  257. package/src/config/package_info.ts +1 -1
  258. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  259. package/src/contract_function_simulator/contract_function_simulator.ts +424 -114
  260. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  261. package/src/contract_function_simulator/execution_note_cache.ts +51 -28
  262. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  263. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  264. package/src/contract_function_simulator/index.ts +2 -1
  265. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +15 -11
  266. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +7 -6
  267. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +3 -6
  268. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +9 -12
  269. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  270. package/src/contract_function_simulator/oracle/interfaces.ts +105 -62
  271. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  272. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  273. package/src/contract_function_simulator/oracle/note_packing_utils.ts +27 -13
  274. package/src/contract_function_simulator/oracle/oracle.ts +441 -163
  275. package/src/contract_function_simulator/oracle/private_execution.ts +6 -72
  276. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +201 -167
  277. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +676 -113
  278. package/src/contract_function_simulator/pick_notes.ts +23 -4
  279. package/src/contract_function_simulator/proxied_contract_data_source.ts +32 -8
  280. package/src/contract_logging.ts +52 -0
  281. package/src/contract_sync/contract_sync_service.ts +176 -0
  282. package/src/contract_sync/helpers.ts +98 -0
  283. package/src/debug/pxe_debug_utils.ts +93 -0
  284. package/src/entrypoints/client/bundle/index.ts +2 -1
  285. package/src/entrypoints/client/bundle/utils.ts +24 -18
  286. package/src/entrypoints/client/lazy/index.ts +2 -1
  287. package/src/entrypoints/client/lazy/utils.ts +25 -19
  288. package/src/entrypoints/pxe_creation_options.ts +13 -2
  289. package/src/entrypoints/server/index.ts +5 -2
  290. package/src/entrypoints/server/utils.ts +33 -42
  291. package/src/error_enriching.ts +7 -15
  292. package/src/events/event_service.ts +96 -0
  293. package/src/events/index.ts +1 -0
  294. package/src/events/private_event_filter_validator.ts +66 -0
  295. package/src/job_coordinator/job_coordinator.ts +150 -0
  296. package/src/logs/log_service.ts +192 -0
  297. package/src/messages/message_context_service.ts +44 -0
  298. package/src/notes/index.ts +1 -0
  299. package/src/notes/note_service.ts +206 -0
  300. package/src/notes_filter.ts +24 -0
  301. package/src/oracle_version.ts +20 -9
  302. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  303. package/src/private_kernel/hints/index.ts +2 -2
  304. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +197 -139
  305. package/src/private_kernel/hints/test_utils.ts +325 -0
  306. package/src/private_kernel/private_kernel_execution_prover.ts +31 -27
  307. package/src/private_kernel/private_kernel_oracle.ts +118 -37
  308. package/src/pxe.ts +454 -354
  309. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +16 -16
  310. package/src/storage/address_store/index.ts +1 -0
  311. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +11 -12
  312. package/src/storage/anchor_block_store/index.ts +1 -0
  313. package/src/storage/capsule_store/capsule_service.ts +90 -0
  314. package/src/storage/capsule_store/capsule_store.ts +333 -0
  315. package/src/storage/capsule_store/index.ts +2 -0
  316. package/src/storage/contract_store/contract_store.ts +431 -0
  317. package/src/storage/contract_store/index.ts +1 -0
  318. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  319. package/src/storage/index.ts +7 -7
  320. package/src/storage/metadata.ts +1 -1
  321. package/src/storage/note_store/index.ts +2 -0
  322. package/src/storage/note_store/note_store.ts +415 -0
  323. package/src/storage/note_store/stored_note.ts +48 -0
  324. package/src/storage/private_event_store/private_event_store.ts +388 -0
  325. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  326. package/src/storage/tagging_store/index.ts +3 -0
  327. package/src/storage/tagging_store/recipient_tagging_store.ts +143 -0
  328. package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
  329. package/src/storage/tagging_store/sender_tagging_store.ts +476 -0
  330. package/src/tagging/constants.ts +10 -2
  331. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  332. package/src/tagging/index.ts +19 -6
  333. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +130 -0
  334. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  335. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +44 -0
  336. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +112 -0
  337. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +51 -0
  338. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +85 -0
  339. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -265
  340. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  341. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  342. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  343. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  344. package/dest/contract_function_simulator/proxied_node.js +0 -27
  345. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -122
  346. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  347. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -694
  348. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  349. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  350. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  351. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  352. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -45
  353. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  354. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  355. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  356. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  357. package/dest/storage/address_data_provider/index.d.ts +0 -2
  358. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  359. package/dest/storage/address_data_provider/index.js +0 -1
  360. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -25
  361. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  362. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -118
  363. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  364. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  365. package/dest/storage/capsule_data_provider/index.js +0 -1
  366. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +0 -64
  367. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  368. package/dest/storage/contract_data_provider/contract_data_provider.js +0 -193
  369. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  370. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  371. package/dest/storage/contract_data_provider/index.js +0 -1
  372. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  373. package/dest/storage/note_data_provider/index.d.ts +0 -3
  374. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  375. package/dest/storage/note_data_provider/index.js +0 -2
  376. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -83
  377. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  378. package/dest/storage/note_data_provider/note_data_provider.js +0 -311
  379. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
  380. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  381. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -105
  382. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  383. package/dest/storage/sync_data_provider/index.js +0 -1
  384. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -10
  385. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  386. package/dest/storage/sync_data_provider/sync_data_provider.js +0 -26
  387. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  388. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  389. package/dest/storage/tagging_data_provider/index.js +0 -1
  390. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -40
  391. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  392. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -89
  393. package/dest/synchronizer/index.d.ts +0 -2
  394. package/dest/synchronizer/index.d.ts.map +0 -1
  395. package/dest/synchronizer/index.js +0 -1
  396. package/dest/synchronizer/synchronizer.d.ts +0 -35
  397. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  398. package/dest/synchronizer/synchronizer.js +0 -101
  399. package/dest/tagging/siloed_tag.d.ts +0 -14
  400. package/dest/tagging/siloed_tag.d.ts.map +0 -1
  401. package/dest/tagging/siloed_tag.js +0 -20
  402. package/dest/tagging/tag.d.ts +0 -12
  403. package/dest/tagging/tag.d.ts.map +0 -1
  404. package/dest/tagging/tag.js +0 -17
  405. package/dest/tagging/utils.d.ts +0 -18
  406. package/dest/tagging/utils.d.ts.map +0 -1
  407. package/dest/tagging/utils.js +0 -24
  408. package/src/contract_function_simulator/execution_data_provider.ts +0 -333
  409. package/src/contract_function_simulator/proxied_node.ts +0 -33
  410. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1008
  411. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -132
  412. package/src/storage/address_data_provider/index.ts +0 -1
  413. package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -147
  414. package/src/storage/capsule_data_provider/index.ts +0 -1
  415. package/src/storage/contract_data_provider/contract_data_provider.ts +0 -277
  416. package/src/storage/contract_data_provider/index.ts +0 -1
  417. package/src/storage/note_data_provider/index.ts +0 -2
  418. package/src/storage/note_data_provider/note_data_provider.ts +0 -399
  419. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -143
  420. package/src/storage/sync_data_provider/index.ts +0 -1
  421. package/src/storage/tagging_data_provider/index.ts +0 -1
  422. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
  423. package/src/synchronizer/index.ts +0 -1
  424. package/src/synchronizer/synchronizer.ts +0 -120
  425. package/src/tagging/siloed_tag.ts +0 -22
  426. package/src/tagging/tag.ts +0 -16
  427. package/src/tagging/utils.ts +0 -31
@@ -0,0 +1,11 @@
1
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { CompleteAddress } from '@aztec/stdlib/contract';
4
+ export declare class AddressStore {
5
+ #private;
6
+ constructor(store: AztecAsyncKVStore);
7
+ addCompleteAddress(completeAddress: CompleteAddress): Promise<boolean>;
8
+ getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined>;
9
+ getCompleteAddresses(): Promise<CompleteAddress[]>;
10
+ }
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vL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AAO,CAAC,eAAe,EAAE,CAAC,CAMjD;CACF"}
@@ -1,6 +1,6 @@
1
1
  import { toArray } from '@aztec/foundation/iterable';
2
2
  import { CompleteAddress } from '@aztec/stdlib/contract';
3
- export class AddressDataProvider {
3
+ export class AddressStore {
4
4
  #store;
5
5
  #completeAddresses;
6
6
  #completeAddressIndex;
@@ -30,18 +30,19 @@ export class AddressDataProvider {
30
30
  }
31
31
  });
32
32
  }
33
- async #getCompleteAddress(address) {
34
- const index = await this.#completeAddressIndex.getAsync(address.toString());
35
- if (index === undefined) {
36
- return undefined;
37
- }
38
- const value = await this.#completeAddresses.atAsync(index);
39
- return value ? await CompleteAddress.fromBuffer(value) : undefined;
40
- }
41
33
  getCompleteAddress(account) {
42
- return this.#getCompleteAddress(account);
34
+ return this.#store.transactionAsync(async ()=>{
35
+ const index = await this.#completeAddressIndex.getAsync(account.toString());
36
+ if (index === undefined) {
37
+ return undefined;
38
+ }
39
+ const value = await this.#completeAddresses.atAsync(index);
40
+ return value ? await CompleteAddress.fromBuffer(value) : undefined;
41
+ });
43
42
  }
44
- async getCompleteAddresses() {
45
- return await Promise.all((await toArray(this.#completeAddresses.valuesAsync())).map((v)=>CompleteAddress.fromBuffer(v)));
43
+ getCompleteAddresses() {
44
+ return this.#store.transactionAsync(async ()=>{
45
+ return await Promise.all((await toArray(this.#completeAddresses.valuesAsync())).map((v)=>CompleteAddress.fromBuffer(v)));
46
+ });
46
47
  }
47
48
  }
@@ -0,0 +1,2 @@
1
+ export { AddressStore } from './address_store.js';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2FkZHJlc3Nfc3RvcmUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLG9CQUFvQixDQUFDIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/address_store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1 @@
1
+ export { AddressStore } from './address_store.js';
@@ -0,0 +1,17 @@
1
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
+ import { BlockHeader } from '@aztec/stdlib/tx';
3
+ export declare class AnchorBlockStore {
4
+ #private;
5
+ constructor(store: AztecAsyncKVStore);
6
+ /**
7
+ * Sets the currently synchronized block
8
+ *
9
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
10
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
11
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
12
+ *
13
+ */
14
+ setHeader(header: BlockHeader): Promise<void>;
15
+ getBlockHeader(): Promise<BlockHeader>;
16
+ }
17
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5jaG9yX2Jsb2NrX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9hbmNob3JfYmxvY2tfc3RvcmUvYW5jaG9yX2Jsb2NrX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUF1QixNQUFNLGlCQUFpQixDQUFDO0FBQzlFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUUvQyxxQkFBYSxnQkFBZ0I7O0lBSTNCLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQUduQztJQUVEOzs7Ozs7O09BT0c7SUFDRyxTQUFTLENBQUMsTUFBTSxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRWxEO0lBRUssY0FBYyxJQUFJLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FPM0M7Q0FDRiJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor_block_store.d.ts","sourceRoot":"","sources":["../../../src/storage/anchor_block_store/anchor_block_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,gBAAgB;;IAI3B,YAAY,KAAK,EAAE,iBAAiB,EAGnC;IAED;;;;;;;OAOG;IACG,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAElD;IAEK,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAO3C;CACF"}
@@ -0,0 +1,26 @@
1
+ import { BlockHeader } from '@aztec/stdlib/tx';
2
+ export class AnchorBlockStore {
3
+ #store;
4
+ #synchronizedHeader;
5
+ constructor(store){
6
+ this.#store = store;
7
+ this.#synchronizedHeader = this.#store.openSingleton('header');
8
+ }
9
+ /**
10
+ * Sets the currently synchronized block
11
+ *
12
+ * Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
13
+ * stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
14
+ * deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
15
+ *
16
+ */ async setHeader(header) {
17
+ await this.#synchronizedHeader.set(header.toBuffer());
18
+ }
19
+ async getBlockHeader() {
20
+ const headerBuffer = await this.#store.transactionAsync(()=>this.#synchronizedHeader.getAsync());
21
+ if (!headerBuffer) {
22
+ throw new Error(`Trying to get block header with a not-yet-synchronized PXE - this should never happen`);
23
+ }
24
+ return BlockHeader.fromBuffer(headerBuffer);
25
+ }
26
+ }
@@ -1,2 +1,2 @@
1
- export { SyncDataProvider } from './sync_data_provider.js';
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL3N5bmNfZGF0YV9wcm92aWRlci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQyJ9
1
+ export { AnchorBlockStore } from './anchor_block_store.js';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2FuY2hvcl9ibG9ja19zdG9yZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/anchor_block_store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1 @@
1
+ export { AnchorBlockStore } from './anchor_block_store.js';
@@ -0,0 +1,21 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { Capsule } from '@aztec/stdlib/tx';
4
+ import type { CapsuleStore } from './capsule_store.js';
5
+ /**
6
+ * Wraps a CapsuleStore with scope-based access control. Each operation asserts that the requested scope is in the
7
+ * allowed scopes list before delegating to the underlying store.
8
+ */
9
+ export declare class CapsuleService {
10
+ private readonly capsuleStore;
11
+ private readonly allowedScopes;
12
+ constructor(capsuleStore: CapsuleStore, allowedScopes: AztecAddress[]);
13
+ setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress): void;
14
+ getCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress, transientCapsules?: Capsule[]): Promise<Fr[] | null>;
15
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): void;
16
+ copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number, jobId: string, scope: AztecAddress): Promise<void>;
17
+ appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
18
+ readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]>;
19
+ setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
20
+ }
21
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2Fwc3VsZV9zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9jYXBzdWxlX3N0b3JlL2NhcHN1bGVfc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFaEQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFFdkQ7OztHQUdHO0FBQ0gscUJBQWEsY0FBYztJQUV2QixPQUFPLENBQUMsUUFBUSxDQUFDLFlBQVk7SUFDN0IsT0FBTyxDQUFDLFFBQVE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AAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAYtB;IAED,aAAa,CAAC,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,QAGxF;IAED,WAAW,CACT,eAAe,EAAE,YAAY,EAC7B,OAAO,EAAE,EAAE,EACX,OAAO,EAAE,EAAE,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAGf;IAED,oBAAoB,CAClB,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,EAAE,EACZ,OAAO,EAAE,EAAE,EAAE,EAAE,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAGf;IAED,gBAAgB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAGjH;IAED,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,iBAG/G;CACF"}
@@ -0,0 +1,50 @@
1
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ /**
3
+ * Wraps a CapsuleStore with scope-based access control. Each operation asserts that the requested scope is in the
4
+ * allowed scopes list before delegating to the underlying store.
5
+ */ export class CapsuleService {
6
+ capsuleStore;
7
+ allowedScopes;
8
+ constructor(capsuleStore, allowedScopes){
9
+ this.capsuleStore = capsuleStore;
10
+ this.allowedScopes = allowedScopes;
11
+ }
12
+ setCapsule(contractAddress, slot, capsule, jobId, scope) {
13
+ assertAllowedScope(scope, this.allowedScopes);
14
+ this.capsuleStore.setCapsule(contractAddress, slot, capsule, jobId, scope);
15
+ }
16
+ async getCapsule(contractAddress, slot, jobId, scope, transientCapsules) {
17
+ assertAllowedScope(scope, this.allowedScopes);
18
+ // TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
19
+ const maybeTransientCapsule = transientCapsules?.find((c)=>c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot) && (c.scope ?? AztecAddress.ZERO).equals(scope))?.data;
20
+ return maybeTransientCapsule ?? await this.capsuleStore.getCapsule(contractAddress, slot, jobId, scope);
21
+ }
22
+ deleteCapsule(contractAddress, slot, jobId, scope) {
23
+ assertAllowedScope(scope, this.allowedScopes);
24
+ this.capsuleStore.deleteCapsule(contractAddress, slot, jobId, scope);
25
+ }
26
+ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope) {
27
+ assertAllowedScope(scope, this.allowedScopes);
28
+ return this.capsuleStore.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope);
29
+ }
30
+ appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
31
+ assertAllowedScope(scope, this.allowedScopes);
32
+ return this.capsuleStore.appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
33
+ }
34
+ readCapsuleArray(contractAddress, baseSlot, jobId, scope) {
35
+ assertAllowedScope(scope, this.allowedScopes);
36
+ return this.capsuleStore.readCapsuleArray(contractAddress, baseSlot, jobId, scope);
37
+ }
38
+ setCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
39
+ assertAllowedScope(scope, this.allowedScopes);
40
+ return this.capsuleStore.setCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
41
+ }
42
+ }
43
+ function assertAllowedScope(scope, allowedScopes) {
44
+ if (scope.equals(AztecAddress.ZERO)) {
45
+ return;
46
+ }
47
+ if (!allowedScopes.some((allowed)=>allowed.equals(scope))) {
48
+ throw new Error(`Scope ${scope.toString()} is not in the allowed scopes list: [${allowedScopes.map((s)=>s.toString()).join(', ')}]. See https://docs.aztec.network/errors/10`);
49
+ }
50
+ }
@@ -0,0 +1,72 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { type Logger } from '@aztec/foundation/log';
3
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
6
+ export declare class CapsuleStore implements StagedStore {
7
+ #private;
8
+ readonly storeName = "capsule";
9
+ logger: Logger;
10
+ constructor(store: AztecAsyncKVStore);
11
+ /**
12
+ * Commits staged data to main storage.
13
+ * Called by JobCoordinator when a job completes successfully.
14
+ * Note: JobCoordinator wraps all commits in a single transaction, so we don't
15
+ * need our own transactionAsync here (and using one would deadlock on IndexedDB).
16
+ * @param jobId - The jobId identifying which staged data to commit
17
+ */
18
+ commit(jobId: string): Promise<void>;
19
+ /**
20
+ * Discards staged data without committing.
21
+ */
22
+ discardStaged(jobId: string): Promise<void>;
23
+ /**
24
+ * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
25
+ * * If data was already stored at this slot, it is overwritten.
26
+ * @param contractAddress - The contract address to scope the data under.
27
+ * @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
28
+ * @param capsule - An array of field elements representing the capsule.
29
+ * @param jobId - The context in which this store will be visible until PXE decides to persist it to underlying KV store
30
+ * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
31
+ * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
32
+ * network state it's backed by local PXE db.
33
+ */
34
+ setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress): void;
35
+ /**
36
+ * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
37
+ * @param contractAddress - The contract address under which the data is scoped.
38
+ * @param slot - The slot in the database to read.
39
+ * @returns The stored data or `null` if no data is stored under the slot.
40
+ */
41
+ getCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[] | null>;
42
+ /**
43
+ * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
44
+ * @param contractAddress - The contract address under which the data is scoped.
45
+ * @param slot - The slot in the database to delete.
46
+ */
47
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr, jobId: string, scope: AztecAddress): void;
48
+ /**
49
+ * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
50
+ * structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
51
+ * Supports overlapping source and destination regions (which will result in the overlapped source values being
52
+ * overwritten). All copied slots must exist in the database (i.e. have been stored and not deleted)
53
+ *
54
+ * @param contractAddress - The contract address under which the data is scoped.
55
+ * @param srcSlot - The first slot to copy from.
56
+ * @param dstSlot - The first slot to copy to.
57
+ * @param numEntries - The number of entries to copy.
58
+ */
59
+ copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number, jobId: string, scope: AztecAddress): Promise<void>;
60
+ /**
61
+ * Appends multiple capsules to a capsule array stored at the base slot.
62
+ * The array length is stored at the base slot, and elements are stored in consecutive slots after it.
63
+ * All operations are performed in a single transaction.
64
+ * @param contractAddress - The contract address that owns the capsule array
65
+ * @param baseSlot - The slot where the array length is stored
66
+ * @param content - Array of capsule data to append
67
+ */
68
+ appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
69
+ readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, jobId: string, scope: AztecAddress): Promise<Fr[][]>;
70
+ setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][], jobId: string, scope: AztecAddress): Promise<void>;
71
+ }
72
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2Fwc3VsZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvY2Fwc3VsZV9zdG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OAAO,EAAE,EAAE,EACX,OAAO,EAAE,EAAE,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CA2Bf;IAED;;;;;;;OAOG;IACH,oBAAoB,CAClB,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,EAAE,EACZ,OAAO,EAAE,EAAE,EAAE,EAAE,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAqBf;IAED,gBAAgB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CA2BjH;IAED,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,iBA2B/G;CACF"}
@@ -0,0 +1,261 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ export class CapsuleStore {
4
+ storeName = 'capsule';
5
+ #store;
6
+ // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${scope}:${key}`, using the zero
7
+ // address for the global scope.
8
+ #capsules;
9
+ // jobId => `${contractAddress}:${scope}:${key}` => capsule data
10
+ // when `#stagedCapsules.get('some-job-id').get('${some-contract-address}:${some-scope}:${some-key}') === null`,
11
+ // it signals that the capsule was deleted during the job, so it needs to be deleted on commit
12
+ #stagedCapsules;
13
+ logger;
14
+ constructor(store){
15
+ this.#store = store;
16
+ this.#capsules = this.#store.openMap('capsules');
17
+ this.#stagedCapsules = new Map();
18
+ this.logger = createLogger('pxe:capsule-data-provider');
19
+ }
20
+ /**
21
+ * Given a job denoted by `jobId`, it returns the
22
+ * capsules that said job has interacted with.
23
+ *
24
+ * Capsules that haven't been committed to persistence KV storage
25
+ * are kept in-memory in `#stagedCapsules`, this method provides a convenient
26
+ * way to access that in-memory collection of data.
27
+ *
28
+ * @param jobId
29
+ * @returns
30
+ */ #getJobStagedCapsules(jobId) {
31
+ let jobStagedCapsules = this.#stagedCapsules.get(jobId);
32
+ if (!jobStagedCapsules) {
33
+ jobStagedCapsules = new Map();
34
+ this.#stagedCapsules.set(jobId, jobStagedCapsules);
35
+ }
36
+ return jobStagedCapsules;
37
+ }
38
+ /**
39
+ * Reads a capsule's slot from the staged version of the data associated to the given jobId.
40
+ *
41
+ * If it is not there, it reads it from the KV store.
42
+ */ async #getFromStage(jobId, dbSlotKey) {
43
+ const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
44
+ const staged = jobStagedCapsules.get(dbSlotKey);
45
+ // Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
46
+ // keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
47
+ // requests). The staged value still takes precedence if it exists (including null for deletions).
48
+ const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
49
+ return staged !== undefined ? staged : dbValue;
50
+ }
51
+ /**
52
+ * Writes a capsule to the stage of a job.
53
+ */ #setOnStage(jobId, dbSlotKey, capsuleData) {
54
+ this.#getJobStagedCapsules(jobId).set(dbSlotKey, capsuleData);
55
+ }
56
+ /**
57
+ * Deletes a capsule on the stage of a job. Note the capsule will still
58
+ * exist in storage until the job is committed.
59
+ */ #deleteOnStage(jobId, dbSlotKey) {
60
+ this.#getJobStagedCapsules(jobId).set(dbSlotKey, null);
61
+ }
62
+ async #loadCapsuleFromDb(dbSlotKey) {
63
+ const dataBuffer = await this.#capsules.getAsync(dbSlotKey);
64
+ if (!dataBuffer) {
65
+ return null;
66
+ }
67
+ return dataBuffer;
68
+ }
69
+ /**
70
+ * Commits staged data to main storage.
71
+ * Called by JobCoordinator when a job completes successfully.
72
+ * Note: JobCoordinator wraps all commits in a single transaction, so we don't
73
+ * need our own transactionAsync here (and using one would deadlock on IndexedDB).
74
+ * @param jobId - The jobId identifying which staged data to commit
75
+ */ async commit(jobId) {
76
+ const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
77
+ for (const [key, value] of jobStagedCapsules){
78
+ // In the write stage, we represent deleted capsules with null
79
+ // (as opposed to undefined, which denotes there was never a capsule there to begin with).
80
+ // So we delete from actual KV store here.
81
+ if (value === null) {
82
+ await this.#capsules.delete(key);
83
+ } else {
84
+ await this.#capsules.set(key, value);
85
+ }
86
+ }
87
+ this.#stagedCapsules.delete(jobId);
88
+ }
89
+ /**
90
+ * Discards staged data without committing.
91
+ */ discardStaged(jobId) {
92
+ this.#stagedCapsules.delete(jobId);
93
+ return Promise.resolve();
94
+ }
95
+ /**
96
+ * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
97
+ * * If data was already stored at this slot, it is overwritten.
98
+ * @param contractAddress - The contract address to scope the data under.
99
+ * @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
100
+ * @param capsule - An array of field elements representing the capsule.
101
+ * @param jobId - The context in which this store will be visible until PXE decides to persist it to underlying KV store
102
+ * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
103
+ * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
104
+ * network state it's backed by local PXE db.
105
+ */ setCapsule(contractAddress, slot, capsule, jobId, scope) {
106
+ const dbSlotKey = dbSlotToKey(contractAddress, slot, scope);
107
+ // A store overrides any pre-existing data on the slot
108
+ this.#setOnStage(jobId, dbSlotKey, Buffer.concat(capsule.map((value)=>value.toBuffer())));
109
+ }
110
+ /**
111
+ * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
112
+ * @param contractAddress - The contract address under which the data is scoped.
113
+ * @param slot - The slot in the database to read.
114
+ * @returns The stored data or `null` if no data is stored under the slot.
115
+ */ getCapsule(contractAddress, slot, jobId, scope) {
116
+ return this.#store.transactionAsync(()=>this.#getCapsuleInternal(contractAddress, slot, jobId, scope));
117
+ }
118
+ /** Same as getCapsule but without its own transaction, for use inside an existing transactionAsync. */ async #getCapsuleInternal(contractAddress, slot, jobId, scope) {
119
+ const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot, scope));
120
+ if (!dataBuffer) {
121
+ this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
122
+ return null;
123
+ }
124
+ const capsule = [];
125
+ for(let i = 0; i < dataBuffer.length; i += Fr.SIZE_IN_BYTES){
126
+ capsule.push(Fr.fromBuffer(dataBuffer.subarray(i, i + Fr.SIZE_IN_BYTES)));
127
+ }
128
+ return capsule;
129
+ }
130
+ /**
131
+ * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
132
+ * @param contractAddress - The contract address under which the data is scoped.
133
+ * @param slot - The slot in the database to delete.
134
+ */ deleteCapsule(contractAddress, slot, jobId, scope) {
135
+ // When we commit this, we will interpret null as a deletion, so we'll propagate the delete to the KV store
136
+ this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot, scope));
137
+ }
138
+ /**
139
+ * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
140
+ * structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
141
+ * Supports overlapping source and destination regions (which will result in the overlapped source values being
142
+ * overwritten). All copied slots must exist in the database (i.e. have been stored and not deleted)
143
+ *
144
+ * @param contractAddress - The contract address under which the data is scoped.
145
+ * @param srcSlot - The first slot to copy from.
146
+ * @param dstSlot - The first slot to copy to.
147
+ * @param numEntries - The number of entries to copy.
148
+ */ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId, scope) {
149
+ // This transactional context gives us "copy atomicity":
150
+ // there shouldn't be concurrent writes to what's being copied here.
151
+ // Equally important: this in practice is expected to perform thousands of DB operations
152
+ // and not using a transaction here would heavily impact performance.
153
+ return this.#store.transactionAsync(async ()=>{
154
+ // In order to support overlapping source and destination regions, we need to check the relative positions of source
155
+ // and destination. If destination is ahead of source, then by the time we overwrite source elements using forward
156
+ // indexes we'll have already read those. On the contrary, if source is ahead of destination we need to use backward
157
+ // indexes to avoid reading elements that've been overwritten.
158
+ const indexes = Array.from(Array(numEntries).keys());
159
+ if (srcSlot.lt(dstSlot)) {
160
+ indexes.reverse();
161
+ }
162
+ for (const i of indexes){
163
+ const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)), scope);
164
+ const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)), scope);
165
+ const toCopy = await this.#getFromStage(jobId, currentSrcSlot);
166
+ if (!toCopy) {
167
+ throw new Error(`Attempted to copy empty slot ${currentSrcSlot} for contract ${contractAddress.toString()}`);
168
+ }
169
+ this.#setOnStage(jobId, currentDstSlot, toCopy);
170
+ }
171
+ });
172
+ }
173
+ /**
174
+ * Appends multiple capsules to a capsule array stored at the base slot.
175
+ * The array length is stored at the base slot, and elements are stored in consecutive slots after it.
176
+ * All operations are performed in a single transaction.
177
+ * @param contractAddress - The contract address that owns the capsule array
178
+ * @param baseSlot - The slot where the array length is stored
179
+ * @param content - Array of capsule data to append
180
+ */ appendToCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
181
+ // We wrap this in a transaction to serialize concurrent calls from Promise.all.
182
+ // Without this, concurrent appends to the same array could race: both read length=0,
183
+ // both write at the same slots, one overwrites the other.
184
+ // Equally important: this in practice is expected to perform thousands of DB operations
185
+ // and not using a transaction here would heavily impact performance.
186
+ return this.#store.transactionAsync(async ()=>{
187
+ // Load current length, defaulting to 0 if not found
188
+ const lengthData = await this.#getCapsuleInternal(contractAddress, baseSlot, jobId, scope);
189
+ const currentLength = lengthData ? lengthData[0].toNumber() : 0;
190
+ // Store each capsule at consecutive slots after baseSlot + 1 + currentLength
191
+ for(let i = 0; i < content.length; i++){
192
+ const nextSlot = arraySlot(baseSlot, currentLength + i);
193
+ this.setCapsule(contractAddress, nextSlot, content[i], jobId, scope);
194
+ }
195
+ // Update length to include all new capsules
196
+ const newLength = currentLength + content.length;
197
+ this.setCapsule(contractAddress, baseSlot, [
198
+ new Fr(newLength)
199
+ ], jobId, scope);
200
+ });
201
+ }
202
+ readCapsuleArray(contractAddress, baseSlot, jobId, scope) {
203
+ // I'm leaving this transactional context here though because I'm assuming this
204
+ // gives us "read array atomicity": there shouldn't be concurrent writes to what's being copied
205
+ // here.
206
+ // This is one point we should revisit in the future if we want to relax the concurrency
207
+ // of jobs: different calls running concurrently on the same contract may cause trouble.
208
+ return this.#store.transactionAsync(async ()=>{
209
+ // Load length, defaulting to 0 if not found
210
+ const maybeLength = await this.#getCapsuleInternal(contractAddress, baseSlot, jobId, scope);
211
+ const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
212
+ const values = [];
213
+ // Read each capsule at consecutive slots after baseSlot
214
+ for(let i = 0; i < length; i++){
215
+ const currentValue = await this.#getCapsuleInternal(contractAddress, arraySlot(baseSlot, i), jobId, scope);
216
+ if (currentValue == undefined) {
217
+ throw new Error(`Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`);
218
+ }
219
+ values.push(currentValue);
220
+ }
221
+ return values;
222
+ });
223
+ }
224
+ setCapsuleArray(contractAddress, baseSlot, content, jobId, scope) {
225
+ // This transactional context in theory isn't so critical now because we aren't
226
+ // writing to DB so if there's exceptions midway and it blows up, no visible impact
227
+ // to persistent storage will happen.
228
+ // I'm leaving this transactional context here though because I'm assuming this
229
+ // gives us "write array atomicity": there shouldn't be concurrent writes to what's being copied
230
+ // here.
231
+ // This is one point we should revisit in the future if we want to relax the concurrency
232
+ // of jobs: different calls running concurrently on the same contract may cause trouble.
233
+ return this.#store.transactionAsync(async ()=>{
234
+ // Load current length, defaulting to 0 if not found
235
+ const maybeLength = await this.#getCapsuleInternal(contractAddress, baseSlot, jobId, scope);
236
+ const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
237
+ // Set the new length
238
+ this.setCapsule(contractAddress, baseSlot, [
239
+ new Fr(content.length)
240
+ ], jobId, scope);
241
+ // Store the new content, possibly overwriting existing values
242
+ for(let i = 0; i < content.length; i++){
243
+ this.setCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId, scope);
244
+ }
245
+ // Clear any stragglers
246
+ for(let i = content.length; i < originalLength; i++){
247
+ this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId, scope);
248
+ }
249
+ });
250
+ }
251
+ }
252
+ function dbSlotToKey(contractAddress, slot, scope) {
253
+ return [
254
+ contractAddress.toString(),
255
+ scope.toString(),
256
+ slot.toString()
257
+ ].join(':');
258
+ }
259
+ function arraySlot(baseSlot, index) {
260
+ return baseSlot.add(new Fr(1)).add(new Fr(index));
261
+ }
@@ -0,0 +1,3 @@
1
+ export { CapsuleService } from './capsule_service.js';
2
+ export { CapsuleStore } from './capsule_store.js';
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL2NhcHN1bGVfc3RvcmUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3RELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/capsule_store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { CapsuleService } from './capsule_service.js';
2
+ export { CapsuleStore } from './capsule_store.js';