@aztec/pxe 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108

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 (379) hide show
  1. package/README.md +5 -5
  2. package/dest/bin/check_oracle_version.d.ts +1 -1
  3. package/dest/bin/check_oracle_version.js +110 -10
  4. package/dest/block_synchronizer/block_synchronizer.d.ts +39 -0
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  6. package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +23 -23
  7. package/dest/block_synchronizer/index.d.ts +2 -0
  8. package/dest/block_synchronizer/index.d.ts.map +1 -0
  9. package/dest/block_synchronizer/index.js +1 -0
  10. package/dest/config/index.d.ts +9 -17
  11. package/dest/config/index.d.ts.map +1 -1
  12. package/dest/config/index.js +10 -16
  13. package/dest/config/package_info.d.ts +1 -1
  14. package/dest/config/package_info.js +1 -1
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +44 -15
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +142 -57
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +11 -9
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +28 -17
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  23. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  24. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  25. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.d.ts +4 -2
  27. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/index.js +2 -1
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -2
  30. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +5 -4
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +8 -4
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +6 -3
  38. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +12 -3
  40. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
  41. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  42. package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
  43. package/dest/contract_function_simulator/oracle/index.d.ts +2 -2
  44. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/index.js +1 -1
  46. package/dest/contract_function_simulator/oracle/interfaces.d.ts +103 -0
  47. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  48. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  49. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -4
  50. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  52. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +10 -4
  53. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/oracle/note_packing_utils.js +10 -5
  55. package/dest/contract_function_simulator/oracle/oracle.d.ts +17 -15
  56. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  57. package/dest/contract_function_simulator/oracle/oracle.js +101 -81
  58. package/dest/contract_function_simulator/oracle/private_execution.d.ts +11 -12
  59. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  60. package/dest/contract_function_simulator/oracle/private_execution.js +15 -24
  61. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +51 -25
  62. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  63. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +103 -27
  64. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +65 -36
  65. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  66. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +171 -69
  67. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  68. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  69. package/dest/contract_function_simulator/pick_notes.js +1 -1
  70. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  71. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  72. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  73. package/dest/contract_function_simulator/proxied_node.d.ts +1 -1
  74. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -1
  75. package/dest/debug/pxe_debug_utils.d.ts +31 -0
  76. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  77. package/dest/debug/pxe_debug_utils.js +37 -0
  78. package/dest/entrypoints/client/bundle/index.d.ts +4 -3
  79. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  80. package/dest/entrypoints/client/bundle/index.js +2 -2
  81. package/dest/entrypoints/client/bundle/utils.d.ts +9 -9
  82. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/client/bundle/utils.js +21 -12
  84. package/dest/entrypoints/client/lazy/index.d.ts +4 -3
  85. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  86. package/dest/entrypoints/client/lazy/index.js +2 -2
  87. package/dest/entrypoints/client/lazy/utils.d.ts +8 -8
  88. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  89. package/dest/entrypoints/client/lazy/utils.js +20 -11
  90. package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
  91. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  92. package/dest/entrypoints/server/index.d.ts +5 -3
  93. package/dest/entrypoints/server/index.d.ts.map +1 -1
  94. package/dest/entrypoints/server/index.js +3 -2
  95. package/dest/entrypoints/server/utils.d.ts +5 -24
  96. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  97. package/dest/entrypoints/server/utils.js +17 -45
  98. package/dest/error_enriching.d.ts +11 -0
  99. package/dest/error_enriching.d.ts.map +1 -0
  100. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +9 -6
  101. package/dest/events/event_service.d.ts +15 -0
  102. package/dest/events/event_service.d.ts.map +1 -0
  103. package/dest/events/event_service.js +47 -0
  104. package/dest/events/index.d.ts +2 -0
  105. package/dest/events/index.d.ts.map +1 -0
  106. package/dest/events/index.js +1 -0
  107. package/dest/events/private_event_filter_validator.d.ts +9 -0
  108. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  109. package/dest/events/private_event_filter_validator.js +39 -0
  110. package/dest/logs/log_service.d.ts +26 -0
  111. package/dest/logs/log_service.d.ts.map +1 -0
  112. package/dest/logs/log_service.js +120 -0
  113. package/dest/notes/index.d.ts +2 -0
  114. package/dest/notes/index.d.ts.map +1 -0
  115. package/dest/notes/index.js +1 -0
  116. package/dest/notes/note_service.d.ts +48 -0
  117. package/dest/notes/note_service.d.ts.map +1 -0
  118. package/dest/notes/note_service.js +152 -0
  119. package/dest/oracle_version.d.ts +3 -3
  120. package/dest/oracle_version.js +2 -2
  121. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +3 -3
  122. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  123. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +7 -7
  124. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +1 -1
  125. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +6 -6
  126. package/dest/private_kernel/hints/index.d.ts +1 -1
  127. package/dest/private_kernel/index.d.ts +1 -1
  128. package/dest/private_kernel/private_kernel_execution_prover.d.ts +9 -2
  129. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  130. package/dest/private_kernel/private_kernel_execution_prover.js +38 -32
  131. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -2
  132. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  133. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +10 -9
  134. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  135. package/dest/private_kernel/private_kernel_oracle_impl.js +7 -7
  136. package/dest/public_storage/public_storage_service.d.ts +24 -0
  137. package/dest/public_storage/public_storage_service.d.ts.map +1 -0
  138. package/dest/public_storage/public_storage_service.js +26 -0
  139. package/dest/pxe.d.ts +232 -0
  140. package/dest/pxe.d.ts.map +1 -0
  141. package/dest/{pxe_service/pxe_service.js → pxe.js} +299 -324
  142. package/dest/storage/address_store/address_store.d.ts +11 -0
  143. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  144. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +1 -4
  145. package/dest/storage/address_store/index.d.ts +2 -0
  146. package/dest/storage/address_store/index.d.ts.map +1 -0
  147. package/dest/storage/address_store/index.js +1 -0
  148. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -0
  149. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  150. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +2 -12
  151. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  152. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  153. package/dest/storage/anchor_block_store/index.js +1 -0
  154. package/dest/storage/capsule_store/capsule_store.d.ts +57 -0
  155. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  156. package/dest/storage/{capsule_data_provider/capsule_data_provider.js → capsule_store/capsule_store.js} +34 -10
  157. package/dest/storage/capsule_store/index.d.ts +2 -0
  158. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  159. package/dest/storage/capsule_store/index.js +1 -0
  160. package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +10 -18
  161. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  162. package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +46 -18
  163. package/dest/storage/contract_store/index.d.ts +2 -0
  164. package/dest/storage/contract_store/index.d.ts.map +1 -0
  165. package/dest/storage/contract_store/index.js +1 -0
  166. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  167. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  168. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  169. package/dest/storage/index.d.ts +8 -9
  170. package/dest/storage/index.d.ts.map +1 -1
  171. package/dest/storage/index.js +7 -8
  172. package/dest/storage/metadata.d.ts +1 -1
  173. package/dest/storage/note_store/index.d.ts +3 -0
  174. package/dest/storage/note_store/index.d.ts.map +1 -0
  175. package/dest/storage/note_store/index.js +2 -0
  176. package/dest/storage/note_store/note_store.d.ts +84 -0
  177. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  178. package/dest/storage/{note_data_provider/note_data_provider.js → note_store/note_store.js} +144 -82
  179. package/dest/storage/private_event_store/private_event_store.d.ts +56 -0
  180. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  181. package/dest/storage/private_event_store/private_event_store.js +157 -0
  182. package/dest/storage/tagging_store/index.d.ts +4 -0
  183. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  184. package/dest/storage/tagging_store/index.js +3 -0
  185. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +21 -0
  186. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  187. package/dest/storage/tagging_store/recipient_tagging_store.js +42 -0
  188. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  189. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  190. package/dest/storage/tagging_store/sender_address_book_store.js +30 -0
  191. package/dest/storage/tagging_store/sender_tagging_store.d.ts +67 -0
  192. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  193. package/dest/storage/tagging_store/sender_tagging_store.js +196 -0
  194. package/dest/tagging/index.d.ts +16 -0
  195. package/dest/tagging/index.d.ts.map +1 -0
  196. package/dest/tagging/index.js +23 -0
  197. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  198. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  199. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  200. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  201. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  202. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  203. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  204. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  205. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +29 -0
  206. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +20 -0
  207. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  208. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  209. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  210. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  211. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +32 -0
  212. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
  213. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  214. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +55 -0
  215. package/dest/tree_membership/tree_membership_service.d.ts +52 -0
  216. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
  217. package/dest/tree_membership/tree_membership_service.js +84 -0
  218. package/package.json +22 -24
  219. package/src/bin/check_oracle_version.ts +134 -10
  220. package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +22 -23
  221. package/src/block_synchronizer/index.ts +1 -0
  222. package/src/config/index.ts +18 -32
  223. package/src/config/package_info.ts +1 -1
  224. package/src/contract_function_simulator/contract_function_simulator.ts +233 -75
  225. package/src/contract_function_simulator/execution_note_cache.ts +33 -17
  226. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  227. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  228. package/src/contract_function_simulator/index.ts +3 -1
  229. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  230. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
  231. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +10 -5
  232. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +14 -2
  233. package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
  234. package/src/contract_function_simulator/oracle/index.ts +1 -1
  235. package/src/contract_function_simulator/oracle/interfaces.ts +175 -0
  236. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  237. package/src/contract_function_simulator/oracle/note_packing_utils.ts +21 -5
  238. package/src/contract_function_simulator/oracle/oracle.ts +135 -80
  239. package/src/contract_function_simulator/oracle/private_execution.ts +22 -28
  240. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +200 -56
  241. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +260 -109
  242. package/src/contract_function_simulator/pick_notes.ts +1 -1
  243. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  244. package/src/debug/pxe_debug_utils.ts +48 -0
  245. package/src/entrypoints/client/bundle/index.ts +3 -2
  246. package/src/entrypoints/client/bundle/utils.ts +21 -23
  247. package/src/entrypoints/client/lazy/index.ts +3 -2
  248. package/src/entrypoints/client/lazy/utils.ts +20 -23
  249. package/src/entrypoints/pxe_creation_options.ts +4 -1
  250. package/src/entrypoints/server/index.ts +4 -2
  251. package/src/entrypoints/server/utils.ts +20 -68
  252. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +11 -15
  253. package/src/events/event_service.ts +77 -0
  254. package/src/events/index.ts +1 -0
  255. package/src/events/private_event_filter_validator.ts +48 -0
  256. package/src/logs/log_service.ts +202 -0
  257. package/src/notes/index.ts +1 -0
  258. package/src/notes/note_service.ts +200 -0
  259. package/src/oracle_version.ts +2 -2
  260. package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +5 -9
  261. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +6 -6
  262. package/src/private_kernel/private_kernel_execution_prover.ts +51 -43
  263. package/src/private_kernel/private_kernel_oracle.ts +2 -1
  264. package/src/private_kernel/private_kernel_oracle_impl.ts +10 -9
  265. package/src/public_storage/public_storage_service.ts +33 -0
  266. package/src/{pxe_service/pxe_service.ts → pxe.ts} +349 -410
  267. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +1 -7
  268. package/src/storage/address_store/index.ts +1 -0
  269. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +2 -17
  270. package/src/storage/anchor_block_store/index.ts +1 -0
  271. package/src/storage/{capsule_data_provider/capsule_data_provider.ts → capsule_store/capsule_store.ts} +34 -12
  272. package/src/storage/capsule_store/index.ts +1 -0
  273. package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +67 -28
  274. package/src/storage/contract_store/index.ts +1 -0
  275. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  276. package/src/storage/index.ts +7 -8
  277. package/src/storage/note_store/index.ts +2 -0
  278. package/src/storage/{note_data_provider/note_data_provider.ts → note_store/note_store.ts} +173 -111
  279. package/src/storage/private_event_store/private_event_store.ts +213 -0
  280. package/src/storage/tagging_store/index.ts +3 -0
  281. package/src/storage/tagging_store/recipient_tagging_store.ts +53 -0
  282. package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
  283. package/src/storage/tagging_store/sender_tagging_store.ts +244 -0
  284. package/src/tagging/index.ts +28 -0
  285. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
  286. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  287. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +43 -0
  288. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +96 -0
  289. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -0
  290. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +72 -0
  291. package/src/tree_membership/tree_membership_service.ts +112 -0
  292. package/dest/bin/index.d.ts +0 -3
  293. package/dest/bin/index.d.ts.map +0 -1
  294. package/dest/bin/index.js +0 -48
  295. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -285
  296. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  297. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  298. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +0 -87
  299. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +0 -1
  300. package/dest/contract_function_simulator/oracle/typed_oracle.js +0 -146
  301. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -158
  302. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  303. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -701
  304. package/dest/contract_function_simulator/tagging_utils.d.ts +0 -17
  305. package/dest/contract_function_simulator/tagging_utils.d.ts.map +0 -1
  306. package/dest/contract_function_simulator/tagging_utils.js +0 -23
  307. package/dest/pxe_service/error_enriching.d.ts +0 -11
  308. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  309. package/dest/pxe_service/index.d.ts +0 -3
  310. package/dest/pxe_service/index.d.ts.map +0 -1
  311. package/dest/pxe_service/index.js +0 -2
  312. package/dest/pxe_service/pxe_service.d.ts +0 -100
  313. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  314. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -13
  315. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  316. package/dest/storage/address_data_provider/index.d.ts +0 -2
  317. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  318. package/dest/storage/address_data_provider/index.js +0 -1
  319. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -27
  320. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  321. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  322. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  323. package/dest/storage/capsule_data_provider/index.js +0 -1
  324. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  325. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  326. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  327. package/dest/storage/contract_data_provider/index.js +0 -1
  328. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  329. package/dest/storage/data_provider.d.ts +0 -4
  330. package/dest/storage/data_provider.d.ts.map +0 -1
  331. package/dest/storage/data_provider.js +0 -1
  332. package/dest/storage/note_data_provider/index.d.ts +0 -3
  333. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  334. package/dest/storage/note_data_provider/index.js +0 -2
  335. package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
  336. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  337. package/dest/storage/note_data_provider/note_dao.js +0 -102
  338. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -20
  339. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  340. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
  341. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  342. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -96
  343. package/dest/storage/sync_data_provider/index.d.ts +0 -2
  344. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  345. package/dest/storage/sync_data_provider/index.js +0 -1
  346. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -12
  347. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  348. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  349. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  350. package/dest/storage/tagging_data_provider/index.js +0 -1
  351. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -18
  352. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  353. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -82
  354. package/dest/synchronizer/index.d.ts +0 -2
  355. package/dest/synchronizer/index.d.ts.map +0 -1
  356. package/dest/synchronizer/index.js +0 -1
  357. package/dest/synchronizer/synchronizer.d.ts +0 -35
  358. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  359. package/dest/test/pxe_test_suite.d.ts +0 -3
  360. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  361. package/dest/test/pxe_test_suite.js +0 -97
  362. package/src/bin/index.ts +0 -62
  363. package/src/contract_function_simulator/execution_data_provider.ts +0 -361
  364. package/src/contract_function_simulator/oracle/typed_oracle.ts +0 -289
  365. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1020
  366. package/src/contract_function_simulator/tagging_utils.ts +0 -32
  367. package/src/pxe_service/index.ts +0 -2
  368. package/src/storage/address_data_provider/index.ts +0 -1
  369. package/src/storage/capsule_data_provider/index.ts +0 -1
  370. package/src/storage/contract_data_provider/index.ts +0 -1
  371. package/src/storage/data_provider.ts +0 -3
  372. package/src/storage/note_data_provider/index.ts +0 -2
  373. package/src/storage/note_data_provider/note_dao.ts +0 -154
  374. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -134
  375. package/src/storage/sync_data_provider/index.ts +0 -1
  376. package/src/storage/tagging_data_provider/index.ts +0 -1
  377. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -123
  378. package/src/synchronizer/index.ts +0 -1
  379. package/src/test/pxe_test_suite.ts +0 -113
