@aztec-labs/pxe 6.0.0-nightly.20260829

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 (603) hide show
  1. package/README.md +13 -0
  2. package/dest/bin/check_oracle_version.d.ts +2 -0
  3. package/dest/bin/check_oracle_version.d.ts.map +1 -0
  4. package/dest/bin/check_oracle_version.js +22 -0
  5. package/dest/bin/index.d.ts +2 -0
  6. package/dest/bin/index.d.ts.map +1 -0
  7. package/dest/bin/index.js +1 -0
  8. package/dest/bin/oracle_version_helpers.d.ts +20 -0
  9. package/dest/bin/oracle_version_helpers.d.ts.map +1 -0
  10. package/dest/bin/oracle_version_helpers.js +25 -0
  11. package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
  12. package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
  13. package/dest/block_synchronizer/block_stream_source.js +37 -0
  14. package/dest/block_synchronizer/block_synchronizer.d.ts +47 -0
  15. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  16. package/dest/block_synchronizer/block_synchronizer.js +192 -0
  17. package/dest/block_synchronizer/index.d.ts +2 -0
  18. package/dest/block_synchronizer/index.d.ts.map +1 -0
  19. package/dest/block_synchronizer/index.js +1 -0
  20. package/dest/config/index.d.ts +57 -0
  21. package/dest/config/index.d.ts.map +1 -0
  22. package/dest/config/index.js +80 -0
  23. package/dest/config/package_info.d.ts +5 -0
  24. package/dest/config/package_info.d.ts.map +1 -0
  25. package/dest/config/package_info.js +6 -0
  26. package/dest/contract/contract_call_graph.d.ts +51 -0
  27. package/dest/contract/contract_call_graph.d.ts.map +1 -0
  28. package/dest/contract/contract_call_graph.js +91 -0
  29. package/dest/contract/contract_class_service.d.ts +24 -0
  30. package/dest/contract/contract_class_service.d.ts.map +1 -0
  31. package/dest/contract/contract_class_service.js +36 -0
  32. package/dest/contract/contract_sync_service.d.ts +82 -0
  33. package/dest/contract/contract_sync_service.d.ts.map +1 -0
  34. package/dest/contract/contract_sync_service.js +210 -0
  35. package/dest/contract/helpers.d.ts +7 -0
  36. package/dest/contract/helpers.d.ts.map +1 -0
  37. package/dest/contract/helpers.js +20 -0
  38. package/dest/contract/skip_sync_contracts.d.ts +11 -0
  39. package/dest/contract/skip_sync_contracts.d.ts.map +1 -0
  40. package/dest/contract/skip_sync_contracts.js +18 -0
  41. package/dest/contract_function_simulator/anchored_contract_data.d.ts +36 -0
  42. package/dest/contract_function_simulator/anchored_contract_data.d.ts.map +1 -0
  43. package/dest/contract_function_simulator/anchored_contract_data.js +54 -0
  44. package/dest/contract_function_simulator/contract_function_simulator.d.ts +114 -0
  45. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
  46. package/dest/contract_function_simulator/contract_function_simulator.js +495 -0
  47. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  48. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  49. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  50. package/dest/contract_function_simulator/execution_note_cache.d.ts +98 -0
  51. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
  52. package/dest/contract_function_simulator/execution_note_cache.js +189 -0
  53. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +12 -0
  54. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  55. package/dest/contract_function_simulator/execution_tagging_index_cache.js +30 -0
  56. package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
  57. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
  58. package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
  59. package/dest/contract_function_simulator/index.d.ts +36 -0
  60. package/dest/contract_function_simulator/index.d.ts.map +1 -0
  61. package/dest/contract_function_simulator/index.js +20 -0
  62. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +29 -0
  63. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -0
  64. package/dest/contract_function_simulator/noir-structs/bounded_vec.js +30 -0
  65. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts +9 -0
  66. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts.map +1 -0
  67. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.js +1 -0
  68. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts +7 -0
  69. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts.map +1 -0
  70. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.js +1 -0
  71. package/dest/contract_function_simulator/noir-structs/ephemeral_array.d.ts +37 -0
  72. package/dest/contract_function_simulator/noir-structs/ephemeral_array.d.ts.map +1 -0
  73. package/dest/contract_function_simulator/noir-structs/ephemeral_array.js +59 -0
  74. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +20 -0
  75. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -0
  76. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +39 -0
  77. package/dest/contract_function_simulator/noir-structs/fact.d.ts +16 -0
  78. package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -0
  79. package/dest/contract_function_simulator/noir-structs/fact.js +6 -0
  80. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +27 -0
  81. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -0
  82. package/dest/contract_function_simulator/noir-structs/fact_collection.js +31 -0
  83. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +25 -0
  84. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -0
  85. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +14 -0
  86. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +19 -0
  87. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -0
  88. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +4 -0
  89. package/dest/contract_function_simulator/noir-structs/note_data.d.ts +27 -0
  90. package/dest/contract_function_simulator/noir-structs/note_data.d.ts.map +1 -0
  91. package/dest/contract_function_simulator/noir-structs/note_data.js +3 -0
  92. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +22 -0
  93. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -0
  94. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +47 -0
  95. package/dest/contract_function_simulator/noir-structs/nullifier_membership_witness_data.d.ts +12 -0
  96. package/dest/contract_function_simulator/noir-structs/nullifier_membership_witness_data.d.ts.map +1 -0
  97. package/dest/contract_function_simulator/noir-structs/nullifier_membership_witness_data.js +6 -0
  98. package/dest/contract_function_simulator/noir-structs/option.d.ts +59 -0
  99. package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -0
  100. package/dest/contract_function_simulator/noir-structs/option.js +67 -0
  101. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts +11 -0
  102. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts.map +1 -0
  103. package/dest/contract_function_simulator/noir-structs/origin_block.js +5 -0
  104. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts +11 -0
  105. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts.map +1 -0
  106. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.js +4 -0
  107. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +8 -0
  108. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -0
  109. package/dest/contract_function_simulator/noir-structs/provided_secret.js +1 -0
  110. package/dest/contract_function_simulator/noir-structs/public_data_witness_data.d.ts +13 -0
  111. package/dest/contract_function_simulator/noir-structs/public_data_witness_data.d.ts.map +1 -0
  112. package/dest/contract_function_simulator/noir-structs/public_data_witness_data.js +3 -0
  113. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +28 -0
  114. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -0
  115. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +50 -0
  116. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +19 -0
  117. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -0
  118. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +9 -0
  119. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +15 -0
  120. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -0
  121. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +5 -0
  122. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +11 -0
  123. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  124. package/dest/contract_function_simulator/noir-structs/utility_context.js +3 -0
  125. package/dest/contract_function_simulator/oracle/acir_callback.d.ts +21 -0
  126. package/dest/contract_function_simulator/oracle/acir_callback.d.ts.map +1 -0
  127. package/dest/contract_function_simulator/oracle/acir_callback.js +115 -0
  128. package/dest/contract_function_simulator/oracle/index.d.ts +3 -0
  129. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
  130. package/dest/contract_function_simulator/oracle/index.js +2 -0
  131. package/dest/contract_function_simulator/oracle/interfaces.d.ts +24 -0
  132. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  133. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  134. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts +39 -0
  135. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts.map +1 -0
  136. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.js +107 -0
  137. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +28 -0
  138. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
  139. package/dest/contract_function_simulator/oracle/note_packing_utils.js +54 -0
  140. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +139 -0
  141. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -0
  142. package/dest/contract_function_simulator/oracle/oracle_registry.js +1024 -0
  143. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +292 -0
  144. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -0
  145. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +1258 -0
  146. package/dest/contract_function_simulator/oracle/private_execution.d.ts +23 -0
  147. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
  148. package/dest/contract_function_simulator/oracle/private_execution.js +88 -0
  149. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +226 -0
  150. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
  151. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +585 -0
  152. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +333 -0
  153. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
  154. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +900 -0
  155. package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
  156. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
  157. package/dest/contract_function_simulator/pick_notes.js +68 -0
  158. package/dest/contract_function_simulator/transient_array_service.d.ts +31 -0
  159. package/dest/contract_function_simulator/transient_array_service.d.ts.map +1 -0
  160. package/dest/contract_function_simulator/transient_array_service.js +62 -0
  161. package/dest/contract_logging.d.ts +27 -0
  162. package/dest/contract_logging.d.ts.map +1 -0
  163. package/dest/contract_logging.js +38 -0
  164. package/dest/debug/pxe_debug_utils.d.ts +38 -0
  165. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  166. package/dest/debug/pxe_debug_utils.js +44 -0
  167. package/dest/entrypoints/client/bundle/index.d.ts +10 -0
  168. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -0
  169. package/dest/entrypoints/client/bundle/index.js +8 -0
  170. package/dest/entrypoints/client/bundle/utils.d.ts +16 -0
  171. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -0
  172. package/dest/entrypoints/client/bundle/utils.js +78 -0
  173. package/dest/entrypoints/client/lazy/index.d.ts +10 -0
  174. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -0
  175. package/dest/entrypoints/client/lazy/index.js +8 -0
  176. package/dest/entrypoints/client/lazy/utils.d.ts +15 -0
  177. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -0
  178. package/dest/entrypoints/client/lazy/utils.js +77 -0
  179. package/dest/entrypoints/client/store.d.ts +14 -0
  180. package/dest/entrypoints/client/store.d.ts.map +1 -0
  181. package/dest/entrypoints/client/store.js +42 -0
  182. package/dest/entrypoints/pxe_creation_options.d.ts +32 -0
  183. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
  184. package/dest/entrypoints/pxe_creation_options.js +3 -0
  185. package/dest/entrypoints/server/circuit_recording/circuit_recorder.d.ts +121 -0
  186. package/dest/entrypoints/server/circuit_recording/circuit_recorder.d.ts.map +1 -0
  187. package/dest/entrypoints/server/circuit_recording/circuit_recorder.js +208 -0
  188. package/dest/entrypoints/server/circuit_recording/file_circuit_recorder.d.ts +20 -0
  189. package/dest/entrypoints/server/circuit_recording/file_circuit_recorder.d.ts.map +1 -0
  190. package/dest/entrypoints/server/circuit_recording/file_circuit_recorder.js +131 -0
  191. package/dest/entrypoints/server/circuit_recording/memory_circuit_recorder.d.ts +10 -0
  192. package/dest/entrypoints/server/circuit_recording/memory_circuit_recorder.d.ts.map +1 -0
  193. package/dest/entrypoints/server/circuit_recording/memory_circuit_recorder.js +9 -0
  194. package/dest/entrypoints/server/circuit_recording/simulator_recorder_wrapper.d.ts +18 -0
  195. package/dest/entrypoints/server/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -0
  196. package/dest/entrypoints/server/circuit_recording/simulator_recorder_wrapper.js +41 -0
  197. package/dest/entrypoints/server/index.d.ts +17 -0
  198. package/dest/entrypoints/server/index.d.ts.map +1 -0
  199. package/dest/entrypoints/server/index.js +14 -0
  200. package/dest/entrypoints/server/store.d.ts +18 -0
  201. package/dest/entrypoints/server/store.d.ts.map +1 -0
  202. package/dest/entrypoints/server/store.js +28 -0
  203. package/dest/entrypoints/server/utils.d.ts +9 -0
  204. package/dest/entrypoints/server/utils.d.ts.map +1 -0
  205. package/dest/entrypoints/server/utils.js +84 -0
  206. package/dest/error_enriching.d.ts +13 -0
  207. package/dest/error_enriching.d.ts.map +1 -0
  208. package/dest/error_enriching.js +80 -0
  209. package/dest/events/event_service.d.ts +30 -0
  210. package/dest/events/event_service.d.ts.map +1 -0
  211. package/dest/events/event_service.js +76 -0
  212. package/dest/events/index.d.ts +2 -0
  213. package/dest/events/index.d.ts.map +1 -0
  214. package/dest/events/index.js +1 -0
  215. package/dest/events/private_event_filter_validator.d.ts +10 -0
  216. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  217. package/dest/events/private_event_filter_validator.js +53 -0
  218. package/dest/hooks/authorize_utility_call.d.ts +41 -0
  219. package/dest/hooks/authorize_utility_call.d.ts.map +1 -0
  220. package/dest/hooks/authorize_utility_call.js +4 -0
  221. package/dest/hooks/execution_hooks.d.ts +62 -0
  222. package/dest/hooks/execution_hooks.d.ts.map +1 -0
  223. package/dest/hooks/execution_hooks.js +9 -0
  224. package/dest/hooks/index.d.ts +5 -0
  225. package/dest/hooks/index.d.ts.map +1 -0
  226. package/dest/hooks/index.js +2 -0
  227. package/dest/hooks/resolve_custom_request.d.ts +23 -0
  228. package/dest/hooks/resolve_custom_request.d.ts.map +1 -0
  229. package/dest/hooks/resolve_custom_request.js +3 -0
  230. package/dest/hooks/resolve_tagging_secret_strategy.d.ts +50 -0
  231. package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -0
  232. package/dest/hooks/resolve_tagging_secret_strategy.js +3 -0
  233. package/dest/logs/log_service.d.ts +40 -0
  234. package/dest/logs/log_service.d.ts.map +1 -0
  235. package/dest/logs/log_service.js +217 -0
  236. package/dest/messages/tx_resolver_service.d.ts +28 -0
  237. package/dest/messages/tx_resolver_service.d.ts.map +1 -0
  238. package/dest/messages/tx_resolver_service.js +62 -0
  239. package/dest/node/benchmarked_node.d.ts +22 -0
  240. package/dest/node/benchmarked_node.d.ts.map +1 -0
  241. package/dest/node/benchmarked_node.js +93 -0
  242. package/dest/node/caching_aztec_node.d.ts +24 -0
  243. package/dest/node/caching_aztec_node.d.ts.map +1 -0
  244. package/dest/node/caching_aztec_node.js +268 -0
  245. package/dest/notes/index.d.ts +2 -0
  246. package/dest/notes/index.d.ts.map +1 -0
  247. package/dest/notes/index.js +1 -0
  248. package/dest/notes/note_service.d.ts +77 -0
  249. package/dest/notes/note_service.d.ts.map +1 -0
  250. package/dest/notes/note_service.js +173 -0
  251. package/dest/notes_filter.d.ts +24 -0
  252. package/dest/notes_filter.d.ts.map +1 -0
  253. package/dest/notes_filter.js +4 -0
  254. package/dest/operation_lifecycle.d.ts +45 -0
  255. package/dest/operation_lifecycle.d.ts.map +1 -0
  256. package/dest/operation_lifecycle.js +68 -0
  257. package/dest/operation_queue.d.ts +75 -0
  258. package/dest/operation_queue.d.ts.map +1 -0
  259. package/dest/operation_queue.js +100 -0
  260. package/dest/oracle_version.d.ts +4 -0
  261. package/dest/oracle_version.d.ts.map +1 -0
  262. package/dest/oracle_version.js +21 -0
  263. package/dest/private_kernel/batch_planner.d.ts +47 -0
  264. package/dest/private_kernel/batch_planner.d.ts.map +1 -0
  265. package/dest/private_kernel/batch_planner.js +104 -0
  266. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  267. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  268. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.js +41 -0
  269. package/dest/private_kernel/hints/index.d.ts +3 -0
  270. package/dest/private_kernel/hints/index.d.ts.map +1 -0
  271. package/dest/private_kernel/hints/index.js +2 -0
  272. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
  273. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  274. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +343 -0
  275. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  276. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  277. package/dest/private_kernel/hints/test_utils.js +202 -0
  278. package/dest/private_kernel/index.d.ts +3 -0
  279. package/dest/private_kernel/index.d.ts.map +1 -0
  280. package/dest/private_kernel/index.js +2 -0
  281. package/dest/private_kernel/private_kernel_execution_prover.d.ts +49 -0
  282. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -0
  283. package/dest/private_kernel/private_kernel_execution_prover.js +408 -0
  284. package/dest/private_kernel/private_kernel_oracle.d.ts +65 -0
  285. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -0
  286. package/dest/private_kernel/private_kernel_oracle.js +110 -0
  287. package/dest/pxe.d.ts +364 -0
  288. package/dest/pxe.d.ts.map +1 -0
  289. package/dest/pxe.js +903 -0
  290. package/dest/storage/address_store/address_store.d.ts +11 -0
  291. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  292. package/dest/storage/address_store/address_store.js +49 -0
  293. package/dest/storage/address_store/index.d.ts +2 -0
  294. package/dest/storage/address_store/index.d.ts.map +1 -0
  295. package/dest/storage/address_store/index.js +1 -0
  296. package/dest/storage/allowed_scopes.d.ts +6 -0
  297. package/dest/storage/allowed_scopes.d.ts.map +1 -0
  298. package/dest/storage/allowed_scopes.js +7 -0
  299. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +20 -0
  300. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  301. package/dest/storage/anchor_block_store/anchor_block_store.js +28 -0
  302. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  303. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  304. package/dest/storage/anchor_block_store/index.js +1 -0
  305. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts +42 -0
  306. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts.map +1 -0
  307. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.js +93 -0
  308. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +15 -0
  309. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -0
  310. package/dest/storage/backwards_compatibility_tests/schema_tests.js +674 -0
  311. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts +19 -0
  312. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts.map +1 -0
  313. package/dest/storage/backwards_compatibility_tests/store_spy.js +63 -0
  314. package/dest/storage/base_staging_store.d.ts +110 -0
  315. package/dest/storage/base_staging_store.d.ts.map +1 -0
  316. package/dest/storage/base_staging_store.js +141 -0
  317. package/dest/storage/capsule_store/capsule_service.d.ts +22 -0
  318. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  319. package/dest/storage/capsule_store/capsule_service.js +47 -0
  320. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  321. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  322. package/dest/storage/capsule_store/capsule_store.js +256 -0
  323. package/dest/storage/capsule_store/index.d.ts +3 -0
  324. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  325. package/dest/storage/capsule_store/index.js +2 -0
  326. package/dest/storage/contract_store/contract_store.d.ts +96 -0
  327. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  328. package/dest/storage/contract_store/contract_store.js +282 -0
  329. package/dest/storage/contract_store/index.d.ts +2 -0
  330. package/dest/storage/contract_store/index.d.ts.map +1 -0
  331. package/dest/storage/contract_store/index.js +1 -0
  332. package/dest/storage/contract_store/private_functions_tree.d.ts +27 -0
  333. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  334. package/dest/storage/contract_store/private_functions_tree.js +48 -0
  335. package/dest/storage/fact_store/fact_service.d.ts +23 -0
  336. package/dest/storage/fact_store/fact_service.d.ts.map +1 -0
  337. package/dest/storage/fact_store/fact_service.js +45 -0
  338. package/dest/storage/fact_store/fact_store.d.ts +101 -0
  339. package/dest/storage/fact_store/fact_store.d.ts.map +1 -0
  340. package/dest/storage/fact_store/fact_store.js +350 -0
  341. package/dest/storage/fact_store/fact_store_keys.d.ts +34 -0
  342. package/dest/storage/fact_store/fact_store_keys.d.ts.map +1 -0
  343. package/dest/storage/fact_store/fact_store_keys.js +50 -0
  344. package/dest/storage/fact_store/index.d.ts +6 -0
  345. package/dest/storage/fact_store/index.d.ts.map +1 -0
  346. package/dest/storage/fact_store/index.js +4 -0
  347. package/dest/storage/fact_store/origin_state.d.ts +59 -0
  348. package/dest/storage/fact_store/origin_state.d.ts.map +1 -0
  349. package/dest/storage/fact_store/origin_state.js +60 -0
  350. package/dest/storage/fact_store/stored_fact.d.ts +32 -0
  351. package/dest/storage/fact_store/stored_fact.d.ts.map +1 -0
  352. package/dest/storage/fact_store/stored_fact.js +64 -0
  353. package/dest/storage/index.d.ts +10 -0
  354. package/dest/storage/index.d.ts.map +1 -0
  355. package/dest/storage/index.js +9 -0
  356. package/dest/storage/metadata.d.ts +2 -0
  357. package/dest/storage/metadata.d.ts.map +1 -0
  358. package/dest/storage/metadata.js +1 -0
  359. package/dest/storage/note_store/index.d.ts +3 -0
  360. package/dest/storage/note_store/index.d.ts.map +1 -0
  361. package/dest/storage/note_store/index.js +2 -0
  362. package/dest/storage/note_store/note_store.d.ts +92 -0
  363. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  364. package/dest/storage/note_store/note_store.js +273 -0
  365. package/dest/storage/note_store/stored_note.d.ts +11 -0
  366. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  367. package/dest/storage/note_store/stored_note.js +27 -0
  368. package/dest/storage/note_store/test_utils.d.ts +9 -0
  369. package/dest/storage/note_store/test_utils.d.ts.map +1 -0
  370. package/dest/storage/note_store/test_utils.js +10 -0
  371. package/dest/storage/open_pxe_stores.d.ts +35 -0
  372. package/dest/storage/open_pxe_stores.d.ts.map +1 -0
  373. package/dest/storage/open_pxe_stores.js +29 -0
  374. package/dest/storage/private_event_store/private_event_store.d.ts +90 -0
  375. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  376. package/dest/storage/private_event_store/private_event_store.js +276 -0
  377. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  378. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  379. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  380. package/dest/storage/rollbackable.d.ts +15 -0
  381. package/dest/storage/rollbackable.d.ts.map +1 -0
  382. package/dest/storage/rollbackable.js +3 -0
  383. package/dest/storage/staged_write_coordinator.d.ts +103 -0
  384. package/dest/storage/staged_write_coordinator.d.ts.map +1 -0
  385. package/dest/storage/staged_write_coordinator.js +141 -0
  386. package/dest/storage/store_identity.d.ts +35 -0
  387. package/dest/storage/store_identity.d.ts.map +1 -0
  388. package/dest/storage/store_identity.js +44 -0
  389. package/dest/storage/tagging_store/index.d.ts +4 -0
  390. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  391. package/dest/storage/tagging_store/index.js +3 -0
  392. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +36 -0
  393. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  394. package/dest/storage/tagging_store/recipient_tagging_store.js +74 -0
  395. package/dest/storage/tagging_store/sender_tagging_store.d.ts +113 -0
  396. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  397. package/dest/storage/tagging_store/sender_tagging_store.js +432 -0
  398. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +51 -0
  399. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -0
  400. package/dest/storage/tagging_store/tagging_secret_sources_store.js +105 -0
  401. package/dest/tagging/constants.d.ts +11 -0
  402. package/dest/tagging/constants.d.ts.map +1 -0
  403. package/dest/tagging/constants.js +38 -0
  404. package/dest/tagging/get_all_logs_by_tags.d.ts +69 -0
  405. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  406. package/dest/tagging/get_all_logs_by_tags.js +79 -0
  407. package/dest/tagging/index.d.ts +18 -0
  408. package/dest/tagging/index.d.ts.map +1 -0
  409. package/dest/tagging/index.js +16 -0
  410. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts +31 -0
  411. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts.map +1 -0
  412. package/dest/tagging/persist_sender_tagging_index_ranges.js +43 -0
  413. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +75 -0
  414. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -0
  415. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +235 -0
  416. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  417. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  418. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  419. package/dest/tagging/reconcile_tagging_index_ranges.d.ts +36 -0
  420. package/dest/tagging/reconcile_tagging_index_ranges.d.ts.map +1 -0
  421. package/dest/tagging/reconcile_tagging_index_ranges.js +74 -0
  422. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +20 -0
  423. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  424. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +77 -0
  425. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts +22 -0
  426. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts.map +1 -0
  427. package/dest/tagging/sender_sync/utils/classify_pending_txs.js +62 -0
  428. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +30 -0
  429. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  430. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +74 -0
  431. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts +29 -0
  432. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts.map +1 -0
  433. package/dest/tagging/sender_sync/utils/resolve_pending_txs.js +42 -0
  434. package/dest/tagging/sender_sync/utils/test_utils.d.ts +16 -0
  435. package/dest/tagging/sender_sync/utils/test_utils.d.ts.map +1 -0
  436. package/dest/tagging/sender_sync/utils/test_utils.js +24 -0
  437. package/dest/tagging/testing/tag_query_test_utils.d.ts +6 -0
  438. package/dest/tagging/testing/tag_query_test_utils.d.ts.map +1 -0
  439. package/dest/tagging/testing/tag_query_test_utils.js +10 -0
  440. package/dest/test_utils.d.ts +3 -0
  441. package/dest/test_utils.d.ts.map +1 -0
  442. package/dest/test_utils.js +1 -0
  443. package/package.json +119 -0
  444. package/src/bin/check_oracle_version.ts +28 -0
  445. package/src/bin/index.ts +1 -0
  446. package/src/bin/oracle_version_helpers.ts +30 -0
  447. package/src/block_synchronizer/block_stream_source.ts +48 -0
  448. package/src/block_synchronizer/block_synchronizer.ts +225 -0
  449. package/src/block_synchronizer/index.ts +1 -0
  450. package/src/config/index.ts +141 -0
  451. package/src/config/package_info.ts +3 -0
  452. package/src/contract/contract_call_graph.ts +121 -0
  453. package/src/contract/contract_class_service.ts +45 -0
  454. package/src/contract/contract_sync_service.ts +349 -0
  455. package/src/contract/helpers.ts +35 -0
  456. package/src/contract/skip_sync_contracts.ts +23 -0
  457. package/src/contract_function_simulator/anchored_contract_data.ts +74 -0
  458. package/src/contract_function_simulator/contract_function_simulator.ts +928 -0
  459. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  460. package/src/contract_function_simulator/execution_note_cache.ts +232 -0
  461. package/src/contract_function_simulator/execution_tagging_index_cache.ts +33 -0
  462. package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
  463. package/src/contract_function_simulator/index.ts +107 -0
  464. package/src/contract_function_simulator/noir-structs/bounded_vec.ts +43 -0
  465. package/src/contract_function_simulator/noir-structs/contract_class_log_data.ts +9 -0
  466. package/src/contract_function_simulator/noir-structs/embedded_curve_point.ts +4 -0
  467. package/src/contract_function_simulator/noir-structs/ephemeral_array.ts +66 -0
  468. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +52 -0
  469. package/src/contract_function_simulator/noir-structs/fact.ts +13 -0
  470. package/src/contract_function_simulator/noir-structs/fact_collection.ts +64 -0
  471. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +35 -0
  472. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +19 -0
  473. package/src/contract_function_simulator/noir-structs/note_data.ts +27 -0
  474. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +59 -0
  475. package/src/contract_function_simulator/noir-structs/nullifier_membership_witness_data.ts +15 -0
  476. package/src/contract_function_simulator/noir-structs/option.ts +75 -0
  477. package/src/contract_function_simulator/noir-structs/origin_block.ts +8 -0
  478. package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
  479. package/src/contract_function_simulator/noir-structs/provided_secret.ts +5 -0
  480. package/src/contract_function_simulator/noir-structs/public_data_witness_data.ts +13 -0
  481. package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +66 -0
  482. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +19 -0
  483. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +16 -0
  484. package/src/contract_function_simulator/noir-structs/utility_context.ts +11 -0
  485. package/src/contract_function_simulator/oracle/acir_callback.ts +154 -0
  486. package/src/contract_function_simulator/oracle/index.ts +2 -0
  487. package/src/contract_function_simulator/oracle/interfaces.ts +20 -0
  488. package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +147 -0
  489. package/src/contract_function_simulator/oracle/note_packing_utils.ts +68 -0
  490. package/src/contract_function_simulator/oracle/oracle_registry.ts +709 -0
  491. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +1089 -0
  492. package/src/contract_function_simulator/oracle/private_execution.ts +140 -0
  493. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +812 -0
  494. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +1341 -0
  495. package/src/contract_function_simulator/pick_notes.ts +160 -0
  496. package/src/contract_function_simulator/transient_array_service.ts +91 -0
  497. package/src/contract_logging.ts +52 -0
  498. package/src/debug/pxe_debug_utils.ts +89 -0
  499. package/src/entrypoints/client/bundle/index.ts +9 -0
  500. package/src/entrypoints/client/bundle/utils.ts +89 -0
  501. package/src/entrypoints/client/lazy/index.ts +9 -0
  502. package/src/entrypoints/client/lazy/utils.ts +89 -0
  503. package/src/entrypoints/client/store.ts +54 -0
  504. package/src/entrypoints/pxe_creation_options.ts +34 -0
  505. package/src/entrypoints/server/circuit_recording/circuit_recorder.ts +267 -0
  506. package/src/entrypoints/server/circuit_recording/file_circuit_recorder.ts +152 -0
  507. package/src/entrypoints/server/circuit_recording/memory_circuit_recorder.ts +13 -0
  508. package/src/entrypoints/server/circuit_recording/simulator_recorder_wrapper.ts +90 -0
  509. package/src/entrypoints/server/index.ts +17 -0
  510. package/src/entrypoints/server/store.ts +46 -0
  511. package/src/entrypoints/server/utils.ts +103 -0
  512. package/src/error_enriching.ts +124 -0
  513. package/src/events/event_service.ts +129 -0
  514. package/src/events/index.ts +1 -0
  515. package/src/events/private_event_filter_validator.ts +66 -0
  516. package/src/hooks/authorize_utility_call.ts +44 -0
  517. package/src/hooks/execution_hooks.ts +68 -0
  518. package/src/hooks/index.ts +13 -0
  519. package/src/hooks/resolve_custom_request.ts +24 -0
  520. package/src/hooks/resolve_tagging_secret_strategy.ts +60 -0
  521. package/src/logs/log_service.ts +295 -0
  522. package/src/messages/tx_resolver_service.ts +81 -0
  523. package/src/node/benchmarked_node.ts +141 -0
  524. package/src/node/caching_aztec_node.ts +407 -0
  525. package/src/notes/index.ts +1 -0
  526. package/src/notes/note_service.ts +238 -0
  527. package/src/notes_filter.ts +24 -0
  528. package/src/operation_lifecycle.ts +99 -0
  529. package/src/operation_queue.ts +149 -0
  530. package/src/oracle_version.ts +22 -0
  531. package/src/private_kernel/batch_planner.ts +168 -0
  532. package/src/private_kernel/hints/compute_tx_expiration_timestamp.ts +58 -0
  533. package/src/private_kernel/hints/index.ts +2 -0
  534. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +553 -0
  535. package/src/private_kernel/hints/test_utils.ts +318 -0
  536. package/src/private_kernel/index.ts +2 -0
  537. package/src/private_kernel/private_kernel_execution_prover.ts +656 -0
  538. package/src/private_kernel/private_kernel_oracle.ts +184 -0
  539. package/src/pxe.ts +1417 -0
  540. package/src/storage/address_store/address_store.ts +66 -0
  541. package/src/storage/address_store/index.ts +1 -0
  542. package/src/storage/allowed_scopes.ts +14 -0
  543. package/src/storage/anchor_block_store/anchor_block_store.ts +35 -0
  544. package/src/storage/anchor_block_store/index.ts +1 -0
  545. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +22 -0
  546. package/src/storage/backwards_compatibility_tests/__snapshots__/AnchorBlockStore.json +3 -0
  547. package/src/storage/backwards_compatibility_tests/__snapshots__/CapsuleStore.json +16 -0
  548. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +28 -0
  549. package/src/storage/backwards_compatibility_tests/__snapshots__/FactStore.json +40 -0
  550. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +52 -0
  551. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +40 -0
  552. package/src/storage/backwards_compatibility_tests/__snapshots__/NoteStore.json +56 -0
  553. package/src/storage/backwards_compatibility_tests/__snapshots__/PrivateEventStore.json +44 -0
  554. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +26 -0
  555. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +30 -0
  556. package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +30 -0
  557. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +117 -0
  558. package/src/storage/backwards_compatibility_tests/kv_store_snapshot.ts +122 -0
  559. package/src/storage/backwards_compatibility_tests/schema_tests.ts +813 -0
  560. package/src/storage/backwards_compatibility_tests/store_spy.ts +73 -0
  561. package/src/storage/base_staging_store.ts +227 -0
  562. package/src/storage/capsule_store/capsule_service.ts +97 -0
  563. package/src/storage/capsule_store/capsule_store.ts +349 -0
  564. package/src/storage/capsule_store/index.ts +2 -0
  565. package/src/storage/contract_store/contract_store.ts +403 -0
  566. package/src/storage/contract_store/index.ts +1 -0
  567. package/src/storage/contract_store/private_functions_tree.ts +68 -0
  568. package/src/storage/fact_store/fact_service.ts +70 -0
  569. package/src/storage/fact_store/fact_store.ts +424 -0
  570. package/src/storage/fact_store/fact_store_keys.ts +75 -0
  571. package/src/storage/fact_store/index.ts +15 -0
  572. package/src/storage/fact_store/origin_state.ts +84 -0
  573. package/src/storage/fact_store/stored_fact.ts +80 -0
  574. package/src/storage/index.ts +9 -0
  575. package/src/storage/metadata.ts +1 -0
  576. package/src/storage/note_store/index.ts +2 -0
  577. package/src/storage/note_store/note_store.ts +367 -0
  578. package/src/storage/note_store/stored_note.ts +26 -0
  579. package/src/storage/note_store/test_utils.ts +16 -0
  580. package/src/storage/open_pxe_stores.ts +52 -0
  581. package/src/storage/private_event_store/private_event_store.ts +383 -0
  582. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  583. package/src/storage/rollbackable.ts +14 -0
  584. package/src/storage/staged_write_coordinator.ts +218 -0
  585. package/src/storage/store_identity.ts +72 -0
  586. package/src/storage/tagging_store/index.ts +3 -0
  587. package/src/storage/tagging_store/recipient_tagging_store.ts +114 -0
  588. package/src/storage/tagging_store/sender_tagging_store.ts +564 -0
  589. package/src/storage/tagging_store/tagging_secret_sources_store.ts +138 -0
  590. package/src/tagging/constants.ts +42 -0
  591. package/src/tagging/get_all_logs_by_tags.ts +157 -0
  592. package/src/tagging/index.ts +25 -0
  593. package/src/tagging/persist_sender_tagging_index_ranges.ts +59 -0
  594. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +357 -0
  595. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  596. package/src/tagging/reconcile_tagging_index_ranges.ts +102 -0
  597. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +113 -0
  598. package/src/tagging/sender_sync/utils/classify_pending_txs.ts +92 -0
  599. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +92 -0
  600. package/src/tagging/sender_sync/utils/resolve_pending_txs.ts +65 -0
  601. package/src/tagging/sender_sync/utils/test_utils.ts +46 -0
  602. package/src/tagging/testing/tag_query_test_utils.ts +11 -0
  603. package/src/test_utils.ts +2 -0
