@aztec/pxe 0.0.0-test.1 → 0.0.1-commit.5476d83

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/README.md +5 -5
  2. package/dest/bin/check_oracle_version.d.ts +2 -0
  3. package/dest/bin/check_oracle_version.d.ts.map +1 -0
  4. package/dest/bin/check_oracle_version.js +39 -0
  5. package/dest/config/index.d.ts +11 -24
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +18 -33
  8. package/dest/config/package_info.d.ts +1 -1
  9. package/dest/config/package_info.js +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts +56 -0
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
  12. package/dest/contract_function_simulator/contract_function_simulator.js +300 -0
  13. package/dest/contract_function_simulator/execution_data_provider.d.ts +265 -0
  14. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -0
  15. package/dest/contract_function_simulator/execution_data_provider.js +14 -0
  16. package/dest/contract_function_simulator/execution_note_cache.d.ts +94 -0
  17. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
  18. package/dest/contract_function_simulator/execution_note_cache.js +190 -0
  19. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  20. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  22. package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
  23. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
  24. package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
  25. package/dest/contract_function_simulator/index.d.ts +14 -0
  26. package/dest/contract_function_simulator/index.d.ts.map +1 -0
  27. package/dest/contract_function_simulator/index.js +12 -0
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +20 -0
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -0
  30. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +37 -0
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +15 -0
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +25 -0
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +17 -0
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -0
  36. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +65 -0
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +23 -0
  38. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -0
  39. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +48 -0
  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 +14 -0
  44. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
  45. package/dest/contract_function_simulator/oracle/index.js +2 -0
  46. package/dest/contract_function_simulator/oracle/interfaces.d.ts +100 -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 +17 -0
  50. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
  51. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
  52. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +24 -0
  53. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
  54. package/dest/contract_function_simulator/oracle/note_packing_utils.js +50 -0
  55. package/dest/contract_function_simulator/oracle/oracle.d.ts +58 -0
  56. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
  57. package/dest/contract_function_simulator/oracle/oracle.js +333 -0
  58. package/dest/contract_function_simulator/oracle/private_execution.d.ts +48 -0
  59. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
  60. package/dest/contract_function_simulator/oracle/private_execution.js +123 -0
  61. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +231 -0
  62. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
  63. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +428 -0
  64. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +153 -0
  65. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
  66. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +265 -0
  67. package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
  68. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
  69. package/dest/contract_function_simulator/pick_notes.js +51 -0
  70. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +6 -0
  71. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -0
  72. package/dest/contract_function_simulator/proxied_contract_data_source.js +62 -0
  73. package/dest/contract_function_simulator/proxied_node.d.ts +9 -0
  74. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -0
  75. package/dest/contract_function_simulator/proxied_node.js +27 -0
  76. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +122 -0
  77. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -0
  78. package/dest/contract_function_simulator/pxe_oracle_interface.js +694 -0
  79. package/dest/entrypoints/client/bundle/index.d.ts +5 -3
  80. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  81. package/dest/entrypoints/client/bundle/index.js +3 -2
  82. package/dest/entrypoints/client/bundle/utils.d.ts +10 -10
  83. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  84. package/dest/entrypoints/client/bundle/utils.js +18 -12
  85. package/dest/entrypoints/client/lazy/index.d.ts +5 -3
  86. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  87. package/dest/entrypoints/client/lazy/index.js +3 -2
  88. package/dest/entrypoints/client/lazy/utils.d.ts +9 -9
  89. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  90. package/dest/entrypoints/client/lazy/utils.js +17 -11
  91. package/dest/entrypoints/pxe_creation_options.d.ts +14 -0
  92. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
  93. package/dest/entrypoints/server/index.d.ts +6 -4
  94. package/dest/entrypoints/server/index.d.ts.map +1 -1
  95. package/dest/entrypoints/server/index.js +4 -3
  96. package/dest/entrypoints/server/utils.d.ts +8 -16
  97. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  98. package/dest/entrypoints/server/utils.js +30 -35
  99. package/dest/error_enriching.d.ts +11 -0
  100. package/dest/error_enriching.d.ts.map +1 -0
  101. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +26 -18
  102. package/dest/oracle_version.d.ts +3 -0
  103. package/dest/oracle_version.d.ts.map +1 -0
  104. package/dest/oracle_version.js +10 -0
  105. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +28 -0
  106. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -0
  107. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +271 -0
  108. package/dest/private_kernel/hints/compute_side_effect_uniqueness_hints.d.ts +3 -0
  109. package/dest/private_kernel/hints/compute_side_effect_uniqueness_hints.d.ts.map +1 -0
  110. package/dest/private_kernel/hints/compute_side_effect_uniqueness_hints.js +48 -0
  111. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
  112. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
  113. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
  114. package/dest/private_kernel/hints/index.d.ts +3 -0
  115. package/dest/private_kernel/hints/index.d.ts.map +1 -0
  116. package/dest/{kernel_prover → private_kernel}/hints/index.js +1 -0
  117. package/dest/private_kernel/index.d.ts +3 -0
  118. package/dest/private_kernel/index.d.ts.map +1 -0
  119. package/dest/private_kernel/index.js +2 -0
  120. package/dest/private_kernel/private_kernel_execution_prover.d.ts +44 -0
  121. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -0
  122. package/dest/private_kernel/private_kernel_execution_prover.js +289 -0
  123. package/dest/private_kernel/private_kernel_oracle.d.ts +62 -0
  124. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -0
  125. package/dest/private_kernel/private_kernel_oracle.js +4 -0
  126. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +45 -0
  127. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -0
  128. package/dest/{kernel_oracle/index.js → private_kernel/private_kernel_oracle_impl.js} +19 -9
  129. package/dest/pxe.d.ts +240 -0
  130. package/dest/pxe.d.ts.map +1 -0
  131. package/dest/pxe.js +771 -0
  132. package/dest/storage/address_data_provider/address_data_provider.d.ts +2 -4
  133. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -1
  134. package/dest/storage/address_data_provider/address_data_provider.js +0 -3
  135. package/dest/storage/address_data_provider/index.d.ts +1 -1
  136. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +15 -6
  137. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
  138. package/dest/storage/capsule_data_provider/capsule_data_provider.js +85 -24
  139. package/dest/storage/capsule_data_provider/index.d.ts +1 -1
  140. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +13 -58
  141. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
  142. package/dest/storage/contract_data_provider/contract_data_provider.js +89 -79
  143. package/dest/storage/contract_data_provider/index.d.ts +1 -2
  144. package/dest/storage/contract_data_provider/index.d.ts.map +1 -1
  145. package/dest/storage/contract_data_provider/index.js +0 -1
  146. package/dest/storage/contract_data_provider/private_functions_tree.d.ts +3 -42
  147. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -1
  148. package/dest/storage/contract_data_provider/private_functions_tree.js +9 -61
  149. package/dest/storage/index.d.ts +3 -4
  150. package/dest/storage/index.d.ts.map +1 -1
  151. package/dest/storage/index.js +2 -3
  152. package/dest/storage/metadata.d.ts +2 -0
  153. package/dest/storage/metadata.d.ts.map +1 -0
  154. package/dest/storage/metadata.js +1 -0
  155. package/dest/storage/note_data_provider/index.d.ts +2 -2
  156. package/dest/storage/note_data_provider/index.d.ts.map +1 -1
  157. package/dest/storage/note_data_provider/index.js +1 -1
  158. package/dest/storage/note_data_provider/note_data_provider.d.ts +73 -10
  159. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
  160. package/dest/storage/note_data_provider/note_data_provider.js +145 -83
  161. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +37 -0
  162. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -0
  163. package/dest/storage/private_event_data_provider/private_event_data_provider.js +105 -0
  164. package/dest/storage/sync_data_provider/index.d.ts +1 -1
  165. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +3 -5
  166. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -1
  167. package/dest/storage/sync_data_provider/sync_data_provider.js +2 -5
  168. package/dest/storage/tagging_data_provider/index.d.ts +1 -1
  169. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +29 -7
  170. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -1
  171. package/dest/storage/tagging_data_provider/tagging_data_provider.js +48 -24
  172. package/dest/synchronizer/index.d.ts +1 -1
  173. package/dest/synchronizer/synchronizer.d.ts +8 -10
  174. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  175. package/dest/synchronizer/synchronizer.js +17 -19
  176. package/dest/tagging/constants.d.ts +2 -0
  177. package/dest/tagging/constants.d.ts.map +1 -0
  178. package/dest/tagging/constants.js +2 -0
  179. package/dest/tagging/index.d.ts +7 -0
  180. package/dest/tagging/index.d.ts.map +1 -0
  181. package/dest/tagging/index.js +5 -0
  182. package/dest/tagging/siloed_tag.d.ts +14 -0
  183. package/dest/tagging/siloed_tag.d.ts.map +1 -0
  184. package/dest/tagging/siloed_tag.js +20 -0
  185. package/dest/tagging/tag.d.ts +12 -0
  186. package/dest/tagging/tag.d.ts.map +1 -0
  187. package/dest/tagging/tag.js +17 -0
  188. package/dest/tagging/utils.d.ts +18 -0
  189. package/dest/tagging/utils.d.ts.map +1 -0
  190. package/dest/tagging/utils.js +24 -0
  191. package/package.json +37 -34
  192. package/src/bin/check_oracle_version.ts +50 -0
  193. package/src/config/index.ts +27 -55
  194. package/src/config/package_info.ts +1 -1
  195. package/src/contract_function_simulator/contract_function_simulator.ts +553 -0
  196. package/src/contract_function_simulator/execution_data_provider.ts +333 -0
  197. package/src/contract_function_simulator/execution_note_cache.ts +229 -0
  198. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  199. package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
  200. package/src/contract_function_simulator/index.ts +13 -0
  201. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +47 -0
  202. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +27 -0
  203. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +69 -0
  204. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +61 -0
  205. package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
  206. package/src/contract_function_simulator/oracle/index.ts +16 -0
  207. package/src/contract_function_simulator/oracle/interfaces.ts +170 -0
  208. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
  209. package/src/contract_function_simulator/oracle/note_packing_utils.ts +54 -0
  210. package/src/contract_function_simulator/oracle/oracle.ts +583 -0
  211. package/src/contract_function_simulator/oracle/private_execution.ts +207 -0
  212. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +633 -0
  213. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +358 -0
  214. package/src/contract_function_simulator/pick_notes.ts +141 -0
  215. package/src/contract_function_simulator/proxied_contract_data_source.ts +66 -0
  216. package/src/contract_function_simulator/proxied_node.ts +33 -0
  217. package/src/contract_function_simulator/pxe_oracle_interface.ts +1008 -0
  218. package/src/entrypoints/client/bundle/index.ts +4 -2
  219. package/src/entrypoints/client/bundle/utils.ts +36 -36
  220. package/src/entrypoints/client/lazy/index.ts +4 -2
  221. package/src/entrypoints/client/lazy/utils.ts +36 -31
  222. package/src/entrypoints/{client/pxe_creation_options.ts → pxe_creation_options.ts} +4 -1
  223. package/src/entrypoints/server/index.ts +5 -3
  224. package/src/entrypoints/server/utils.ts +58 -50
  225. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +36 -27
  226. package/src/oracle_version.ts +11 -0
  227. package/src/{kernel_prover → private_kernel}/hints/build_private_kernel_reset_private_inputs.ts +158 -146
  228. package/src/private_kernel/hints/compute_side_effect_uniqueness_hints.ts +173 -0
  229. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
  230. package/src/{kernel_prover → private_kernel}/hints/index.ts +1 -0
  231. package/src/private_kernel/index.ts +2 -0
  232. package/src/private_kernel/private_kernel_execution_prover.ts +436 -0
  233. package/src/{kernel_prover/proving_data_oracle.ts → private_kernel/private_kernel_oracle.ts} +17 -29
  234. package/src/{kernel_oracle/index.ts → private_kernel/private_kernel_oracle_impl.ts} +30 -15
  235. package/src/pxe.ts +1085 -0
  236. package/src/storage/address_data_provider/address_data_provider.ts +1 -7
  237. package/src/storage/capsule_data_provider/capsule_data_provider.ts +97 -30
  238. package/src/storage/contract_data_provider/contract_data_provider.ts +109 -93
  239. package/src/storage/contract_data_provider/index.ts +0 -1
  240. package/src/storage/contract_data_provider/private_functions_tree.ts +11 -75
  241. package/src/storage/index.ts +2 -4
  242. package/src/storage/metadata.ts +1 -0
  243. package/src/storage/note_data_provider/index.ts +1 -1
  244. package/src/storage/note_data_provider/note_data_provider.ts +176 -122
  245. package/src/storage/private_event_data_provider/private_event_data_provider.ts +143 -0
  246. package/src/storage/sync_data_provider/sync_data_provider.ts +4 -10
  247. package/src/storage/tagging_data_provider/tagging_data_provider.ts +58 -30
  248. package/src/synchronizer/synchronizer.ts +21 -22
  249. package/src/tagging/constants.ts +2 -0
  250. package/src/tagging/index.ts +6 -0
  251. package/src/tagging/siloed_tag.ts +22 -0
  252. package/src/tagging/tag.ts +16 -0
  253. package/src/tagging/utils.ts +31 -0
  254. package/dest/bin/index.d.ts +0 -3
  255. package/dest/bin/index.d.ts.map +0 -1
  256. package/dest/bin/index.js +0 -28
  257. package/dest/entrypoints/client/pxe_creation_options.d.ts +0 -11
  258. package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
  259. package/dest/kernel_oracle/index.d.ts +0 -45
  260. package/dest/kernel_oracle/index.d.ts.map +0 -1
  261. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  262. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  263. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +0 -270
  264. package/dest/kernel_prover/hints/index.d.ts +0 -2
  265. package/dest/kernel_prover/hints/index.d.ts.map +0 -1
  266. package/dest/kernel_prover/index.d.ts +0 -3
  267. package/dest/kernel_prover/index.d.ts.map +0 -1
  268. package/dest/kernel_prover/index.js +0 -2
  269. package/dest/kernel_prover/kernel_prover.d.ts +0 -38
  270. package/dest/kernel_prover/kernel_prover.d.ts.map +0 -1
  271. package/dest/kernel_prover/kernel_prover.js +0 -217
  272. package/dest/kernel_prover/proving_data_oracle.d.ts +0 -73
  273. package/dest/kernel_prover/proving_data_oracle.d.ts.map +0 -1
  274. package/dest/kernel_prover/proving_data_oracle.js +0 -4
  275. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +0 -11
  276. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +0 -1
  277. package/dest/note_decryption_utils/add_public_values_to_payload.js +0 -47
  278. package/dest/pxe_http/index.d.ts +0 -2
  279. package/dest/pxe_http/index.d.ts.map +0 -1
  280. package/dest/pxe_http/index.js +0 -1
  281. package/dest/pxe_http/pxe_http_server.d.ts +0 -16
  282. package/dest/pxe_http/pxe_http_server.d.ts.map +0 -1
  283. package/dest/pxe_http/pxe_http_server.js +0 -27
  284. package/dest/pxe_oracle_interface/index.d.ts +0 -159
  285. package/dest/pxe_oracle_interface/index.d.ts.map +0 -1
  286. package/dest/pxe_oracle_interface/index.js +0 -692
  287. package/dest/pxe_oracle_interface/tagging_utils.d.ts +0 -17
  288. package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
  289. package/dest/pxe_oracle_interface/tagging_utils.js +0 -23
  290. package/dest/pxe_service/error_enriching.d.ts +0 -11
  291. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  292. package/dest/pxe_service/index.d.ts +0 -3
  293. package/dest/pxe_service/index.d.ts.map +0 -1
  294. package/dest/pxe_service/index.js +0 -2
  295. package/dest/pxe_service/pxe_service.d.ts +0 -111
  296. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  297. package/dest/pxe_service/pxe_service.js +0 -664
  298. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts +0 -11
  299. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +0 -1
  300. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +0 -20
  301. package/dest/storage/auth_witness_data_provider/index.d.ts +0 -2
  302. package/dest/storage/auth_witness_data_provider/index.d.ts.map +0 -1
  303. package/dest/storage/auth_witness_data_provider/index.js +0 -1
  304. package/dest/storage/data_provider.d.ts +0 -4
  305. package/dest/storage/data_provider.d.ts.map +0 -1
  306. package/dest/storage/data_provider.js +0 -1
  307. package/dest/storage/note_data_provider/note_dao.d.ts +0 -106
  308. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  309. package/dest/storage/note_data_provider/note_dao.js +0 -106
  310. package/dest/test/pxe_test_suite.d.ts +0 -3
  311. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  312. package/dest/test/pxe_test_suite.js +0 -97
  313. package/src/bin/index.ts +0 -38
  314. package/src/kernel_prover/index.ts +0 -2
  315. package/src/kernel_prover/kernel_prover.ts +0 -351
  316. package/src/note_decryption_utils/add_public_values_to_payload.ts +0 -64
  317. package/src/pxe_http/index.ts +0 -1
  318. package/src/pxe_http/pxe_http_server.ts +0 -29
  319. package/src/pxe_oracle_interface/index.ts +0 -925
  320. package/src/pxe_oracle_interface/tagging_utils.ts +0 -32
  321. package/src/pxe_service/index.ts +0 -2
  322. package/src/pxe_service/pxe_service.ts +0 -949
  323. package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +0 -34
  324. package/src/storage/auth_witness_data_provider/index.ts +0 -1
  325. package/src/storage/data_provider.ts +0 -3
  326. package/src/storage/note_data_provider/note_dao.ts +0 -162
  327. package/src/test/pxe_test_suite.ts +0 -111
  328. /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
