@aztec/pxe 0.0.1-commit.03f7ef2 → 0.0.1-commit.0b941701

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 (328) hide show
  1. package/dest/bin/check_oracle_version.js +1 -1
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +14 -10
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +72 -32
  5. package/dest/config/index.d.ts +3 -1
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +17 -0
  8. package/dest/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  10. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  11. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts +28 -27
  13. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/contract_function_simulator.js +56 -40
  15. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  16. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  18. package/dest/contract_function_simulator/index.d.ts +2 -2
  19. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/index.js +1 -1
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +6 -3
  24. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
  25. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
  26. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  27. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  29. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -11
  30. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  32. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  34. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  36. package/dest/contract_function_simulator/oracle/oracle.d.ts +10 -8
  37. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/oracle.js +43 -32
  39. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  40. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/private_execution.js +1 -37
  42. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +26 -26
  43. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +28 -41
  45. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +44 -34
  46. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +92 -92
  48. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  49. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  50. package/dest/contract_function_simulator/proxied_contract_data_source.js +5 -5
  51. package/dest/contract_sync/index.d.ts +23 -0
  52. package/dest/contract_sync/index.d.ts.map +1 -0
  53. package/dest/contract_sync/index.js +54 -0
  54. package/dest/debug/pxe_debug_utils.d.ts +6 -6
  55. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  56. package/dest/debug/pxe_debug_utils.js +8 -7
  57. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  58. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  59. package/dest/entrypoints/client/bundle/utils.js +10 -1
  60. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  61. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  62. package/dest/entrypoints/client/lazy/utils.js +10 -1
  63. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  64. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  65. package/dest/entrypoints/server/index.d.ts +3 -1
  66. package/dest/entrypoints/server/index.d.ts.map +1 -1
  67. package/dest/entrypoints/server/index.js +2 -0
  68. package/dest/entrypoints/server/utils.d.ts +1 -1
  69. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  70. package/dest/entrypoints/server/utils.js +11 -7
  71. package/dest/error_enriching.d.ts +4 -4
  72. package/dest/error_enriching.d.ts.map +1 -1
  73. package/dest/error_enriching.js +6 -6
  74. package/dest/events/event_service.d.ts +8 -7
  75. package/dest/events/event_service.d.ts.map +1 -1
  76. package/dest/events/event_service.js +22 -24
  77. package/dest/events/private_event_filter_validator.d.ts +6 -6
  78. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  79. package/dest/events/private_event_filter_validator.js +5 -6
  80. package/dest/job_coordinator/job_coordinator.d.ts +74 -0
  81. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  82. package/dest/job_coordinator/job_coordinator.js +93 -0
  83. package/dest/logs/log_service.d.ts +15 -31
  84. package/dest/logs/log_service.d.ts.map +1 -1
  85. package/dest/logs/log_service.js +77 -188
  86. package/dest/notes/note_service.d.ts +10 -9
  87. package/dest/notes/note_service.d.ts.map +1 -1
  88. package/dest/notes/note_service.js +40 -44
  89. package/dest/oracle_version.d.ts +3 -3
  90. package/dest/oracle_version.d.ts.map +1 -1
  91. package/dest/oracle_version.js +4 -3
  92. package/dest/private_kernel/hints/index.d.ts +2 -2
  93. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  94. package/dest/private_kernel/hints/index.js +1 -1
  95. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  96. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  97. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +13 -7
  98. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  99. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  100. package/dest/private_kernel/private_kernel_execution_prover.js +4 -5
  101. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
  102. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  103. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  104. package/dest/pxe.d.ts +17 -44
  105. package/dest/pxe.d.ts.map +1 -1
  106. package/dest/pxe.js +131 -147
  107. package/dest/storage/address_store/address_store.d.ts +11 -0
  108. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  109. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +1 -1
  110. package/dest/storage/address_store/index.d.ts +2 -0
  111. package/dest/storage/address_store/index.d.ts.map +1 -0
  112. package/dest/storage/address_store/index.js +1 -0
  113. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -0
  114. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  115. package/dest/storage/{anchor_block_data_provider/anchor_block_data_provider.js → anchor_block_store/anchor_block_store.js} +1 -1
  116. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  117. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  118. package/dest/storage/anchor_block_store/index.js +1 -0
  119. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  120. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  121. package/dest/storage/capsule_store/capsule_store.js +255 -0
  122. package/dest/storage/capsule_store/index.d.ts +2 -0
  123. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  124. package/dest/storage/capsule_store/index.js +1 -0
  125. package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +3 -3
  126. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  127. package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +2 -2
  128. package/dest/storage/contract_store/index.d.ts +2 -0
  129. package/dest/storage/contract_store/index.d.ts.map +1 -0
  130. package/dest/storage/contract_store/index.js +1 -0
  131. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  132. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  133. package/dest/storage/index.d.ts +8 -8
  134. package/dest/storage/index.d.ts.map +1 -1
  135. package/dest/storage/index.js +7 -7
  136. package/dest/storage/note_store/index.d.ts +3 -0
  137. package/dest/storage/note_store/index.d.ts.map +1 -0
  138. package/dest/storage/note_store/index.js +2 -0
  139. package/dest/storage/note_store/note_store.d.ts +73 -0
  140. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  141. package/dest/storage/note_store/note_store.js +303 -0
  142. package/dest/storage/note_store/stored_note.d.ts +16 -0
  143. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  144. package/dest/storage/note_store/stored_note.js +43 -0
  145. package/dest/storage/private_event_store/private_event_store.d.ts +91 -0
  146. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  147. package/dest/storage/private_event_store/private_event_store.js +250 -0
  148. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  149. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  150. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  151. package/dest/storage/tagging_store/index.d.ts +4 -0
  152. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  153. package/dest/storage/tagging_store/index.js +3 -0
  154. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
  155. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  156. package/dest/storage/tagging_store/recipient_tagging_store.js +99 -0
  157. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  158. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  159. package/dest/storage/tagging_store/sender_address_book_store.js +30 -0
  160. package/dest/storage/{tagging_data_provider/sender_tagging_data_provider.d.ts → tagging_store/sender_tagging_store.d.ts} +19 -9
  161. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  162. package/dest/storage/{tagging_data_provider/sender_tagging_data_provider.js → tagging_store/sender_tagging_store.js} +111 -29
  163. package/dest/tagging/constants.d.ts +2 -2
  164. package/dest/tagging/constants.d.ts.map +1 -1
  165. package/dest/tagging/constants.js +10 -3
  166. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  167. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  168. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  169. package/dest/tagging/index.d.ts +15 -3
  170. package/dest/tagging/index.d.ts.map +1 -1
  171. package/dest/tagging/index.js +14 -2
  172. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +4 -3
  173. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  174. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +8 -8
  175. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  176. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  177. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  178. package/dest/tagging/{sync → sender_sync}/sync_sender_tagging_indexes.d.ts +4 -4
  179. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  180. package/dest/tagging/{sync → sender_sync}/sync_sender_tagging_indexes.js +8 -23
  181. package/dest/tagging/{sync → sender_sync}/utils/get_status_change_of_pending.d.ts +1 -1
  182. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  183. package/dest/tagging/{sync → sender_sync}/utils/get_status_change_of_pending.js +5 -8
  184. package/dest/tagging/{sync → sender_sync}/utils/load_and_store_new_tagging_indexes.d.ts +7 -4
  185. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  186. package/dest/tagging/{sync → sender_sync}/utils/load_and_store_new_tagging_indexes.js +12 -7
  187. package/package.json +18 -18
  188. package/src/bin/check_oracle_version.ts +1 -0
  189. package/src/block_synchronizer/block_synchronizer.ts +83 -34
  190. package/src/config/index.ts +14 -0
  191. package/src/config/package_info.ts +1 -1
  192. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  193. package/src/contract_function_simulator/contract_function_simulator.ts +79 -64
  194. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  195. package/src/contract_function_simulator/index.ts +1 -1
  196. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +5 -1
  197. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
  198. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  199. package/src/contract_function_simulator/oracle/interfaces.ts +20 -10
  200. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  201. package/src/contract_function_simulator/oracle/oracle.ts +56 -41
  202. package/src/contract_function_simulator/oracle/private_execution.ts +1 -69
  203. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +77 -78
  204. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +121 -105
  205. package/src/contract_function_simulator/proxied_contract_data_source.ts +7 -7
  206. package/src/contract_sync/index.ts +98 -0
  207. package/src/debug/pxe_debug_utils.ts +7 -6
  208. package/src/entrypoints/client/bundle/utils.ts +7 -1
  209. package/src/entrypoints/client/lazy/utils.ts +7 -2
  210. package/src/entrypoints/pxe_creation_options.ts +2 -1
  211. package/src/entrypoints/server/index.ts +2 -0
  212. package/src/entrypoints/server/utils.ts +11 -15
  213. package/src/error_enriching.ts +7 -15
  214. package/src/events/event_service.ts +23 -27
  215. package/src/events/private_event_filter_validator.ts +4 -6
  216. package/src/job_coordinator/job_coordinator.ts +149 -0
  217. package/src/logs/log_service.ts +116 -260
  218. package/src/notes/note_service.ts +43 -46
  219. package/src/oracle_version.ts +4 -3
  220. package/src/private_kernel/hints/index.ts +1 -1
  221. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +33 -22
  222. package/src/private_kernel/private_kernel_execution_prover.ts +3 -5
  223. package/src/private_kernel/private_kernel_oracle.ts +116 -36
  224. package/src/pxe.ts +189 -190
  225. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +1 -1
  226. package/src/storage/address_store/index.ts +1 -0
  227. package/src/storage/{anchor_block_data_provider/anchor_block_data_provider.ts → anchor_block_store/anchor_block_store.ts} +1 -1
  228. package/src/storage/anchor_block_store/index.ts +1 -0
  229. package/src/storage/capsule_store/capsule_store.ts +315 -0
  230. package/src/storage/capsule_store/index.ts +1 -0
  231. package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +2 -2
  232. package/src/storage/contract_store/index.ts +1 -0
  233. package/src/storage/index.ts +7 -7
  234. package/src/storage/note_store/index.ts +2 -0
  235. package/src/storage/note_store/note_store.ts +381 -0
  236. package/src/storage/note_store/stored_note.ts +48 -0
  237. package/src/storage/private_event_store/private_event_store.ts +363 -0
  238. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  239. package/src/storage/tagging_store/index.ts +3 -0
  240. package/src/storage/tagging_store/recipient_tagging_store.ts +129 -0
  241. package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
  242. package/src/storage/{tagging_data_provider/sender_tagging_data_provider.ts → tagging_store/sender_tagging_store.ts} +129 -28
  243. package/src/tagging/constants.ts +10 -3
  244. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  245. package/src/tagging/index.ts +17 -2
  246. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +23 -9
  247. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  248. package/src/tagging/{sync → sender_sync}/sync_sender_tagging_indexes.ts +12 -25
  249. package/src/tagging/{sync → sender_sync}/utils/get_status_change_of_pending.ts +5 -13
  250. package/src/tagging/{sync → sender_sync}/utils/load_and_store_new_tagging_indexes.ts +19 -7
  251. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  252. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  253. package/dest/contract_function_simulator/proxied_node.js +0 -27
  254. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  255. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  256. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  257. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  258. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  259. package/dest/public_storage/public_storage_service.d.ts +0 -24
  260. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  261. package/dest/public_storage/public_storage_service.js +0 -26
  262. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  263. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  264. package/dest/storage/address_data_provider/index.d.ts +0 -2
  265. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  266. package/dest/storage/address_data_provider/index.js +0 -1
  267. package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts +0 -9
  268. package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts.map +0 -1
  269. package/dest/storage/anchor_block_data_provider/index.d.ts +0 -2
  270. package/dest/storage/anchor_block_data_provider/index.d.ts.map +0 -1
  271. package/dest/storage/anchor_block_data_provider/index.js +0 -1
  272. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -57
  273. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  274. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -146
  275. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  276. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  277. package/dest/storage/capsule_data_provider/index.js +0 -1
  278. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  279. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  280. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  281. package/dest/storage/contract_data_provider/index.js +0 -1
  282. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  283. package/dest/storage/note_data_provider/index.d.ts +0 -3
  284. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  285. package/dest/storage/note_data_provider/index.js +0 -2
  286. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -84
  287. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  288. package/dest/storage/note_data_provider/note_data_provider.js +0 -322
  289. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -51
  290. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  291. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -115
  292. package/dest/storage/tagging_data_provider/index.d.ts +0 -3
  293. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  294. package/dest/storage/tagging_data_provider/index.js +0 -2
  295. package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts +0 -31
  296. package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts.map +0 -1
  297. package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.js +0 -65
  298. package/dest/storage/tagging_data_provider/sender_tagging_data_provider.d.ts.map +0 -1
  299. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts +0 -21
  300. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts.map +0 -1
  301. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.js +0 -42
  302. package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts.map +0 -1
  303. package/dest/tagging/sync/utils/get_status_change_of_pending.d.ts.map +0 -1
  304. package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts.map +0 -1
  305. package/dest/tagging/utils.d.ts +0 -18
  306. package/dest/tagging/utils.d.ts.map +0 -1
  307. package/dest/tagging/utils.js +0 -25
  308. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  309. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  310. package/dest/tree_membership/tree_membership_service.js +0 -84
  311. package/src/contract_function_simulator/proxied_node.ts +0 -33
  312. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
  313. package/src/public_storage/public_storage_service.ts +0 -33
  314. package/src/storage/address_data_provider/index.ts +0 -1
  315. package/src/storage/anchor_block_data_provider/index.ts +0 -1
  316. package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -179
  317. package/src/storage/capsule_data_provider/index.ts +0 -1
  318. package/src/storage/contract_data_provider/index.ts +0 -1
  319. package/src/storage/note_data_provider/index.ts +0 -2
  320. package/src/storage/note_data_provider/note_data_provider.ts +0 -412
  321. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -162
  322. package/src/storage/tagging_data_provider/index.ts +0 -2
  323. package/src/storage/tagging_data_provider/recipient_tagging_data_provider.ts +0 -86
  324. package/src/tagging/recipient_sync/new_recipient_tagging_data_provider.ts +0 -53
  325. package/src/tagging/utils.ts +0 -32
  326. package/src/tree_membership/tree_membership_service.ts +0 -112
  327. /package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +0 -0
  328. /package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +0 -0
