@aztec/pxe 0.0.1-commit.b6e433891 → 0.0.1-commit.b8a057fa

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 (497) hide show
  1. package/dest/bin/check_oracle_version.js +45 -111
  2. package/dest/bin/index.d.ts +2 -0
  3. package/dest/bin/index.d.ts.map +1 -0
  4. package/dest/bin/index.js +1 -0
  5. package/dest/bin/oracle_version_helpers.d.ts +51 -0
  6. package/dest/bin/oracle_version_helpers.d.ts.map +1 -0
  7. package/dest/bin/oracle_version_helpers.js +254 -0
  8. package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
  9. package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
  10. package/dest/block_synchronizer/block_stream_source.js +37 -0
  11. package/dest/block_synchronizer/block_synchronizer.d.ts +23 -15
  12. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  13. package/dest/block_synchronizer/block_synchronizer.js +84 -28
  14. package/dest/config/index.d.ts +8 -1
  15. package/dest/config/index.d.ts.map +1 -1
  16. package/dest/config/index.js +13 -14
  17. package/dest/config/package_info.js +1 -1
  18. package/dest/contract/contract_class_service.d.ts +31 -0
  19. package/dest/contract/contract_class_service.d.ts.map +1 -0
  20. package/dest/contract/contract_class_service.js +68 -0
  21. package/dest/contract/contract_sync_service.d.ts +48 -0
  22. package/dest/contract/contract_sync_service.d.ts.map +1 -0
  23. package/dest/contract/contract_sync_service.js +116 -0
  24. package/dest/contract/helpers.d.ts +7 -0
  25. package/dest/contract/helpers.d.ts.map +1 -0
  26. package/dest/contract/helpers.js +20 -0
  27. package/dest/contract_function_simulator/anchored_contract_data.d.ts +36 -0
  28. package/dest/contract_function_simulator/anchored_contract_data.d.ts.map +1 -0
  29. package/dest/contract_function_simulator/anchored_contract_data.js +54 -0
  30. package/dest/contract_function_simulator/contract_function_simulator.d.ts +27 -21
  31. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/contract_function_simulator.js +86 -42
  33. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  34. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  35. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  36. package/dest/contract_function_simulator/execution_note_cache.d.ts +4 -10
  37. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/execution_note_cache.js +8 -28
  39. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -9
  40. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/execution_tagging_index_cache.js +3 -7
  42. package/dest/contract_function_simulator/index.d.ts +26 -6
  43. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/index.js +12 -4
  45. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +29 -0
  46. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -0
  47. package/dest/contract_function_simulator/noir-structs/bounded_vec.js +30 -0
  48. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts +9 -0
  49. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts.map +1 -0
  50. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.js +1 -0
  51. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts +7 -0
  52. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts.map +1 -0
  53. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.js +1 -0
  54. package/dest/contract_function_simulator/noir-structs/ephemeral_array.d.ts +37 -0
  55. package/dest/contract_function_simulator/noir-structs/ephemeral_array.d.ts.map +1 -0
  56. package/dest/contract_function_simulator/noir-structs/ephemeral_array.js +59 -0
  57. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +5 -5
  58. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -9
  60. package/dest/contract_function_simulator/noir-structs/fact.d.ts +16 -0
  61. package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -0
  62. package/dest/contract_function_simulator/noir-structs/fact.js +6 -0
  63. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +27 -0
  64. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -0
  65. package/dest/contract_function_simulator/noir-structs/fact_collection.js +31 -0
  66. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +19 -10
  67. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  68. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +12 -24
  69. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +11 -9
  70. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  71. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -61
  72. package/dest/contract_function_simulator/noir-structs/note_data.d.ts +27 -0
  73. package/dest/contract_function_simulator/noir-structs/note_data.d.ts.map +1 -0
  74. package/dest/contract_function_simulator/noir-structs/note_data.js +3 -0
  75. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +5 -5
  76. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  77. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +8 -10
  78. package/dest/contract_function_simulator/noir-structs/option.d.ts +59 -0
  79. package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -0
  80. package/dest/contract_function_simulator/noir-structs/option.js +67 -0
  81. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts +11 -0
  82. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts.map +1 -0
  83. package/dest/contract_function_simulator/noir-structs/origin_block.js +5 -0
  84. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts +11 -0
  85. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts.map +1 -0
  86. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.js +4 -0
  87. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +8 -0
  88. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -0
  89. package/dest/contract_function_simulator/noir-structs/provided_secret.js +1 -0
  90. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +28 -0
  91. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -0
  92. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +43 -0
  93. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +21 -0
  94. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -0
  95. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +50 -0
  96. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +14 -0
  97. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -0
  98. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +5 -0
  99. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +6 -11
  100. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  101. package/dest/contract_function_simulator/noir-structs/utility_context.js +1 -20
  102. package/dest/contract_function_simulator/oracle/acir_callback.d.ts +21 -0
  103. package/dest/contract_function_simulator/oracle/acir_callback.d.ts.map +1 -0
  104. package/dest/contract_function_simulator/oracle/acir_callback.js +115 -0
  105. package/dest/contract_function_simulator/oracle/index.d.ts +2 -13
  106. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
  107. package/dest/contract_function_simulator/oracle/index.js +1 -1
  108. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -103
  109. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  110. package/dest/contract_function_simulator/oracle/interfaces.js +2 -2
  111. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts +39 -0
  112. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts.map +1 -0
  113. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.js +74 -0
  114. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -14
  115. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  116. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -24
  117. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +2 -2
  118. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  119. package/dest/contract_function_simulator/oracle/note_packing_utils.js +2 -2
  120. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +136 -0
  121. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -0
  122. package/dest/contract_function_simulator/oracle/oracle_registry.js +989 -0
  123. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +222 -0
  124. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -0
  125. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +1243 -0
  126. package/dest/contract_function_simulator/oracle/private_execution.d.ts +1 -1
  127. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  128. package/dest/contract_function_simulator/oracle/private_execution.js +3 -4
  129. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +52 -42
  130. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  131. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +193 -62
  132. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +150 -77
  133. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  134. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +508 -191
  135. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  136. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  137. package/dest/contract_function_simulator/pick_notes.js +20 -3
  138. package/dest/contract_function_simulator/transient_array_service.d.ts +31 -0
  139. package/dest/contract_function_simulator/transient_array_service.d.ts.map +1 -0
  140. package/dest/contract_function_simulator/transient_array_service.js +62 -0
  141. package/dest/contract_logging.d.ts +9 -4
  142. package/dest/contract_logging.d.ts.map +1 -1
  143. package/dest/contract_logging.js +21 -6
  144. package/dest/debug/pxe_debug_utils.d.ts +4 -9
  145. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  146. package/dest/debug/pxe_debug_utils.js +0 -6
  147. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  148. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  149. package/dest/entrypoints/client/bundle/index.js +0 -1
  150. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  151. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  152. package/dest/entrypoints/client/bundle/utils.js +20 -7
  153. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  154. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  155. package/dest/entrypoints/client/lazy/index.js +0 -1
  156. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  157. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  158. package/dest/entrypoints/client/lazy/utils.js +20 -7
  159. package/dest/entrypoints/pxe_creation_options.d.ts +16 -2
  160. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  161. package/dest/entrypoints/pxe_creation_options.js +3 -1
  162. package/dest/entrypoints/server/index.d.ts +6 -4
  163. package/dest/entrypoints/server/index.d.ts.map +1 -1
  164. package/dest/entrypoints/server/index.js +4 -3
  165. package/dest/entrypoints/server/utils.d.ts +4 -3
  166. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  167. package/dest/entrypoints/server/utils.js +20 -6
  168. package/dest/error_enriching.d.ts +5 -3
  169. package/dest/error_enriching.d.ts.map +1 -1
  170. package/dest/error_enriching.js +13 -11
  171. package/dest/events/event_service.d.ts +15 -6
  172. package/dest/events/event_service.d.ts.map +1 -1
  173. package/dest/events/event_service.js +44 -11
  174. package/dest/events/private_event_filter_validator.d.ts +3 -2
  175. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  176. package/dest/events/private_event_filter_validator.js +15 -0
  177. package/dest/hooks/authorize_utility_call.d.ts +41 -0
  178. package/dest/hooks/authorize_utility_call.d.ts.map +1 -0
  179. package/dest/hooks/authorize_utility_call.js +4 -0
  180. package/dest/hooks/execution_hooks.d.ts +62 -0
  181. package/dest/hooks/execution_hooks.d.ts.map +1 -0
  182. package/dest/hooks/execution_hooks.js +9 -0
  183. package/dest/hooks/index.d.ts +5 -0
  184. package/dest/hooks/index.d.ts.map +1 -0
  185. package/dest/hooks/index.js +1 -0
  186. package/dest/hooks/resolve_custom_request.d.ts +23 -0
  187. package/dest/hooks/resolve_custom_request.d.ts.map +1 -0
  188. package/dest/hooks/resolve_custom_request.js +3 -0
  189. package/dest/hooks/resolve_tagging_secret_strategy.d.ts +48 -0
  190. package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -0
  191. package/dest/hooks/resolve_tagging_secret_strategy.js +3 -0
  192. package/dest/logs/log_service.d.ts +13 -12
  193. package/dest/logs/log_service.d.ts.map +1 -1
  194. package/dest/logs/log_service.js +186 -81
  195. package/dest/messages/tx_resolver_service.d.ts +17 -0
  196. package/dest/messages/tx_resolver_service.d.ts.map +1 -0
  197. package/dest/messages/tx_resolver_service.js +55 -0
  198. package/dest/notes/note_service.d.ts +27 -6
  199. package/dest/notes/note_service.d.ts.map +1 -1
  200. package/dest/notes/note_service.js +80 -56
  201. package/dest/notes_filter.d.ts +2 -3
  202. package/dest/notes_filter.d.ts.map +1 -1
  203. package/dest/oracle_version.d.ts +4 -3
  204. package/dest/oracle_version.d.ts.map +1 -1
  205. package/dest/oracle_version.js +20 -10
  206. package/dest/private_kernel/batch_planner.d.ts +47 -0
  207. package/dest/private_kernel/batch_planner.d.ts.map +1 -0
  208. package/dest/private_kernel/batch_planner.js +104 -0
  209. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +1 -1
  210. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  211. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +7 -3
  212. package/dest/private_kernel/hints/test_utils.d.ts +1 -1
  213. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -1
  214. package/dest/private_kernel/hints/test_utils.js +3 -4
  215. package/dest/private_kernel/private_kernel_execution_prover.d.ts +6 -2
  216. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  217. package/dest/private_kernel/private_kernel_execution_prover.js +203 -89
  218. package/dest/private_kernel/private_kernel_oracle.d.ts +12 -10
  219. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  220. package/dest/private_kernel/private_kernel_oracle.js +40 -26
  221. package/dest/pxe.d.ts +167 -55
  222. package/dest/pxe.d.ts.map +1 -1
  223. package/dest/pxe.js +337 -207
  224. package/dest/storage/allowed_scopes.d.ts +6 -0
  225. package/dest/storage/allowed_scopes.d.ts.map +1 -0
  226. package/dest/storage/allowed_scopes.js +7 -0
  227. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -6
  228. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  229. package/dest/storage/anchor_block_store/anchor_block_store.js +9 -7
  230. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts +42 -0
  231. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts.map +1 -0
  232. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.js +93 -0
  233. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +15 -0
  234. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -0
  235. package/dest/storage/backwards_compatibility_tests/schema_tests.js +647 -0
  236. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts +19 -0
  237. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts.map +1 -0
  238. package/dest/storage/backwards_compatibility_tests/store_spy.js +63 -0
  239. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  240. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  241. package/dest/storage/capsule_store/capsule_service.js +47 -0
  242. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  243. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  244. package/dest/storage/capsule_store/capsule_store.js +36 -28
  245. package/dest/storage/capsule_store/index.d.ts +2 -1
  246. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  247. package/dest/storage/capsule_store/index.js +1 -0
  248. package/dest/storage/contract_store/contract_store.d.ts +27 -24
  249. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  250. package/dest/storage/contract_store/contract_store.js +70 -98
  251. package/dest/storage/fact_store/fact_service.d.ts +22 -0
  252. package/dest/storage/fact_store/fact_service.d.ts.map +1 -0
  253. package/dest/storage/fact_store/fact_service.js +45 -0
  254. package/dest/storage/fact_store/fact_store.d.ts +95 -0
  255. package/dest/storage/fact_store/fact_store.d.ts.map +1 -0
  256. package/dest/storage/fact_store/fact_store.js +408 -0
  257. package/dest/storage/fact_store/fact_store_keys.d.ts +34 -0
  258. package/dest/storage/fact_store/fact_store_keys.d.ts.map +1 -0
  259. package/dest/storage/fact_store/fact_store_keys.js +50 -0
  260. package/dest/storage/fact_store/index.d.ts +6 -0
  261. package/dest/storage/fact_store/index.d.ts.map +1 -0
  262. package/dest/storage/fact_store/index.js +4 -0
  263. package/dest/storage/fact_store/origin_state.d.ts +57 -0
  264. package/dest/storage/fact_store/origin_state.d.ts.map +1 -0
  265. package/dest/storage/fact_store/origin_state.js +53 -0
  266. package/dest/storage/fact_store/stored_fact.d.ts +32 -0
  267. package/dest/storage/fact_store/stored_fact.d.ts.map +1 -0
  268. package/dest/storage/fact_store/stored_fact.js +64 -0
  269. package/dest/storage/index.d.ts +3 -2
  270. package/dest/storage/index.d.ts.map +1 -1
  271. package/dest/storage/index.js +2 -1
  272. package/dest/storage/metadata.d.ts +2 -2
  273. package/dest/storage/metadata.d.ts.map +1 -1
  274. package/dest/storage/metadata.js +1 -1
  275. package/dest/storage/note_store/note_store.d.ts +42 -33
  276. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  277. package/dest/storage/note_store/note_store.js +199 -170
  278. package/dest/storage/note_store/stored_note.d.ts +3 -8
  279. package/dest/storage/note_store/stored_note.d.ts.map +1 -1
  280. package/dest/storage/note_store/stored_note.js +4 -20
  281. package/dest/storage/open_pxe_stores.d.ts +35 -0
  282. package/dest/storage/open_pxe_stores.d.ts.map +1 -0
  283. package/dest/storage/open_pxe_stores.js +29 -0
  284. package/dest/storage/private_event_store/private_event_store.d.ts +13 -16
  285. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  286. package/dest/storage/private_event_store/private_event_store.js +43 -43
  287. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  288. package/dest/storage/tagging_store/index.d.ts +2 -2
  289. package/dest/storage/tagging_store/index.d.ts.map +1 -1
  290. package/dest/storage/tagging_store/index.js +1 -1
  291. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  292. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  293. package/dest/storage/tagging_store/sender_tagging_store.d.ts +5 -5
  294. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  295. package/dest/storage/tagging_store/sender_tagging_store.js +3 -3
  296. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +51 -0
  297. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -0
  298. package/dest/storage/tagging_store/tagging_secret_sources_store.js +105 -0
  299. package/dest/tagging/constants.d.ts +2 -2
  300. package/dest/tagging/constants.d.ts.map +1 -1
  301. package/dest/tagging/constants.js +5 -8
  302. package/dest/tagging/get_all_logs_by_tags.d.ts +34 -10
  303. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  304. package/dest/tagging/get_all_logs_by_tags.js +36 -37
  305. package/dest/tagging/index.d.ts +5 -4
  306. package/dest/tagging/index.d.ts.map +1 -1
  307. package/dest/tagging/index.js +4 -3
  308. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts +29 -0
  309. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts.map +1 -0
  310. package/dest/tagging/persist_sender_tagging_index_ranges.js +42 -0
  311. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +69 -0
  312. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -0
  313. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +203 -0
  314. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +3 -3
  315. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -1
  316. package/dest/tagging/reconcile_tagging_index_ranges.d.ts +36 -0
  317. package/dest/tagging/reconcile_tagging_index_ranges.d.ts.map +1 -0
  318. package/dest/tagging/reconcile_tagging_index_ranges.js +74 -0
  319. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +4 -5
  320. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  321. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +26 -14
  322. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -6
  323. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  324. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +21 -0
  325. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +4 -4
  326. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  327. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +2 -2
  328. package/package.json +20 -17
  329. package/src/bin/check_oracle_version.ts +51 -133
  330. package/src/bin/index.ts +5 -0
  331. package/src/bin/oracle_version_helpers.ts +311 -0
  332. package/src/block_synchronizer/block_stream_source.ts +42 -0
  333. package/src/block_synchronizer/block_synchronizer.ts +102 -39
  334. package/src/config/index.ts +15 -8
  335. package/src/config/package_info.ts +1 -1
  336. package/src/contract/contract_class_service.ts +83 -0
  337. package/src/contract/contract_sync_service.ts +176 -0
  338. package/src/contract/helpers.ts +35 -0
  339. package/src/contract_function_simulator/anchored_contract_data.ts +74 -0
  340. package/src/contract_function_simulator/contract_function_simulator.ts +140 -58
  341. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  342. package/src/contract_function_simulator/execution_note_cache.ts +8 -29
  343. package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -9
  344. package/src/contract_function_simulator/index.ts +69 -5
  345. package/src/contract_function_simulator/noir-structs/bounded_vec.ts +43 -0
  346. package/src/contract_function_simulator/noir-structs/contract_class_log_data.ts +9 -0
  347. package/src/contract_function_simulator/noir-structs/embedded_curve_point.ts +4 -0
  348. package/src/contract_function_simulator/noir-structs/ephemeral_array.ts +66 -0
  349. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +5 -7
  350. package/src/contract_function_simulator/noir-structs/fact.ts +13 -0
  351. package/src/contract_function_simulator/noir-structs/fact_collection.ts +64 -0
  352. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +27 -20
  353. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +14 -61
  354. package/src/contract_function_simulator/noir-structs/note_data.ts +27 -0
  355. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +6 -8
  356. package/src/contract_function_simulator/noir-structs/option.ts +75 -0
  357. package/src/contract_function_simulator/noir-structs/origin_block.ts +8 -0
  358. package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
  359. package/src/contract_function_simulator/noir-structs/provided_secret.ts +5 -0
  360. package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +58 -0
  361. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +53 -0
  362. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +15 -0
  363. package/src/contract_function_simulator/noir-structs/utility_context.ts +5 -17
  364. package/src/contract_function_simulator/oracle/acir_callback.ts +154 -0
  365. package/src/contract_function_simulator/oracle/index.ts +1 -15
  366. package/src/contract_function_simulator/oracle/interfaces.ts +11 -176
  367. package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +120 -0
  368. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +6 -21
  369. package/src/contract_function_simulator/oracle/note_packing_utils.ts +3 -3
  370. package/src/contract_function_simulator/oracle/oracle_registry.ts +689 -0
  371. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +964 -0
  372. package/src/contract_function_simulator/oracle/private_execution.ts +3 -4
  373. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +240 -86
  374. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +783 -305
  375. package/src/contract_function_simulator/pick_notes.ts +22 -3
  376. package/src/contract_function_simulator/transient_array_service.ts +91 -0
  377. package/src/contract_logging.ts +18 -5
  378. package/src/debug/pxe_debug_utils.ts +4 -12
  379. package/src/entrypoints/client/bundle/index.ts +0 -1
  380. package/src/entrypoints/client/bundle/utils.ts +19 -7
  381. package/src/entrypoints/client/lazy/index.ts +0 -1
  382. package/src/entrypoints/client/lazy/utils.ts +19 -7
  383. package/src/entrypoints/pxe_creation_options.ts +21 -1
  384. package/src/entrypoints/server/index.ts +6 -3
  385. package/src/entrypoints/server/utils.ts +24 -7
  386. package/src/error_enriching.ts +27 -11
  387. package/src/events/event_service.ts +69 -21
  388. package/src/events/private_event_filter_validator.ts +21 -1
  389. package/src/hooks/authorize_utility_call.ts +44 -0
  390. package/src/hooks/execution_hooks.ts +68 -0
  391. package/src/hooks/index.ts +12 -0
  392. package/src/hooks/resolve_custom_request.ts +24 -0
  393. package/src/hooks/resolve_tagging_secret_strategy.ts +57 -0
  394. package/src/logs/log_service.ts +224 -146
  395. package/src/messages/tx_resolver_service.ts +69 -0
  396. package/src/notes/note_service.ts +119 -85
  397. package/src/notes_filter.ts +1 -3
  398. package/src/oracle_version.ts +20 -10
  399. package/src/private_kernel/batch_planner.ts +168 -0
  400. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +12 -2
  401. package/src/private_kernel/hints/test_utils.ts +3 -10
  402. package/src/private_kernel/private_kernel_execution_prover.ts +335 -121
  403. package/src/private_kernel/private_kernel_oracle.ts +58 -29
  404. package/src/pxe.ts +533 -236
  405. package/src/storage/allowed_scopes.ts +14 -0
  406. package/src/storage/anchor_block_store/anchor_block_store.ts +9 -7
  407. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +22 -0
  408. package/src/storage/backwards_compatibility_tests/__snapshots__/AnchorBlockStore.json +3 -0
  409. package/src/storage/backwards_compatibility_tests/__snapshots__/CapsuleStore.json +16 -0
  410. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +28 -0
  411. package/src/storage/backwards_compatibility_tests/__snapshots__/FactStore.json +40 -0
  412. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +52 -0
  413. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +40 -0
  414. package/src/storage/backwards_compatibility_tests/__snapshots__/NoteStore.json +56 -0
  415. package/src/storage/backwards_compatibility_tests/__snapshots__/PrivateEventStore.json +44 -0
  416. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +18 -0
  417. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +22 -0
  418. package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +30 -0
  419. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +117 -0
  420. package/src/storage/backwards_compatibility_tests/kv_store_snapshot.ts +122 -0
  421. package/src/storage/backwards_compatibility_tests/schema_tests.ts +774 -0
  422. package/src/storage/backwards_compatibility_tests/store_spy.ts +73 -0
  423. package/src/storage/capsule_store/capsule_service.ts +85 -0
  424. package/src/storage/capsule_store/capsule_store.ts +44 -26
  425. package/src/storage/capsule_store/index.ts +1 -0
  426. package/src/storage/contract_store/contract_store.ts +96 -124
  427. package/src/storage/fact_store/fact_service.ts +69 -0
  428. package/src/storage/fact_store/fact_store.ts +487 -0
  429. package/src/storage/fact_store/fact_store_keys.ts +75 -0
  430. package/src/storage/fact_store/index.ts +14 -0
  431. package/src/storage/fact_store/origin_state.ts +75 -0
  432. package/src/storage/fact_store/stored_fact.ts +80 -0
  433. package/src/storage/index.ts +2 -1
  434. package/src/storage/metadata.ts +1 -1
  435. package/src/storage/note_store/note_store.ts +228 -192
  436. package/src/storage/note_store/stored_note.ts +5 -27
  437. package/src/storage/open_pxe_stores.ts +52 -0
  438. package/src/storage/private_event_store/private_event_store.ts +52 -54
  439. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  440. package/src/storage/tagging_store/index.ts +1 -1
  441. package/src/storage/tagging_store/recipient_tagging_store.ts +5 -9
  442. package/src/storage/tagging_store/sender_tagging_store.ts +6 -6
  443. package/src/storage/tagging_store/tagging_secret_sources_store.ts +138 -0
  444. package/src/tagging/constants.ts +6 -8
  445. package/src/tagging/get_all_logs_by_tags.ts +78 -50
  446. package/src/tagging/index.ts +4 -3
  447. package/src/tagging/persist_sender_tagging_index_ranges.ts +57 -0
  448. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +301 -0
  449. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  450. package/src/tagging/reconcile_tagging_index_ranges.ts +102 -0
  451. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +41 -19
  452. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +23 -8
  453. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +4 -5
  454. package/dest/access_scopes.d.ts +0 -9
  455. package/dest/access_scopes.d.ts.map +0 -1
  456. package/dest/access_scopes.js +0 -6
  457. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +0 -16
  458. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +0 -1
  459. package/dest/contract_function_simulator/noir-structs/message_tx_context.js +0 -57
  460. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +0 -9
  461. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +0 -1
  462. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +0 -42
  463. package/dest/contract_function_simulator/oracle/oracle.d.ts +0 -61
  464. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +0 -1
  465. package/dest/contract_function_simulator/oracle/oracle.js +0 -437
  466. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +0 -6
  467. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +0 -1
  468. package/dest/contract_function_simulator/proxied_contract_data_source.js +0 -80
  469. package/dest/contract_sync/contract_sync_service.d.ts +0 -45
  470. package/dest/contract_sync/contract_sync_service.d.ts.map +0 -1
  471. package/dest/contract_sync/contract_sync_service.js +0 -114
  472. package/dest/contract_sync/helpers.d.ts +0 -29
  473. package/dest/contract_sync/helpers.d.ts.map +0 -1
  474. package/dest/contract_sync/helpers.js +0 -55
  475. package/dest/messages/message_context_service.d.ts +0 -17
  476. package/dest/messages/message_context_service.d.ts.map +0 -1
  477. package/dest/messages/message_context_service.js +0 -36
  478. package/dest/storage/tagging_store/sender_address_book_store.d.ts +0 -14
  479. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +0 -1
  480. package/dest/storage/tagging_store/sender_address_book_store.js +0 -36
  481. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +0 -14
  482. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +0 -1
  483. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +0 -99
  484. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +0 -14
  485. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +0 -1
  486. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +0 -33
  487. package/src/access_scopes.ts +0 -9
  488. package/src/contract_function_simulator/noir-structs/message_tx_context.ts +0 -55
  489. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +0 -135
  490. package/src/contract_function_simulator/oracle/oracle.ts +0 -675
  491. package/src/contract_function_simulator/proxied_contract_data_source.ts +0 -83
  492. package/src/contract_sync/contract_sync_service.ts +0 -181
  493. package/src/contract_sync/helpers.ts +0 -98
  494. package/src/messages/message_context_service.ts +0 -45
  495. package/src/storage/tagging_store/sender_address_book_store.ts +0 -48
  496. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +0 -140
  497. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +0 -44