@@ -1,18 +1,20 @@
1
1
  import { toBufferBE } from '@aztec/foundation/bigint-buffer';
2
- import type { Fr, Point } from '@aztec/foundation/fields';
2
+ import type { Fr } from '@aztec/foundation/fields';
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
6
  import type { InBlock } from '@aztec/stdlib/block';
7
- import type { PublicKey } from '@aztec/stdlib/keys';
8
7
  import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
9
-
10
- import type { DataProvider } from '../data_provider.js';
11
- import { NoteDao } from './note_dao.js';
12
-
13
- export class NoteDataProvider implements DataProvider {
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 {
14
17
  #store: AztecAsyncKVStore;
15
-
16
18
  #notes: AztecAsyncMap<string, Buffer>;
17
19
  #nullifiedNotes: AztecAsyncMap<string, Buffer>;
18
20
  #nullifierToNoteId: AztecAsyncMap<string, string>;
@@ -21,16 +23,12 @@ export class NoteDataProvider implements DataProvider {
21
23
  #nullifiedNotesToScope: AztecAsyncMultiMap<string, string>;
22
24
  #nullifiedNotesByContract: AztecAsyncMultiMap<string, string>;
23
25
  #nullifiedNotesByStorageSlot: AztecAsyncMultiMap<string, string>;
24
- #nullifiedNotesByTxHash: AztecAsyncMultiMap<string, string>;
25
- #nullifiedNotesByAddressPoint: AztecAsyncMultiMap<string, string>;
26
26
  #nullifiedNotesByNullifier: AztecAsyncMap<string, string>;
27
27
 
28
28
  #scopes: AztecAsyncMap<string, true>;
29
29
  #notesToScope: AztecAsyncMultiMap<string, string>;
30
30
  #notesByContractAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
31
31
  #notesByStorageSlotAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
32
- #notesByTxHashAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
33
- #notesByAddressPointAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
34
32
 
35
33
  private constructor(store: AztecAsyncKVStore) {
36
34
  this.#store = store;
@@ -42,29 +40,41 @@ export class NoteDataProvider implements DataProvider {
42
40
  this.#nullifiedNotesToScope = store.openMultiMap('nullified_notes_to_scope');
43
41
  this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
44
42
  this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
45
- this.#nullifiedNotesByTxHash = store.openMultiMap('nullified_notes_by_tx_hash');
46
- this.#nullifiedNotesByAddressPoint = store.openMultiMap('nullified_notes_by_address_point');
47
43
  this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
48
44
 
49
45
  this.#scopes = store.openMap('scopes');
50
46
  this.#notesToScope = store.openMultiMap('notes_to_scope');
51
47
  this.#notesByContractAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
52
48
  this.#notesByStorageSlotAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
53
- this.#notesByTxHashAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
54
- this.#notesByAddressPointAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
55
49
  }
56
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
+ */
57
60
  public static async create(store: AztecAsyncKVStore): Promise<NoteDataProvider> {
58
61
  const pxeDB = new NoteDataProvider(store);
59
62
  for await (const scope of pxeDB.#scopes.keysAsync()) {
60
63
  pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
61
64
  pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
62
- pxeDB.#notesByTxHashAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_tx_hash`));
63
- pxeDB.#notesByAddressPointAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_address_point`));
64
65
  }
65
66
  return pxeDB;
66
67
  }
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
+ */
68
78
  public async addScope(scope: AztecAddress): Promise<boolean> {
69
79
  const scopeString = scope.toString();
70
80
 
@@ -75,26 +85,27 @@ export class NoteDataProvider implements DataProvider {
75
85
  await this.#scopes.set(scopeString, true);
76
86
  this.#notesByContractAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_contract`));
77
87
  this.#notesByStorageSlotAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_storage_slot`));
78
- this.#notesByTxHashAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_tx_hash`));
79
- this.#notesByAddressPointAndScope.set(
80
- scopeString,
81
- this.#store.openMultiMap(`${scopeString}:notes_by_address_point`),
82
- );
83
88
 
84
89
  return true;
85
90
  }
86
91
 
87
- async addNotes(notes: NoteDao[], scope: AztecAddress = AztecAddress.ZERO): Promise<void> {
88
- if (!(await this.#scopes.hasAsync(scope.toString()))) {
89
- await this.addScope(scope);
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> {
92
103
  return this.#store.transactionAsync(async () => {
104
+ if (!(await this.#scopes.hasAsync(scope.toString()))) {
105
+ await this.addScope(scope);
106
+ }
107
+
93
108
  for (const dao of notes) {
94
- // store notes by their index in the notes hash tree
95
- // this provides the uniqueness we need to store individual notes
96
- // and should also return notes in the order that they were created.
97
- // Had we stored them by their nullifier, they would be returned in random order
98
109
  const noteIndex = toBufferBE(dao.index, 32).toString('hex');
99
110
  await this.#notes.set(noteIndex, dao.toBuffer());
100
111
  await this.#notesToScope.set(noteIndex, scope.toString());
@@ -102,13 +113,34 @@ export class NoteDataProvider implements DataProvider {
102
113
 
103
114
  await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
104
115
  await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
105
- await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
106
- await this.#notesByAddressPointAndScope.get(scope.toString())!.set(dao.addressPoint.toString(), noteIndex);
107
116
  }
108
117
  });
109
118
  }
110
119
 
111
- 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> {
112
144
  return this.#store.transactionAsync(async () => {
113
145
  const notes = await toArray(this.#notes.valuesAsync());
114
146
  for (const note of notes) {
@@ -120,8 +152,6 @@ export class NoteDataProvider implements DataProvider {
120
152
  await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
121
153
  const scopes = await toArray(this.#scopes.keysAsync());
122
154
  for (const scope of scopes) {
123
- await this.#notesByAddressPointAndScope.get(scope)!.deleteValue(noteDao.addressPoint.toString(), noteIndex);
124
- await this.#notesByTxHashAndScope.get(scope)!.deleteValue(noteDao.txHash.toString(), noteIndex);
125
155
  await this.#notesByContractAndScope.get(scope)!.deleteValue(noteDao.contractAddress.toString(), noteIndex);
126
156
  await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(noteDao.storageSlot.toString(), noteIndex);
127
157
  }
@@ -130,41 +160,50 @@ export class NoteDataProvider implements DataProvider {
130
160
  });
131
161
  }
132
162
 
133
- public async unnullifyNotesAfter(blockNumber: number, synchedBlockNumber?: number): Promise<void> {
134
- const nullifiersToUndo: string[] = [];
135
- const currentBlockNumber = blockNumber + 1;
136
- const maxBlockNumber = synchedBlockNumber ?? currentBlockNumber;
137
- for (let i = currentBlockNumber; i <= maxBlockNumber; i++) {
138
- nullifiersToUndo.push(...(await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i))));
139
- }
140
- const notesIndexesToReinsert = await Promise.all(
141
- nullifiersToUndo.map(nullifier => this.#nullifiedNotesByNullifier.getAsync(nullifier)),
142
- );
143
- const notNullNoteIndexes = notesIndexesToReinsert.filter(noteIndex => noteIndex != undefined);
144
- const nullifiedNoteBuffers = await Promise.all(
145
- notNullNoteIndexes.map(noteIndex => this.#nullifiedNotes.getAsync(noteIndex!)),
146
- );
147
- const noteDaos = nullifiedNoteBuffers
148
- .filter(buffer => buffer != undefined)
149
- .map(buffer => NoteDao.fromBuffer(buffer!));
150
-
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> {
151
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
+
152
191
  for (const dao of noteDaos) {
153
192
  const noteIndex = toBufferBE(dao.index, 32).toString('hex');
154
193
  await this.#notes.set(noteIndex, dao.toBuffer());
155
194
  await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
156
195
 
157
- let scopes = (await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex))) ?? [];
196
+ const scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex));
158
197
 
159
198
  if (scopes.length === 0) {
160
- scopes = [new AztecAddress(dao.addressPoint.x).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}`);
161
202
  }
162
203
 
163
204
  for (const scope of scopes) {
164
205
  await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
165
206
  await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
166
- await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
167
- await this.#notesByAddressPointAndScope.get(scope.toString())!.set(dao.addressPoint.toString(), noteIndex);
168
207
  await this.#notesToScope.set(noteIndex, scope);
169
208
  }
170
209
 
@@ -173,18 +212,32 @@ export class NoteDataProvider implements DataProvider {
173
212
  await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
174
213
  await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
175
214
  await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
176
- await this.#nullifiedNotesByTxHash.deleteValue(dao.txHash.toString(), noteIndex);
177
- await this.#nullifiedNotesByAddressPoint.deleteValue(dao.addressPoint.toString(), noteIndex);
178
215
  await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
179
216
  }
180
217
  });
181
218
  }
182
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
+ * storageSlot, status, scopes and siloedNullifier.
228
+ * @returns Promise resolving to array of NoteDao objects matching the filter
229
+ * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
230
+ */
183
231
  async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
184
- const publicKey: PublicKey | undefined = filter.owner ? await filter.owner.toAddressPoint() : undefined;
185
-
186
232
  filter.status = filter.status ?? NoteStatus.ACTIVE;
187
233
 
234
+ // throw early if scopes is an empty array
235
+ if (filter.scopes !== undefined && filter.scopes.length === 0) {
236
+ throw new Error(
237
+ 'Trying to get notes with an empty scopes array. Scopes have to be set to undefined if intending on not filtering by scopes.',
238
+ );
239
+ }
240
+
188
241
  const candidateNoteSources = [];
189
242
 
190
243
  filter.scopes ??= (await toArray(this.#scopes.keysAsync())).map(addressString =>
@@ -196,29 +249,19 @@ export class NoteDataProvider implements DataProvider {
196
249
  for (const scope of new Set(filter.scopes)) {
197
250
  const formattedScopeString = scope.toString();
198
251
  if (!(await this.#scopes.hasAsync(formattedScopeString))) {
199
- throw new Error('Trying to get incoming notes of an scope that is not in the PXE database');
252
+ throw new Error('Trying to get incoming notes of a scope that is not in the PXE database');
200
253
  }
201
254
 
202
255
  activeNoteIdsPerScope.push(
203
- publicKey
204
- ? await toArray(
205
- this.#notesByAddressPointAndScope.get(formattedScopeString)!.getValuesAsync(publicKey.toString()),
206
- )
207
- : filter.txHash
256
+ filter.storageSlot
208
257
  ? await toArray(
209
- this.#notesByTxHashAndScope.get(formattedScopeString)!.getValuesAsync(filter.txHash.toString()),
258
+ this.#notesByStorageSlotAndScope.get(formattedScopeString)!.getValuesAsync(filter.storageSlot.toString()),
210
259
  )
211
- : filter.contractAddress
212
- ? await toArray(
260
+ : await toArray(
213
261
  this.#notesByContractAndScope
214
262
  .get(formattedScopeString)!
215
263
  .getValuesAsync(filter.contractAddress.toString()),
216
- )
217
- : filter.storageSlot
218
- ? await toArray(
219
- this.#notesByStorageSlotAndScope.get(formattedScopeString)!.getValuesAsync(filter.storageSlot.toString()),
220
- )
221
- : await toArray(this.#notesByAddressPointAndScope.get(formattedScopeString)!.valuesAsync()),
264
+ ),
222
265
  );
223
266
  }
224
267
 
@@ -227,19 +270,28 @@ export class NoteDataProvider implements DataProvider {
227
270
  notes: this.#notes,
228
271
  });
229
272
 
230
- if (filter.status == NoteStatus.ACTIVE_OR_NULLIFIED) {
231
- candidateNoteSources.push({
232
- ids: publicKey
233
- ? await toArray(this.#nullifiedNotesByAddressPoint.getValuesAsync(publicKey.toString()))
234
- : filter.txHash
235
- ? await toArray(this.#nullifiedNotesByTxHash.getValuesAsync(filter.txHash.toString()))
236
- : filter.contractAddress
237
- ? await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()))
238
- : filter.storageSlot
239
- ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
240
- : await toArray(this.#nullifiedNotes.keysAsync()),
241
- notes: this.#nullifiedNotes,
242
- });
273
+ // If status is ACTIVE_OR_NULLIFIED we add nullified notes as candidates on top of the default active ones.
274
+ if (filter.status === NoteStatus.ACTIVE_OR_NULLIFIED) {
275
+ const nullifiedIds = filter.storageSlot
276
+ ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
277
+ : await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()));
278
+
279
+ const setOfScopes = new Set(filter.scopes.map(s => s.toString() as string));
280
+ const filteredNullifiedIds = new Set<string>();
281
+
282
+ for (const noteId of nullifiedIds) {
283
+ const scopeList = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteId));
284
+ if (scopeList.some(scope => setOfScopes.has(scope))) {
285
+ filteredNullifiedIds.add(noteId);
286
+ }
287
+ }
288
+
289
+ if (filteredNullifiedIds.size > 0) {
290
+ candidateNoteSources.push({
291
+ ids: filteredNullifiedIds,
292
+ notes: this.#nullifiedNotes,
293
+ });
294
+ }
243
295
  }
244
296
 
245
297
  const result: NoteDao[] = [];
@@ -251,11 +303,7 @@ export class NoteDataProvider implements DataProvider {
251
303
  }
252
304
 
253
305
  const note = NoteDao.fromBuffer(serializedNote);
254
- if (filter.contractAddress && !note.contractAddress.equals(filter.contractAddress)) {
255
- continue;
256
- }
257
-
258
- if (filter.txHash && !note.txHash.equals(filter.txHash)) {
306
+ if (!note.contractAddress.equals(filter.contractAddress)) {
259
307
  continue;
260
308
  }
261
309
 
@@ -263,10 +311,6 @@ export class NoteDataProvider implements DataProvider {
263
311
  continue;
264
312
  }
265
313
 
266
- if (publicKey && !note.addressPoint.equals(publicKey)) {
267
- continue;
268
- }
269
-
270
314
  if (filter.siloedNullifier && !note.siloedNullifier.equals(filter.siloedNullifier)) {
271
315
  continue;
272
316
  }
@@ -278,7 +322,18 @@ export class NoteDataProvider implements DataProvider {
278
322
  return result;
279
323
  }
280
324
 
281
- removeNullifiedNotes(nullifiers: InBlock<Fr>[], accountAddressPoint: Point): Promise<NoteDao[]> {
325
+ /**
326
+ * Transitions notes from "active" to "nullified" state.
327
+ *
328
+ * This operation processes a batch of nullifiers to mark the corresponding notes
329
+ * as spent/nullified. The operation is atomic - if any nullifier is not found,
330
+ * the entire operation fails and no notes are modified.
331
+ *
332
+ * @param nullifiers - Array of nullifiers with their block numbers to process
333
+ * @returns Promise resolving to array of nullified NoteDao objects
334
+ * @throws Error if any nullifier is not found in the active notes
335
+ */
336
+ applyNullifiers(nullifiers: InBlock<Fr>[]): Promise<NoteDao[]> {
282
337
  if (nullifiers.length === 0) {
283
338
  return Promise.resolve([]);
284
339
  }
@@ -288,24 +343,33 @@ export class NoteDataProvider implements DataProvider {
288
343
 
289
344
  for (const blockScopedNullifier of nullifiers) {
290
345
  const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier;
291
- const noteIndex = await this.#nullifierToNoteId.getAsync(nullifier.toString());
346
+ const nullifierKey = nullifier.toString();
347
+
348
+ const noteIndex = await this.#nullifierToNoteId.getAsync(nullifierKey);
292
349
  if (!noteIndex) {
293
- continue;
350
+ // Check if already nullified?
351
+ const alreadyNullified = await this.#nullifiedNotesByNullifier.getAsync(nullifierKey);
352
+ if (alreadyNullified) {
353
+ throw new Error(`Nullifier already applied in applyNullifiers`);
354
+ }
355
+ throw new Error('Nullifier not found in applyNullifiers');
294
356
  }
295
357
 
296
358
  const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
297
359
 
298
360
  if (!noteBuffer) {
299
- // note doesn't exist. Maybe it got nullified already
300
- continue;
361
+ throw new Error('Note not found in applyNullifiers');
301
362
  }
302
- const noteScopes = (await toArray(this.#notesToScope.getValuesAsync(noteIndex))) ?? [];
303
- const note = NoteDao.fromBuffer(noteBuffer);
304
- if (!note.addressPoint.equals(accountAddressPoint)) {
305
- // tried to nullify someone else's note
306
- continue;
363
+
364
+ const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex));
365
+ if (noteScopes.length === 0) {
366
+ // We should never run into this error because notes always have a scope assigned to them - either on initial
367
+ // insertion via `addNotes` or when removing their nullifiers.
368
+ throw new Error('Note scopes are missing in applyNullifiers');
307
369
  }
308
370
 
371
+ const note = NoteDao.fromBuffer(noteBuffer);
372
+
309
373
  nullifiedNotes.push(note);
310
374
 
311
375
  await this.#notes.delete(noteIndex);
@@ -314,23 +378,17 @@ export class NoteDataProvider implements DataProvider {
314
378
  const scopes = await toArray(this.#scopes.keysAsync());
315
379
 
316
380
  for (const scope of scopes) {
317
- await this.#notesByAddressPointAndScope.get(scope)!.deleteValue(accountAddressPoint.toString(), noteIndex);
318
- await this.#notesByTxHashAndScope.get(scope)!.deleteValue(note.txHash.toString(), noteIndex);
319
381
  await this.#notesByContractAndScope.get(scope)!.deleteValue(note.contractAddress.toString(), noteIndex);
320
382
  await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
321
383
  }
322
384
 
323
- if (noteScopes !== undefined) {
324
- for (const scope of noteScopes) {
325
- await this.#nullifiedNotesToScope.set(noteIndex, scope);
326
- }
385
+ for (const scope of noteScopes) {
386
+ await this.#nullifiedNotesToScope.set(noteIndex, scope);
327
387
  }
328
388
  await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
329
389
  await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
330
390
  await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
331
391
  await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
332
- await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
333
- await this.#nullifiedNotesByAddressPoint.set(note.addressPoint.toString(), noteIndex);
334
392
  await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
335
393
 
336
394
  await this.#nullifierToNoteId.delete(nullifier.toString());
@@ -338,8 +396,4 @@ export class NoteDataProvider implements DataProvider {
338
396
  return nullifiedNotes;
339
397
  });
340
398
  }
341
-
342
- async getSize() {
343
- return (await this.getNotes({})).reduce((sum, note) => sum + note.getSize(), 0);
344
- }
345
399
  }
@@ -0,0 +1,143 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
+ import type { AztecAsyncArray, AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
5
+ import type { EventSelector } from '@aztec/stdlib/abi';
6
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
+ import { L2BlockHash } from '@aztec/stdlib/block';
8
+ import { TxHash } from '@aztec/stdlib/tx';
9
+
10
+ import type { PrivateEvent } from '../../pxe.js';
11
+
12
+ interface PrivateEventEntry {
13
+ msgContent: Buffer;
14
+ blockNumber: number;
15
+ blockHash: Buffer;
16
+ eventCommitmentIndex: number;
17
+ txHash: Buffer;
18
+ }
19
+
20
+ /**
21
+ * Stores decrypted private event logs.
22
+ */
23
+ export class PrivateEventDataProvider {
24
+ #store: AztecAsyncKVStore;
25
+ /** Array storing the actual private event log entries containing the log content and block number */
26
+ #eventLogs: AztecAsyncArray<PrivateEventEntry>;
27
+ /** Map from contract_address_recipient_eventSelector to array of indices into #eventLogs for efficient lookup */
28
+ #eventLogIndex: AztecAsyncMap<string, number[]>;
29
+ /** Map from eventCommitmentIndex to boolean indicating if log has been seen. */
30
+ #seenLogs: AztecAsyncMap<number, boolean>;
31
+
32
+ logger = createLogger('private_event_data_provider');
33
+
34
+ constructor(store: AztecAsyncKVStore) {
35
+ this.#store = store;
36
+ this.#eventLogs = this.#store.openArray('private_event_logs');
37
+ this.#eventLogIndex = this.#store.openMap('private_event_log_index');
38
+ this.#seenLogs = this.#store.openMap('seen_logs');
39
+ }
40
+
41
+ /**
42
+ * Store a private event log.
43
+ * @param contractAddress - The address of the contract that emitted the event.
44
+ * @param recipient - The recipient of the event.
45
+ * @param eventSelector - The event selector of the event.
46
+ * @param msgContent - The content of the event.
47
+ * @param txHash - The transaction hash of the event log.
48
+ * @param eventCommitmentIndex - The index of the event commitment in the nullifier tree.
49
+ * @param blockNumber - The block number in which the event was emitted.
50
+ */
51
+ storePrivateEventLog(
52
+ contractAddress: AztecAddress,
53
+ recipient: AztecAddress,
54
+ eventSelector: EventSelector,
55
+ msgContent: Fr[],
56
+ txHash: TxHash,
57
+ eventCommitmentIndex: number,
58
+ blockNumber: number,
59
+ blockHash: L2BlockHash,
60
+ ): Promise<void> {
61
+ return this.#store.transactionAsync(async () => {
62
+ const key = `${contractAddress.toString()}_${recipient.toString()}_${eventSelector.toString()}`;
63
+
64
+ // Check if this exact log has already been stored using eventCommitmentIndex as unique identifier
65
+ const hasBeenSeen = await this.#seenLogs.getAsync(eventCommitmentIndex);
66
+ if (hasBeenSeen) {
67
+ this.logger.verbose('Ignoring duplicate event log', { txHash: txHash.toString(), eventCommitmentIndex });
68
+ return;
69
+ }
70
+
71
+ this.logger.verbose('storing private event log', { contractAddress, recipient, msgContent, blockNumber });
72
+
73
+ const index = await this.#eventLogs.lengthAsync();
74
+ await this.#eventLogs.push({
75
+ msgContent: serializeToBuffer(msgContent),
76
+ blockNumber,
77
+ blockHash: blockHash.toBuffer(),
78
+ eventCommitmentIndex,
79
+ txHash: txHash.toBuffer(),
80
+ });
81
+
82
+ const existingIndices = (await this.#eventLogIndex.getAsync(key)) || [];
83
+ await this.#eventLogIndex.set(key, [...existingIndices, index]);
84
+
85
+ // Mark this log as seen using eventCommitmentIndex
86
+ await this.#seenLogs.set(eventCommitmentIndex, true);
87
+ });
88
+ }
89
+
90
+ /**
91
+ * Returns the private events given search parameters.
92
+ * @param contractAddress - The address of the contract to get events from.
93
+ * @param from - The block number to search from.
94
+ * @param numBlocks - The amount of blocks to search.
95
+ * @param recipients - The addresses that decrypted the logs.
96
+ * @param eventSelector - The event selector to filter by.
97
+ * @returns - The event log contents.
98
+ */
99
+ public async getPrivateEvents(
100
+ contractAddress: AztecAddress,
101
+ from: number,
102
+ numBlocks: number,
103
+ recipients: AztecAddress[],
104
+ eventSelector: EventSelector,
105
+ ): Promise<PrivateEvent[]> {
106
+ const events: Array<{ eventCommitmentIndex: number; event: PrivateEvent }> = [];
107
+
108
+ for (const recipient of recipients) {
109
+ const key = `${contractAddress.toString()}_${recipient.toString()}_${eventSelector.toString()}`;
110
+ const indices = (await this.#eventLogIndex.getAsync(key)) || [];
111
+
112
+ for (const index of indices) {
113
+ const entry = await this.#eventLogs.atAsync(index);
114
+ if (!entry || entry.blockNumber < from || entry.blockNumber >= from + numBlocks) {
115
+ continue;
116
+ }
117
+
118
+ // Convert buffer back to Fr array
119
+ const reader = BufferReader.asReader(entry.msgContent);
120
+ const numFields = entry.msgContent.length / Fr.SIZE_IN_BYTES;
121
+ const msgContent = reader.readArray(numFields, Fr);
122
+ const txHash = TxHash.fromBuffer(entry.txHash);
123
+ const blockHash = L2BlockHash.fromBuffer(entry.blockHash);
124
+
125
+ events.push({
126
+ eventCommitmentIndex: entry.eventCommitmentIndex,
127
+ event: {
128
+ packedEvent: msgContent,
129
+ blockNumber: entry.blockNumber,
130
+ recipient,
131
+ txHash,
132
+ blockHash,
133
+ eventSelector,
134
+ },
135
+ });
136
+ }
137
+ }
138
+
139
+ // Sort by eventCommitmentIndex only
140
+ events.sort((a, b) => a.eventCommitmentIndex - b.eventCommitmentIndex);
141
+ return events.map(ev => ev.event);
142
+ }
143
+ }
@@ -1,9 +1,7 @@
1
1
  import type { AztecAsyncKVStore, AztecAsyncSingleton } from '@aztec/kv-store';
2
2
  import { BlockHeader } from '@aztec/stdlib/tx';
3
3
 
4
- import type { DataProvider } from '../data_provider.js';
5
-
6
- export class SyncDataProvider implements DataProvider {
4
+ export class SyncDataProvider {
7
5
  #store: AztecAsyncKVStore;
8
6
  #synchronizedHeader: AztecAsyncSingleton<Buffer>;
9
7
 
@@ -16,13 +14,13 @@ export class SyncDataProvider implements DataProvider {
16
14
  await this.#synchronizedHeader.set(header.toBuffer());
17
15
  }
18
16
 
19
- async getBlockNumber(): Promise<number | undefined> {
17
+ async getBlockNumber(): Promise<number> {
20
18
  const headerBuffer = await this.#synchronizedHeader.getAsync();
21
19
  if (!headerBuffer) {
22
- return undefined;
20
+ throw new Error(`Trying to get block number with a not-yet-synchronized PXE - this should never happen`);
23
21
  }
24
22
 
25
- return Number(BlockHeader.fromBuffer(headerBuffer).globalVariables.blockNumber.toBigInt());
23
+ return BlockHeader.fromBuffer(headerBuffer).globalVariables.blockNumber;
26
24
  }
27
25
 
28
26
  async getBlockHeader(): Promise<BlockHeader> {
@@ -33,8 +31,4 @@ export class SyncDataProvider implements DataProvider {
33
31
 
34
32
  return BlockHeader.fromBuffer(headerBuffer);
35
33
  }
36
-
37
- async getSize(): Promise<number> {
38
- return (await this.#synchronizedHeader.getAsync())?.length ?? 0;
39
- }
40
34
  }