@aztec/pxe 0.0.1-commit.03f7ef2 → 0.0.1-commit.04852196a

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 (380) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/bin/check_oracle_version.js +1 -1
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +17 -11
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  7. package/dest/block_synchronizer/block_synchronizer.js +80 -34
  8. package/dest/config/index.d.ts +4 -2
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +18 -1
  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 +65 -40
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +212 -92
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -3
  24. package/dest/contract_function_simulator/index.d.ts +2 -2
  25. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.js +1 -1
  27. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -4
  30. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
  31. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -2
  33. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  34. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  36. package/dest/contract_function_simulator/oracle/interfaces.d.ts +55 -47
  37. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  39. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  41. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  43. package/dest/contract_function_simulator/oracle/oracle.d.ts +44 -42
  44. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/oracle.js +178 -112
  46. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  47. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/oracle/private_execution.js +2 -38
  49. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +63 -63
  50. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +120 -88
  52. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +106 -70
  53. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +167 -145
  55. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  56. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  57. package/dest/contract_function_simulator/proxied_contract_data_source.js +5 -5
  58. package/dest/contract_logging.d.ts +22 -0
  59. package/dest/contract_logging.d.ts.map +1 -0
  60. package/dest/contract_logging.js +23 -0
  61. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  62. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  63. package/dest/contract_sync/contract_sync_service.js +97 -0
  64. package/dest/contract_sync/helpers.d.ts +29 -0
  65. package/dest/contract_sync/helpers.d.ts.map +1 -0
  66. package/dest/contract_sync/helpers.js +55 -0
  67. package/dest/debug/pxe_debug_utils.d.ts +26 -12
  68. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  69. package/dest/debug/pxe_debug_utils.js +30 -19
  70. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  71. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  72. package/dest/entrypoints/client/bundle/index.js +3 -0
  73. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  74. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  75. package/dest/entrypoints/client/bundle/utils.js +31 -8
  76. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  77. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  78. package/dest/entrypoints/client/lazy/index.js +3 -0
  79. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  80. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  81. package/dest/entrypoints/client/lazy/utils.js +32 -9
  82. package/dest/entrypoints/pxe_creation_options.d.ts +5 -3
  83. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  84. package/dest/entrypoints/server/index.d.ts +5 -1
  85. package/dest/entrypoints/server/index.d.ts.map +1 -1
  86. package/dest/entrypoints/server/index.js +4 -0
  87. package/dest/entrypoints/server/utils.d.ts +1 -1
  88. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  89. package/dest/entrypoints/server/utils.js +39 -16
  90. package/dest/error_enriching.d.ts +4 -4
  91. package/dest/error_enriching.d.ts.map +1 -1
  92. package/dest/error_enriching.js +6 -6
  93. package/dest/events/event_service.d.ts +8 -8
  94. package/dest/events/event_service.d.ts.map +1 -1
  95. package/dest/events/event_service.js +21 -24
  96. package/dest/events/private_event_filter_validator.d.ts +6 -6
  97. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  98. package/dest/events/private_event_filter_validator.js +5 -6
  99. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  100. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  101. package/dest/job_coordinator/job_coordinator.js +94 -0
  102. package/dest/logs/log_service.d.ts +18 -32
  103. package/dest/logs/log_service.d.ts.map +1 -1
  104. package/dest/logs/log_service.js +76 -197
  105. package/dest/notes/note_service.d.ts +13 -12
  106. package/dest/notes/note_service.d.ts.map +1 -1
  107. package/dest/notes/note_service.js +42 -46
  108. package/dest/notes_filter.d.ts +25 -0
  109. package/dest/notes_filter.d.ts.map +1 -0
  110. package/dest/notes_filter.js +4 -0
  111. package/dest/oracle_version.d.ts +3 -3
  112. package/dest/oracle_version.d.ts.map +1 -1
  113. package/dest/oracle_version.js +5 -4
  114. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  115. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  116. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  117. package/dest/private_kernel/hints/index.d.ts +3 -3
  118. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  119. package/dest/private_kernel/hints/index.js +2 -2
  120. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
  121. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  122. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +141 -74
  123. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  124. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  125. package/dest/private_kernel/hints/test_utils.js +203 -0
  126. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  127. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  128. package/dest/private_kernel/private_kernel_execution_prover.js +24 -17
  129. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -24
  130. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  131. package/dest/private_kernel/private_kernel_oracle.js +94 -2
  132. package/dest/pxe.d.ts +87 -67
  133. package/dest/pxe.d.ts.map +1 -1
  134. package/dest/pxe.js +211 -189
  135. package/dest/storage/address_store/address_store.d.ts +11 -0
  136. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  137. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +13 -12
  138. package/dest/storage/address_store/index.d.ts +2 -0
  139. package/dest/storage/address_store/index.d.ts.map +1 -0
  140. package/dest/storage/address_store/index.js +1 -0
  141. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +17 -0
  142. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  143. package/dest/storage/{anchor_block_data_provider/anchor_block_data_provider.js → anchor_block_store/anchor_block_store.js} +9 -2
  144. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  145. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  146. package/dest/storage/anchor_block_store/index.js +1 -0
  147. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  148. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  149. package/dest/storage/capsule_store/capsule_store.js +253 -0
  150. package/dest/storage/capsule_store/index.d.ts +2 -0
  151. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  152. package/dest/storage/capsule_store/index.js +1 -0
  153. package/dest/storage/contract_store/contract_store.d.ts +93 -0
  154. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  155. package/dest/storage/contract_store/contract_store.js +309 -0
  156. package/dest/storage/contract_store/index.d.ts +2 -0
  157. package/dest/storage/contract_store/index.d.ts.map +1 -0
  158. package/dest/storage/contract_store/index.js +1 -0
  159. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  160. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  161. package/dest/storage/index.d.ts +8 -8
  162. package/dest/storage/index.d.ts.map +1 -1
  163. package/dest/storage/index.js +7 -7
  164. package/dest/storage/metadata.d.ts +1 -1
  165. package/dest/storage/metadata.js +1 -1
  166. package/dest/storage/note_store/index.d.ts +3 -0
  167. package/dest/storage/note_store/index.d.ts.map +1 -0
  168. package/dest/storage/note_store/index.js +2 -0
  169. package/dest/storage/note_store/note_store.d.ts +83 -0
  170. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  171. package/dest/storage/note_store/note_store.js +343 -0
  172. package/dest/storage/note_store/stored_note.d.ts +16 -0
  173. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  174. package/dest/storage/note_store/stored_note.js +43 -0
  175. package/dest/storage/private_event_store/private_event_store.d.ts +91 -0
  176. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  177. package/dest/storage/private_event_store/private_event_store.js +273 -0
  178. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  179. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  180. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  181. package/dest/storage/tagging_store/index.d.ts +4 -0
  182. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  183. package/dest/storage/tagging_store/index.js +3 -0
  184. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
  185. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  186. package/dest/storage/tagging_store/recipient_tagging_store.js +111 -0
  187. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  188. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  189. package/dest/storage/tagging_store/sender_address_book_store.js +36 -0
  190. package/dest/storage/{tagging_data_provider/sender_tagging_data_provider.d.ts → tagging_store/sender_tagging_store.d.ts} +20 -10
  191. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  192. package/dest/storage/tagging_store/sender_tagging_store.js +348 -0
  193. package/dest/tagging/constants.d.ts +2 -2
  194. package/dest/tagging/constants.d.ts.map +1 -1
  195. package/dest/tagging/constants.js +10 -3
  196. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  197. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  198. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  199. package/dest/tagging/index.d.ts +16 -4
  200. package/dest/tagging/index.d.ts.map +1 -1
  201. package/dest/tagging/index.js +15 -3
  202. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +6 -6
  203. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  204. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +13 -13
  205. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  206. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -7
  207. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  208. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +16 -12
  209. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +17 -0
  210. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  211. package/dest/tagging/{sync → sender_sync}/sync_sender_tagging_indexes.js +9 -27
  212. package/dest/tagging/{sync → sender_sync}/utils/get_status_change_of_pending.d.ts +1 -1
  213. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  214. package/dest/tagging/{sync → sender_sync}/utils/get_status_change_of_pending.js +5 -8
  215. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
  216. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  217. package/dest/tagging/{sync → sender_sync}/utils/load_and_store_new_tagging_indexes.js +25 -21
  218. package/package.json +27 -18
  219. package/src/access_scopes.ts +9 -0
  220. package/src/bin/check_oracle_version.ts +1 -0
  221. package/src/block_synchronizer/block_synchronizer.ts +99 -46
  222. package/src/config/index.ts +15 -1
  223. package/src/config/package_info.ts +1 -1
  224. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  225. package/src/contract_function_simulator/contract_function_simulator.ts +366 -156
  226. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  227. package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
  228. package/src/contract_function_simulator/index.ts +1 -1
  229. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +6 -2
  230. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  231. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  232. package/src/contract_function_simulator/oracle/interfaces.ts +62 -49
  233. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  234. package/src/contract_function_simulator/oracle/oracle.ts +194 -134
  235. package/src/contract_function_simulator/oracle/private_execution.ts +2 -70
  236. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +157 -168
  237. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +245 -167
  238. package/src/contract_function_simulator/proxied_contract_data_source.ts +7 -7
  239. package/src/contract_logging.ts +39 -0
  240. package/src/contract_sync/contract_sync_service.ts +152 -0
  241. package/src/contract_sync/helpers.ts +98 -0
  242. package/src/debug/pxe_debug_utils.ts +65 -20
  243. package/src/entrypoints/client/bundle/index.ts +3 -0
  244. package/src/entrypoints/client/bundle/utils.ts +23 -16
  245. package/src/entrypoints/client/lazy/index.ts +3 -0
  246. package/src/entrypoints/client/lazy/utils.ts +24 -17
  247. package/src/entrypoints/pxe_creation_options.ts +4 -2
  248. package/src/entrypoints/server/index.ts +4 -0
  249. package/src/entrypoints/server/utils.ts +33 -41
  250. package/src/error_enriching.ts +7 -15
  251. package/src/events/event_service.ts +22 -28
  252. package/src/events/private_event_filter_validator.ts +4 -6
  253. package/src/job_coordinator/job_coordinator.ts +150 -0
  254. package/src/logs/log_service.ts +122 -273
  255. package/src/notes/note_service.ts +45 -49
  256. package/src/notes_filter.ts +26 -0
  257. package/src/oracle_version.ts +5 -4
  258. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  259. package/src/private_kernel/hints/index.ts +2 -2
  260. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +196 -138
  261. package/src/private_kernel/hints/test_utils.ts +325 -0
  262. package/src/private_kernel/private_kernel_execution_prover.ts +27 -19
  263. package/src/private_kernel/private_kernel_oracle.ts +116 -36
  264. package/src/pxe.ts +339 -261
  265. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +16 -16
  266. package/src/storage/address_store/index.ts +1 -0
  267. package/src/storage/{anchor_block_data_provider/anchor_block_data_provider.ts → anchor_block_store/anchor_block_store.ts} +9 -1
  268. package/src/storage/anchor_block_store/index.ts +1 -0
  269. package/src/storage/capsule_store/capsule_store.ts +315 -0
  270. package/src/storage/capsule_store/index.ts +1 -0
  271. package/src/storage/contract_store/contract_store.ts +429 -0
  272. package/src/storage/contract_store/index.ts +1 -0
  273. package/src/storage/index.ts +7 -7
  274. package/src/storage/metadata.ts +1 -1
  275. package/src/storage/note_store/index.ts +2 -0
  276. package/src/storage/note_store/note_store.ts +418 -0
  277. package/src/storage/note_store/stored_note.ts +48 -0
  278. package/src/storage/private_event_store/private_event_store.ts +384 -0
  279. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  280. package/src/storage/tagging_store/index.ts +3 -0
  281. package/src/storage/tagging_store/recipient_tagging_store.ts +143 -0
  282. package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
  283. package/src/storage/tagging_store/sender_tagging_store.ts +429 -0
  284. package/src/tagging/constants.ts +10 -3
  285. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  286. package/src/tagging/index.ts +18 -3
  287. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +29 -18
  288. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  289. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +17 -16
  290. package/src/tagging/{sync → sender_sync}/sync_sender_tagging_indexes.ts +15 -33
  291. package/src/tagging/{sync → sender_sync}/utils/get_status_change_of_pending.ts +5 -13
  292. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +75 -0
  293. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  294. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  295. package/dest/contract_function_simulator/proxied_node.js +0 -27
  296. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  297. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  298. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  299. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  300. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  301. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  302. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  303. package/dest/public_storage/public_storage_service.d.ts +0 -24
  304. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  305. package/dest/public_storage/public_storage_service.js +0 -26
  306. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  307. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  308. package/dest/storage/address_data_provider/index.d.ts +0 -2
  309. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  310. package/dest/storage/address_data_provider/index.js +0 -1
  311. package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts +0 -9
  312. package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts.map +0 -1
  313. package/dest/storage/anchor_block_data_provider/index.d.ts +0 -2
  314. package/dest/storage/anchor_block_data_provider/index.d.ts.map +0 -1
  315. package/dest/storage/anchor_block_data_provider/index.js +0 -1
  316. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -57
  317. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  318. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -146
  319. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  320. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  321. package/dest/storage/capsule_data_provider/index.js +0 -1
  322. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +0 -66
  323. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  324. package/dest/storage/contract_data_provider/contract_data_provider.js +0 -224
  325. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  326. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  327. package/dest/storage/contract_data_provider/index.js +0 -1
  328. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  329. package/dest/storage/note_data_provider/index.d.ts +0 -3
  330. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  331. package/dest/storage/note_data_provider/index.js +0 -2
  332. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -84
  333. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  334. package/dest/storage/note_data_provider/note_data_provider.js +0 -322
  335. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -51
  336. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  337. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -115
  338. package/dest/storage/tagging_data_provider/index.d.ts +0 -3
  339. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  340. package/dest/storage/tagging_data_provider/index.js +0 -2
  341. package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts +0 -31
  342. package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts.map +0 -1
  343. package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.js +0 -65
  344. package/dest/storage/tagging_data_provider/sender_tagging_data_provider.d.ts.map +0 -1
  345. package/dest/storage/tagging_data_provider/sender_tagging_data_provider.js +0 -196
  346. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts +0 -21
  347. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts.map +0 -1
  348. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.js +0 -42
  349. package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts +0 -21
  350. package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts.map +0 -1
  351. package/dest/tagging/sync/utils/get_status_change_of_pending.d.ts.map +0 -1
  352. package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts +0 -18
  353. package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts.map +0 -1
  354. package/dest/tagging/utils.d.ts +0 -18
  355. package/dest/tagging/utils.d.ts.map +0 -1
  356. package/dest/tagging/utils.js +0 -25
  357. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  358. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  359. package/dest/tree_membership/tree_membership_service.js +0 -84
  360. package/src/contract_function_simulator/proxied_node.ts +0 -33
  361. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
  362. package/src/public_storage/public_storage_service.ts +0 -33
  363. package/src/storage/address_data_provider/index.ts +0 -1
  364. package/src/storage/anchor_block_data_provider/index.ts +0 -1
  365. package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -179
  366. package/src/storage/capsule_data_provider/index.ts +0 -1
  367. package/src/storage/contract_data_provider/contract_data_provider.ts +0 -319
  368. package/src/storage/contract_data_provider/index.ts +0 -1
  369. package/src/storage/note_data_provider/index.ts +0 -2
  370. package/src/storage/note_data_provider/note_data_provider.ts +0 -412
  371. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -162
  372. package/src/storage/tagging_data_provider/index.ts +0 -2
  373. package/src/storage/tagging_data_provider/recipient_tagging_data_provider.ts +0 -86
  374. package/src/storage/tagging_data_provider/sender_tagging_data_provider.ts +0 -244
  375. package/src/tagging/recipient_sync/new_recipient_tagging_data_provider.ts +0 -53
  376. package/src/tagging/sync/utils/load_and_store_new_tagging_indexes.ts +0 -72
  377. package/src/tagging/utils.ts +0 -32
  378. package/src/tree_membership/tree_membership_service.ts +0 -112
  379. /package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +0 -0
  380. /package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +0 -0
