@aztec/pxe 0.0.1-commit.d3ec352c → 0.0.1-commit.d6f2b3f94

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 (387) hide show
  1. package/dest/bin/check_oracle_version.js +105 -15
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +45 -0
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  4. package/dest/block_synchronizer/block_synchronizer.js +153 -0
  5. package/dest/block_synchronizer/index.d.ts +2 -0
  6. package/dest/block_synchronizer/index.d.ts.map +1 -0
  7. package/dest/block_synchronizer/index.js +1 -0
  8. package/dest/config/index.d.ts +6 -4
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +17 -0
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  13. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +42 -14
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +74 -33
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +21 -12
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +48 -31
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +1 -1
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.js +1 -1
  23. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  24. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/index.d.ts +2 -2
  26. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/index.js +1 -1
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +5 -4
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +6 -3
  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 +2 -2
  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 +1 -1
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -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 +1 -1
  40. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  41. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  43. package/dest/contract_function_simulator/oracle/interfaces.d.ts +22 -18
  44. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +4 -2
  46. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  48. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +11 -7
  49. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  50. package/dest/contract_function_simulator/oracle/note_packing_utils.js +14 -10
  51. package/dest/contract_function_simulator/oracle/oracle.d.ts +11 -9
  52. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  53. package/dest/contract_function_simulator/oracle/oracle.js +82 -48
  54. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -28
  55. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  56. package/dest/contract_function_simulator/oracle/private_execution.js +2 -38
  57. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +34 -25
  58. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +41 -45
  60. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +88 -32
  61. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  62. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +201 -74
  63. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  64. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  65. package/dest/contract_function_simulator/pick_notes.js +1 -1
  66. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  67. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  68. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  69. package/dest/contract_sync/contract_sync_service.d.ts +41 -0
  70. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  71. package/dest/contract_sync/contract_sync_service.js +82 -0
  72. package/dest/contract_sync/helpers.d.ts +28 -0
  73. package/dest/contract_sync/helpers.d.ts.map +1 -0
  74. package/dest/contract_sync/helpers.js +55 -0
  75. package/dest/debug/pxe_debug_utils.d.ts +44 -0
  76. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  77. package/dest/debug/pxe_debug_utils.js +48 -0
  78. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  79. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  80. package/dest/entrypoints/client/bundle/index.js +0 -1
  81. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  82. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/client/bundle/utils.js +23 -8
  84. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  85. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  86. package/dest/entrypoints/client/lazy/index.js +0 -1
  87. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  88. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  89. package/dest/entrypoints/client/lazy/utils.js +24 -9
  90. package/dest/entrypoints/pxe_creation_options.d.ts +7 -3
  91. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  92. package/dest/entrypoints/server/index.d.ts +4 -2
  93. package/dest/entrypoints/server/index.d.ts.map +1 -1
  94. package/dest/entrypoints/server/index.js +3 -1
  95. package/dest/entrypoints/server/utils.d.ts +1 -1
  96. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  97. package/dest/entrypoints/server/utils.js +30 -15
  98. package/dest/error_enriching.d.ts +4 -4
  99. package/dest/error_enriching.d.ts.map +1 -1
  100. package/dest/error_enriching.js +6 -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 +44 -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 +38 -0
  110. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  111. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  112. package/dest/job_coordinator/job_coordinator.js +94 -0
  113. package/dest/logs/log_service.d.ts +28 -0
  114. package/dest/logs/log_service.d.ts.map +1 -0
  115. package/dest/logs/log_service.js +123 -0
  116. package/dest/notes/index.d.ts +2 -0
  117. package/dest/notes/index.d.ts.map +1 -0
  118. package/dest/notes/index.js +1 -0
  119. package/dest/notes/note_service.d.ts +48 -0
  120. package/dest/notes/note_service.d.ts.map +1 -0
  121. package/dest/notes/note_service.js +147 -0
  122. package/dest/oracle_version.d.ts +3 -3
  123. package/dest/oracle_version.d.ts.map +1 -1
  124. package/dest/oracle_version.js +4 -3
  125. package/dest/private_kernel/hints/index.d.ts +2 -2
  126. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  127. package/dest/private_kernel/hints/index.js +1 -1
  128. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  129. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  130. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +13 -7
  131. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  132. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  133. package/dest/private_kernel/private_kernel_execution_prover.js +10 -11
  134. package/dest/private_kernel/private_kernel_oracle.d.ts +26 -29
  135. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  136. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  137. package/dest/pxe.d.ts +56 -81
  138. package/dest/pxe.d.ts.map +1 -1
  139. package/dest/pxe.js +209 -217
  140. package/dest/storage/address_store/address_store.d.ts +11 -0
  141. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  142. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +13 -12
  143. package/dest/storage/address_store/index.d.ts +2 -0
  144. package/dest/storage/address_store/index.d.ts.map +1 -0
  145. package/dest/storage/address_store/index.js +1 -0
  146. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +17 -0
  147. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  148. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +10 -10
  149. package/dest/storage/{sync_data_provider → anchor_block_store}/index.d.ts +2 -2
  150. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  151. package/dest/storage/anchor_block_store/index.js +1 -0
  152. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  153. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  154. package/dest/storage/capsule_store/capsule_store.js +253 -0
  155. package/dest/storage/capsule_store/index.d.ts +2 -0
  156. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  157. package/dest/storage/capsule_store/index.js +1 -0
  158. package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +7 -5
  159. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  160. package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +56 -16
  161. package/dest/storage/contract_store/index.d.ts +2 -0
  162. package/dest/storage/contract_store/index.d.ts.map +1 -0
  163. package/dest/storage/contract_store/index.js +1 -0
  164. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  165. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  166. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  167. package/dest/storage/index.d.ts +8 -8
  168. package/dest/storage/index.d.ts.map +1 -1
  169. package/dest/storage/index.js +7 -7
  170. package/dest/storage/metadata.d.ts +1 -1
  171. package/dest/storage/metadata.js +1 -1
  172. package/dest/storage/note_store/index.d.ts +3 -0
  173. package/dest/storage/note_store/index.d.ts.map +1 -0
  174. package/dest/storage/note_store/index.js +2 -0
  175. package/dest/storage/note_store/note_store.d.ts +83 -0
  176. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  177. package/dest/storage/note_store/note_store.js +344 -0
  178. package/dest/storage/note_store/stored_note.d.ts +16 -0
  179. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  180. package/dest/storage/note_store/stored_note.js +43 -0
  181. package/dest/storage/private_event_store/private_event_store.d.ts +91 -0
  182. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  183. package/dest/storage/private_event_store/private_event_store.js +273 -0
  184. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  185. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  186. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  187. package/dest/storage/tagging_store/index.d.ts +4 -0
  188. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  189. package/dest/storage/tagging_store/index.js +3 -0
  190. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
  191. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  192. package/dest/storage/tagging_store/recipient_tagging_store.js +111 -0
  193. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  194. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  195. package/dest/storage/tagging_store/sender_address_book_store.js +36 -0
  196. package/dest/storage/tagging_store/sender_tagging_store.d.ts +77 -0
  197. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  198. package/dest/storage/tagging_store/sender_tagging_store.js +348 -0
  199. package/dest/tagging/constants.d.ts +2 -2
  200. package/dest/tagging/constants.d.ts.map +1 -1
  201. package/dest/tagging/constants.js +10 -2
  202. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  203. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  204. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  205. package/dest/tagging/index.d.ts +16 -6
  206. package/dest/tagging/index.d.ts.map +1 -1
  207. package/dest/tagging/index.js +15 -5
  208. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +15 -0
  209. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  210. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  211. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  212. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  213. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  214. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +15 -0
  215. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  216. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +32 -0
  217. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +21 -0
  218. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  219. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  220. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  221. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  222. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +29 -0
  223. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +21 -0
  224. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  225. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +60 -0
  226. package/package.json +27 -18
  227. package/src/bin/check_oracle_version.ts +131 -20
  228. package/src/block_synchronizer/block_synchronizer.ts +178 -0
  229. package/src/block_synchronizer/index.ts +1 -0
  230. package/src/config/index.ts +17 -3
  231. package/src/config/package_info.ts +1 -1
  232. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  233. package/src/contract_function_simulator/contract_function_simulator.ts +117 -34
  234. package/src/contract_function_simulator/execution_note_cache.ts +51 -29
  235. package/src/contract_function_simulator/execution_tagging_index_cache.ts +1 -1
  236. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  237. package/src/contract_function_simulator/index.ts +1 -1
  238. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +6 -2
  239. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
  240. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  241. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  242. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  243. package/src/contract_function_simulator/oracle/interfaces.ts +27 -17
  244. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  245. package/src/contract_function_simulator/oracle/note_packing_utils.ts +27 -13
  246. package/src/contract_function_simulator/oracle/oracle.ts +97 -51
  247. package/src/contract_function_simulator/oracle/private_execution.ts +2 -69
  248. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +121 -59
  249. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +294 -91
  250. package/src/contract_function_simulator/pick_notes.ts +1 -1
  251. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  252. package/src/contract_sync/contract_sync_service.ts +129 -0
  253. package/src/contract_sync/helpers.ts +93 -0
  254. package/src/debug/pxe_debug_utils.ts +91 -0
  255. package/src/entrypoints/client/bundle/index.ts +0 -1
  256. package/src/entrypoints/client/bundle/utils.ts +15 -16
  257. package/src/entrypoints/client/lazy/index.ts +0 -1
  258. package/src/entrypoints/client/lazy/utils.ts +16 -17
  259. package/src/entrypoints/pxe_creation_options.ts +6 -2
  260. package/src/entrypoints/server/index.ts +3 -1
  261. package/src/entrypoints/server/utils.ts +26 -34
  262. package/src/error_enriching.ts +7 -15
  263. package/src/events/event_service.ts +71 -0
  264. package/src/events/index.ts +1 -0
  265. package/src/events/private_event_filter_validator.ts +46 -0
  266. package/src/job_coordinator/job_coordinator.ts +150 -0
  267. package/src/logs/log_service.ts +220 -0
  268. package/src/notes/index.ts +1 -0
  269. package/src/notes/note_service.ts +195 -0
  270. package/src/oracle_version.ts +4 -3
  271. package/src/private_kernel/hints/index.ts +1 -1
  272. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +34 -23
  273. package/src/private_kernel/private_kernel_execution_prover.ts +13 -12
  274. package/src/private_kernel/private_kernel_oracle.ts +118 -37
  275. package/src/pxe.ts +299 -280
  276. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +16 -16
  277. package/src/storage/address_store/index.ts +1 -0
  278. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +10 -12
  279. package/src/storage/anchor_block_store/index.ts +1 -0
  280. package/src/storage/capsule_store/capsule_store.ts +315 -0
  281. package/src/storage/capsule_store/index.ts +1 -0
  282. package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +67 -14
  283. package/src/storage/contract_store/index.ts +1 -0
  284. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  285. package/src/storage/index.ts +7 -7
  286. package/src/storage/metadata.ts +1 -1
  287. package/src/storage/note_store/index.ts +2 -0
  288. package/src/storage/note_store/note_store.ts +415 -0
  289. package/src/storage/note_store/stored_note.ts +48 -0
  290. package/src/storage/private_event_store/private_event_store.ts +384 -0
  291. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  292. package/src/storage/tagging_store/index.ts +3 -0
  293. package/src/storage/tagging_store/recipient_tagging_store.ts +139 -0
  294. package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
  295. package/src/storage/tagging_store/sender_tagging_store.ts +429 -0
  296. package/src/tagging/constants.ts +10 -2
  297. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  298. package/src/tagging/index.ts +18 -5
  299. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +143 -0
  300. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  301. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +49 -0
  302. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +99 -0
  303. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +36 -0
  304. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +84 -0
  305. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -267
  306. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  307. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  308. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  309. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  310. package/dest/contract_function_simulator/proxied_node.js +0 -27
  311. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -123
  312. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  313. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -696
  314. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  315. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  316. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -45
  317. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  318. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  319. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  320. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  321. package/dest/storage/address_data_provider/index.d.ts +0 -2
  322. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  323. package/dest/storage/address_data_provider/index.js +0 -1
  324. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -25
  325. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  326. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -118
  327. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  328. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  329. package/dest/storage/capsule_data_provider/index.js +0 -1
  330. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  331. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  332. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  333. package/dest/storage/contract_data_provider/index.js +0 -1
  334. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  335. package/dest/storage/note_data_provider/index.d.ts +0 -3
  336. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  337. package/dest/storage/note_data_provider/index.js +0 -2
  338. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -83
  339. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  340. package/dest/storage/note_data_provider/note_data_provider.js +0 -314
  341. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
  342. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  343. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -105
  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 -11
  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 -40
  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 -89
  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 -36
  358. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  359. package/dest/synchronizer/synchronizer.js +0 -102
  360. package/dest/tagging/siloed_tag.d.ts +0 -14
  361. package/dest/tagging/siloed_tag.d.ts.map +0 -1
  362. package/dest/tagging/siloed_tag.js +0 -20
  363. package/dest/tagging/tag.d.ts +0 -12
  364. package/dest/tagging/tag.d.ts.map +0 -1
  365. package/dest/tagging/tag.js +0 -17
  366. package/dest/tagging/utils.d.ts +0 -18
  367. package/dest/tagging/utils.d.ts.map +0 -1
  368. package/dest/tagging/utils.js +0 -24
  369. package/src/contract_function_simulator/execution_data_provider.ts +0 -342
  370. package/src/contract_function_simulator/proxied_node.ts +0 -33
  371. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1023
  372. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -132
  373. package/src/storage/address_data_provider/index.ts +0 -1
  374. package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -147
  375. package/src/storage/capsule_data_provider/index.ts +0 -1
  376. package/src/storage/contract_data_provider/index.ts +0 -1
  377. package/src/storage/note_data_provider/index.ts +0 -2
  378. package/src/storage/note_data_provider/note_data_provider.ts +0 -403
  379. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -143
  380. package/src/storage/sync_data_provider/index.ts +0 -1
  381. package/src/storage/tagging_data_provider/index.ts +0 -1
  382. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
  383. package/src/synchronizer/index.ts +0 -1
  384. package/src/synchronizer/synchronizer.ts +0 -121
  385. package/src/tagging/siloed_tag.ts +0 -22
  386. package/src/tagging/tag.ts +0 -16
  387. package/src/tagging/utils.ts +0 -31
