@aztec/pxe 5.0.0-rc.1 → 5.0.0

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 (297) hide show
  1. package/dest/block_synchronizer/block_stream_source.d.ts +5 -5
  2. package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_stream_source.js +4 -29
  4. package/dest/block_synchronizer/block_synchronizer.d.ts +16 -12
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  6. package/dest/block_synchronizer/block_synchronizer.js +49 -15
  7. package/dest/config/index.d.ts +2 -1
  8. package/dest/config/index.d.ts.map +1 -1
  9. package/dest/config/index.js +1 -0
  10. package/dest/contract/contract_class_service.d.ts +31 -0
  11. package/dest/contract/contract_class_service.d.ts.map +1 -0
  12. package/dest/contract/contract_class_service.js +68 -0
  13. package/dest/{contract_sync → contract}/contract_sync_service.d.ts +7 -6
  14. package/dest/contract/contract_sync_service.d.ts.map +1 -0
  15. package/dest/{contract_sync → contract}/contract_sync_service.js +10 -30
  16. package/dest/contract/helpers.d.ts +7 -0
  17. package/dest/contract/helpers.d.ts.map +1 -0
  18. package/dest/contract/helpers.js +20 -0
  19. package/dest/contract_function_simulator/anchored_contract_data.d.ts +36 -0
  20. package/dest/contract_function_simulator/anchored_contract_data.d.ts.map +1 -0
  21. package/dest/contract_function_simulator/anchored_contract_data.js +54 -0
  22. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +39 -0
  23. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +1 -0
  24. package/dest/contract_function_simulator/aztec_node_read_cache.js +60 -0
  25. package/dest/contract_function_simulator/contract_function_simulator.d.ts +19 -18
  26. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/contract_function_simulator.js +52 -31
  28. package/dest/contract_function_simulator/execution_note_cache.d.ts +3 -9
  29. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/execution_note_cache.js +8 -28
  31. package/dest/contract_function_simulator/index.d.ts +17 -9
  32. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/index.js +4 -7
  34. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +8 -27
  35. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/noir-structs/bounded_vec.js +8 -23
  37. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts +9 -0
  38. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts.map +1 -0
  39. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.js +1 -0
  40. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts +7 -0
  41. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts.map +1 -0
  42. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.js +1 -0
  43. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  44. package/dest/contract_function_simulator/noir-structs/fact.d.ts +16 -0
  45. package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -0
  46. package/dest/contract_function_simulator/noir-structs/fact.js +6 -0
  47. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +27 -0
  48. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -0
  49. package/dest/contract_function_simulator/noir-structs/fact_collection.js +31 -0
  50. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +11 -12
  51. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +6 -49
  53. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +10 -8
  54. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  55. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -60
  56. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -2
  57. package/dest/contract_function_simulator/noir-structs/option.d.ts +9 -11
  58. package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/noir-structs/option.js +18 -13
  60. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts +11 -0
  61. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts.map +1 -0
  62. package/dest/contract_function_simulator/noir-structs/origin_block.js +5 -0
  63. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts +11 -0
  64. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts.map +1 -0
  65. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.js +4 -0
  66. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +6 -9
  67. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -1
  68. package/dest/contract_function_simulator/noir-structs/provided_secret.js +1 -14
  69. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +28 -0
  70. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -0
  71. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +50 -0
  72. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +21 -0
  73. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -0
  74. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +50 -0
  75. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +14 -0
  76. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -0
  77. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +5 -0
  78. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +6 -11
  79. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  80. package/dest/contract_function_simulator/noir-structs/utility_context.js +1 -20
  81. package/dest/contract_function_simulator/oracle/acir_callback.d.ts +7 -2
  82. package/dest/contract_function_simulator/oracle/acir_callback.d.ts.map +1 -1
  83. package/dest/contract_function_simulator/oracle/acir_callback.js +55 -11
  84. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts +39 -0
  85. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts.map +1 -0
  86. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.js +107 -0
  87. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -14
  88. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  89. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -24
  90. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +86 -8
  91. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
  92. package/dest/contract_function_simulator/oracle/oracle_registry.js +168 -18
  93. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +123 -40
  94. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  95. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +947 -264
  96. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +21 -8
  97. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  98. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +126 -16
  99. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +63 -33
  100. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  101. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +175 -90
  102. package/dest/debug/pxe_debug_utils.d.ts +2 -2
  103. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  104. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  105. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  106. package/dest/entrypoints/client/bundle/utils.js +3 -2
  107. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  108. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  109. package/dest/entrypoints/client/lazy/utils.js +3 -2
  110. package/dest/entrypoints/pxe_creation_options.d.ts +8 -2
  111. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  112. package/dest/entrypoints/server/index.d.ts +5 -3
  113. package/dest/entrypoints/server/index.d.ts.map +1 -1
  114. package/dest/entrypoints/server/index.js +3 -2
  115. package/dest/entrypoints/server/utils.d.ts +1 -1
  116. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  117. package/dest/entrypoints/server/utils.js +3 -1
  118. package/dest/error_enriching.d.ts +5 -3
  119. package/dest/error_enriching.d.ts.map +1 -1
  120. package/dest/error_enriching.js +13 -11
  121. package/dest/hooks/execution_hooks.d.ts +27 -7
  122. package/dest/hooks/execution_hooks.d.ts.map +1 -1
  123. package/dest/hooks/execution_hooks.js +3 -3
  124. package/dest/hooks/index.d.ts +4 -3
  125. package/dest/hooks/index.d.ts.map +1 -1
  126. package/dest/hooks/index.js +1 -0
  127. package/dest/hooks/resolve_custom_request.d.ts +23 -0
  128. package/dest/hooks/resolve_custom_request.d.ts.map +1 -0
  129. package/dest/hooks/resolve_custom_request.js +3 -0
  130. package/dest/hooks/resolve_tagging_secret_strategy.d.ts +50 -0
  131. package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -0
  132. package/dest/hooks/resolve_tagging_secret_strategy.js +3 -0
  133. package/dest/logs/log_service.d.ts +7 -6
  134. package/dest/logs/log_service.d.ts.map +1 -1
  135. package/dest/logs/log_service.js +79 -28
  136. package/dest/messages/tx_resolver_service.d.ts +17 -0
  137. package/dest/messages/tx_resolver_service.d.ts.map +1 -0
  138. package/dest/messages/{message_context_service.js → tx_resolver_service.js} +8 -8
  139. package/dest/oracle_version.d.ts +3 -3
  140. package/dest/oracle_version.js +3 -3
  141. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +1 -1
  142. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  143. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +6 -2
  144. package/dest/private_kernel/hints/test_utils.js +1 -1
  145. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  146. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  147. package/dest/private_kernel/private_kernel_execution_prover.js +17 -36
  148. package/dest/private_kernel/private_kernel_oracle.d.ts +4 -2
  149. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  150. package/dest/private_kernel/private_kernel_oracle.js +17 -5
  151. package/dest/pxe.d.ts +109 -47
  152. package/dest/pxe.d.ts.map +1 -1
  153. package/dest/pxe.js +222 -139
  154. package/dest/storage/allowed_scopes.d.ts +6 -0
  155. package/dest/storage/allowed_scopes.d.ts.map +1 -0
  156. package/dest/storage/allowed_scopes.js +7 -0
  157. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +1 -1
  158. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -1
  159. package/dest/storage/backwards_compatibility_tests/schema_tests.js +114 -37
  160. package/dest/storage/capsule_store/capsule_service.d.ts +1 -1
  161. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -1
  162. package/dest/storage/capsule_store/capsule_service.js +6 -9
  163. package/dest/storage/contract_store/contract_store.d.ts +27 -24
  164. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  165. package/dest/storage/contract_store/contract_store.js +64 -75
  166. package/dest/storage/fact_store/fact_service.d.ts +22 -0
  167. package/dest/storage/fact_store/fact_service.d.ts.map +1 -0
  168. package/dest/storage/fact_store/fact_service.js +45 -0
  169. package/dest/storage/fact_store/fact_store.d.ts +95 -0
  170. package/dest/storage/fact_store/fact_store.d.ts.map +1 -0
  171. package/dest/storage/fact_store/fact_store.js +408 -0
  172. package/dest/storage/fact_store/fact_store_keys.d.ts +34 -0
  173. package/dest/storage/fact_store/fact_store_keys.d.ts.map +1 -0
  174. package/dest/storage/fact_store/fact_store_keys.js +50 -0
  175. package/dest/storage/fact_store/index.d.ts +6 -0
  176. package/dest/storage/fact_store/index.d.ts.map +1 -0
  177. package/dest/storage/fact_store/index.js +4 -0
  178. package/dest/storage/fact_store/origin_state.d.ts +57 -0
  179. package/dest/storage/fact_store/origin_state.d.ts.map +1 -0
  180. package/dest/storage/fact_store/origin_state.js +53 -0
  181. package/dest/storage/fact_store/stored_fact.d.ts +32 -0
  182. package/dest/storage/fact_store/stored_fact.d.ts.map +1 -0
  183. package/dest/storage/fact_store/stored_fact.js +64 -0
  184. package/dest/storage/index.d.ts +2 -1
  185. package/dest/storage/index.d.ts.map +1 -1
  186. package/dest/storage/index.js +1 -0
  187. package/dest/storage/metadata.d.ts +2 -2
  188. package/dest/storage/metadata.d.ts.map +1 -1
  189. package/dest/storage/metadata.js +1 -1
  190. package/dest/storage/open_pxe_stores.d.ts +5 -3
  191. package/dest/storage/open_pxe_stores.d.ts.map +1 -1
  192. package/dest/storage/open_pxe_stores.js +5 -3
  193. package/dest/storage/tagging_store/index.d.ts +2 -2
  194. package/dest/storage/tagging_store/index.d.ts.map +1 -1
  195. package/dest/storage/tagging_store/index.js +1 -1
  196. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +51 -0
  197. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -0
  198. package/dest/storage/tagging_store/tagging_secret_sources_store.js +105 -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 +18 -9
  202. package/package.json +17 -17
  203. package/src/block_synchronizer/block_stream_source.ts +6 -45
  204. package/src/block_synchronizer/block_synchronizer.ts +65 -24
  205. package/src/config/index.ts +1 -0
  206. package/src/contract/contract_class_service.ts +83 -0
  207. package/src/{contract_sync → contract}/contract_sync_service.ts +18 -37
  208. package/src/contract/helpers.ts +35 -0
  209. package/src/contract_function_simulator/anchored_contract_data.ts +74 -0
  210. package/src/contract_function_simulator/aztec_node_read_cache.ts +89 -0
  211. package/src/contract_function_simulator/contract_function_simulator.ts +86 -43
  212. package/src/contract_function_simulator/execution_note_cache.ts +7 -28
  213. package/src/contract_function_simulator/index.ts +24 -9
  214. package/src/contract_function_simulator/noir-structs/bounded_vec.ts +12 -24
  215. package/src/contract_function_simulator/noir-structs/contract_class_log_data.ts +9 -0
  216. package/src/contract_function_simulator/noir-structs/embedded_curve_point.ts +4 -0
  217. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  218. package/src/contract_function_simulator/noir-structs/fact.ts +13 -0
  219. package/src/contract_function_simulator/noir-structs/fact_collection.ts +64 -0
  220. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +20 -46
  221. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +13 -60
  222. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  223. package/src/contract_function_simulator/noir-structs/option.ts +17 -11
  224. package/src/contract_function_simulator/noir-structs/origin_block.ts +8 -0
  225. package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
  226. package/src/contract_function_simulator/noir-structs/provided_secret.ts +4 -15
  227. package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +66 -0
  228. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +53 -0
  229. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +15 -0
  230. package/src/contract_function_simulator/noir-structs/utility_context.ts +5 -17
  231. package/src/contract_function_simulator/oracle/acir_callback.ts +58 -12
  232. package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +147 -0
  233. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +6 -21
  234. package/src/contract_function_simulator/oracle/oracle_registry.ts +119 -86
  235. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +659 -248
  236. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +155 -24
  237. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +300 -115
  238. package/src/debug/pxe_debug_utils.ts +1 -1
  239. package/src/entrypoints/client/bundle/utils.ts +3 -2
  240. package/src/entrypoints/client/lazy/utils.ts +3 -2
  241. package/src/entrypoints/pxe_creation_options.ts +7 -1
  242. package/src/entrypoints/server/index.ts +5 -2
  243. package/src/entrypoints/server/utils.ts +3 -1
  244. package/src/error_enriching.ts +27 -11
  245. package/src/hooks/execution_hooks.ts +28 -8
  246. package/src/hooks/index.ts +8 -2
  247. package/src/hooks/resolve_custom_request.ts +24 -0
  248. package/src/hooks/resolve_tagging_secret_strategy.ts +60 -0
  249. package/src/logs/log_service.ts +91 -37
  250. package/src/messages/{message_context_service.ts → tx_resolver_service.ts} +16 -9
  251. package/src/oracle_version.ts +3 -3
  252. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +11 -1
  253. package/src/private_kernel/hints/test_utils.ts +1 -1
  254. package/src/private_kernel/private_kernel_execution_prover.ts +22 -52
  255. package/src/private_kernel/private_kernel_oracle.ts +23 -4
  256. package/src/pxe.ts +320 -158
  257. package/src/storage/allowed_scopes.ts +14 -0
  258. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +6 -6
  259. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +1 -1
  260. package/src/storage/backwards_compatibility_tests/__snapshots__/FactStore.json +40 -0
  261. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +12 -12
  262. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +1 -1
  263. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +11 -3
  264. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +12 -4
  265. package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +30 -0
  266. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +21 -5
  267. package/src/storage/backwards_compatibility_tests/schema_tests.ts +125 -36
  268. package/src/storage/capsule_store/capsule_service.ts +8 -13
  269. package/src/storage/contract_store/contract_store.ts +86 -93
  270. package/src/storage/fact_store/fact_service.ts +69 -0
  271. package/src/storage/fact_store/fact_store.ts +487 -0
  272. package/src/storage/fact_store/fact_store_keys.ts +75 -0
  273. package/src/storage/fact_store/index.ts +14 -0
  274. package/src/storage/fact_store/origin_state.ts +75 -0
  275. package/src/storage/fact_store/stored_fact.ts +80 -0
  276. package/src/storage/index.ts +1 -0
  277. package/src/storage/metadata.ts +1 -1
  278. package/src/storage/open_pxe_stores.ts +6 -3
  279. package/src/storage/tagging_store/index.ts +1 -1
  280. package/src/storage/tagging_store/tagging_secret_sources_store.ts +138 -0
  281. package/src/tagging/constants.ts +19 -9
  282. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +0 -6
  283. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +0 -1
  284. package/dest/contract_function_simulator/proxied_contract_data_source.js +0 -51
  285. package/dest/contract_sync/contract_sync_service.d.ts.map +0 -1
  286. package/dest/contract_sync/helpers.d.ts +0 -27
  287. package/dest/contract_sync/helpers.d.ts.map +0 -1
  288. package/dest/contract_sync/helpers.js +0 -53
  289. package/dest/messages/message_context_service.d.ts +0 -17
  290. package/dest/messages/message_context_service.d.ts.map +0 -1
  291. package/dest/storage/tagging_store/sender_address_book_store.d.ts +0 -14
  292. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +0 -1
  293. package/dest/storage/tagging_store/sender_address_book_store.js +0 -36
  294. package/src/contract_function_simulator/proxied_contract_data_source.ts +0 -60
  295. package/src/contract_sync/helpers.ts +0 -86
  296. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderAddressBookStore.json +0 -16
  297. package/src/storage/tagging_store/sender_address_book_store.ts +0 -48
