@aztec/pxe 0.0.0-test.1 → 0.0.1-commit.24de95ac
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/README.md +5 -5
- package/dest/bin/check_oracle_version.d.ts +2 -0
- package/dest/bin/check_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_oracle_version.js +39 -0
- package/dest/config/index.d.ts +10 -15
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +11 -20
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +56 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
- package/dest/contract_function_simulator/contract_function_simulator.js +301 -0
- package/dest/contract_function_simulator/execution_data_provider.d.ts +274 -0
- package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_data_provider.js +14 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts +93 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_note_cache.js +183 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
- package/dest/contract_function_simulator/index.d.ts +14 -0
- package/dest/contract_function_simulator/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/index.js +12 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +20 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +37 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +15 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +25 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +17 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +65 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +22 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +42 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
- package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
- package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/index.js +2 -0
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +97 -0
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +19 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +22 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +49 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +57 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/oracle.js +328 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +48 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution.js +123 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +236 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +417 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +154 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +265 -0
- package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
- package/dest/contract_function_simulator/pick_notes.js +51 -0
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +6 -0
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -0
- package/dest/contract_function_simulator/proxied_contract_data_source.js +62 -0
- package/dest/contract_function_simulator/proxied_node.d.ts +9 -0
- package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/proxied_node.js +27 -0
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +122 -0
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -0
- package/dest/contract_function_simulator/pxe_oracle_interface.js +701 -0
- package/dest/entrypoints/client/bundle/index.d.ts +4 -2
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -2
- package/dest/entrypoints/client/bundle/utils.d.ts +9 -9
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +18 -12
- package/dest/entrypoints/client/lazy/index.d.ts +4 -2
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -2
- package/dest/entrypoints/client/lazy/utils.d.ts +8 -8
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +17 -11
- package/dest/entrypoints/{client/pxe_creation_options.d.ts → pxe_creation_options.d.ts} +4 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
- package/dest/entrypoints/server/index.d.ts +5 -3
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +4 -3
- package/dest/entrypoints/server/utils.d.ts +7 -15
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +34 -28
- package/dest/{pxe_service/error_enriching.d.ts → error_enriching.d.ts} +1 -1
- package/dest/error_enriching.d.ts.map +1 -0
- package/dest/{pxe_service/error_enriching.js → error_enriching.js} +26 -18
- package/dest/oracle_version.d.ts +3 -0
- package/dest/oracle_version.d.ts.map +1 -0
- package/dest/oracle_version.js +10 -0
- package/dest/{kernel_prover → private_kernel}/hints/build_private_kernel_reset_private_inputs.d.ts +6 -6
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -0
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +271 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
- package/dest/private_kernel/hints/index.d.ts +3 -0
- package/dest/private_kernel/hints/index.d.ts.map +1 -0
- package/dest/{kernel_prover → private_kernel}/hints/index.js +1 -0
- package/dest/private_kernel/index.d.ts +3 -0
- package/dest/private_kernel/index.d.ts.map +1 -0
- package/dest/private_kernel/index.js +2 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +44 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -0
- package/dest/private_kernel/private_kernel_execution_prover.js +285 -0
- package/dest/{kernel_prover/proving_data_oracle.d.ts → private_kernel/private_kernel_oracle.d.ts} +17 -28
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -0
- package/dest/private_kernel/private_kernel_oracle.js +4 -0
- package/dest/{kernel_oracle/index.d.ts → private_kernel/private_kernel_oracle_impl.d.ts} +8 -8
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -0
- package/dest/{kernel_oracle/index.js → private_kernel/private_kernel_oracle_impl.js} +19 -9
- package/dest/pxe.d.ts +233 -0
- package/dest/pxe.d.ts.map +1 -0
- package/dest/pxe.js +789 -0
- package/dest/storage/address_data_provider/address_data_provider.d.ts +1 -3
- package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -1
- package/dest/storage/address_data_provider/address_data_provider.js +0 -3
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +14 -5
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.js +85 -24
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts +12 -47
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
- package/dest/storage/contract_data_provider/contract_data_provider.js +92 -70
- package/dest/storage/contract_data_provider/index.d.ts +0 -1
- package/dest/storage/contract_data_provider/index.d.ts.map +1 -1
- package/dest/storage/contract_data_provider/index.js +0 -1
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts +2 -41
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -1
- package/dest/storage/contract_data_provider/private_functions_tree.js +9 -61
- package/dest/storage/index.d.ts +2 -3
- package/dest/storage/index.d.ts.map +1 -1
- package/dest/storage/index.js +2 -3
- package/dest/storage/metadata.d.ts +2 -0
- package/dest/storage/metadata.d.ts.map +1 -0
- package/dest/storage/metadata.js +1 -0
- package/dest/storage/note_data_provider/note_dao.d.ts +16 -22
- package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -1
- package/dest/storage/note_data_provider/note_dao.js +16 -20
- package/dest/storage/note_data_provider/note_data_provider.d.ts +71 -8
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
- package/dest/storage/note_data_provider/note_data_provider.js +133 -74
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +43 -0
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -0
- package/dest/storage/private_event_data_provider/private_event_data_provider.js +104 -0
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts +2 -4
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -1
- package/dest/storage/sync_data_provider/sync_data_provider.js +2 -5
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +28 -6
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.js +48 -24
- package/dest/synchronizer/synchronizer.d.ts +7 -9
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +17 -19
- package/dest/tagging/constants.d.ts +2 -0
- package/dest/tagging/constants.d.ts.map +1 -0
- package/dest/tagging/constants.js +2 -0
- package/dest/tagging/index.d.ts +7 -0
- package/dest/tagging/index.d.ts.map +1 -0
- package/dest/tagging/index.js +5 -0
- package/dest/tagging/siloed_tag.d.ts +14 -0
- package/dest/tagging/siloed_tag.d.ts.map +1 -0
- package/dest/tagging/siloed_tag.js +20 -0
- package/dest/tagging/tag.d.ts +12 -0
- package/dest/tagging/tag.d.ts.map +1 -0
- package/dest/tagging/tag.js +17 -0
- package/dest/tagging/utils.d.ts +18 -0
- package/dest/tagging/utils.d.ts.map +1 -0
- package/dest/tagging/utils.js +24 -0
- package/package.json +34 -32
- package/src/bin/check_oracle_version.ts +50 -0
- package/src/config/index.ts +20 -33
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +548 -0
- package/src/contract_function_simulator/execution_data_provider.ts +343 -0
- package/src/contract_function_simulator/execution_note_cache.ts +222 -0
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
- package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
- package/src/contract_function_simulator/index.ts +13 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +47 -0
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +27 -0
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +69 -0
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +52 -0
- package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
- package/src/contract_function_simulator/oracle/index.ts +16 -0
- package/src/contract_function_simulator/oracle/interfaces.ts +160 -0
- package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +52 -0
- package/src/contract_function_simulator/oracle/oracle.ts +575 -0
- package/src/contract_function_simulator/oracle/private_execution.ts +207 -0
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +625 -0
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +358 -0
- package/src/contract_function_simulator/pick_notes.ts +141 -0
- package/src/contract_function_simulator/proxied_contract_data_source.ts +66 -0
- package/src/contract_function_simulator/proxied_node.ts +33 -0
- package/src/contract_function_simulator/pxe_oracle_interface.ts +1019 -0
- package/src/entrypoints/client/bundle/index.ts +4 -2
- package/src/entrypoints/client/bundle/utils.ts +36 -36
- package/src/entrypoints/client/lazy/index.ts +4 -2
- package/src/entrypoints/client/lazy/utils.ts +36 -31
- package/src/entrypoints/{client/pxe_creation_options.ts → pxe_creation_options.ts} +4 -1
- package/src/entrypoints/server/index.ts +5 -3
- package/src/entrypoints/server/utils.ts +69 -47
- package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +36 -27
- package/src/oracle_version.ts +11 -0
- package/src/{kernel_prover → private_kernel}/hints/build_private_kernel_reset_private_inputs.ts +158 -142
- package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
- package/src/{kernel_prover → private_kernel}/hints/index.ts +1 -0
- package/src/private_kernel/index.ts +2 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +436 -0
- package/src/{kernel_prover/proving_data_oracle.ts → private_kernel/private_kernel_oracle.ts} +17 -29
- package/src/{kernel_oracle/index.ts → private_kernel/private_kernel_oracle_impl.ts} +30 -15
- package/src/pxe.ts +1113 -0
- package/src/storage/address_data_provider/address_data_provider.ts +1 -7
- package/src/storage/capsule_data_provider/capsule_data_provider.ts +97 -30
- package/src/storage/contract_data_provider/contract_data_provider.ts +114 -81
- package/src/storage/contract_data_provider/index.ts +0 -1
- package/src/storage/contract_data_provider/private_functions_tree.ts +11 -75
- package/src/storage/index.ts +2 -4
- package/src/storage/metadata.ts +1 -0
- package/src/storage/note_data_provider/note_dao.ts +19 -27
- package/src/storage/note_data_provider/note_data_provider.ts +161 -113
- package/src/storage/private_event_data_provider/private_event_data_provider.ts +148 -0
- package/src/storage/sync_data_provider/sync_data_provider.ts +4 -10
- package/src/storage/tagging_data_provider/tagging_data_provider.ts +58 -30
- package/src/synchronizer/synchronizer.ts +21 -22
- package/src/tagging/constants.ts +2 -0
- package/src/tagging/index.ts +6 -0
- package/src/tagging/siloed_tag.ts +22 -0
- package/src/tagging/tag.ts +16 -0
- package/src/tagging/utils.ts +31 -0
- package/dest/bin/index.d.ts +0 -3
- package/dest/bin/index.d.ts.map +0 -1
- package/dest/bin/index.js +0 -28
- package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
- package/dest/kernel_oracle/index.d.ts.map +0 -1
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +0 -270
- package/dest/kernel_prover/hints/index.d.ts +0 -2
- package/dest/kernel_prover/hints/index.d.ts.map +0 -1
- package/dest/kernel_prover/index.d.ts +0 -3
- package/dest/kernel_prover/index.d.ts.map +0 -1
- package/dest/kernel_prover/index.js +0 -2
- package/dest/kernel_prover/kernel_prover.d.ts +0 -38
- package/dest/kernel_prover/kernel_prover.d.ts.map +0 -1
- package/dest/kernel_prover/kernel_prover.js +0 -217
- package/dest/kernel_prover/proving_data_oracle.d.ts.map +0 -1
- package/dest/kernel_prover/proving_data_oracle.js +0 -4
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +0 -11
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +0 -1
- package/dest/note_decryption_utils/add_public_values_to_payload.js +0 -47
- package/dest/pxe_http/index.d.ts +0 -2
- package/dest/pxe_http/index.d.ts.map +0 -1
- package/dest/pxe_http/index.js +0 -1
- package/dest/pxe_http/pxe_http_server.d.ts +0 -16
- package/dest/pxe_http/pxe_http_server.d.ts.map +0 -1
- package/dest/pxe_http/pxe_http_server.js +0 -27
- package/dest/pxe_oracle_interface/index.d.ts +0 -159
- package/dest/pxe_oracle_interface/index.d.ts.map +0 -1
- package/dest/pxe_oracle_interface/index.js +0 -692
- package/dest/pxe_oracle_interface/tagging_utils.d.ts +0 -17
- package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
- package/dest/pxe_oracle_interface/tagging_utils.js +0 -23
- package/dest/pxe_service/error_enriching.d.ts.map +0 -1
- package/dest/pxe_service/index.d.ts +0 -3
- package/dest/pxe_service/index.d.ts.map +0 -1
- package/dest/pxe_service/index.js +0 -2
- package/dest/pxe_service/pxe_service.d.ts +0 -111
- package/dest/pxe_service/pxe_service.d.ts.map +0 -1
- package/dest/pxe_service/pxe_service.js +0 -664
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts +0 -11
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +0 -1
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +0 -20
- package/dest/storage/auth_witness_data_provider/index.d.ts +0 -2
- package/dest/storage/auth_witness_data_provider/index.d.ts.map +0 -1
- package/dest/storage/auth_witness_data_provider/index.js +0 -1
- package/dest/storage/data_provider.d.ts +0 -4
- package/dest/storage/data_provider.d.ts.map +0 -1
- package/dest/storage/data_provider.js +0 -1
- package/dest/test/pxe_test_suite.d.ts +0 -3
- package/dest/test/pxe_test_suite.d.ts.map +0 -1
- package/dest/test/pxe_test_suite.js +0 -97
- package/src/bin/index.ts +0 -38
- package/src/kernel_prover/index.ts +0 -2
- package/src/kernel_prover/kernel_prover.ts +0 -351
- package/src/note_decryption_utils/add_public_values_to_payload.ts +0 -64
- package/src/pxe_http/index.ts +0 -1
- package/src/pxe_http/pxe_http_server.ts +0 -29
- package/src/pxe_oracle_interface/index.ts +0 -925
- package/src/pxe_oracle_interface/tagging_utils.ts +0 -32
- package/src/pxe_service/index.ts +0 -2
- package/src/pxe_service/pxe_service.ts +0 -949
- package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +0 -34
- package/src/storage/auth_witness_data_provider/index.ts +0 -1
- package/src/storage/data_provider.ts +0 -3
- package/src/test/pxe_test_suite.ts +0 -111
- /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
|
|
2
2
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
3
3
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
-
import type { NoteData } from '@aztec/simulator/client';
|
|
5
|
-
import { NoteSelector } from '@aztec/stdlib/abi';
|
|
6
4
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
-
import type { PublicKey } from '@aztec/stdlib/keys';
|
|
8
5
|
import { Note } from '@aztec/stdlib/note';
|
|
9
6
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
10
7
|
|
|
8
|
+
import type { NoteData } from '../../contract_function_simulator/oracle/interfaces.js';
|
|
9
|
+
|
|
11
10
|
/**
|
|
12
11
|
* A Note Data Access Object, representing a note that was committed to the note hash tree, holding all of the
|
|
13
12
|
* information required to use it during execution and manage its state.
|
|
@@ -23,10 +22,10 @@ export class NoteDao implements NoteData {
|
|
|
23
22
|
/**
|
|
24
23
|
* The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
|
|
25
24
|
* since contracts typically make queries based on it.
|
|
26
|
-
|
|
25
|
+
*/
|
|
27
26
|
public storageSlot: Fr,
|
|
28
|
-
/** The
|
|
29
|
-
public
|
|
27
|
+
/** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
|
|
28
|
+
public noteNonce: Fr,
|
|
30
29
|
|
|
31
30
|
// Computed values
|
|
32
31
|
/**
|
|
@@ -53,13 +52,11 @@ export class NoteDao implements NoteData {
|
|
|
53
52
|
public l2BlockHash: string,
|
|
54
53
|
/** The index of the leaf in the global note hash tree the note is stored at */
|
|
55
54
|
public index: bigint,
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
/** The note type identifier for the contract.
|
|
60
|
-
* TODO(#12013): remove
|
|
55
|
+
/**
|
|
56
|
+
* The address whose public key was used to encrypt the note log during delivery.
|
|
57
|
+
* (This is the x-coordinate of the public key.)
|
|
61
58
|
*/
|
|
62
|
-
public
|
|
59
|
+
public recipient: AztecAddress,
|
|
63
60
|
) {}
|
|
64
61
|
|
|
65
62
|
toBuffer(): Buffer {
|
|
@@ -67,15 +64,14 @@ export class NoteDao implements NoteData {
|
|
|
67
64
|
this.note,
|
|
68
65
|
this.contractAddress,
|
|
69
66
|
this.storageSlot,
|
|
70
|
-
this.
|
|
67
|
+
this.noteNonce,
|
|
71
68
|
this.noteHash,
|
|
72
69
|
this.siloedNullifier,
|
|
73
70
|
this.txHash,
|
|
74
71
|
this.l2BlockNumber,
|
|
75
72
|
Fr.fromHexString(this.l2BlockHash),
|
|
76
73
|
this.index,
|
|
77
|
-
this.
|
|
78
|
-
this.noteTypeId,
|
|
74
|
+
this.recipient,
|
|
79
75
|
]);
|
|
80
76
|
}
|
|
81
77
|
|
|
@@ -85,29 +81,27 @@ export class NoteDao implements NoteData {
|
|
|
85
81
|
const note = Note.fromBuffer(reader);
|
|
86
82
|
const contractAddress = AztecAddress.fromBuffer(reader);
|
|
87
83
|
const storageSlot = Fr.fromBuffer(reader);
|
|
88
|
-
const
|
|
84
|
+
const noteNonce = Fr.fromBuffer(reader);
|
|
89
85
|
const noteHash = Fr.fromBuffer(reader);
|
|
90
86
|
const siloedNullifier = Fr.fromBuffer(reader);
|
|
91
87
|
const txHash = reader.readObject(TxHash);
|
|
92
88
|
const l2BlockNumber = reader.readNumber();
|
|
93
89
|
const l2BlockHash = Fr.fromBuffer(reader).toString();
|
|
94
90
|
const index = toBigIntBE(reader.readBytes(32));
|
|
95
|
-
const
|
|
96
|
-
const noteTypeId = reader.readObject(NoteSelector);
|
|
91
|
+
const recipient = AztecAddress.fromBuffer(reader);
|
|
97
92
|
|
|
98
93
|
return new NoteDao(
|
|
99
94
|
note,
|
|
100
95
|
contractAddress,
|
|
101
96
|
storageSlot,
|
|
102
|
-
|
|
97
|
+
noteNonce,
|
|
103
98
|
noteHash,
|
|
104
99
|
siloedNullifier,
|
|
105
100
|
txHash,
|
|
106
101
|
l2BlockNumber,
|
|
107
102
|
l2BlockHash,
|
|
108
103
|
index,
|
|
109
|
-
|
|
110
|
-
noteTypeId,
|
|
104
|
+
recipient,
|
|
111
105
|
);
|
|
112
106
|
}
|
|
113
107
|
|
|
@@ -134,29 +128,27 @@ export class NoteDao implements NoteData {
|
|
|
134
128
|
note = Note.random(),
|
|
135
129
|
contractAddress = undefined,
|
|
136
130
|
storageSlot = Fr.random(),
|
|
137
|
-
|
|
131
|
+
noteNonce = Fr.random(),
|
|
138
132
|
noteHash = Fr.random(),
|
|
139
133
|
siloedNullifier = Fr.random(),
|
|
140
134
|
txHash = TxHash.random(),
|
|
141
135
|
l2BlockNumber = Math.floor(Math.random() * 1000),
|
|
142
136
|
l2BlockHash = Fr.random().toString(),
|
|
143
137
|
index = Fr.random().toBigInt(),
|
|
144
|
-
|
|
145
|
-
noteTypeId = NoteSelector.random(),
|
|
138
|
+
recipient = undefined,
|
|
146
139
|
}: Partial<NoteDao> = {}) {
|
|
147
140
|
return new NoteDao(
|
|
148
141
|
note,
|
|
149
142
|
contractAddress ?? (await AztecAddress.random()),
|
|
150
143
|
storageSlot,
|
|
151
|
-
|
|
144
|
+
noteNonce,
|
|
152
145
|
noteHash,
|
|
153
146
|
siloedNullifier,
|
|
154
147
|
txHash,
|
|
155
148
|
l2BlockNumber,
|
|
156
149
|
l2BlockHash,
|
|
157
150
|
index,
|
|
158
|
-
|
|
159
|
-
noteTypeId,
|
|
151
|
+
recipient ?? (await AztecAddress.random()),
|
|
160
152
|
);
|
|
161
153
|
}
|
|
162
154
|
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
2
|
-
import type { Fr
|
|
2
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
4
4
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
5
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
import type { InBlock } from '@aztec/stdlib/block';
|
|
7
|
-
import type { PublicKey } from '@aztec/stdlib/keys';
|
|
8
7
|
import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
|
|
9
8
|
|
|
10
|
-
import type { DataProvider } from '../data_provider.js';
|
|
11
9
|
import { NoteDao } from './note_dao.js';
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* NoteDataProvider manages the storage and retrieval of notes.
|
|
13
|
+
*
|
|
14
|
+
* Notes can be active or nullified. This class processes new notes, nullifications,
|
|
15
|
+
* and performs rollback handling in the case of a reorg.
|
|
16
|
+
**/
|
|
17
|
+
export class NoteDataProvider {
|
|
14
18
|
#store: AztecAsyncKVStore;
|
|
15
|
-
|
|
16
19
|
#notes: AztecAsyncMap<string, Buffer>;
|
|
17
20
|
#nullifiedNotes: AztecAsyncMap<string, Buffer>;
|
|
18
21
|
#nullifierToNoteId: AztecAsyncMap<string, string>;
|
|
@@ -21,16 +24,12 @@ export class NoteDataProvider implements DataProvider {
|
|
|
21
24
|
#nullifiedNotesToScope: AztecAsyncMultiMap<string, string>;
|
|
22
25
|
#nullifiedNotesByContract: AztecAsyncMultiMap<string, string>;
|
|
23
26
|
#nullifiedNotesByStorageSlot: AztecAsyncMultiMap<string, string>;
|
|
24
|
-
#nullifiedNotesByTxHash: AztecAsyncMultiMap<string, string>;
|
|
25
|
-
#nullifiedNotesByAddressPoint: AztecAsyncMultiMap<string, string>;
|
|
26
27
|
#nullifiedNotesByNullifier: AztecAsyncMap<string, string>;
|
|
27
28
|
|
|
28
29
|
#scopes: AztecAsyncMap<string, true>;
|
|
29
30
|
#notesToScope: AztecAsyncMultiMap<string, string>;
|
|
30
31
|
#notesByContractAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
31
32
|
#notesByStorageSlotAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
32
|
-
#notesByTxHashAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
33
|
-
#notesByAddressPointAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
34
33
|
|
|
35
34
|
private constructor(store: AztecAsyncKVStore) {
|
|
36
35
|
this.#store = store;
|
|
@@ -42,29 +41,41 @@ export class NoteDataProvider implements DataProvider {
|
|
|
42
41
|
this.#nullifiedNotesToScope = store.openMultiMap('nullified_notes_to_scope');
|
|
43
42
|
this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
|
|
44
43
|
this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
|
|
45
|
-
this.#nullifiedNotesByTxHash = store.openMultiMap('nullified_notes_by_tx_hash');
|
|
46
|
-
this.#nullifiedNotesByAddressPoint = store.openMultiMap('nullified_notes_by_address_point');
|
|
47
44
|
this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
|
|
48
45
|
|
|
49
46
|
this.#scopes = store.openMap('scopes');
|
|
50
47
|
this.#notesToScope = store.openMultiMap('notes_to_scope');
|
|
51
48
|
this.#notesByContractAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
52
49
|
this.#notesByStorageSlotAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
53
|
-
this.#notesByTxHashAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
54
|
-
this.#notesByAddressPointAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
55
50
|
}
|
|
56
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Creates and initializes a new NoteDataProvider instance.
|
|
54
|
+
*
|
|
55
|
+
* This factory method creates a NoteDataProvider and restores any existing
|
|
56
|
+
* scope-specific indexes from the database.
|
|
57
|
+
*
|
|
58
|
+
* @param store - The key-value store to use for persistence
|
|
59
|
+
* @returns Promise resolving to a fully initialized NoteDataProvider instance
|
|
60
|
+
*/
|
|
57
61
|
public static async create(store: AztecAsyncKVStore): Promise<NoteDataProvider> {
|
|
58
62
|
const pxeDB = new NoteDataProvider(store);
|
|
59
63
|
for await (const scope of pxeDB.#scopes.keysAsync()) {
|
|
60
64
|
pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
|
|
61
65
|
pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
|
|
62
|
-
pxeDB.#notesByTxHashAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_tx_hash`));
|
|
63
|
-
pxeDB.#notesByAddressPointAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_address_point`));
|
|
64
66
|
}
|
|
65
67
|
return pxeDB;
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Adds a new scope to the note data provider.
|
|
72
|
+
*
|
|
73
|
+
* Scopes provide privacy isolation by creating separate indexes for each user.
|
|
74
|
+
* Each scope gets its own set of indexes for efficient note retrieval by various criteria.
|
|
75
|
+
*
|
|
76
|
+
* @param scope - The AztecAddress representing the scope/user to add
|
|
77
|
+
* @returns Promise resolving to true if scope was added, false if it already existed
|
|
78
|
+
*/
|
|
68
79
|
public async addScope(scope: AztecAddress): Promise<boolean> {
|
|
69
80
|
const scopeString = scope.toString();
|
|
70
81
|
|
|
@@ -75,26 +86,27 @@ export class NoteDataProvider implements DataProvider {
|
|
|
75
86
|
await this.#scopes.set(scopeString, true);
|
|
76
87
|
this.#notesByContractAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_contract`));
|
|
77
88
|
this.#notesByStorageSlotAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_storage_slot`));
|
|
78
|
-
this.#notesByTxHashAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_tx_hash`));
|
|
79
|
-
this.#notesByAddressPointAndScope.set(
|
|
80
|
-
scopeString,
|
|
81
|
-
this.#store.openMultiMap(`${scopeString}:notes_by_address_point`),
|
|
82
|
-
);
|
|
83
89
|
|
|
84
90
|
return true;
|
|
85
91
|
}
|
|
86
92
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Adds multiple notes to the data provider under the specified scope.
|
|
95
|
+
*
|
|
96
|
+
* Notes are stored using their index from the notes hash tree as the key, which provides
|
|
97
|
+
* uniqueness and maintains creation order. Each note is indexed by multiple criteria
|
|
98
|
+
* for efficient retrieval.
|
|
99
|
+
*
|
|
100
|
+
* @param notes - Notes to store
|
|
101
|
+
* @param scope - The scope (user/account) under which to store the notes
|
|
102
|
+
*/
|
|
103
|
+
addNotes(notes: NoteDao[], scope: AztecAddress): Promise<void> {
|
|
92
104
|
return this.#store.transactionAsync(async () => {
|
|
105
|
+
if (!(await this.#scopes.hasAsync(scope.toString()))) {
|
|
106
|
+
await this.addScope(scope);
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
for (const dao of notes) {
|
|
94
|
-
// store notes by their index in the notes hash tree
|
|
95
|
-
// this provides the uniqueness we need to store individual notes
|
|
96
|
-
// and should also return notes in the order that they were created.
|
|
97
|
-
// Had we stored them by their nullifier, they would be returned in random order
|
|
98
110
|
const noteIndex = toBufferBE(dao.index, 32).toString('hex');
|
|
99
111
|
await this.#notes.set(noteIndex, dao.toBuffer());
|
|
100
112
|
await this.#notesToScope.set(noteIndex, scope.toString());
|
|
@@ -102,13 +114,34 @@ export class NoteDataProvider implements DataProvider {
|
|
|
102
114
|
|
|
103
115
|
await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
|
|
104
116
|
await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
|
|
105
|
-
await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
|
|
106
|
-
await this.#notesByAddressPointAndScope.get(scope.toString())!.set(dao.addressPoint.toString(), noteIndex);
|
|
107
117
|
}
|
|
108
118
|
});
|
|
109
119
|
}
|
|
110
120
|
|
|
111
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Synchronizes notes and nullifiers to a specific block number.
|
|
123
|
+
*
|
|
124
|
+
* This method ensures that the state of notes and nullifiers is consistent with the
|
|
125
|
+
* specified block number. It restores any notes that were nullified after the given block
|
|
126
|
+
* and deletes any active notes created after that block.
|
|
127
|
+
*
|
|
128
|
+
* @param blockNumber - The new chain tip after a reorg
|
|
129
|
+
* @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
|
|
130
|
+
*/
|
|
131
|
+
public async rollbackNotesAndNullifiers(blockNumber: number, synchedBlockNumber: number): Promise<void> {
|
|
132
|
+
await this.#rewindNullifiersAfterBlock(blockNumber, synchedBlockNumber);
|
|
133
|
+
await this.#deleteActiveNotesAfterBlock(blockNumber);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Deletes (removes) all active notes created after the specified block number.
|
|
138
|
+
*
|
|
139
|
+
* Permanently delete notes from the active notes store, e.g. during a reorg.
|
|
140
|
+
* Note: This only affects #notes (active notes), not #nullifiedNotes.
|
|
141
|
+
*
|
|
142
|
+
* @param blockNumber - Notes created after this block number will be deleted
|
|
143
|
+
*/
|
|
144
|
+
#deleteActiveNotesAfterBlock(blockNumber: number): Promise<void> {
|
|
112
145
|
return this.#store.transactionAsync(async () => {
|
|
113
146
|
const notes = await toArray(this.#notes.valuesAsync());
|
|
114
147
|
for (const note of notes) {
|
|
@@ -120,8 +153,6 @@ export class NoteDataProvider implements DataProvider {
|
|
|
120
153
|
await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
|
|
121
154
|
const scopes = await toArray(this.#scopes.keysAsync());
|
|
122
155
|
for (const scope of scopes) {
|
|
123
|
-
await this.#notesByAddressPointAndScope.get(scope)!.deleteValue(noteDao.addressPoint.toString(), noteIndex);
|
|
124
|
-
await this.#notesByTxHashAndScope.get(scope)!.deleteValue(noteDao.txHash.toString(), noteIndex);
|
|
125
156
|
await this.#notesByContractAndScope.get(scope)!.deleteValue(noteDao.contractAddress.toString(), noteIndex);
|
|
126
157
|
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(noteDao.storageSlot.toString(), noteIndex);
|
|
127
158
|
}
|
|
@@ -130,25 +161,34 @@ export class NoteDataProvider implements DataProvider {
|
|
|
130
161
|
});
|
|
131
162
|
}
|
|
132
163
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const nullifiedNoteBuffers = await Promise.all(
|
|
145
|
-
notNullNoteIndexes.map(noteIndex => this.#nullifiedNotes.getAsync(noteIndex!)),
|
|
146
|
-
);
|
|
147
|
-
const noteDaos = nullifiedNoteBuffers
|
|
148
|
-
.filter(buffer => buffer != undefined)
|
|
149
|
-
.map(buffer => NoteDao.fromBuffer(buffer!));
|
|
150
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Rewinds nullifications after a given block number.
|
|
166
|
+
*
|
|
167
|
+
* This operation "unnullifies" notes, rolling back nullifications that occurred
|
|
168
|
+
* in orphaned blocks, e.g. during a reorg. The notes are restored to the
|
|
169
|
+
* active notes store and removed from the nullified store.
|
|
170
|
+
*
|
|
171
|
+
* @param blockNumber - Revert nullifications that occurred after this block
|
|
172
|
+
* @param synchedBlockNumber - Upper bound for the block range to process
|
|
173
|
+
*/
|
|
174
|
+
async #rewindNullifiersAfterBlock(blockNumber: number, synchedBlockNumber: number): Promise<void> {
|
|
151
175
|
await this.#store.transactionAsync(async () => {
|
|
176
|
+
const nullifiersToUndo: string[] = [];
|
|
177
|
+
const currentBlockNumber = blockNumber + 1;
|
|
178
|
+
for (let i = currentBlockNumber; i <= synchedBlockNumber; i++) {
|
|
179
|
+
nullifiersToUndo.push(...(await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i))));
|
|
180
|
+
}
|
|
181
|
+
const notesIndexesToReinsert = await Promise.all(
|
|
182
|
+
nullifiersToUndo.map(nullifier => this.#nullifiedNotesByNullifier.getAsync(nullifier)),
|
|
183
|
+
);
|
|
184
|
+
const notNullNoteIndexes = notesIndexesToReinsert.filter(noteIndex => noteIndex != undefined);
|
|
185
|
+
const nullifiedNoteBuffers = await Promise.all(
|
|
186
|
+
notNullNoteIndexes.map(noteIndex => this.#nullifiedNotes.getAsync(noteIndex!)),
|
|
187
|
+
);
|
|
188
|
+
const noteDaos = nullifiedNoteBuffers
|
|
189
|
+
.filter(buffer => buffer != undefined)
|
|
190
|
+
.map(buffer => NoteDao.fromBuffer(buffer!));
|
|
191
|
+
|
|
152
192
|
for (const dao of noteDaos) {
|
|
153
193
|
const noteIndex = toBufferBE(dao.index, 32).toString('hex');
|
|
154
194
|
await this.#notes.set(noteIndex, dao.toBuffer());
|
|
@@ -157,14 +197,12 @@ export class NoteDataProvider implements DataProvider {
|
|
|
157
197
|
let scopes = (await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex))) ?? [];
|
|
158
198
|
|
|
159
199
|
if (scopes.length === 0) {
|
|
160
|
-
scopes = [
|
|
200
|
+
scopes = [dao.recipient.toString()];
|
|
161
201
|
}
|
|
162
202
|
|
|
163
203
|
for (const scope of scopes) {
|
|
164
204
|
await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
|
|
165
205
|
await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
|
|
166
|
-
await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
|
|
167
|
-
await this.#notesByAddressPointAndScope.get(scope.toString())!.set(dao.addressPoint.toString(), noteIndex);
|
|
168
206
|
await this.#notesToScope.set(noteIndex, scope);
|
|
169
207
|
}
|
|
170
208
|
|
|
@@ -173,18 +211,32 @@ export class NoteDataProvider implements DataProvider {
|
|
|
173
211
|
await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
|
|
174
212
|
await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
|
|
175
213
|
await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
|
|
176
|
-
await this.#nullifiedNotesByTxHash.deleteValue(dao.txHash.toString(), noteIndex);
|
|
177
|
-
await this.#nullifiedNotesByAddressPoint.deleteValue(dao.addressPoint.toString(), noteIndex);
|
|
178
214
|
await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
|
|
179
215
|
}
|
|
180
216
|
});
|
|
181
217
|
}
|
|
182
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Retrieves notes based on the provided filter criteria.
|
|
221
|
+
*
|
|
222
|
+
* This method queries both active and optionally nullified notes based on the filter
|
|
223
|
+
* parameters.
|
|
224
|
+
*
|
|
225
|
+
* @param filter - Filter criteria including contractAddress (required), and optional
|
|
226
|
+
* storageSlot, status, scopes and siloedNullifier.
|
|
227
|
+
* @returns Promise resolving to array of NoteDao objects matching the filter
|
|
228
|
+
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
229
|
+
*/
|
|
183
230
|
async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
184
|
-
const publicKey: PublicKey | undefined = filter.owner ? await filter.owner.toAddressPoint() : undefined;
|
|
185
|
-
|
|
186
231
|
filter.status = filter.status ?? NoteStatus.ACTIVE;
|
|
187
232
|
|
|
233
|
+
// throw early if scopes is an empty array
|
|
234
|
+
if (filter.scopes !== undefined && filter.scopes.length === 0) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
'Trying to get notes with an empty scopes array. Scopes have to be set to undefined if intending on not filtering by scopes.',
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
188
240
|
const candidateNoteSources = [];
|
|
189
241
|
|
|
190
242
|
filter.scopes ??= (await toArray(this.#scopes.keysAsync())).map(addressString =>
|
|
@@ -196,29 +248,19 @@ export class NoteDataProvider implements DataProvider {
|
|
|
196
248
|
for (const scope of new Set(filter.scopes)) {
|
|
197
249
|
const formattedScopeString = scope.toString();
|
|
198
250
|
if (!(await this.#scopes.hasAsync(formattedScopeString))) {
|
|
199
|
-
throw new Error('Trying to get incoming notes of
|
|
251
|
+
throw new Error('Trying to get incoming notes of a scope that is not in the PXE database');
|
|
200
252
|
}
|
|
201
253
|
|
|
202
254
|
activeNoteIdsPerScope.push(
|
|
203
|
-
|
|
204
|
-
? await toArray(
|
|
205
|
-
this.#notesByAddressPointAndScope.get(formattedScopeString)!.getValuesAsync(publicKey.toString()),
|
|
206
|
-
)
|
|
207
|
-
: filter.txHash
|
|
255
|
+
filter.storageSlot
|
|
208
256
|
? await toArray(
|
|
209
|
-
this.#
|
|
257
|
+
this.#notesByStorageSlotAndScope.get(formattedScopeString)!.getValuesAsync(filter.storageSlot.toString()),
|
|
210
258
|
)
|
|
211
|
-
:
|
|
212
|
-
? await toArray(
|
|
259
|
+
: await toArray(
|
|
213
260
|
this.#notesByContractAndScope
|
|
214
261
|
.get(formattedScopeString)!
|
|
215
262
|
.getValuesAsync(filter.contractAddress.toString()),
|
|
216
|
-
)
|
|
217
|
-
: filter.storageSlot
|
|
218
|
-
? await toArray(
|
|
219
|
-
this.#notesByStorageSlotAndScope.get(formattedScopeString)!.getValuesAsync(filter.storageSlot.toString()),
|
|
220
|
-
)
|
|
221
|
-
: await toArray(this.#notesByAddressPointAndScope.get(formattedScopeString)!.valuesAsync()),
|
|
263
|
+
),
|
|
222
264
|
);
|
|
223
265
|
}
|
|
224
266
|
|
|
@@ -227,19 +269,28 @@ export class NoteDataProvider implements DataProvider {
|
|
|
227
269
|
notes: this.#notes,
|
|
228
270
|
});
|
|
229
271
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
272
|
+
// If status is ACTIVE_OR_NULLIFIED we add nullified notes as candidates on top of the default active ones.
|
|
273
|
+
if (filter.status === NoteStatus.ACTIVE_OR_NULLIFIED) {
|
|
274
|
+
const nullifiedIds = filter.storageSlot
|
|
275
|
+
? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
|
|
276
|
+
: await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()));
|
|
277
|
+
|
|
278
|
+
const setOfScopes = new Set(filter.scopes.map(s => s.toString() as string));
|
|
279
|
+
const filteredNullifiedIds = new Set<string>();
|
|
280
|
+
|
|
281
|
+
for (const noteId of nullifiedIds) {
|
|
282
|
+
const scopeList = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteId));
|
|
283
|
+
if (scopeList.some(scope => setOfScopes.has(scope))) {
|
|
284
|
+
filteredNullifiedIds.add(noteId);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (filteredNullifiedIds.size > 0) {
|
|
289
|
+
candidateNoteSources.push({
|
|
290
|
+
ids: filteredNullifiedIds,
|
|
291
|
+
notes: this.#nullifiedNotes,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
243
294
|
}
|
|
244
295
|
|
|
245
296
|
const result: NoteDao[] = [];
|
|
@@ -251,11 +302,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
251
302
|
}
|
|
252
303
|
|
|
253
304
|
const note = NoteDao.fromBuffer(serializedNote);
|
|
254
|
-
if (
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (filter.txHash && !note.txHash.equals(filter.txHash)) {
|
|
305
|
+
if (!note.contractAddress.equals(filter.contractAddress)) {
|
|
259
306
|
continue;
|
|
260
307
|
}
|
|
261
308
|
|
|
@@ -263,10 +310,6 @@ export class NoteDataProvider implements DataProvider {
|
|
|
263
310
|
continue;
|
|
264
311
|
}
|
|
265
312
|
|
|
266
|
-
if (publicKey && !note.addressPoint.equals(publicKey)) {
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
313
|
if (filter.siloedNullifier && !note.siloedNullifier.equals(filter.siloedNullifier)) {
|
|
271
314
|
continue;
|
|
272
315
|
}
|
|
@@ -278,7 +321,18 @@ export class NoteDataProvider implements DataProvider {
|
|
|
278
321
|
return result;
|
|
279
322
|
}
|
|
280
323
|
|
|
281
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Transitions notes from "active" to "nullified" state.
|
|
326
|
+
*
|
|
327
|
+
* This operation processes a batch of nullifiers to mark the corresponding notes
|
|
328
|
+
* as spent/nullified. The operation is atomic - if any nullifier is not found,
|
|
329
|
+
* the entire operation fails and no notes are modified.
|
|
330
|
+
*
|
|
331
|
+
* @param nullifiers - Array of nullifiers with their block numbers to process
|
|
332
|
+
* @returns Promise resolving to array of nullified NoteDao objects
|
|
333
|
+
* @throws Error if any nullifier is not found in the active notes
|
|
334
|
+
*/
|
|
335
|
+
applyNullifiers(nullifiers: InBlock<Fr>[]): Promise<NoteDao[]> {
|
|
282
336
|
if (nullifiers.length === 0) {
|
|
283
337
|
return Promise.resolve([]);
|
|
284
338
|
}
|
|
@@ -288,23 +342,25 @@ export class NoteDataProvider implements DataProvider {
|
|
|
288
342
|
|
|
289
343
|
for (const blockScopedNullifier of nullifiers) {
|
|
290
344
|
const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier;
|
|
291
|
-
const
|
|
345
|
+
const nullifierKey = nullifier.toString();
|
|
346
|
+
|
|
347
|
+
const noteIndex = await this.#nullifierToNoteId.getAsync(nullifierKey);
|
|
292
348
|
if (!noteIndex) {
|
|
293
|
-
|
|
349
|
+
// Check if already nullified?
|
|
350
|
+
const alreadyNullified = await this.#nullifiedNotesByNullifier.getAsync(nullifierKey);
|
|
351
|
+
if (alreadyNullified) {
|
|
352
|
+
throw new Error(`Nullifier already applied in applyNullifiers`);
|
|
353
|
+
}
|
|
354
|
+
throw new Error('Nullifier not found in applyNullifiers');
|
|
294
355
|
}
|
|
295
356
|
|
|
296
357
|
const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
|
|
297
358
|
|
|
298
359
|
if (!noteBuffer) {
|
|
299
|
-
|
|
300
|
-
continue;
|
|
360
|
+
throw new Error('Note not found in applyNullifiers');
|
|
301
361
|
}
|
|
302
362
|
const noteScopes = (await toArray(this.#notesToScope.getValuesAsync(noteIndex))) ?? [];
|
|
303
363
|
const note = NoteDao.fromBuffer(noteBuffer);
|
|
304
|
-
if (!note.addressPoint.equals(accountAddressPoint)) {
|
|
305
|
-
// tried to nullify someone else's note
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
364
|
|
|
309
365
|
nullifiedNotes.push(note);
|
|
310
366
|
|
|
@@ -314,8 +370,6 @@ export class NoteDataProvider implements DataProvider {
|
|
|
314
370
|
const scopes = await toArray(this.#scopes.keysAsync());
|
|
315
371
|
|
|
316
372
|
for (const scope of scopes) {
|
|
317
|
-
await this.#notesByAddressPointAndScope.get(scope)!.deleteValue(accountAddressPoint.toString(), noteIndex);
|
|
318
|
-
await this.#notesByTxHashAndScope.get(scope)!.deleteValue(note.txHash.toString(), noteIndex);
|
|
319
373
|
await this.#notesByContractAndScope.get(scope)!.deleteValue(note.contractAddress.toString(), noteIndex);
|
|
320
374
|
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
|
|
321
375
|
}
|
|
@@ -329,8 +383,6 @@ export class NoteDataProvider implements DataProvider {
|
|
|
329
383
|
await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
|
|
330
384
|
await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
|
|
331
385
|
await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
|
|
332
|
-
await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
|
|
333
|
-
await this.#nullifiedNotesByAddressPoint.set(note.addressPoint.toString(), noteIndex);
|
|
334
386
|
await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
|
|
335
387
|
|
|
336
388
|
await this.#nullifierToNoteId.delete(nullifier.toString());
|
|
@@ -338,8 +390,4 @@ export class NoteDataProvider implements DataProvider {
|
|
|
338
390
|
return nullifiedNotes;
|
|
339
391
|
});
|
|
340
392
|
}
|
|
341
|
-
|
|
342
|
-
async getSize() {
|
|
343
|
-
return (await this.getNotes({})).reduce((sum, note) => sum + note.getSize(), 0);
|
|
344
|
-
}
|
|
345
393
|
}
|