@aztec/pxe 3.0.0-canary.a9708bd → 3.0.0-devnet.2-patch.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/README.md +5 -5
  2. package/dest/bin/check_oracle_version.d.ts +1 -1
  3. package/dest/bin/check_oracle_version.js +110 -10
  4. package/dest/config/index.d.ts +9 -17
  5. package/dest/config/index.d.ts.map +1 -1
  6. package/dest/config/index.js +10 -16
  7. package/dest/config/package_info.d.ts +1 -1
  8. package/dest/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts +6 -6
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  11. package/dest/contract_function_simulator/contract_function_simulator.js +97 -42
  12. package/dest/contract_function_simulator/execution_data_provider.d.ts +40 -57
  13. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/execution_note_cache.d.ts +11 -9
  15. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/execution_note_cache.js +28 -17
  17. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  18. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  19. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  20. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  21. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/index.d.ts +4 -2
  23. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/index.js +2 -1
  25. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -2
  26. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +2 -2
  28. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
  30. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +8 -4
  32. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +6 -3
  33. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +12 -3
  35. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
  36. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  37. package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
  38. package/dest/contract_function_simulator/oracle/index.d.ts +2 -2
  39. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/index.js +1 -1
  41. package/dest/contract_function_simulator/oracle/interfaces.d.ts +104 -0
  42. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  43. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  44. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -4
  45. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  47. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +10 -4
  48. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/oracle/note_packing_utils.js +10 -5
  50. package/dest/contract_function_simulator/oracle/oracle.d.ts +17 -15
  51. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/oracle/oracle.js +101 -81
  53. package/dest/contract_function_simulator/oracle/private_execution.d.ts +6 -5
  54. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  55. package/dest/contract_function_simulator/oracle/private_execution.js +7 -16
  56. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +34 -22
  57. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  58. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +89 -25
  59. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +23 -33
  60. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  61. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +38 -42
  62. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  63. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  64. package/dest/contract_function_simulator/pick_notes.js +1 -1
  65. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  66. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  67. package/dest/contract_function_simulator/proxied_node.d.ts +1 -1
  68. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -1
  69. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +34 -68
  70. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -1
  71. package/dest/contract_function_simulator/pxe_oracle_interface.js +220 -208
  72. package/dest/entrypoints/client/bundle/index.d.ts +4 -2
  73. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  74. package/dest/entrypoints/client/bundle/index.js +2 -1
  75. package/dest/entrypoints/client/bundle/utils.d.ts +9 -9
  76. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  77. package/dest/entrypoints/client/bundle/utils.js +21 -12
  78. package/dest/entrypoints/client/lazy/index.d.ts +4 -2
  79. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  80. package/dest/entrypoints/client/lazy/index.js +2 -1
  81. package/dest/entrypoints/client/lazy/utils.d.ts +8 -8
  82. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/client/lazy/utils.js +20 -11
  84. package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
  85. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  86. package/dest/entrypoints/server/index.d.ts +4 -2
  87. package/dest/entrypoints/server/index.d.ts.map +1 -1
  88. package/dest/entrypoints/server/index.js +2 -1
  89. package/dest/entrypoints/server/utils.d.ts +5 -24
  90. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  91. package/dest/entrypoints/server/utils.js +17 -45
  92. package/dest/error_enriching.d.ts +11 -0
  93. package/dest/error_enriching.d.ts.map +1 -0
  94. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +3 -0
  95. package/dest/events/index.d.ts +2 -0
  96. package/dest/events/index.d.ts.map +1 -0
  97. package/dest/events/index.js +1 -0
  98. package/dest/events/private_event_filter_validator.d.ts +8 -0
  99. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  100. package/dest/events/private_event_filter_validator.js +39 -0
  101. package/dest/oracle_version.d.ts +3 -3
  102. package/dest/oracle_version.js +2 -2
  103. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +3 -3
  104. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  105. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +7 -7
  106. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +1 -1
  107. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +6 -6
  108. package/dest/private_kernel/hints/index.d.ts +1 -1
  109. package/dest/private_kernel/index.d.ts +1 -1
  110. package/dest/private_kernel/private_kernel_execution_prover.d.ts +9 -2
  111. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  112. package/dest/private_kernel/private_kernel_execution_prover.js +38 -32
  113. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -2
  114. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  115. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +8 -7
  116. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  117. package/dest/pxe.d.ts +240 -0
  118. package/dest/pxe.d.ts.map +1 -0
  119. package/dest/{pxe_service/pxe_service.js → pxe.js} +227 -241
  120. package/dest/storage/address_data_provider/address_data_provider.d.ts +2 -4
  121. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -1
  122. package/dest/storage/address_data_provider/address_data_provider.js +0 -3
  123. package/dest/storage/address_data_provider/index.d.ts +1 -1
  124. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +3 -5
  125. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
  126. package/dest/storage/capsule_data_provider/capsule_data_provider.js +1 -5
  127. package/dest/storage/capsule_data_provider/index.d.ts +1 -1
  128. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +6 -17
  129. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
  130. package/dest/storage/contract_data_provider/contract_data_provider.js +0 -15
  131. package/dest/storage/contract_data_provider/index.d.ts +1 -1
  132. package/dest/storage/contract_data_provider/private_functions_tree.d.ts +1 -1
  133. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -1
  134. package/dest/storage/contract_data_provider/private_functions_tree.js +1 -1
  135. package/dest/storage/index.d.ts +1 -2
  136. package/dest/storage/index.d.ts.map +1 -1
  137. package/dest/storage/index.js +0 -1
  138. package/dest/storage/metadata.d.ts +1 -1
  139. package/dest/storage/note_data_provider/index.d.ts +2 -2
  140. package/dest/storage/note_data_provider/index.d.ts.map +1 -1
  141. package/dest/storage/note_data_provider/index.js +1 -1
  142. package/dest/storage/note_data_provider/note_data_provider.d.ts +75 -11
  143. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
  144. package/dest/storage/note_data_provider/note_data_provider.js +143 -81
  145. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +31 -17
  146. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -1
  147. package/dest/storage/private_event_data_provider/private_event_data_provider.js +47 -28
  148. package/dest/storage/sync_data_provider/index.d.ts +1 -1
  149. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +4 -5
  150. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -1
  151. package/dest/storage/sync_data_provider/sync_data_provider.js +0 -3
  152. package/dest/storage/tagging_data_provider/index.d.ts +1 -1
  153. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +29 -7
  154. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -1
  155. package/dest/storage/tagging_data_provider/tagging_data_provider.js +46 -39
  156. package/dest/synchronizer/index.d.ts +1 -1
  157. package/dest/synchronizer/synchronizer.d.ts +3 -2
  158. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  159. package/dest/synchronizer/synchronizer.js +4 -4
  160. package/dest/tagging/constants.d.ts +2 -0
  161. package/dest/tagging/constants.d.ts.map +1 -0
  162. package/dest/tagging/constants.js +2 -0
  163. package/dest/tagging/index.d.ts +7 -0
  164. package/dest/tagging/index.d.ts.map +1 -0
  165. package/dest/tagging/index.js +5 -0
  166. package/dest/tagging/siloed_tag.d.ts +14 -0
  167. package/dest/tagging/siloed_tag.d.ts.map +1 -0
  168. package/dest/tagging/siloed_tag.js +20 -0
  169. package/dest/tagging/tag.d.ts +12 -0
  170. package/dest/tagging/tag.d.ts.map +1 -0
  171. package/dest/tagging/tag.js +17 -0
  172. package/dest/tagging/utils.d.ts +18 -0
  173. package/dest/tagging/utils.d.ts.map +1 -0
  174. package/dest/tagging/utils.js +24 -0
  175. package/package.json +22 -24
  176. package/src/bin/check_oracle_version.ts +134 -10
  177. package/src/config/index.ts +18 -32
  178. package/src/config/package_info.ts +1 -1
  179. package/src/contract_function_simulator/contract_function_simulator.ts +151 -62
  180. package/src/contract_function_simulator/execution_data_provider.ts +47 -65
  181. package/src/contract_function_simulator/execution_note_cache.ts +33 -17
  182. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  183. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  184. package/src/contract_function_simulator/index.ts +3 -1
  185. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  186. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  187. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +10 -5
  188. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +14 -2
  189. package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
  190. package/src/contract_function_simulator/oracle/index.ts +1 -1
  191. package/src/contract_function_simulator/oracle/interfaces.ts +176 -0
  192. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  193. package/src/contract_function_simulator/oracle/note_packing_utils.ts +21 -5
  194. package/src/contract_function_simulator/oracle/oracle.ts +135 -80
  195. package/src/contract_function_simulator/oracle/private_execution.ts +10 -17
  196. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +123 -49
  197. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +68 -80
  198. package/src/contract_function_simulator/pick_notes.ts +1 -1
  199. package/src/contract_function_simulator/pxe_oracle_interface.ts +291 -271
  200. package/src/entrypoints/client/bundle/index.ts +3 -1
  201. package/src/entrypoints/client/bundle/utils.ts +21 -23
  202. package/src/entrypoints/client/lazy/index.ts +3 -1
  203. package/src/entrypoints/client/lazy/utils.ts +20 -23
  204. package/src/entrypoints/pxe_creation_options.ts +4 -1
  205. package/src/entrypoints/server/index.ts +3 -1
  206. package/src/entrypoints/server/utils.ts +20 -68
  207. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +5 -1
  208. package/src/events/index.ts +1 -0
  209. package/src/events/private_event_filter_validator.ts +47 -0
  210. package/src/oracle_version.ts +2 -2
  211. package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +5 -9
  212. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +6 -6
  213. package/src/private_kernel/private_kernel_execution_prover.ts +51 -43
  214. package/src/private_kernel/private_kernel_oracle.ts +2 -1
  215. package/src/private_kernel/private_kernel_oracle_impl.ts +4 -3
  216. package/src/{pxe_service/pxe_service.ts → pxe.ts} +256 -308
  217. package/src/storage/address_data_provider/address_data_provider.ts +1 -7
  218. package/src/storage/capsule_data_provider/capsule_data_provider.ts +2 -12
  219. package/src/storage/contract_data_provider/contract_data_provider.ts +4 -27
  220. package/src/storage/contract_data_provider/private_functions_tree.ts +1 -1
  221. package/src/storage/index.ts +0 -1
  222. package/src/storage/note_data_provider/index.ts +1 -1
  223. package/src/storage/note_data_provider/note_data_provider.ts +171 -109
  224. package/src/storage/private_event_data_provider/private_event_data_provider.ts +69 -41
  225. package/src/storage/sync_data_provider/sync_data_provider.ts +3 -8
  226. package/src/storage/tagging_data_provider/tagging_data_provider.ts +52 -55
  227. package/src/synchronizer/synchronizer.ts +4 -4
  228. package/src/tagging/constants.ts +2 -0
  229. package/src/tagging/index.ts +6 -0
  230. package/src/tagging/siloed_tag.ts +22 -0
  231. package/src/tagging/tag.ts +16 -0
  232. package/src/tagging/utils.ts +31 -0
  233. package/dest/bin/index.d.ts +0 -3
  234. package/dest/bin/index.d.ts.map +0 -1
  235. package/dest/bin/index.js +0 -48
  236. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +0 -87
  237. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +0 -1
  238. package/dest/contract_function_simulator/oracle/typed_oracle.js +0 -146
  239. package/dest/contract_function_simulator/tagging_utils.d.ts +0 -17
  240. package/dest/contract_function_simulator/tagging_utils.d.ts.map +0 -1
  241. package/dest/contract_function_simulator/tagging_utils.js +0 -23
  242. package/dest/pxe_service/error_enriching.d.ts +0 -11
  243. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  244. package/dest/pxe_service/index.d.ts +0 -3
  245. package/dest/pxe_service/index.d.ts.map +0 -1
  246. package/dest/pxe_service/index.js +0 -2
  247. package/dest/pxe_service/pxe_service.d.ts +0 -100
  248. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  249. package/dest/storage/data_provider.d.ts +0 -4
  250. package/dest/storage/data_provider.d.ts.map +0 -1
  251. package/dest/storage/data_provider.js +0 -1
  252. package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
  253. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  254. package/dest/storage/note_data_provider/note_dao.js +0 -102
  255. package/dest/test/pxe_test_suite.d.ts +0 -3
  256. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  257. package/dest/test/pxe_test_suite.js +0 -97
  258. package/src/bin/index.ts +0 -62
  259. package/src/contract_function_simulator/oracle/typed_oracle.ts +0 -289
  260. package/src/contract_function_simulator/tagging_utils.ts +0 -32
  261. package/src/pxe_service/index.ts +0 -2
  262. package/src/storage/data_provider.ts +0 -3
  263. package/src/storage/note_data_provider/note_dao.ts +0 -154
  264. package/src/test/pxe_test_suite.ts +0 -113