package/src/pxe.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { Point } from '@aztec/foundation/curves/grumpkin';
4
5
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
6
  import { SerialQueue } from '@aztec/foundation/queue';
6
7
  import { Timer } from '@aztec/foundation/timer';
7
8
  import { KeyStore } from '@aztec/key-store';
9
+ import type { AccountPrivacyKeys, AccountPrivacySecretKeys } from '@aztec/key-store';
8
10
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
9
11
  import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/protocol-contracts';
10
12
  import type { CircuitSimulator } from '@aztec/simulator/client';
@@ -12,6 +14,7 @@ import {
12
14
  type ContractArtifact,
13
15
  EventSelector,
14
16
  FunctionCall,
17
+ type FunctionSelector,
15
18
  FunctionType,
16
19
  decodeFunctionSignature,
17
20
  } from '@aztec/stdlib/abi';
@@ -20,18 +23,21 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
20
23
  import { GENESIS_BLOCK_HEADER_HASH, type L2TipsProvider } from '@aztec/stdlib/block';
21
24
  import {
22
25
  CompleteAddress,
26
+ type ContractInstancePreimage,
27
+ type ContractInstancePreimageWithAddress,
23
28
  type ContractInstanceWithAddress,
24
29
  type PartialAddress,
25
30
  computeContractAddressFromInstance,
26
- getContractClassFromArtifact,
27
31
  } from '@aztec/stdlib/contract';
