@aztec/pxe 0.0.1-commit.9593d84 → 0.0.1-commit.96bb3f7

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 (343) hide show
  1. package/dest/bin/check_oracle_version.js +105 -15
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +39 -0
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  4. package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +24 -23
  5. package/dest/block_synchronizer/index.d.ts +2 -0
  6. package/dest/block_synchronizer/index.d.ts.map +1 -0
  7. package/dest/block_synchronizer/index.js +1 -0
  8. package/dest/config/index.d.ts +4 -4
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/package_info.js +1 -1
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts +42 -12
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.js +50 -19
  14. package/dest/contract_function_simulator/execution_note_cache.d.ts +4 -3
  15. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/execution_note_cache.js +4 -3
  17. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +1 -1
  18. package/dest/contract_function_simulator/execution_tagging_index_cache.js +1 -1
  19. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  20. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  21. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -3
  22. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -2
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +5 -4
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
  27. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  28. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
  30. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +5 -4
  31. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -3
  33. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +2 -2
  34. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/noir-structs/utility_context.js +1 -1
  36. package/dest/contract_function_simulator/oracle/interfaces.d.ts +16 -13
  37. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -2
  39. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  41. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +7 -3
  42. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/note_packing_utils.js +7 -3
  44. package/dest/contract_function_simulator/oracle/oracle.d.ts +3 -3
  45. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/oracle/oracle.js +27 -15
  47. package/dest/contract_function_simulator/oracle/private_execution.d.ts +9 -10
  48. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/oracle/private_execution.js +13 -14
  50. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +27 -27
  51. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +32 -46
  53. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +59 -16
  54. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  55. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +149 -40
  56. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  57. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  58. package/dest/contract_function_simulator/pick_notes.js +1 -1
  59. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  60. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  61. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  62. package/dest/debug/pxe_debug_utils.d.ts +31 -0
  63. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  64. package/dest/debug/pxe_debug_utils.js +37 -0
  65. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  66. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  67. package/dest/entrypoints/client/bundle/index.js +0 -1
  68. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  69. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  70. package/dest/entrypoints/client/bundle/utils.js +12 -3
  71. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  72. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  73. package/dest/entrypoints/client/lazy/index.js +0 -1
  74. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  75. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  76. package/dest/entrypoints/client/lazy/utils.js +12 -3
  77. package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
  78. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  79. package/dest/entrypoints/server/index.d.ts +2 -2
  80. package/dest/entrypoints/server/index.d.ts.map +1 -1
  81. package/dest/entrypoints/server/index.js +1 -1
  82. package/dest/entrypoints/server/utils.d.ts +1 -1
  83. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  84. package/dest/entrypoints/server/utils.js +12 -8
  85. package/dest/error_enriching.d.ts +4 -4
  86. package/dest/error_enriching.d.ts.map +1 -1
  87. package/dest/error_enriching.js +6 -6
  88. package/dest/events/event_service.d.ts +15 -0
  89. package/dest/events/event_service.d.ts.map +1 -0
  90. package/dest/events/event_service.js +47 -0
  91. package/dest/events/index.d.ts +2 -0
  92. package/dest/events/index.d.ts.map +1 -0
  93. package/dest/events/index.js +1 -0
  94. package/dest/events/private_event_filter_validator.d.ts +9 -0
  95. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  96. package/dest/events/private_event_filter_validator.js +39 -0
  97. package/dest/job_coordinator/job_coordinator.d.ts +74 -0
  98. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  99. package/dest/job_coordinator/job_coordinator.js +93 -0
  100. package/dest/logs/log_service.d.ts +26 -0
  101. package/dest/logs/log_service.d.ts.map +1 -0
  102. package/dest/logs/log_service.js +120 -0
  103. package/dest/notes/index.d.ts +2 -0
  104. package/dest/notes/index.d.ts.map +1 -0
  105. package/dest/notes/index.js +1 -0
  106. package/dest/notes/note_service.d.ts +48 -0
  107. package/dest/notes/note_service.d.ts.map +1 -0
  108. package/dest/notes/note_service.js +152 -0
  109. package/dest/oracle_version.d.ts +2 -2
  110. package/dest/oracle_version.js +2 -2
  111. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +2 -2
  112. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  113. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +2 -2
  114. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  115. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  116. package/dest/private_kernel/private_kernel_execution_prover.js +7 -8
  117. package/dest/private_kernel/private_kernel_oracle.d.ts +5 -3
  118. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  119. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +8 -7
  120. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  121. package/dest/private_kernel/private_kernel_oracle_impl.js +9 -10
  122. package/dest/public_storage/public_storage_service.d.ts +24 -0
  123. package/dest/public_storage/public_storage_service.d.ts.map +1 -0
  124. package/dest/public_storage/public_storage_service.js +26 -0
  125. package/dest/pxe.d.ts +39 -46
  126. package/dest/pxe.d.ts.map +1 -1
  127. package/dest/pxe.js +165 -154
  128. package/dest/storage/address_store/address_store.d.ts +11 -0
  129. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  130. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +1 -1
  131. package/dest/storage/address_store/index.d.ts +2 -0
  132. package/dest/storage/address_store/index.d.ts.map +1 -0
  133. package/dest/storage/address_store/index.js +1 -0
  134. package/dest/storage/{sync_data_provider/sync_data_provider.d.ts → anchor_block_store/anchor_block_store.d.ts} +2 -3
  135. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  136. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +2 -9
  137. package/dest/storage/{sync_data_provider → anchor_block_store}/index.d.ts +2 -2
  138. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  139. package/dest/storage/anchor_block_store/index.js +1 -0
  140. package/dest/storage/capsule_store/capsule_store.d.ts +57 -0
  141. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  142. package/dest/storage/{capsule_data_provider/capsule_data_provider.js → capsule_store/capsule_store.js} +34 -6
  143. package/dest/storage/capsule_store/index.d.ts +2 -0
  144. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  145. package/dest/storage/capsule_store/index.js +1 -0
  146. package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +8 -5
  147. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  148. package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +46 -3
  149. package/dest/storage/contract_store/index.d.ts +2 -0
  150. package/dest/storage/contract_store/index.d.ts.map +1 -0
  151. package/dest/storage/contract_store/index.js +1 -0
  152. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  153. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  154. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  155. package/dest/storage/index.d.ts +8 -8
  156. package/dest/storage/index.d.ts.map +1 -1
  157. package/dest/storage/index.js +7 -7
  158. package/dest/storage/note_store/index.d.ts +3 -0
  159. package/dest/storage/note_store/index.d.ts.map +1 -0
  160. package/dest/storage/note_store/index.js +2 -0
  161. package/dest/storage/{note_data_provider/note_data_provider.d.ts → note_store/note_store.d.ts} +13 -12
  162. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  163. package/dest/storage/{note_data_provider/note_data_provider.js → note_store/note_store.js} +20 -9
  164. package/dest/storage/private_event_store/private_event_store.d.ts +56 -0
  165. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  166. package/dest/storage/private_event_store/private_event_store.js +158 -0
  167. package/dest/storage/tagging_store/index.d.ts +4 -0
  168. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  169. package/dest/storage/tagging_store/index.js +3 -0
  170. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +21 -0
  171. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  172. package/dest/storage/tagging_store/recipient_tagging_store.js +42 -0
  173. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  174. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  175. package/dest/storage/tagging_store/sender_address_book_store.js +30 -0
  176. package/dest/storage/tagging_store/sender_tagging_store.d.ts +67 -0
  177. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  178. package/dest/storage/tagging_store/sender_tagging_store.js +196 -0
  179. package/dest/tagging/constants.d.ts +2 -2
  180. package/dest/tagging/constants.d.ts.map +1 -1
  181. package/dest/tagging/constants.js +10 -2
  182. package/dest/tagging/index.d.ts +15 -6
  183. package/dest/tagging/index.d.ts.map +1 -1
  184. package/dest/tagging/index.js +14 -5
  185. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  186. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  187. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  188. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  189. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  190. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  191. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  192. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  193. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +29 -0
  194. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +20 -0
  195. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  196. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  197. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  198. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  199. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +32 -0
  200. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
  201. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  202. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +55 -0
  203. package/dest/tree_membership/tree_membership_service.d.ts +52 -0
  204. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
  205. package/dest/tree_membership/tree_membership_service.js +84 -0
  206. package/package.json +17 -17
  207. package/src/bin/check_oracle_version.ts +130 -20
  208. package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +23 -23
  209. package/src/block_synchronizer/index.ts +1 -0
  210. package/src/config/index.ts +3 -3
  211. package/src/config/package_info.ts +1 -1
  212. package/src/contract_function_simulator/contract_function_simulator.ts +93 -19
  213. package/src/contract_function_simulator/execution_note_cache.ts +7 -3
  214. package/src/contract_function_simulator/execution_tagging_index_cache.ts +1 -1
  215. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  216. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +5 -1
  217. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
  218. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  219. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +5 -2
  220. package/src/contract_function_simulator/noir-structs/utility_context.ts +1 -1
  221. package/src/contract_function_simulator/oracle/interfaces.ts +15 -10
  222. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  223. package/src/contract_function_simulator/oracle/note_packing_utils.ts +17 -3
  224. package/src/contract_function_simulator/oracle/oracle.ts +33 -11
  225. package/src/contract_function_simulator/oracle/private_execution.ts +17 -17
  226. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +101 -58
  227. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +225 -47
  228. package/src/contract_function_simulator/pick_notes.ts +1 -1
  229. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  230. package/src/debug/pxe_debug_utils.ts +48 -0
  231. package/src/entrypoints/client/bundle/index.ts +0 -1
  232. package/src/entrypoints/client/bundle/utils.ts +9 -3
  233. package/src/entrypoints/client/lazy/index.ts +0 -1
  234. package/src/entrypoints/client/lazy/utils.ts +9 -4
  235. package/src/entrypoints/pxe_creation_options.ts +4 -1
  236. package/src/entrypoints/server/index.ts +1 -1
  237. package/src/entrypoints/server/utils.ts +12 -16
  238. package/src/error_enriching.ts +7 -15
  239. package/src/events/event_service.ts +79 -0
  240. package/src/events/index.ts +1 -0
  241. package/src/events/private_event_filter_validator.ts +48 -0
  242. package/src/job_coordinator/job_coordinator.ts +149 -0
  243. package/src/logs/log_service.ts +202 -0
  244. package/src/notes/index.ts +1 -0
  245. package/src/notes/note_service.ts +200 -0
  246. package/src/oracle_version.ts +2 -2
  247. package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +2 -3
  248. package/src/private_kernel/private_kernel_execution_prover.ts +7 -8
  249. package/src/private_kernel/private_kernel_oracle.ts +4 -2
  250. package/src/private_kernel/private_kernel_oracle_impl.ts +12 -17
  251. package/src/public_storage/public_storage_service.ts +33 -0
  252. package/src/pxe.ts +214 -188
  253. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +1 -1
  254. package/src/storage/address_store/index.ts +1 -0
  255. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +2 -11
  256. package/src/storage/anchor_block_store/index.ts +1 -0
  257. package/src/storage/{capsule_data_provider/capsule_data_provider.ts → capsule_store/capsule_store.ts} +34 -2
  258. package/src/storage/capsule_store/index.ts +1 -0
  259. package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +65 -3
  260. package/src/storage/contract_store/index.ts +1 -0
  261. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  262. package/src/storage/index.ts +7 -7
  263. package/src/storage/note_store/index.ts +2 -0
  264. package/src/storage/{note_data_provider/note_data_provider.ts → note_store/note_store.ts} +26 -13
  265. package/src/storage/private_event_store/private_event_store.ts +216 -0
  266. package/src/storage/tagging_store/index.ts +3 -0
  267. package/src/storage/tagging_store/recipient_tagging_store.ts +53 -0
  268. package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
  269. package/src/storage/tagging_store/sender_tagging_store.ts +244 -0
  270. package/src/tagging/constants.ts +10 -2
  271. package/src/tagging/index.ts +17 -5
  272. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +132 -0
  273. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  274. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +43 -0
  275. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +96 -0
  276. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +48 -0
  277. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +72 -0
  278. package/src/tree_membership/tree_membership_service.ts +112 -0
  279. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -265
  280. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  281. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  282. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -122
  283. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  284. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -694
  285. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  286. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  287. package/dest/storage/address_data_provider/index.d.ts +0 -2
  288. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  289. package/dest/storage/address_data_provider/index.js +0 -1
  290. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -25
  291. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  292. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  293. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  294. package/dest/storage/capsule_data_provider/index.js +0 -1
  295. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  296. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  297. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  298. package/dest/storage/contract_data_provider/index.js +0 -1
  299. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  300. package/dest/storage/note_data_provider/index.d.ts +0 -3
  301. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  302. package/dest/storage/note_data_provider/index.js +0 -2
  303. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  304. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
  305. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  306. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -105
  307. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  308. package/dest/storage/sync_data_provider/index.js +0 -1
  309. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  310. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  311. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  312. package/dest/storage/tagging_data_provider/index.js +0 -1
  313. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -40
  314. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  315. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -89
  316. package/dest/synchronizer/index.d.ts +0 -2
  317. package/dest/synchronizer/index.d.ts.map +0 -1
  318. package/dest/synchronizer/index.js +0 -1
  319. package/dest/synchronizer/synchronizer.d.ts +0 -35
  320. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  321. package/dest/tagging/siloed_tag.d.ts +0 -14
  322. package/dest/tagging/siloed_tag.d.ts.map +0 -1
  323. package/dest/tagging/siloed_tag.js +0 -20
  324. package/dest/tagging/tag.d.ts +0 -12
  325. package/dest/tagging/tag.d.ts.map +0 -1
  326. package/dest/tagging/tag.js +0 -17
  327. package/dest/tagging/utils.d.ts +0 -18
  328. package/dest/tagging/utils.d.ts.map +0 -1
  329. package/dest/tagging/utils.js +0 -24
  330. package/src/contract_function_simulator/execution_data_provider.ts +0 -333
  331. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1008
  332. package/src/storage/address_data_provider/index.ts +0 -1
  333. package/src/storage/capsule_data_provider/index.ts +0 -1
  334. package/src/storage/contract_data_provider/index.ts +0 -1
  335. package/src/storage/note_data_provider/index.ts +0 -2
  336. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -143
  337. package/src/storage/sync_data_provider/index.ts +0 -1
  338. package/src/storage/tagging_data_provider/index.ts +0 -1
  339. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
  340. package/src/synchronizer/index.ts +0 -1
  341. package/src/tagging/siloed_tag.ts +0 -22
  342. package/src/tagging/tag.ts +0 -16
  343. package/src/tagging/utils.ts +0 -31