@@ -0,0 +1,1243 @@
1
+ import { CONTRACT_CLASS_LOG_SIZE_IN_FIELDS, FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH, L1_TO_L2_MSG_TREE_HEIGHT, MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NULLIFIER_TREE_HEIGHT, PRIVATE_LOG_CIPHERTEXT_LEN, PRIVATE_LOG_SIZE_IN_FIELDS, PUBLIC_DATA_TREE_HEIGHT } from '@aztec/constants';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { padArrayEnd } from '@aztec/foundation/collection';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { EthAddress } from '@aztec/foundation/eth-address';
6
+ import { FieldReader } from '@aztec/foundation/serialize';
7
+ import { fromUintArray } from '@aztec/simulator/client';
8
+ import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
9
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import { BlockHash } from '@aztec/stdlib/block';
11
+ import { Tag, appTaggingSecretKindFromDeliveryMode } from '@aztec/stdlib/logs';
12
+ import { TxHash } from '@aztec/stdlib/tx';
13
+ import { BoundedVec } from '../noir-structs/bounded_vec.js';
14
+ import { EphemeralArray } from '../noir-structs/ephemeral_array.js';
15
+ import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
16
+ import { logSourceFromField } from '../noir-structs/log_retrieval_request.js';
17
+ import { NoteValidationRequest } from '../noir-structs/note_validation_request.js';
18
+ import { Option } from '../noir-structs/option.js';
19
+ import { resolvedTaggingStrategyFromFields, resolvedTaggingStrategyToFields } from '../noir-structs/resolved_tagging_strategy.js';
20
+ import { packAsHintedNote } from './note_packing_utils.js';
21
+ /**
22
+ * Asserts that every reader was fully consumed by a deserialization, throwing on leftover fields.
23
+ */ export function assertReadersConsumed(readers) {
24
+ readers.forEach((reader, slot)=>{
25
+ if (!reader.isFinished()) {
26
+ throw new Error(`Malformed oracle input: ${reader.remainingFields()} unexpected trailing field(s) in slot ${slot}`);
27
+ }
28
+ });
29
+ }
30
+ // ─── Scalar Type Mappings ────────────────────────────────────────────────────
31
+ export const FIELD = {
32
+ serialization: {
33
+ fn: (v)=>[
34
+ v
35
+ ]
36
+ },
37
+ deserialization: {
38
+ fn: ([reader])=>reader.readField()
39
+ },
40
+ shape: [
41
+ 'scalar'
42
+ ]
43
+ };
44
+ export const BOOL = {
45
+ serialization: {
46
+ fn: (v)=>[
47
+ new Fr(v ? 1n : 0n)
48
+ ]
49
+ },
50
+ deserialization: {
51
+ fn: ([reader])=>!reader.readField().isZero()
52
+ },
53
+ shape: [
54
+ 'scalar'
55
+ ]
56
+ };
57
+ export const U32 = {
58
+ serialization: {
59
+ fn: (v)=>[
60
+ new Fr(v)
61
+ ]
62
+ },
63
+ deserialization: {
64
+ fn: ([reader])=>{
65
+ const value = reader.readField().toBigInt();
66
+ if (value > 0xffffffffn) {
67
+ throw new Error(`U32 overflow: value ${value} exceeds u32 max (${0xffffffffn})`);
68
+ }
69
+ return Number(value);
70
+ }
71
+ },
72
+ shape: [
73
+ 'scalar'
74
+ ]
75
+ };
76
+ export const BLOCK_NUMBER = {
77
+ serialization: {
78
+ fn: (v)=>[
79
+ new Fr(v)
80
+ ]
81
+ },
82
+ deserialization: {
83
+ fn: ([reader])=>BlockNumber(reader.readField().toNumber())
84
+ },
85
+ shape: [
86
+ 'scalar'
87
+ ]
88
+ };
89
+ /** A u8 byte: serializes to a single Fr; deserializes from a single Fr to a number in [0, 255]. */ export const BYTE = {
90
+ serialization: {
91
+ fn: (byte)=>[
92
+ new Fr(byte)
93
+ ]
94
+ },
95
+ deserialization: {
96
+ fn: ([reader])=>{
97
+ const value = reader.readField().toBigInt();
98
+ if (value > 0xffn) {
99
+ throw new Error(`BYTE overflow: value ${value} exceeds u8 max (255)`);
100
+ }
101
+ return Number(value);
102
+ }
103
+ },
104
+ shape: [
105
+ 'scalar'
106
+ ]
107
+ };
108
+ // Noir passes `MessageDelivery` onchain variants here.
109
+ export const DELIVERY_MODE = {
110
+ deserialization: {
111
+ fn: (readers)=>appTaggingSecretKindFromDeliveryMode(BYTE.deserialization.fn(readers))
112
+ },
113
+ shape: BYTE.shape
114
+ };
115
+ export const RESOLVED_TAGGING_STRATEGY = {
116
+ serialization: {
117
+ fn: (resolved)=>resolvedTaggingStrategyToFields(resolved)
118
+ },
119
+ deserialization: {
120
+ fn: ([kindReader, secretReader])=>resolvedTaggingStrategyFromFields(kindReader.readField().toNumber(), secretReader.readField())
121
+ },
122
+ shape: [
123
+ 'scalar',
124
+ 'scalar'
125
+ ]
126
+ };
127
+ export const BIGINT = {
128
+ serialization: {
129
+ fn: (v)=>[
130
+ new Fr(v)
131
+ ]
132
+ },
133
+ deserialization: {
134
+ fn: ([reader])=>reader.readField().toBigInt()
135
+ },
136
+ shape: [
137
+ 'scalar'
138
+ ]
139
+ };
140
+ /** Reads every field in the slot as a UTF-8 character code. */ export const STR = {
141
+ serialization: {
142
+ fn: (str)=>[
143
+ Array.from(Buffer.from(str, 'utf-8')).map((b)=>new Fr(b))
144
+ ]
145
+ },
146
+ deserialization: {
147
+ fn: ([reader])=>{
148
+ const chars = [];
149
+ while(!reader.isFinished()){
150
+ chars.push(String.fromCharCode(reader.readField().toNumber()));
151
+ }
152
+ return chars.join('');
153
+ }
154
+ },
155
+ shape: [
156
+ 'variable'
157
+ ]
158
+ };
159
+ export const AZTEC_ADDRESS = {
160
+ serialization: {
161
+ fn: (v)=>[
162
+ v.toField()
163
+ ]
164
+ },
165
+ deserialization: {
166
+ fn: ([reader])=>AztecAddress.fromFieldUnsafe(reader.readField())
167
+ },
168
+ shape: [
169
+ 'scalar'
170
+ ]
171
+ };
172
+ export const BLOCK_HASH = {
173
+ serialization: {
174
+ fn: (v)=>[
175
+ new Fr(v.toBuffer())
176
+ ]
177
+ },
178
+ deserialization: {
179
+ fn: ([reader])=>new BlockHash(reader.readField())
180
+ },
181
+ shape: [
182
+ 'scalar'
183
+ ]
184
+ };
185
+ export const FUNCTION_SELECTOR = {
186
+ serialization: {
187
+ fn: (v)=>[
188
+ v.toField()
189
+ ]
190
+ },
191
+ deserialization: {
192
+ fn: ([reader])=>FunctionSelector.fromField(reader.readField())
193
+ },
194
+ shape: [
195
+ 'scalar'
196
+ ]
197
+ };
198
+ export const NOTE_SELECTOR = {
199
+ serialization: {
200
+ fn: (v)=>[
201
+ v.toField()
202
+ ]
203
+ },
204
+ deserialization: {
205
+ fn: ([reader])=>NoteSelector.fromField(reader.readField())
206
+ },
207
+ shape: [
208
+ 'scalar'
209
+ ]
210
+ };
211
+ export const TX_HASH = {
212
+ serialization: {
213
+ fn: (v)=>[
214
+ v.hash
215
+ ]
216
+ },
217
+ deserialization: {
218
+ fn: ([reader])=>TxHash.fromField(reader.readField())
219
+ },
220
+ shape: [
221
+ 'scalar'
222
+ ]
223
+ };
224
+ const TAG = {
225
+ serialization: {
226
+ fn: (v)=>[
227
+ v.value
228
+ ]
229
+ },
230
+ deserialization: {
231
+ fn: ([reader])=>new Tag(reader.readField())
232
+ },
233
+ shape: [
234
+ 'scalar'
235
+ ]
236
+ };
237
+ export const POINT = STRUCT([
238
+ {
239
+ name: 'x',
240
+ type: FIELD
241
+ },
242
+ {
243
+ name: 'y',
244
+ type: FIELD
245
+ }
246
+ ]);
247
+ const LOG_SOURCE = {
248
+ serialization: {
249
+ fn: (v)=>[
250
+ new Fr(v)
251
+ ]
252
+ },
253
+ deserialization: {
254
+ fn: ([reader])=>logSourceFromField(reader.readField())
255
+ },
256
+ shape: [
257
+ 'scalar'
258
+ ]
259
+ };
260
+ export const ETH_ADDRESS = {
261
+ serialization: {
262
+ fn: (v)=>[
263
+ v.toField()
264
+ ]
265
+ },
266
+ deserialization: {
267
+ fn: ([reader])=>EthAddress.fromField(reader.readField())
268
+ },
269
+ shape: [
270
+ 'scalar'
271
+ ]
272
+ };
273
+ export const SLOT_NUMBER = {
274
+ serialization: {
275
+ fn: (v)=>[
276
+ new Fr(v)
277
+ ]
278
+ },
279
+ shape: [
280
+ 'scalar'
281
+ ]
282
+ };
283
+ const APPEND_ONLY_TREE_SNAPSHOT = STRUCT([
284
+ {
285
+ name: 'root',
286
+ type: FIELD
287
+ },
288
+ {
289
+ name: 'nextAvailableLeafIndex',
290
+ type: U32
291
+ }
292
+ ]);
293
+ const PARTIAL_STATE_REFERENCE = STRUCT([
294
+ {
295
+ name: 'noteHashTree',
296
+ type: APPEND_ONLY_TREE_SNAPSHOT
297
+ },
298
+ {
299
+ name: 'nullifierTree',
300
+ type: APPEND_ONLY_TREE_SNAPSHOT
301
+ },
302
+ {
303
+ name: 'publicDataTree',
304
+ type: APPEND_ONLY_TREE_SNAPSHOT
305
+ }
306
+ ]);
307
+ const STATE_REFERENCE = STRUCT([
308
+ {
309
+ name: 'l1ToL2MessageTree',
310
+ type: APPEND_ONLY_TREE_SNAPSHOT
311
+ },
312
+ {
313
+ name: 'partial',
314
+ type: PARTIAL_STATE_REFERENCE
315
+ }
316
+ ]);
317
+ const GAS_FEES = STRUCT([
318
+ {
319
+ name: 'feePerDaGas',
320
+ type: BIGINT
321
+ },
322
+ {
323
+ name: 'feePerL2Gas',
324
+ type: BIGINT
325
+ }
326
+ ]);
327
+ const GLOBAL_VARIABLES = STRUCT([
328
+ {
329
+ name: 'chainId',
330
+ type: FIELD
331
+ },
332
+ {
333
+ name: 'version',
334
+ type: FIELD
335
+ },
336
+ {
337
+ name: 'blockNumber',
338
+ type: BLOCK_NUMBER
339
+ },
340
+ {
341
+ name: 'slotNumber',
342
+ type: SLOT_NUMBER
343
+ },
344
+ {
345
+ name: 'timestamp',
346
+ type: BIGINT
347
+ },
348
+ {
349
+ name: 'coinbase',
350
+ type: ETH_ADDRESS
351
+ },
352
+ {
353
+ name: 'feeRecipient',
354
+ type: AZTEC_ADDRESS
355
+ },
356
+ {
357
+ name: 'gasFees',
358
+ type: GAS_FEES
359
+ }
360
+ ]);
361
+ export const BLOCK_HEADER = STRUCT([
362
+ {
363
+ name: 'lastArchive',
364
+ type: APPEND_ONLY_TREE_SNAPSHOT
365
+ },
366
+ {
367
+ name: 'state',
368
+ type: STATE_REFERENCE
369
+ },
370
+ {
371
+ name: 'spongeBlobHash',
372
+ type: FIELD
373
+ },
374
+ {
375
+ name: 'globalVariables',
376
+ type: GLOBAL_VARIABLES
377
+ },
378
+ {
379
+ name: 'totalFees',
380
+ type: FIELD
381
+ },
382
+ {
383
+ name: 'totalManaUsed',
384
+ type: FIELD
385
+ }
386
+ ]);
387
+ export const KEY_VALIDATION_REQUEST = STRUCT([
388
+ {
389
+ name: 'pkMHash',
390
+ type: FIELD
391
+ },
392
+ {
393
+ name: 'skApp',
394
+ type: FIELD
395
+ }
396
+ ]);
397
+ const PUBLIC_KEYS = STRUCT([
398
+ {
399
+ name: 'npkMHash',
400
+ type: FIELD
401
+ },
402
+ {
403
+ name: 'ivpkM',
404
+ type: POINT
405
+ },
406
+ {
407
+ name: 'ovpkMHash',
408
+ type: FIELD
409
+ },
410
+ {
411
+ name: 'tpkMHash',
412
+ type: FIELD
413
+ },
414
+ {
415
+ name: 'mspkMHash',
416
+ type: FIELD
417
+ },
418
+ {
419
+ name: 'fbpkMHash',
420
+ type: FIELD
421
+ }
422
+ ]);
423
+ export const CONTRACT_INSTANCE = STRUCT([
424
+ {
425
+ name: 'salt',
426
+ type: FIELD
427
+ },
428
+ {
429
+ name: 'deployer',
430
+ type: AZTEC_ADDRESS
431
+ },
432
+ // Note that the nr side of this struct does not contain the current class, only original
433
+ {
434
+ name: 'originalContractClassId',
435
+ type: FIELD
436
+ },
437
+ {
438
+ name: 'initializationHash',
439
+ type: FIELD
440
+ },
441
+ {
442
+ name: 'immutablesHash',
443
+ type: FIELD
444
+ },
445
+ {
446
+ name: 'publicKeys',
447
+ type: PUBLIC_KEYS
448
+ }
449
+ ]);
450
+ const NULLIFIER_LEAF = STRUCT([
451
+ {
452
+ name: 'nullifier',
453
+ type: FIELD
454
+ }
455
+ ]);
456
+ const NULLIFIER_LEAF_PREIMAGE = STRUCT([
457
+ {
458
+ name: 'leaf',
459
+ type: NULLIFIER_LEAF
460
+ },
461
+ {
462
+ name: 'nextKey',
463
+ type: FIELD
464
+ },
465
+ {
466
+ name: 'nextIndex',
467
+ type: BIGINT
468
+ }
469
+ ]);
470
+ export const NULLIFIER_MEMBERSHIP_WITNESS = STRUCT([
471
+ {
472
+ name: 'leafPreimage',
473
+ type: NULLIFIER_LEAF_PREIMAGE
474
+ },
475
+ {
476
+ name: 'index',
477
+ type: BIGINT
478
+ },
479
+ {
480
+ name: 'siblingPath',
481
+ type: SIBLING_PATH(NULLIFIER_TREE_HEIGHT)
482
+ }
483
+ ]);
484
+ const PUBLIC_DATA_LEAF = STRUCT([
485
+ {
486
+ name: 'slot',
487
+ type: FIELD
488
+ },
489
+ {
490
+ name: 'value',
491
+ type: FIELD
492
+ }
493
+ ]);
494
+ const PUBLIC_DATA_LEAF_PREIMAGE = STRUCT([
495
+ {
496
+ name: 'leaf',
497
+ type: PUBLIC_DATA_LEAF
498
+ },
499
+ {
500
+ name: 'nextKey',
501
+ type: FIELD
502
+ },
503
+ {
504
+ name: 'nextIndex',
505
+ type: BIGINT
506
+ }
507
+ ]);
508
+ export const PUBLIC_DATA_WITNESS = STRUCT([
509
+ {
510
+ name: 'index',
511
+ type: BIGINT
512
+ },
513
+ {
514
+ name: 'leafPreimage',
515
+ type: PUBLIC_DATA_LEAF_PREIMAGE
516
+ },
517
+ {
518
+ name: 'siblingPath',
519
+ type: SIBLING_PATH(PUBLIC_DATA_TREE_HEIGHT)
520
+ }
521
+ ]);
522
+ export const MESSAGE_LOAD_ORACLE_INPUTS = STRUCT([
523
+ {
524
+ name: 'index',
525
+ type: BIGINT
526
+ },
527
+ {
528
+ name: 'siblingPath',
529
+ type: SIBLING_PATH(L1_TO_L2_MSG_TREE_HEIGHT)
530
+ }
531
+ ]);
532
+ export const UTILITY_CONTEXT = STRUCT([
533
+ {
534
+ name: 'blockHeader',
535
+ type: BLOCK_HEADER
536
+ },
537
+ {
538
+ name: 'contractAddress',
539
+ type: AZTEC_ADDRESS
540
+ },
541
+ {
542
+ name: 'msgSender',
543
+ type: AZTEC_ADDRESS
544
+ }
545
+ ]);
546
+ export const CALL_PRIVATE_RESULT = STRUCT([
547
+ {
548
+ name: 'endSideEffectCounter',
549
+ type: FIELD
550
+ },
551
+ {
552
+ name: 'returnsHash',
553
+ type: FIELD
554
+ }
555
+ ]);
556
+ export const PUBLIC_KEYS_AND_PARTIAL_ADDRESS = STRUCT([
557
+ {
558
+ name: 'publicKeys',
559
+ type: PUBLIC_KEYS
560
+ },
561
+ {
562
+ name: 'partialAddress',
563
+ type: FIELD
564
+ }
565
+ ]);
566
+ export const CONTRACT_CLASS_LOG = STRUCT([
567
+ {
568
+ name: 'contractAddress',
569
+ type: AZTEC_ADDRESS
570
+ },
571
+ {
572
+ name: 'fields',
573
+ type: FIXED_ARRAY(FIELD, CONTRACT_CLASS_LOG_SIZE_IN_FIELDS)
574
+ },
575
+ {
576
+ name: 'emittedLength',
577
+ type: U32
578
+ }
579
+ ]);
580
+ const REVERT_CODE = {
581
+ serialization: {
582
+ fn: (rc)=>[
583
+ rc.toField()
584
+ ]
585
+ },
586
+ shape: [
587
+ 'scalar'
588
+ ]
589
+ };
590
+ const PUBLIC_DATA_WRITE = STRUCT([
591
+ {
592
+ name: 'leafSlot',
593
+ type: FIELD
594
+ },
595
+ {
596
+ name: 'value',
597
+ type: FIELD
598
+ }
599
+ ]);
600
+ const PRIVATE_LOG = STRUCT([
601
+ {
602
+ name: 'fields',
603
+ type: FIXED_ARRAY(FIELD, PRIVATE_LOG_SIZE_IN_FIELDS)
604
+ },
605
+ {
606
+ name: 'emittedLength',
607
+ type: U32
608
+ }
609
+ ]);
610
+ const FLAT_PUBLIC_LOGS = STRUCT([
611
+ {
612
+ name: 'length',
613
+ type: U32
614
+ },
615
+ {
616
+ name: 'payload',
617
+ type: FIXED_ARRAY(FIELD, FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH)
618
+ }
619
+ ]);
620
+ const CONTRACT_CLASS_LOG_ENTRY = STRUCT([
621
+ {
622
+ name: 'fields',
623
+ type: FIXED_ARRAY(FIELD, CONTRACT_CLASS_LOG_SIZE_IN_FIELDS)
624
+ },
625
+ {
626
+ name: 'emittedLength',
627
+ type: U32
628
+ },
629
+ {
630
+ name: 'contractAddress',
631
+ type: AZTEC_ADDRESS
632
+ }
633
+ ]);
634
+ const CONTRACT_CLASS_LOGS = FIXED_ARRAY(CONTRACT_CLASS_LOG_ENTRY, MAX_CONTRACT_CLASS_LOGS_PER_TX);
635
+ export const TX_EFFECT = STRUCT([
636
+ {
637
+ name: 'revertCode',
638
+ type: REVERT_CODE
639
+ },
640
+ {
641
+ name: 'txHash',
642
+ type: TX_HASH
643
+ },
644
+ {
645
+ name: 'transactionFee',
646
+ type: FIELD
647
+ },
648
+ {
649
+ name: 'noteHashes',
650
+ type: FIXED_ARRAY(FIELD, MAX_NOTE_HASHES_PER_TX)
651
+ },
652
+ {
653
+ name: 'nullifiers',
654
+ type: FIXED_ARRAY(FIELD, MAX_NULLIFIERS_PER_TX)
655
+ },
656
+ {
657
+ name: 'l2ToL1Msgs',
658
+ type: FIXED_ARRAY(FIELD, MAX_L2_TO_L1_MSGS_PER_TX)
659
+ },
660
+ {
661
+ name: 'publicDataWrites',
662
+ type: FIXED_ARRAY(PUBLIC_DATA_WRITE, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX)
663
+ },
664
+ {
665
+ name: 'privateLogs',
666
+ type: FIXED_ARRAY(PRIVATE_LOG, MAX_PRIVATE_LOGS_PER_TX)
667
+ },
668
+ {
669
+ name: 'publicLogs',
670
+ type: FLAT_PUBLIC_LOGS
671
+ },
672
+ {
673
+ name: 'contractClassLogs',
674
+ type: CONTRACT_CLASS_LOGS
675
+ }
676
+ ]);
677
+ export const NOTE = {
678
+ serialization: {
679
+ fn: (noteData)=>packAsHintedNote({
680
+ contractAddress: noteData.contractAddress,
681
+ owner: noteData.owner,
682
+ randomness: noteData.randomness,
683
+ storageSlot: noteData.storageSlot,
684
+ noteNonce: noteData.noteNonce,
685
+ isPending: noteData.isPending,
686
+ note: noteData.note
687
+ })
688
+ },
689
+ // A packed note is the note's (variable-count) field items followed by 6 metadata scalars, emitted as one field
690
+ // output per element. Its length depends on the note, so it is described as a single variable-width run.
691
+ shape: [
692
+ 'variable'
693
+ ]
694
+ };
695
+ export const NOTE_VALIDATION_REQUEST = {
696
+ deserialization: {
697
+ fn: ([reader])=>NoteValidationRequest.fromFields(reader)
698
+ },
699
+ shape: [
700
+ 'variable'
701
+ ]
702
+ };
703
+ export const EVENT_VALIDATION_REQUEST = {
704
+ deserialization: {
705
+ fn: ([reader])=>EventValidationRequest.fromFields(reader)
706
+ },
707
+ shape: [
708
+ 'variable'
709
+ ]
710
+ };
711
+ export const LOG_RETRIEVAL_REQUEST = STRUCT([
712
+ {
713
+ name: 'contractAddress',
714
+ type: AZTEC_ADDRESS
715
+ },
716
+ {
717
+ name: 'tag',
718
+ type: TAG
719
+ },
720
+ {
721
+ name: 'source',
722
+ type: LOG_SOURCE
723
+ },
724
+ {
725
+ name: 'fromBlock',
726
+ type: OPTION(BLOCK_NUMBER)
727
+ },
728
+ {
729
+ name: 'toBlock',
730
+ type: OPTION(BLOCK_NUMBER)
731
+ }
732
+ ]);
733
+ export const LOG_RETRIEVAL_RESPONSE = STRUCT([
734
+ {
735
+ name: 'logPayload',
736
+ type: FIXED_BOUNDED_VEC(FIELD, PRIVATE_LOG_CIPHERTEXT_LEN)
737
+ },
738
+ {
739
+ name: 'txHash',
740
+ type: TX_HASH
741
+ },
742
+ {
743
+ name: 'uniqueNoteHashesInTx',
744
+ type: FIXED_BOUNDED_VEC(FIELD, MAX_NOTE_HASHES_PER_TX)
745
+ },
746
+ {
747
+ name: 'firstNullifierInTx',
748
+ type: FIELD
749
+ },
750
+ {
751
+ name: 'blockNumber',
752
+ type: BLOCK_NUMBER
753
+ },
754
+ {
755
+ name: 'blockTimestamp',
756
+ type: BIGINT
757
+ },
758
+ {
759
+ name: 'blockHash',
760
+ type: BLOCK_HASH
761
+ }
762
+ ]);
763
+ // `ResolvedTx.toFields()` packs the whole struct into a single slot: txHash, the uniqueNoteHashesInTx BoundedVec
764
+ // (MAX_NOTE_HASHES_PER_TX storage fields + length), firstNullifierInTx, blockNumber and blockHash.
765
+ export const RESOLVED_TX = {
766
+ serialization: {
767
+ fn: (resolved)=>[
768
+ resolved.toFields()
769
+ ]
770
+ },
771
+ shape: [
772
+ {
773
+ len: MAX_NOTE_HASHES_PER_TX + 5
774
+ }
775
+ ]
776
+ };
777
+ export const PENDING_TAGGED_LOG = STRUCT([
778
+ {
779
+ name: 'log',
780
+ type: FIXED_BOUNDED_VEC(FIELD, PRIVATE_LOG_SIZE_IN_FIELDS)
781
+ },
782
+ {
783
+ name: 'context',
784
+ type: RESOLVED_TX
785
+ }
786
+ ]);
787
+ export const ORIGIN_BLOCK = {
788
+ serialization: {
789
+ fn: (ob)=>[
790
+ new Fr(ob.blockNumber),
791
+ ob.blockHash
792
+ ]
793
+ },
794
+ deserialization: {
795
+ fn: ([blockNumberReader, blockHashReader])=>({
796
+ blockNumber: blockNumberReader.readField().toNumber(),
797
+ blockHash: blockHashReader.readField()
798
+ })
799
+ },
800
+ shape: [
801
+ 'scalar',
802
+ 'scalar'
803
+ ]
804
+ };
805
+ /** Read-side origin of a retractable fact, carrying the chain state of its origin block. */ export const RETRACTABLE_FACT_ORIGIN = {
806
+ serialization: {
807
+ fn: (o)=>[
808
+ new Fr(o.blockNumber),
809
+ o.blockHash,
810
+ new Fr(o.blockState)
811
+ ]
812
+ },
813
+ shape: [
814
+ 'scalar',
815
+ 'scalar',
816
+ 'scalar'
817
+ ]
818
+ };
819
+ // `facts` and `payload` each materialize to a single service-slot id, so a Fact occupies: factTypeId, the payload
820
+ // array slot, and `OPTION(RETRACTABLE_FACT_ORIGIN)` (its discriminant plus RETRACTABLE_FACT_ORIGIN's three slots).
821
+ export const FACT = {
822
+ serialization: {
823
+ fn: (f)=>[
824
+ f.factTypeId,
825
+ f.payload.materializeSlot((v)=>FIELD.serialization.fn(v).flat()),
826
+ ...OPTION(RETRACTABLE_FACT_ORIGIN).serialization.fn(f.originBlock)
827
+ ]
828
+ },
829
+ shape: [
830
+ 'scalar',
831
+ 'scalar',
832
+ 'scalar',
833
+ 'scalar',
834
+ 'scalar',
835
+ 'scalar'
836
+ ]
837
+ };
838
+ export const FACT_COLLECTION = {
839
+ serialization: {
840
+ fn: (c)=>[
841
+ c.contractAddress.toField(),
842
+ c.scope.toField(),
843
+ c.factCollectionTypeId,
844
+ c.factCollectionId,
845
+ c.facts.materializeSlot((v)=>FACT.serialization.fn(v).flat())
846
+ ]
847
+ },
848
+ shape: [
849
+ 'scalar',
850
+ 'scalar',
851
+ 'scalar',
852
+ 'scalar',
853
+ 'scalar'
854
+ ]
855
+ };
856
+ export const PROVIDED_SECRET = {
857
+ deserialization: {
858
+ fn: ([reader])=>({
859
+ secret: reader.readField(),
860
+ mode: appTaggingSecretKindFromDeliveryMode(BYTE.deserialization.fn([
861
+ reader
862
+ ]))
863
+ })
864
+ },
865
+ shape: [
866
+ {
867
+ len: 2
868
+ }
869
+ ]
870
+ };
871
+ // ─── Combinator Type Mappings ────────────────────────────────────────────────
872
+ function SIBLING_PATH(height) {
873
+ return {
874
+ serialization: {
875
+ fn: (sp)=>[
876
+ sp.toFields()
877
+ ]
878
+ },
879
+ shape: [
880
+ {
881
+ len: height
882
+ }
883
+ ]
884
+ };
885
+ }
886
+ export function MEMBERSHIP_WITNESS(height) {
887
+ return STRUCT([
888
+ {
889
+ name: 'leafIndex',
890
+ type: BIGINT
891
+ },
892
+ {
893
+ name: 'siblingPath',
894
+ type: FIXED_ARRAY(FIELD, height)
895
+ }
896
+ ]);
897
+ }
898
+ export function ARRAY(inner) {
899
+ return {
900
+ kind: 'array',
901
+ inner,
902
+ serialization: inner.serialization ? {
903
+ fn: (values)=>[
904
+ packElements(inner, values)
905
+ ]
906
+ } : undefined,
907
+ deserialization: inner.deserialization ? {
908
+ // The whole slot is the array, so read as many elements as its fields hold.
909
+ fn: ([reader])=>unpackElements(inner, reader, reader.remainingFields() / fieldWidth(inner.shape))
910
+ } : undefined,
911
+ // One slot of variable length (all elements flattened into it).
912
+ shape: [
913
+ {
914
+ lenFrom: (size)=>size.length * fieldWidth(inner.shape)
915
+ }
916
+ ]
917
+ };
918
+ }
919
+ /**
920
+ * Noir's fixed-length array `[T; length]` in one slot: serializes `values` (each flattened via `element`)
921
+ * zero-padded to exactly `length * elementWidth` fields, and deserializes all `length` elements back. An absent
922
+ * element is the zero encoding, so the padding is derived from the shape.
923
+ */ export function FIXED_ARRAY(element, length) {
924
+ const elementWidth = fieldWidth(element.shape);
925
+ return {
926
+ kind: 'fixed-array',
927
+ inner: element,
928
+ length,
929
+ serialization: element.serialization ? {
930
+ fn: (values)=>[
931
+ padArrayEnd(packElements(element, values), Fr.ZERO, length * elementWidth)
932
+ ]
933
+ } : undefined,
934
+ deserialization: element.deserialization ? {
935
+ fn: ([reader])=>unpackElements(element, reader, length)
936
+ } : undefined,
937
+ shape: [
938
+ {
939
+ len: length * elementWidth
940
+ }
941
+ ]
942
+ };
943
+ }
944
+ /**
945
+ * Maps Noir's `BoundedVec<T, MaxLen>` ↔ TS `BoundedVec<T>` over 2 slots:
946
+ * slot 0 — flat storage, padded/parsed as `maxLength * elementSize` fields
947
+ * slot 1 — length scalar (count of actual items)
948
+ *
949
+ * Both directions are derived from `element`: bidirectional iff `element` has both serialization and deserialization.
950
+ *
951
+ * @example Serializing `BoundedVec.from({ data: [0x41, 0x42], maxLength: 4 })` with `BOUNDED_VEC(BYTE)`:
952
+ * ```
953
+ * slot 0: [Fr(0x41), Fr(0x42), Fr(0), Fr(0)] // data padded to maxLength
954
+ * slot 1: Fr(2) // actual length
955
+ * ```
956
+ */ export function BOUNDED_VEC(inner) {
957
+ return {
958
+ kind: 'bounded-vec',
959
+ inner,
960
+ serialization: inner.serialization ? {
961
+ fn: (bv)=>{
962
+ if (bv.data.length > bv.maxLength) {
963
+ throw new Error(`Got ${bv.data.length} items, but maxLength is ${bv.maxLength}`);
964
+ }
965
+ // Fixed-width elements take their width from the shape (consistent with deserialization); only a
966
+ // variable-width element (e.g. a packed note) falls back to the runtime `elementSize` the value carries.
967
+ const elementWidth = tryFieldWidth(inner.shape) ?? bv.elementSize;
968
+ const flat = padArrayEnd(packElements(inner, bv.data), Fr.ZERO, bv.maxLength * elementWidth);
969
+ return [
970
+ flat,
971
+ new Fr(bv.data.length)
972
+ ];
973
+ }
974
+ } : undefined,
975
+ deserialization: inner.deserialization ? {
976
+ fn: ([storageReader, lengthReader])=>{
977
+ // slot 0 is the padded storage, slot 1 the actual length. Parse only the first `length` elements out of
978
+ // storage, then drain the trailing zero-padding so the storage reader is fully consumed.
979
+ const maxLength = storageReader.remainingFields() / fieldWidth(inner.shape);
980
+ const length = lengthReader.readField().toNumber();
981
+ const elements = unpackElements(inner, storageReader, length);
982
+ storageReader.skip(storageReader.remainingFields());
983
+ return BoundedVec.from({
984
+ data: elements,
985
+ maxLength
986
+ });
987
+ }
988
+ } : undefined,
989
+ // slot 0: variable-length storage; slot 1: the length scalar.
990
+ shape: [
991
+ {
992
+ lenFrom: (size)=>size.maxLength * fieldWidth(inner.shape)
993
+ },
994
+ 'scalar'
995
+ ]
996
+ };
997
+ }
998
+ /**
999
+ * Noir's `BoundedVec<T, MaxLen>` in its padded form (one fixed-width slot): `maxLength * elementWidth` storage fields
1000
+ * (zero-padded) followed by the actual length, with no length prefix, so the width is statically known. Serialize-only.
1001
+ * Throws if the input exceeds `maxLength`.
1002
+ */ export function FIXED_BOUNDED_VEC(element, maxLength) {
1003
+ const width = fieldWidth(element.shape);
1004
+ return {
1005
+ kind: 'fixed-bounded-vec',
1006
+ inner: element,
1007
+ maxLength,
1008
+ serialization: element.serialization ? {
1009
+ fn: (values)=>{
1010
+ if (values.length > maxLength) {
1011
+ throw new Error(`Got ${values.length} items, but maxLength is ${maxLength}`);
1012
+ }
1013
+ const flat = padArrayEnd(packElements(element, values), Fr.ZERO, maxLength * width);
1014
+ return [
1015
+ [
1016
+ ...flat,
1017
+ new Fr(values.length)
1018
+ ]
1019
+ ];
1020
+ }
1021
+ } : undefined,
1022
+ shape: [
1023
+ {
1024
+ len: maxLength * width + 1
1025
+ }
1026
+ ]
1027
+ };
1028
+ }
1029
+ /**
1030
+ * Wraps an inner TypeMapping in Noir-style `Option<T>`, adding a leading discriminant slot.
1031
+ *
1032
+ * For the `None` case, the inner's slots must still be present on the wire as zero-padding (so `Some` and `None` have
1033
+ * identical size). That padding is derived entirely from `inner.shape`.
1034
+ *
1035
+ * @example Serializing `Option.some(AztecAddress.fromFieldUnsafe(Fr(42)))` with `OPTION(AZTEC_ADDRESS)`:
1036
+ * ```
1037
+ * slot 0: Fr(1) // discriminant: Some
1038
+ * slot 1: Fr(42) // inner value
1039
+ * ```
1040
+ *
1041
+ * @example Serializing `Option.none()` with `OPTION(AZTEC_ADDRESS)`:
1042
+ * ```
1043
+ * slot 0: Fr(0) // discriminant: None
1044
+ * slot 1: Fr(0) // zero-filled from AZTEC_ADDRESS.shape
1045
+ * ```
1046
+ */ export function OPTION(inner) {
1047
+ return {
1048
+ kind: 'option',
1049
+ inner,
1050
+ serialization: inner.serialization ? {
1051
+ fn: (opt)=>opt.isSome() ? [
1052
+ Fr.ONE,
1053
+ ...inner.serialization.fn(opt.value)
1054
+ ] : [
1055
+ Fr.ZERO,
1056
+ ...zeroSlotsFromShape(inner.shape, opt.size)
1057
+ ]
1058
+ } : undefined,
1059
+ deserialization: inner.deserialization ? {
1060
+ fn: ([discriminant, ...innerReaders])=>{
1061
+ if (discriminant.readField().isZero()) {
1062
+ // None still carries the inner's zero-padded slots; consume them without parsing, since an inner that
1063
+ // validates its fields would reject the zeros.
1064
+ innerReaders.forEach((reader)=>reader.skip(reader.remainingFields()));
1065
+ return Option.none();
1066
+ }
1067
+ return Option.some(inner.deserialization.fn(innerReaders));
1068
+ }
1069
+ } : undefined,
1070
+ // A leading discriminant slot followed by the inner's slots.
1071
+ shape: [
1072
+ 'scalar',
1073
+ ...inner.shape
1074
+ ]
1075
+ };
1076
+ }
1077
+ /**
1078
+ * A fixed packed uint buffer (Noir `[u8; length]` at `bitSize` 8): one slot of `length` packed uint values ↔ `Buffer`.
1079
+ * `length` is the field count, which equals the byte count at `bitSize` 8.
1080
+ */ export function BUFFER(bitSize, length) {
1081
+ return {
1082
+ serialization: {
1083
+ fn: (buf)=>[
1084
+ Array.from(buf).map((b)=>new Fr(b))
1085
+ ]
1086
+ },
1087
+ deserialization: {
1088
+ fn: ([reader])=>fromUintArray(reader.readFieldArray(length).map((f)=>f.toString()), bitSize)
1089
+ },
1090
+ shape: [
1091
+ {
1092
+ len: length
1093
+ }
1094
+ ]
1095
+ };
1096
+ }
1097
+ export function EPHEMERAL_ARRAY(element) {
1098
+ // EphemeralArray.readAll hands each row's flat fields in as a single reader; reconstruct the element's per-slot
1099
+ // readers from its shape, deserialize, and assert the row was fully consumed so a row with trailing fields is
1100
+ // rejected.
1101
+ const rowElement = element.deserialization ? {
1102
+ deserialization: {
1103
+ fn: ([rowReader])=>deserializeElement(element, rowReader.readFieldArray(rowReader.remainingFields()))
1104
+ },
1105
+ // `fn` reads the whole row from one reader, so this is one variable-width slot, not the element's multi-slot
1106
+ // shape.
1107
+ shape: [
1108
+ 'variable'
1109
+ ]
1110
+ } : undefined;
1111
+ return {
1112
+ serialization: element.serialization ? {
1113
+ fn: (ea)=>[
1114
+ ea.materializeSlot((v)=>serializeElement(element, v))
1115
+ ]
1116
+ } : undefined,
1117
+ deserialization: rowElement ? {
1118
+ fn: ([reader])=>EphemeralArray.fromSlot(reader.readField(), rowElement)
1119
+ } : undefined,
1120
+ // A single slot carrying the array's service-slot id.
1121
+ shape: [
1122
+ 'scalar'
1123
+ ]
1124
+ };
1125
+ }
1126
+ /**
1127
+ * A Noir struct: its `shape` and (de)serialization are the concatenation of its fields', so callers never hand-write a
1128
+ * `shape`. `T` is the struct's TS value type and must match the field layout — serialization reads each field by name
1129
+ * off the value, deserialization returns the decoded bag as `T`; convert in the handler, not here, when `T` differs.
1130
+ */ export function STRUCT(fields) {
1131
+ return {
1132
+ kind: 'struct',
1133
+ fields,
1134
+ serialization: fields.every((f)=>f.type.serialization) ? {
1135
+ fn: (value)=>{
1136
+ const props = value;
1137
+ return fields.flatMap((f)=>f.type.serialization.fn(props[f.name]));
1138
+ }
1139
+ } : undefined,
1140
+ deserialization: fields.every((f)=>f.type.deserialization) ? {
1141
+ fn: (readers)=>{
1142
+ const props = {};
1143
+ let slot = 0;
1144
+ for (const f of fields){
1145
+ const slotCount = f.type.shape.length;
1146
+ props[f.name] = f.type.deserialization.fn(readers.slice(slot, slot + slotCount));
1147
+ slot += slotCount;
1148
+ }
1149
+ return props;
1150
+ }
1151
+ } : undefined,
1152
+ shape: fields.flatMap((f)=>f.type.shape)
1153
+ };
1154
+ }
1155
+ /** Number of InputSlots a deserializable type spans, derived from its {@link TypeMapping.shape}. */ export function slotsOf(mapping) {
1156
+ return mapping.shape.length;
1157
+ }
1158
+ /** Number of fields a fully-static shape occupies, or `undefined` if any slot is variable-width. */ export function tryFieldWidth(shape) {
1159
+ let total = 0;
1160
+ for (const slot of shape){
1161
+ if (slot === 'scalar') {
1162
+ total += 1;
1163
+ } else if (typeof slot === 'object' && 'len' in slot) {
1164
+ total += slot.len;
1165
+ } else {
1166
+ return undefined;
1167
+ }
1168
+ }
1169
+ return total;
1170
+ }
1171
+ /** Number of fields a fully-static shape occupies. Throws on a variable-width shape, whose field count isn't known. */ function fieldWidth(shape) {
1172
+ const width = tryFieldWidth(shape);
1173
+ if (width === undefined) {
1174
+ throw new Error('Cannot compute a fixed field width for a variable-width shape');
1175
+ }
1176
+ return width;
1177
+ }
1178
+ /** Reconstructs a value's per-slot readers from a flat run of fields, using its shape (inverse of slot-flattening). */ function splitByShape(fields, shape) {
1179
+ const readers = [];
1180
+ let cursor = 0;
1181
+ shape.forEach((slot, i)=>{
1182
+ if (slot === 'scalar' || typeof slot === 'object' && 'len' in slot) {
1183
+ const width = slot === 'scalar' ? 1 : slot.len;
1184
+ if (cursor + width > fields.length) {
1185
+ throw new Error(`Not enough fields to reconstruct shape: needed ${width}, had ${fields.length - cursor}`);
1186
+ }
1187
+ readers.push(new FieldReader(fields.slice(cursor, cursor + width)));
1188
+ cursor += width;
1189
+ } else {
1190
+ // A variable slot (sized or not) takes whatever remains, so it must be last.
1191
+ if (i !== shape.length - 1) {
1192
+ throw new Error('A variable-width slot must be last to be reconstructed from a flat field array');
1193
+ }
1194
+ readers.push(new FieldReader(fields.slice(cursor)));
1195
+ cursor = fields.length;
1196
+ }
1197
+ });
1198
+ if (cursor !== fields.length) {
1199
+ throw new Error(`Malformed flattened value: ${fields.length - cursor} unexpected trailing field(s)`);
1200
+ }
1201
+ return readers;
1202
+ }
1203
+ /** Serializes one element to its flat fields. Element must be serializable. */ function serializeElement(element, value) {
1204
+ return element.serialization.fn(value).flat();
1205
+ }
1206
+ /**
1207
+ * Deserializes one element from its exact flat fields, reconstructing its per-slot readers from its shape and asserting
1208
+ * they are fully consumed (so trailing fields are rejected). Element must be deserializable.
1209
+ */ function deserializeElement(element, fields) {
1210
+ const readers = splitByShape(fields, element.shape);
1211
+ const value = element.deserialization.fn(readers);
1212
+ assertReadersConsumed(readers);
1213
+ return value;
1214
+ }
1215
+ /** Flattens `values` into one contiguous run of fields by serializing each element. Element must be serializable. */ function packElements(element, values) {
1216
+ return values.flatMap((v)=>serializeElement(element, v));
1217
+ }
1218
+ /**
1219
+ * Reads `count` fixed-width elements out of a packed run (the inverse of {@link packElements}). Element must be
1220
+ * deserializable.
1221
+ */ function unpackElements(element, reader, count) {
1222
+ const elementWidth = fieldWidth(element.shape);
1223
+ return Array.from({
1224
+ length: count
1225
+ }, ()=>deserializeElement(element, reader.readFieldArray(elementWidth)));
1226
+ }
1227
+ /** Builds the zero-filled slots for a `None`, matching a `Some`'s wire shape (variable slots sized from `size`). */ function zeroSlotsFromShape(shape, size) {
1228
+ return shape.map((slot)=>{
1229
+ if (slot === 'scalar') {
1230
+ return Fr.ZERO;
1231
+ }
1232
+ if (slot === 'variable') {
1233
+ throw new Error('Cannot zero-fill an unsized variable-width slot');
1234
+ }
1235
+ if ('len' in slot) {
1236
+ return Array(slot.len).fill(Fr.ZERO);
1237
+ }
1238
+ if (size === undefined) {
1239
+ throw new Error('Serializing Option.none() over a variable-size inner needs a size, e.g. Option.none({ length: n })');
1240
+ }
1241
+ return Array(slot.lenFrom(size)).fill(Fr.ZERO);
1242
+ });
1243
+ }