@@ -1,179 +0,0 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { type Logger, createLogger } from '@aztec/foundation/log';
3
- import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
4
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
-
6
- export class CapsuleDataProvider {
7
- #store: AztecAsyncKVStore;
8
-
9
- // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
10
- #capsules: AztecAsyncMap<string, Buffer>;
11
-
12
- logger: Logger;
13
-
14
- constructor(store: AztecAsyncKVStore) {
15
- this.#store = store;
16
-
17
- this.#capsules = this.#store.openMap('capsules');
18
-
19
- this.logger = createLogger('pxe:capsule-data-provider');
20
- }
21
-
22
- /**
23
- * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
24
- * * If data was already stored at this slot, it is overwritten.
25
- * @param contractAddress - The contract address to scope the data under.
26
- * @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
27
- * @param capsule - An array of field elements representing the capsule.
28
- * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
29
- * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
30
- * network state it's backed by local PXE db.
31
- */
32
- async storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
33
- await this.#capsules.set(dbSlotToKey(contractAddress, slot), Buffer.concat(capsule.map(value => value.toBuffer())));
34
- }
35
-
36
- /**
37
- * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
38
- * @param contractAddress - The contract address under which the data is scoped.
39
- * @param slot - The slot in the database to read.
40
- * @returns The stored data or `null` if no data is stored under the slot.
41
- */
42
- async loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
43
- const dataBuffer = await this.#capsules.getAsync(dbSlotToKey(contractAddress, slot));
44
- if (!dataBuffer) {
45
- this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
46
- return null;
47
- }
48
- const capsule: Fr[] = [];
49
- for (let i = 0; i < dataBuffer.length; i += Fr.SIZE_IN_BYTES) {
50
- capsule.push(Fr.fromBuffer(dataBuffer.subarray(i, i + Fr.SIZE_IN_BYTES)));
51
- }
52
- return capsule;
53
- }
54
-
55
- /**
56
- * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
57
- * @param contractAddress - The contract address under which the data is scoped.
58
- * @param slot - The slot in the database to delete.
59
- */
60
- async deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
61
- await this.#capsules.delete(dbSlotToKey(contractAddress, slot));
62
- }
63
-
64
- /**
65
- * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
66
- * structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
67
- * Supports overlapping source and destination regions (which will result in the overlapped source values being
68
- * overwritten). All copied slots must exist in the database (i.e. have been stored and not deleted)
69
- *
70
- * @param contractAddress - The contract address under which the data is scoped.
71
- * @param srcSlot - The first slot to copy from.
72
- * @param dstSlot - The first slot to copy to.
73
- * @param numEntries - The number of entries to copy.
74
- */
75
- copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
76
- return this.#store.transactionAsync(async () => {
77
- // In order to support overlapping source and destination regions, we need to check the relative positions of source
78
- // and destination. If destination is ahead of source, then by the time we overwrite source elements using forward
79
- // indexes we'll have already read those. On the contrary, if source is ahead of destination we need to use backward
80
- // indexes to avoid reading elements that've been overwritten.
81
-
82
- const indexes = Array.from(Array(numEntries).keys());
83
- if (srcSlot.lt(dstSlot)) {
84
- indexes.reverse();
85
- }
86
-
87
- for (const i of indexes) {
88
- const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
89
- const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
90
-
91
- const toCopy = await this.#capsules.getAsync(currentSrcSlot);
92
- if (!toCopy) {
93
- throw new Error(`Attempted to copy empty slot ${currentSrcSlot} for contract ${contractAddress.toString()}`);
94
- }
95
-
96
- await this.#capsules.set(currentDstSlot, toCopy);
97
- }
98
- });
99
- }
100
-
101
- /**
102
- * Appends multiple capsules to a capsule array stored at the base slot.
103
- * The array length is stored at the base slot, and elements are stored in consecutive slots after it.
104
- * All operations are performed in a single transaction.
105
- * @param contractAddress - The contract address that owns the capsule array
106
- * @param baseSlot - The slot where the array length is stored
107
- * @param content - Array of capsule data to append
108
- */
109
- appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][]): Promise<void> {
110
- return this.#store.transactionAsync(async () => {
111
- // Load current length, defaulting to 0 if not found
112
- const lengthData = await this.loadCapsule(contractAddress, baseSlot);
113
- const currentLength = lengthData ? lengthData[0].toNumber() : 0;
114
-
115
- // Store each capsule at consecutive slots after baseSlot + 1 + currentLength
116
- for (let i = 0; i < content.length; i++) {
117
- const nextSlot = arraySlot(baseSlot, currentLength + i);
118
- await this.storeCapsule(contractAddress, nextSlot, content[i]);
119
- }
120
-
121
- // Update length to include all new capsules
122
- const newLength = currentLength + content.length;
123
- await this.storeCapsule(contractAddress, baseSlot, [new Fr(newLength)]);
124
- });
125
- }
126
-
127
- readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr): Promise<Fr[][]> {
128
- return this.#store.transactionAsync(async () => {
129
- // Load length, defaulting to 0 if not found
130
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
131
- const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
132
-
133
- const values: Fr[][] = [];
134
-
135
- // Read each capsule at consecutive slots after baseSlot
136
- for (let i = 0; i < length; i++) {
137
- const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i));
138
- if (currentValue == undefined) {
139
- throw new Error(
140
- `Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`,
141
- );
142
- }
143
-
144
- values.push(currentValue);
145
- }
146
-
147
- return values;
148
- });
149
- }
150
-
151
- setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][]) {
152
- return this.#store.transactionAsync(async () => {
153
- // Load current length, defaulting to 0 if not found
154
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
155
- const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
156
-
157
- // Set the new length
158
- await this.storeCapsule(contractAddress, baseSlot, [new Fr(content.length)]);
159
-
160
- // Store the new content, possibly overwriting existing values
161
- for (let i = 0; i < content.length; i++) {
162
- await this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i]);
163
- }
164
-
165
- // Clear any stragglers
166
- for (let i = content.length; i < originalLength; i++) {
167
- await this.deleteCapsule(contractAddress, arraySlot(baseSlot, i));
168
- }
169
- });
170
- }
171
- }
172
-
173
- function dbSlotToKey(contractAddress: AztecAddress, slot: Fr): string {
174
- return `${contractAddress.toString()}:${slot.toString()}`;
175
- }
176
-
177
- function arraySlot(baseSlot: Fr, index: number) {
178
- return baseSlot.add(new Fr(1)).add(new Fr(index));
179
- }
@@ -1 +0,0 @@
1
- export { CapsuleDataProvider } from './capsule_data_provider.js';
@@ -1 +0,0 @@
1
- export { ContractDataProvider } from './contract_data_provider.js';
@@ -1,2 +0,0 @@
1
- export { NoteDao } from '@aztec/stdlib/note';
2
- export { NoteDataProvider } from './note_data_provider.js';
@@ -1,412 +0,0 @@
1
- import { toBufferBE } from '@aztec/foundation/bigint-buffer';
2
- import type { Fr } from '@aztec/foundation/curves/bn254';
3
- import { toArray } from '@aztec/foundation/iterable';
4
- import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
5
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import type { DataInBlock } from '@aztec/stdlib/block';
7
- import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
8
- import { NoteDao } from '@aztec/stdlib/note';
9
-
10
- /**
11
- * NoteDataProvider manages the storage and retrieval of notes.
12
- *
13
- * Notes can be active or nullified. This class processes new notes, nullifications,
14
- * and performs rollback handling in the case of a reorg.
15
- **/
16
- export class NoteDataProvider {
17
- #store: AztecAsyncKVStore;
18
- #notes: AztecAsyncMap<string, Buffer>;
19
- #nullifiedNotes: AztecAsyncMap<string, Buffer>;
20
- #nullifierToNoteId: AztecAsyncMap<string, string>;
21
- #nullifiersByBlockNumber: AztecAsyncMultiMap<number, string>;
22
-
23
- #nullifiedNotesToScope: AztecAsyncMultiMap<string, string>;
24
- #nullifiedNotesByContract: AztecAsyncMultiMap<string, string>;
25
- #nullifiedNotesByStorageSlot: AztecAsyncMultiMap<string, string>;
26
- #nullifiedNotesByNullifier: AztecAsyncMap<string, string>;
27
-
28
- #scopes: AztecAsyncMap<string, true>;
29
- #notesToScope: AztecAsyncMultiMap<string, string>;
30
- #notesByContractAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
31
- #notesByStorageSlotAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
32
-
33
- private constructor(store: AztecAsyncKVStore) {
34
- this.#store = store;
35
- this.#notes = store.openMap('notes');
36
- this.#nullifiedNotes = store.openMap('nullified_notes');
37
- this.#nullifierToNoteId = store.openMap('nullifier_to_note');
38
- this.#nullifiersByBlockNumber = store.openMultiMap('nullifier_to_block_number');
39
-
40
- this.#nullifiedNotesToScope = store.openMultiMap('nullified_notes_to_scope');
41
- this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
42
- this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
43
- this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
44
-
45
- this.#scopes = store.openMap('scopes');
46
- this.#notesToScope = store.openMultiMap('notes_to_scope');
47
- this.#notesByContractAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
48
- this.#notesByStorageSlotAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
49
- }
50
-
51
- /**
52
- * Creates and initializes a new NoteDataProvider instance.
53
- *
54
- * This factory method creates a NoteDataProvider and restores any existing
55
- * scope-specific indexes from the database.
56
- *
57
- * @param store - The key-value store to use for persistence
58
- * @returns Promise resolving to a fully initialized NoteDataProvider instance
59
- */
60
- public static async create(store: AztecAsyncKVStore): Promise<NoteDataProvider> {
61
- const pxeDB = new NoteDataProvider(store);
62
- for await (const scope of pxeDB.#scopes.keysAsync()) {
63
- pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
64
- pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
65
- }
66
- return pxeDB;
67
- }
68
-
69
- /**
70
- * Adds a new scope to the note data provider.
71
- *
72
- * Scopes provide privacy isolation by creating separate indexes for each user.
73
- * Each scope gets its own set of indexes for efficient note retrieval by various criteria.
74
- *
75
- * @param scope - The AztecAddress representing the scope/user to add
76
- * @returns Promise resolving to true if scope was added, false if it already existed
77
- */
78
- public async addScope(scope: AztecAddress): Promise<boolean> {
79
- const scopeString = scope.toString();
80
-
81
- if (await this.#scopes.hasAsync(scopeString)) {
82
- return false;
83
- }
84
-
85
- await this.#scopes.set(scopeString, true);
86
- this.#notesByContractAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_contract`));
87
- this.#notesByStorageSlotAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_storage_slot`));
88
-
89
- return true;
90
- }
91
-
92
- /**
93
- * Adds multiple notes to the data provider under the specified scope.
94
- *
95
- * Notes are stored using their index from the notes hash tree as the key, which provides
96
- * uniqueness and maintains creation order. Each note is indexed by multiple criteria
97
- * for efficient retrieval.
98
- *
99
- * @param notes - Notes to store
100
- * @param scope - The scope (user/account) under which to store the notes
101
- */
102
- addNotes(notes: NoteDao[], scope: AztecAddress): Promise<void> {
103
- return this.#store.transactionAsync(async () => {
104
- if (!(await this.#scopes.hasAsync(scope.toString()))) {
105
- await this.addScope(scope);
106
- }
107
-
108
- for (const dao of notes) {
109
- const noteIndex = toBufferBE(dao.index, 32).toString('hex');
110
- await this.#notes.set(noteIndex, dao.toBuffer());
111
- await this.#notesToScope.set(noteIndex, scope.toString());
112
- await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
113
-
114
- await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
115
- await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
116
- }
117
- });
118
- }
119
-
120
- /**
121
- * Synchronizes notes and nullifiers to a specific block number.
122
- *
123
- * This method ensures that the state of notes and nullifiers is consistent with the
124
- * specified block number. It restores any notes that were nullified after the given block
125
- * and deletes any active notes created after that block.
126
- *
127
- * @param blockNumber - The new chain tip after a reorg
128
- * @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
129
- */
130
- public async rollbackNotesAndNullifiers(blockNumber: number, synchedBlockNumber: number): Promise<void> {
131
- await this.#rewindNullifiersAfterBlock(blockNumber, synchedBlockNumber);
132
- await this.#deleteActiveNotesAfterBlock(blockNumber);
133
- }
134
-
135
- /**
136
- * Deletes (removes) all active notes created after the specified block number.
137
- *
138
- * Permanently delete notes from the active notes store, e.g. during a reorg.
139
- * Note: This only affects #notes (active notes), not #nullifiedNotes.
140
- *
141
- * @param blockNumber - Notes created after this block number will be deleted
142
- */
143
- #deleteActiveNotesAfterBlock(blockNumber: number): Promise<void> {
144
- return this.#store.transactionAsync(async () => {
145
- const notes = await toArray(this.#notes.valuesAsync());
146
- for (const note of notes) {
147
- const noteDao = NoteDao.fromBuffer(note);
148
- if (noteDao.l2BlockNumber > blockNumber) {
149
- const noteIndex = toBufferBE(noteDao.index, 32).toString('hex');
150
- await this.#notes.delete(noteIndex);
151
- await this.#notesToScope.delete(noteIndex);
152
- await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
153
- const scopes = await toArray(this.#scopes.keysAsync());
154
- for (const scope of scopes) {
155
- await this.#notesByContractAndScope.get(scope)!.deleteValue(noteDao.contractAddress.toString(), noteIndex);
156
- await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(noteDao.storageSlot.toString(), noteIndex);
157
- }
158
- }
159
- }
160
- });
161
- }
162
-
163
- /**
164
- * Rewinds nullifications after a given block number.
165
- *
166
- * This operation "unnullifies" notes, rolling back nullifications that occurred
167
- * in orphaned blocks, e.g. during a reorg. The notes are restored to the
168
- * active notes store and removed from the nullified store.
169
- *
170
- * @param blockNumber - Revert nullifications that occurred after this block
171
- * @param synchedBlockNumber - Upper bound for the block range to process
172
- */
173
- async #rewindNullifiersAfterBlock(blockNumber: number, synchedBlockNumber: number): Promise<void> {
174
- await this.#store.transactionAsync(async () => {
175
- const nullifiersToUndo: string[] = [];
176
- const currentBlockNumber = blockNumber + 1;
177
- for (let i = currentBlockNumber; i <= synchedBlockNumber; i++) {
178
- nullifiersToUndo.push(...(await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i))));
179
- }
180
- const notesIndexesToReinsert = await Promise.all(
181
- nullifiersToUndo.map(nullifier => this.#nullifiedNotesByNullifier.getAsync(nullifier)),
182
- );
183
- const notNullNoteIndexes = notesIndexesToReinsert.filter(noteIndex => noteIndex != undefined);
184
- const nullifiedNoteBuffers = await Promise.all(
185
- notNullNoteIndexes.map(noteIndex => this.#nullifiedNotes.getAsync(noteIndex!)),
186
- );
187
- const noteDaos = nullifiedNoteBuffers
188
- .filter(buffer => buffer != undefined)
189
- .map(buffer => NoteDao.fromBuffer(buffer!));
190
-
191
- for (const dao of noteDaos) {
192
- const noteIndex = toBufferBE(dao.index, 32).toString('hex');
193
- await this.#notes.set(noteIndex, dao.toBuffer());
194
- await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
195
-
196
- const scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex));
197
-
198
- if (scopes.length === 0) {
199
- // We should never run into this error because notes always have a scope assigned to them - either on initial
200
- // insertion via `addNotes` or when removing their nullifiers.
201
- throw new Error(`No scopes found for nullified note with index ${noteIndex}`);
202
- }
203
-
204
- for (const scope of scopes) {
205
- await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
206
- await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
207
- await this.#notesToScope.set(noteIndex, scope);
208
- }
209
-
210
- await this.#nullifiedNotes.delete(noteIndex);
211
- await this.#nullifiedNotesToScope.delete(noteIndex);
212
- await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
213
- await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
214
- await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
215
- await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
216
- }
217
- });
218
- }
219
-
220
- /**
221
- * Retrieves notes based on the provided filter criteria.
222
- *
223
- * This method queries both active and optionally nullified notes based on the filter
224
- * parameters.
225
- *
226
- * @param filter - Filter criteria including contractAddress (required), and optional
227
- * owner, storageSlot, status, scopes, and siloedNullifier.
228
- * @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
229
- * returned once if this is the case)
230
- * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
231
- */
232
- async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
233
- filter.status = filter.status ?? NoteStatus.ACTIVE;
234
-
235
- // throw early if scopes is an empty array
236
- if (filter.scopes !== undefined && filter.scopes.length === 0) {
237
- throw new Error(
238
- 'Trying to get notes with an empty scopes array. Scopes have to be set to undefined if intending on not filtering by scopes.',
239
- );
240
- }
241
-
242
- const candidateNoteSources = [];
243
-
244
- filter.scopes ??= (await toArray(this.#scopes.keysAsync())).map(addressString =>
245
- AztecAddress.fromString(addressString),
246
- );
247
-
248
- const activeNoteIdsPerScope: string[][] = [];
249
-
250
- for (const scope of new Set(filter.scopes)) {
251
- const formattedScopeString = scope.toString();
252
- if (!(await this.#scopes.hasAsync(formattedScopeString))) {
253
- throw new Error('Trying to get incoming notes of a scope that is not in the PXE database');
254
- }
255
-
256
- activeNoteIdsPerScope.push(
257
- filter.storageSlot
258
- ? await toArray(
259
- this.#notesByStorageSlotAndScope.get(formattedScopeString)!.getValuesAsync(filter.storageSlot.toString()),
260
- )
261
- : await toArray(
262
- this.#notesByContractAndScope
263
- .get(formattedScopeString)!
264
- .getValuesAsync(filter.contractAddress.toString()),
265
- ),
266
- );
267
- }
268
-
269
- candidateNoteSources.push({
270
- ids: new Set(activeNoteIdsPerScope.flat()),
271
- notes: this.#notes,
272
- });
273
-
274
- // If status is ACTIVE_OR_NULLIFIED we add nullified notes as candidates on top of the default active ones.
275
- if (filter.status === NoteStatus.ACTIVE_OR_NULLIFIED) {
276
- const nullifiedIds = filter.storageSlot
277
- ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
278
- : await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()));
279
-
280
- const setOfScopes = new Set(filter.scopes.map(s => s.toString() as string));
281
- const filteredNullifiedIds = new Set<string>();
282
-
283
- for (const noteId of nullifiedIds) {
284
- const scopeList = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteId));
285
- if (scopeList.some(scope => setOfScopes.has(scope))) {
286
- filteredNullifiedIds.add(noteId);
287
- }
288
- }
289
-
290
- if (filteredNullifiedIds.size > 0) {
291
- candidateNoteSources.push({
292
- ids: filteredNullifiedIds,
293
- notes: this.#nullifiedNotes,
294
- });
295
- }
296
- }
297
-
298
- const result: NoteDao[] = [];
299
- for (const { ids, notes } of candidateNoteSources) {
300
- for (const id of ids) {
301
- const serializedNote = await notes.getAsync(id);
302
- if (!serializedNote) {
303
- continue;
304
- }
305
-
306
- const note = NoteDao.fromBuffer(serializedNote);
307
- if (!note.contractAddress.equals(filter.contractAddress)) {
308
- continue;
309
- }
310
-
311
- if (filter.owner && !note.owner.equals(filter.owner)) {
312
- continue;
313
- }
314
-
315
- if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot!)) {
316
- continue;
317
- }
318
-
319
- if (filter.siloedNullifier && !note.siloedNullifier.equals(filter.siloedNullifier)) {
320
- continue;
321
- }
322
-
323
- result.push(note);
324
- }
325
- }
326
-
327
- // A note might be present in multiple scopes - we ensure it is only returned once
328
- const deduplicated: NoteDao[] = [];
329
- for (const note of result) {
330
- if (!deduplicated.some(existing => existing.equals(note))) {
331
- deduplicated.push(note);
332
- }
333
- }
334
-
335
- return deduplicated;
336
- }
337
-
338
- /**
339
- * Transitions notes from "active" to "nullified" state.
340
- *
341
- * This operation processes a batch of nullifiers to mark the corresponding notes
342
- * as spent/nullified. The operation is atomic - if any nullifier is not found,
343
- * the entire operation fails and no notes are modified.
344
- *
345
- * @param nullifiers - Array of nullifiers with their block numbers to process
346
- * @returns Promise resolving to array of nullified NoteDao objects
347
- * @throws Error if any nullifier is not found in the active notes
348
- */
349
- applyNullifiers(nullifiers: DataInBlock<Fr>[]): Promise<NoteDao[]> {
350
- if (nullifiers.length === 0) {
351
- return Promise.resolve([]);
352
- }
353
-
354
- return this.#store.transactionAsync(async () => {
355
- const nullifiedNotes: NoteDao[] = [];
356
-
357
- for (const blockScopedNullifier of nullifiers) {
358
- const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier;
359
- const nullifierKey = nullifier.toString();
360
-
361
- const noteIndex = await this.#nullifierToNoteId.getAsync(nullifierKey);
362
- if (!noteIndex) {
363
- // Check if already nullified?
364
- const alreadyNullified = await this.#nullifiedNotesByNullifier.getAsync(nullifierKey);
365
- if (alreadyNullified) {
366
- throw new Error(`Nullifier already applied in applyNullifiers`);
367
- }
368
- throw new Error('Nullifier not found in applyNullifiers');
369
- }
370
-
371
- const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
372
-
373
- if (!noteBuffer) {
374
- throw new Error('Note not found in applyNullifiers');
375
- }
376
-
377
- const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex));
378
- if (noteScopes.length === 0) {
379
- // We should never run into this error because notes always have a scope assigned to them - either on initial
380
- // insertion via `addNotes` or when removing their nullifiers.
381
- throw new Error('Note scopes are missing in applyNullifiers');
382
- }
383
-
384
- const note = NoteDao.fromBuffer(noteBuffer);
385
-
386
- nullifiedNotes.push(note);
387
-
388
- await this.#notes.delete(noteIndex);
389
- await this.#notesToScope.delete(noteIndex);
390
-
391
- const scopes = await toArray(this.#scopes.keysAsync());
392
-
393
- for (const scope of scopes) {
394
- await this.#notesByContractAndScope.get(scope)!.deleteValue(note.contractAddress.toString(), noteIndex);
395
- await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
396
- }
397
-
398
- for (const scope of noteScopes) {
399
- await this.#nullifiedNotesToScope.set(noteIndex, scope);
400
- }
401
- await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
402
- await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
403
- await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
404
- await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
405
- await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
406
-
407
- await this.#nullifierToNoteId.delete(nullifier.toString());
408
- }
409
- return nullifiedNotes;
410
- });
411
- }
412
- }