@@ -0,0 +1,424 @@
1
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import { createLogger } from '@aztec-labs/foundation/log';
3
+ import { allToCompletion } from '@aztec-labs/foundation/promise';
4
+ import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec-labs/kv-store';
5
+
6
+ import { BaseStagingStore, type ReadonlyDb } from '../base_staging_store.js';
7
+ import type { ChangeSetId } from '../staged_write_coordinator.js';
8
+ import { FactCollectionKey, type FactCollectionTypeKey, type OriginBlock } from './fact_store_keys.js';
9
+ import { type Fact, StoredFact, factKeyStrOf } from './stored_fact.js';
10
+
11
+ type BlockNum = number;
12
+ type FactBuffer = Buffer;
13
+ type FactCollectionTypeKeyStr = string;
14
+ type FactCollectionKeyStr = string;
15
+ type FactKeyStr = string;
16
+
17
+ /** A fact collection as returned by the store. */
18
+ export type FactCollection = { key: FactCollectionKey; facts: Fact[] };
19
+
20
+ /** Internal auxiliary type assembling a collection. */
21
+ type CollectionWithFacts = { key: FactCollectionKey; facts: Map<FactKeyStr, Fact> };
22
+
23
+ /** A pending operation for a change set: record a fact, or delete a fact collection. */
24
+ type StagedOp = { kind: 'recordFact'; fact: StoredFact } | { kind: 'deleteFactCollection'; key: FactCollectionKey };
25
+
26
+ /**
27
+ * Stores immutable facts grouped into collections, isolated by contract and scope.
28
+ *
29
+ * A fact collection is a contract-defined bag of facts identified by a {@link FactCollectionKey} (contract, scope,
30
+ * collection type, and id). A fact is a contract-defined immutable, typed datum in a collection. Collections are
31
+ * implicit: one comes into being when its first fact is recorded and ceases to exist once it has no facts left.
32
+ *
33
+ * What makes this store different to, for example, the `CapsuleStore`, is that it is designed to support use cases
34
+ * where resilience to reorgs is needed, via what we call _retractability_.
35
+ *
36
+ * Facts can be retractable or non-retractable. They are retractable if they are associated to an origin block.
37
+ * Retractable facts are removed from the store when their origin block is pruned (typically due to a reorg).
38
+ * Non-retractable facts survive reorgs: they must then be explicitly deleted, so as not to keep consuming resources
39
+ * (storage and compute) indefinitely.
40
+ *
41
+ * Fact collections are isolated by scope.
42
+ *
43
+ * This store is designed to enable Aztec.nr to implement complex workflows such as offchain reception or partial note
44
+ * processing by storing structured data that is guaranteed to exist conditionally to specific blocks being included in
45
+ * the chain, while leaving the complexity of ensuring said guarantees to PXE.
46
+ *
47
+ * A key design driver is that PXE knows nothing about the actual fact contents: it just manages enough metadata to
48
+ * provide the guarantees mentioned above. That way, concepts such as offchain delivery or partial notes are completely
49
+ * defined by Aztec.nr, opening the door to further extension without the need for ad-hoc PXE support.
50
+ *
51
+ * As with most other PXE stores, writes are staged per change set ID and flushed atomically on commit.
52
+ */
53
+ export class FactStore extends BaseStagingStore<FactStoreChangeSet, FactStoreDb> {
54
+ logger = createLogger('fact_store');
55
+
56
+ constructor(store: AztecAsyncKVStore) {
57
+ super({
58
+ storeName: 'fact',
59
+ store,
60
+ buildChangeSet: () => [],
61
+ buildDb: db => ({
62
+ facts: db.openMap('facts'),
63
+ factsByCollection: db.openMultiMap('facts_by_collection'),
64
+ factsByBlock: db.openMultiMap('facts_by_block'),
65
+ }),
66
+ });
67
+ }
68
+
69
+ /**
70
+ * Records a fact in a collection.
71
+ *
72
+ * The collection is created implicitly on the first fact recorded for its key: recording into an existing collection
73
+ * just adds to it.
74
+ *
75
+ * If `originBlock === undefined`, the fact is non-retractable: it survives reorgs. A defined origin block makes the
76
+ * fact retractable: on a prune below its block, it will be deleted.
77
+ *
78
+ * Idempotent: re-recording an identical fact (same collection, fact type, payload, and origin block) is a no-op.
79
+ * The same payload tied to a different origin block is a distinct fact.
80
+ */
81
+ recordFact(
82
+ factCollectionKey: FactCollectionKey,
83
+ factTypeId: Fr,
84
+ payload: Fr[],
85
+ originBlock: OriginBlock | undefined,
86
+ changeSetId: ChangeSetId,
87
+ ): Promise<void> {
88
+ return this.withChangeSet(changeSetId, changeSet => {
89
+ changeSet.push({
90
+ kind: 'recordFact',
91
+ fact: new StoredFact(factCollectionKey, factTypeId, payload, originBlock),
92
+ });
93
+ });
94
+ }
95
+
96
+ /**
97
+ * Deletes a fact collection: removes every fact under the (scope-qualified) collection key.
98
+ *
99
+ * Idempotent: deleting a collection that does not exist is a no-op.
100
+ */
101
+ deleteFactCollection(factCollectionKey: FactCollectionKey, changeSetId: ChangeSetId): Promise<void> {
102
+ return this.withChangeSet(changeSetId, changeSet => {
103
+ changeSet.push({ kind: 'deleteFactCollection', key: factCollectionKey });
104
+ });
105
+ }
106
+
107
+ /**
108
+ * Returns the fact collection for the (scope-qualified) key, or undefined if it has no facts.
109
+ */
110
+ getFactCollection(
111
+ factCollectionKey: FactCollectionKey,
112
+ changeSetId: ChangeSetId,
113
+ ): Promise<FactCollection | undefined> {
114
+ return this.withChangeSetAndDb(changeSetId, async (changeSet, db) => {
115
+ const collectionKey = factCollectionKey.toString();
116
+ const committedCollection = await this.#loadCommittedCollection(db, factCollectionKey);
117
+ const committed = new Map(committedCollection ? [[collectionKey, committedCollection]] : []);
118
+
119
+ const collection = this.#foldStagedOps(committed, changeSet).get(collectionKey);
120
+ if (!collection) {
121
+ return undefined;
122
+ }
123
+ const facts = [...collection.facts.values()];
124
+ return facts.length > 0 ? { key: factCollectionKey, facts } : undefined;
125
+ });
126
+ }
127
+
128
+ /**
129
+ * Returns every fact collection of the given type for the queried scope, each holding its facts.
130
+ */
131
+ getFactCollectionsByType(
132
+ factCollectionTypeKey: FactCollectionTypeKey,
133
+ changeSetId: ChangeSetId,
134
+ ): Promise<FactCollection[]> {
135
+ return this.withChangeSetAndDb(changeSetId, async (changeSet, db) => {
136
+ const typeKey = factCollectionTypeKey.toString();
137
+ const committed = await this.#readCollectionsFromDbByType(db, typeKey);
138
+
139
+ return Array.from(this.#foldStagedOps(committed, changeSet, typeKey).values())
140
+ .map(collection => ({ key: collection.key, facts: [...collection.facts.values()] }))
141
+ .filter(collection => collection.facts.length > 0);
142
+ });
143
+ }
144
+
145
+ protected async flushChangeSet(changeSet: FactStoreChangeSet, db: FactStoreDb): Promise<void> {
146
+ for (const op of changeSet) {
147
+ switch (op.kind) {
148
+ case 'recordFact':
149
+ await this.#commitFact(db, op.fact);
150
+ break;
151
+ case 'deleteFactCollection':
152
+ await this.#deleteCollection(db, op.key.toString());
153
+ break;
154
+ default: {
155
+ const _exhaustive: never = op;
156
+ throw new Error(`Unhandled FactStore staged op kind: ${JSON.stringify(_exhaustive)}`);
157
+ }
158
+ }
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Removes every retractable fact originating from blocks over height `toBlock`, across all scopes.
164
+ *
165
+ * Non-retractable facts are untouched.
166
+ */
167
+ protected async applyRollback(toBlock: BlockNum, db: FactStoreDb): Promise<void> {
168
+ const removedFacts = await this.#retractFacts(db, toBlock);
169
+
170
+ this.logger.verbose('rolled back fact store', { removedFacts, toBlock });
171
+ }
172
+
173
+ /**
174
+ * Deletes retractable facts originating above `toBlock`, returning the number of by-block entries scanned.
175
+ * Retraction is scope-agnostic: a reorg invalidates a fact regardless of which scope's collection it belongs to.
176
+ *
177
+ * Requires to be run in a transactionAsync context.
178
+ */
179
+ async #retractFacts(db: FactStoreDb, toBlock: BlockNum): Promise<number> {
180
+ // Snapshot the orphaned fact keys before mutating so we never delete from the cursor we are iterating, kicking off
181
+ // each fact-body read during the scan so a DB request stays pending across the cursor-to-delete boundary (a drained
182
+ // cursor with no read in flight would let the transaction auto-commit before the deletes).
183
+ const factReads = new Map<FactKeyStr, Promise<FactBuffer | undefined>>();
184
+ for await (const [, factKey] of db.factsByBlock.entriesAsync({ start: toBlock + 1 })) {
185
+ factReads.set(factKey, db.facts.getAsync(factKey));
186
+ }
187
+ await allToCompletion(
188
+ Array.from(factReads, async ([factKey, read]) => {
189
+ const buf = await read;
190
+ if (!buf) {
191
+ // The by-block index just yielded this factKey, so a missing primary record means the indexes are out of
192
+ // sync. Log as this should be unreachable unless there is a bug.
193
+ this.logger.warn('Skipping retraction of a fact missing from the primary store: by-block index is stale', {
194
+ factKey,
195
+ });
196
+ return;
197
+ }
198
+ await this.#deleteFact(db, factKey, StoredFact.fromBuffer(buf));
199
+ }),
200
+ );
201
+ return factReads.size;
202
+ }
203
+
204
+ async #readCollectionsFromDbByType(
205
+ db: ReadonlyDb<FactStoreDb>,
206
+ typeKey: FactCollectionTypeKeyStr,
207
+ ): Promise<Map<FactCollectionKeyStr, CollectionWithFacts>> {
208
+ const factReadsByCollection = new Map<FactCollectionKeyStr, Map<FactKeyStr, Promise<FactBuffer | undefined>>>();
209
+ for await (const [collectionKey, factKey] of db.factsByCollection.entriesAsync({
210
+ start: `${typeKey}:`,
211
+ end: `${typeKey};`,
212
+ })) {
213
+ let reads = factReadsByCollection.get(collectionKey);
214
+ if (!reads) {
215
+ reads = new Map<FactKeyStr, Promise<FactBuffer | undefined>>();
216
+ factReadsByCollection.set(collectionKey, reads);
217
+ }
218
+ reads.set(factKey, db.facts.getAsync(factKey));
219
+ }
220
+
221
+ const result = new Map<FactCollectionKeyStr, CollectionWithFacts>();
222
+ for (const [collectionKey, reads] of factReadsByCollection) {
223
+ const collection = await this.#assembleCollection(FactCollectionKey.fromString(collectionKey), reads);
224
+ result.set(collectionKey, collection);
225
+ }
226
+ return result;
227
+ }
228
+
229
+ async #loadCommittedCollection(
230
+ db: ReadonlyDb<FactStoreDb>,
231
+ collectionKey: FactCollectionKey,
232
+ ): Promise<CollectionWithFacts | undefined> {
233
+ // Kick off each fact read while iterating the index so a DB request is always pending. Draining the cursor and only
234
+ // then reading the facts one `await` at a time would let the IndexedDB transaction auto-commit at the boundary
235
+ // (IndexedDB auto-commits once control returns to the event loop with no pending request), throwing mid-read on the
236
+ // browser backend.
237
+ const factReads = new Map<FactKeyStr, Promise<FactBuffer | undefined>>();
238
+ for await (const factKey of db.factsByCollection.getValuesAsync(collectionKey.toString())) {
239
+ factReads.set(factKey, db.facts.getAsync(factKey));
240
+ }
241
+ if (factReads.size === 0) {
242
+ return undefined;
243
+ }
244
+
245
+ return this.#assembleCollection(collectionKey, factReads);
246
+ }
247
+
248
+ /**
249
+ * Assemble a collection's facts from a set of in-flight DB reads.
250
+ */
251
+ async #assembleCollection(
252
+ collectionKey: FactCollectionKey,
253
+ reads: Map<FactKeyStr, Promise<FactBuffer | undefined>>,
254
+ ): Promise<CollectionWithFacts> {
255
+ const factKeys = [...reads.keys()];
256
+ const bufs = await allToCompletion([...reads.values()]);
257
+
258
+ // Await-free tail: deserialize. No DB ops from here on.
259
+ const facts = new Map<FactKeyStr, Fact>();
260
+ for (let i = 0; i < factKeys.length; i++) {
261
+ const factKey = factKeys[i];
262
+ const buf = bufs[i];
263
+ if (!buf) {
264
+ // Defensive: a #factsByCollection entry must always reference a live #facts entry. A missing one means the
265
+ // indexes are corrupt.
266
+ throw new Error(`Fact not found for factKey ${factKey}`);
267
+ }
268
+ const stored = StoredFact.fromBuffer(buf);
269
+ if (stored.factCollectionKey.toString() !== collectionKey.toString()) {
270
+ // Defensive: every read fact must belong to the collection being assembled. A mismatch means the indexes are
271
+ // corrupt.
272
+ throw new Error(`Fact ${factKey} does not belong to collection ${collectionKey}`);
273
+ }
274
+ facts.set(factKey, stored.toFact());
275
+ }
276
+ return { key: collectionKey, facts };
277
+ }
278
+
279
+ /**
280
+ * Assembles the current view of a collection of collections together with their facts, combining the committed with
281
+ * staged data.
282
+ *
283
+ * When `typeKey` is given, staged records of other types are ignored, so the result holds only that type.
284
+ */
285
+ #foldStagedOps(
286
+ committed: Map<FactCollectionKeyStr, CollectionWithFacts>,
287
+ changeSet: FactStoreChangeSet,
288
+ typeKey?: FactCollectionTypeKeyStr,
289
+ ): Map<FactCollectionKeyStr, CollectionWithFacts> {
290
+ const result = new Map<FactCollectionKeyStr, CollectionWithFacts>();
291
+
292
+ // Copy to avoid mutating the contents of `committed`.
293
+ for (const [collectionKey, { key, facts }] of committed) {
294
+ result.set(collectionKey, { key, facts: new Map(facts) });
295
+ }
296
+ for (const op of changeSet) {
297
+ switch (op.kind) {
298
+ case 'recordFact':
299
+ this.#foldRecordFact(result, op, typeKey);
300
+ break;
301
+ case 'deleteFactCollection':
302
+ this.#foldDeleteFactCollection(result, op);
303
+ break;
304
+ default: {
305
+ const _exhaustive: never = op;
306
+ throw new Error(`Unhandled FactStore staged op kind: ${JSON.stringify(_exhaustive)}`);
307
+ }
308
+ }
309
+ }
310
+ return result;
311
+ }
312
+
313
+ /**
314
+ * Folds a staged `recordFact` op into view.
315
+ *
316
+ * When `typeKey` is given, an op of another type is ignored, keeping the view limited to that type.
317
+ */
318
+ #foldRecordFact(
319
+ result: Map<FactCollectionKeyStr, CollectionWithFacts>,
320
+ op: Extract<StagedOp, { kind: 'recordFact' }>,
321
+ typeKey?: FactCollectionTypeKeyStr,
322
+ ): void {
323
+ const key = op.fact.factCollectionKey;
324
+
325
+ // Type filter doesn't match, nothing to do with this fact
326
+ if (typeKey !== undefined && key.factCollectionTypeKey().toString() !== typeKey) {
327
+ return;
328
+ }
329
+
330
+ const collectionKey = key.toString();
331
+ let collection = result.get(collectionKey);
332
+
333
+ // Collection didn't exist before this point, the created fact brings it into existence
334
+ if (!collection) {
335
+ collection = { key, facts: new Map<FactKeyStr, Fact>() };
336
+ result.set(collectionKey, collection);
337
+ }
338
+
339
+ const fKey = factKeyStrOf(op.fact);
340
+ if (!collection.facts.has(fKey)) {
341
+ collection.facts.set(fKey, op.fact.toFact());
342
+ }
343
+ }
344
+
345
+ /**
346
+ * Folds a staged `deleteFactCollection` op into the view: the scope-qualified collection is removed outright.
347
+ */
348
+ #foldDeleteFactCollection(
349
+ result: Map<FactCollectionKeyStr, CollectionWithFacts>,
350
+ op: Extract<StagedOp, { kind: 'deleteFactCollection' }>,
351
+ ): void {
352
+ result.delete(op.key.toString());
353
+ }
354
+
355
+ /**
356
+ * Writes a fact to persistent storage. Idempotent: an identical fact (same scope-qualified key) is left untouched.
357
+ */
358
+ async #commitFact(db: FactStoreDb, fact: StoredFact): Promise<void> {
359
+ const factKey = factKeyStrOf(fact);
360
+ if (await db.facts.hasAsync(factKey)) {
361
+ this.logger.debug(`Ignoring already recorded fact`, { factKey });
362
+ return;
363
+ }
364
+ await db.facts.set(factKey, fact.toBuffer());
365
+ await db.factsByCollection.set(fact.factCollectionKey.toString(), factKey);
366
+ if (fact.originBlock !== undefined) {
367
+ await db.factsByBlock.set(fact.originBlock.blockNumber, factKey);
368
+ }
369
+ }
370
+
371
+ /**
372
+ * Deletes every fact under the (scope-qualified) collection key.
373
+ *
374
+ * Caller must wrap in a transaction.
375
+ */
376
+ async #deleteCollection(db: FactStoreDb, collectionKey: FactCollectionKeyStr): Promise<void> {
377
+ // Snapshot the fact index before mutating so we never delete from the cursor we are iterating, kicking off each
378
+ // fact-body read during the scan so a DB request stays pending across the cursor-to-mutation boundary (a drained
379
+ // cursor with no read in flight would let the transaction auto-commit before the deletes).
380
+ const factReads = new Map<FactKeyStr, Promise<FactBuffer | undefined>>();
381
+ for await (const factKey of db.factsByCollection.getValuesAsync(collectionKey)) {
382
+ factReads.set(factKey, db.facts.getAsync(factKey));
383
+ }
384
+ await allToCompletion(
385
+ Array.from(factReads, async ([factKey, read]) => {
386
+ const buf = await read;
387
+ if (!buf) {
388
+ // A #factsByCollection entry must always reference a live #facts entry, a missing one means the indexes are
389
+ // corrupt.
390
+ throw new Error(`Fact not found for factKey ${factKey}`);
391
+ }
392
+ await this.#deleteFact(db, factKey, StoredFact.fromBuffer(buf));
393
+ }),
394
+ );
395
+ }
396
+
397
+ /**
398
+ * Deletes a fact from the primary store and all its indexes (`factsByCollection`, plus `factsByBlock` if
399
+ * retractable).
400
+ *
401
+ * Caller must wrap in a transaction.
402
+ */
403
+ async #deleteFact(db: FactStoreDb, factKey: FactKeyStr, fact: StoredFact): Promise<void> {
404
+ await db.facts.delete(factKey);
405
+ await db.factsByCollection.deleteValue(fact.factCollectionKey.toString(), factKey);
406
+ if (fact.originBlock !== undefined) {
407
+ await db.factsByBlock.deleteValue(fact.originBlock.blockNumber, factKey);
408
+ }
409
+ }
410
+ }
411
+
412
+ /** A change set's staged data: the ops it has accumulated, replayed over committed state on read and on flush. */
413
+ type FactStoreChangeSet = StagedOp[];
414
+
415
+ type FactStoreDb = {
416
+ /** Primary index of fact records. */
417
+ facts: AztecAsyncMap<FactKeyStr, FactBuffer>;
418
+
419
+ /** Index for per-collection fact enumeration and by-type collection discovery. */
420
+ factsByCollection: AztecAsyncMultiMap<FactCollectionKeyStr, FactKeyStr>;
421
+
422
+ /** Index for delete-on-prune of retractable facts (those with an origin block). */
423
+ factsByBlock: AztecAsyncMultiMap<BlockNum, FactKeyStr>;
424
+ };
@@ -0,0 +1,75 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import type { FieldsOf } from '@aztec-labs/foundation/types';
3
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
4
+
5
+ /**
6
+ * The block a retractable fact originates from.
7
+ */
8
+ export type OriginBlock = { blockNumber: number; blockHash: Fr };
9
+
10
+ /** Facts are always tied to a real scope; the zero address is not a valid fact scope. */
11
+ function assertNonZeroScope(scope: AztecAddress): void {
12
+ if (scope.equals(AztecAddress.ZERO)) {
13
+ throw new Error('scope must not be the zero address');
14
+ }
15
+ }
16
+
17
+ /** Identifies all fact collections of one type within a contract, for one scope. */
18
+ export class FactCollectionTypeKey {
19
+ constructor(
20
+ public readonly contractAddress: AztecAddress,
21
+ public readonly scope: AztecAddress,
22
+ public readonly factCollectionTypeId: Fr,
23
+ ) {
24
+ assertNonZeroScope(scope);
25
+ }
26
+
27
+ static from(fields: FieldsOf<FactCollectionTypeKey>): FactCollectionTypeKey {
28
+ return new FactCollectionTypeKey(fields.contractAddress, fields.scope, fields.factCollectionTypeId);
29
+ }
30
+
31
+ toString(): string {
32
+ return `${this.contractAddress}:${this.scope}:${this.factCollectionTypeId}`;
33
+ }
34
+ }
35
+
36
+ /** Uniquely identifies a single fact collection, isolated by scope; all its facts share this key. */
37
+ export class FactCollectionKey {
38
+ constructor(
39
+ public readonly contractAddress: AztecAddress,
40
+ public readonly scope: AztecAddress,
41
+ public readonly factCollectionTypeId: Fr,
42
+ public readonly factCollectionId: Fr,
43
+ ) {
44
+ assertNonZeroScope(scope);
45
+ }
46
+
47
+ static from(fields: FieldsOf<FactCollectionKey>): FactCollectionKey {
48
+ return new FactCollectionKey(
49
+ fields.contractAddress,
50
+ fields.scope,
51
+ fields.factCollectionTypeId,
52
+ fields.factCollectionId,
53
+ );
54
+ }
55
+
56
+ /** Inverse of toString */
57
+ static fromString(str: string): FactCollectionKey {
58
+ const [contractAddress, scope, factCollectionTypeId, factCollectionId] = str.split(':');
59
+ return new FactCollectionKey(
60
+ AztecAddress.fromStringUnsafe(contractAddress),
61
+ AztecAddress.fromStringUnsafe(scope),
62
+ Fr.fromString(factCollectionTypeId),
63
+ Fr.fromString(factCollectionId),
64
+ );
65
+ }
66
+
67
+ /** The key grouping this collection with the other collections of its type within the same contract and scope. */
68
+ factCollectionTypeKey(): FactCollectionTypeKey {
69
+ return new FactCollectionTypeKey(this.contractAddress, this.scope, this.factCollectionTypeId);
70
+ }
71
+
72
+ toString(): string {
73
+ return `${this.contractAddress}:${this.scope}:${this.factCollectionTypeId}:${this.factCollectionId}`;
74
+ }
75
+ }
@@ -0,0 +1,15 @@
1
+ export { FactStore, type FactCollection } from './fact_store.js';
2
+ export { FactService } from './fact_service.js';
3
+ export { FactCollectionKey, FactCollectionTypeKey, type OriginBlock } from './fact_store_keys.js';
4
+ export type { Fact } from './stored_fact.js';
5
+ export {
6
+ OriginBlockState,
7
+ classifyOriginBlockState,
8
+ originBlockStateFromNumber,
9
+ anchoredTipBlockNumbers,
10
+ toFactWithOriginState,
11
+ type TipBlockNumbers,
12
+ type RetractableFactOrigin,
13
+ type FactWithOriginState,
14
+ type FactCollectionWithOriginState,
15
+ } from './origin_state.js';
@@ -0,0 +1,84 @@
1
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import type { L2Tips } from '@aztec-labs/stdlib/block';
3
+
4
+ import type { FactCollectionKey, OriginBlock } from './fact_store_keys.js';
5
+ import type { Fact } from './stored_fact.js';
6
+
7
+ /**
8
+ * Chain state of a retractable fact's origin block, mirroring the L2 chain tips.
9
+ *
10
+ * - `Pending`: above the proven tip.
11
+ * - `Proven`: proof on L1 but not yet finalized.
12
+ * - `Finalized`: L1-finalized.
13
+ *
14
+ * The numeric discriminants must stay in sync with the Noir `OriginBlockState` in
15
+ * `noir-projects/aztec-nr/aztec/src/facts/origin_state.nr`: PXE serializes this value into the `Fact` oracle response
16
+ * and Noir deserializes it via `from_u8`, which rejects any value outside this set.
17
+ */
18
+ export enum OriginBlockState {
19
+ Pending = 1,
20
+ Proven = 2,
21
+ Finalized = 3,
22
+ }
23
+
24
+ /** Parses a numeric origin-block-state discriminant, rejecting unknown values. */
25
+ export function originBlockStateFromNumber(value: number): OriginBlockState {
26
+ if (!(value in OriginBlockState)) {
27
+ const validNames = Object.keys(OriginBlockState).filter(k => isNaN(Number(k)));
28
+ throw new Error(`Invalid OriginBlockState value ${value}, expected one of ${validNames.join(', ')}`);
29
+ }
30
+ return value as OriginBlockState;
31
+ }
32
+
33
+ /** The two chain-tip block numbers needed to classify an origin block (`finalized <= proven` always holds). */
34
+ export type TipBlockNumbers = { provenBlockNumber: number; finalizedBlockNumber: number };
35
+
36
+ /**
37
+ * Projects the live chain tips to the block numbers used for classification, capped at the anchor block.
38
+ *
39
+ * A utility execution reads against a fixed anchor block, and every other node query in the oracle is bounded by it.
40
+ * Capping the proven/finalized tips at the anchor keeps origin-state consistent with that view and deterministic
41
+ * across runs: an origin block at or before the anchor classifies exactly as it would against the live tips, while an
42
+ * origin block above the anchor is reported `Pending` rather than trusting tips that look past the anchor.
43
+ */
44
+ export function anchoredTipBlockNumbers(tips: L2Tips, anchorBlockNumber: number): TipBlockNumbers {
45
+ return {
46
+ provenBlockNumber: Math.min(tips.proven.block.number, anchorBlockNumber),
47
+ finalizedBlockNumber: Math.min(tips.finalized.block.number, anchorBlockNumber),
48
+ };
49
+ }
50
+
51
+ /** A retractable fact's origin block annotated with that block's current chain state. */
52
+ export type RetractableFactOrigin = OriginBlock & { blockState: OriginBlockState };
53
+
54
+ /** A fact enriched with origin-block state. `originBlock` is undefined for a non-retractable fact. */
55
+ export type FactWithOriginState = { factTypeId: Fr; payload: Fr[]; originBlock: RetractableFactOrigin | undefined };
56
+
57
+ /** A fact collection whose facts carry origin-block state. */
58
+ export type FactCollectionWithOriginState = { key: FactCollectionKey; facts: FactWithOriginState[] };
59
+
60
+ /**
61
+ * Classifies an origin block by number against the chain tips. A surviving retractable fact's origin block is
62
+ * guaranteed canonical (a reorg would have pruned the fact), so a number comparison is sufficient.
63
+ */
64
+ export function classifyOriginBlockState(blockNumber: number, tips: TipBlockNumbers): OriginBlockState {
65
+ if (blockNumber <= tips.finalizedBlockNumber) {
66
+ return OriginBlockState.Finalized;
67
+ }
68
+ if (blockNumber <= tips.provenBlockNumber) {
69
+ return OriginBlockState.Proven;
70
+ }
71
+ return OriginBlockState.Pending;
72
+ }
73
+
74
+ /** Enriches a stored fact with the chain state of its origin block (when retractable). */
75
+ export function toFactWithOriginState(fact: Fact, tips: TipBlockNumbers): FactWithOriginState {
76
+ const originBlock: RetractableFactOrigin | undefined = fact.originBlock
77
+ ? {
78
+ blockNumber: fact.originBlock.blockNumber,
79
+ blockHash: fact.originBlock.blockHash,
80
+ blockState: classifyOriginBlockState(fact.originBlock.blockNumber, tips),
81
+ }
82
+ : undefined;
83
+ return { factTypeId: fact.factTypeId, payload: fact.payload, originBlock };
84
+ }
@@ -0,0 +1,80 @@
1
+ import { sha256ToField } from '@aztec-labs/foundation/crypto/sha256';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import { BufferReader, serializeToBuffer } from '@aztec-labs/foundation/serialize';
4
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
5
+
6
+ import { FactCollectionKey, type OriginBlock } from './fact_store_keys.js';
7
+
8
+ /** A fact as returned by the fact store. */
9
+ export type Fact = { factTypeId: Fr; payload: Fr[]; originBlock: OriginBlock | undefined };
10
+
11
+ /**
12
+ * A single immutable fact belonging to a fact collection.
13
+ */
14
+ export class StoredFact {
15
+ constructor(
16
+ public readonly factCollectionKey: FactCollectionKey,
17
+ public readonly factTypeId: Fr,
18
+ public readonly payload: Fr[],
19
+ public readonly originBlock: OriginBlock | undefined,
20
+ ) {}
21
+
22
+ /** Whether this fact is deleted on block pruning (true) or survives reorgs (false). */
23
+ get isRetractable(): boolean {
24
+ return this.originBlock !== undefined;
25
+ }
26
+
27
+ /** Stable digest of the payload, used for fact idempotency. */
28
+ payloadHash(): Fr {
29
+ return sha256ToField([this.payload.length, ...this.payload]);
30
+ }
31
+
32
+ /** Returns the externally facing view of this fact. */
33
+ toFact(): Fact {
34
+ return { factTypeId: this.factTypeId, payload: this.payload, originBlock: this.originBlock };
35
+ }
36
+
37
+ toBuffer(): Buffer {
38
+ return serializeToBuffer(
39
+ this.factCollectionKey.contractAddress,
40
+ this.factCollectionKey.scope,
41
+ this.factCollectionKey.factCollectionTypeId,
42
+ this.factCollectionKey.factCollectionId,
43
+ this.factTypeId,
44
+ this.payload.length,
45
+ ...this.payload,
46
+ this.originBlock !== undefined,
47
+ this.originBlock ? this.originBlock.blockNumber : 0,
48
+ this.originBlock ? this.originBlock.blockHash : Fr.ZERO,
49
+ );
50
+ }
51
+
52
+ static fromBuffer(buffer: Buffer | BufferReader): StoredFact {
53
+ const reader = BufferReader.asReader(buffer);
54
+ const contractAddress = reader.readObject(AztecAddress);
55
+ const scope = reader.readObject(AztecAddress);
56
+ const factCollectionTypeId = reader.readObject(Fr);
57
+ const factCollectionId = reader.readObject(Fr);
58
+ const factTypeId = reader.readObject(Fr);
59
+ const payloadLen = reader.readNumber();
60
+ const payload = reader.readArray(payloadLen, Fr);
61
+ const hasOriginBlock = reader.readBoolean();
62
+ const blockNumber = reader.readNumber();
63
+ const blockHash = reader.readObject(Fr);
64
+ const originBlock = hasOriginBlock ? { blockNumber, blockHash } : undefined;
65
+ return new StoredFact(
66
+ new FactCollectionKey(contractAddress, scope, factCollectionTypeId, factCollectionId),
67
+ factTypeId,
68
+ [...payload],
69
+ originBlock,
70
+ );
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Builds the serialized key that identifies a fact in the store.
76
+ */
77
+ export function factKeyStrOf(fact: StoredFact): string {
78
+ const origin = fact.originBlock ? `${fact.originBlock.blockNumber}:${fact.originBlock.blockHash}` : 'none';
79
+ return `${fact.factCollectionKey}:${fact.factTypeId}:${fact.payloadHash()}:${origin}`;
80
+ }
@@ -0,0 +1,9 @@
1
+ export * from './address_store/index.js';
2
+ export * from './anchor_block_store/index.js';
3
+ export * from './capsule_store/index.js';
4
+ export * from './contract_store/index.js';
5
+ export * from './fact_store/index.js';
6
+ export * from './note_store/index.js';
7
+ export * from './tagging_store/index.js';
8
+ export * from './metadata.js';
9
+ export * from './private_event_store/private_event_store.js';