28
32
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
33
+ import type { AztecNode, AztecNodeDebug, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
30
34
  import type {
31
35
  PrivateExecutionStep,
32
36
  PrivateKernelExecutionProofOutput,
33
37
  PrivateKernelTailCircuitPublicInputs,
34
38
  } from '@aztec/stdlib/kernel';
39
+ import { computeAddressSecret } from '@aztec/stdlib/keys';
40
+ import { deriveEcdhSharedSecretPoint } from '@aztec/stdlib/logs';
35
41
  import {
36
42
  BlockHeader,
37
43
  type ContractOverrides,
@@ -54,21 +60,20 @@ import { inspect } from 'util';
54
60
 
55
61
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
62
  import type { PXEConfig } from './config/index.js';
63
+ import { ContractClassService } from './contract/contract_class_service.js';
64
+ import { ContractSyncService } from './contract/contract_sync_service.js';
57
65
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
58
66
  import {
59
67
  ContractFunctionSimulator,
60
68
  generateSimulatedProvingResult,
61
69
  } from './contract_function_simulator/contract_function_simulator.js';
62
- import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
70
  import { displayDebugLogs } from './contract_logging.js';
64
- import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
- import { readCurrentClassId } from './contract_sync/helpers.js';
66
71
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
67
72
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
68
73
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
69
74
  import type { ExecutionHooks } from './hooks/index.js';
70
75
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
- import { MessageContextService } from './messages/message_context_service.js';
76
+ import { TxResolverService } from './messages/tx_resolver_service.js';
72
77
  import {
73
78
  PrivateKernelExecutionProver,
74
79
  type PrivateKernelExecutionProverConfig,
@@ -78,12 +83,16 @@ import { AddressStore } from './storage/address_store/address_store.js';
78
83
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
79
84
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
80
85
  import { ContractStore } from './storage/contract_store/contract_store.js';
86
+ import { FactStore } from './storage/fact_store/index.js';
81
87
  import { NoteStore } from './storage/note_store/note_store.js';
82
88
  import { openPxeStores } from './storage/open_pxe_stores.js';
83
89
  import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
84
90
  import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
85
- import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
86
91
  import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
92
+ import {
93
+ type SharedSecretKind,
94
+ TaggingSecretSourcesStore,
95
+ } from './storage/tagging_store/tagging_secret_sources_store.js';
87
96
  import { persistSenderTaggingIndexRangesForTx } from './tagging/index.js';
88
97
 
89
98
  export type PackedPrivateEvent = InTx & {
@@ -160,6 +169,11 @@ export type PreloadedContractsProvider = {
160
169
  export type PXECreateArgs = {
161
170
  /** The Aztec node to connect to. */
162
171
  node: AztecNode;
172
+ /**
173
+ * Optional debug API client. When provided, public function signatures are registered with the node so that
174
+ * node-side public-execution stack traces can be named. Skipped when the node does not expose the debug API.
175
+ */
176
+ nodeDebug?: AztecNodeDebug;
163
177
  /** The key-value store for persisting PXE state. */
164
178
  store: AztecAsyncKVStore;
165
179
  /** The prover for generating private kernel proofs. */
@@ -182,6 +196,34 @@ export type PXECreateArgs = {
182
196
  hooks?: ExecutionHooks;
183
197
  };
184
198
 
199
+ /** A source from which PXE derives the tagging secrets it scans for to discover incoming private logs. */
200
+ export type TaggingSecretSource =
201
+ /**
202
+ * Derives a shared secret via ECDH from an external `sender` address against every account registered in this PXE
203
+ * (present and future), so registering one sender applies it to all of them. The address is not secret, so unlike
204
+ * `arbitrary-secret` it can be reused freely across recipients.
205
+ */
206
+ | { kind: 'address-derived'; sender: AztecAddress }
207
+ /**
208
+ * A shared secret point provided directly, scoped to a single recipient. It bypasses ECDH, so it must not be
209
+ * reused across recipients (each would then be able to find the others' tags).
210
+ */
211
+ | { kind: 'arbitrary-secret'; recipient: AztecAddress; secret: Point }
212
+ /**
213
+ * A handshake known by the x-coordinate of its ephemeral public key (the value a recipient learns while authorizing
214
+ * an interactive handshake, which emits no discoverable announcement). The ephemeral key's y-coordinate is always
215
+ * positive by protocol construction, so the x-coordinate alone identifies it.
216
+ */
217
+ | { kind: 'handshake'; recipient: AztecAddress; ephPk: Fr };
218
+
219
+ /**
220
+ * The registered form of a {@link TaggingSecretSource}.
221
+ */
222
+ export type RegisteredTaggingSecretSource =
223
+ | Exclude<TaggingSecretSource, { kind: 'handshake' }>
224
+ /** A handshake's resolved shared secret, derived at registration from the handshake's ephemeral key. */
225
+ | { kind: 'handshake'; recipient: AztecAddress; secret: Point };
226
+
185
227
  /**
186
228
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
187
229
  * manage private state of users.
@@ -189,20 +231,23 @@ export type PXECreateArgs = {
189
231
  export class PXE {
190
232
  private constructor(
191
233
  private node: AztecNode,
234
+ private nodeDebug: AztecNodeDebug | undefined,
192
235
  private db: AztecAsyncKVStore,
193
236
  private blockStateSynchronizer: BlockSynchronizer,
194
237
  private keyStore: KeyStore,
195
238
  private contractStore: ContractStore,
196
239
  private noteStore: NoteStore,
197
240
  private capsuleStore: CapsuleStore,
241
+ private factStore: FactStore,
198
242
  private anchorBlockStore: AnchorBlockStore,
199
243
  private senderTaggingStore: SenderTaggingStore,
200
- private senderAddressBookStore: SenderAddressBookStore,
244
+ private taggingSecretSourcesStore: TaggingSecretSourcesStore,
201
245
  private recipientTaggingStore: RecipientTaggingStore,
202
246
  private addressStore: AddressStore,
203
247
  private privateEventStore: PrivateEventStore,
204
248
  private contractSyncService: ContractSyncService,
205
- private messageContextService: MessageContextService,
249
+ private contractClassService: ContractClassService,
250
+ private txResolver: TxResolverService,
206
251
  private l2TipsStore: L2TipsProvider,
207
252
  private simulator: CircuitSimulator,
208
253
  private proverEnabled: boolean,
@@ -226,6 +271,7 @@ export class PXE {
226
271
  */
227
272
  public static async create({
228
273
  node,
274
+ nodeDebug,
229
275
  store,
230
276
  proofCreator,
231
277
  simulator,
@@ -262,19 +308,22 @@ export class PXE {
262
308
  noteStore,
263
309
  anchorBlockStore,
264
310
  senderTaggingStore,
265
- senderAddressBookStore,
311
+ taggingSecretSourcesStore,
266
312
  recipientTaggingStore,
267
313
  capsuleStore,
268
314
  keyStore,
269
315
  l2TipsStore,
316
+ factStore,
270
317
  } = openPxeStores(store, initialBlockHash);
318
+ const contractClassService = new ContractClassService(node, contractStore);
271
319
  const contractSyncService = new ContractSyncService(
272
320
  node,
273
321
  contractStore,
322
+ contractClassService,
274
323
  noteStore,
275
324
  createLogger('pxe:contract_sync', bindings),
276
325
  );
277
- const messageContextService = new MessageContextService(node);
326
+ const txResolver = new TxResolverService(node);
278
327
 
279
328
  const synchronizer = new BlockSynchronizer(
280
329
  node,
@@ -282,8 +331,10 @@ export class PXE {
282
331
  anchorBlockStore,
283
332
  noteStore,
284
333
  privateEventStore,
334
+ factStore,
285
335
  l2TipsStore,
286
336
  contractSyncService,
337
+ contractClassService,
287
338
  config,
288
339
  bindings,
289
340
  );
@@ -295,6 +346,7 @@ export class PXE {
295
346
  recipientTaggingStore,
296
347
  privateEventStore,
297
348
  noteStore,
349
+ factStore,
298
350
  contractSyncService,
299
351
  ]);
300
352
 
@@ -304,20 +356,23 @@ export class PXE {
304
356
 
305
357
  const pxe = new PXE(
306
358
  node,
359
+ nodeDebug,
307
360
  store,
308
361
  synchronizer,
309
362
  keyStore,
310
363
  contractStore,
311
364
  noteStore,
312
365
  capsuleStore,
366
+ factStore,
313
367
  anchorBlockStore,
314
368
  senderTaggingStore,
315
- senderAddressBookStore,
369
+ taggingSecretSourcesStore,
316
370
  recipientTaggingStore,
317
371
  addressStore,
318
372
  privateEventStore,
319
373
  contractSyncService,
320
- messageContextService,
374
+ contractClassService,
375
+ txResolver,
321
376
  l2TipsStore,
322
377
  simulator,
323
378
  proverEnabled,
@@ -348,10 +403,10 @@ export class PXE {
348
403
  // Internal methods
349
404
 
350
405
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
351
- const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
352
-
353
406
  return new ContractFunctionSimulator({
354
- contractStore: proxyContractStore,
407
+ contractStore: this.contractStore,
408
+ contractClassService: this.contractClassService,
409
+ overrides: overrides?.contracts,
355
410
  noteStore: this.noteStore,
356
411
  keyStore: this.keyStore,
357
412
  addressStore: this.addressStore,
@@ -359,16 +414,41 @@ export class PXE {
359
414
  l2TipsStore: this.l2TipsStore,
360
415
  senderTaggingStore: this.senderTaggingStore,
361
416
  recipientTaggingStore: this.recipientTaggingStore,
362
- senderAddressBookStore: this.senderAddressBookStore,
417
+ taggingSecretSourcesStore: this.taggingSecretSourcesStore,
363
418
  capsuleStore: this.capsuleStore,
419
+ factStore: this.factStore,
364
420
  privateEventStore: this.privateEventStore,
365
421
  simulator: this.simulator,
366
422
  contractSyncService: this.contractSyncService,
367
- messageContextService: this.messageContextService,
423
+ txResolver: this.txResolver,
368
424
  hooks: this.hooks,
369
425
  });
370
426
  }
371
427
 
428
+ /** Best-effort debug function name for the class `address` runs at `anchorBlockHeader`. Used for log display only. */
429
+ async #getDebugFunctionName(
430
+ address: AztecAddress,
431
+ selector: FunctionSelector,
432
+ anchorBlockHeader: BlockHeader,
433
+ ): Promise<string> {
434
+ try {
435
+ const classId = await this.contractClassService.getCurrentClassId(address, anchorBlockHeader);
436
+ return classId ? await this.contractStore.getDebugFunctionName(classId, selector) : `${address}:${selector}`;
437
+ } catch {
438
+ return `${address}:${selector}`;
439
+ }
440
+ }
441
+
442
+ /** Best-effort debug contract name for the class `address` runs at `anchorBlockHeader`. Used for log display only. */
443
+ async #getDebugContractName(address: AztecAddress, anchorBlockHeader: BlockHeader): Promise<string | undefined> {
444
+ try {
445
+ const classId = await this.contractClassService.getCurrentClassId(address, anchorBlockHeader);
446
+ return classId ? await this.contractStore.getDebugContractName(classId) : undefined;
447
+ } catch {
448
+ return undefined;
449
+ }
450
+ }
451
+
372
452
  #contextualizeError(err: Error, ...context: string[]): Error {
373
453
  let contextStr = '';
374
454
  if (context.length > 0) {
@@ -432,7 +512,14 @@ export class PXE {
432
512
 
433
513
  async #registerPreloadedContracts() {
434
514
  const contracts = await this.preloadedContractsProvider.getPreloadedContracts();
435
- await Promise.all(contracts.map(({ instance, artifact }) => this.registerContract({ instance, artifact })));
515
+ await Promise.all(
516
+ contracts.map(async ({ instance, artifact }) => {
517
+ if (artifact) {
518
+ await this.registerContractClass(artifact);
519
+ }
520
+ await this.registerContract(instance);
521
+ }),
522
+ );
436
523
  this.log.verbose(`Registered preloaded contracts in pxe`, {
437
524
  contracts: contracts.map(({ instance }) => instance.address.toString()),
438
525
  });
@@ -469,8 +556,6 @@ export class PXE {
469
556
  );
470
557
 
471
558
  const result = await contractFunctionSimulator.run(txRequest, {
472
- contractAddress,
473
- selector: functionSelector,
474
559
  anchorBlockHeader,
475
560
  scopes,
476
561
  jobId,
@@ -480,7 +565,7 @@ export class PXE {
480
565
  return result;
481
566
  } catch (err) {
482
567
  if (err instanceof SimulationError) {
483
- await enrichSimulationError(err, this.contractStore, this.log);
568
+ await enrichSimulationError(err, this.contractStore, this.contractClassService, anchorBlockHeader, this.log);
484
569
  }
485
570
  throw err;
486
571
  }
@@ -515,7 +600,8 @@ export class PXE {
515
600
  return { result, offchainEffects };
516
601
  } catch (err) {
517
602
  if (err instanceof SimulationError) {
518
- await enrichSimulationError(err, this.contractStore, this.log);
603
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
604
+ await enrichSimulationError(err, this.contractStore, this.contractClassService, anchorBlockHeader, this.log);
519
605
  }
520
606
  throw err;
521
607
  }
@@ -539,7 +625,14 @@ export class PXE {
539
625
  } catch (err) {
540
626
  if (err instanceof SimulationError) {
541
627
  try {
542
- await enrichPublicSimulationError(err, this.contractStore, this.log);
628
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
629
+ await enrichPublicSimulationError(
630
+ err,
631
+ this.contractStore,
632
+ this.contractClassService,
633
+ anchorBlockHeader,
634
+ this.log,
635
+ );
543
636
  } catch (enrichErr) {
544
637
  this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
545
638
  }
@@ -566,7 +659,13 @@ export class PXE {
566
659
  anchorBlockHeader: BlockHeader,
567
660
  config: PrivateKernelExecutionProverConfig,
568
661
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
569
- const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
662
+ const kernelOracle = new PrivateKernelOracle(
663
+ this.contractStore,
664
+ this.contractClassService,
665
+ this.keyStore,
666
+ this.node,
667
+ anchorBlockHeader,
668
+ );
570
669
  const kernelTraceProver = new PrivateKernelExecutionProver(
571
670
  kernelOracle,
572
671
  proofCreator,
@@ -610,11 +709,11 @@ export class PXE {
610
709
  }
611
710
 
612
711
  /**
613
- * Returns the contract instance for a given address, if it's registered in the PXE.
712
+ * Returns the address preimage of the contract instance at a given address, if it's registered in the PXE.
614
713
  * @param address - The contract address.
615
- * @returns The contract instance if found, undefined otherwise.
714
+ * @returns The contract instance address preimage if found, undefined otherwise.
616
715
  */
617
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
716
+ public getContractInstance(address: AztecAddress): Promise<ContractInstancePreimageWithAddress | undefined> {
618
717
  return this.contractStore.getContractInstance(address);
619
718
  }
620
719
 
@@ -628,18 +727,22 @@ export class PXE {
628
727
  }
629
728
 
630
729
  /**
631
- * Registers a user account in PXE given its master encryption private key.
632
- * Once a new account is registered, the PXE will trial-decrypt all published notes on
633
- * the chain and store those that correspond to the registered account. Will do nothing if the
634
- * account is already registered.
730
+ * Registers a user account in PXE.
731
+ *
732
+ * PXE holds the account's four privacy secret keys but only the *public* message-signing and fallback keys: their
733
+ * secret keys are withheld, since PXE is not trusted to hold them.
734
+ *
735
+ * Does nothing if the account is already registered.
736
+ *
737
+ * The four privacy secret keys can be retrieved later with {@link getAccountSecretKeys}.
635
738
  *
636
- * @param secretKey - Secret key of the corresponding user master public key.
739
+ * @param keys - The account's privacy keys: four secret keys plus the message-signing and fallback public keys.
637
740
  * @param partialAddress - The partial address of the account contract corresponding to the account being registered.
638
741
  * @returns The complete address of the account.
639
742
  */
640
- public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
743
+ public async registerAccount(keys: AccountPrivacyKeys, partialAddress: PartialAddress): Promise<CompleteAddress> {
641
744
  const accounts = await this.keyStore.getAccounts();
642
- const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
745
+ const accountCompleteAddress = await this.keyStore.addAccount(keys, partialAddress);
643
746
  if (accounts.some(a => a.equals(accountCompleteAddress.address))) {
644
747
  this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
645
748
  return accountCompleteAddress;
@@ -653,62 +756,186 @@ export class PXE {
653
756
  }
654
757
 
655
758
  /**
656
- * Registers a sender in this PXE.
759
+ * Retrieves the four privacy secret keys PXE holds for a registered account (nullifier-hiding, incoming-viewing,
760
+ * outgoing-viewing, tagging).
657
761
  *
658
- * After registering a new sender, the PXE will sync private logs that are tagged with this sender's address.
659
- * Will do nothing if the address is already registered.
762
+ * These do NOT grant control over an account's assets, e.g. they are insufficient to impersonate the account or to
763
+ * spend notes, but they _do_ guard the account's privacy. Parties that have knowledge of these keys can decrypt all
764
+ * messages sent to the account, discover all of their on-chain activity, including notes, events, etc.
660
765
  *
661
- * @param sender - Address of the sender to register.
662
- * @returns The address of the sender.
663
- * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
766
+ * Security is paramount when handling these keys, which should itself be a very rare occurrence. Other than exporting
767
+ * and then importing an account into a separate PXE/wallet, there is typically no need for a wallet to ever access
768
+ * these keys. Applications should NEVER be given access to them.
769
+ *
770
+ * @throws If the account is not registered.
664
771
  */
665
- public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
666
- if (!(await sender.isValid())) {
667
- throw new Error(
668
- `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
669
- );
670
- }
772
+ public getAccountSecretKeys(account: AztecAddress): Promise<AccountPrivacySecretKeys> {
773
+ return this.keyStore.getAccountSecretKeys(account);
774
+ }
671
775
 
672
- const accounts = await this.keyStore.getAccounts();
673
- if (accounts.some(a => a.equals(sender))) {
674
- this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
675
- return sender;
776
+ /**
777
+ * Registers a source from which this PXE derives the tagging secrets it scans for to discover incoming private logs.
778
+ * See {@link TaggingSecretSource} for the meaning of each variant. Does nothing if the source is already registered.
779
+ *
780
+ * After a new source is added we clear the cache tracking which contracts have finished syncing, so every contract
781
+ * re-syncs against the new source's logs (whose notes/events could belong to any contract). Already-discovered
782
+ * notes/events are not discarded.
783
+ */
784
+ public async registerTaggingSecretSource(source: TaggingSecretSource): Promise<void> {
785
+ let wasAdded: boolean;
786
+
787
+ switch (source.kind) {
788
+ case 'address-derived':
789
+ wasAdded = await this.#registerSender(source.sender);
790
+ break;
791
+ case 'arbitrary-secret':
792
+ wasAdded = await this.#registerSharedSecret(source.recipient, 'arbitrary-secret', source.secret);
793
+ break;
794
+ case 'handshake':
795
+ wasAdded = await this.#registerSharedSecret(
796
+ source.recipient,
797
+ 'handshake',
798
+ await this.#deriveHandshakeSecret(source.recipient, source.ephPk),
799
+ );
800
+ break;
801
+ default: {
802
+ const _: never = source;
803
+ throw new Error('Unhandled tagging secret source kind');
804
+ }
676
805
  }
677
806
 
678
- const wasAdded = await this.senderAddressBookStore.addSender(sender);
679
-
680
807
  if (wasAdded) {
681
- this.log.info(`Added sender:\n ${sender.toString()}`);
682
- // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
683
- // all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
808
+ // Queued to avoid wiping while a job is in flight.
684
809
  await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
685
- } else {
686
- this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
687
810
  }
811
+ }
688
812
 
689
- return sender;
813
+ /**
814
+ * Removes a previously registered tagging secret source, identified by its registered form (see
815
+ * {@link getTaggingSecretSources}). Does nothing if it was not registered.
816
+ */
817
+ public async removeTaggingSecretSource(source: RegisteredTaggingSecretSource): Promise<void> {
818
+ switch (source.kind) {
819
+ case 'address-derived': {
820
+ const { sender } = source;
821
+ const wasRemoved = await this.taggingSecretSourcesStore.removeSender(sender);
822
+ this.log.info(
823
+ wasRemoved
824
+ ? `Removed sender:\n ${sender.toString()}`
825
+ : `Sender:\n "${sender.toString()}"\n not registered in PXE.`,
826
+ );
827
+ break;
828
+ }
829
+ case 'arbitrary-secret':
830
+ case 'handshake': {
831
+ const { kind, recipient, secret } = source;
832
+ const wasRemoved = await this.taggingSecretSourcesStore.removeSharedSecret(recipient, kind, secret);
833
+ this.log.info(
834
+ wasRemoved
835
+ ? `Removed ${kind} shared secret for recipient:\n ${recipient.toString()}`
836
+ : `No ${kind} shared secret registered for recipient:\n ${recipient.toString()}`,
837
+ );
838
+ break;
839
+ }
840
+ default: {
841
+ const _: never = source;
842
+ throw new Error('Unhandled tagging secret source kind');
843
+ }
844
+ }
690
845
  }
691
846
 
692
847
  /**
693
- * Retrieves senders registered in this PXE.
694
- * @returns Senders registered in this PXE.
848
+ * Retrieves the tagging secret sources registered in this PXE, in their registered form. Without a filter it
849
+ * returns every source; pass `{ kind }` to narrow to a single variant. See {@link RegisteredTaggingSecretSource}.
695
850
  */
696
- public getSenders(): Promise<AztecAddress[]> {
697
- return this.senderAddressBookStore.getSenders();
851
+ public getTaggingSecretSources<K extends RegisteredTaggingSecretSource['kind']>(filter: {
852
+ kind: K;
853
+ }): Promise<Extract<RegisteredTaggingSecretSource, { kind: K }>[]>;
854
+ public getTaggingSecretSources(): Promise<RegisteredTaggingSecretSource[]>;
855
+ public async getTaggingSecretSources(filter?: {
856
+ kind?: RegisteredTaggingSecretSource['kind'];
857
+ }): Promise<RegisteredTaggingSecretSource[]> {
858
+ const [senders, secrets] = await Promise.all([
859
+ this.taggingSecretSourcesStore.getSenders(),
860
+ this.taggingSecretSourcesStore.getAllSharedSecrets(),
861
+ ]);
862
+
863
+ const sources: RegisteredTaggingSecretSource[] = [
864
+ ...senders.map((sender): RegisteredTaggingSecretSource => ({ kind: 'address-derived', sender })),
865
+ ...secrets.map(({ recipient, kind, secret }): RegisteredTaggingSecretSource => ({ kind, recipient, secret })),
866
+ ];
867
+
868
+ return filter?.kind ? sources.filter(source => source.kind === filter.kind) : sources;
869
+ }
870
+
871
+ /** Registers a sender, skipping addresses that belong to a local account. Returns whether it was newly added. */
872
+ async #registerSender(address: AztecAddress): Promise<boolean> {
873
+ if (!(await address.isValid())) {
874
+ throw new Error(
875
+ `Address ${address} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
876
+ );
877
+ }
878
+
879
+ const accounts = await this.keyStore.getAccounts();
880
+ if (accounts.some(a => a.equals(address))) {
881
+ this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
882
+ return false;
883
+ }
884
+
885
+ const wasAdded = await this.taggingSecretSourcesStore.addSender(address);
886
+ this.log.info(
887
+ wasAdded ? `Added sender:\n ${address.toString()}` : `Sender:\n "${address.toString()}"\n already registered.`,
888
+ );
889
+ return wasAdded;
698
890
  }
699
891
 
700
892
  /**
701
- * Removes a sender registered in this PXE.
702
- * @param sender - The address of the sender to remove.
893
+ * Derives the shared secret of a handshake from its ephemeral public key: `S = addressSecret(recipient) * ephPk`,
894
+ * the same derivation the recipient-side scan uses for handshakes discovered onchain. The ephemeral key is
895
+ * reconstructed from its x-coordinate with a positive y, matching how the protocol generates it.
896
+ *
897
+ * @throws If `ephPk` is not the x-coordinate of a Grumpkin curve point, or if `recipient` is not an account of
898
+ * this PXE, since the derivation needs its keys.
703
899
  */
704
- public async removeSender(sender: AztecAddress): Promise<void> {
705
- const wasRemoved = await this.senderAddressBookStore.removeSender(sender);
900
+ async #deriveHandshakeSecret(recipient: AztecAddress, ephPk: Fr): Promise<Point> {
901
+ let ephPkPoint: Point;
902
+ try {
903
+ ephPkPoint = await Point.fromXAndSign(ephPk, true);
904
+ } catch {
905
+ throw new Error(`Ephemeral public key x-coordinate ${ephPk} does not correspond to a Grumpkin curve point.`);
906
+ }
706
907
 
707
- if (wasRemoved) {
708
- this.log.info(`Removed sender:\n ${sender.toString()}`);
709
- } else {
710
- this.log.info(`Sender:\n "${sender.toString()}"\n not registered in PXE.`);
908
+ const completeAddress = await this.addressStore.getCompleteAddress(recipient);
909
+ if (!completeAddress || !(await this.keyStore.hasAccount(recipient))) {
910
+ throw new Error(
911
+ `Recipient ${recipient} is not an account of this PXE. A handshake's shared secret can only be derived for an account whose keys are held.`,
912
+ );
711
913
  }
914
+
915
+ const ivskM = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
916
+ const addressSecret = await computeAddressSecret(await completeAddress.getPreaddress(), ivskM);
917
+ return deriveEcdhSharedSecretPoint(addressSecret, ephPkPoint);
918
+ }
919
+
920
+ /** Registers a resolved shared secret scoped to a recipient. Returns whether it was newly added. */
921
+ async #registerSharedSecret(recipient: AztecAddress, kind: SharedSecretKind, secret: Point): Promise<boolean> {
922
+ if (!(await recipient.isValid())) {
923
+ throw new Error(
924
+ `Recipient ${recipient} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register a shared secret for it.`,
925
+ );
926
+ }
927
+
928
+ if (secret.isZero() || !secret.isOnCurve()) {
929
+ throw new Error(`Shared secret ${secret} is not a valid non-zero point on the Grumpkin curve.`);
930
+ }
931
+
932
+ const wasAdded = await this.taggingSecretSourcesStore.addSharedSecret(recipient, kind, secret);
933
+ this.log.info(
934
+ wasAdded
935
+ ? `Added ${kind} shared secret for recipient:\n ${recipient.toString()}`
936
+ : `${kind} shared secret already registered for recipient:\n ${recipient.toString()}`,
937
+ );
938
+ return wasAdded;
712
939
  }
713
940
 
714
941
  /**
@@ -732,98 +959,33 @@ export class PXE {
732
959
  */
733
960
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
734
961
  const contractClassId = await this.contractStore.addContractArtifact(artifact);
962
+ // Publishing the artifact's public function signatures to the node is part of "registering a class", so that
963
+ // node-side debugging works regardless of which entrypoint (registerContractClass or registerContract) was used.
964
+ const publicFunctionSignatures = artifact.functions
965
+ .filter(fn => fn.functionType === FunctionType.PUBLIC)
966
+ .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
967
+ if (publicFunctionSignatures.length > 0) {
968
+ await this.nodeDebug?.registerContractFunctionSignatures(publicFunctionSignatures);
969
+ }
735
970
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
736
971
  }
737
972
 
738
973
  /**
739
- * Adds deployed contracts to the PXE. Deployed contract information is used to access the
740
- * contract code when simulating local transactions. This is automatically called by aztec.js when
741
- * deploying a contract. Dapps that wish to interact with contracts already deployed should register
742
- * these contracts in their users' PXE through this method.
974
+ * Registers a deployed contract instance so its private state can be synced and its functions simulated. The
975
+ * artifact for the class the instance runs must be registered separately via {@link registerContractClass}, before
976
+ * or after this call; registration performs no validation, so a missing or mismatched artifact only surfaces when
977
+ * the contract is later simulated. This is automatically called by aztec.js when deploying a contract.
743
978
  *
744
- * @param contract - A contract instance to register, with an optional artifact which can be omitted if the contract class has already been registered.
745
- */
746
- public async registerContract(contract: { instance: ContractInstanceWithAddress; artifact?: ContractArtifact }) {
747
- const { instance } = contract;
748
- let { artifact } = contract;
749
-
750
- if (artifact) {
751
- // If the user provides an artifact, validate it against the expected class id and register it
752
- const contractClass = await getContractClassFromArtifact(artifact);
753
- if (!contractClass.id.equals(instance.currentContractClassId)) {
754
- throw new Error(
755
- `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
756
- );
757
- }
758
- const computedAddress = await computeContractAddressFromInstance(instance);
759
- if (!computedAddress.equals(instance.address)) {
760
- throw new Error('Added a contract in which the address does not match the contract instance.');
761
- }
762
-
763
- await this.contractStore.addContractArtifact(artifact, contractClass);
764
-
765
- const publicFunctionSignatures = artifact.functions
766
- .filter(fn => fn.functionType === FunctionType.PUBLIC)
767
- .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
768
- if (publicFunctionSignatures.length > 0) {
769
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
770
- }
771
- } else {
772
- // Otherwise, make sure there is an artifact already registered for that class id
773
- artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
774
- if (!artifact) {
775
- throw new Error(
776
- `Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`,
777
- );
778
- }
779
- }
780
-
781
- await this.contractStore.addContractInstance(instance);
782
- this.log.info(
783
- `Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
784
- );
785
- }
786
-
787
- /**
788
- * Updates a deployed contract in the PXE. This is used to update the contract artifact when
789
- * an update has happened, so the new code can be used in the simulation of local transactions.
790
- * This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
791
- * @param contractAddress - The address of the contract to update.
792
- * @param artifact - The updated artifact for the contract.
793
- * @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
794
- * the current one (current one from the point of view of the node to which the PXE is connected).
979
+ * @param instance - The address preimage of the contract instance to register. The address is derived from it.
980
+ * @returns The address of the registered instance.
795
981
  */
796
- public updateContract(contractAddress: AztecAddress, artifact: ContractArtifact): Promise<void> {
797
- // We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
798
- // class while we're simulating it.
982
+ public registerContract(instance: ContractInstancePreimage): Promise<AztecAddress> {
983
+ // Run inside the job queue so we can't race a concurrent simulation while writing the instance to the store.
799
984
  return this.#putInJobQueue(async () => {
800
- const currentInstance = await this.contractStore.getContractInstance(contractAddress);
801
- if (!currentInstance) {
802
- throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
803
- }
804
- const contractClass = await getContractClassFromArtifact(artifact);
805
- await this.#maybeSync();
806
-
807
- const header = await this.anchorBlockStore.getBlockHeader();
808
-
809
- const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
810
- if (!contractClass.id.equals(currentClassId)) {
811
- throw new Error('Could not update contract to a class different from the current one.');
812
- }
813
-
814
- const publicFunctionSignatures = artifact.functions
815
- .filter(fn => fn.functionType === FunctionType.PUBLIC)
816
- .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
817
- if (publicFunctionSignatures.length > 0) {
818
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
819
- }
820
-
821
- currentInstance.currentContractClassId = contractClass.id;
822
- await Promise.all([
823
- this.contractStore.addContractArtifact(artifact, contractClass),
824
- this.contractStore.addContractInstance(currentInstance),
825
- ]);
826
- this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
985
+ const address = await computeContractAddressFromInstance(instance);
986
+ await this.contractStore.addContractInstance({ ...instance, address });
987
+ this.log.info(`Added contract at ${address}`, { address });
988
+ return address;
827
989
  });
828
990
  }
829
991
 
@@ -1085,7 +1247,7 @@ export class PXE {
1085
1247
  if (skipKernels) {
1086
1248
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
1087
1249
  privateExecutionResult,
1088
- (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
1250
+ (addr, sel) => this.#getDebugFunctionName(addr, sel, anchorBlockHeader),
1089
1251
  this.node,
1090
1252
  ));
1091
1253
  } else {
@@ -1112,7 +1274,7 @@ export class PXE {
1112
1274
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement, overrides);
1113
1275
  publicSimulationTime = publicSimulationTimer.ms();
1114
1276
  if (publicOutput?.debugLogs?.length) {
1115
- await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
1277
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.#getDebugContractName(addr, anchorBlockHeader));
1116
1278
  }
1117
1279
  }
1118
1280