@@ -0,0 +1,71 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { EventSelector } from '@aztec/stdlib/abi';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { siloNullifier } from '@aztec/stdlib/hash';
5
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
6
+ import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
7
+
8
+ import { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
9
+
10
+ export class EventService {
11
+ constructor(
12
+ private readonly anchorBlockHeader: BlockHeader,
13
+ private readonly aztecNode: AztecNode,
14
+ private readonly privateEventStore: PrivateEventStore,
15
+ private readonly jobId: string,
16
+ ) {}
17
+
18
+ public async validateAndStoreEvent(
19
+ contractAddress: AztecAddress,
20
+ selector: EventSelector,
21
+ randomness: Fr,
22
+ content: Fr[],
23
+ eventCommitment: Fr,
24
+ txHash: TxHash,
25
+ scope: AztecAddress,
26
+ ): Promise<void> {
27
+ // While using 'latest' block number would be fine for private events since they cannot be accessed from Aztec.nr
28
+ // (and thus we're less concerned about being ahead of the synced block), we use the synced block number to
29
+ // maintain consistent behavior in the PXE. Additionally, events should never be ahead of the synced block here
30
+ // since `fetchTaggedLogs` only processes logs up to the synced block.
31
+ const [siloedEventCommitment, txEffect] = await Promise.all([
32
+ siloNullifier(contractAddress, eventCommitment),
33
+ this.aztecNode.getTxEffect(txHash),
34
+ ]);
35
+
36
+ const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
37
+
38
+ if (!txEffect) {
39
+ throw new Error(`Could not find tx effect for tx hash ${txHash}`);
40
+ }
41
+
42
+ if (txEffect.l2BlockNumber > anchorBlockNumber) {
43
+ throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${anchorBlockNumber}`);
44
+ }
45
+
46
+ // Find the index of the event commitment in the nullifiers array to determine event ordering within the tx
47
+ const eventIndexInTx = txEffect.data.nullifiers.findIndex(n => n.equals(siloedEventCommitment));
48
+ if (eventIndexInTx === -1) {
49
+ throw new Error(
50
+ `Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present in tx ${txHash}`,
51
+ );
52
+ }
53
+
54
+ return this.privateEventStore.storePrivateEventLog(
55
+ selector,
56
+ randomness,
57
+ content,
58
+ siloedEventCommitment,
59
+ {
60
+ contractAddress,
61
+ scope,
62
+ txHash,
63
+ l2BlockNumber: txEffect.l2BlockNumber,
64
+ l2BlockHash: txEffect.l2BlockHash,
65
+ txIndexInBlock: txEffect.txIndexInBlock,
66
+ eventIndexInTx,
67
+ },
68
+ this.jobId,
69
+ );
70
+ }
71
+ }
@@ -0,0 +1 @@
1
+ export * from './private_event_filter_validator.js';
@@ -0,0 +1,46 @@
1
+ import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
3
+ import { BlockNumber } from '@aztec/foundation/branded-types';
4
+
5
+ import type { PrivateEventStoreFilter } from '../storage/private_event_store/private_event_store.js';
6
+
7
+ export class PrivateEventFilterValidator {
8
+ constructor(private lastBlock: BlockNumber) {}
9
+
10
+ validate(filter: PrivateEventFilter): PrivateEventStoreFilter {
11
+ let { fromBlock, toBlock } = filter;
12
+
13
+ // Block range filters in Aztec Node are defined as closed-open intervals [fromBlock, toBlock), so
14
+ // we respect that convention here for consistency.
15
+ // We then default to [INITIAL_L2_BLOCK_NUM, latestKnownBlock + 1), ie: by default return events from
16
+ // the first block to the latest known block.
17
+ if (!fromBlock || !toBlock) {
18
+ fromBlock = fromBlock ?? BlockNumber(INITIAL_L2_BLOCK_NUM);
19
+ toBlock = toBlock ?? BlockNumber(this.lastBlock + 1);
20
+ }
21
+
22
+ if (filter.scopes.length === 0) {
23
+ throw new Error('At least one scope is required to get private events');
24
+ }
25
+
26
+ if (fromBlock < 1) {
27
+ throw new Error('fromBlock must be greater than or equal to 1');
28
+ }
29
+
30
+ if (toBlock < 1) {
31
+ throw new Error('toBlock must be greater than or equal to 1');
32
+ }
33
+
34
+ if (fromBlock >= toBlock) {
35
+ throw new Error('toBlock must be strictly greater than fromBlock');
36
+ }
37
+
38
+ return {
39
+ contractAddress: filter.contractAddress,
40
+ scopes: filter.scopes,
41
+ txHash: filter.txHash,
42
+ toBlock,
43
+ fromBlock,
44
+ };
45
+ }
46
+ }
@@ -0,0 +1,150 @@
1
+ import { randomBytes } from '@aztec/foundation/crypto/random';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
4
+
5
+ /**
6
+ * Interface that stores must implement to support staged writes.
7
+ */
8
+ export interface StagedStore {
9
+ /** Unique name identifying this store (used for tracking staged stores from JobCoordinator) */
10
+ readonly storeName: string;
11
+
12
+ /**
13
+ * Commits staged data to main storage.
14
+ * Should be called within a transaction for atomicity.
15
+ *
16
+ * @param jobId - The job identifier
17
+ */
18
+ commit(jobId: string): Promise<void>;
19
+
20
+ /**
21
+ * Discards staged data without committing.
22
+ * Called on abort.
23
+ *
24
+ * @param jobId - The job identifier
25
+ */
26
+ discardStaged(jobId: string): Promise<void>;
27
+ }
28
+
29
+ /**
30
+ * JobCoordinator manages job lifecycle and provides crash resilience for PXE operations.
31
+ *
32
+ * It uses a staged writes pattern:
33
+ * 1. When a job begins, a unique job ID is created
34
+ * 2. During the job, all writes go to staging (keyed by job ID)
35
+ * 3. On commit, staging is promoted to main storage
36
+ * 4. On abort, staged data is discarded
37
+ *
38
+ * Note: PXE should only rely on a single JobCoordinator instance, so it can eventually
39
+ * orchestrate concurrent jobs. Right now it doesn't make a difference because we're
40
+ * using a job queue with concurrency=1.
41
+ */
42
+ export class JobCoordinator {
43
+ private readonly log: Logger;
44
+
45
+ /** The underlying KV store */
46
+ kvStore: AztecAsyncKVStore;
47
+
48
+ #currentJobId: string | undefined;
49
+ #stores: Map<string, StagedStore> = new Map();
50
+
51
+ constructor(kvStore: AztecAsyncKVStore, bindings?: LoggerBindings) {
52
+ this.kvStore = kvStore;
53
+ this.log = createLogger('pxe:job_coordinator', bindings);
54
+ }
55
+
56
+ /**
57
+ * Registers a staged store.
58
+ * Must be called during initialization for all stores that need staging support.
59
+ */
60
+ registerStore(store: StagedStore): void {
61
+ if (this.#stores.has(store.storeName)) {
62
+ throw new Error(`Store "${store.storeName}" is already registered`);
63
+ }
64
+ this.#stores.set(store.storeName, store);
65
+ this.log.debug(`Registered staged store: ${store.storeName}`);
66
+ }
67
+
68
+ /**
69
+ * Registers multiple staged stores.
70
+ */
71
+ registerStores(stores: StagedStore[]): void {
72
+ for (const store of stores) {
73
+ this.registerStore(store);
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Begins a new job and returns a job ID for staged writes.
79
+ *
80
+ * @returns Job ID to pass to store operations
81
+ */
82
+ beginJob(): string {
83
+ if (this.#currentJobId) {
84
+ throw new Error(
85
+ `Cannot begin job: job ${this.#currentJobId} is already in progress. ` +
86
+ `This should not happen - ensure jobs are properly committed or aborted.`,
87
+ );
88
+ }
89
+
90
+ const jobId = randomBytes(8).toString('hex');
91
+ this.#currentJobId = jobId;
92
+
93
+ this.log.debug(`Started job ${jobId}`);
94
+ return jobId;
95
+ }
96
+
97
+ /**
98
+ * Commits a job by promoting all staged data to main storage.
99
+ *
100
+ * @param jobId - The job ID returned from beginJob
101
+ */
102
+ async commitJob(jobId: string): Promise<void> {
103
+ if (!this.#currentJobId || this.#currentJobId !== jobId) {
104
+ throw new Error(
105
+ `Cannot commit job ${jobId}: no matching job in progress. ` + `Current job: ${this.#currentJobId ?? 'none'}`,
106
+ );
107
+ }
108
+
109
+ this.log.debug(`Committing job ${jobId}`);
110
+
111
+ // Commit all stores atomically in a single transaction.
112
+ // Each store's commit is a no-op if it has no staged data (but that's up to each store to handle).
113
+ await this.kvStore.transactionAsync(async () => {
114
+ for (const store of this.#stores.values()) {
115
+ await store.commit(jobId);
116
+ }
117
+ });
118
+
119
+ this.#currentJobId = undefined;
120
+ this.log.debug(`Job ${jobId} committed successfully`);
121
+ }
122
+
123
+ /**
124
+ * Aborts a job by discarding all staged data.
125
+ *
126
+ * @param jobId - The job ID returned from beginJob
127
+ */
128
+ async abortJob(jobId: string): Promise<void> {
129
+ if (!this.#currentJobId || this.#currentJobId !== jobId) {
130
+ // Job may have already been aborted or never started properly
131
+ this.log.warn(`Abort called for job ${jobId} but current job is ${this.#currentJobId ?? 'none'}`);
132
+ }
133
+
134
+ this.log.debug(`Aborting job ${jobId}`);
135
+
136
+ for (const store of this.#stores.values()) {
137
+ await store.discardStaged(jobId);
138
+ }
139
+
140
+ this.#currentJobId = undefined;
141
+ this.log.debug(`Job ${jobId} aborted`);
142
+ }
143
+
144
+ /**
145
+ * Checks if there's a job currently in progress.
146
+ */
147
+ hasJobInProgress(): boolean {
148
+ return this.#currentJobId !== undefined;
149
+ }
150
+ }
@@ -0,0 +1,220 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import type { KeyStore } from '@aztec/key-store';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { CompleteAddress } from '@aztec/stdlib/contract';
6
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
7
+ import { DirectionalAppTaggingSecret, PendingTaggedLog, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
8
+ import type { BlockHeader } from '@aztec/stdlib/tx';
9
+
10
+ import type { LogRetrievalRequest } from '../contract_function_simulator/noir-structs/log_retrieval_request.js';
11
+ import { LogRetrievalResponse } from '../contract_function_simulator/noir-structs/log_retrieval_response.js';
12
+ import { AddressStore } from '../storage/address_store/address_store.js';
13
+ import { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
14
+ import type { RecipientTaggingStore } from '../storage/tagging_store/recipient_tagging_store.js';
15
+ import type { SenderAddressBookStore } from '../storage/tagging_store/sender_address_book_store.js';
16
+ import {
17
+ getAllPrivateLogsByTags,
18
+ getAllPublicLogsByTagsFromContract,
19
+ loadPrivateLogsForSenderRecipientPair,
20
+ } from '../tagging/index.js';
21
+
22
+ export class LogService {
23
+ private log: Logger;
24
+
25
+ constructor(
26
+ private readonly aztecNode: AztecNode,
27
+ private readonly anchorBlockHeader: BlockHeader,
28
+ private readonly keyStore: KeyStore,
29
+ private readonly capsuleStore: CapsuleStore,
30
+ private readonly recipientTaggingStore: RecipientTaggingStore,
31
+ private readonly senderAddressBookStore: SenderAddressBookStore,
32
+ private readonly addressStore: AddressStore,
33
+ private readonly jobId: string,
34
+ bindings?: LoggerBindings,
35
+ ) {
36
+ this.log = createLogger('pxe:log_service', bindings);
37
+ }
38
+
39
+ public async bulkRetrieveLogs(logRetrievalRequests: LogRetrievalRequest[]): Promise<(LogRetrievalResponse | null)[]> {
40
+ return await Promise.all(
41
+ logRetrievalRequests.map(async request => {
42
+ const [publicLog, privateLog] = await Promise.all([
43
+ this.#getPublicLogByTag(request.tag, request.contractAddress),
44
+ this.#getPrivateLogByTag(await SiloedTag.compute(request.tag, request.contractAddress)),
45
+ ]);
46
+
47
+ if (publicLog !== null && privateLog !== null) {
48
+ throw new Error(
49
+ `Found both a public and private log when searching for tag ${request.tag} from contract ${request.contractAddress}`,
50
+ );
51
+ }
52
+
53
+ return publicLog ?? privateLog;
54
+ }),
55
+ );
56
+ }
57
+
58
+ async #getPublicLogByTag(tag: Tag, contractAddress: AztecAddress): Promise<LogRetrievalResponse | null> {
59
+ const anchorBlockHash = await this.anchorBlockHeader.hash();
60
+ const allLogsPerTag = await getAllPublicLogsByTagsFromContract(
61
+ this.aztecNode,
62
+ contractAddress,
63
+ [tag],
64
+ anchorBlockHash,
65
+ );
66
+ const logsForTag = allLogsPerTag[0];
67
+
68
+ if (logsForTag.length === 0) {
69
+ return null;
70
+ } else if (logsForTag.length > 1) {
71
+ // TODO(#11627): handle this case
72
+ throw new Error(
73
+ `Got ${logsForTag.length} logs for tag ${tag} and contract ${contractAddress.toString()}. getPublicLogByTag currently only supports a single log per tag`,
74
+ );
75
+ }
76
+
77
+ const scopedLog = logsForTag[0];
78
+
79
+ return new LogRetrievalResponse(
80
+ scopedLog.logData.slice(1), // Skip the tag
81
+ scopedLog.txHash,
82
+ scopedLog.noteHashes,
83
+ scopedLog.firstNullifier,
84
+ );
85
+ }
86
+
87
+ async #getPrivateLogByTag(siloedTag: SiloedTag): Promise<LogRetrievalResponse | null> {
88
+ const anchorBlockHash = await this.anchorBlockHeader.hash();
89
+ const allLogsPerTag = await getAllPrivateLogsByTags(this.aztecNode, [siloedTag], anchorBlockHash);
90
+ const logsForTag = allLogsPerTag[0];
91
+
92
+ if (logsForTag.length === 0) {
93
+ return null;
94
+ } else if (logsForTag.length > 1) {
95
+ // TODO(#11627): handle this case
96
+ throw new Error(
97
+ `Got ${logsForTag.length} logs for tag ${siloedTag}. getPrivateLogByTag currently only supports a single log per tag`,
98
+ );
99
+ }
100
+
101
+ const scopedLog = logsForTag[0];
102
+
103
+ return new LogRetrievalResponse(
104
+ scopedLog.logData.slice(1), // Skip the tag
105
+ scopedLog.txHash,
106
+ scopedLog.noteHashes,
107
+ scopedLog.firstNullifier,
108
+ );
109
+ }
110
+
111
+ public async fetchTaggedLogs(
112
+ contractAddress: AztecAddress,
113
+ pendingTaggedLogArrayBaseSlot: Fr,
114
+ scopes?: AztecAddress[],
115
+ ) {
116
+ this.log.verbose(`Fetching tagged logs for ${contractAddress.toString()}`);
117
+
118
+ // We only load logs from block up to and including the anchor block number
119
+ const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
120
+ const anchorBlockHash = await this.anchorBlockHeader.hash();
121
+
122
+ // Determine recipients: use scopes if provided, otherwise get all accounts
123
+ const recipients = scopes && scopes.length > 0 ? scopes : await this.keyStore.getAccounts();
124
+
125
+ // For each recipient, fetch secrets, load logs, and store them.
126
+ // We run these per-recipient tasks in parallel so that logs are loaded for all recipients concurrently.
127
+ await Promise.all(
128
+ recipients.map(async recipient => {
129
+ // Get all secrets for this recipient (one per sender)
130
+ const secrets = await this.#getSecretsForSenders(contractAddress, recipient);
131
+
132
+ // Load logs for all sender-recipient pairs in parallel
133
+ const logArrays = await Promise.all(
134
+ secrets.map(secret =>
135
+ loadPrivateLogsForSenderRecipientPair(
136
+ secret,
137
+ contractAddress,
138
+ this.aztecNode,
139
+ this.recipientTaggingStore,
140
+ anchorBlockNumber,
141
+ anchorBlockHash,
142
+ this.jobId,
143
+ ),
144
+ ),
145
+ );
146
+
147
+ // Flatten all logs from all secrets
148
+ const allLogs = logArrays.flat();
149
+
150
+ // Store the logs for this recipient
151
+ if (allLogs.length > 0) {
152
+ await this.#storePendingTaggedLogs(contractAddress, pendingTaggedLogArrayBaseSlot, recipient, allLogs);
153
+ }
154
+ }),
155
+ );
156
+ }
157
+
158
+ async #getSecretsForSenders(
159
+ contractAddress: AztecAddress,
160
+ recipient: AztecAddress,
161
+ ): Promise<DirectionalAppTaggingSecret[]> {
162
+ const recipientCompleteAddress = await this.#getCompleteAddress(recipient);
163
+ const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
164
+
165
+ // We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
166
+ // (recipient = us, sender = us)
167
+ const allSenders = [...(await this.senderAddressBookStore.getSenders()), ...(await this.keyStore.getAccounts())];
168
+
169
+ // We deduplicate the senders by adding them to a set and then converting the set back to an array
170
+ const deduplicatedSenders = Array.from(new Set(allSenders.map(sender => sender.toString()))).map(sender =>
171
+ AztecAddress.fromString(sender),
172
+ );
173
+
174
+ return Promise.all(
175
+ deduplicatedSenders.map(sender => {
176
+ return DirectionalAppTaggingSecret.compute(
177
+ recipientCompleteAddress,
178
+ recipientIvsk,
179
+ sender,
180
+ contractAddress,
181
+ recipient,
182
+ );
183
+ }),
184
+ );
185
+ }
186
+
187
+ #storePendingTaggedLogs(
188
+ contractAddress: AztecAddress,
189
+ capsuleArrayBaseSlot: Fr,
190
+ recipient: AztecAddress,
191
+ privateLogs: TxScopedL2Log[],
192
+ ) {
193
+ // Build all pending tagged logs from the scoped logs
194
+ const pendingTaggedLogs = privateLogs.map(scopedLog => {
195
+ const pendingTaggedLog = new PendingTaggedLog(
196
+ scopedLog.logData,
197
+ scopedLog.txHash,
198
+ scopedLog.noteHashes,
199
+ scopedLog.firstNullifier,
200
+ recipient,
201
+ );
202
+
203
+ return pendingTaggedLog.toFields();
204
+ });
205
+
206
+ // TODO: This looks like it could belong more at the oracle interface level
207
+ return this.capsuleStore.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs, this.jobId);
208
+ }
209
+
210
+ async #getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
211
+ const completeAddress = await this.addressStore.getCompleteAddress(account);
212
+ if (!completeAddress) {
213
+ throw new Error(
214
+ `No public key registered for address ${account}.
215
+ Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
216
+ );
217
+ }
218
+ return completeAddress;
219
+ }
220
+ }
@@ -0,0 +1 @@
1
+ export { NoteService } from './note_service.js';
@@ -0,0 +1,195 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { DataInBlock } from '@aztec/stdlib/block';
4
+ import { computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
5
+ import { type AztecNode, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/client';
6
+ import { Note, NoteDao, NoteStatus } from '@aztec/stdlib/note';
7
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
8
+ import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
9
+
10
+ import type { NoteStore } from '../storage/note_store/note_store.js';
11
+
12
+ export class NoteService {
13
+ constructor(
14
+ private readonly noteStore: NoteStore,
15
+ private readonly aztecNode: AztecNode,
16
+ private readonly anchorBlockHeader: BlockHeader,
17
+ private readonly jobId: string,
18
+ ) {}
19
+
20
+ /**
21
+ * Retrieves a set of notes stored in the database for a given contract address and storage slot.
22
+ * The query result is paginated using 'limit' and 'offset' values.
23
+ * Returns an object containing an array of note data.
24
+ *
25
+ * @param owner - The owner of the notes. If undefined, returns notes for all known owners.
26
+ * @param status - The status of notes to fetch.
27
+ * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all.
28
+ */
29
+ public async getNotes(
30
+ contractAddress: AztecAddress,
31
+ owner: AztecAddress | undefined,
32
+ storageSlot: Fr,
33
+ status: NoteStatus,
34
+ scopes?: AztecAddress[],
35
+ ) {
36
+ const noteDaos = await this.noteStore.getNotes(
37
+ {
38
+ contractAddress,
39
+ owner,
40
+ storageSlot,
41
+ status,
42
+ scopes,
43
+ },
44
+ this.jobId,
45
+ );
46
+ return noteDaos.map(
47
+ ({ contractAddress, owner, storageSlot, randomness, noteNonce, note, noteHash, siloedNullifier }) => ({
48
+ contractAddress,
49
+ owner,
50
+ storageSlot,
51
+ randomness,
52
+ noteNonce,
53
+ note,
54
+ noteHash,
55
+ isPending: false, // Note service deals only with settled notes
56
+ siloedNullifier,
57
+ }),
58
+ );
59
+ }
60
+
61
+ /**
62
+ * Looks for nullifiers of active contract notes and marks them as nullified if a nullifier is found.
63
+ *
64
+ * Fetches notes from the NoteStore and checks which nullifiers are present in the
65
+ * onchain nullifier Merkle tree - up to the latest locally synced block. We use the
66
+ * locally synced block instead of querying the chain's 'latest' block to ensure correctness:
67
+ * notes are only marked nullified once their corresponding nullifier has been included in a
68
+ * block up to which the PXE has synced.
69
+ * This allows recent nullifications to be processed even if the node is not an archive node.
70
+ *
71
+ * @param contractAddress - The contract whose notes should be checked and nullified.
72
+ */
73
+ public async syncNoteNullifiers(contractAddress: AztecAddress): Promise<void> {
74
+ const anchorBlockHash = await this.anchorBlockHeader.hash();
75
+
76
+ const contractNotes = await this.noteStore.getNotes({ contractAddress }, this.jobId);
77
+
78
+ if (contractNotes.length === 0) {
79
+ return;
80
+ }
81
+
82
+ const nullifiersToCheck = contractNotes.map(note => note.siloedNullifier);
83
+ const nullifierBatches = nullifiersToCheck.reduce(
84
+ (acc, nullifier) => {
85
+ if (acc[acc.length - 1].length < MAX_RPC_LEN) {
86
+ acc[acc.length - 1].push(nullifier);
87
+ } else {
88
+ acc.push([nullifier]);
89
+ }
90
+ return acc;
91
+ },
92
+ [[]] as Fr[][],
93
+ );
94
+ const nullifierIndexes = (
95
+ await Promise.all(
96
+ nullifierBatches.map(batch =>
97
+ this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, batch),
98
+ ),
99
+ )
100
+ ).flat();
101
+
102
+ const foundNullifiers = nullifiersToCheck
103
+ .map((nullifier, i) => {
104
+ if (nullifierIndexes[i] !== undefined) {
105
+ return { ...nullifierIndexes[i], ...{ data: nullifier } } as DataInBlock<Fr>;
106
+ }
107
+ })
108
+ .filter(nullifier => nullifier !== undefined) as DataInBlock<Fr>[];
109
+
110
+ await this.noteStore.applyNullifiers(foundNullifiers, this.jobId);
111
+ }
112
+
113
+ public async validateAndStoreNote(
114
+ contractAddress: AztecAddress,
115
+ owner: AztecAddress,
116
+ storageSlot: Fr,
117
+ randomness: Fr,
118
+ noteNonce: Fr,
119
+ content: Fr[],
120
+ noteHash: Fr,
121
+ nullifier: Fr,
122
+ txHash: TxHash,
123
+ recipient: AztecAddress,
124
+ ): Promise<void> {
125
+ // We are going to store the new note in the NoteStore, which will let us later return it via `getNotes`.
126
+ // There's two things we need to check before we do this however:
127
+ // - we must make sure the note does actually exist in the note hash tree
128
+ // - we need to check if the note has already been nullified
129
+ //
130
+ // Failing to do either of the above would result in circuits getting either non-existent notes and failing to
131
+ // produce inclusion proofs for them, or getting nullified notes and producing duplicate nullifiers, both of which
132
+ // are catastrophic failure modes.
133
+ //
134
+ // Note that adding a note and removing it is *not* equivalent to never adding it in the first place. A nullifier
135
+ // emitted in a block that comes after note creation might result in the note being de-nullified by a chain reorg,
136
+ // so we must store both the note hash and nullifier block information.
137
+
138
+ // We avoid making node queries at 'latest' since we don't want to process notes or nullifiers that only exist ahead
139
+ // in time of the locally synced state.
140
+ // Note that while this technically results in historical queries, we perform it at the latest locally synced block
141
+ // number which *should* be recent enough to be available, even for non-archive nodes.
142
+ // Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
143
+ // logs up to the synced block making this only an additional safety check.
144
+ const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
145
+ const anchorBlockHash = await this.anchorBlockHeader.hash();
146
+
147
+ // By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
148
+ // of other contracts, which would constitute a security breach.
149
+ const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, await siloNoteHash(contractAddress, noteHash));
150
+ const siloedNullifier = await siloNullifier(contractAddress, nullifier);
151
+
152
+ const [txEffect, [nullifierIndex]] = await Promise.all([
153
+ this.aztecNode.getTxEffect(txHash),
154
+ this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, [siloedNullifier]),
155
+ ]);
156
+ if (!txEffect) {
157
+ throw new Error(`Could not find tx effect for tx hash ${txHash}`);
158
+ }
159
+
160
+ if (txEffect.l2BlockNumber > anchorBlockNumber) {
161
+ throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${anchorBlockNumber}`);
162
+ }
163
+
164
+ // Find the index of the note hash in the noteHashes array to determine note ordering within the tx
165
+ const noteIndexInTx = txEffect.data.noteHashes.findIndex(nh => nh.equals(uniqueNoteHash));
166
+ if (noteIndexInTx === -1) {
167
+ throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present in tx ${txHash}`);
168
+ }
169
+
170
+ const noteDao = new NoteDao(
171
+ new Note(content),
172
+ contractAddress,
173
+ owner,
174
+ storageSlot,
175
+ randomness,
176
+ noteNonce,
177
+ noteHash,
178
+ siloedNullifier,
179
+ txHash,
180
+ txEffect.l2BlockNumber,
181
+ txEffect.l2BlockHash.toString(),
182
+ txEffect.txIndexInBlock,
183
+ noteIndexInTx,
184
+ );
185
+
186
+ // The note was found by `recipient`, so we use that as the scope when storing the note.
187
+ await this.noteStore.addNotes([noteDao], recipient, this.jobId);
188
+
189
+ if (nullifierIndex !== undefined) {
190
+ // We found nullifier index which implies that the note has already been nullified.
191
+ const { data: _, ...blockHashAndNum } = nullifierIndex;
192
+ await this.noteStore.applyNullifiers([{ data: siloedNullifier, ...blockHashAndNum }], this.jobId);
193
+ }
194
+ }
195
+ }