@@ -1,17 +1,20 @@
1
1
  import { toBufferBE } from '@aztec/foundation/bigint-buffer';
2
- import type { Fr } from '@aztec/foundation/fields';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { toArray } from '@aztec/foundation/iterable';
4
4
  import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
5
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import type { InBlock } from '@aztec/stdlib/block';
6
+ import type { DataInBlock } from '@aztec/stdlib/block';
7
7
  import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
8
-
9
- import type { DataProvider } from '../data_provider.js';
10
- import { NoteDao } from './note_dao.js';
11
-
12
- export class NoteDataProvider implements DataProvider {
8
+ import { NoteDao } from '@aztec/stdlib/note';
9
+
10
+ /**
11
+ * NoteStore 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 NoteStore {
13
17
  #store: AztecAsyncKVStore;
14
-
15
18
  #notes: AztecAsyncMap<string, Buffer>;
16
19
  #nullifiedNotes: AztecAsyncMap<string, Buffer>;
17
20
  #nullifierToNoteId: AztecAsyncMap<string, string>;
@@ -20,16 +23,12 @@ export class NoteDataProvider implements DataProvider {
20
23
  #nullifiedNotesToScope: AztecAsyncMultiMap<string, string>;
21
24
  #nullifiedNotesByContract: AztecAsyncMultiMap<string, string>;
22
25
  #nullifiedNotesByStorageSlot: AztecAsyncMultiMap<string, string>;
23
- #nullifiedNotesByTxHash: AztecAsyncMultiMap<string, string>;
24
- #nullifiedNotesByRecipient: AztecAsyncMultiMap<string, string>;
25
26
  #nullifiedNotesByNullifier: AztecAsyncMap<string, string>;
26
27
 
27
28
  #scopes: AztecAsyncMap<string, true>;
28
29
  #notesToScope: AztecAsyncMultiMap<string, string>;
29
30
  #notesByContractAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
30
31
  #notesByStorageSlotAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
31
- #notesByTxHashAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
32
- #notesByRecipientAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
33
32
 
34
33
  private constructor(store: AztecAsyncKVStore) {
35
34
  this.#store = store;
@@ -41,29 +40,41 @@ export class NoteDataProvider implements DataProvider {
41
40
  this.#nullifiedNotesToScope = store.openMultiMap('nullified_notes_to_scope');
42
41
  this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
43
42
  this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
44
- this.#nullifiedNotesByTxHash = store.openMultiMap('nullified_notes_by_tx_hash');
45
- this.#nullifiedNotesByRecipient = store.openMultiMap('nullified_notes_by_recipient');
46
43
  this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
47
44
 
48
45
  this.#scopes = store.openMap('scopes');
49
46
  this.#notesToScope = store.openMultiMap('notes_to_scope');
50
47
  this.#notesByContractAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
51
48
  this.#notesByStorageSlotAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
52
- this.#notesByTxHashAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
53
- this.#notesByRecipientAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
54
49
  }
55
50
 
56
- public static async create(store: AztecAsyncKVStore): Promise<NoteDataProvider> {
57
- const pxeDB = new NoteDataProvider(store);
51
+ /**
52
+ * Creates and initializes a new NoteStore instance.
53
+ *
54
+ * This factory method creates a NoteStore 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 NoteStore instance
59
+ */
60
+ public static async create(store: AztecAsyncKVStore): Promise<NoteStore> {
61
+ const pxeDB = new NoteStore(store);
58
62
  for await (const scope of pxeDB.#scopes.keysAsync()) {
59
63
  pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
60
64
  pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
61
- pxeDB.#notesByTxHashAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_tx_hash`));
62
- pxeDB.#notesByRecipientAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_recipient`));
63
65
  }
64
66
  return pxeDB;
65
67
  }
66
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
+ */
67
78
  public async addScope(scope: AztecAddress): Promise<boolean> {
68
79
  const scopeString = scope.toString();
69
80
 
@@ -74,23 +85,27 @@ export class NoteDataProvider implements DataProvider {
74
85
  await this.#scopes.set(scopeString, true);
75
86
  this.#notesByContractAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_contract`));
76
87
  this.#notesByStorageSlotAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_storage_slot`));
77
- this.#notesByTxHashAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_tx_hash`));
78
- this.#notesByRecipientAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_recipient`));
79
88
 
80
89
  return true;
81
90
  }
82
91
 
83
- addNotes(notes: NoteDao[], scope: AztecAddress = AztecAddress.ZERO): Promise<void> {
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> {
84
103
  return this.#store.transactionAsync(async () => {
85
104
  if (!(await this.#scopes.hasAsync(scope.toString()))) {
86
105
  await this.addScope(scope);
87
106
  }
88
107
 
89
108
  for (const dao of notes) {
90
- // store notes by their index in the notes hash tree
91
- // this provides the uniqueness we need to store individual notes
92
- // and should also return notes in the order that they were created.
93
- // Had we stored them by their nullifier, they would be returned in random order
94
109
  const noteIndex = toBufferBE(dao.index, 32).toString('hex');
95
110
  await this.#notes.set(noteIndex, dao.toBuffer());
96
111
  await this.#notesToScope.set(noteIndex, scope.toString());
@@ -98,13 +113,34 @@ export class NoteDataProvider implements DataProvider {
98
113
 
99
114
  await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
100
115
  await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
101
- await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
102
- await this.#notesByRecipientAndScope.get(scope.toString())!.set(dao.recipient.toString(), noteIndex);
103
116
  }
104
117
  });
105
118
  }
106
119
 
107
- public removeNotesAfter(blockNumber: number): Promise<void> {
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> {
108
144
  return this.#store.transactionAsync(async () => {
109
145
  const notes = await toArray(this.#notes.valuesAsync());
110
146
  for (const note of notes) {
@@ -116,8 +152,6 @@ export class NoteDataProvider implements DataProvider {
116
152
  await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
117
153
  const scopes = await toArray(this.#scopes.keysAsync());
118
154
  for (const scope of scopes) {
119
- await this.#notesByRecipientAndScope.get(scope)!.deleteValue(noteDao.recipient.toString(), noteIndex);
120
- await this.#notesByTxHashAndScope.get(scope)!.deleteValue(noteDao.txHash.toString(), noteIndex);
121
155
  await this.#notesByContractAndScope.get(scope)!.deleteValue(noteDao.contractAddress.toString(), noteIndex);
122
156
  await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(noteDao.storageSlot.toString(), noteIndex);
123
157
  }
@@ -126,12 +160,21 @@ export class NoteDataProvider implements DataProvider {
126
160
  });
127
161
  }
128
162
 
129
- public async unnullifyNotesAfter(blockNumber: number, synchedBlockNumber?: number): Promise<void> {
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> {
130
174
  await this.#store.transactionAsync(async () => {
131
175
  const nullifiersToUndo: string[] = [];
132
176
  const currentBlockNumber = blockNumber + 1;
133
- const maxBlockNumber = synchedBlockNumber ?? currentBlockNumber;
134
- for (let i = currentBlockNumber; i <= maxBlockNumber; i++) {
177
+ for (let i = currentBlockNumber; i <= synchedBlockNumber; i++) {
135
178
  nullifiersToUndo.push(...(await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i))));
136
179
  }
137
180
  const notesIndexesToReinsert = await Promise.all(
@@ -150,17 +193,17 @@ export class NoteDataProvider implements DataProvider {
150
193
  await this.#notes.set(noteIndex, dao.toBuffer());
151
194
  await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
152
195
 
153
- let scopes = (await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex))) ?? [];
196
+ const scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex));
154
197
 
155
198
  if (scopes.length === 0) {
156
- scopes = [dao.recipient.toString()];
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}`);
157
202
  }
158
203
 
159
204
  for (const scope of scopes) {
160
205
  await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
161
206
  await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
162
- await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
163
- await this.#notesByRecipientAndScope.get(scope.toString())!.set(dao.recipient.toString(), noteIndex);
164
207
  await this.#notesToScope.set(noteIndex, scope);
165
208
  }
166
209
 
@@ -169,16 +212,33 @@ export class NoteDataProvider implements DataProvider {
169
212
  await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
170
213
  await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
171
214
  await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
172
- await this.#nullifiedNotesByTxHash.deleteValue(dao.txHash.toString(), noteIndex);
173
- await this.#nullifiedNotesByRecipient.deleteValue(dao.recipient.toString(), noteIndex);
174
215
  await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
175
216
  }
176
217
  });
177
218
  }
178
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
+ */
179
232
  async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
180
233
  filter.status = filter.status ?? NoteStatus.ACTIVE;
181
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
+
182
242
  const candidateNoteSources = [];
183
243
 
184
244
  filter.scopes ??= (await toArray(this.#scopes.keysAsync())).map(addressString =>
@@ -190,29 +250,19 @@ export class NoteDataProvider implements DataProvider {
190
250
  for (const scope of new Set(filter.scopes)) {
191
251
  const formattedScopeString = scope.toString();
192
252
  if (!(await this.#scopes.hasAsync(formattedScopeString))) {
193
- throw new Error('Trying to get incoming notes of an scope that is not in the PXE database');
253
+ throw new Error('Trying to get incoming notes of a scope that is not in the PXE database');
194
254
  }
195
255
 
196
256
  activeNoteIdsPerScope.push(
197
- filter.recipient
257
+ filter.storageSlot
198
258
  ? await toArray(
199
- this.#notesByRecipientAndScope.get(formattedScopeString)!.getValuesAsync(filter.recipient.toString()),
259
+ this.#notesByStorageSlotAndScope.get(formattedScopeString)!.getValuesAsync(filter.storageSlot.toString()),
200
260
  )
201
- : filter.txHash
202
- ? await toArray(
203
- this.#notesByTxHashAndScope.get(formattedScopeString)!.getValuesAsync(filter.txHash.toString()),
204
- )
205
- : filter.storageSlot
206
- ? await toArray(
207
- this.#notesByStorageSlotAndScope
208
- .get(formattedScopeString)!
209
- .getValuesAsync(filter.storageSlot.toString()),
210
- )
211
- : await toArray(
212
- this.#notesByContractAndScope
213
- .get(formattedScopeString)!
214
- .getValuesAsync(filter.contractAddress.toString()),
215
- ),
261
+ : await toArray(
262
+ this.#notesByContractAndScope
263
+ .get(formattedScopeString)!
264
+ .getValuesAsync(filter.contractAddress.toString()),
265
+ ),
216
266
  );
217
267
  }
218
268
 
@@ -221,17 +271,28 @@ export class NoteDataProvider implements DataProvider {
221
271
  notes: this.#notes,
222
272
  });
223
273
 
224
- if (filter.status == NoteStatus.ACTIVE_OR_NULLIFIED) {
225
- candidateNoteSources.push({
226
- ids: filter.recipient
227
- ? await toArray(this.#nullifiedNotesByRecipient.getValuesAsync(filter.recipient.toString()))
228
- : filter.txHash
229
- ? await toArray(this.#nullifiedNotesByTxHash.getValuesAsync(filter.txHash.toString()))
230
- : filter.storageSlot
231
- ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
232
- : await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString())),
233
- notes: this.#nullifiedNotes,
234
- });
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
+ }
235
296
  }
236
297
 
237
298
  const result: NoteDao[] = [];
@@ -247,7 +308,7 @@ export class NoteDataProvider implements DataProvider {
247
308
  continue;
248
309
  }
249
310
 
250
- if (filter.txHash && !note.txHash.equals(filter.txHash)) {
311
+ if (filter.owner && !note.owner.equals(filter.owner)) {
251
312
  continue;
252
313
  }
253
314
 
@@ -255,10 +316,6 @@ export class NoteDataProvider implements DataProvider {
255
316
  continue;
256
317
  }
257
318
 
258
- if (filter.recipient && !note.recipient.equals(filter.recipient)) {
259
- continue;
260
- }
261
-
262
319
  if (filter.siloedNullifier && !note.siloedNullifier.equals(filter.siloedNullifier)) {
263
320
  continue;
264
321
  }
@@ -267,10 +324,29 @@ export class NoteDataProvider implements DataProvider {
267
324
  }
268
325
  }
269
326
 
270
- return result;
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;
271
336
  }
272
337
 
273
- removeNullifiedNotes(nullifiers: InBlock<Fr>[], recipient: AztecAddress): Promise<NoteDao[]> {
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[]> {
274
350
  if (nullifiers.length === 0) {
275
351
  return Promise.resolve([]);
276
352
  }
@@ -280,22 +356,33 @@ export class NoteDataProvider implements DataProvider {
280
356
 
281
357
  for (const blockScopedNullifier of nullifiers) {
282
358
  const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier;
283
- const noteIndex = await this.#nullifierToNoteId.getAsync(nullifier.toString());
359
+ const nullifierKey = nullifier.toString();
360
+
361
+ const noteIndex = await this.#nullifierToNoteId.getAsync(nullifierKey);
284
362
  if (!noteIndex) {
285
- throw new Error('Nullifier not found in removeNullifiedNotes');
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');
286
369
  }
287
370
 
288
371
  const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
289
372
 
290
373
  if (!noteBuffer) {
291
- throw new Error('Note not found in removeNullifiedNotes');
374
+ throw new Error('Note not found in applyNullifiers');
292
375
  }
293
- const noteScopes = (await toArray(this.#notesToScope.getValuesAsync(noteIndex))) ?? [];
294
- const note = NoteDao.fromBuffer(noteBuffer);
295
- if (!note.recipient.equals(recipient)) {
296
- throw new Error("Tried to nullify someone else's note");
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');
297
382
  }
298
383
 
384
+ const note = NoteDao.fromBuffer(noteBuffer);
385
+
299
386
  nullifiedNotes.push(note);
300
387
 
301
388
  await this.#notes.delete(noteIndex);
@@ -304,23 +391,17 @@ export class NoteDataProvider implements DataProvider {
304
391
  const scopes = await toArray(this.#scopes.keysAsync());
305
392
 
306
393
  for (const scope of scopes) {
307
- await this.#notesByRecipientAndScope.get(scope)!.deleteValue(note.recipient.toString(), noteIndex);
308
- await this.#notesByTxHashAndScope.get(scope)!.deleteValue(note.txHash.toString(), noteIndex);
309
394
  await this.#notesByContractAndScope.get(scope)!.deleteValue(note.contractAddress.toString(), noteIndex);
310
395
  await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
311
396
  }
312
397
 
313
- if (noteScopes !== undefined) {
314
- for (const scope of noteScopes) {
315
- await this.#nullifiedNotesToScope.set(noteIndex, scope);
316
- }
398
+ for (const scope of noteScopes) {
399
+ await this.#nullifiedNotesToScope.set(noteIndex, scope);
317
400
  }
318
401
  await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
319
402
  await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
320
403
  await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
321
404
  await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
322
- await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
323
- await this.#nullifiedNotesByRecipient.set(note.recipient.toString(), noteIndex);
324
405
  await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
325
406
 
326
407
  await this.#nullifierToNoteId.delete(nullifier.toString());
@@ -328,23 +409,4 @@ export class NoteDataProvider implements DataProvider {
328
409
  return nullifiedNotes;
329
410
  });
330
411
  }
331
-
332
- async getSize() {
333
- const scopes = await toArray(this.#scopes.keysAsync());
334
- const contractAddresses = new Set<string>();
335
-
336
- // Collect all unique contract addresses across all scopes
337
- for (const scope of scopes) {
338
- const addresses = await toArray(this.#notesByContractAndScope.get(scope)!.keysAsync());
339
- addresses.forEach(addr => contractAddresses.add(addr));
340
- }
341
-
342
- // Get all notes for each contract address
343
- const allNotes = await Promise.all(
344
- Array.from(contractAddresses).map(addr => this.getNotes({ contractAddress: AztecAddress.fromString(addr) })),
345
- );
346
-
347
- // Reduce all notes to get total size
348
- return allNotes.flat().reduce((sum, note) => sum + note.getSize(), 0);
349
- }
350
412
  }