@aztec/pxe 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240
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.
- package/dest/bin/check_oracle_version.d.ts +12 -2
- package/dest/bin/check_oracle_version.d.ts.map +1 -1
- package/dest/bin/check_oracle_version.js +32 -26
- package/dest/bin/index.d.ts +2 -0
- package/dest/bin/index.d.ts.map +1 -0
- package/dest/bin/index.js +1 -0
- package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
- package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
- package/dest/block_synchronizer/block_stream_source.js +62 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +16 -6
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +94 -23
- package/dest/config/index.d.ts +10 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -2
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/benchmarked_node.js +77 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +69 -36
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +240 -91
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
- package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +45 -28
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -11
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -15
- package/dest/contract_function_simulator/index.d.ts +5 -2
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +4 -1
- package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +48 -0
- package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/bounded_vec.js +45 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +5 -7
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +9 -10
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +13 -3
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +35 -4
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +5 -8
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +7 -11
- package/dest/contract_function_simulator/noir-structs/option.d.ts +61 -0
- package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/option.js +62 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +70 -50
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +7 -7
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +10 -10
- package/dest/contract_function_simulator/oracle/oracle.d.ts +74 -43
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +471 -264
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +147 -0
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/oracle_registry.js +1199 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -38
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +74 -91
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +164 -110
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +156 -78
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +459 -186
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +20 -3
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +35 -64
- package/dest/contract_logging.d.ts +27 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +38 -0
- package/dest/contract_sync/contract_sync_service.d.ts +42 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +135 -0
- package/dest/contract_sync/helpers.d.ts +27 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +53 -0
- package/dest/debug/pxe_debug_utils.d.ts +19 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +22 -17
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +33 -11
- package/dest/entrypoints/client/lazy/index.d.ts +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +34 -12
- package/dest/entrypoints/pxe_creation_options.d.ts +11 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +6 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +5 -1
- package/dest/entrypoints/server/utils.d.ts +4 -3
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +40 -13
- package/dest/events/event_service.d.ts +17 -8
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +58 -28
- package/dest/events/private_event_filter_validator.d.ts +6 -5
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +20 -6
- package/dest/hooks/authorize_utility_call.d.ts +41 -0
- package/dest/hooks/authorize_utility_call.d.ts.map +1 -0
- package/dest/hooks/authorize_utility_call.js +4 -0
- package/dest/hooks/execution_hooks.d.ts +42 -0
- package/dest/hooks/execution_hooks.d.ts.map +1 -0
- package/dest/hooks/execution_hooks.js +9 -0
- package/dest/hooks/index.d.ts +4 -0
- package/dest/hooks/index.d.ts.map +1 -0
- package/dest/hooks/index.js +1 -0
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +13 -10
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +132 -84
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +38 -0
- package/dest/notes/note_service.d.ts +31 -9
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +97 -77
- package/dest/notes_filter.d.ts +24 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -9
- package/dest/private_kernel/batch_planner.d.ts +47 -0
- package/dest/private_kernel/batch_planner.d.ts.map +1 -0
- package/dest/private_kernel/batch_planner.js +104 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +3 -3
- package/dest/private_kernel/hints/index.d.ts.map +1 -1
- package/dest/private_kernel/hints/index.js +2 -2
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
- package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +141 -74
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +202 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +7 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +168 -67
- package/dest/private_kernel/private_kernel_oracle.d.ts +28 -29
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +96 -2
- package/dest/pxe.d.ts +126 -59
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +257 -200
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +9 -2
- package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts +42 -0
- package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts.map +1 -0
- package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.js +93 -0
- package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +15 -0
- package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -0
- package/dest/storage/backwards_compatibility_tests/schema_tests.js +591 -0
- package/dest/storage/backwards_compatibility_tests/store_spy.d.ts +19 -0
- package/dest/storage/backwards_compatibility_tests/store_spy.d.ts.map +1 -0
- package/dest/storage/backwards_compatibility_tests/store_spy.js +63 -0
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +25 -10
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +143 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +42 -16
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +158 -102
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +50 -51
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +284 -263
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/open_pxe_stores.d.ts +33 -0
- package/dest/storage/open_pxe_stores.d.ts.map +1 -0
- package/dest/storage/open_pxe_stores.js +27 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +43 -8
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +229 -111
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +16 -9
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +43 -32
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +300 -122
- package/dest/tagging/get_all_logs_by_tags.d.ts +48 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +59 -0
- package/dest/tagging/index.d.ts +7 -5
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +5 -3
- package/dest/tagging/persist_sender_tagging_index_ranges.d.ts +29 -0
- package/dest/tagging/persist_sender_tagging_index_ranges.d.ts.map +1 -0
- package/dest/tagging/persist_sender_tagging_index_ranges.js +42 -0
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +56 -0
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +163 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +3 -3
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/reconcile_tagging_index_ranges.d.ts +36 -0
- package/dest/tagging/reconcile_tagging_index_ranges.d.ts.map +1 -0
- package/dest/tagging/reconcile_tagging_index_ranges.js +74 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +34 -18
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +13 -7
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +44 -16
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +8 -7
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +44 -27
- package/package.json +31 -19
- package/src/bin/check_oracle_version.ts +42 -31
- package/src/bin/index.ts +1 -0
- package/src/block_synchronizer/block_stream_source.ts +81 -0
- package/src/block_synchronizer/block_synchronizer.ts +116 -36
- package/src/config/index.ts +21 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/benchmarked_node.ts +103 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +417 -156
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- package/src/contract_function_simulator/execution_note_cache.ts +44 -25
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -18
- package/src/contract_function_simulator/index.ts +4 -1
- package/src/contract_function_simulator/noir-structs/bounded_vec.ts +55 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +11 -10
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +36 -3
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +6 -11
- package/src/contract_function_simulator/noir-structs/option.ts +69 -0
- package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
- package/src/contract_function_simulator/oracle/interfaces.ts +93 -70
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +13 -13
- package/src/contract_function_simulator/oracle/oracle.ts +567 -461
- package/src/contract_function_simulator/oracle/oracle_registry.ts +904 -0
- package/src/contract_function_simulator/oracle/private_execution.ts +5 -71
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +213 -209
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +657 -254
- package/src/contract_function_simulator/pick_notes.ts +22 -3
- package/src/contract_function_simulator/proxied_contract_data_source.ts +41 -64
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +189 -0
- package/src/contract_sync/helpers.ts +86 -0
- package/src/debug/pxe_debug_utils.ts +55 -18
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +26 -20
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +28 -21
- package/src/entrypoints/pxe_creation_options.ts +16 -1
- package/src/entrypoints/server/index.ts +5 -1
- package/src/entrypoints/server/utils.ts +37 -32
- package/src/events/event_service.ts +79 -39
- package/src/events/private_event_filter_validator.ts +23 -5
- package/src/hooks/authorize_utility_call.ts +44 -0
- package/src/hooks/execution_hooks.ts +48 -0
- package/src/hooks/index.ts +7 -0
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +171 -141
- package/src/messages/message_context_service.ts +45 -0
- package/src/notes/note_service.ts +137 -107
- package/src/notes_filter.ts +24 -0
- package/src/oracle_version.ts +20 -9
- package/src/private_kernel/batch_planner.ts +169 -0
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +2 -2
- package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +196 -137
- package/src/private_kernel/hints/test_utils.ts +318 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +261 -93
- package/src/private_kernel/private_kernel_oracle.ts +129 -40
- package/src/pxe.ts +467 -273
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +9 -1
- package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +22 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/AnchorBlockStore.json +3 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/CapsuleStore.json +16 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +28 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +52 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +46 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/NoteStore.json +36 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/PrivateEventStore.json +44 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +18 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/SenderAddressBookStore.json +16 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +22 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +97 -0
- package/src/storage/backwards_compatibility_tests/kv_store_snapshot.ts +122 -0
- package/src/storage/backwards_compatibility_tests/schema_tests.ts +712 -0
- package/src/storage/backwards_compatibility_tests/store_spy.ts +73 -0
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +183 -29
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +194 -125
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +323 -320
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/open_pxe_stores.ts +49 -0
- package/src/storage/private_event_store/private_event_store.ts +296 -124
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +107 -21
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +366 -134
- package/src/tagging/get_all_logs_by_tags.ts +120 -0
- package/src/tagging/index.ts +6 -4
- package/src/tagging/persist_sender_tagging_index_ranges.ts +57 -0
- package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +240 -0
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +4 -4
- package/src/tagging/reconcile_tagging_index_ranges.ts +102 -0
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +59 -21
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +47 -29
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +41 -29
- package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
- package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
- package/dest/contract_function_simulator/proxied_node.js +0 -27
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +0 -85
- package/dest/public_storage/public_storage_service.d.ts +0 -24
- package/dest/public_storage/public_storage_service.d.ts.map +0 -1
- package/dest/public_storage/public_storage_service.js +0 -26
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +0 -14
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +0 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +0 -99
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +0 -14
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +0 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +0 -29
- package/dest/tree_membership/tree_membership_service.d.ts +0 -52
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -84
- package/src/contract_function_simulator/proxied_node.ts +0 -33
- package/src/private_kernel/private_kernel_oracle_impl.ts +0 -127
- package/src/public_storage/public_storage_service.ts +0 -33
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +0 -132
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +0 -43
- package/src/tree_membership/tree_membership_service.ts +0 -112
|
@@ -0,0 +1,904 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import {
|
|
3
|
+
ARCHIVE_HEIGHT,
|
|
4
|
+
BLOCK_HEADER_LENGTH,
|
|
5
|
+
KEY_VALIDATION_REQUEST_LENGTH,
|
|
6
|
+
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
7
|
+
MAX_CONTRACT_CLASS_LOGS_PER_TX,
|
|
8
|
+
MAX_L2_TO_L1_MSGS_PER_TX,
|
|
9
|
+
MAX_NOTE_HASHES_PER_TX,
|
|
10
|
+
MAX_NULLIFIERS_PER_TX,
|
|
11
|
+
MAX_PRIVATE_LOGS_PER_TX,
|
|
12
|
+
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
13
|
+
NOTE_HASH_TREE_HEIGHT,
|
|
14
|
+
} from '@aztec/constants';
|
|
15
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
16
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
17
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
18
|
+
import { FieldReader } from '@aztec/foundation/serialize';
|
|
19
|
+
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
20
|
+
import { type ACVMField, fromUintArray, toACVMField } from '@aztec/simulator/client';
|
|
21
|
+
import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
22
|
+
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
23
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
24
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
25
|
+
import type { ContractInstance, PartialAddress } from '@aztec/stdlib/contract';
|
|
26
|
+
import { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
27
|
+
import type { PublicKeys } from '@aztec/stdlib/keys';
|
|
28
|
+
import { ContractClassLog, ContractClassLogFields, FlatPublicLogs, PrivateLog, Tag } from '@aztec/stdlib/logs';
|
|
29
|
+
import { NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
30
|
+
import { BlockHeader, TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
31
|
+
|
|
32
|
+
import { BoundedVec } from '../noir-structs/bounded_vec.js';
|
|
33
|
+
import { Option } from '../noir-structs/option.js';
|
|
34
|
+
import { UtilityContext } from '../noir-structs/utility_context.js';
|
|
35
|
+
import type { NoteData } from './interfaces.js';
|
|
36
|
+
import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
37
|
+
import { packAsHintedNote } from './note_packing_utils.js';
|
|
38
|
+
|
|
39
|
+
const FIELD: TypeMapping<Fr> = {
|
|
40
|
+
serialization: { fn: v => [v] },
|
|
41
|
+
deserialization: { fn: ([reader]) => reader.readField(), slots: 1 },
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const BOOL: TypeMapping<boolean> = {
|
|
45
|
+
serialization: { fn: v => [new Fr(v ? 1n : 0n)] },
|
|
46
|
+
deserialization: { fn: ([reader]) => !reader.readField().isZero(), slots: 1 },
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const U32: TypeMapping<number> = {
|
|
50
|
+
serialization: { fn: v => [new Fr(v)] },
|
|
51
|
+
deserialization: {
|
|
52
|
+
fn: ([reader]) => {
|
|
53
|
+
const value = reader.readField().toBigInt();
|
|
54
|
+
if (value > 0xffffffffn) {
|
|
55
|
+
throw new Error(`U32 overflow: value ${value} exceeds u32 max (${0xffffffffn})`);
|
|
56
|
+
}
|
|
57
|
+
return Number(value);
|
|
58
|
+
},
|
|
59
|
+
slots: 1,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const BLOCK_NUMBER: TypeMapping<BlockNumber> = {
|
|
64
|
+
serialization: { fn: v => [new Fr(v)] },
|
|
65
|
+
deserialization: { fn: ([reader]) => BlockNumber(reader.readField().toNumber()), slots: 1 },
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** A u8 byte: serializes to a single Fr; deserializes from a single Fr to a number in [0, 255]. */
|
|
69
|
+
export const BYTE: TypeMapping<number> = {
|
|
70
|
+
serialization: { fn: byte => [new Fr(byte)] },
|
|
71
|
+
deserialization: {
|
|
72
|
+
fn: ([reader]) => {
|
|
73
|
+
const value = reader.readField().toBigInt();
|
|
74
|
+
if (value > 0xffn) {
|
|
75
|
+
throw new Error(`BYTE overflow: value ${value} exceeds u8 max (255)`);
|
|
76
|
+
}
|
|
77
|
+
return Number(value);
|
|
78
|
+
},
|
|
79
|
+
slots: 1,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Reads every field in the slot as a UTF-8 character code. */
|
|
84
|
+
const STR: TypeMapping<string> = {
|
|
85
|
+
serialization: { fn: str => [Array.from(Buffer.from(str, 'utf-8')).map(b => new Fr(b))] },
|
|
86
|
+
deserialization: {
|
|
87
|
+
fn: ([reader]) => {
|
|
88
|
+
const chars: string[] = [];
|
|
89
|
+
while (!reader.isFinished()) {
|
|
90
|
+
chars.push(String.fromCharCode(reader.readField().toNumber()));
|
|
91
|
+
}
|
|
92
|
+
return chars.join('');
|
|
93
|
+
},
|
|
94
|
+
slots: 1,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const AZTEC_ADDRESS: TypeMapping<AztecAddress> = {
|
|
99
|
+
serialization: { fn: v => [v.toField()] },
|
|
100
|
+
deserialization: { fn: ([reader]) => AztecAddress.fromField(reader.readField()), slots: 1 },
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const BLOCK_HASH: TypeMapping<BlockHash> = {
|
|
104
|
+
serialization: { fn: v => [new Fr(v.toBuffer())] },
|
|
105
|
+
deserialization: { fn: ([reader]) => new BlockHash(reader.readField()), slots: 1 },
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const FUNCTION_SELECTOR: TypeMapping<FunctionSelector> = {
|
|
109
|
+
serialization: { fn: v => [v.toField()] },
|
|
110
|
+
deserialization: { fn: ([reader]) => FunctionSelector.fromField(reader.readField()), slots: 1 },
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const NOTE_SELECTOR: TypeMapping<NoteSelector> = {
|
|
114
|
+
serialization: { fn: v => [v.toField()] },
|
|
115
|
+
deserialization: { fn: ([reader]) => NoteSelector.fromField(reader.readField()), slots: 1 },
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const TX_HASH: TypeMapping<TxHash> = {
|
|
119
|
+
serialization: { fn: v => [v.hash] },
|
|
120
|
+
deserialization: { fn: ([reader]) => TxHash.fromField(reader.readField()), slots: 1 },
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const TAG: TypeMapping<Tag> = {
|
|
124
|
+
serialization: { fn: v => [v.value] },
|
|
125
|
+
deserialization: { fn: ([reader]) => new Tag(reader.readField()), slots: 1 },
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const BLOCK_HEADER: TypeMapping<BlockHeader> = {
|
|
129
|
+
serialization: { fn: v => v.toFields() },
|
|
130
|
+
deserialization: { fn: ([reader]) => BlockHeader.fromFields(reader.readFieldArray(BLOCK_HEADER_LENGTH)), slots: 1 },
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const KEY_VALIDATION_REQUEST: TypeMapping<KeyValidationRequest> = {
|
|
134
|
+
serialization: { fn: v => v.toFields() },
|
|
135
|
+
deserialization: {
|
|
136
|
+
fn: ([reader]) => KeyValidationRequest.fromFields(reader.readFieldArray(KEY_VALIDATION_REQUEST_LENGTH)),
|
|
137
|
+
slots: 1,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const CONTRACT_INSTANCE: TypeMapping<ContractInstance> = {
|
|
142
|
+
serialization: {
|
|
143
|
+
fn: v => [
|
|
144
|
+
v.salt,
|
|
145
|
+
v.deployer.toField(),
|
|
146
|
+
v.currentContractClassId,
|
|
147
|
+
v.initializationHash,
|
|
148
|
+
v.immutablesHash,
|
|
149
|
+
...v.publicKeys.toFields(),
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const NULLIFIER_MEMBERSHIP_WITNESS: TypeMapping<NullifierMembershipWitness> = {
|
|
155
|
+
serialization: {
|
|
156
|
+
fn: (w: NullifierMembershipWitness) =>
|
|
157
|
+
w
|
|
158
|
+
.toNoirRepresentation()
|
|
159
|
+
.map(slot => (Array.isArray(slot) ? slot.map(s => Fr.fromString(s)) : Fr.fromString(slot as string))),
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const PUBLIC_DATA_WITNESS: TypeMapping<PublicDataWitness> = {
|
|
164
|
+
serialization: {
|
|
165
|
+
fn: (w: PublicDataWitness) =>
|
|
166
|
+
w
|
|
167
|
+
.toNoirRepresentation()
|
|
168
|
+
.map(slot => (Array.isArray(slot) ? slot.map(s => Fr.fromString(s)) : Fr.fromString(slot as string))),
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const MESSAGE_LOAD_ORACLE_INPUTS: TypeMapping<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> = {
|
|
173
|
+
serialization: {
|
|
174
|
+
fn: (m: MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>) =>
|
|
175
|
+
m
|
|
176
|
+
.toNoirRepresentation()
|
|
177
|
+
.map(slot => (Array.isArray(slot) ? slot.map(s => Fr.fromString(s)) : Fr.fromString(slot as string))),
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const UTILITY_CONTEXT: TypeMapping<UtilityContext> = {
|
|
182
|
+
serialization: {
|
|
183
|
+
fn: (ctx: UtilityContext) => [...ctx.blockHeader.toFields(), ctx.contractAddress.toField()],
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const CALL_PRIVATE_RESULT: TypeMapping<{ endSideEffectCounter: Fr; returnsHash: Fr }> = {
|
|
188
|
+
serialization: { fn: v => [[v.endSideEffectCounter, v.returnsHash]] },
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const PUBLIC_KEYS_AND_PARTIAL_ADDRESS: TypeMapping<{
|
|
192
|
+
publicKeys: PublicKeys;
|
|
193
|
+
partialAddress: PartialAddress;
|
|
194
|
+
}> = {
|
|
195
|
+
serialization: {
|
|
196
|
+
fn: v => [[...v.publicKeys.toFields(), v.partialAddress]],
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const CONTRACT_CLASS_LOG_INPUT: TypeMapping<ContractClassLog> = {
|
|
201
|
+
deserialization: {
|
|
202
|
+
fn: ([addrReader, fieldsReader, lengthReader]) => {
|
|
203
|
+
const addr = AztecAddress.fromField(addrReader.readField());
|
|
204
|
+
const fields = new ContractClassLogFields([...fieldsReader.readFieldArray(fieldsReader.remainingFields())]);
|
|
205
|
+
const length = lengthReader.readField().toNumber();
|
|
206
|
+
return new ContractClassLog(addr, fields, length);
|
|
207
|
+
},
|
|
208
|
+
// ContractClassLog input occupies 3 ACVM slots: [contractAddress], [message fields...], [length].
|
|
209
|
+
slots: 3,
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const TX_EFFECT: TypeMapping<TxEffect> = {
|
|
214
|
+
serialization: {
|
|
215
|
+
fn: (effect: TxEffect) => {
|
|
216
|
+
const flatPublicLogs = FlatPublicLogs.fromLogs(effect.publicLogs);
|
|
217
|
+
return [
|
|
218
|
+
effect.revertCode.toField(),
|
|
219
|
+
effect.txHash.hash,
|
|
220
|
+
effect.transactionFee,
|
|
221
|
+
padArrayEnd(effect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
|
|
222
|
+
padArrayEnd(effect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX),
|
|
223
|
+
padArrayEnd(effect.l2ToL1Msgs, Fr.ZERO, MAX_L2_TO_L1_MSGS_PER_TX),
|
|
224
|
+
padArrayEnd(
|
|
225
|
+
effect.publicDataWrites,
|
|
226
|
+
PublicDataWrite.empty(),
|
|
227
|
+
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
228
|
+
).flatMap(w => w.toFields()),
|
|
229
|
+
padArrayEnd(effect.privateLogs, PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX).flatMap(l => l.toFields()),
|
|
230
|
+
new Fr(flatPublicLogs.length),
|
|
231
|
+
flatPublicLogs.payload,
|
|
232
|
+
padArrayEnd(effect.contractClassLogs, ContractClassLog.empty(), MAX_CONTRACT_CLASS_LOGS_PER_TX).flatMap(l => [
|
|
233
|
+
...l.fields.toFields(),
|
|
234
|
+
new Fr(l.emittedLength),
|
|
235
|
+
l.contractAddress.toField(),
|
|
236
|
+
]),
|
|
237
|
+
] as (Fr | Fr[])[];
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const NOTE: TypeMapping<NoteData> = {
|
|
243
|
+
serialization: {
|
|
244
|
+
fn: noteData =>
|
|
245
|
+
packAsHintedNote({
|
|
246
|
+
contractAddress: noteData.contractAddress,
|
|
247
|
+
owner: noteData.owner,
|
|
248
|
+
randomness: noteData.randomness,
|
|
249
|
+
storageSlot: noteData.storageSlot,
|
|
250
|
+
noteNonce: noteData.noteNonce,
|
|
251
|
+
isPending: noteData.isPending,
|
|
252
|
+
note: noteData.note,
|
|
253
|
+
}),
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const ORACLE_REGISTRY = {
|
|
258
|
+
aztec_utl_assertCompatibleOracleVersion: makeEntry({
|
|
259
|
+
params: [
|
|
260
|
+
{ name: 'major', type: U32 },
|
|
261
|
+
{ name: 'minor', type: U32 },
|
|
262
|
+
],
|
|
263
|
+
}),
|
|
264
|
+
|
|
265
|
+
aztec_utl_getRandomField: makeEntry({ returnType: FIELD }),
|
|
266
|
+
|
|
267
|
+
aztec_utl_log: makeEntry({
|
|
268
|
+
params: [
|
|
269
|
+
{ name: 'level', type: U32 },
|
|
270
|
+
{ name: 'message', type: STR },
|
|
271
|
+
{ name: 'fieldsSize', type: U32 },
|
|
272
|
+
{ name: 'fields', type: ARRAY(FIELD) },
|
|
273
|
+
],
|
|
274
|
+
}),
|
|
275
|
+
|
|
276
|
+
aztec_utl_getUtilityContext: makeEntry({ returnType: UTILITY_CONTEXT }),
|
|
277
|
+
|
|
278
|
+
aztec_utl_getKeyValidationRequest: makeEntry({
|
|
279
|
+
params: [{ name: 'pkMHash', type: FIELD }],
|
|
280
|
+
returnType: KEY_VALIDATION_REQUEST,
|
|
281
|
+
}),
|
|
282
|
+
|
|
283
|
+
aztec_utl_getContractInstance: makeEntry({
|
|
284
|
+
params: [{ name: 'address', type: AZTEC_ADDRESS }],
|
|
285
|
+
returnType: CONTRACT_INSTANCE,
|
|
286
|
+
}),
|
|
287
|
+
|
|
288
|
+
aztec_utl_getNoteHashMembershipWitness: makeEntry({
|
|
289
|
+
params: [
|
|
290
|
+
{ name: 'anchorBlockHash', type: BLOCK_HASH },
|
|
291
|
+
{ name: 'noteHash', type: FIELD },
|
|
292
|
+
],
|
|
293
|
+
returnType: MEMBERSHIP_WITNESS(NOTE_HASH_TREE_HEIGHT),
|
|
294
|
+
}),
|
|
295
|
+
|
|
296
|
+
aztec_utl_getBlockHashMembershipWitness: makeEntry({
|
|
297
|
+
params: [
|
|
298
|
+
{ name: 'anchorBlockHash', type: BLOCK_HASH },
|
|
299
|
+
{ name: 'blockHash', type: BLOCK_HASH },
|
|
300
|
+
],
|
|
301
|
+
returnType: OPTION(MEMBERSHIP_WITNESS(ARCHIVE_HEIGHT)),
|
|
302
|
+
}),
|
|
303
|
+
|
|
304
|
+
aztec_utl_getNullifierMembershipWitness: makeEntry({
|
|
305
|
+
params: [
|
|
306
|
+
{ name: 'blockHash', type: BLOCK_HASH },
|
|
307
|
+
{ name: 'nullifier', type: FIELD },
|
|
308
|
+
],
|
|
309
|
+
returnType: NULLIFIER_MEMBERSHIP_WITNESS,
|
|
310
|
+
}),
|
|
311
|
+
|
|
312
|
+
aztec_utl_getLowNullifierMembershipWitness: makeEntry({
|
|
313
|
+
params: [
|
|
314
|
+
{ name: 'blockHash', type: BLOCK_HASH },
|
|
315
|
+
{ name: 'nullifier', type: FIELD },
|
|
316
|
+
],
|
|
317
|
+
returnType: NULLIFIER_MEMBERSHIP_WITNESS,
|
|
318
|
+
}),
|
|
319
|
+
|
|
320
|
+
aztec_utl_getPublicDataWitness: makeEntry({
|
|
321
|
+
params: [
|
|
322
|
+
{ name: 'blockHash', type: BLOCK_HASH },
|
|
323
|
+
{ name: 'leafSlot', type: FIELD },
|
|
324
|
+
],
|
|
325
|
+
returnType: PUBLIC_DATA_WITNESS,
|
|
326
|
+
}),
|
|
327
|
+
|
|
328
|
+
aztec_utl_getBlockHeader: makeEntry({
|
|
329
|
+
params: [{ name: 'blockNumber', type: BLOCK_NUMBER }],
|
|
330
|
+
returnType: BLOCK_HEADER,
|
|
331
|
+
}),
|
|
332
|
+
|
|
333
|
+
aztec_utl_getAuthWitness: makeEntry({
|
|
334
|
+
params: [{ name: 'messageHash', type: FIELD }],
|
|
335
|
+
returnType: ARRAY(FIELD),
|
|
336
|
+
}),
|
|
337
|
+
|
|
338
|
+
aztec_utl_getPublicKeysAndPartialAddress: makeEntry({
|
|
339
|
+
params: [{ name: 'address', type: AZTEC_ADDRESS }],
|
|
340
|
+
returnType: OPTION(PUBLIC_KEYS_AND_PARTIAL_ADDRESS),
|
|
341
|
+
}),
|
|
342
|
+
|
|
343
|
+
aztec_utl_doesNullifierExist: makeEntry({
|
|
344
|
+
params: [{ name: 'innerNullifier', type: FIELD }],
|
|
345
|
+
returnType: BOOL,
|
|
346
|
+
}),
|
|
347
|
+
|
|
348
|
+
aztec_utl_getL1ToL2MembershipWitness: makeEntry({
|
|
349
|
+
params: [
|
|
350
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
351
|
+
{ name: 'messageHash', type: FIELD },
|
|
352
|
+
{ name: 'secret', type: FIELD },
|
|
353
|
+
],
|
|
354
|
+
returnType: MESSAGE_LOAD_ORACLE_INPUTS,
|
|
355
|
+
}),
|
|
356
|
+
|
|
357
|
+
aztec_utl_getFromPublicStorage: makeEntry({
|
|
358
|
+
params: [
|
|
359
|
+
{ name: 'blockHash', type: BLOCK_HASH },
|
|
360
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
361
|
+
{ name: 'startStorageSlot', type: FIELD },
|
|
362
|
+
{ name: 'numberOfElements', type: U32 },
|
|
363
|
+
],
|
|
364
|
+
returnType: ARRAY(FIELD),
|
|
365
|
+
}),
|
|
366
|
+
|
|
367
|
+
aztec_utl_getNotes: makeEntry({
|
|
368
|
+
params: [
|
|
369
|
+
{ name: 'owner', type: OPTION(AZTEC_ADDRESS) },
|
|
370
|
+
{ name: 'storageSlot', type: FIELD },
|
|
371
|
+
{ name: 'numSelects', type: U32 },
|
|
372
|
+
{ name: 'selectByIndexes', type: ARRAY(U32) },
|
|
373
|
+
{ name: 'selectByOffsets', type: ARRAY(U32) },
|
|
374
|
+
{ name: 'selectByLengths', type: ARRAY(U32) },
|
|
375
|
+
{ name: 'selectValues', type: ARRAY(FIELD) },
|
|
376
|
+
{ name: 'selectComparators', type: ARRAY(U32) },
|
|
377
|
+
{ name: 'sortByIndexes', type: ARRAY(U32) },
|
|
378
|
+
{ name: 'sortByOffsets', type: ARRAY(U32) },
|
|
379
|
+
{ name: 'sortByLengths', type: ARRAY(U32) },
|
|
380
|
+
{ name: 'sortOrder', type: ARRAY(U32) },
|
|
381
|
+
{ name: 'limit', type: U32 },
|
|
382
|
+
{ name: 'offset', type: U32 },
|
|
383
|
+
{ name: 'status', type: U32 },
|
|
384
|
+
{ name: 'maxNotes', type: U32 },
|
|
385
|
+
{ name: 'packedHintedNoteLength', type: U32 },
|
|
386
|
+
],
|
|
387
|
+
returnType: BOUNDED_VEC(NOTE),
|
|
388
|
+
}),
|
|
389
|
+
|
|
390
|
+
aztec_utl_getPendingTaggedLogs: makeEntry({
|
|
391
|
+
params: [{ name: 'scope', type: AZTEC_ADDRESS }],
|
|
392
|
+
returnType: FIELD,
|
|
393
|
+
}),
|
|
394
|
+
|
|
395
|
+
aztec_utl_validateAndStoreEnqueuedNotesAndEvents: makeEntry({
|
|
396
|
+
params: [
|
|
397
|
+
{ name: 'noteValidationRequestsArrayBaseSlot', type: FIELD },
|
|
398
|
+
{ name: 'eventValidationRequestsArrayBaseSlot', type: FIELD },
|
|
399
|
+
{ name: 'scope', type: AZTEC_ADDRESS },
|
|
400
|
+
],
|
|
401
|
+
}),
|
|
402
|
+
|
|
403
|
+
aztec_utl_getLogsByTag: makeEntry({
|
|
404
|
+
params: [{ name: 'requestArrayBaseSlot', type: FIELD }],
|
|
405
|
+
returnType: FIELD,
|
|
406
|
+
}),
|
|
407
|
+
|
|
408
|
+
aztec_utl_getMessageContextsByTxHash: makeEntry({
|
|
409
|
+
params: [{ name: 'requestArrayBaseSlot', type: FIELD }],
|
|
410
|
+
returnType: FIELD,
|
|
411
|
+
}),
|
|
412
|
+
|
|
413
|
+
aztec_utl_getTxEffect: makeEntry({
|
|
414
|
+
params: [{ name: 'txHash', type: TX_HASH }],
|
|
415
|
+
returnType: OPTION(TX_EFFECT),
|
|
416
|
+
}),
|
|
417
|
+
|
|
418
|
+
aztec_utl_setCapsule: makeEntry({
|
|
419
|
+
params: [
|
|
420
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
421
|
+
{ name: 'slot', type: FIELD },
|
|
422
|
+
{ name: 'capsule', type: ARRAY(FIELD) },
|
|
423
|
+
{ name: 'scope', type: AZTEC_ADDRESS },
|
|
424
|
+
],
|
|
425
|
+
}),
|
|
426
|
+
|
|
427
|
+
aztec_utl_getCapsule: makeEntry({
|
|
428
|
+
params: [
|
|
429
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
430
|
+
{ name: 'slot', type: FIELD },
|
|
431
|
+
{ name: 'tSize', type: U32 },
|
|
432
|
+
{ name: 'scope', type: AZTEC_ADDRESS },
|
|
433
|
+
],
|
|
434
|
+
returnType: OPTION(ARRAY(FIELD)),
|
|
435
|
+
}),
|
|
436
|
+
|
|
437
|
+
aztec_utl_deleteCapsule: makeEntry({
|
|
438
|
+
params: [
|
|
439
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
440
|
+
{ name: 'slot', type: FIELD },
|
|
441
|
+
{ name: 'scope', type: AZTEC_ADDRESS },
|
|
442
|
+
],
|
|
443
|
+
}),
|
|
444
|
+
|
|
445
|
+
aztec_utl_copyCapsule: makeEntry({
|
|
446
|
+
params: [
|
|
447
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
448
|
+
{ name: 'srcSlot', type: FIELD },
|
|
449
|
+
{ name: 'dstSlot', type: FIELD },
|
|
450
|
+
{ name: 'numEntries', type: U32 },
|
|
451
|
+
{ name: 'scope', type: AZTEC_ADDRESS },
|
|
452
|
+
],
|
|
453
|
+
}),
|
|
454
|
+
|
|
455
|
+
aztec_utl_decryptAes128: makeEntry({
|
|
456
|
+
params: [
|
|
457
|
+
{ name: 'ciphertext', type: BOUNDED_VEC(BYTE) },
|
|
458
|
+
{ name: 'iv', type: BUFFER(8) },
|
|
459
|
+
{ name: 'symKey', type: BUFFER(8) },
|
|
460
|
+
],
|
|
461
|
+
returnType: OPTION(BOUNDED_VEC(BYTE)),
|
|
462
|
+
}),
|
|
463
|
+
|
|
464
|
+
aztec_utl_getSharedSecrets: makeEntry({
|
|
465
|
+
params: [
|
|
466
|
+
{ name: 'address', type: AZTEC_ADDRESS },
|
|
467
|
+
{ name: 'ephPksSlot', type: FIELD },
|
|
468
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
469
|
+
],
|
|
470
|
+
returnType: FIELD,
|
|
471
|
+
}),
|
|
472
|
+
|
|
473
|
+
aztec_utl_setContractSyncCacheInvalid: makeEntry({
|
|
474
|
+
params: [
|
|
475
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
476
|
+
{ name: 'scopes', type: BOUNDED_VEC(AZTEC_ADDRESS) },
|
|
477
|
+
],
|
|
478
|
+
}),
|
|
479
|
+
|
|
480
|
+
aztec_utl_emitOffchainEffect: makeEntry({
|
|
481
|
+
params: [{ name: 'data', type: ARRAY(FIELD) }],
|
|
482
|
+
}),
|
|
483
|
+
|
|
484
|
+
aztec_utl_callUtilityFunction: makeEntry({
|
|
485
|
+
params: [
|
|
486
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
487
|
+
{ name: 'functionSelector', type: FUNCTION_SELECTOR },
|
|
488
|
+
{ name: 'args', type: ARRAY(FIELD) },
|
|
489
|
+
],
|
|
490
|
+
returnType: ARRAY(FIELD),
|
|
491
|
+
}),
|
|
492
|
+
|
|
493
|
+
aztec_utl_pushEphemeral: makeEntry({
|
|
494
|
+
params: [
|
|
495
|
+
{ name: 'slot', type: FIELD },
|
|
496
|
+
{ name: 'elements', type: ARRAY(FIELD) },
|
|
497
|
+
],
|
|
498
|
+
returnType: U32,
|
|
499
|
+
}),
|
|
500
|
+
|
|
501
|
+
aztec_utl_popEphemeral: makeEntry({
|
|
502
|
+
params: [{ name: 'slot', type: FIELD }],
|
|
503
|
+
returnType: ARRAY(FIELD),
|
|
504
|
+
}),
|
|
505
|
+
|
|
506
|
+
aztec_utl_getEphemeral: makeEntry({
|
|
507
|
+
params: [
|
|
508
|
+
{ name: 'slot', type: FIELD },
|
|
509
|
+
{ name: 'index', type: U32 },
|
|
510
|
+
],
|
|
511
|
+
returnType: ARRAY(FIELD),
|
|
512
|
+
}),
|
|
513
|
+
|
|
514
|
+
aztec_utl_setEphemeral: makeEntry({
|
|
515
|
+
params: [
|
|
516
|
+
{ name: 'slot', type: FIELD },
|
|
517
|
+
{ name: 'index', type: U32 },
|
|
518
|
+
{ name: 'elements', type: ARRAY(FIELD) },
|
|
519
|
+
],
|
|
520
|
+
}),
|
|
521
|
+
|
|
522
|
+
aztec_utl_getEphemeralLen: makeEntry({
|
|
523
|
+
params: [{ name: 'slot', type: FIELD }],
|
|
524
|
+
returnType: U32,
|
|
525
|
+
}),
|
|
526
|
+
|
|
527
|
+
aztec_utl_removeEphemeral: makeEntry({
|
|
528
|
+
params: [
|
|
529
|
+
{ name: 'slot', type: FIELD },
|
|
530
|
+
{ name: 'index', type: U32 },
|
|
531
|
+
],
|
|
532
|
+
}),
|
|
533
|
+
|
|
534
|
+
aztec_utl_clearEphemeral: makeEntry({
|
|
535
|
+
params: [{ name: 'slot', type: FIELD }],
|
|
536
|
+
}),
|
|
537
|
+
|
|
538
|
+
aztec_prv_setHashPreimage: makeEntry({
|
|
539
|
+
params: [
|
|
540
|
+
{ name: 'values', type: ARRAY(FIELD) },
|
|
541
|
+
{ name: 'hash', type: FIELD },
|
|
542
|
+
],
|
|
543
|
+
}),
|
|
544
|
+
|
|
545
|
+
aztec_prv_getHashPreimage: makeEntry({
|
|
546
|
+
params: [{ name: 'returnsHash', type: FIELD }],
|
|
547
|
+
returnType: ARRAY(FIELD),
|
|
548
|
+
}),
|
|
549
|
+
|
|
550
|
+
aztec_prv_notifyCreatedNote: makeEntry({
|
|
551
|
+
params: [
|
|
552
|
+
{ name: 'owner', type: AZTEC_ADDRESS },
|
|
553
|
+
{ name: 'storageSlot', type: FIELD },
|
|
554
|
+
{ name: 'randomness', type: FIELD },
|
|
555
|
+
{ name: 'noteTypeId', type: NOTE_SELECTOR },
|
|
556
|
+
{ name: 'note', type: ARRAY(FIELD) },
|
|
557
|
+
{ name: 'noteHash', type: FIELD },
|
|
558
|
+
{ name: 'counter', type: U32 },
|
|
559
|
+
],
|
|
560
|
+
}),
|
|
561
|
+
|
|
562
|
+
aztec_prv_notifyNullifiedNote: makeEntry({
|
|
563
|
+
params: [
|
|
564
|
+
{ name: 'innerNullifier', type: FIELD },
|
|
565
|
+
{ name: 'noteHash', type: FIELD },
|
|
566
|
+
{ name: 'counter', type: U32 },
|
|
567
|
+
],
|
|
568
|
+
}),
|
|
569
|
+
|
|
570
|
+
aztec_prv_notifyCreatedNullifier: makeEntry({
|
|
571
|
+
params: [{ name: 'innerNullifier', type: FIELD }],
|
|
572
|
+
}),
|
|
573
|
+
|
|
574
|
+
aztec_prv_isNullifierPending: makeEntry({
|
|
575
|
+
params: [
|
|
576
|
+
{ name: 'innerNullifier', type: FIELD },
|
|
577
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
578
|
+
],
|
|
579
|
+
returnType: BOOL,
|
|
580
|
+
}),
|
|
581
|
+
|
|
582
|
+
aztec_prv_notifyCreatedContractClassLog: makeEntry({
|
|
583
|
+
params: [
|
|
584
|
+
{ name: 'log', type: CONTRACT_CLASS_LOG_INPUT },
|
|
585
|
+
{ name: 'counter', type: U32 },
|
|
586
|
+
],
|
|
587
|
+
}),
|
|
588
|
+
|
|
589
|
+
aztec_prv_callPrivateFunction: makeEntry({
|
|
590
|
+
params: [
|
|
591
|
+
{ name: 'contractAddress', type: AZTEC_ADDRESS },
|
|
592
|
+
{ name: 'functionSelector', type: FUNCTION_SELECTOR },
|
|
593
|
+
{ name: 'argsHash', type: FIELD },
|
|
594
|
+
{ name: 'sideEffectCounter', type: U32 },
|
|
595
|
+
{ name: 'isStaticCall', type: BOOL },
|
|
596
|
+
],
|
|
597
|
+
returnType: CALL_PRIVATE_RESULT,
|
|
598
|
+
}),
|
|
599
|
+
|
|
600
|
+
aztec_prv_assertValidPublicCalldata: makeEntry({
|
|
601
|
+
params: [{ name: 'calldataHash', type: FIELD }],
|
|
602
|
+
}),
|
|
603
|
+
|
|
604
|
+
aztec_prv_notifyRevertiblePhaseStart: makeEntry({
|
|
605
|
+
params: [{ name: 'minRevertibleSideEffectCounter', type: U32 }],
|
|
606
|
+
}),
|
|
607
|
+
|
|
608
|
+
aztec_prv_isExecutionInRevertiblePhase: makeEntry({
|
|
609
|
+
params: [{ name: 'sideEffectCounter', type: U32 }],
|
|
610
|
+
returnType: BOOL,
|
|
611
|
+
}),
|
|
612
|
+
|
|
613
|
+
aztec_prv_getNextAppTagAsSender: makeEntry({
|
|
614
|
+
params: [
|
|
615
|
+
{ name: 'sender', type: AZTEC_ADDRESS },
|
|
616
|
+
{ name: 'recipient', type: AZTEC_ADDRESS },
|
|
617
|
+
],
|
|
618
|
+
returnType: TAG,
|
|
619
|
+
}),
|
|
620
|
+
|
|
621
|
+
aztec_prv_getNextConstrainedTaggingIndex: makeEntry({
|
|
622
|
+
params: [{ name: 'appSiloedSecret', type: FIELD }],
|
|
623
|
+
returnType: U32,
|
|
624
|
+
}),
|
|
625
|
+
|
|
626
|
+
aztec_prv_getSenderForTags: makeEntry({ returnType: OPTION(AZTEC_ADDRESS) }),
|
|
627
|
+
} satisfies Record<string, OracleRegistryEntry>;
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Deserializes oracle inputs, calls the handler with typed params, and serializes the result.
|
|
631
|
+
*/
|
|
632
|
+
export async function callHandler<K extends keyof typeof ORACLE_REGISTRY>({
|
|
633
|
+
oracle,
|
|
634
|
+
inputs,
|
|
635
|
+
handler,
|
|
636
|
+
}: {
|
|
637
|
+
oracle: K;
|
|
638
|
+
inputs: InputSlot[];
|
|
639
|
+
handler: (
|
|
640
|
+
params: ParamTypes<ReturnType<(typeof ORACLE_REGISTRY)[K]['deserializeParams']>>,
|
|
641
|
+
) => MaybePromise<Parameters<(typeof ORACLE_REGISTRY)[K]['serializeReturn']>[0]>;
|
|
642
|
+
}): Promise<OutputSlot[]> {
|
|
643
|
+
const entry = ORACLE_REGISTRY[oracle] as OracleRegistryEntry;
|
|
644
|
+
const named = entry.deserializeParams(inputs);
|
|
645
|
+
const positional = named.map(p => p.value);
|
|
646
|
+
const result = await handler(positional as any);
|
|
647
|
+
return entry.serializeReturn(result);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// ─── Helper Types ─────────────────────────────────────────────────────────────
|
|
651
|
+
|
|
652
|
+
/** One ACVM input slot: an array of hex-encoded field strings. */
|
|
653
|
+
type InputSlot = ACVMField[];
|
|
654
|
+
|
|
655
|
+
/** One ACVM output slot: a scalar hex string or an array of hex strings. */
|
|
656
|
+
type OutputSlot = ACVMField | ACVMField[];
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Describes how to serialize and/or deserialize a single typed value to/from ACVM wire format.
|
|
660
|
+
* Either side is optional — output-only types omit `deserialization`, input-only types omit `serialization`.
|
|
661
|
+
*/
|
|
662
|
+
export interface TypeMapping<T = any> {
|
|
663
|
+
serialization?: {
|
|
664
|
+
/** Convert a typed value to ACVM output slot(s). */
|
|
665
|
+
fn: (value: T) => (Fr | Fr[])[];
|
|
666
|
+
};
|
|
667
|
+
deserialization?: {
|
|
668
|
+
/** Read a typed value from one FieldReader per consumed slot. */
|
|
669
|
+
fn: (readers: FieldReader[]) => T;
|
|
670
|
+
/**
|
|
671
|
+
* Number of InputSlots this type reads from. `deserialization.fn` receives one FieldReader per slot in `readers`.
|
|
672
|
+
*
|
|
673
|
+
* Examples:
|
|
674
|
+
* - `FIELD`, `U32`, `AZTEC_ADDRESS` — single slot → `slots: 1`
|
|
675
|
+
* - `OPTION(T)` — discriminant + inner slots → `slots: T.slots + 1`
|
|
676
|
+
* - `CONTRACT_CLASS_LOG_INPUT` — [addr], [fields], [len] → `slots: 3`
|
|
677
|
+
*/
|
|
678
|
+
slots: number;
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* A full oracle registry entry describing param and return serialization.
|
|
684
|
+
*
|
|
685
|
+
* TDeserializedParams — the array of named pairs returned by `deserializeParams`.
|
|
686
|
+
* TReturnValue — the typed handler return value consumed by `serializeReturn`.
|
|
687
|
+
*/
|
|
688
|
+
interface OracleRegistryEntry<
|
|
689
|
+
TDeserializedParams extends readonly NamedValue[] = readonly NamedValue[],
|
|
690
|
+
TReturnValue = any,
|
|
691
|
+
> {
|
|
692
|
+
/** Deserialize all ACVM inputs into named pairs in positional order. */
|
|
693
|
+
deserializeParams(inputs: InputSlot[]): TDeserializedParams;
|
|
694
|
+
/** Serialize a handler return value into ACVM output slots. */
|
|
695
|
+
serializeReturn(result: TReturnValue): OutputSlot[];
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function makeEntry<const TParams extends RegistryParam[] = [], TReturnValue = void>({
|
|
699
|
+
params,
|
|
700
|
+
returnType,
|
|
701
|
+
}: {
|
|
702
|
+
params?: [...TParams];
|
|
703
|
+
returnType?: TypeMapping<TReturnValue>;
|
|
704
|
+
} = {}): OracleRegistryEntry<InferDeserializedParams<TParams>, TReturnValue> {
|
|
705
|
+
return {
|
|
706
|
+
deserializeParams(inputs: InputSlot[]): InferDeserializedParams<TParams> {
|
|
707
|
+
const resolvedParams: RegistryParam[] = params ?? [];
|
|
708
|
+
// Walk the input slots left-to-right, advancing by each param's slot count.
|
|
709
|
+
let offset = 0;
|
|
710
|
+
return resolvedParams.map(param => {
|
|
711
|
+
if (!param.type.deserialization) {
|
|
712
|
+
throw new Error(`Param '${param.name}' has no deserialization defined`);
|
|
713
|
+
}
|
|
714
|
+
// Collect the slots for this param and wrap each in a FieldReader.
|
|
715
|
+
const slotCount = param.type.deserialization.slots;
|
|
716
|
+
const readers = inputs
|
|
717
|
+
.slice(offset, offset + slotCount)
|
|
718
|
+
.map(slot => new FieldReader(slot.map(hex => Fr.fromString(hex))));
|
|
719
|
+
offset += slotCount;
|
|
720
|
+
// Delegate to the TypeMapping's deserializer and tag the result with the param name.
|
|
721
|
+
return { name: param.name, value: param.type.deserialization.fn(readers) };
|
|
722
|
+
}) as unknown as InferDeserializedParams<TParams>;
|
|
723
|
+
},
|
|
724
|
+
serializeReturn(result: TReturnValue): OutputSlot[] {
|
|
725
|
+
if (returnType?.serialization === undefined) {
|
|
726
|
+
return [];
|
|
727
|
+
}
|
|
728
|
+
return returnType.serialization
|
|
729
|
+
.fn(result)
|
|
730
|
+
.map(slot => (Array.isArray(slot) ? slot.map(toACVMField) : toACVMField(slot)));
|
|
731
|
+
},
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/** `_height` is unused at runtime but lets TypeScript infer the exact `N` for `MembershipWitness<N>`. */
|
|
736
|
+
function MEMBERSHIP_WITNESS<N extends number>(_height: N): TypeMapping<MembershipWitness<N>> {
|
|
737
|
+
return {
|
|
738
|
+
serialization: {
|
|
739
|
+
fn: (witness: MembershipWitness<N>) => [new Fr(witness.leafIndex), [...witness.siblingPath]],
|
|
740
|
+
},
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function ARRAY<T>(element: TypeMapping<T>): TypeMapping<T[]> {
|
|
745
|
+
return {
|
|
746
|
+
serialization: element.serialization
|
|
747
|
+
? { fn: values => [values.flatMap(v => element.serialization!.fn(v).flat())] }
|
|
748
|
+
: undefined,
|
|
749
|
+
deserialization: element.deserialization
|
|
750
|
+
? {
|
|
751
|
+
fn: ([reader]) => {
|
|
752
|
+
const result: T[] = [];
|
|
753
|
+
while (!reader.isFinished()) {
|
|
754
|
+
result.push(element.deserialization!.fn([reader]));
|
|
755
|
+
}
|
|
756
|
+
return result;
|
|
757
|
+
},
|
|
758
|
+
slots: 1,
|
|
759
|
+
}
|
|
760
|
+
: undefined,
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Maps Noir's `BoundedVec<T, MaxLen>` ↔ TS `BoundedVec<T>` over 2 slots:
|
|
766
|
+
* slot 0 — flat storage, padded/parsed as `maxLength * elementSize` fields
|
|
767
|
+
* slot 1 — length scalar (count of actual items)
|
|
768
|
+
*
|
|
769
|
+
* Both directions are derived from `element`: bidirectional iff `element` has both serialization and deserialization.
|
|
770
|
+
*
|
|
771
|
+
* @example Serializing `BoundedVec.from({ data: [0x41, 0x42], maxLength: 4 })` with `BOUNDED_VEC(BYTE)`:
|
|
772
|
+
* ```
|
|
773
|
+
* slot 0: [Fr(0x41), Fr(0x42), Fr(0), Fr(0)] // data padded to maxLength
|
|
774
|
+
* slot 1: Fr(2) // actual length
|
|
775
|
+
* ```
|
|
776
|
+
*/
|
|
777
|
+
function BOUNDED_VEC<T>(element: TypeMapping<T>): TypeMapping<BoundedVec<T>> {
|
|
778
|
+
return {
|
|
779
|
+
serialization: element.serialization
|
|
780
|
+
? {
|
|
781
|
+
fn: bv => {
|
|
782
|
+
if (bv.data.length > bv.maxLength) {
|
|
783
|
+
throw new Error(`Got ${bv.data.length} items, but maxLength is ${bv.maxLength}`);
|
|
784
|
+
}
|
|
785
|
+
const flat = bv.data.flatMap(item => element.serialization!.fn(item).flat());
|
|
786
|
+
return [padArrayEnd(flat, Fr.ZERO, bv.maxLength * bv.elementSize), new Fr(bv.data.length)];
|
|
787
|
+
},
|
|
788
|
+
}
|
|
789
|
+
: undefined,
|
|
790
|
+
deserialization: element.deserialization
|
|
791
|
+
? {
|
|
792
|
+
fn: ([storageReader, lengthReader]) => {
|
|
793
|
+
const maxLength = storageReader.remainingFields();
|
|
794
|
+
const length = lengthReader.readField().toNumber();
|
|
795
|
+
const elements: T[] = [];
|
|
796
|
+
for (let i = 0; i < length; i++) {
|
|
797
|
+
elements.push(element.deserialization!.fn([storageReader]));
|
|
798
|
+
}
|
|
799
|
+
return BoundedVec.from<T>({ data: elements, maxLength });
|
|
800
|
+
},
|
|
801
|
+
slots: 2,
|
|
802
|
+
}
|
|
803
|
+
: undefined,
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Wraps an inner TypeMapping in Noir-style `Option<T>`. Adds a discriminant slot and uses the handler-provided
|
|
809
|
+
* `Option.none(shape)` template to produce a correctly-sized zero-filled output for the None case.
|
|
810
|
+
*
|
|
811
|
+
* @example Serializing `Option.some(AztecAddress.fromField(Fr(42)))` with `OPTION(AZTEC_ADDRESS)`:
|
|
812
|
+
* ```
|
|
813
|
+
* slot 0: Fr(1) // discriminant: Some
|
|
814
|
+
* slot 1: Fr(42) // inner value
|
|
815
|
+
* ```
|
|
816
|
+
*
|
|
817
|
+
* @example Serializing `Option.empty(AztecAddress.ZERO)` with `OPTION(AZTEC_ADDRESS)`:
|
|
818
|
+
* ```
|
|
819
|
+
* slot 0: Fr(0) // discriminant: None
|
|
820
|
+
* slot 1: Fr(0) // zero-filled using shape
|
|
821
|
+
* ```
|
|
822
|
+
*/
|
|
823
|
+
function OPTION<T>(inner: TypeMapping<T>): TypeMapping<Option<T>> {
|
|
824
|
+
return {
|
|
825
|
+
serialization: inner.serialization
|
|
826
|
+
? {
|
|
827
|
+
fn: opt => {
|
|
828
|
+
if (opt.isSome()) {
|
|
829
|
+
return [Fr.ONE, ...inner.serialization!.fn(opt.value)];
|
|
830
|
+
}
|
|
831
|
+
if (opt.template === undefined) {
|
|
832
|
+
throw new Error(
|
|
833
|
+
'Cannot serialize Option.empty() without an emptyTemplate — provide one via Option.empty(emptyTemplate)',
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
const zeroSlots = inner
|
|
837
|
+
.serialization!.fn(opt.template)
|
|
838
|
+
.map(s => (Array.isArray(s) ? Array(s.length).fill(Fr.ZERO) : Fr.ZERO));
|
|
839
|
+
return [Fr.ZERO, ...zeroSlots];
|
|
840
|
+
},
|
|
841
|
+
}
|
|
842
|
+
: undefined,
|
|
843
|
+
deserialization: inner.deserialization
|
|
844
|
+
? {
|
|
845
|
+
fn: readers => {
|
|
846
|
+
if (readers[0].readField().isZero()) {
|
|
847
|
+
return Option.none<T>(undefined as unknown as T);
|
|
848
|
+
}
|
|
849
|
+
return Option.some(inner.deserialization!.fn(readers.slice(1)));
|
|
850
|
+
},
|
|
851
|
+
slots: inner.deserialization.slots + 1,
|
|
852
|
+
}
|
|
853
|
+
: undefined,
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** A packed uint buffer (e.g. `[u8; N]` in Noir): 1 slot of packed uint values ↔ `Buffer`. */
|
|
858
|
+
function BUFFER(bitSize: number): TypeMapping<Buffer> {
|
|
859
|
+
return {
|
|
860
|
+
serialization: {
|
|
861
|
+
fn: buf => [Array.from(buf).map(b => new Fr(b))],
|
|
862
|
+
},
|
|
863
|
+
deserialization: {
|
|
864
|
+
fn: ([reader]) => {
|
|
865
|
+
const fields = reader.readFieldArray(reader.remainingFields()).map(f => f.toString());
|
|
866
|
+
return fromUintArray(fields, bitSize);
|
|
867
|
+
},
|
|
868
|
+
slots: 1,
|
|
869
|
+
},
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/** A named oracle parameter with its TypeMapping. */
|
|
874
|
+
interface RegistryParam<TName extends string = string, T = any> {
|
|
875
|
+
name: TName;
|
|
876
|
+
type: TypeMapping<T>;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/** One named param entry from a deserializeParams result. */
|
|
880
|
+
type NamedValue<TName extends string = string, TValue = any> = { readonly name: TName; readonly value: TValue };
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Extracts the positional type tuple from a {@link OracleRegistryEntry.deserializeParams} result,
|
|
884
|
+
* stripping names to produce the handler's argument types.
|
|
885
|
+
*
|
|
886
|
+
* @example `ParamTypes<[NamedValue<'addr', AztecAddress>, NamedValue<'slot', Fr>]>` → `[AztecAddress, Fr]`
|
|
887
|
+
*/
|
|
888
|
+
type ParamTypes<T extends readonly NamedValue[]> = {
|
|
889
|
+
[K in keyof T]: T[K] extends NamedValue<string, infer V> ? V : never;
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Maps a registry entry's `params` declaration to the return type of
|
|
894
|
+
* {@link OracleRegistryEntry.deserializeParams}: each `RegistryParam<Name, Type>` becomes a
|
|
895
|
+
* `NamedValue<Name, Type>` at the same position.
|
|
896
|
+
*
|
|
897
|
+
* @example `InferDeserializedParams<[RegistryParam<'addr', AztecAddress>, RegistryParam<'slot', Fr>]>`
|
|
898
|
+
* → `[NamedValue<'addr', AztecAddress>, NamedValue<'slot', Fr>]`
|
|
899
|
+
*/
|
|
900
|
+
type InferDeserializedParams<T extends RegistryParam[]> = {
|
|
901
|
+
[K in keyof T]: T[K] extends RegistryParam<infer N, infer V> ? NamedValue<N, V> : never;
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
type MaybePromise<T> = T | Promise<T>;
|