@aztec/pxe 3.0.0-canary.a9708bd → 3.0.0-devnet.20251212

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 +12 -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 +11 -11
  84. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  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 +9 -41
  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 +15 -23
  202. package/src/entrypoints/client/lazy/index.ts +3 -1
  203. package/src/entrypoints/client/lazy/utils.ts +14 -22
  204. package/src/entrypoints/pxe_creation_options.ts +2 -0
  205. package/src/entrypoints/server/index.ts +3 -1
  206. package/src/entrypoints/server/utils.ts +12 -56
  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
@@ -3,9 +3,7 @@ import type { AztecAsyncArray, AztecAsyncKVStore, AztecAsyncMap } from '@aztec/k
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { CompleteAddress } from '@aztec/stdlib/contract';
5
5
 
6
- import type { DataProvider } from '../data_provider.js';
7
-
8
- export class AddressDataProvider implements DataProvider {
6
+ export class AddressDataProvider {
9
7
  #store: AztecAsyncKVStore;
10
8
  #completeAddresses: AztecAsyncArray<Buffer>;
11
9
  #completeAddressIndex: AztecAsyncMap<string, number>;
@@ -64,8 +62,4 @@ export class AddressDataProvider implements DataProvider {
64
62
  (await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
65
63
  );
66
64
  }
67
-
68
- async getSize(): Promise<number> {
69
- return (await this.#completeAddresses.lengthAsync()) * CompleteAddress.SIZE_IN_BYTES;
70
- }
71
65
  }
@@ -1,12 +1,9 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { toArray } from '@aztec/foundation/iterable';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
3
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
5
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
5
 
7
- import type { DataProvider } from '../data_provider.js';
8
-
9
- export class CapsuleDataProvider implements DataProvider {
6
+ export class CapsuleDataProvider {
10
7
  #store: AztecAsyncKVStore;
11
8
 
12
9
  // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
@@ -139,13 +136,6 @@ export class CapsuleDataProvider implements DataProvider {
139
136
  }
140
137
  });
141
138
  }
142
-
143
- public async getSize() {
144
- return (await toArray(this.#capsules.valuesAsync())).reduce(
145
- (sum, value) => sum + value.length * Fr.SIZE_IN_BYTES,
146
- 0,
147
- );
148
- }
149
139
  }
150
140
 
151
141
  function dbSlotToKey(contractAddress: AztecAddress, slot: Fr): string {
@@ -1,4 +1,5 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { FUNCTION_TREE_HEIGHT } from '@aztec/constants';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { toArray } from '@aztec/foundation/iterable';
3
4
  import type { MembershipWitness } from '@aztec/foundation/trees';
4
5
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
@@ -22,7 +23,6 @@ import {
22
23
  getContractClassFromArtifact,
23
24
  } from '@aztec/stdlib/contract';
24
25
 
25
- import type { DataProvider } from '../data_provider.js';
26
26
  import { PrivateFunctionsTree } from './private_functions_tree.js';
27
27
 
28
28
  /**
@@ -32,7 +32,7 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
32
32
  * to efficiently serve the requested data. It interacts with the ContractDatabase and AztecNode to fetch
33
33
  * the required information and facilitate cryptographic proof generation.
34
34
  */
35
- export class ContractDataProvider implements DataProvider {
35
+ export class ContractDataProvider {
36
36
  /** Map from contract class id to private function tree. */
37
37
  // TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
38
38
  #privateFunctionTrees: Map<string, PrivateFunctionsTree> = new Map();
@@ -184,23 +184,6 @@ export class ContractDataProvider implements DataProvider {
184
184
  return fnArtifact && { ...fnArtifact, contractName: artifact.name };
185
185
  }
186
186
 
187
- /**
188
- * Retrieves the artifact of a specified function within a given contract.
189
- * The function is identified by its name, which is unique within a contract.
190
- * Throws if the contract has not been added to the database.
191
- *
192
- * @param contractAddress - The AztecAddress representing the contract containing the function.
193
- * @param functionName - The name of the function.
194
- * @returns The corresponding function's artifact as an object
195
- */
196
- public async getFunctionArtifactByName(
197
- contractAddress: AztecAddress,
198
- functionName: string,
199
- ): Promise<FunctionArtifact | undefined> {
200
- const artifact = await this.#getContractArtifactByAddress(contractAddress);
201
- return artifact?.functions.find(fn => fn.name === functionName);
202
- }
203
-
204
187
  public async getFunctionAbi(
205
188
  contractAddress: AztecAddress,
206
189
  selector: FunctionSelector,
@@ -248,7 +231,7 @@ export class ContractDataProvider implements DataProvider {
248
231
  public async getFunctionMembershipWitness(
249
232
  contractClassId: Fr,
250
233
  selector: FunctionSelector,
251
- ): Promise<MembershipWitness<5> | undefined> {
234
+ ): Promise<MembershipWitness<typeof FUNCTION_TREE_HEIGHT> | undefined> {
252
235
  const tree = await this.#getPrivateFunctionTreeForClassId(contractClassId);
253
236
  return tree?.getFunctionMembershipWitness(selector);
254
237
  }
@@ -264,12 +247,6 @@ export class ContractDataProvider implements DataProvider {
264
247
  return `${artifact?.name ?? contractAddress}:${fnArtifact?.name ?? selector}`;
265
248
  }
266
249
 
267
- public async getSize() {
268
- return (await toArray(this.#contractInstances.valuesAsync()))
269
- .concat(await toArray(this.#contractArtifacts.valuesAsync()))
270
- .reduce((sum, value) => sum + value.length, 0);
271
- }
272
-
273
250
  async #findFunctionArtifactBySelector(
274
251
  artifact: ContractArtifact,
275
252
  selector: FunctionSelector,
@@ -1,5 +1,5 @@
1
1
  import { FUNCTION_TREE_HEIGHT } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { assertLength } from '@aztec/foundation/serialize';
4
4
  import { MembershipWitness, type MerkleTree } from '@aztec/foundation/trees';
5
5
  import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
@@ -4,6 +4,5 @@ export * from './contract_data_provider/index.js';
4
4
  export * from './note_data_provider/index.js';
5
5
  export * from './sync_data_provider/index.js';
6
6
  export * from './tagging_data_provider/index.js';
7
- export * from './data_provider.js';
8
7
  export * from './metadata.js';
9
8
  export * from './private_event_data_provider/private_event_data_provider.js';
@@ -1,2 +1,2 @@
1
- export { NoteDao } from './note_dao.js';
1
+ export { NoteDao } from '@aztec/stdlib/note';
2
2
  export { NoteDataProvider } from './note_data_provider.js';
@@ -1,17 +1,20 @@
1
1
  import { toBufferBE } from '@aztec/foundation/bigint-buffer';
2
- import type { Fr } from '@aztec/foundation/fields';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
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
- import type { InBlock } from '@aztec/stdlib/block';
6
+ import type { DataInBlock } from '@aztec/stdlib/block';
7
7
  import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
8
-
9
- import type { DataProvider } from '../data_provider.js';
10
- import { NoteDao } from './note_dao.js';
11
-
12
- export class NoteDataProvider implements DataProvider {
8
+ import { NoteDao } from '@aztec/stdlib/note';
9
+
10
+ /**
11
+ * NoteDataProvider manages the storage and retrieval of notes.
12
+ *
13
+ * Notes can be active or nullified. This class processes new notes, nullifications,
14
+ * and performs rollback handling in the case of a reorg.
15
+ **/
16
+ export class NoteDataProvider {
13
17
  #store: AztecAsyncKVStore;
14
-
15
18
  #notes: AztecAsyncMap<string, Buffer>;
16
19
  #nullifiedNotes: AztecAsyncMap<string, Buffer>;
17
20
  #nullifierToNoteId: AztecAsyncMap<string, string>;
@@ -20,16 +23,12 @@ export class NoteDataProvider implements DataProvider {
20
23
  #nullifiedNotesToScope: AztecAsyncMultiMap<string, string>;
21
24
  #nullifiedNotesByContract: AztecAsyncMultiMap<string, string>;
22
25
  #nullifiedNotesByStorageSlot: AztecAsyncMultiMap<string, string>;
23
- #nullifiedNotesByTxHash: AztecAsyncMultiMap<string, string>;
24
- #nullifiedNotesByRecipient: AztecAsyncMultiMap<string, string>;
25
26
  #nullifiedNotesByNullifier: AztecAsyncMap<string, string>;
26
27
 
27
28
  #scopes: AztecAsyncMap<string, true>;
28
29
  #notesToScope: AztecAsyncMultiMap<string, string>;
29
30
  #notesByContractAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
30
31
  #notesByStorageSlotAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
31
- #notesByTxHashAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
32
- #notesByRecipientAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
33
32
 
34
33
  private constructor(store: AztecAsyncKVStore) {
35
34
  this.#store = store;
@@ -41,29 +40,41 @@ export class NoteDataProvider implements DataProvider {
41
40
  this.#nullifiedNotesToScope = store.openMultiMap('nullified_notes_to_scope');
42
41
  this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
43
42
  this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
44
- this.#nullifiedNotesByTxHash = store.openMultiMap('nullified_notes_by_tx_hash');
45
- this.#nullifiedNotesByRecipient = store.openMultiMap('nullified_notes_by_recipient');
46
43
  this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
47
44
 
48
45
  this.#scopes = store.openMap('scopes');
49
46
  this.#notesToScope = store.openMultiMap('notes_to_scope');
50
47
  this.#notesByContractAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
51
48
  this.#notesByStorageSlotAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
52
- this.#notesByTxHashAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
53
- this.#notesByRecipientAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
54
49
  }
55
50
 
51
+ /**
52
+ * Creates and initializes a new NoteDataProvider instance.
53
+ *
54
+ * This factory method creates a NoteDataProvider and restores any existing
55
+ * scope-specific indexes from the database.
56
+ *
57
+ * @param store - The key-value store to use for persistence
58
+ * @returns Promise resolving to a fully initialized NoteDataProvider instance
59
+ */
56
60
  public static async create(store: AztecAsyncKVStore): Promise<NoteDataProvider> {
57
61
  const pxeDB = new NoteDataProvider(store);
58
62
  for await (const scope of pxeDB.#scopes.keysAsync()) {
59
63
  pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
60
64
  pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
61
- pxeDB.#notesByTxHashAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_tx_hash`));
62
- pxeDB.#notesByRecipientAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_recipient`));
63
65
  }
64
66
  return pxeDB;
65
67
  }
66
68
 
69
+ /**
70
+ * Adds a new scope to the note data provider.
71
+ *
72
+ * Scopes provide privacy isolation by creating separate indexes for each user.
73
+ * Each scope gets its own set of indexes for efficient note retrieval by various criteria.
74
+ *
75
+ * @param scope - The AztecAddress representing the scope/user to add
76
+ * @returns Promise resolving to true if scope was added, false if it already existed
77
+ */
67
78
  public async addScope(scope: AztecAddress): Promise<boolean> {
68
79
  const scopeString = scope.toString();
69
80
 
@@ -74,23 +85,27 @@ export class NoteDataProvider implements DataProvider {
74
85
  await this.#scopes.set(scopeString, true);
75
86
  this.#notesByContractAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_contract`));
76
87
  this.#notesByStorageSlotAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_storage_slot`));
77
- this.#notesByTxHashAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_tx_hash`));
78
- this.#notesByRecipientAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_recipient`));
79
88
 
80
89
  return true;
81
90
  }
82
91
 
83
- addNotes(notes: NoteDao[], scope: AztecAddress = AztecAddress.ZERO): Promise<void> {
92
+ /**
93
+ * Adds multiple notes to the data provider under the specified scope.
94
+ *
95
+ * Notes are stored using their index from the notes hash tree as the key, which provides
96
+ * uniqueness and maintains creation order. Each note is indexed by multiple criteria
97
+ * for efficient retrieval.
98
+ *
99
+ * @param notes - Notes to store
100
+ * @param scope - The scope (user/account) under which to store the notes
101
+ */
102
+ addNotes(notes: NoteDao[], scope: AztecAddress): Promise<void> {
84
103
  return this.#store.transactionAsync(async () => {
85
104
  if (!(await this.#scopes.hasAsync(scope.toString()))) {
86
105
  await this.addScope(scope);
87
106
  }
88
107
 
89
108
  for (const dao of notes) {
90
- // store notes by their index in the notes hash tree
91
- // this provides the uniqueness we need to store individual notes
92
- // and should also return notes in the order that they were created.
93
- // Had we stored them by their nullifier, they would be returned in random order
94
109
  const noteIndex = toBufferBE(dao.index, 32).toString('hex');
95
110
  await this.#notes.set(noteIndex, dao.toBuffer());
96
111
  await this.#notesToScope.set(noteIndex, scope.toString());
@@ -98,13 +113,34 @@ export class NoteDataProvider implements DataProvider {
98
113
 
99
114
  await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
100
115
  await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
101
- await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
102
- await this.#notesByRecipientAndScope.get(scope.toString())!.set(dao.recipient.toString(), noteIndex);
103
116
  }
104
117
  });
105
118
  }
106
119
 
107
- public removeNotesAfter(blockNumber: number): Promise<void> {
120
+ /**
121
+ * Synchronizes notes and nullifiers to a specific block number.
122
+ *
123
+ * This method ensures that the state of notes and nullifiers is consistent with the
124
+ * specified block number. It restores any notes that were nullified after the given block
125
+ * and deletes any active notes created after that block.
126
+ *
127
+ * @param blockNumber - The new chain tip after a reorg
128
+ * @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
129
+ */
130
+ public async rollbackNotesAndNullifiers(blockNumber: number, synchedBlockNumber: number): Promise<void> {
131
+ await this.#rewindNullifiersAfterBlock(blockNumber, synchedBlockNumber);
132
+ await this.#deleteActiveNotesAfterBlock(blockNumber);
133
+ }
134
+
135
+ /**
136
+ * Deletes (removes) all active notes created after the specified block number.
137
+ *
138
+ * Permanently delete notes from the active notes store, e.g. during a reorg.
139
+ * Note: This only affects #notes (active notes), not #nullifiedNotes.
140
+ *
141
+ * @param blockNumber - Notes created after this block number will be deleted
142
+ */
143
+ #deleteActiveNotesAfterBlock(blockNumber: number): Promise<void> {
108
144
  return this.#store.transactionAsync(async () => {
109
145
  const notes = await toArray(this.#notes.valuesAsync());
110
146
  for (const note of notes) {
@@ -116,8 +152,6 @@ export class NoteDataProvider implements DataProvider {
116
152
  await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
117
153
  const scopes = await toArray(this.#scopes.keysAsync());
118
154
  for (const scope of scopes) {
119
- await this.#notesByRecipientAndScope.get(scope)!.deleteValue(noteDao.recipient.toString(), noteIndex);
120
- await this.#notesByTxHashAndScope.get(scope)!.deleteValue(noteDao.txHash.toString(), noteIndex);
121
155
  await this.#notesByContractAndScope.get(scope)!.deleteValue(noteDao.contractAddress.toString(), noteIndex);
122
156
  await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(noteDao.storageSlot.toString(), noteIndex);
123
157
  }
@@ -126,12 +160,21 @@ export class NoteDataProvider implements DataProvider {
126
160
  });
127
161
  }
128
162
 
129
- public async unnullifyNotesAfter(blockNumber: number, synchedBlockNumber?: number): Promise<void> {
163
+ /**
164
+ * Rewinds nullifications after a given block number.
165
+ *
166
+ * This operation "unnullifies" notes, rolling back nullifications that occurred
167
+ * in orphaned blocks, e.g. during a reorg. The notes are restored to the
168
+ * active notes store and removed from the nullified store.
169
+ *
170
+ * @param blockNumber - Revert nullifications that occurred after this block
171
+ * @param synchedBlockNumber - Upper bound for the block range to process
172
+ */
173
+ async #rewindNullifiersAfterBlock(blockNumber: number, synchedBlockNumber: number): Promise<void> {
130
174
  await this.#store.transactionAsync(async () => {
131
175
  const nullifiersToUndo: string[] = [];
132
176
  const currentBlockNumber = blockNumber + 1;
133
- const maxBlockNumber = synchedBlockNumber ?? currentBlockNumber;
134
- for (let i = currentBlockNumber; i <= maxBlockNumber; i++) {
177
+ for (let i = currentBlockNumber; i <= synchedBlockNumber; i++) {
135
178
  nullifiersToUndo.push(...(await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i))));
136
179
  }
137
180
  const notesIndexesToReinsert = await Promise.all(
@@ -150,17 +193,17 @@ export class NoteDataProvider implements DataProvider {
150
193
  await this.#notes.set(noteIndex, dao.toBuffer());
151
194
  await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
152
195
 
153
- let scopes = (await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex))) ?? [];
196
+ const scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex));
154
197
 
155
198
  if (scopes.length === 0) {
156
- scopes = [dao.recipient.toString()];
199
+ // We should never run into this error because notes always have a scope assigned to them - either on initial
200
+ // insertion via `addNotes` or when removing their nullifiers.
201
+ throw new Error(`No scopes found for nullified note with index ${noteIndex}`);
157
202
  }
158
203
 
159
204
  for (const scope of scopes) {
160
205
  await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
161
206
  await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
162
- await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
163
- await this.#notesByRecipientAndScope.get(scope.toString())!.set(dao.recipient.toString(), noteIndex);
164
207
  await this.#notesToScope.set(noteIndex, scope);
165
208
  }
166
209
 
@@ -169,16 +212,33 @@ export class NoteDataProvider implements DataProvider {
169
212
  await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
170
213
  await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
171
214
  await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
172
- await this.#nullifiedNotesByTxHash.deleteValue(dao.txHash.toString(), noteIndex);
173
- await this.#nullifiedNotesByRecipient.deleteValue(dao.recipient.toString(), noteIndex);
174
215
  await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
175
216
  }
176
217
  });
177
218
  }
178
219
 
220
+ /**
221
+ * Retrieves notes based on the provided filter criteria.
222
+ *
223
+ * This method queries both active and optionally nullified notes based on the filter
224
+ * parameters.
225
+ *
226
+ * @param filter - Filter criteria including contractAddress (required), and optional
227
+ * owner, storageSlot, status, scopes, and siloedNullifier.
228
+ * @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
229
+ * returned once if this is the case)
230
+ * @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
231
+ */
179
232
  async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
180
233
  filter.status = filter.status ?? NoteStatus.ACTIVE;
181
234
 
235
+ // throw early if scopes is an empty array
236
+ if (filter.scopes !== undefined && filter.scopes.length === 0) {
237
+ throw new Error(
238
+ 'Trying to get notes with an empty scopes array. Scopes have to be set to undefined if intending on not filtering by scopes.',
239
+ );
240
+ }
241
+
182
242
  const candidateNoteSources = [];
183
243
 
184
244
  filter.scopes ??= (await toArray(this.#scopes.keysAsync())).map(addressString =>
@@ -190,29 +250,19 @@ export class NoteDataProvider implements DataProvider {
190
250
  for (const scope of new Set(filter.scopes)) {
191
251
  const formattedScopeString = scope.toString();
192
252
  if (!(await this.#scopes.hasAsync(formattedScopeString))) {
193
- throw new Error('Trying to get incoming notes of an scope that is not in the PXE database');
253
+ throw new Error('Trying to get incoming notes of a scope that is not in the PXE database');
194
254
  }
195
255
 
196
256
  activeNoteIdsPerScope.push(
197
- filter.recipient
257
+ filter.storageSlot
198
258
  ? await toArray(
199
- this.#notesByRecipientAndScope.get(formattedScopeString)!.getValuesAsync(filter.recipient.toString()),
259
+ this.#notesByStorageSlotAndScope.get(formattedScopeString)!.getValuesAsync(filter.storageSlot.toString()),
200
260
  )
201
- : filter.txHash
202
- ? await toArray(
203
- this.#notesByTxHashAndScope.get(formattedScopeString)!.getValuesAsync(filter.txHash.toString()),
204
- )
205
- : filter.storageSlot
206
- ? await toArray(
207
- this.#notesByStorageSlotAndScope
208
- .get(formattedScopeString)!
209
- .getValuesAsync(filter.storageSlot.toString()),
210
- )
211
- : await toArray(
212
- this.#notesByContractAndScope
213
- .get(formattedScopeString)!
214
- .getValuesAsync(filter.contractAddress.toString()),
215
- ),
261
+ : await toArray(
262
+ this.#notesByContractAndScope
263
+ .get(formattedScopeString)!
264
+ .getValuesAsync(filter.contractAddress.toString()),
265
+ ),
216
266
  );
217
267
  }
218
268
 
@@ -221,17 +271,28 @@ export class NoteDataProvider implements DataProvider {
221
271
  notes: this.#notes,
222
272
  });
223
273
 
224
- if (filter.status == NoteStatus.ACTIVE_OR_NULLIFIED) {
225
- candidateNoteSources.push({
226
- ids: filter.recipient
227
- ? await toArray(this.#nullifiedNotesByRecipient.getValuesAsync(filter.recipient.toString()))
228
- : filter.txHash
229
- ? await toArray(this.#nullifiedNotesByTxHash.getValuesAsync(filter.txHash.toString()))
230
- : filter.storageSlot
231
- ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
232
- : await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString())),
233
- notes: this.#nullifiedNotes,
234
- });
274
+ // If status is ACTIVE_OR_NULLIFIED we add nullified notes as candidates on top of the default active ones.
275
+ if (filter.status === NoteStatus.ACTIVE_OR_NULLIFIED) {
276
+ const nullifiedIds = filter.storageSlot
277
+ ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString()))
278
+ : await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString()));
279
+
280
+ const setOfScopes = new Set(filter.scopes.map(s => s.toString() as string));
281
+ const filteredNullifiedIds = new Set<string>();
282
+
283
+ for (const noteId of nullifiedIds) {
284
+ const scopeList = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteId));
285
+ if (scopeList.some(scope => setOfScopes.has(scope))) {
286
+ filteredNullifiedIds.add(noteId);
287
+ }
288
+ }
289
+
290
+ if (filteredNullifiedIds.size > 0) {
291
+ candidateNoteSources.push({
292
+ ids: filteredNullifiedIds,
293
+ notes: this.#nullifiedNotes,
294
+ });
295
+ }
235
296
  }
236
297
 
237
298
  const result: NoteDao[] = [];
@@ -247,7 +308,7 @@ export class NoteDataProvider implements DataProvider {
247
308
  continue;
248
309
  }
249
310
 
250
- if (filter.txHash && !note.txHash.equals(filter.txHash)) {
311
+ if (filter.owner && !note.owner.equals(filter.owner)) {
251
312
  continue;
252
313
  }
253
314
 
@@ -255,10 +316,6 @@ export class NoteDataProvider implements DataProvider {
255
316
  continue;
256
317
  }
257
318
 
258
- if (filter.recipient && !note.recipient.equals(filter.recipient)) {
259
- continue;
260
- }
261
-
262
319
  if (filter.siloedNullifier && !note.siloedNullifier.equals(filter.siloedNullifier)) {
263
320
  continue;
264
321
  }
@@ -267,10 +324,29 @@ export class NoteDataProvider implements DataProvider {
267
324
  }
268
325
  }
269
326
 
270
- return result;
327
+ // A note might be present in multiple scopes - we ensure it is only returned once
328
+ const deduplicated: NoteDao[] = [];
329
+ for (const note of result) {
330
+ if (!deduplicated.some(existing => existing.equals(note))) {
331
+ deduplicated.push(note);
332
+ }
333
+ }
334
+
335
+ return deduplicated;
271
336
  }
272
337
 
273
- removeNullifiedNotes(nullifiers: InBlock<Fr>[], recipient: AztecAddress): Promise<NoteDao[]> {
338
+ /**
339
+ * Transitions notes from "active" to "nullified" state.
340
+ *
341
+ * This operation processes a batch of nullifiers to mark the corresponding notes
342
+ * as spent/nullified. The operation is atomic - if any nullifier is not found,
343
+ * the entire operation fails and no notes are modified.
344
+ *
345
+ * @param nullifiers - Array of nullifiers with their block numbers to process
346
+ * @returns Promise resolving to array of nullified NoteDao objects
347
+ * @throws Error if any nullifier is not found in the active notes
348
+ */
349
+ applyNullifiers(nullifiers: DataInBlock<Fr>[]): Promise<NoteDao[]> {
274
350
  if (nullifiers.length === 0) {
275
351
  return Promise.resolve([]);
276
352
  }
@@ -280,22 +356,33 @@ export class NoteDataProvider implements DataProvider {
280
356
 
281
357
  for (const blockScopedNullifier of nullifiers) {
282
358
  const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier;
283
- const noteIndex = await this.#nullifierToNoteId.getAsync(nullifier.toString());
359
+ const nullifierKey = nullifier.toString();
360
+
361
+ const noteIndex = await this.#nullifierToNoteId.getAsync(nullifierKey);
284
362
  if (!noteIndex) {
285
- throw new Error('Nullifier not found in removeNullifiedNotes');
363
+ // Check if already nullified?
364
+ const alreadyNullified = await this.#nullifiedNotesByNullifier.getAsync(nullifierKey);
365
+ if (alreadyNullified) {
366
+ throw new Error(`Nullifier already applied in applyNullifiers`);
367
+ }
368
+ throw new Error('Nullifier not found in applyNullifiers');
286
369
  }
287
370
 
288
371
  const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
289
372
 
290
373
  if (!noteBuffer) {
291
- throw new Error('Note not found in removeNullifiedNotes');
374
+ throw new Error('Note not found in applyNullifiers');
292
375
  }
293
- const noteScopes = (await toArray(this.#notesToScope.getValuesAsync(noteIndex))) ?? [];
294
- const note = NoteDao.fromBuffer(noteBuffer);
295
- if (!note.recipient.equals(recipient)) {
296
- throw new Error("Tried to nullify someone else's note");
376
+
377
+ const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex));
378
+ if (noteScopes.length === 0) {
379
+ // We should never run into this error because notes always have a scope assigned to them - either on initial
380
+ // insertion via `addNotes` or when removing their nullifiers.
381
+ throw new Error('Note scopes are missing in applyNullifiers');
297
382
  }
298
383
 
384
+ const note = NoteDao.fromBuffer(noteBuffer);
385
+
299
386
  nullifiedNotes.push(note);
300
387
 
301
388
  await this.#notes.delete(noteIndex);
@@ -304,23 +391,17 @@ export class NoteDataProvider implements DataProvider {
304
391
  const scopes = await toArray(this.#scopes.keysAsync());
305
392
 
306
393
  for (const scope of scopes) {
307
- await this.#notesByRecipientAndScope.get(scope)!.deleteValue(note.recipient.toString(), noteIndex);
308
- await this.#notesByTxHashAndScope.get(scope)!.deleteValue(note.txHash.toString(), noteIndex);
309
394
  await this.#notesByContractAndScope.get(scope)!.deleteValue(note.contractAddress.toString(), noteIndex);
310
395
  await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
311
396
  }
312
397
 
313
- if (noteScopes !== undefined) {
314
- for (const scope of noteScopes) {
315
- await this.#nullifiedNotesToScope.set(noteIndex, scope);
316
- }
398
+ for (const scope of noteScopes) {
399
+ await this.#nullifiedNotesToScope.set(noteIndex, scope);
317
400
  }
318
401
  await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
319
402
  await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
320
403
  await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
321
404
  await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
322
- await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
323
- await this.#nullifiedNotesByRecipient.set(note.recipient.toString(), noteIndex);
324
405
  await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
325
406
 
326
407
  await this.#nullifierToNoteId.delete(nullifier.toString());
@@ -328,23 +409,4 @@ export class NoteDataProvider implements DataProvider {
328
409
  return nullifiedNotes;
329
410
  });
330
411
  }
331
-
332
- async getSize() {
333
- const scopes = await toArray(this.#scopes.keysAsync());
334
- const contractAddresses = new Set<string>();
335
-
336
- // Collect all unique contract addresses across all scopes
337
- for (const scope of scopes) {
338
- const addresses = await toArray(this.#notesByContractAndScope.get(scope)!.keysAsync());
339
- addresses.forEach(addr => contractAddresses.add(addr));
340
- }
341
-
342
- // Get all notes for each contract address
343
- const allNotes = await Promise.all(
344
- Array.from(contractAddresses).map(addr => this.getNotes({ contractAddress: AztecAddress.fromString(addr) })),
345
- );
346
-
347
- // Reduce all notes to get total size
348
- return allNotes.flat().reduce((sum, note) => sum + note.getSize(), 0);
349
- }
350
412
  }