@@ -1,133 +0,0 @@
1
- import { NOTE_HASH_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT, VK_TREE_HEIGHT } from '@aztec/constants';
2
- import type { Fr } from '@aztec/foundation/curves/bn254';
3
- import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
4
- import { createLogger } from '@aztec/foundation/log';
5
- import type { Tuple } from '@aztec/foundation/serialize';
6
- import { MembershipWitness } from '@aztec/foundation/trees';
7
- import type { KeyStore } from '@aztec/key-store';
8
- import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree';
9
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
10
- import type { FunctionSelector } from '@aztec/stdlib/abi';
11
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
12
- import type { BlockParameter } from '@aztec/stdlib/block';
13
- import { computeContractClassIdPreimage, computeSaltedInitializationHash } from '@aztec/stdlib/contract';
14
- import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
15
- import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
16
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
17
- import { UpdatedClassIdHints } from '@aztec/stdlib/kernel';
18
- import type { NullifierMembershipWitness } from '@aztec/stdlib/trees';
19
- import type { VerificationKeyAsFields } from '@aztec/stdlib/vks';
20
-
21
- import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
22
- import type { PrivateKernelOracle } from './private_kernel_oracle.js';
23
-
24
- // TODO: Block number should not be "latest".
25
- // It should be fixed at the time the proof is being simulated. I.e., it should be the same as the value defined in the constant data.
26
-
27
- /**
28
- * A data oracle that provides information needed for simulating a transaction.
29
- */
30
- export class PrivateKernelOracleImpl implements PrivateKernelOracle {
31
- constructor(
32
- private contractDataProvider: ContractDataProvider,
33
- private keyStore: KeyStore,
34
- private node: AztecNode,
35
- private blockNumber: BlockParameter = 'latest',
36
- private log = createLogger('pxe:kernel_oracle'),
37
- ) {}
38
-
39
- public async getContractAddressPreimage(address: AztecAddress) {
40
- const instance = await this.contractDataProvider.getContractInstance(address);
41
- if (!instance) {
42
- throw new Error(`Contract instance not found when getting address preimage. Contract address: ${address}.`);
43
- }
44
- return {
45
- saltedInitializationHash: await computeSaltedInitializationHash(instance),
46
- ...instance,
47
- };
48
- }
49
-
50
- public async getContractClassIdPreimage(contractClassId: Fr) {
51
- const contractClass = await this.contractDataProvider.getContractClass(contractClassId);
52
- if (!contractClass) {
53
- throw new Error(`Contract class not found when getting class id preimage. Class id: ${contractClassId}.`);
54
- }
55
- return computeContractClassIdPreimage(contractClass);
56
- }
57
-
58
- public async getFunctionMembershipWitness(contractClassId: Fr, selector: FunctionSelector) {
59
- const membershipWitness = await this.contractDataProvider.getFunctionMembershipWitness(contractClassId, selector);
60
- if (!membershipWitness) {
61
- throw new Error(
62
- `Membership witness not found for contract class id ${contractClassId} and selector ${selector}.`,
63
- );
64
- }
65
- return membershipWitness;
66
- }
67
-
68
- public getVkMembershipWitness(vk: VerificationKeyAsFields) {
69
- const leafIndex = getVKIndex(vk);
70
- return Promise.resolve(new MembershipWitness(VK_TREE_HEIGHT, BigInt(leafIndex), getVKSiblingPath(leafIndex)));
71
- }
72
-
73
- async getNoteHashMembershipWitness(leafIndex: bigint): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT>> {
74
- const path = await this.node.getNoteHashSiblingPath(this.blockNumber, leafIndex);
75
- return new MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT>(
76
- path.pathSize,
77
- leafIndex,
78
- path.toFields() as Tuple<Fr, typeof NOTE_HASH_TREE_HEIGHT>,
79
- );
80
- }
81
-
82
- getNullifierMembershipWitness(nullifier: Fr): Promise<NullifierMembershipWitness | undefined> {
83
- return this.node.getNullifierMembershipWitness(this.blockNumber, nullifier);
84
- }
85
-
86
- async getNoteHashTreeRoot(): Promise<Fr> {
87
- const header = await this.node.getBlockHeader(this.blockNumber);
88
- if (!header) {
89
- throw new Error(`No block header found for block number ${this.blockNumber}`);
90
- }
91
- return header.state.partial.noteHashTree.root;
92
- }
93
-
94
- public getMasterSecretKey(masterPublicKey: Point): Promise<GrumpkinScalar> {
95
- return this.keyStore.getMasterSecretKey(masterPublicKey);
96
- }
97
-
98
- public getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string> {
99
- return this.contractDataProvider.getDebugFunctionName(contractAddress, selector);
100
- }
101
-
102
- public async getUpdatedClassIdHints(contractAddress: AztecAddress): Promise<UpdatedClassIdHints> {
103
- const { delayedPublicMutableSlot, delayedPublicMutableHashSlot } =
104
- await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(contractAddress);
105
-
106
- const hashLeafSlot = await computePublicDataTreeLeafSlot(
107
- ProtocolContractAddress.ContractInstanceRegistry,
108
- delayedPublicMutableHashSlot,
109
- );
110
- const updatedClassIdWitness = await this.node.getPublicDataWitness(this.blockNumber, hashLeafSlot);
111
-
112
- if (!updatedClassIdWitness) {
113
- throw new Error(`No public data tree witness found for ${hashLeafSlot}`);
114
- }
115
-
116
- const readStorage = (storageSlot: Fr) =>
117
- this.node.getPublicStorageAt(this.blockNumber, ProtocolContractAddress.ContractInstanceRegistry, storageSlot);
118
- const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(
119
- delayedPublicMutableSlot,
120
- readStorage,
121
- );
122
-
123
- return new UpdatedClassIdHints(
124
- new MembershipWitness(
125
- PUBLIC_DATA_TREE_HEIGHT,
126
- updatedClassIdWitness.index,
127
- updatedClassIdWitness.siblingPath.toTuple(),
128
- ),
129
- updatedClassIdWitness.leafPreimage,
130
- delayedPublicMutableValues,
131
- );
132
- }
133
- }
@@ -1,33 +0,0 @@
1
- import type { Fr } from '@aztec/foundation/curves/bn254';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import type { BlockParameter } from '@aztec/stdlib/block';
4
- import type { AztecNode } from '@aztec/stdlib/interfaces/server';
5
-
6
- import type { AnchorBlockDataProvider } from '../storage/anchor_block_data_provider/anchor_block_data_provider.js';
7
-
8
- export class PublicStorageService {
9
- constructor(
10
- private readonly anchorBlockDataProvider: AnchorBlockDataProvider,
11
- private readonly aztecNode: AztecNode,
12
- ) {}
13
-
14
- /**
15
- * Gets the storage value at the given contract storage slot.
16
- *
17
- * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
18
- * Aztec's version of `eth_getStorageAt`.
19
- *
20
- * @param blockNumber - The block number at which to get the data.
21
- * @param contract - Address of the contract to query.
22
- * @param slot - Slot to query.
23
- * @returns Storage value at the given contract slot.
24
- * @throws If the contract is not deployed.
25
- */
26
- public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
27
- const anchorBlockNumber = (await this.anchorBlockDataProvider.getBlockHeader()).getBlockNumber();
28
- if (blockNumber !== 'latest' && blockNumber > anchorBlockNumber) {
29
- throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
30
- }
31
- return await this.aztecNode.getPublicStorageAt(blockNumber, contract, slot);
32
- }
33
- }
@@ -1 +0,0 @@
1
- export { AddressDataProvider } from './address_data_provider.js';
@@ -1 +0,0 @@
1
- export { AnchorBlockDataProvider } from './anchor_block_data_provider.js';
@@ -1,179 +0,0 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { type Logger, createLogger } from '@aztec/foundation/log';
3
- import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
4
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
-
6
- export class CapsuleDataProvider {
7
- #store: AztecAsyncKVStore;
8
-
9
- // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
10
- #capsules: AztecAsyncMap<string, Buffer>;
11
-
12
- logger: Logger;
13
-
14
- constructor(store: AztecAsyncKVStore) {
15
- this.#store = store;
16
-
17
- this.#capsules = this.#store.openMap('capsules');
18
-
19
- this.logger = createLogger('pxe:capsule-data-provider');
20
- }
21
-
22
- /**
23
- * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
24
- * * If data was already stored at this slot, it is overwritten.
25
- * @param contractAddress - The contract address to scope the data under.
26
- * @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
27
- * @param capsule - An array of field elements representing the capsule.
28
- * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
29
- * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
30
- * network state it's backed by local PXE db.
31
- */
32
- async storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
33
- await this.#capsules.set(dbSlotToKey(contractAddress, slot), Buffer.concat(capsule.map(value => value.toBuffer())));
34
- }
35
-
36
- /**
37
- * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
38
- * @param contractAddress - The contract address under which the data is scoped.
39
- * @param slot - The slot in the database to read.
40
- * @returns The stored data or `null` if no data is stored under the slot.
41
- */
42
- async loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
43
- const dataBuffer = await this.#capsules.getAsync(dbSlotToKey(contractAddress, slot));
44
- if (!dataBuffer) {
45
- this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
46
- return null;
47
- }
48
- const capsule: Fr[] = [];
49
- for (let i = 0; i < dataBuffer.length; i += Fr.SIZE_IN_BYTES) {
50
- capsule.push(Fr.fromBuffer(dataBuffer.subarray(i, i + Fr.SIZE_IN_BYTES)));
51
- }
52
- return capsule;
53
- }
54
-
55
- /**
56
- * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
57
- * @param contractAddress - The contract address under which the data is scoped.
58
- * @param slot - The slot in the database to delete.
59
- */
60
- async deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
61
- await this.#capsules.delete(dbSlotToKey(contractAddress, slot));
62
- }
63
-
64
- /**
65
- * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
66
- * structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
67
- * Supports overlapping source and destination regions (which will result in the overlapped source values being
68
- * overwritten). All copied slots must exist in the database (i.e. have been stored and not deleted)
69
- *
70
- * @param contractAddress - The contract address under which the data is scoped.
71
- * @param srcSlot - The first slot to copy from.
72
- * @param dstSlot - The first slot to copy to.
73
- * @param numEntries - The number of entries to copy.
74
- */
75
- copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
76
- return this.#store.transactionAsync(async () => {
77
- // In order to support overlapping source and destination regions, we need to check the relative positions of source
78
- // and destination. If destination is ahead of source, then by the time we overwrite source elements using forward
79
- // indexes we'll have already read those. On the contrary, if source is ahead of destination we need to use backward
80
- // indexes to avoid reading elements that've been overwritten.
81
-
82
- const indexes = Array.from(Array(numEntries).keys());
83
- if (srcSlot.lt(dstSlot)) {
84
- indexes.reverse();
85
- }
86
-
87
- for (const i of indexes) {
88
- const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
89
- const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
90
-
91
- const toCopy = await this.#capsules.getAsync(currentSrcSlot);
92
- if (!toCopy) {
93
- throw new Error(`Attempted to copy empty slot ${currentSrcSlot} for contract ${contractAddress.toString()}`);
94
- }
95
-
96
- await this.#capsules.set(currentDstSlot, toCopy);
97
- }
98
- });
99
- }
100
-
101
- /**
102
- * Appends multiple capsules to a capsule array stored at the base slot.
103
- * The array length is stored at the base slot, and elements are stored in consecutive slots after it.
104
- * All operations are performed in a single transaction.
105
- * @param contractAddress - The contract address that owns the capsule array
106
- * @param baseSlot - The slot where the array length is stored
107
- * @param content - Array of capsule data to append
108
- */
109
- appendToCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][]): Promise<void> {
110
- return this.#store.transactionAsync(async () => {
111
- // Load current length, defaulting to 0 if not found
112
- const lengthData = await this.loadCapsule(contractAddress, baseSlot);
113
- const currentLength = lengthData ? lengthData[0].toNumber() : 0;
114
-
115
- // Store each capsule at consecutive slots after baseSlot + 1 + currentLength
116
- for (let i = 0; i < content.length; i++) {
117
- const nextSlot = arraySlot(baseSlot, currentLength + i);
118
- await this.storeCapsule(contractAddress, nextSlot, content[i]);
119
- }
120
-
121
- // Update length to include all new capsules
122
- const newLength = currentLength + content.length;
123
- await this.storeCapsule(contractAddress, baseSlot, [new Fr(newLength)]);
124
- });
125
- }
126
-
127
- readCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr): Promise<Fr[][]> {
128
- return this.#store.transactionAsync(async () => {
129
- // Load length, defaulting to 0 if not found
130
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
131
- const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
132
-
133
- const values: Fr[][] = [];
134
-
135
- // Read each capsule at consecutive slots after baseSlot
136
- for (let i = 0; i < length; i++) {
137
- const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i));
138
- if (currentValue == undefined) {
139
- throw new Error(
140
- `Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`,
141
- );
142
- }
143
-
144
- values.push(currentValue);
145
- }
146
-
147
- return values;
148
- });
149
- }
150
-
151
- setCapsuleArray(contractAddress: AztecAddress, baseSlot: Fr, content: Fr[][]) {
152
- return this.#store.transactionAsync(async () => {
153
- // Load current length, defaulting to 0 if not found
154
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
155
- const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
156
-
157
- // Set the new length
158
- await this.storeCapsule(contractAddress, baseSlot, [new Fr(content.length)]);
159
-
160
- // Store the new content, possibly overwriting existing values
161
- for (let i = 0; i < content.length; i++) {
162
- await this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i]);
163
- }
164
-
165
- // Clear any stragglers
166
- for (let i = content.length; i < originalLength; i++) {
167
- await this.deleteCapsule(contractAddress, arraySlot(baseSlot, i));
168
- }
169
- });
170
- }
171
- }
172
-
173
- function dbSlotToKey(contractAddress: AztecAddress, slot: Fr): string {
174
- return `${contractAddress.toString()}:${slot.toString()}`;
175
- }
176
-
177
- function arraySlot(baseSlot: Fr, index: number) {
178
- return baseSlot.add(new Fr(1)).add(new Fr(index));
179
- }
@@ -1 +0,0 @@
1
- export { CapsuleDataProvider } from './capsule_data_provider.js';
@@ -1,319 +0,0 @@
1
- import type { FUNCTION_TREE_HEIGHT } from '@aztec/constants';
2
- import type { Fr } from '@aztec/foundation/curves/bn254';
3
- import { toArray } from '@aztec/foundation/iterable';
4
- import type { MembershipWitness } from '@aztec/foundation/trees';
5
- import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
6
- import {
7
- type ContractArtifact,
8
- type FunctionAbi,
9
- type FunctionArtifact,
10
- type FunctionArtifactWithContractName,
11
- FunctionCall,
12
- type FunctionDebugMetadata,
13
- FunctionSelector,
14
- FunctionType,
15
- contractArtifactFromBuffer,
16
- contractArtifactToBuffer,
17
- encodeArguments,
18
- getFunctionDebugMetadata,
19
- } from '@aztec/stdlib/abi';
20
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
21
- import {
22
- type ContractClass,
23
- type ContractInstanceWithAddress,
24
- SerializableContractInstance,
25
- getContractClassFromArtifact,
26
- } from '@aztec/stdlib/contract';
27
-
28
- import { PrivateFunctionsTree } from './private_functions_tree.js';
29
-
30
- /**
31
- * ContractDataProvider serves as a data manager and retriever for Aztec.nr contracts.
32
- * It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
33
- * from a given contract address and function selector. The class maintains a cache of ContractTree instances
34
- * to efficiently serve the requested data. It interacts with the ContractDatabase and AztecNode to fetch
35
- * the required information and facilitate cryptographic proof generation.
36
- */
37
- export class ContractDataProvider {
38
- /** Map from contract class id to private function tree. */
39
- // TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
40
- #privateFunctionTrees: Map<string, PrivateFunctionsTree> = new Map();
41
-
42
- /** Map from contract address to contract class id */
43
- #contractClassIdMap: Map<string, Fr> = new Map();
44
-
45
- #contractArtifacts: AztecAsyncMap<string, Buffer>;
46
- #contractInstances: AztecAsyncMap<string, Buffer>;
47
-
48
- constructor(store: AztecAsyncKVStore) {
49
- this.#contractArtifacts = store.openMap('contract_artifacts');
50
- this.#contractInstances = store.openMap('contracts_instances');
51
- }
52
-
53
- // Setters
54
-
55
- public async addContractArtifact(id: Fr, contract: ContractArtifact): Promise<void> {
56
- const privateFunctions = contract.functions.filter(
57
- functionArtifact => functionArtifact.functionType === FunctionType.PRIVATE,
58
- );
59
-
60
- const privateSelectors = await Promise.all(
61
- privateFunctions.map(async privateFunctionArtifact =>
62
- (
63
- await FunctionSelector.fromNameAndParameters(privateFunctionArtifact.name, privateFunctionArtifact.parameters)
64
- ).toString(),
65
- ),
66
- );
67
-
68
- if (privateSelectors.length !== new Set(privateSelectors).size) {
69
- throw new Error('Repeated function selectors of private functions');
70
- }
71
-
72
- await this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract));
73
- }
74
-
75
- async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
76
- this.#contractClassIdMap.set(contract.address.toString(), contract.currentContractClassId);
77
-
78
- await this.#contractInstances.set(
79
- contract.address.toString(),
80
- new SerializableContractInstance(contract).toBuffer(),
81
- );
82
- }
83
-
84
- // Private getters
85
-
86
- async #getContractClassId(contractAddress: AztecAddress): Promise<Fr | undefined> {
87
- if (!this.#contractClassIdMap.has(contractAddress.toString())) {
88
- const instance = await this.getContractInstance(contractAddress);
89
- if (!instance) {
90
- return;
91
- }
92
- this.#contractClassIdMap.set(contractAddress.toString(), instance.currentContractClassId);
93
- }
94
- return this.#contractClassIdMap.get(contractAddress.toString());
95
- }
96
-
97
- /**
98
- * Retrieve or create a ContractTree instance based on the provided class id.
99
- * If an existing tree with the same class id is found in the cache, it will be returned.
100
- * Otherwise, a new ContractTree instance will be created using the contract data from the database
101
- * and added to the cache before returning.
102
- *
103
- * @param classId - The class id of the contract for which the ContractTree is required.
104
- * @returns A ContractTree instance associated with the specified contract address.
105
- * @throws An Error if the contract is not found in the ContractDatabase.
106
- */
107
- async #getPrivateFunctionTreeForClassId(classId: Fr): Promise<PrivateFunctionsTree | undefined> {
108
- if (!this.#privateFunctionTrees.has(classId.toString())) {
109
- const artifact = await this.getContractArtifact(classId);
110
- if (!artifact) {
111
- return;
112
- }
113
- const tree = await PrivateFunctionsTree.create(artifact);
114
- this.#privateFunctionTrees.set(classId.toString(), tree);
115
- }
116
- return this.#privateFunctionTrees.get(classId.toString())!;
117
- }
118
-
119
- async #getContractArtifactByAddress(contractAddress: AztecAddress): Promise<ContractArtifact | undefined> {
120
- const contractClassId = await this.#getContractClassId(contractAddress);
121
- return contractClassId && this.getContractArtifact(contractClassId);
122
- }
123
-
124
- // Public getters
125
-
126
- async getContractsAddresses(): Promise<AztecAddress[]> {
127
- const keys = await toArray(this.#contractInstances.keysAsync());
128
- return keys.map(AztecAddress.fromString);
129
- }
130
-
131
- /** Returns a contract instance for a given address. Throws if not found. */
132
- public async getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
133
- const contract = await this.#contractInstances.getAsync(contractAddress.toString());
134
- return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
135
- }
136
-
137
- public async getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | undefined> {
138
- const contract = await this.#contractArtifacts.getAsync(contractClassId.toString());
139
- // TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
140
- return contract && contractArtifactFromBuffer(Buffer.from(contract));
141
- }
142
-
143
- /** Returns a contract class for a given class id. Throws if not found. */
144
- public async getContractClass(contractClassId: Fr): Promise<ContractClass | undefined> {
145
- const artifact = await this.getContractArtifact(contractClassId);
146
- return artifact && getContractClassFromArtifact(artifact);
147
- }
148
-
149
- public async getContract(
150
- address: AztecAddress,
151
- ): Promise<(ContractInstanceWithAddress & ContractArtifact) | undefined> {
152
- const instance = await this.getContractInstance(address);
153
- if (!instance) {
154
- return;
155
- }
156
- const artifact = await this.getContractArtifact(instance.currentContractClassId);
157
- if (!artifact) {
158
- return;
159
- }
160
- return { ...instance, ...artifact };
161
- }
162
-
163
- /**
164
- * Retrieves the artifact of a specified function within a given contract.
165
- * The function is identified by its selector, which is a unique code generated from the function's signature.
166
- * Throws an error if the contract address or function selector are invalid or not found.
167
- *
168
- * @param contractAddress - The AztecAddress representing the contract containing the function.
169
- * @param selector - The function selector.
170
- * @returns The corresponding function's artifact as an object.
171
- */
172
- public async getFunctionArtifact(
173
- contractAddress: AztecAddress,
174
- selector: FunctionSelector,
175
- ): Promise<FunctionArtifactWithContractName | undefined> {
176
- const artifact = await this.#getContractArtifactByAddress(contractAddress);
177
- const fnArtifact = artifact && (await this.#findFunctionArtifactBySelector(artifact, selector));
178
- return fnArtifact && { ...fnArtifact, contractName: artifact.name };
179
- }
180
-
181
- public async getFunctionArtifactWithDebugMetadata(
182
- contractAddress: AztecAddress,
183
- selector: FunctionSelector,
184
- ): Promise<FunctionArtifactWithContractName> {
185
- const artifact = await this.getFunctionArtifact(contractAddress, selector);
186
- if (!artifact) {
187
- throw new Error(`Function artifact not found for contract ${contractAddress} and selector ${selector}.`);
188
- }
189
- const debug = await this.getFunctionDebugMetadata(contractAddress, selector);
190
- return {
191
- ...artifact,
192
- debug,
193
- };
194
- }
195
-
196
- public async getPublicFunctionArtifact(
197
- contractAddress: AztecAddress,
198
- ): Promise<FunctionArtifactWithContractName | undefined> {
199
- const artifact = await this.#getContractArtifactByAddress(contractAddress);
200
- const fnArtifact = artifact && artifact.functions.find(fn => fn.functionType === FunctionType.PUBLIC);
201
- return fnArtifact && { ...fnArtifact, contractName: artifact.name };
202
- }
203
-
204
- public async getFunctionAbi(
205
- contractAddress: AztecAddress,
206
- selector: FunctionSelector,
207
- ): Promise<FunctionAbi | undefined> {
208
- const artifact = await this.#getContractArtifactByAddress(contractAddress);
209
- return artifact && (await this.#findFunctionAbiBySelector(artifact, selector));
210
- }
211
-
212
- /**
213
- * Retrieves the debug metadata of a specified function within a given contract.
214
- * The function is identified by its selector, which is a unique code generated from the function's signature.
215
- * Returns undefined if the debug metadata for the given function is not found.
216
- * Throws if the contract has not been added to the database.
217
- *
218
- * @param contractAddress - The AztecAddress representing the contract containing the function.
219
- * @param selector - The function selector.
220
- * @returns The corresponding function's artifact as an object.
221
- */
222
- public async getFunctionDebugMetadata(
223
- contractAddress: AztecAddress,
224
- selector: FunctionSelector,
225
- ): Promise<FunctionDebugMetadata | undefined> {
226
- const artifact = await this.#getContractArtifactByAddress(contractAddress);
227
- const fnArtifact = artifact && (await this.#findFunctionArtifactBySelector(artifact, selector));
228
- return fnArtifact && getFunctionDebugMetadata(artifact, fnArtifact);
229
- }
230
-
231
- public async getPublicFunctionDebugMetadata(
232
- contractAddress: AztecAddress,
233
- ): Promise<FunctionDebugMetadata | undefined> {
234
- const artifact = await this.#getContractArtifactByAddress(contractAddress);
235
- const fnArtifact = artifact && artifact.functions.find(fn => fn.functionType === FunctionType.PUBLIC);
236
- return fnArtifact && getFunctionDebugMetadata(artifact, fnArtifact);
237
- }
238
-
239
- /**
240
- * Retrieve the function membership witness for the given contract class and function selector.
241
- * The function membership witness represents a proof that the function belongs to the specified contract.
242
- * Throws an error if the contract address or function selector is unknown.
243
- *
244
- * @param contractClassId - The id of the class.
245
- * @param selector - The function selector.
246
- * @returns A promise that resolves with the MembershipWitness instance for the specified contract's function.
247
- */
248
- public async getFunctionMembershipWitness(
249
- contractClassId: Fr,
250
- selector: FunctionSelector,
251
- ): Promise<MembershipWitness<typeof FUNCTION_TREE_HEIGHT> | undefined> {
252
- const tree = await this.#getPrivateFunctionTreeForClassId(contractClassId);
253
- return tree?.getFunctionMembershipWitness(selector);
254
- }
255
-
256
- public async getDebugContractName(contractAddress: AztecAddress) {
257
- const artifact = await this.#getContractArtifactByAddress(contractAddress);
258
- return artifact?.name;
259
- }
260
-
261
- public async getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector) {
262
- const artifact = await this.#getContractArtifactByAddress(contractAddress);
263
- const fnArtifact = artifact && (await this.#findFunctionAbiBySelector(artifact, selector));
264
- return `${artifact?.name ?? contractAddress}:${fnArtifact?.name ?? selector}`;
265
- }
266
-
267
- async #findFunctionArtifactBySelector(
268
- artifact: ContractArtifact,
269
- selector: FunctionSelector,
270
- ): Promise<FunctionArtifact | undefined> {
271
- const functions = artifact.functions;
272
- for (let i = 0; i < functions.length; i++) {
273
- const fn = functions[i];
274
- const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
275
- if (fnSelector.equals(selector)) {
276
- return fn;
277
- }
278
- }
279
- }
280
-
281
- async #findFunctionAbiBySelector(
282
- artifact: ContractArtifact,
283
- selector: FunctionSelector,
284
- ): Promise<FunctionAbi | undefined> {
285
- const functions = [...artifact.functions, ...(artifact.nonDispatchPublicFunctions ?? [])];
286
- for (let i = 0; i < functions.length; i++) {
287
- const fn = functions[i];
288
- const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
289
- if (fnSelector.equals(selector)) {
290
- return fn;
291
- }
292
- }
293
- }
294
-
295
- public async getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
296
- const contract = await this.getContract(to);
297
- if (!contract) {
298
- throw new Error(
299
- `Unknown contract ${to}: add it to PXE by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
300
- );
301
- }
302
-
303
- const functionDao = contract.functions.find(f => f.name === functionName);
304
- if (!functionDao) {
305
- throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
306
- }
307
-
308
- return {
309
- name: functionDao.name,
310
- args: encodeArguments(functionDao, args),
311
- selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
312
- type: functionDao.functionType,
313
- to,
314
- hideMsgSender: false,
315
- isStatic: functionDao.isStatic,
316
- returnTypes: functionDao.returnTypes,
317
- };
318
- }
319
- }
@@ -1 +0,0 @@
1
- export { ContractDataProvider } from './contract_data_provider.js';
@@ -1,2 +0,0 @@
1
- export { NoteDao } from '@aztec/stdlib/note';
2
- export { NoteDataProvider } from './note_data_provider.js';