@@ -0,0 +1,56 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
3
+ import type { EventSelector } from '@aztec/stdlib/abi';
4
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import { type InTx, TxHash } from '@aztec/stdlib/tx';
6
+ import type { PackedPrivateEvent } from '../../pxe.js';
7
+ export type PrivateEventStoreFilter = {
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
+ };
18
+ /**
19
+ * Stores decrypted private event logs.
20
+ */
21
+ export declare class PrivateEventStore {
22
+ #private;
23
+ logger: import("@aztec/foundation/log").Logger;
24
+ constructor(store: AztecAsyncKVStore);
25
+ /**
26
+ * Store a private event log.
27
+ * @param eventSelector - The event selector of the event.
28
+ * @param msgContent - The content of the event.
29
+ * @param eventCommitmentIndex - The index of the event commitment in the nullifier tree.
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.
35
+ */
36
+ storePrivateEventLog(eventSelector: EventSelector, randomness: Fr, msgContent: Fr[], eventCommitmentIndex: number, metadata: PrivateEventMetadata): Promise<void>;
37
+ /**
38
+ * Returns the private events given search parameters.
39
+ * @param eventSelector - The event selector to filter by.
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 .
47
+ */
48
+ getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventStoreFilter): Promise<PackedPrivateEvent[]>;
49
+ /**
50
+ * Rolls back private events that were stored after a given `blockNumber` and up to `synchedBlockNumber` (the block
51
+ * number up to which PXE managed to sync before the reorg happened).
52
+ */
53
+ rollbackEventsAfterBlock(blockNumber: number, synchedBlockNumber: number): Promise<void>;
54
+ }
55
+ export {};
56
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJpdmF0ZV9ldmVudF9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvcHJpdmF0ZV9ldmVudF9zdG9yZS9wcml2YXRlX2V2ZW50X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUdwRCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUN2RCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUVoRSxPQUFPLEVBQUUsS0FBSyxJQUFJLEVBQUUsTUFBTSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFckQsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFFdkQsTUFBTSxNQUFNLHVCQUF1QixHQUFHO0lBQ3BDLGVBQWUsRUFBRSxZQUFZLENBQUM7SUFDOUIsU0FBUyxFQUFFLE1BQU0sQ0FBQztJQUNsQixPQUFPLEVBQUUsTUFBTSxDQUFDO0lBQ2hCLE1BQU0sRUFBRSxZQUFZLEVBQUUsQ0FBQztJQUN2QixNQUFNLENBQUMsRUFBRSxNQUFNLENBQUM7Q0FDakIsQ0FBQztBQWFGLEtBQUssb0JBQW9CLEdBQUcsSUFBSSxHQUFHO0lBQ2pDLGVBQWUsRUFBRSxZQUFZLENBQUM7SUFDOUIsS0FBSyxFQUFFLFlBQVksQ0FBQztDQUNyQixDQUFDO0FBRUY7O0dBRUc7QUFDSCxxQkFBYSxpQkFBaUI7O0lBVzVCLE1BQU0seUNBQXVDO0lBRTdDLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQU1uQztJQU1EOzs7Ozs7Ozs7O09BVUc7SUFDSCxvQkFBb0IsQ0FDbEIsYUFBYSxFQUFFLGFBQWEsRUFDNUIsVUFBVSxFQUFFLEVBQUUsRUFDZCxVQUFVLEVBQUUsRUFBRSxFQUFFLEVBQ2hCLG9CQUFvQixFQUFFLE1BQU0sRUFDNUIsUUFBUSxFQUFFLG9CQUFvQixHQUM3QixPQUFPLENBQUMsSUFBSSxDQUFDLENBa0NmO0lBRUQ7Ozs7Ozs7Ozs7T0FVRztJQUNVLGdCQUFnQixDQUMzQixhQUFhLEVBQUUsYUFBYSxFQUM1QixNQUFNLEVBQUUsdUJBQXVCLEdBQzlCLE9BQU8sQ0FBQyxrQkFBa0IsRUFBRSxDQUFDLENBd0MvQjtJQUVEOzs7T0FHRztJQUNVLHdCQUF3QixDQUFDLFdBQVcsRUFBRSxNQUFNLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FxQ3BHO0NBQ0YifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private_event_store.d.ts","sourceRoot":"","sources":["../../../src/storage/private_event_store/private_event_store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAGpD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,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,uBAAuB,GAAG;IACpC,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;AAaF,KAAK,oBAAoB,GAAG,IAAI,GAAG;IACjC,eAAe,EAAE,YAAY,CAAC;IAC9B,KAAK,EAAE,YAAY,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,qBAAa,iBAAiB;;IAW5B,MAAM,yCAAuC;IAE7C,YAAY,KAAK,EAAE,iBAAiB,EAMnC;IAMD;;;;;;;;;;OAUG;IACH,oBAAoB,CAClB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,EAAE,EACd,UAAU,EAAE,EAAE,EAAE,EAChB,oBAAoB,EAAE,MAAM,EAC5B,QAAQ,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAkCf;IAED;;;;;;;;;;OAUG;IACU,gBAAgB,CAC3B,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAwC/B;IAED;;;OAGG;IACU,wBAAwB,CAAC,WAAW,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCpG;CACF"}
@@ -0,0 +1,158 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
+ import { L2BlockHash } from '@aztec/stdlib/block';
6
+ import { TxHash } from '@aztec/stdlib/tx';
7
+ /**
8
+ * Stores decrypted private event logs.
9
+ */ export class PrivateEventStore {
10
+ #store;
11
+ /** Map storing the actual private event log entries, keyed by eventCommitmentIndex */ #eventLogs;
12
+ /** Map from contractAddress_scope_eventSelector to eventCommitmentIndex[] for efficient lookup */ #eventsByContractScopeSelector;
13
+ /** Map from block number to eventCommitmentIndex[] for rollback support */ #eventsByBlockNumber;
14
+ /** Map from eventCommitmentIndex to boolean indicating if log has been seen. */ #seenLogs;
15
+ logger = createLogger('private_event_store');
16
+ constructor(store){
17
+ this.#store = store;
18
+ this.#eventLogs = this.#store.openMap('private_event_logs');
19
+ this.#eventsByContractScopeSelector = this.#store.openMap('events_by_contract_scope_selector');
20
+ this.#seenLogs = this.#store.openMap('seen_logs');
21
+ this.#eventsByBlockNumber = this.#store.openMap('events_by_block_number');
22
+ }
23
+ #keyFor(contractAddress, scope, eventSelector) {
24
+ return `${contractAddress.toString()}_${scope.toString()}_${eventSelector.toString()}`;
25
+ }
26
+ /**
27
+ * Store a private event log.
28
+ * @param eventSelector - The event selector of the event.
29
+ * @param msgContent - The content of the event.
30
+ * @param eventCommitmentIndex - The index of the event commitment in the nullifier tree.
31
+ * @param metadata
32
+ * contractAddress - The address of the contract that emitted the event.
33
+ * scope - The address to which the event is scoped.
34
+ * txHash - The transaction hash of the event log.
35
+ * blockNumber - The block number in which the event was emitted.
36
+ */ storePrivateEventLog(eventSelector, randomness, msgContent, eventCommitmentIndex, metadata) {
37
+ const { contractAddress, scope, txHash, l2BlockNumber, l2BlockHash } = metadata;
38
+ return this.#store.transactionAsync(async ()=>{
39
+ const key = this.#keyFor(contractAddress, scope, eventSelector);
40
+ // Check if this exact log has already been stored using eventCommitmentIndex as unique identifier
41
+ const hasBeenSeen = await this.#seenLogs.getAsync(eventCommitmentIndex);
42
+ if (hasBeenSeen) {
43
+ this.logger.verbose('Ignoring duplicate event log', {
44
+ txHash: txHash.toString(),
45
+ eventCommitmentIndex
46
+ });
47
+ return;
48
+ }
49
+ this.logger.verbose('storing private event log', {
50
+ contractAddress,
51
+ scope,
52
+ msgContent,
53
+ l2BlockNumber
54
+ });
55
+ await this.#eventLogs.set(eventCommitmentIndex, {
56
+ randomness,
57
+ msgContent: serializeToBuffer(msgContent),
58
+ l2BlockNumber,
59
+ l2BlockHash: l2BlockHash.toBuffer(),
60
+ eventCommitmentIndex,
61
+ txHash: txHash.toBuffer(),
62
+ lookupKey: key
63
+ });
64
+ const existingIndices = await this.#eventsByContractScopeSelector.getAsync(key) || [];
65
+ await this.#eventsByContractScopeSelector.set(key, [
66
+ ...existingIndices,
67
+ eventCommitmentIndex
68
+ ]);
69
+ const existingBlockIndices = await this.#eventsByBlockNumber.getAsync(l2BlockNumber) || [];
70
+ await this.#eventsByBlockNumber.set(l2BlockNumber, [
71
+ ...existingBlockIndices,
72
+ eventCommitmentIndex
73
+ ]);
74
+ // Mark this log as seen using eventCommitmentIndex
75
+ await this.#seenLogs.set(eventCommitmentIndex, true);
76
+ });
77
+ }
78
+ /**
79
+ * Returns the private events given search parameters.
80
+ * @param eventSelector - The event selector to filter by.
81
+ * @param filter - Filtering criteria:
82
+ * contractAddress: The address of the contract to get events from.
83
+ * fromBlock: The block number to search from (inclusive).
84
+ * toBlock: The block number to search upto (exclusive).
85
+ * scope: - The addresses that decrypted the logs.
86
+ * @returns - The event log contents, augmented with metadata about
87
+ * the transaction and block it the event was included in .
88
+ */ async getPrivateEvents(eventSelector, filter) {
89
+ const events = [];
90
+ for (const scope of filter.scopes){
91
+ const key = this.#keyFor(filter.contractAddress, scope, eventSelector);
92
+ const eventCommitmentIndices = await this.#eventsByContractScopeSelector.getAsync(key) || [];
93
+ for (const eventCommitmentIndex of eventCommitmentIndices){
94
+ const entry = await this.#eventLogs.getAsync(eventCommitmentIndex);
95
+ if (!entry || entry.l2BlockNumber < filter.fromBlock || entry.l2BlockNumber >= filter.toBlock) {
96
+ continue;
97
+ }
98
+ // Convert buffer back to Fr array
99
+ const reader = BufferReader.asReader(entry.msgContent);
100
+ const numFields = entry.msgContent.length / Fr.SIZE_IN_BYTES;
101
+ const msgContent = reader.readArray(numFields, Fr);
102
+ const txHash = TxHash.fromBuffer(entry.txHash);
103
+ const l2BlockHash = L2BlockHash.fromBuffer(entry.l2BlockHash);
104
+ if (filter.txHash && !txHash.equals(filter.txHash)) {
105
+ continue;
106
+ }
107
+ events.push({
108
+ eventCommitmentIndex: entry.eventCommitmentIndex,
109
+ event: {
110
+ packedEvent: msgContent,
111
+ l2BlockNumber: BlockNumber(entry.l2BlockNumber),
112
+ txHash,
113
+ l2BlockHash,
114
+ eventSelector
115
+ }
116
+ });
117
+ }
118
+ }
119
+ // Sort by eventCommitmentIndex only
120
+ events.sort((a, b)=>a.eventCommitmentIndex - b.eventCommitmentIndex);
121
+ return events.map((ev)=>ev.event);
122
+ }
123
+ /**
124
+ * Rolls back private events that were stored after a given `blockNumber` and up to `synchedBlockNumber` (the block
125
+ * number up to which PXE managed to sync before the reorg happened).
126
+ */ async rollbackEventsAfterBlock(blockNumber, synchedBlockNumber) {
127
+ await this.#store.transactionAsync(async ()=>{
128
+ let removedCount = 0;
129
+ for(let block = blockNumber + 1; block <= synchedBlockNumber; block++){
130
+ const indices = await this.#eventsByBlockNumber.getAsync(block);
131
+ if (indices) {
132
+ await this.#eventsByBlockNumber.delete(block);
133
+ for (const eventCommitmentIndex of indices){
134
+ const entry = await this.#eventLogs.getAsync(eventCommitmentIndex);
135
+ if (!entry) {
136
+ throw new Error(`Event log not found for eventCommitmentIndex ${eventCommitmentIndex}`);
137
+ }
138
+ await this.#eventLogs.delete(eventCommitmentIndex);
139
+ await this.#seenLogs.delete(eventCommitmentIndex);
140
+ // Update #eventsByContractScopeSelector using the stored lookupKey
141
+ const existingIndices = await this.#eventsByContractScopeSelector.getAsync(entry.lookupKey);
142
+ if (!existingIndices || existingIndices.length === 0) {
143
+ throw new Error(`No indices found in #eventsByContractScopeSelector for key ${entry.lookupKey}`);
144
+ }
145
+ const filteredIndices = existingIndices.filter((idx)=>idx !== eventCommitmentIndex);
146
+ if (filteredIndices.length === 0) {
147
+ await this.#eventsByContractScopeSelector.delete(entry.lookupKey);
148
+ } else {
149
+ await this.#eventsByContractScopeSelector.set(entry.lookupKey, filteredIndices);
150
+ }
151
+ removedCount++;
152
+ }
153
+ }
154
+ }
155
+ this.logger.verbose(`Rolled back ${removedCount} private events after block ${blockNumber}`);
156
+ });
157
+ }
158
+ }
@@ -0,0 +1,4 @@
1
+ export { SenderTaggingStore } from './sender_tagging_store.js';
2
+ export { SenderAddressBookStore } from './sender_address_book_store.js';
3
+ export { RecipientTaggingStore } from './recipient_tagging_store.js';
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL3RhZ2dpbmdfc3RvcmUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFDL0QsT0FBTyxFQUFFLHNCQUFzQixFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDeEUsT0FBTyxFQUFFLHFCQUFxQixFQUFFLE1BQU0sOEJBQThCLENBQUMifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { SenderTaggingStore } from './sender_tagging_store.js';
2
+ export { SenderAddressBookStore } from './sender_address_book_store.js';
3
+ export { RecipientTaggingStore } from './recipient_tagging_store.js';
@@ -0,0 +1,21 @@
1
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
+ import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
3
+ /**
4
+ * Data provider of tagging data used when syncing the logs as a recipient. The sender counterpart of this class
5
+ * is called SenderTaggingStore. We have the providers separate for the sender and recipient because
6
+ * the algorithms are completely disjoint and there is not data reuse between the two.
7
+ *
8
+ * @dev Chain reorgs do not need to be handled here because both the finalized and aged indexes refer to finalized
9
+ * blocks, which by definition cannot be affected by reorgs.
10
+ *
11
+ * TODO(benesjan): Relocate to yarn-project/pxe/src/storage/tagging_store
12
+ */
13
+ export declare class RecipientTaggingStore {
14
+ #private;
15
+ constructor(store: AztecAsyncKVStore);
16
+ getHighestAgedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined>;
17
+ updateHighestAgedIndex(secret: DirectionalAppTaggingSecret, index: number): Promise<void>;
18
+ getHighestFinalizedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined>;
19
+ updateHighestFinalizedIndex(secret: DirectionalAppTaggingSecret, index: number): Promise<void>;
20
+ }
21
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVjaXBpZW50X3RhZ2dpbmdfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL3RhZ2dpbmdfc3RvcmUvcmVjaXBpZW50X3RhZ2dpbmdfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDeEUsT0FBTyxLQUFLLEVBQUUsMkJBQTJCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUV0RTs7Ozs7Ozs7O0dBU0c7QUFDSCxxQkFBYSxxQkFBcUI7O0lBTWhDLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQUtuQztJQUVELG1CQUFtQixDQUFDLE1BQU0sRUFBRSwyQkFBMkIsR0FBRyxPQUFPLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQyxDQUVwRjtJQUVLLHNCQUFzQixDQUFDLE1BQU0sRUFBRSwyQkFBMkIsRUFBRSxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FPOUY7SUFFRCx3QkFBd0IsQ0FBQyxNQUFNLEVBQUUsMkJBQTJCLEdBQUcsT0FBTyxDQUFDLE1BQU0sR0FBRyxTQUFTLENBQUMsQ0FFekY7SUFFSywyQkFBMkIsQ0FBQyxNQUFNLEVBQUUsMkJBQTJCLEVBQUUsS0FBSyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBUW5HO0NBQ0YifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recipient_tagging_store.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/recipient_tagging_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEtE;;;;;;;;;GASG;AACH,qBAAa,qBAAqB;;IAMhC,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAED,mBAAmB,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAEpF;IAEK,sBAAsB,CAAC,MAAM,EAAE,2BAA2B,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO9F;IAED,wBAAwB,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAEzF;IAEK,2BAA2B,CAAC,MAAM,EAAE,2BAA2B,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQnG;CACF"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Data provider of tagging data used when syncing the logs as a recipient. The sender counterpart of this class
3
+ * is called SenderTaggingStore. We have the providers separate for the sender and recipient because
4
+ * the algorithms are completely disjoint and there is not data reuse between the two.
5
+ *
6
+ * @dev Chain reorgs do not need to be handled here because both the finalized and aged indexes refer to finalized
7
+ * blocks, which by definition cannot be affected by reorgs.
8
+ *
9
+ * TODO(benesjan): Relocate to yarn-project/pxe/src/storage/tagging_store
10
+ */ export class RecipientTaggingStore {
11
+ #store;
12
+ #highestAgedIndex;
13
+ #highestFinalizedIndex;
14
+ constructor(store){
15
+ this.#store = store;
16
+ this.#highestAgedIndex = this.#store.openMap('highest_aged_index');
17
+ this.#highestFinalizedIndex = this.#store.openMap('highest_finalized_index');
18
+ }
19
+ getHighestAgedIndex(secret) {
20
+ return this.#highestAgedIndex.getAsync(secret.toString());
21
+ }
22
+ async updateHighestAgedIndex(secret, index) {
23
+ const currentIndex = await this.#highestAgedIndex.getAsync(secret.toString());
24
+ if (currentIndex !== undefined && index <= currentIndex) {
25
+ // Log sync should never set a lower highest aged index.
26
+ throw new Error(`New highest aged index (${index}) must be higher than the current one (${currentIndex})`);
27
+ }
28
+ await this.#highestAgedIndex.set(secret.toString(), index);
29
+ }
30
+ getHighestFinalizedIndex(secret) {
31
+ return this.#highestFinalizedIndex.getAsync(secret.toString());
32
+ }
33
+ async updateHighestFinalizedIndex(secret, index) {
34
+ const currentIndex = await this.#highestFinalizedIndex.getAsync(secret.toString());
35
+ if (currentIndex !== undefined && index < currentIndex) {
36
+ // Log sync should never set a lower highest finalized index but it can happen that it would try to set the same
37
+ // one because we are loading logs from highest aged index + 1 and not from the highest finalized index.
38
+ throw new Error(`New highest finalized index (${index}) must be higher than the current one (${currentIndex})`);
39
+ }
40
+ await this.#highestFinalizedIndex.set(secret.toString(), index);
41
+ }
42
+ }
@@ -0,0 +1,14 @@
1
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ /**
4
+ * Stores sender addresses. During recipient log synchronization, these senders are used, along with a given recipient,
5
+ * to derive directional app tagging secrets that are then used to sync the logs.
6
+ */
7
+ export declare class SenderAddressBookStore {
8
+ #private;
9
+ constructor(store: AztecAsyncKVStore);
10
+ addSender(address: AztecAddress): Promise<boolean>;
11
+ getSenders(): Promise<AztecAddress[]>;
12
+ removeSender(address: AztecAddress): Promise<boolean>;
13
+ }
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VuZGVyX2FkZHJlc3NfYm9va19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvdGFnZ2luZ19zdG9yZS9zZW5kZXJfYWRkcmVzc19ib29rX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFpQixNQUFNLGlCQUFpQixDQUFDO0FBQ3hFLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUUzRDs7O0dBR0c7QUFDSCxxQkFBYSxzQkFBc0I7O0lBSWpDLFlBQVksS0FBSyxFQUFFLGlCQUFpQixFQUluQztJQUVLLFNBQVMsQ0FBQyxPQUFPLEVBQUUsWUFBWSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FRdkQ7SUFFSyxVQUFVLElBQUksT0FBTyxDQUFDLFlBQVksRUFBRSxDQUFDLENBRTFDO0lBRUssWUFBWSxDQUFDLE9BQU8sRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQVExRDtDQUNGIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sender_address_book_store.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/sender_address_book_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;;GAGG;AACH,qBAAa,sBAAsB;;IAIjC,YAAY,KAAK,EAAE,iBAAiB,EAInC;IAEK,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAQvD;IAEK,UAAU,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAE1C;IAEK,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAQ1D;CACF"}
@@ -0,0 +1,30 @@
1
+ import { toArray } from '@aztec/foundation/iterable';
2
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ /**
4
+ * Stores sender addresses. During recipient log synchronization, these senders are used, along with a given recipient,
5
+ * to derive directional app tagging secrets that are then used to sync the logs.
6
+ */ export class SenderAddressBookStore {
7
+ #store;
8
+ #addressBook;
9
+ constructor(store){
10
+ this.#store = store;
11
+ this.#addressBook = this.#store.openMap('address_book');
12
+ }
13
+ async addSender(address) {
14
+ if (await this.#addressBook.hasAsync(address.toString())) {
15
+ return false;
16
+ }
17
+ await this.#addressBook.set(address.toString(), true);
18
+ return true;
19
+ }
20
+ async getSenders() {
21
+ return (await toArray(this.#addressBook.keysAsync())).map(AztecAddress.fromString);
22
+ }
23
+ async removeSender(address) {
24
+ if (!await this.#addressBook.hasAsync(address.toString())) {
25
+ return false;
26
+ }
27
+ await this.#addressBook.delete(address.toString());
28
+ return true;
29
+ }
30
+ }
@@ -0,0 +1,67 @@
1
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
+ import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
3
+ import { TxHash } from '@aztec/stdlib/tx';
4
+ /**
5
+ * Data provider of tagging data used when syncing the sender tagging indexes. The recipient counterpart of this class
6
+ * is called RecipientTaggingStore. We have the providers separate for the sender and recipient because
7
+ * the algorithms are completely disjoint and there is not data reuse between the two.
8
+ */
9
+ export declare class SenderTaggingStore {
10
+ #private;
11
+ constructor(store: AztecAsyncKVStore);
12
+ /**
13
+ * Stores pending indexes.
14
+ * @remarks Ignores the index if the same preTag + txHash combination already exists in the db with the same index.
15
+ * This is expected to happen because whenever we start sync we start from the last finalized index and we can have
16
+ * pending indexes already stored from previous syncs.
17
+ * @param preTags - The pre-tags containing the directional app tagging secrets and the indexes that are to be
18
+ * stored in the db.
19
+ * @param txHash - The tx in which the pretags were used in private logs.
20
+ * @throws If any two pre-tags contain the same directional app tagging secret. This is enforced because we care
21
+ * only about the highest index for a given secret that was used in the tx. Hence this check is a good way to catch
22
+ * bugs.
23
+ * @throws If the newly stored pending index is further than window length from the highest finalized index for the
24
+ * same secret. This is enforced in order to give a guarantee to a recipient that he doesn't need to look further than
25
+ * window length ahead of the highest finalized index.
26
+ * @throws If a secret + txHash pair already exists in the db with a different index value. It should never happen
27
+ * that we would attempt to store a different index for a given secret-txHash pair because we always store just the
28
+ * highest index for a given secret-txHash pair. Hence this is a good way to catch bugs.
29
+ * @throws If the newly stored pending index is lower than or equal to the last finalized index for the same secret.
30
+ * This is enforced because this should never happen if the syncing is done correctly as we look for logs from higher
31
+ * indexes than finalized ones.
32
+ */
33
+ storePendingIndexes(preTags: PreTag[], txHash: TxHash): Promise<void>;
34
+ /**
35
+ * Returns the transaction hashes of all pending transactions that contain indexes within a specified range
36
+ * for a given directional app tagging secret.
37
+ * @param secret - The directional app tagging secret to query pending indexes for.
38
+ * @param startIndex - The lower bound of the index range (inclusive).
39
+ * @param endIndex - The upper bound of the index range (exclusive).
40
+ * @returns An array of unique transaction hashes for pending transactions that contain indexes in the range
41
+ * [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
42
+ */
43
+ getTxHashesOfPendingIndexes(secret: DirectionalAppTaggingSecret, startIndex: number, endIndex: number): Promise<TxHash[]>;
44
+ /**
45
+ * Returns the last (highest) finalized index for a given secret.
46
+ * @param secret - The secret to get the last finalized index for.
47
+ * @returns The last (highest) finalized index for the given secret.
48
+ */
49
+ getLastFinalizedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined>;
50
+ /**
51
+ * Returns the last used index for a given directional app tagging secret, considering both finalized and pending
52
+ * indexes.
53
+ * @param secret - The directional app tagging secret to query the last used index for.
54
+ * @returns The last used index.
55
+ */
56
+ getLastUsedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined>;
57
+ /**
58
+ * Drops all pending indexes corresponding to the given transaction hashes.
59
+ */
60
+ dropPendingIndexes(txHashes: TxHash[]): Promise<void>;
61
+ /**
62
+ * Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
63
+ * indexes.
64
+ */
65
+ finalizePendingIndexes(txHashes: TxHash[]): Promise<void>;
66
+ }
67
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VuZGVyX3RhZ2dpbmdfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zdG9yYWdlL3RhZ2dpbmdfc3RvcmUvc2VuZGVyX3RhZ2dpbmdfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDeEUsT0FBTyxLQUFLLEVBQUUsMkJBQTJCLEVBQUUsTUFBTSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDOUUsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBSTFDOzs7O0dBSUc7QUFDSCxxQkFBYSxrQkFBa0I7O0lBa0I3QixZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFLbkM7SUFFRDs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7T0FvQkc7SUFDRyxtQkFBbUIsQ0FBQyxPQUFPLEVBQUUsTUFBTSxFQUFFLEVBQUUsTUFBTSxFQUFFLE1BQU0saUJBaUQxRDtJQUVEOzs7Ozs7OztPQVFHO0lBQ0csMkJBQTJCLENBQy9CLE1BQU0sRUFBRSwyQkFBMkIsRUFDbkMsVUFBVSxFQUFFLE1BQU0sRUFDbEIsUUFBUSxFQUFFLE1BQU0sR0FDZixPQUFPLENBQUMsTUFBTSxFQUFFLENBQUMsQ0FNbkI7SUFFRDs7OztPQUlHO0lBQ0gscUJBQXFCLENBQUMsTUFBTSxFQUFFLDJCQUEyQixHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBRXRGO0lBRUQ7Ozs7O09BS0c7SUFDRyxnQkFBZ0IsQ0FBQyxNQUFNLEVBQUUsMkJBQTJCLEdBQUcsT0FBTyxDQUFDLE1BQU0sR0FBRyxTQUFTLENBQUMsQ0FZdkY7SUFFRDs7T0FFRztJQUNHLGtCQUFrQixDQUFDLFFBQVEsRUFBRSxNQUFNLEVBQUUsaUJBcUIxQztJQUVEOzs7T0FHRztJQUNHLHNCQUFzQixDQUFDLFFBQVEsRUFBRSxNQUFNLEVBQUUsaUJBcUQ5QztDQUNGIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sender_tagging_store.d.ts","sourceRoot":"","sources":["../../../src/storage/tagging_store/sender_tagging_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI1C;;;;GAIG;AACH,qBAAa,kBAAkB;;IAkB7B,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,iBAiD1D;IAED;;;;;;;;OAQG;IACG,2BAA2B,CAC/B,MAAM,EAAE,2BAA2B,EACnC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,EAAE,CAAC,CAMnB;IAED;;;;OAIG;IACH,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAEtF;IAED;;;;;OAKG;IACG,gBAAgB,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAYvF;IAED;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAqB1C;IAED;;;OAGG;IACG,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAqD9C;CACF"}
@@ -0,0 +1,196 @@
1
+ import { toArray } from '@aztec/foundation/iterable';
2
+ import { TxHash } from '@aztec/stdlib/tx';
3
+ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.js';
4
+ /**
5
+ * Data provider of tagging data used when syncing the sender tagging indexes. The recipient counterpart of this class
6
+ * is called RecipientTaggingStore. We have the providers separate for the sender and recipient because
7
+ * the algorithms are completely disjoint and there is not data reuse between the two.
8
+ */ export class SenderTaggingStore {
9
+ #store;
10
+ // Stores the pending indexes for each directional app tagging secret. Pending here means that the tx that contained
11
+ // the private logs with tags corresponding to these indexes has not been finalized yet.
12
+ //
13
+ // We don't store just the highest index because if their transaction is dropped we'd then need the information about
14
+ // the lower pending indexes. For each secret-tx pair however we only store the largest index used in that tx, since
15
+ // the smaller ones are irrelevant due to tx atomicity.
16
+ //
17
+ // TODO(#17615): This assumes no logs are used in the non-revertible phase.
18
+ #pendingIndexes;
19
+ // Stores the last (highest) finalized index for each directional app tagging secret. We care only about the last
20
+ // index because unlike the pending indexes, it will never happen that a finalized index would be removed and hence
21
+ // we don't need to store the history.
22
+ #lastFinalizedIndexes;
23
+ constructor(store){
24
+ this.#store = store;
25
+ this.#pendingIndexes = this.#store.openMap('pending_indexes');
26
+ this.#lastFinalizedIndexes = this.#store.openMap('last_finalized_indexes');
27
+ }
28
+ /**
29
+ * Stores pending indexes.
30
+ * @remarks Ignores the index if the same preTag + txHash combination already exists in the db with the same index.
31
+ * This is expected to happen because whenever we start sync we start from the last finalized index and we can have
32
+ * pending indexes already stored from previous syncs.
33
+ * @param preTags - The pre-tags containing the directional app tagging secrets and the indexes that are to be
34
+ * stored in the db.
35
+ * @param txHash - The tx in which the pretags were used in private logs.
36
+ * @throws If any two pre-tags contain the same directional app tagging secret. This is enforced because we care
37
+ * only about the highest index for a given secret that was used in the tx. Hence this check is a good way to catch
38
+ * bugs.
39
+ * @throws If the newly stored pending index is further than window length from the highest finalized index for the
40
+ * same secret. This is enforced in order to give a guarantee to a recipient that he doesn't need to look further than
41
+ * window length ahead of the highest finalized index.
42
+ * @throws If a secret + txHash pair already exists in the db with a different index value. It should never happen
43
+ * that we would attempt to store a different index for a given secret-txHash pair because we always store just the
44
+ * highest index for a given secret-txHash pair. Hence this is a good way to catch bugs.
45
+ * @throws If the newly stored pending index is lower than or equal to the last finalized index for the same secret.
46
+ * This is enforced because this should never happen if the syncing is done correctly as we look for logs from higher
47
+ * indexes than finalized ones.
48
+ */ async storePendingIndexes(preTags, txHash) {
49
+ // The secrets in pre-tags should be unique because we always store just the highest index per given secret-txHash
50
+ // pair. Below we check that this is the case.
51
+ const secretsSet = new Set(preTags.map((preTag)=>preTag.secret.toString()));
52
+ if (secretsSet.size !== preTags.length) {
53
+ throw new Error(`Duplicate secrets found when storing pending indexes`);
54
+ }
55
+ for (const { secret, index } of preTags){
56
+ // First we check that for any secret the highest used index in tx is not further than window length from
57
+ // the highest finalized index.
58
+ const finalizedIndex = await this.getLastFinalizedIndex(secret) ?? 0;
59
+ if (index > finalizedIndex + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) {
60
+ throw new Error(`Highest used index ${index} is further than window length from the highest finalized index ${finalizedIndex}.
61
+ Tagging window length ${UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN} is configured too low. Contact the Aztec team
62
+ to increase it!`);
63
+ }
64
+ // Throw if the new pending index is lower than or equal to the last finalized index
65
+ const secretStr = secret.toString();
66
+ const lastFinalizedIndex = await this.#lastFinalizedIndexes.getAsync(secretStr);
67
+ if (lastFinalizedIndex !== undefined && index <= lastFinalizedIndex) {
68
+ throw new Error(`Cannot store pending index ${index} for secret ${secretStr}: ` + `it is lower than or equal to the last finalized index ${lastFinalizedIndex}`);
69
+ }
70
+ // Check if this secret + txHash combination already exists
71
+ const txHashStr = txHash.toString();
72
+ const existingForSecret = await this.#pendingIndexes.getAsync(secretStr) ?? [];
73
+ const existingForSecretAndTx = existingForSecret.find((entry)=>entry.txHash === txHashStr);
74
+ if (existingForSecretAndTx) {
75
+ // If it exists with a different index, throw an error
76
+ if (existingForSecretAndTx.index !== index) {
77
+ throw new Error(`Cannot store index ${index} for secret ${secretStr} and txHash ${txHashStr}: ` + `a different index ${existingForSecretAndTx.index} already exists for this secret-txHash pair`);
78
+ }
79
+ // If it exists with the same index, ignore the update (no-op)
80
+ } else {
81
+ // If it doesn't exist, add it
82
+ await this.#pendingIndexes.set(secretStr, [
83
+ ...existingForSecret,
84
+ {
85
+ index,
86
+ txHash: txHashStr
87
+ }
88
+ ]);
89
+ }
90
+ }
91
+ }
92
+ /**
93
+ * Returns the transaction hashes of all pending transactions that contain indexes within a specified range
94
+ * for a given directional app tagging secret.
95
+ * @param secret - The directional app tagging secret to query pending indexes for.
96
+ * @param startIndex - The lower bound of the index range (inclusive).
97
+ * @param endIndex - The upper bound of the index range (exclusive).
98
+ * @returns An array of unique transaction hashes for pending transactions that contain indexes in the range
99
+ * [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
100
+ */ async getTxHashesOfPendingIndexes(secret, startIndex, endIndex) {
101
+ const existing = await this.#pendingIndexes.getAsync(secret.toString()) ?? [];
102
+ const txHashes = existing.filter((entry)=>entry.index >= startIndex && entry.index < endIndex).map((entry)=>entry.txHash);
103
+ return Array.from(new Set(txHashes)).map(TxHash.fromString);
104
+ }
105
+ /**
106
+ * Returns the last (highest) finalized index for a given secret.
107
+ * @param secret - The secret to get the last finalized index for.
108
+ * @returns The last (highest) finalized index for the given secret.
109
+ */ getLastFinalizedIndex(secret) {
110
+ return this.#lastFinalizedIndexes.getAsync(secret.toString());
111
+ }
112
+ /**
113
+ * Returns the last used index for a given directional app tagging secret, considering both finalized and pending
114
+ * indexes.
115
+ * @param secret - The directional app tagging secret to query the last used index for.
116
+ * @returns The last used index.
117
+ */ async getLastUsedIndex(secret) {
118
+ const secretStr = secret.toString();
119
+ const pendingTxScopedIndexes = await this.#pendingIndexes.getAsync(secretStr) ?? [];
120
+ const pendingIndexes = pendingTxScopedIndexes.map((entry)=>entry.index);
121
+ if (pendingTxScopedIndexes.length === 0) {
122
+ return this.#lastFinalizedIndexes.getAsync(secretStr);
123
+ }
124
+ // As the last used index we return the highest one from the pending indexes. Note that this value will be always
125
+ // higher than the last finalized index because we prune lower pending indexes when a tx is finalized.
126
+ return Math.max(...pendingIndexes);
127
+ }
128
+ /**
129
+ * Drops all pending indexes corresponding to the given transaction hashes.
130
+ */ async dropPendingIndexes(txHashes) {
131
+ if (txHashes.length === 0) {
132
+ return;
133
+ }
134
+ const txHashStrs = new Set(txHashes.map((txHash)=>txHash.toString()));
135
+ const allSecrets = await toArray(this.#pendingIndexes.keysAsync());
136
+ for (const secret of allSecrets){
137
+ const pendingData = await this.#pendingIndexes.getAsync(secret);
138
+ if (pendingData) {
139
+ const filtered = pendingData.filter((item)=>!txHashStrs.has(item.txHash));
140
+ if (filtered.length === 0) {
141
+ await this.#pendingIndexes.delete(secret);
142
+ } else if (filtered.length !== pendingData.length) {
143
+ // Some items were filtered out, so update the pending data
144
+ await this.#pendingIndexes.set(secret, filtered);
145
+ }
146
+ // else: No items were filtered out (txHashes not found for this secret) --> no-op
147
+ }
148
+ }
149
+ }
150
+ /**
151
+ * Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
152
+ * indexes.
153
+ */ async finalizePendingIndexes(txHashes) {
154
+ if (txHashes.length === 0) {
155
+ return;
156
+ }
157
+ for (const txHash of txHashes){
158
+ const txHashStr = txHash.toString();
159
+ const allSecrets = await toArray(this.#pendingIndexes.keysAsync());
160
+ for (const secret of allSecrets){
161
+ const pendingData = await this.#pendingIndexes.getAsync(secret);
162
+ if (!pendingData) {
163
+ continue;
164
+ }
165
+ const matchingIndexes = pendingData.filter((item)=>item.txHash === txHashStr).map((item)=>item.index);
166
+ if (matchingIndexes.length === 0) {
167
+ continue;
168
+ }
169
+ if (matchingIndexes.length > 1) {
170
+ // We should always just store the highest pending index for a given tx hash and secret because the lower
171
+ // values are irrelevant.
172
+ throw new Error(`Multiple pending indexes found for tx hash ${txHashStr} and secret ${secret}`);
173
+ }
174
+ let lastFinalized = await this.#lastFinalizedIndexes.getAsync(secret);
175
+ const newFinalized = matchingIndexes[0];
176
+ if (newFinalized < (lastFinalized ?? 0)) {
177
+ // This should never happen because when last finalized index was finalized we should have pruned the lower
178
+ // pending indexes.
179
+ throw new Error(`New finalized index ${newFinalized} is smaller than the current last finalized index ${lastFinalized}`);
180
+ }
181
+ await this.#lastFinalizedIndexes.set(secret, newFinalized);
182
+ lastFinalized = newFinalized;
183
+ // When we add pending indexes, we ensure they are higher than the last finalized index. However, because we
184
+ // cannot control the order in which transactions are finalized, there may be pending indexes that are now
185
+ // obsolete because they are lower than the most recently finalized index. For this reason, we prune these
186
+ // outdated pending indexes.
187
+ const remainingItemsOfHigherIndex = pendingData.filter((item)=>item.index > (lastFinalized ?? 0));
188
+ if (remainingItemsOfHigherIndex.length === 0) {
189
+ await this.#pendingIndexes.delete(secret);
190
+ } else {
191
+ await this.#pendingIndexes.set(secret, remainingItemsOfHigherIndex);
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
@@ -1,2 +1,2 @@
1
- export declare const WINDOW_HALF_SIZE = 10;
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGFnZ2luZy9jb25zdGFudHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsZUFBTyxNQUFNLGdCQUFnQixLQUFLLENBQUMifQ==
1
+ export declare const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN = 20;
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGFnZ2luZy9jb25zdGFudHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBU0EsZUFBTyxNQUFNLHNDQUFzQyxLQUFLLENBQUMifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/tagging/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,gBAAgB,KAAK,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/tagging/constants.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,sCAAsC,KAAK,CAAC"}