@@ -2,8 +2,13 @@ import { toBufferBE } from '@aztec/foundation/bigint-buffer';
2
2
  import { toArray } from '@aztec/foundation/iterable';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { NoteStatus } from '@aztec/stdlib/note';
5
- import { NoteDao } from './note_dao.js';
6
- export class NoteDataProvider {
5
+ import { NoteDao } from '@aztec/stdlib/note';
6
+ /**
7
+ * NoteDataProvider manages the storage and retrieval of notes.
8
+ *
9
+ * Notes can be active or nullified. This class processes new notes, nullifications,
10
+ * and performs rollback handling in the case of a reorg.
11
+ **/ export class NoteDataProvider {
7
12
  #store;
8
13
  #notes;
9
14
  #nullifiedNotes;
@@ -12,15 +17,11 @@ export class NoteDataProvider {
12
17
  #nullifiedNotesToScope;
13
18
  #nullifiedNotesByContract;
14
19
  #nullifiedNotesByStorageSlot;
15
- #nullifiedNotesByTxHash;
16
- #nullifiedNotesByRecipient;
17
20
  #nullifiedNotesByNullifier;
18
21
  #scopes;
19
22
  #notesToScope;
20
23
  #notesByContractAndScope;
21
24
  #notesByStorageSlotAndScope;
22
- #notesByTxHashAndScope;
23
- #notesByRecipientAndScope;
24
25
  constructor(store){
25
26
  this.#store = store;
26
27
  this.#notes = store.openMap('notes');
@@ -30,27 +31,37 @@ export class NoteDataProvider {
30
31
  this.#nullifiedNotesToScope = store.openMultiMap('nullified_notes_to_scope');
31
32
  this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
32
33
  this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
33
- this.#nullifiedNotesByTxHash = store.openMultiMap('nullified_notes_by_tx_hash');
34
- this.#nullifiedNotesByRecipient = store.openMultiMap('nullified_notes_by_recipient');
35
34
  this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
36
35
  this.#scopes = store.openMap('scopes');
37
36
  this.#notesToScope = store.openMultiMap('notes_to_scope');
38
37
  this.#notesByContractAndScope = new Map();
39
38
  this.#notesByStorageSlotAndScope = new Map();
40
- this.#notesByTxHashAndScope = new Map();
41
- this.#notesByRecipientAndScope = new Map();
42
39
  }
43
- static async create(store) {
40
+ /**
41
+ * Creates and initializes a new NoteDataProvider instance.
42
+ *
43
+ * This factory method creates a NoteDataProvider and restores any existing
44
+ * scope-specific indexes from the database.
45
+ *
46
+ * @param store - The key-value store to use for persistence
47
+ * @returns Promise resolving to a fully initialized NoteDataProvider instance
48
+ */ static async create(store) {
44
49
  const pxeDB = new NoteDataProvider(store);
45
50
  for await (const scope of pxeDB.#scopes.keysAsync()){
46
51
  pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
47
52
  pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
48
- pxeDB.#notesByTxHashAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_tx_hash`));
49
- pxeDB.#notesByRecipientAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_recipient`));
50
53
  }
51
54
  return pxeDB;
52
55
  }
53
- async addScope(scope) {
56
+ /**
57
+ * Adds a new scope to the note data provider.
58
+ *
59
+ * Scopes provide privacy isolation by creating separate indexes for each user.
60
+ * Each scope gets its own set of indexes for efficient note retrieval by various criteria.
61
+ *
62
+ * @param scope - The AztecAddress representing the scope/user to add
63
+ * @returns Promise resolving to true if scope was added, false if it already existed
64
+ */ async addScope(scope) {
54
65
  const scopeString = scope.toString();
55
66
  if (await this.#scopes.hasAsync(scopeString)) {
56
67
  return false;
@@ -58,32 +69,53 @@ export class NoteDataProvider {
58
69
  await this.#scopes.set(scopeString, true);
59
70
  this.#notesByContractAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_contract`));
60
71
  this.#notesByStorageSlotAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_storage_slot`));
61
- this.#notesByTxHashAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_tx_hash`));
62
- this.#notesByRecipientAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_recipient`));
63
72
  return true;
64
73
  }
65
- addNotes(notes, scope = AztecAddress.ZERO) {
74
+ /**
75
+ * Adds multiple notes to the data provider under the specified scope.
76
+ *
77
+ * Notes are stored using their index from the notes hash tree as the key, which provides
78
+ * uniqueness and maintains creation order. Each note is indexed by multiple criteria
79
+ * for efficient retrieval.
80
+ *
81
+ * @param notes - Notes to store
82
+ * @param scope - The scope (user/account) under which to store the notes
83
+ */ addNotes(notes, scope) {
66
84
  return this.#store.transactionAsync(async ()=>{
67
85
  if (!await this.#scopes.hasAsync(scope.toString())) {
68
86
  await this.addScope(scope);
69
87
  }
70
88
  for (const dao of notes){
71
- // store notes by their index in the notes hash tree
72
- // this provides the uniqueness we need to store individual notes
73
- // and should also return notes in the order that they were created.
74
- // Had we stored them by their nullifier, they would be returned in random order
75
89
  const noteIndex = toBufferBE(dao.index, 32).toString('hex');
76
90
  await this.#notes.set(noteIndex, dao.toBuffer());
77
91
  await this.#notesToScope.set(noteIndex, scope.toString());
78
92
  await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
79
93
  await this.#notesByContractAndScope.get(scope.toString()).set(dao.contractAddress.toString(), noteIndex);
80
94
  await this.#notesByStorageSlotAndScope.get(scope.toString()).set(dao.storageSlot.toString(), noteIndex);
81
- await this.#notesByTxHashAndScope.get(scope.toString()).set(dao.txHash.toString(), noteIndex);
82
- await this.#notesByRecipientAndScope.get(scope.toString()).set(dao.recipient.toString(), noteIndex);
83
95
  }
84
96
  });
85
97
  }
86
- removeNotesAfter(blockNumber) {
98
+ /**
99
+ * Synchronizes notes and nullifiers to a specific block number.
100
+ *
101
+ * This method ensures that the state of notes and nullifiers is consistent with the
102
+ * specified block number. It restores any notes that were nullified after the given block
103
+ * and deletes any active notes created after that block.
104
+ *
105
+ * @param blockNumber - The new chain tip after a reorg
106
+ * @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
107
+ */ async rollbackNotesAndNullifiers(blockNumber, synchedBlockNumber) {
108
+ await this.#rewindNullifiersAfterBlock(blockNumber, synchedBlockNumber);
109
+ await this.#deleteActiveNotesAfterBlock(blockNumber);
110
+ }
111
+ /**
112
+ * Deletes (removes) all active notes created after the specified block number.
113
+ *
114
+ * Permanently delete notes from the active notes store, e.g. during a reorg.
115
+ * Note: This only affects #notes (active notes), not #nullifiedNotes.
116
+ *
117
+ * @param blockNumber - Notes created after this block number will be deleted
118
+ */ #deleteActiveNotesAfterBlock(blockNumber) {
87
119
  return this.#store.transactionAsync(async ()=>{
88
120
  const notes = await toArray(this.#notes.valuesAsync());
89
121
  for (const note of notes){
@@ -95,8 +127,6 @@ export class NoteDataProvider {
95
127
  await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
96
128
  const scopes = await toArray(this.#scopes.keysAsync());
97
129
  for (const scope of scopes){
98
- await this.#notesByRecipientAndScope.get(scope).deleteValue(noteDao.recipient.toString(), noteIndex);
99
- await this.#notesByTxHashAndScope.get(scope).deleteValue(noteDao.txHash.toString(), noteIndex);
100
130
  await this.#notesByContractAndScope.get(scope).deleteValue(noteDao.contractAddress.toString(), noteIndex);
101
131
  await this.#notesByStorageSlotAndScope.get(scope).deleteValue(noteDao.storageSlot.toString(), noteIndex);
102
132
  }
@@ -104,12 +134,20 @@ export class NoteDataProvider {
104
134
  }
105
135
  });
106
136
  }
107
- async unnullifyNotesAfter(blockNumber, synchedBlockNumber) {
137
+ /**
138
+ * Rewinds nullifications after a given block number.
139
+ *
140
+ * This operation "unnullifies" notes, rolling back nullifications that occurred
141
+ * in orphaned blocks, e.g. during a reorg. The notes are restored to the
142
+ * active notes store and removed from the nullified store.
143
+ *
144
+ * @param blockNumber - Revert nullifications that occurred after this block
145
+ * @param synchedBlockNumber - Upper bound for the block range to process
146
+ */ async #rewindNullifiersAfterBlock(blockNumber, synchedBlockNumber) {
108
147
  await this.#store.transactionAsync(async ()=>{
109
148
  const nullifiersToUndo = [];
110
149
  const currentBlockNumber = blockNumber + 1;
111
- const maxBlockNumber = synchedBlockNumber ?? currentBlockNumber;
112
- for(let i = currentBlockNumber; i <= maxBlockNumber; i++){
150
+ for(let i = currentBlockNumber; i <= synchedBlockNumber; i++){
113
151
  nullifiersToUndo.push(...await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i)));
114
152
  }
115
153
  const notesIndexesToReinsert = await Promise.all(nullifiersToUndo.map((nullifier)=>this.#nullifiedNotesByNullifier.getAsync(nullifier)));
@@ -120,17 +158,15 @@ export class NoteDataProvider {
120
158
  const noteIndex = toBufferBE(dao.index, 32).toString('hex');
121
159
  await this.#notes.set(noteIndex, dao.toBuffer());
122
160
  await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
123
- let scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex)) ?? [];
161
+ const scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex));
124
162
  if (scopes.length === 0) {
125
- scopes = [
126
- dao.recipient.toString()
127
- ];
163
+ // We should never run into this error because notes always have a scope assigned to them - either on initial
164
+ // insertion via `addNotes` or when removing their nullifiers.
165
+ throw new Error(`No scopes found for nullified note with index ${noteIndex}`);
128
166
  }
129
167
  for (const scope of scopes){
130
168
  await this.#notesByContractAndScope.get(scope.toString()).set(dao.contractAddress.toString(), noteIndex);
131
169
  await this.#notesByStorageSlotAndScope.get(scope.toString()).set(dao.storageSlot.toString(), noteIndex);
132
- await this.#notesByTxHashAndScope.get(scope.toString()).set(dao.txHash.toString(), noteIndex);
133
- await this.#notesByRecipientAndScope.get(scope.toString()).set(dao.recipient.toString(), noteIndex);
134
170
  await this.#notesToScope.set(noteIndex, scope);
135
171
  }
136
172
  await this.#nullifiedNotes.delete(noteIndex);
@@ -138,33 +174,58 @@ export class NoteDataProvider {
138
174
  await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
139
175
  await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
140
176
  await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
141
- await this.#nullifiedNotesByTxHash.deleteValue(dao.txHash.toString(), noteIndex);
142
- await this.#nullifiedNotesByRecipient.deleteValue(dao.recipient.toString(), noteIndex);
143
177
  await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
144
178
  }
145
179
  });
146
180
  }
147
- async getNotes(filter) {
181
+ /**
182
+ * Retrieves notes based on the provided filter criteria.
183
+ *
184
+ * This method queries both active and optionally nullified notes based on the filter
185
+ * parameters.
186
+ *
187
+ * @param filter - Filter criteria including contractAddress (required), and optional
188
+ * owner, storageSlot, status, scopes, and siloedNullifier.
189
+ * @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
190
+ * returned once if this is the case)
191
+ * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
192
+ */ async getNotes(filter) {
148
193
  filter.status = filter.status ?? NoteStatus.ACTIVE;
194
+ // throw early if scopes is an empty array
195
+ if (filter.scopes !== undefined && filter.scopes.length === 0) {
196
+ throw new Error('Trying to get notes with an empty scopes array. Scopes have to be set to undefined if intending on not filtering by scopes.');
197
+ }
149
198
  const candidateNoteSources = [];
150
199
  filter.scopes ??= (await toArray(this.#scopes.keysAsync())).map((addressString)=>AztecAddress.fromString(addressString));
151
200
  const activeNoteIdsPerScope = [];
152
201
  for (const scope of new Set(filter.scopes)){
153
202
  const formattedScopeString = scope.toString();
154
203
  if (!await this.#scopes.hasAsync(formattedScopeString)) {
155
- throw new Error('Trying to get incoming notes of an scope that is not in the PXE database');
204
+ throw new Error('Trying to get incoming notes of a scope that is not in the PXE database');
156
205
  }
157
- activeNoteIdsPerScope.push(filter.recipient ? await toArray(this.#notesByRecipientAndScope.get(formattedScopeString).getValuesAsync(filter.recipient.toString())) : filter.txHash ? await toArray(this.#notesByTxHashAndScope.get(formattedScopeString).getValuesAsync(filter.txHash.toString())) : filter.storageSlot ? await toArray(this.#notesByStorageSlotAndScope.get(formattedScopeString).getValuesAsync(filter.storageSlot.toString())) : await toArray(this.#notesByContractAndScope.get(formattedScopeString).getValuesAsync(filter.contractAddress.toString())));
206
+ activeNoteIdsPerScope.push(filter.storageSlot ? await toArray(this.#notesByStorageSlotAndScope.get(formattedScopeString).getValuesAsync(filter.storageSlot.toString())) : await toArray(this.#notesByContractAndScope.get(formattedScopeString).getValuesAsync(filter.contractAddress.toString())));
158
207
  }
159
208
  candidateNoteSources.push({
160
209
  ids: new Set(activeNoteIdsPerScope.flat()),
161
210
  notes: this.#notes
162
211
  });
163
- if (filter.status == NoteStatus.ACTIVE_OR_NULLIFIED) {
164
- candidateNoteSources.push({
165
- ids: filter.recipient ? await toArray(this.#nullifiedNotesByRecipient.getValuesAsync(filter.recipient.toString())) : filter.txHash ? await toArray(this.#nullifiedNotesByTxHash.getValuesAsync(filter.txHash.toString())) : filter.storageSlot ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString())) : await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString())),
166
- notes: this.#nullifiedNotes
167
- });
212
+ // If status is ACTIVE_OR_NULLIFIED we add nullified notes as candidates on top of the default active ones.
213
+ if (filter.status === NoteStatus.ACTIVE_OR_NULLIFIED) {
214
+ const nullifiedIds = filter.storageSlot ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString())) : await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()));
215
+ const setOfScopes = new Set(filter.scopes.map((s)=>s.toString()));
216
+ const filteredNullifiedIds = new Set();
217
+ for (const noteId of nullifiedIds){
218
+ const scopeList = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteId));
219
+ if (scopeList.some((scope)=>setOfScopes.has(scope))) {
220
+ filteredNullifiedIds.add(noteId);
221
+ }
222
+ }
223
+ if (filteredNullifiedIds.size > 0) {
224
+ candidateNoteSources.push({
225
+ ids: filteredNullifiedIds,
226
+ notes: this.#nullifiedNotes
227
+ });
228
+ }
168
229
  }
169
230
  const result = [];
170
231
  for (const { ids, notes } of candidateNoteSources){
@@ -177,24 +238,38 @@ export class NoteDataProvider {
177
238
  if (!note.contractAddress.equals(filter.contractAddress)) {
178
239
  continue;
179
240
  }
180
- if (filter.txHash && !note.txHash.equals(filter.txHash)) {
241
+ if (filter.owner && !note.owner.equals(filter.owner)) {
181
242
  continue;
182
243
  }
183
244
  if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot)) {
184
245
  continue;
185
246
  }
186
- if (filter.recipient && !note.recipient.equals(filter.recipient)) {
187
- continue;
188
- }
189
247
  if (filter.siloedNullifier && !note.siloedNullifier.equals(filter.siloedNullifier)) {
190
248
  continue;
191
249
  }
192
250
  result.push(note);
193
251
  }
194
252
  }
195
- return result;
253
+ // A note might be present in multiple scopes - we ensure it is only returned once
254
+ const deduplicated = [];
255
+ for (const note of result){
256
+ if (!deduplicated.some((existing)=>existing.equals(note))) {
257
+ deduplicated.push(note);
258
+ }
259
+ }
260
+ return deduplicated;
196
261
  }
197
- removeNullifiedNotes(nullifiers, recipient) {
262
+ /**
263
+ * Transitions notes from "active" to "nullified" state.
264
+ *
265
+ * This operation processes a batch of nullifiers to mark the corresponding notes
266
+ * as spent/nullified. The operation is atomic - if any nullifier is not found,
267
+ * the entire operation fails and no notes are modified.
268
+ *
269
+ * @param nullifiers - Array of nullifiers with their block numbers to process
270
+ * @returns Promise resolving to array of nullified NoteDao objects
271
+ * @throws Error if any nullifier is not found in the active notes
272
+ */ applyNullifiers(nullifiers) {
198
273
  if (nullifiers.length === 0) {
199
274
  return Promise.resolve([]);
200
275
  }
@@ -202,59 +277,46 @@ export class NoteDataProvider {
202
277
  const nullifiedNotes = [];
203
278
  for (const blockScopedNullifier of nullifiers){
204
279
  const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier;
205
- const noteIndex = await this.#nullifierToNoteId.getAsync(nullifier.toString());
280
+ const nullifierKey = nullifier.toString();
281
+ const noteIndex = await this.#nullifierToNoteId.getAsync(nullifierKey);
206
282
  if (!noteIndex) {
207
- throw new Error('Nullifier not found in removeNullifiedNotes');
283
+ // Check if already nullified?
284
+ const alreadyNullified = await this.#nullifiedNotesByNullifier.getAsync(nullifierKey);
285
+ if (alreadyNullified) {
286
+ throw new Error(`Nullifier already applied in applyNullifiers`);
287
+ }
288
+ throw new Error('Nullifier not found in applyNullifiers');
208
289
  }
209
290
  const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
210
291
  if (!noteBuffer) {
211
- throw new Error('Note not found in removeNullifiedNotes');
292
+ throw new Error('Note not found in applyNullifiers');
212
293
  }
213
- const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex)) ?? [];
214
- const note = NoteDao.fromBuffer(noteBuffer);
215
- if (!note.recipient.equals(recipient)) {
216
- throw new Error("Tried to nullify someone else's note");
294
+ const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex));
295
+ if (noteScopes.length === 0) {
296
+ // We should never run into this error because notes always have a scope assigned to them - either on initial
297
+ // insertion via `addNotes` or when removing their nullifiers.
298
+ throw new Error('Note scopes are missing in applyNullifiers');
217
299
  }
300
+ const note = NoteDao.fromBuffer(noteBuffer);
218
301
  nullifiedNotes.push(note);
219
302
  await this.#notes.delete(noteIndex);
220
303
  await this.#notesToScope.delete(noteIndex);
221
304
  const scopes = await toArray(this.#scopes.keysAsync());
222
305
  for (const scope of scopes){
223
- await this.#notesByRecipientAndScope.get(scope).deleteValue(note.recipient.toString(), noteIndex);
224
- await this.#notesByTxHashAndScope.get(scope).deleteValue(note.txHash.toString(), noteIndex);
225
306
  await this.#notesByContractAndScope.get(scope).deleteValue(note.contractAddress.toString(), noteIndex);
226
307
  await this.#notesByStorageSlotAndScope.get(scope).deleteValue(note.storageSlot.toString(), noteIndex);
227
308
  }
228
- if (noteScopes !== undefined) {
229
- for (const scope of noteScopes){
230
- await this.#nullifiedNotesToScope.set(noteIndex, scope);
231
- }
309
+ for (const scope of noteScopes){
310
+ await this.#nullifiedNotesToScope.set(noteIndex, scope);
232
311
  }
233
312
  await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
234
313
  await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
235
314
  await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
236
315
  await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
237
- await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
238
- await this.#nullifiedNotesByRecipient.set(note.recipient.toString(), noteIndex);
239
316
  await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
240
317
  await this.#nullifierToNoteId.delete(nullifier.toString());
241
318
  }
242
319
  return nullifiedNotes;
243
320
  });
244
321
  }
245
- async getSize() {
246
- const scopes = await toArray(this.#scopes.keysAsync());
247
- const contractAddresses = new Set();
248
- // Collect all unique contract addresses across all scopes
249
- for (const scope of scopes){
250
- const addresses = await toArray(this.#notesByContractAndScope.get(scope).keysAsync());
251
- addresses.forEach((addr)=>contractAddresses.add(addr));
252
- }
253
- // Get all notes for each contract address
254
- const allNotes = await Promise.all(Array.from(contractAddresses).map((addr)=>this.getNotes({
255
- contractAddress: AztecAddress.fromString(addr)
256
- })));
257
- // Reduce all notes to get total size
258
- return allNotes.flat().reduce((sum, note)=>sum + note.getSize(), 0);
259
- }
260
322
  }
@@ -1,37 +1,51 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
3
3
  import type { EventSelector } from '@aztec/stdlib/abi';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import type { TxHash } from '@aztec/stdlib/tx';
6
- import type { DataProvider } from '../data_provider.js';
5
+ import { type InTx, TxHash } from '@aztec/stdlib/tx';
6
+ import type { PackedPrivateEvent } from '../../pxe.js';
7
+ export type PrivateEventDataProviderFilter = {
8
+ contractAddress: AztecAddress;
9
+ fromBlock: number;
10
+ toBlock: number;
11
+ scopes: AztecAddress[];
12
+ txHash?: TxHash;
13
+ };
14
+ type PrivateEventMetadata = InTx & {
15
+ contractAddress: AztecAddress;
16
+ scope: AztecAddress;
17
+ };
7
18
  /**
8
19
  * Stores decrypted private event logs.
9
20
  */
10
- export declare class PrivateEventDataProvider implements DataProvider {
21
+ export declare class PrivateEventDataProvider {
11
22
  #private;
12
23
  logger: import("@aztec/foundation/log").Logger;
13
24
  constructor(store: AztecAsyncKVStore);
14
25
  /**
15
26
  * Store a private event log.
16
- * @param contractAddress - The address of the contract that emitted the event.
17
- * @param recipient - The recipient of the event.
18
27
  * @param eventSelector - The event selector of the event.
19
28
  * @param msgContent - The content of the event.
20
- * @param txHash - The transaction hash of the event log.
21
29
  * @param eventCommitmentIndex - The index of the event commitment in the nullifier tree.
22
- * @param blockNumber - The block number in which the event was emitted.
30
+ * @param metadata
31
+ * contractAddress - The address of the contract that emitted the event.
32
+ * scope - The address to which the event is scoped.
33
+ * txHash - The transaction hash of the event log.
34
+ * blockNumber - The block number in which the event was emitted.
23
35
  */
24
- storePrivateEventLog(contractAddress: AztecAddress, recipient: AztecAddress, eventSelector: EventSelector, msgContent: Fr[], txHash: TxHash, eventCommitmentIndex: number, blockNumber: number): Promise<void>;
36
+ storePrivateEventLog(eventSelector: EventSelector, msgContent: Fr[], eventCommitmentIndex: number, metadata: PrivateEventMetadata): Promise<void>;
25
37
  /**
26
38
  * Returns the private events given search parameters.
27
- * @param contractAddress - The address of the contract to get events from.
28
- * @param from - The block number to search from.
29
- * @param numBlocks - The amount of blocks to search.
30
- * @param recipients - The addresses that decrypted the logs.
31
39
  * @param eventSelector - The event selector to filter by.
32
- * @returns - The event log contents.
40
+ * @param filter - Filtering criteria:
41
+ * contractAddress: The address of the contract to get events from.
42
+ * fromBlock: The block number to search from (inclusive).
43
+ * toBlock: The block number to search upto (exclusive).
44
+ * scope: - The addresses that decrypted the logs.
45
+ * @returns - The event log contents, augmented with metadata about
46
+ * the transaction and block it the event was included in .
33
47
  */
34
- getPrivateEvents(contractAddress: AztecAddress, from: number, numBlocks: number, recipients: AztecAddress[], eventSelector: EventSelector): Promise<Fr[][]>;
35
- getSize(): Promise<number>;
48
+ getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventDataProviderFilter): Promise<PackedPrivateEvent[]>;
36
49
  }
37
- //# sourceMappingURL=private_event_data_provider.d.ts.map
50
+ export {};
51
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJpdmF0ZV9ldmVudF9kYXRhX3Byb3ZpZGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9wcml2YXRlX2V2ZW50X2RhdGFfcHJvdmlkZXIvcHJpdmF0ZV9ldmVudF9kYXRhX3Byb3ZpZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUdwRCxPQUFPLEtBQUssRUFBbUIsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDekYsT0FBTyxLQUFLLEVBQUUsYUFBYSxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDdkQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFFaEUsT0FBTyxFQUFFLEtBQUssSUFBSSxFQUFFLE1BQU0sRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRXJELE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sY0FBYyxDQUFDO0FBRXZELE1BQU0sTUFBTSw4QkFBOEIsR0FBRztJQUMzQyxlQUFlLEVBQUUsWUFBWSxDQUFDO0lBQzlCLFNBQVMsRUFBRSxNQUFNLENBQUM7SUFDbEIsT0FBTyxFQUFFLE1BQU0sQ0FBQztJQUNoQixNQUFNLEVBQUUsWUFBWSxFQUFFLENBQUM7SUFDdkIsTUFBTSxDQUFDLEVBQUUsTUFBTSxDQUFDO0NBQ2pCLENBQUM7QUFVRixLQUFLLG9CQUFvQixHQUFHLElBQUksR0FBRztJQUNqQyxlQUFlLEVBQUUsWUFBWSxDQUFDO0lBQzlCLEtBQUssRUFBRSxZQUFZLENBQUM7Q0FDckIsQ0FBQztBQUVGOztHQUVHO0FBQ0gscUJBQWEsd0JBQXdCOztJQVNuQyxNQUFNLHlDQUErQztJQUVyRCxZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFLbkM7SUFNRDs7Ozs7Ozs7OztPQVVHO0lBQ0gsb0JBQW9CLENBQ2xCLGFBQWEsRUFBRSxhQUFhLEVBQzVCLFVBQVUsRUFBRSxFQUFFLEVBQUUsRUFDaEIsb0JBQW9CLEVBQUUsTUFBTSxFQUM1QixRQUFRLEVBQUUsb0JBQW9CLEdBQzdCLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0E4QmY7SUFFRDs7Ozs7Ozs7OztPQVVHO0lBQ1UsZ0JBQWdCLENBQzNCLGFBQWEsRUFBRSxhQUFhLEVBQzVCLE1BQU0sRUFBRSw4QkFBOEIsR0FDckMsT0FBTyxDQUFDLGtCQUFrQixFQUFFLENBQUMsQ0F3Qy9CO0NBQ0YifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"private_event_data_provider.d.ts","sourceRoot":"","sources":["../../../src/storage/private_event_data_provider/private_event_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,KAAK,EAAmB,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAQxD;;GAEG;AACH,qBAAa,wBAAyB,YAAW,YAAY;;IAS3D,MAAM,yCAA+C;gBAEzC,KAAK,EAAE,iBAAiB;IAOpC;;;;;;;;;OASG;IACH,oBAAoB,CAClB,eAAe,EAAE,YAAY,EAC7B,SAAS,EAAE,YAAY,EACvB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,EAAE,EAAE,EAChB,MAAM,EAAE,MAAM,EACd,oBAAoB,EAAE,MAAM,EAC5B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC;IA4BhB;;;;;;;;OAQG;IACU,gBAAgB,CAC3B,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,YAAY,EAAE,EAC1B,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC;IAgClB,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CAG3B"}
1
+ {"version":3,"file":"private_event_data_provider.d.ts","sourceRoot":"","sources":["../../../src/storage/private_event_data_provider/private_event_data_provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAGpD,OAAO,KAAK,EAAmB,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,MAAM,8BAA8B,GAAG;IAC3C,eAAe,EAAE,YAAY,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAUF,KAAK,oBAAoB,GAAG,IAAI,GAAG;IACjC,eAAe,EAAE,YAAY,CAAC;IAC9B,KAAK,EAAE,YAAY,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,qBAAa,wBAAwB;;IASnC,MAAM,yCAA+C;IAErD,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAMD;;;;;;;;;;OAUG;IACH,oBAAoB,CAClB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,EAAE,EAAE,EAChB,oBAAoB,EAAE,MAAM,EAC5B,QAAQ,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC,CA8Bf;IAED;;;;;;;;;;OAUG;IACU,gBAAgB,CAC3B,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAwC/B;CACF"}
@@ -1,12 +1,15 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { createLogger } from '@aztec/foundation/log';
3
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
+ import { L2BlockHash } from '@aztec/stdlib/block';
6
+ import { TxHash } from '@aztec/stdlib/tx';
4
7
  /**
5
8
  * Stores decrypted private event logs.
6
9
  */ export class PrivateEventDataProvider {
7
10
  #store;
8
11
  /** Array storing the actual private event log entries containing the log content and block number */ #eventLogs;
9
- /** Map from contract_address_recipient_eventSelector to array of indices into #eventLogs for efficient lookup */ #eventLogIndex;
12
+ /** Map from contract_address_scope_eventSelector to array of indices into #eventLogs for efficient lookup */ #eventLogIndex;
10
13
  /** Map from eventCommitmentIndex to boolean indicating if log has been seen. */ #seenLogs;
11
14
  logger = createLogger('private_event_data_provider');
12
15
  constructor(store){
@@ -15,18 +18,23 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
15
18
  this.#eventLogIndex = this.#store.openMap('private_event_log_index');
16
19
  this.#seenLogs = this.#store.openMap('seen_logs');
17
20
  }
21
+ #keyFor(contractAddress, scope, eventSelector) {
22
+ return `${contractAddress.toString()}_${scope.toString()}_${eventSelector.toString()}`;
23
+ }
18
24
  /**
19
25
  * Store a private event log.
20
- * @param contractAddress - The address of the contract that emitted the event.
21
- * @param recipient - The recipient of the event.
22
26
  * @param eventSelector - The event selector of the event.
23
27
  * @param msgContent - The content of the event.
24
- * @param txHash - The transaction hash of the event log.
25
28
  * @param eventCommitmentIndex - The index of the event commitment in the nullifier tree.
26
- * @param blockNumber - The block number in which the event was emitted.
27
- */ storePrivateEventLog(contractAddress, recipient, eventSelector, msgContent, txHash, eventCommitmentIndex, blockNumber) {
29
+ * @param metadata
30
+ * contractAddress - The address of the contract that emitted the event.
31
+ * scope - The address to which the event is scoped.
32
+ * txHash - The transaction hash of the event log.
33
+ * blockNumber - The block number in which the event was emitted.
34
+ */ storePrivateEventLog(eventSelector, msgContent, eventCommitmentIndex, metadata) {
35
+ const { contractAddress, scope, txHash, l2BlockNumber, l2BlockHash } = metadata;
28
36
  return this.#store.transactionAsync(async ()=>{
29
- const key = `${contractAddress.toString()}_${recipient.toString()}_${eventSelector.toString()}`;
37
+ const key = this.#keyFor(contractAddress, scope, eventSelector);
30
38
  // Check if this exact log has already been stored using eventCommitmentIndex as unique identifier
31
39
  const hasBeenSeen = await this.#seenLogs.getAsync(eventCommitmentIndex);
32
40
  if (hasBeenSeen) {
@@ -38,15 +46,17 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
38
46
  }
39
47
  this.logger.verbose('storing private event log', {
40
48
  contractAddress,
41
- recipient,
49
+ scope,
42
50
  msgContent,
43
- blockNumber
51
+ l2BlockNumber
44
52
  });
45
53
  const index = await this.#eventLogs.lengthAsync();
46
54
  await this.#eventLogs.push({
47
55
  msgContent: serializeToBuffer(msgContent),
48
- blockNumber,
49
- eventCommitmentIndex
56
+ l2BlockNumber,
57
+ l2BlockHash: l2BlockHash.toBuffer(),
58
+ eventCommitmentIndex,
59
+ txHash: txHash.toBuffer()
50
60
  });
51
61
  const existingIndices = await this.#eventLogIndex.getAsync(key) || [];
52
62
  await this.#eventLogIndex.set(key, [
@@ -59,38 +69,47 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
59
69
  }
60
70
  /**
61
71
  * Returns the private events given search parameters.
62
- * @param contractAddress - The address of the contract to get events from.
63
- * @param from - The block number to search from.
64
- * @param numBlocks - The amount of blocks to search.
65
- * @param recipients - The addresses that decrypted the logs.
66
72
  * @param eventSelector - The event selector to filter by.
67
- * @returns - The event log contents.
68
- */ async getPrivateEvents(contractAddress, from, numBlocks, recipients, eventSelector) {
73
+ * @param filter - Filtering criteria:
74
+ * contractAddress: The address of the contract to get events from.
75
+ * fromBlock: The block number to search from (inclusive).
76
+ * toBlock: The block number to search upto (exclusive).
77
+ * scope: - The addresses that decrypted the logs.
78
+ * @returns - The event log contents, augmented with metadata about
79
+ * the transaction and block it the event was included in .
80
+ */ async getPrivateEvents(eventSelector, filter) {
69
81
  const events = [];
70
- for (const recipient of recipients){
71
- const key = `${contractAddress.toString()}_${recipient.toString()}_${eventSelector.toString()}`;
82
+ for (const scope of filter.scopes){
83
+ const key = this.#keyFor(filter.contractAddress, scope, eventSelector);
72
84
  const indices = await this.#eventLogIndex.getAsync(key) || [];
73
85
  for (const index of indices){
74
86
  const entry = await this.#eventLogs.atAsync(index);
75
- if (!entry || entry.blockNumber < from || entry.blockNumber >= from + numBlocks) {
87
+ if (!entry || entry.l2BlockNumber < filter.fromBlock || entry.l2BlockNumber >= filter.toBlock) {
76
88
  continue;
77
89
  }
78
90
  // Convert buffer back to Fr array
79
91
  const reader = BufferReader.asReader(entry.msgContent);
80
92
  const numFields = entry.msgContent.length / Fr.SIZE_IN_BYTES;
81
93
  const msgContent = reader.readArray(numFields, Fr);
94
+ const txHash = TxHash.fromBuffer(entry.txHash);
95
+ const l2BlockHash = L2BlockHash.fromBuffer(entry.l2BlockHash);
96
+ if (filter.txHash && !txHash.equals(filter.txHash)) {
97
+ continue;
98
+ }
82
99
  events.push({
83
- msgContent,
84
- blockNumber: entry.blockNumber,
85
- eventCommitmentIndex: entry.eventCommitmentIndex
100
+ eventCommitmentIndex: entry.eventCommitmentIndex,
101
+ event: {
102
+ packedEvent: msgContent,
103
+ l2BlockNumber: BlockNumber(entry.l2BlockNumber),
104
+ txHash,
105
+ l2BlockHash,
106
+ eventSelector
107
+ }
86
108
  });
87
109
  }
88
110
  }
89
111
  // Sort by eventCommitmentIndex only
90
112
  events.sort((a, b)=>a.eventCommitmentIndex - b.eventCommitmentIndex);
91
- return events.map((e)=>e.msgContent);
92
- }
93
- getSize() {
94
- return this.#eventLogs.lengthAsync();
113
+ return events.map((ev)=>ev.event);
95
114
  }
96
115
  }
@@ -1,2 +1,2 @@
1
1
  export { SyncDataProvider } from './sync_data_provider.js';
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL3N5bmNfZGF0YV9wcm92aWRlci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQyJ9
@@ -1,12 +1,11 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
3
  import { BlockHeader } from '@aztec/stdlib/tx';
3
- import type { DataProvider } from '../data_provider.js';
4
- export declare class SyncDataProvider implements DataProvider {
4
+ export declare class SyncDataProvider {
5
5
  #private;
6
6
  constructor(store: AztecAsyncKVStore);
7
7
  setHeader(header: BlockHeader): Promise<void>;
8
- getBlockNumber(): Promise<number>;
8
+ getBlockNumber(): Promise<BlockNumber>;
9
9
  getBlockHeader(): Promise<BlockHeader>;
10
- getSize(): Promise<number>;
11
10
  }
12
- //# sourceMappingURL=sync_data_provider.d.ts.map
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3luY19kYXRhX3Byb3ZpZGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvc3RvcmFnZS9zeW5jX2RhdGFfcHJvdmlkZXIvc3luY19kYXRhX3Byb3ZpZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ25FLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUF1QixNQUFNLGlCQUFpQixDQUFDO0FBQzlFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUUvQyxxQkFBYSxnQkFBZ0I7O0lBSTNCLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQUduQztJQUVLLFNBQVMsQ0FBQyxNQUFNLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FFbEQ7SUFFSyxjQUFjLElBQUksT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQU8zQztJQUVLLGNBQWMsSUFBSSxPQUFPLENBQUMsV0FBVyxDQUFDLENBTzNDO0NBQ0YifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"sync_data_provider.d.ts","sourceRoot":"","sources":["../../../src/storage/sync_data_provider/sync_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,qBAAa,gBAAiB,YAAW,YAAY;;gBAIvC,KAAK,EAAE,iBAAiB;IAK9B,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IASjC,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAStC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CAGjC"}
1
+ {"version":3,"file":"sync_data_provider.d.ts","sourceRoot":"","sources":["../../../src/storage/sync_data_provider/sync_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,gBAAgB;;IAI3B,YAAY,KAAK,EAAE,iBAAiB,EAGnC;IAEK,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAElD;IAEK,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAO3C;IAEK,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAO3C;CACF"}
@@ -23,7 +23,4 @@ export class SyncDataProvider {
23
23
  }
24
24
  return BlockHeader.fromBuffer(headerBuffer);
25
25
  }
26
- async getSize() {
27
- return (await this.#synchronizedHeader.getAsync())?.length ?? 0;
28
- }
29
26
  }