@aztec/foundation 0.0.0-test.1 → 0.0.1-commit.b655e406

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 (510) hide show
  1. package/dest/array/array.d.ts +5 -0
  2. package/dest/array/array.d.ts.map +1 -1
  3. package/dest/array/array.js +11 -0
  4. package/dest/async-pool/index.d.ts.map +1 -1
  5. package/dest/async-pool/index.js +1 -0
  6. package/dest/bigint/index.d.ts +7 -0
  7. package/dest/bigint/index.d.ts.map +1 -0
  8. package/dest/bigint/index.js +15 -0
  9. package/dest/bigint-buffer/index.d.ts +0 -2
  10. package/dest/bigint-buffer/index.d.ts.map +1 -1
  11. package/dest/buffer/buffer16.d.ts +80 -0
  12. package/dest/buffer/buffer16.d.ts.map +1 -0
  13. package/dest/buffer/buffer16.js +100 -0
  14. package/dest/buffer/buffer32.d.ts +3 -7
  15. package/dest/buffer/buffer32.d.ts.map +1 -1
  16. package/dest/buffer/buffer32.js +6 -6
  17. package/dest/buffer/index.d.ts +1 -0
  18. package/dest/buffer/index.d.ts.map +1 -1
  19. package/dest/buffer/index.js +1 -0
  20. package/dest/collection/array.d.ts +16 -3
  21. package/dest/collection/array.d.ts.map +1 -1
  22. package/dest/collection/array.js +57 -3
  23. package/dest/collection/object.d.ts +16 -0
  24. package/dest/collection/object.d.ts.map +1 -1
  25. package/dest/collection/object.js +25 -0
  26. package/dest/config/env_var.d.ts +1 -1
  27. package/dest/config/env_var.d.ts.map +1 -1
  28. package/dest/config/index.d.ts +48 -1
  29. package/dest/config/index.d.ts.map +1 -1
  30. package/dest/config/index.js +115 -7
  31. package/dest/config/network_config.d.ts +42 -0
  32. package/dest/config/network_config.d.ts.map +1 -0
  33. package/dest/config/network_config.js +9 -0
  34. package/dest/config/network_name.d.ts +3 -0
  35. package/dest/config/network_name.d.ts.map +1 -0
  36. package/dest/config/network_name.js +19 -0
  37. package/dest/config/secret_value.d.ts +28 -0
  38. package/dest/config/secret_value.d.ts.map +1 -0
  39. package/dest/config/secret_value.js +34 -0
  40. package/dest/crypto/aes128/index.d.ts +2 -4
  41. package/dest/crypto/aes128/index.d.ts.map +1 -1
  42. package/dest/crypto/aes128/index.js +23 -6
  43. package/dest/crypto/bls/bn254_keystore.d.ts +296 -0
  44. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -0
  45. package/dest/crypto/bls/bn254_keystore.js +218 -0
  46. package/dest/crypto/bls/index.d.ts +13 -0
  47. package/dest/crypto/bls/index.d.ts.map +1 -0
  48. package/dest/crypto/bls/index.js +87 -0
  49. package/dest/crypto/bn254/bn254_utils.d.ts +39 -0
  50. package/dest/crypto/bn254/bn254_utils.d.ts.map +1 -0
  51. package/dest/crypto/bn254/bn254_utils.js +56 -0
  52. package/dest/crypto/bn254/index.d.ts +55 -0
  53. package/dest/crypto/bn254/index.d.ts.map +1 -0
  54. package/dest/crypto/bn254/index.js +142 -0
  55. package/dest/crypto/ecdsa/index.d.ts +2 -2
  56. package/dest/crypto/ecdsa/index.d.ts.map +1 -1
  57. package/dest/crypto/ecdsa/index.js +70 -48
  58. package/dest/crypto/ecdsa/signature.d.ts +1 -3
  59. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  60. package/dest/crypto/grumpkin/index.d.ts +6 -13
  61. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  62. package/dest/crypto/grumpkin/index.js +69 -54
  63. package/dest/crypto/index.d.ts +2 -0
  64. package/dest/crypto/index.d.ts.map +1 -1
  65. package/dest/crypto/index.js +2 -0
  66. package/dest/crypto/keccak/index.d.ts +2 -4
  67. package/dest/crypto/keccak/index.d.ts.map +1 -1
  68. package/dest/crypto/keys/index.d.ts +0 -2
  69. package/dest/crypto/keys/index.d.ts.map +1 -1
  70. package/dest/crypto/keys/index.js +9 -4
  71. package/dest/crypto/pedersen/pedersen.noble.d.ts +2 -4
  72. package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -1
  73. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -4
  74. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  75. package/dest/crypto/pedersen/pedersen.wasm.js +29 -13
  76. package/dest/crypto/poseidon/index.d.ts +0 -2
  77. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  78. package/dest/crypto/poseidon/index.js +42 -17
  79. package/dest/crypto/random/index.d.ts +1 -3
  80. package/dest/crypto/random/index.d.ts.map +1 -1
  81. package/dest/crypto/random/index.js +2 -34
  82. package/dest/crypto/random/randomness_singleton.d.ts +0 -2
  83. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  84. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  85. package/dest/crypto/schnorr/index.js +35 -37
  86. package/dest/crypto/schnorr/signature.d.ts +3 -5
  87. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  88. package/dest/crypto/secp256k1/index.d.ts +4 -6
  89. package/dest/crypto/secp256k1/index.d.ts.map +1 -1
  90. package/dest/crypto/secp256k1/index.js +29 -18
  91. package/dest/crypto/secp256k1-signer/utils.d.ts +55 -4
  92. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  93. package/dest/crypto/secp256k1-signer/utils.js +92 -6
  94. package/dest/crypto/serialize.d.ts +4 -6
  95. package/dest/crypto/serialize.d.ts.map +1 -1
  96. package/dest/crypto/sha256/index.d.ts +21 -4
  97. package/dest/crypto/sha256/index.d.ts.map +1 -1
  98. package/dest/crypto/sha256/index.js +42 -0
  99. package/dest/crypto/sha512/index.d.ts +1 -3
  100. package/dest/crypto/sha512/index.d.ts.map +1 -1
  101. package/dest/crypto/signature/index.d.ts +0 -2
  102. package/dest/crypto/signature/index.d.ts.map +1 -1
  103. package/dest/crypto/sync/index.js +3 -1
  104. package/dest/crypto/sync/pedersen/index.d.ts +2 -4
  105. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  106. package/dest/crypto/sync/pedersen/index.js +17 -10
  107. package/dest/crypto/sync/poseidon/index.d.ts +0 -2
  108. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  109. package/dest/crypto/sync/poseidon/index.js +27 -12
  110. package/dest/decorators/memoize.d.ts.map +1 -1
  111. package/dest/eth-address/index.d.ts +6 -7
  112. package/dest/eth-address/index.d.ts.map +1 -1
  113. package/dest/eth-address/index.js +5 -0
  114. package/dest/eth-signature/eth_signature.d.ts +16 -14
  115. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  116. package/dest/eth-signature/eth_signature.js +31 -17
  117. package/dest/fields/bls12_fields.d.ts +148 -0
  118. package/dest/fields/bls12_fields.d.ts.map +1 -0
  119. package/dest/fields/bls12_fields.js +359 -0
  120. package/dest/fields/bls12_point.d.ts +229 -0
  121. package/dest/fields/bls12_point.d.ts.map +1 -0
  122. package/dest/fields/bls12_point.js +398 -0
  123. package/dest/fields/coordinate.d.ts +0 -2
  124. package/dest/fields/coordinate.d.ts.map +1 -1
  125. package/dest/fields/fields.d.ts +6 -3
  126. package/dest/fields/fields.d.ts.map +1 -1
  127. package/dest/fields/fields.js +43 -15
  128. package/dest/fields/index.d.ts +2 -0
  129. package/dest/fields/index.d.ts.map +1 -1
  130. package/dest/fields/index.js +2 -0
  131. package/dest/fields/point.d.ts +2 -4
  132. package/dest/fields/point.d.ts.map +1 -1
  133. package/dest/fields/point.js +3 -3
  134. package/dest/fs/index.d.ts +1 -0
  135. package/dest/fs/index.d.ts.map +1 -1
  136. package/dest/fs/index.js +1 -0
  137. package/dest/fs/try_rm_dir.d.ts +3 -0
  138. package/dest/fs/try_rm_dir.d.ts.map +1 -0
  139. package/dest/fs/try_rm_dir.js +16 -0
  140. package/dest/index.d.ts +1 -2
  141. package/dest/index.d.ts.map +1 -1
  142. package/dest/index.js +1 -2
  143. package/dest/iterable/filter.js +1 -1
  144. package/dest/iterable/map.js +1 -1
  145. package/dest/jest/env.js +48 -0
  146. package/dest/jest/setupAfterEnv.js +3 -0
  147. package/dest/json-rpc/client/fetch.d.ts +2 -2
  148. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  149. package/dest/json-rpc/client/fetch.js +16 -30
  150. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +9 -3
  151. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  152. package/dest/json-rpc/client/safe_json_rpc_client.js +173 -13
  153. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  154. package/dest/json-rpc/client/undici.js +6 -7
  155. package/dest/json-rpc/convert.d.ts +2 -9
  156. package/dest/json-rpc/convert.d.ts.map +1 -1
  157. package/dest/json-rpc/convert.js +1 -9
  158. package/dest/json-rpc/errors.d.ts +4 -0
  159. package/dest/json-rpc/errors.d.ts.map +1 -0
  160. package/dest/json-rpc/errors.js +6 -0
  161. package/dest/json-rpc/fixtures/class_a.d.ts +5 -3
  162. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  163. package/dest/json-rpc/fixtures/class_b.d.ts +5 -3
  164. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  165. package/dest/json-rpc/index.d.ts +2 -1
  166. package/dest/json-rpc/index.d.ts.map +1 -1
  167. package/dest/json-rpc/index.js +2 -1
  168. package/dest/json-rpc/js_utils.d.ts.map +1 -1
  169. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +21 -22
  170. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  171. package/dest/json-rpc/server/safe_json_rpc_server.js +161 -56
  172. package/dest/json-rpc/test/integration.d.ts +1 -2
  173. package/dest/json-rpc/test/integration.d.ts.map +1 -1
  174. package/dest/log/console.d.ts.map +1 -1
  175. package/dest/log/gcloud-logger-config.d.ts +0 -1
  176. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  177. package/dest/log/gcloud-logger-config.js +1 -9
  178. package/dest/log/index.d.ts +4 -4
  179. package/dest/log/index.d.ts.map +1 -1
  180. package/dest/log/index.js +4 -4
  181. package/dest/log/libp2p_logger.js +13 -2
  182. package/dest/log/log_fn.d.ts +1 -1
  183. package/dest/log/log_fn.d.ts.map +1 -1
  184. package/dest/log/noir_debug_log_util.d.ts +14 -0
  185. package/dest/log/noir_debug_log_util.d.ts.map +1 -0
  186. package/dest/log/noir_debug_log_util.js +14 -0
  187. package/dest/log/pino-logger.d.ts +2 -2
  188. package/dest/log/pino-logger.d.ts.map +1 -1
  189. package/dest/log/pino-logger.js +28 -2
  190. package/dest/message/index.d.ts.map +1 -1
  191. package/dest/mutex/mutex_database.d.ts.map +1 -1
  192. package/dest/noir/noir_package_config.d.ts +4 -4
  193. package/dest/number/index.d.ts +3 -0
  194. package/dest/number/index.d.ts.map +1 -0
  195. package/dest/number/index.js +12 -0
  196. package/dest/profiler/index.d.ts +2 -0
  197. package/dest/profiler/index.d.ts.map +1 -0
  198. package/dest/profiler/index.js +1 -0
  199. package/dest/profiler/profiler.d.ts +8 -0
  200. package/dest/profiler/profiler.d.ts.map +1 -0
  201. package/dest/profiler/profiler.js +97 -0
  202. package/dest/promise/running-promise.d.ts +1 -1
  203. package/dest/promise/running-promise.d.ts.map +1 -1
  204. package/dest/promise/running-promise.js +2 -2
  205. package/dest/queue/batch_queue.d.ts +1 -1
  206. package/dest/queue/batch_queue.js +1 -1
  207. package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
  208. package/dest/queue/serial_queue.d.ts +2 -2
  209. package/dest/queue/serial_queue.d.ts.map +1 -1
  210. package/dest/queue/serial_queue.js +7 -5
  211. package/dest/retry/index.d.ts +3 -2
  212. package/dest/retry/index.d.ts.map +1 -1
  213. package/dest/retry/index.js +2 -2
  214. package/dest/schemas/api.d.ts.map +1 -1
  215. package/dest/schemas/parse.js +1 -1
  216. package/dest/schemas/schemas.d.ts +9 -6
  217. package/dest/schemas/schemas.d.ts.map +1 -1
  218. package/dest/schemas/schemas.js +15 -1
  219. package/dest/schemas/utils.d.ts +1 -3
  220. package/dest/schemas/utils.d.ts.map +1 -1
  221. package/dest/serialize/buffer_reader.d.ts +27 -2
  222. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  223. package/dest/serialize/buffer_reader.js +44 -2
  224. package/dest/serialize/field_reader.d.ts +10 -1
  225. package/dest/serialize/field_reader.d.ts.map +1 -1
  226. package/dest/serialize/field_reader.js +18 -1
  227. package/dest/serialize/free_funcs.d.ts +23 -21
  228. package/dest/serialize/free_funcs.d.ts.map +1 -1
  229. package/dest/serialize/free_funcs.js +21 -27
  230. package/dest/serialize/serialize.d.ts +4 -5
  231. package/dest/serialize/serialize.d.ts.map +1 -1
  232. package/dest/string/index.d.ts +7 -2
  233. package/dest/string/index.d.ts.map +1 -1
  234. package/dest/string/index.js +27 -1
  235. package/dest/testing/files/index.d.ts +0 -2
  236. package/dest/testing/files/index.d.ts.map +1 -1
  237. package/dest/testing/files/index.js +2 -2
  238. package/dest/testing/formatting.d.ts +4 -0
  239. package/dest/testing/formatting.d.ts.map +1 -0
  240. package/dest/testing/formatting.js +3 -0
  241. package/dest/testing/index.d.ts +1 -0
  242. package/dest/testing/index.d.ts.map +1 -1
  243. package/dest/testing/index.js +1 -0
  244. package/dest/timer/date.d.ts +2 -1
  245. package/dest/timer/date.d.ts.map +1 -1
  246. package/dest/timer/date.js +5 -3
  247. package/dest/timer/index.d.ts +1 -1
  248. package/dest/timer/index.d.ts.map +1 -1
  249. package/dest/timer/index.js +1 -1
  250. package/dest/timer/timeout.d.ts +18 -5
  251. package/dest/timer/timeout.d.ts.map +1 -1
  252. package/dest/timer/timeout.js +43 -22
  253. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  254. package/dest/transport/index.d.ts +0 -1
  255. package/dest/transport/index.d.ts.map +1 -1
  256. package/dest/transport/index.js +0 -1
  257. package/dest/transport/interface/connector.d.ts.map +1 -1
  258. package/dest/transport/interface/listener.d.ts +0 -1
  259. package/dest/transport/interface/listener.d.ts.map +1 -1
  260. package/dest/transport/interface/socket.d.ts.map +1 -1
  261. package/dest/transport/node/node_connector.d.ts +0 -1
  262. package/dest/transport/node/node_connector.d.ts.map +1 -1
  263. package/dest/transport/node/node_connector_socket.d.ts +0 -1
  264. package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
  265. package/dest/transport/node/node_listener.d.ts +0 -1
  266. package/dest/transport/node/node_listener.d.ts.map +1 -1
  267. package/dest/transport/node/node_listener_socket.d.ts +0 -1
  268. package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
  269. package/dest/transport/transport_client.d.ts +0 -1
  270. package/dest/transport/transport_client.d.ts.map +1 -1
  271. package/dest/transport/transport_server.d.ts.map +1 -1
  272. package/dest/trees/hasher.d.ts +4 -6
  273. package/dest/trees/hasher.d.ts.map +1 -1
  274. package/dest/trees/index.d.ts +1 -0
  275. package/dest/trees/index.d.ts.map +1 -1
  276. package/dest/trees/index.js +1 -0
  277. package/dest/trees/indexed_merkle_tree.d.ts +0 -2
  278. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
  279. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -3
  280. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  281. package/dest/trees/indexed_tree_leaf.d.ts +0 -2
  282. package/dest/trees/indexed_tree_leaf.d.ts.map +1 -1
  283. package/dest/trees/membership_witness.d.ts +19 -3
  284. package/dest/trees/membership_witness.d.ts.map +1 -1
  285. package/dest/trees/membership_witness.js +13 -0
  286. package/dest/trees/merkle_tree.d.ts +0 -2
  287. package/dest/trees/merkle_tree.d.ts.map +1 -1
  288. package/dest/trees/merkle_tree_calculator.d.ts +11 -3
  289. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  290. package/dest/trees/merkle_tree_calculator.js +31 -1
  291. package/dest/trees/sibling_path.d.ts +6 -8
  292. package/dest/trees/sibling_path.d.ts.map +1 -1
  293. package/dest/trees/unbalanced_merkle_tree.d.ts +19 -8
  294. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
  295. package/dest/trees/unbalanced_merkle_tree.js +49 -50
  296. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +48 -0
  297. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -0
  298. package/dest/trees/unbalanced_merkle_tree_calculator.js +162 -0
  299. package/dest/trees/unbalanced_tree_store.d.ts +1 -0
  300. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  301. package/dest/trees/unbalanced_tree_store.js +6 -0
  302. package/dest/types/index.d.ts +25 -2
  303. package/dest/types/index.d.ts.map +1 -1
  304. package/dest/url/index.d.ts.map +1 -1
  305. package/dest/url/index.js +1 -1
  306. package/package.json +35 -41
  307. package/src/array/array.ts +13 -0
  308. package/src/async-pool/index.ts +1 -0
  309. package/src/bigint/index.ts +20 -0
  310. package/src/buffer/buffer16.ts +133 -0
  311. package/src/buffer/buffer32.ts +8 -6
  312. package/src/buffer/index.ts +1 -0
  313. package/src/collection/array.ts +66 -4
  314. package/src/collection/object.ts +37 -0
  315. package/src/config/env_var.ts +142 -52
  316. package/src/config/index.ts +191 -8
  317. package/src/config/network_config.ts +16 -0
  318. package/src/config/network_name.ts +28 -0
  319. package/src/config/secret_value.ts +49 -0
  320. package/src/crypto/aes128/index.ts +19 -10
  321. package/src/crypto/bls/bn254_keystore.ts +287 -0
  322. package/src/crypto/bls/index.ts +77 -0
  323. package/src/crypto/bn254/bn254_utils.ts +64 -0
  324. package/src/crypto/bn254/index.ts +170 -0
  325. package/src/crypto/ecdsa/index.ts +41 -23
  326. package/src/crypto/grumpkin/index.ts +35 -45
  327. package/src/crypto/index.ts +2 -0
  328. package/src/crypto/keys/index.ts +5 -5
  329. package/src/crypto/pedersen/pedersen.wasm.ts +22 -18
  330. package/src/crypto/poseidon/index.ts +32 -24
  331. package/src/crypto/random/index.ts +2 -40
  332. package/src/crypto/schnorr/index.ts +20 -17
  333. package/src/crypto/secp256k1/index.ts +15 -11
  334. package/src/crypto/secp256k1-signer/utils.ts +120 -7
  335. package/src/crypto/sha256/index.ts +47 -0
  336. package/src/crypto/sync/index.ts +1 -1
  337. package/src/crypto/sync/pedersen/index.ts +16 -15
  338. package/src/crypto/sync/poseidon/index.ts +27 -22
  339. package/src/eth-address/index.ts +9 -2
  340. package/src/eth-signature/eth_signature.ts +44 -22
  341. package/src/fields/bls12_fields.ts +463 -0
  342. package/src/fields/bls12_point.ts +450 -0
  343. package/src/fields/fields.ts +37 -9
  344. package/src/fields/index.ts +2 -0
  345. package/src/fields/point.ts +1 -3
  346. package/src/fs/index.ts +1 -0
  347. package/src/fs/try_rm_dir.ts +15 -0
  348. package/src/index.ts +1 -2
  349. package/src/iterable/filter.ts +1 -1
  350. package/src/iterable/map.ts +1 -1
  351. package/src/jest/env.mjs +52 -0
  352. package/src/jest/setupAfterEnv.mjs +3 -0
  353. package/src/json-rpc/client/fetch.ts +14 -33
  354. package/src/json-rpc/client/safe_json_rpc_client.ts +226 -13
  355. package/src/json-rpc/client/undici.ts +8 -15
  356. package/src/json-rpc/convert.ts +3 -12
  357. package/src/json-rpc/errors.ts +6 -0
  358. package/src/json-rpc/fixtures/class_a.ts +4 -1
  359. package/src/json-rpc/fixtures/class_b.ts +4 -1
  360. package/src/json-rpc/index.ts +2 -1
  361. package/src/json-rpc/server/safe_json_rpc_server.ts +141 -48
  362. package/src/json-rpc/test/integration.ts +1 -1
  363. package/src/log/console.ts +4 -1
  364. package/src/log/gcloud-logger-config.ts +3 -7
  365. package/src/log/index.ts +4 -4
  366. package/src/log/libp2p_logger.ts +21 -2
  367. package/src/log/log_fn.ts +1 -1
  368. package/src/log/noir_debug_log_util.ts +21 -0
  369. package/src/log/pino-logger.ts +33 -2
  370. package/src/message/index.ts +5 -1
  371. package/src/mutex/mutex_database.ts +2 -3
  372. package/src/number/index.ts +14 -0
  373. package/src/profiler/index.ts +1 -0
  374. package/src/profiler/profiler.ts +125 -0
  375. package/src/promise/running-promise.ts +2 -2
  376. package/src/queue/batch_queue.ts +1 -1
  377. package/src/queue/bounded_serial_queue.ts +4 -1
  378. package/src/queue/serial_queue.ts +5 -5
  379. package/src/retry/index.ts +10 -5
  380. package/src/schemas/api.ts +4 -4
  381. package/src/schemas/parse.ts +1 -1
  382. package/src/schemas/schemas.ts +19 -1
  383. package/src/serialize/buffer_reader.ts +60 -3
  384. package/src/serialize/field_reader.ts +27 -3
  385. package/src/serialize/free_funcs.ts +25 -31
  386. package/src/serialize/serialize.ts +2 -0
  387. package/src/string/index.ts +36 -1
  388. package/src/testing/files/index.ts +6 -2
  389. package/src/testing/formatting.ts +3 -0
  390. package/src/testing/index.ts +1 -0
  391. package/src/timer/date.ts +9 -3
  392. package/src/timer/index.ts +1 -1
  393. package/src/timer/timeout.ts +54 -19
  394. package/src/transport/index.ts +0 -1
  395. package/src/transport/interface/connector.ts +0 -1
  396. package/src/transport/interface/listener.ts +2 -3
  397. package/src/transport/interface/socket.ts +2 -3
  398. package/src/transport/transport_client.ts +3 -4
  399. package/src/transport/transport_server.ts +4 -1
  400. package/src/trees/hasher.ts +4 -4
  401. package/src/trees/index.ts +1 -0
  402. package/src/trees/indexed_merkle_tree.ts +5 -1
  403. package/src/trees/indexed_merkle_tree_calculator.ts +2 -2
  404. package/src/trees/membership_witness.ts +13 -0
  405. package/src/trees/merkle_tree.ts +4 -1
  406. package/src/trees/merkle_tree_calculator.ts +43 -5
  407. package/src/trees/unbalanced_merkle_tree.ts +50 -42
  408. package/src/trees/unbalanced_merkle_tree_calculator.ts +194 -0
  409. package/src/trees/unbalanced_tree_store.ts +5 -1
  410. package/src/types/index.ts +25 -4
  411. package/src/url/index.ts +0 -1
  412. package/dest/crypto/pedersen/pedersen.elliptic.d.ts +0 -13
  413. package/dest/crypto/pedersen/pedersen.elliptic.d.ts.map +0 -1
  414. package/dest/crypto/pedersen/pedersen.elliptic.js +0 -582
  415. package/dest/log/debug.d.ts +0 -56
  416. package/dest/log/debug.d.ts.map +0 -1
  417. package/dest/log/debug.js +0 -75
  418. package/dest/log/log_history.d.ts +0 -31
  419. package/dest/log/log_history.d.ts.map +0 -1
  420. package/dest/log/log_history.js +0 -38
  421. package/dest/transport/browser/index.d.ts +0 -5
  422. package/dest/transport/browser/index.d.ts.map +0 -1
  423. package/dest/transport/browser/index.js +0 -4
  424. package/dest/transport/browser/message_port_socket.d.ts +0 -37
  425. package/dest/transport/browser/message_port_socket.d.ts.map +0 -1
  426. package/dest/transport/browser/message_port_socket.js +0 -42
  427. package/dest/transport/browser/shared_worker_connector.d.ts +0 -19
  428. package/dest/transport/browser/shared_worker_connector.d.ts.map +0 -1
  429. package/dest/transport/browser/shared_worker_connector.js +0 -19
  430. package/dest/transport/browser/shared_worker_listener.d.ts +0 -38
  431. package/dest/transport/browser/shared_worker_listener.d.ts.map +0 -1
  432. package/dest/transport/browser/shared_worker_listener.js +0 -33
  433. package/dest/transport/browser/worker_connector.d.ts +0 -26
  434. package/dest/transport/browser/worker_connector.d.ts.map +0 -1
  435. package/dest/transport/browser/worker_connector.js +0 -30
  436. package/dest/transport/browser/worker_listener.d.ts +0 -39
  437. package/dest/transport/browser/worker_listener.d.ts.map +0 -1
  438. package/dest/transport/browser/worker_listener.js +0 -35
  439. package/dest/wasm/empty_wasi_sdk.d.ts +0 -130
  440. package/dest/wasm/empty_wasi_sdk.d.ts.map +0 -1
  441. package/dest/wasm/empty_wasi_sdk.js +0 -148
  442. package/dest/wasm/index.d.ts +0 -2
  443. package/dest/wasm/index.d.ts.map +0 -1
  444. package/dest/wasm/index.js +0 -1
  445. package/dest/wasm/wasm_module.d.ts +0 -136
  446. package/dest/wasm/wasm_module.d.ts.map +0 -1
  447. package/dest/wasm/wasm_module.js +0 -196
  448. package/dest/worker/browser/index.d.ts +0 -3
  449. package/dest/worker/browser/index.d.ts.map +0 -1
  450. package/dest/worker/browser/index.js +0 -2
  451. package/dest/worker/browser/start_web_module.d.ts +0 -7
  452. package/dest/worker/browser/start_web_module.d.ts.map +0 -1
  453. package/dest/worker/browser/start_web_module.js +0 -27
  454. package/dest/worker/browser/web_data_store.d.ts +0 -24
  455. package/dest/worker/browser/web_data_store.d.ts.map +0 -1
  456. package/dest/worker/browser/web_data_store.js +0 -29
  457. package/dest/worker/browser/web_worker.d.ts +0 -10
  458. package/dest/worker/browser/web_worker.d.ts.map +0 -1
  459. package/dest/worker/browser/web_worker.js +0 -25
  460. package/dest/worker/data_store.d.ts +0 -21
  461. package/dest/worker/data_store.d.ts.map +0 -1
  462. package/dest/worker/data_store.js +0 -3
  463. package/dest/worker/index.d.ts +0 -3
  464. package/dest/worker/index.d.ts.map +0 -1
  465. package/dest/worker/index.js +0 -1
  466. package/dest/worker/node/index.d.ts +0 -3
  467. package/dest/worker/node/index.d.ts.map +0 -1
  468. package/dest/worker/node/index.js +0 -2
  469. package/dest/worker/node/node_data_store.d.ts +0 -13
  470. package/dest/worker/node/node_data_store.d.ts.map +0 -1
  471. package/dest/worker/node/node_data_store.js +0 -20
  472. package/dest/worker/node/node_worker.d.ts +0 -6
  473. package/dest/worker/node/node_worker.d.ts.map +0 -1
  474. package/dest/worker/node/node_worker.js +0 -22
  475. package/dest/worker/node/start_node_module.d.ts +0 -7
  476. package/dest/worker/node/start_node_module.d.ts.map +0 -1
  477. package/dest/worker/node/start_node_module.js +0 -31
  478. package/dest/worker/wasm_worker.d.ts +0 -9
  479. package/dest/worker/wasm_worker.d.ts.map +0 -1
  480. package/dest/worker/wasm_worker.js +0 -3
  481. package/dest/worker/worker_pool.d.ts +0 -40
  482. package/dest/worker/worker_pool.d.ts.map +0 -1
  483. package/dest/worker/worker_pool.js +0 -51
  484. package/src/crypto/pedersen/pedersen.elliptic.ts +0 -584
  485. package/src/log/debug.ts +0 -104
  486. package/src/log/log_history.ts +0 -44
  487. package/src/transport/browser/index.ts +0 -4
  488. package/src/transport/browser/message_port_socket.ts +0 -48
  489. package/src/transport/browser/shared_worker_connector.ts +0 -21
  490. package/src/transport/browser/shared_worker_listener.ts +0 -53
  491. package/src/transport/browser/worker_connector.ts +0 -30
  492. package/src/transport/browser/worker_listener.ts +0 -54
  493. package/src/wasm/README.md +0 -6
  494. package/src/wasm/empty_wasi_sdk.ts +0 -166
  495. package/src/wasm/fixtures/gcd.wasm +0 -0
  496. package/src/wasm/fixtures/gcd.wat +0 -27
  497. package/src/wasm/index.ts +0 -1
  498. package/src/wasm/wasm_module.ts +0 -260
  499. package/src/worker/browser/index.ts +0 -2
  500. package/src/worker/browser/start_web_module.ts +0 -24
  501. package/src/worker/browser/web_data_store.ts +0 -38
  502. package/src/worker/browser/web_worker.ts +0 -25
  503. package/src/worker/data_store.ts +0 -19
  504. package/src/worker/index.ts +0 -2
  505. package/src/worker/node/index.ts +0 -2
  506. package/src/worker/node/node_data_store.ts +0 -27
  507. package/src/worker/node/node_worker.ts +0 -23
  508. package/src/worker/node/start_node_module.ts +0 -30
  509. package/src/worker/wasm_worker.ts +0 -7
  510. package/src/worker/worker_pool.ts +0 -73
@@ -1,63 +1,62 @@
1
- import { padArrayEnd } from '../collection/array.js';
2
1
  import { sha256Trunc } from '../crypto/sha256/index.js';
2
+ import { MerkleTreeCalculator } from './merkle_tree_calculator.js';
3
3
  /**
4
- * Computes the merkle root for an unbalanced tree.
4
+ * Computes the Merkle root of an unbalanced tree.
5
5
  *
6
- * @dev Adapted from unbalanced_tree.ts.
7
- * Calculates the tree upwards layer by layer until we reach the root.
8
- * The L1 calculation instead computes the tree from right to left (slightly cheaper gas).
9
- * TODO: A more thorough investigation of which method is cheaper, then use that method everywhere.
10
- */ export function computeUnbalancedMerkleRoot(leaves, emptyLeaf, hasher = sha256Trunc) {
11
- // Pad leaves to 2
12
- if (leaves.length < 2) {
13
- if (emptyLeaf === undefined) {
14
- throw new Error('Cannot compute a Merkle root with less than 2 leaves');
15
- } else {
16
- leaves = padArrayEnd(leaves, emptyLeaf, 2);
17
- }
6
+ * Unlike a balanced Merkle tree, which requires the number of leaves to be a power of two, an unbalanced tree can have
7
+ * any number of leaves.
8
+ *
9
+ * The tree is constructed by iteratively extracting the smallest power-of-two-sized subtrees from **right to left**.
10
+ * For each such subtree, it computes the subtree root and then combines all subtree roots (again from right to left)
11
+ * into a single root using the provided hash function.
12
+ *
13
+ * Note: We need the final tree to be as shallow as possible, to minimize the size of the sibling path required to prove
14
+ * membership of a leaf. Therefor, the computation proceeds from right to left - smaller subtrees must always be
15
+ * combined before being merged with a larger sibling on their left.
16
+ *
17
+ * For example, consider an unbalanced tree made of three subtrees of sizes 2, 4, and 8. If we combine the size-2 and
18
+ * size-4 subtrees first (producing a subtree of depth 3), and then merge it with the size-8 subtree (also depth 3), the
19
+ * resulting tree has a maximum depth of 4.
20
+ *
21
+ * But if we instead combine the size-4 and size-8 subtrees first (depth 4), and then merge with the size-2 subtree
22
+ * (depth 1), the final tree has a depth of 5.
23
+ */ export function computeUnbalancedMerkleTreeRoot(leaves, hasher = sha256Trunc) {
24
+ if (!leaves.length) {
25
+ throw new Error('Cannot compute a Merkle root with no leaves');
18
26
  }
19
- const depth = Math.ceil(Math.log2(leaves.length));
20
- let [layerWidth, nodeToShift] = leaves.length & 1 ? [
21
- leaves.length - 1,
22
- leaves[leaves.length - 1]
23
- ] : [
24
- leaves.length,
25
- Buffer.alloc(0)
26
- ];
27
- // Allocate this layer's leaves and init the next layer up
28
- let thisLayer = leaves.slice(0, layerWidth);
29
- let nextLayer = [];
30
- for(let i = 0; i < depth; i++){
31
- for(let j = 0; j < layerWidth; j += 2){
32
- // Store the hash of each pair one layer up
33
- nextLayer[j / 2] = hasher(Buffer.concat([
34
- thisLayer[j],
35
- thisLayer[j + 1]
36
- ]));
37
- }
38
- layerWidth /= 2;
39
- if (layerWidth & 1) {
40
- if (nodeToShift.length) {
41
- // If the next layer has odd length, and we have a node that needs to be shifted up, add it here
42
- nextLayer.push(nodeToShift);
43
- layerWidth += 1;
44
- nodeToShift = Buffer.alloc(0);
27
+ if (leaves.length === 1) {
28
+ return leaves[0];
29
+ }
30
+ let numRemainingLeaves = leaves.length;
31
+ let subtreeSize = 1;
32
+ let root;
33
+ while(numRemainingLeaves > 1){
34
+ if ((numRemainingLeaves & subtreeSize) !== 0) {
35
+ const subtreeLeaves = leaves.slice(numRemainingLeaves - subtreeSize, numRemainingLeaves);
36
+ const subtreeRoot = MerkleTreeCalculator.computeTreeRootSync(subtreeLeaves, hasher);
37
+ if (!root) {
38
+ root = subtreeRoot;
45
39
  } else {
46
- // If we don't have a node waiting to be shifted, store the next layer's final node to be shifted
47
- layerWidth -= 1;
48
- nodeToShift = nextLayer[layerWidth];
40
+ root = hasher(Buffer.concat([
41
+ subtreeRoot,
42
+ root
43
+ ]));
49
44
  }
45
+ numRemainingLeaves -= subtreeSize;
50
46
  }
51
- // reset the layers
52
- thisLayer = nextLayer;
53
- nextLayer = [];
47
+ subtreeSize *= 2;
54
48
  }
55
- // return the root
56
- return thisLayer[0];
49
+ return root;
57
50
  }
58
- function getMaxBalancedTreeDepth(numLeaves) {
51
+ /// Get the depth of the maximum balanced tree that can be created with the given number of leaves. The subtree will be
52
+ /// the left most subtree of the wonky tree with a total of `numLeaves` leaves.
53
+ ///
54
+ /// Note: All the leaves may not be used to form the tree. For example, if there are 5 leaves, the maximum depth is 2,
55
+ /// only 4 leaves are used to form a balanced tree.
56
+ function getMaxBalancedSubtreeDepth(numLeaves) {
59
57
  return Math.floor(Math.log2(numLeaves));
60
58
  }
59
+ /// Get the maximum depth of an unbalanced tree that can be created with the given number of leaves.
61
60
  function getMaxUnbalancedTreeDepth(numLeaves) {
62
61
  return Math.ceil(Math.log2(numLeaves));
63
62
  }
@@ -70,7 +69,7 @@ function findPosition(rootLevel, leafLevel, numLeaves, indexOffset, targetIndex)
70
69
  };
71
70
  }
72
71
  // The largest balanced tree that can be created with the given number of leaves.
73
- const maxBalancedTreeDepth = getMaxBalancedTreeDepth(numLeaves);
72
+ const maxBalancedTreeDepth = getMaxBalancedSubtreeDepth(numLeaves);
74
73
  const numBalancedLeaves = 2 ** maxBalancedTreeDepth;
75
74
  const numRemainingLeaves = numLeaves - numBalancedLeaves;
76
75
  if (targetIndex < numBalancedLeaves) {
@@ -0,0 +1,48 @@
1
+ import type { Hasher } from './hasher.js';
2
+ import { SiblingPath } from './sibling_path.js';
3
+ import { type TreeNodeLocation } from './unbalanced_tree_store.js';
4
+ export declare function computeCompressedUnbalancedMerkleTreeRoot(leaves: Buffer[], valueToCompress?: Buffer<ArrayBuffer>, hasher?: Hasher['hash']): Buffer;
5
+ /**
6
+ * An ephemeral unbalanced Merkle tree implementation.
7
+ * Follows the rollup implementation which greedily hashes pairs of nodes up the tree.
8
+ * Remaining rightmost nodes are shifted up until they can be paired.
9
+ * The values that match the `valueToCompress` are skipped and the sibling of the compressed leaf are shifted up until
10
+ * they can be paired.
11
+ * If there is only one leaf, the root is the leaf.
12
+ */
13
+ export declare class UnbalancedMerkleTreeCalculator {
14
+ private readonly leaves;
15
+ private readonly valueToCompress;
16
+ private readonly hasher;
17
+ private store;
18
+ private leafLocations;
19
+ constructor(leaves: Buffer[], valueToCompress: Buffer, hasher: Hasher['hash']);
20
+ static create(leaves: Buffer[], valueToCompress?: Buffer<ArrayBuffer>, hasher?: (left: Buffer, right: Buffer) => Buffer<ArrayBuffer>): UnbalancedMerkleTreeCalculator;
21
+ /**
22
+ * Returns the root of the tree.
23
+ * @returns The root of the tree.
24
+ */
25
+ getRoot(): Buffer;
26
+ /**
27
+ * Returns a sibling path for the element.
28
+ * @param value - The value of the element.
29
+ * @returns A sibling path for the element.
30
+ * Note: The sibling path is an array of sibling hashes, with the lowest hash (leaf hash) first, and the highest hash last.
31
+ */
32
+ getSiblingPath<N extends number>(value: Buffer): SiblingPath<N>;
33
+ /**
34
+ * Returns a sibling path for the leaf at the given index.
35
+ * @param leafIndex - The index of the leaf.
36
+ * @returns A sibling path for the leaf.
37
+ */
38
+ getSiblingPathByLeafIndex<N extends number>(leafIndex: number): SiblingPath<N>;
39
+ getLeafLocation(leafIndex: number): TreeNodeLocation;
40
+ /**
41
+ * Adds leaves and nodes to the store. Updates the leafLocations.
42
+ * @param leaves - The leaves of the tree.
43
+ */
44
+ private buildTree;
45
+ private shiftNodeUp;
46
+ private shiftChildrenUp;
47
+ }
48
+ //# sourceMappingURL=unbalanced_merkle_tree_calculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbalanced_merkle_tree_calculator.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree_calculator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,4BAA4B,CAAC;AAExF,wBAAgB,yCAAyC,CACvD,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,sBAAmB,EAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,GACtB,MAAM,CAGR;AAOD;;;;;;;GAOG;AACH,qBAAa,8BAA8B;IAKvC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,aAAa,CAA0B;gBAG5B,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;IAUzC,MAAM,CAAC,MAAM,CACX,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,sBAAkB,EACjC,MAAM,IAAI,MAAM,MAAM,EAAE,OAAO,MAAM,KAAkD,MAAM,CAAC,WAAW,CAAC;IAK5G;;;OAGG;IACI,OAAO,IAAI,MAAM;IAIxB;;;;;OAKG;IACI,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC;IAStE;;;;OAIG;IACI,yBAAyB,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC;IAqB9E,eAAe,CAAC,SAAS,EAAE,MAAM;IAIxC;;;OAGG;IACH,OAAO,CAAC,SAAS;IAkDjB,OAAO,CAAC,WAAW;IAcnB,OAAO,CAAC,eAAe;CAoBxB"}
@@ -0,0 +1,162 @@
1
+ import { sha256Trunc } from '../crypto/index.js';
2
+ import { SiblingPath } from './sibling_path.js';
3
+ import { UnbalancedTreeStore } from './unbalanced_tree_store.js';
4
+ export function computeCompressedUnbalancedMerkleTreeRoot(leaves, valueToCompress = Buffer.alloc(32), hasher) {
5
+ const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, hasher);
6
+ return calculator.getRoot();
7
+ }
8
+ /**
9
+ * An ephemeral unbalanced Merkle tree implementation.
10
+ * Follows the rollup implementation which greedily hashes pairs of nodes up the tree.
11
+ * Remaining rightmost nodes are shifted up until they can be paired.
12
+ * The values that match the `valueToCompress` are skipped and the sibling of the compressed leaf are shifted up until
13
+ * they can be paired.
14
+ * If there is only one leaf, the root is the leaf.
15
+ */ export class UnbalancedMerkleTreeCalculator {
16
+ leaves;
17
+ valueToCompress;
18
+ hasher;
19
+ store;
20
+ leafLocations;
21
+ constructor(leaves, valueToCompress, hasher){
22
+ this.leaves = leaves;
23
+ this.valueToCompress = valueToCompress;
24
+ this.hasher = hasher;
25
+ this.leafLocations = [];
26
+ if (leaves.length === 0) {
27
+ throw Error('Cannot create a compressed unbalanced tree with 0 leaves.');
28
+ }
29
+ this.store = new UnbalancedTreeStore(leaves.length);
30
+ this.buildTree();
31
+ }
32
+ static create(leaves, valueToCompress = Buffer.alloc(0), hasher = (left, right)=>sha256Trunc(Buffer.concat([
33
+ left,
34
+ right
35
+ ]))) {
36
+ return new UnbalancedMerkleTreeCalculator(leaves, valueToCompress, hasher);
37
+ }
38
+ /**
39
+ * Returns the root of the tree.
40
+ * @returns The root of the tree.
41
+ */ getRoot() {
42
+ return this.store.getRoot().value;
43
+ }
44
+ /**
45
+ * Returns a sibling path for the element.
46
+ * @param value - The value of the element.
47
+ * @returns A sibling path for the element.
48
+ * Note: The sibling path is an array of sibling hashes, with the lowest hash (leaf hash) first, and the highest hash last.
49
+ */ getSiblingPath(value) {
50
+ const leafIndex = this.leaves.findIndex((leaf)=>leaf.equals(value));
51
+ if (leafIndex === -1) {
52
+ throw Error(`Leaf value ${value.toString('hex')} not found in tree.`);
53
+ }
54
+ return this.getSiblingPathByLeafIndex(leafIndex);
55
+ }
56
+ /**
57
+ * Returns a sibling path for the leaf at the given index.
58
+ * @param leafIndex - The index of the leaf.
59
+ * @returns A sibling path for the leaf.
60
+ */ getSiblingPathByLeafIndex(leafIndex) {
61
+ if (leafIndex >= this.leaves.length) {
62
+ throw Error(`Leaf index ${leafIndex} out of bounds. Tree has ${this.leaves.length} leaves.`);
63
+ }
64
+ const leaf = this.leaves[leafIndex];
65
+ if (leaf.equals(this.valueToCompress)) {
66
+ throw Error(`Leaf at index ${leafIndex} has been compressed.`);
67
+ }
68
+ const path = [];
69
+ let location = this.leafLocations[leafIndex];
70
+ while(location.level > 0){
71
+ const sibling = this.store.getSibling(location);
72
+ path.push(sibling.value);
73
+ location = this.store.getParentLocation(location);
74
+ }
75
+ return new SiblingPath(path.length, path);
76
+ }
77
+ getLeafLocation(leafIndex) {
78
+ return this.leafLocations[leafIndex];
79
+ }
80
+ /**
81
+ * Adds leaves and nodes to the store. Updates the leafLocations.
82
+ * @param leaves - The leaves of the tree.
83
+ */ buildTree() {
84
+ this.leafLocations = this.leaves.map((value, i)=>this.store.setLeaf(i, {
85
+ value,
86
+ leafIndex: i
87
+ }));
88
+ // Start with the leaves that are not compressed.
89
+ let toProcess = this.leafLocations.filter((_, i)=>!this.leaves[i].equals(this.valueToCompress));
90
+ if (!toProcess.length) {
91
+ // All leaves are compressed. Set 0 to the root.
92
+ this.store.setNode({
93
+ level: 0,
94
+ index: 0
95
+ }, {
96
+ value: Buffer.alloc(32)
97
+ });
98
+ return;
99
+ }
100
+ const level = toProcess[0].level;
101
+ for(let i = level; i > 0; i--){
102
+ const toProcessNext = [];
103
+ for (const location of toProcess){
104
+ if (location.level !== i) {
105
+ toProcessNext.push(location);
106
+ continue;
107
+ }
108
+ const parentLocation = this.store.getParentLocation(location);
109
+ if (this.store.getNode(parentLocation)) {
110
+ continue;
111
+ }
112
+ const sibling = this.store.getSibling(location);
113
+ // If sibling is undefined, all its children are compressed.
114
+ const shouldShiftUp = !sibling || sibling.value.equals(this.valueToCompress);
115
+ if (shouldShiftUp) {
116
+ // The node becomes the parent if the sibling is a compressed leaf.
117
+ const isLeaf = this.shiftNodeUp(location, parentLocation);
118
+ if (!isLeaf) {
119
+ this.shiftChildrenUp(location);
120
+ }
121
+ } else {
122
+ // Hash the value with the (right) sibling and update the parent node.
123
+ const node = this.store.getNode(location);
124
+ const parentValue = this.hasher(node.value, sibling.value);
125
+ this.store.setNode(parentLocation, {
126
+ value: parentValue
127
+ });
128
+ }
129
+ // Add the parent location to be processed next.
130
+ toProcessNext.push(parentLocation);
131
+ }
132
+ toProcess = toProcessNext;
133
+ }
134
+ }
135
+ shiftNodeUp(fromLocation, toLocation) {
136
+ const node = this.store.getNode(fromLocation);
137
+ this.store.setNode(toLocation, node);
138
+ const isLeaf = node.leafIndex !== undefined;
139
+ if (isLeaf) {
140
+ // Update the location if the node is a leaf.
141
+ this.leafLocations[node.leafIndex] = toLocation;
142
+ }
143
+ return isLeaf;
144
+ }
145
+ shiftChildrenUp(parent) {
146
+ const [left, right] = this.store.getChildLocations(parent);
147
+ const level = parent.level;
148
+ const groupSize = 2 ** level;
149
+ const computeNewLocation = (index)=>({
150
+ level,
151
+ index: Math.floor(index / (groupSize * 2)) * groupSize + index % groupSize
152
+ });
153
+ const isLeftLeaf = this.shiftNodeUp(left, computeNewLocation(left.index));
154
+ const isRightLeaf = this.shiftNodeUp(right, computeNewLocation(right.index));
155
+ if (!isLeftLeaf) {
156
+ this.shiftChildrenUp(left);
157
+ }
158
+ if (!isRightLeaf) {
159
+ this.shiftChildrenUp(right);
160
+ }
161
+ }
162
+ }
@@ -12,6 +12,7 @@ export declare class UnbalancedTreeStore<T> {
12
12
  getChildLocations({ level, index }: TreeNodeLocation): [TreeNodeLocation, TreeNodeLocation];
13
13
  getLeaf(leafIndex: number): T | undefined;
14
14
  getNode(location: TreeNodeLocation): T | undefined;
15
+ getRoot(): T | undefined;
15
16
  getParent(location: TreeNodeLocation): T | undefined;
16
17
  getSibling(location: TreeNodeLocation): T | undefined;
17
18
  getChildren(location: TreeNodeLocation): [T | undefined, T | undefined];
@@ -1 +1 @@
1
- {"version":3,"file":"unbalanced_tree_store.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_tree_store.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAOD,qBAAa,mBAAmB,CAAC,CAAC;;gBAIpB,SAAS,EAAE,MAAM;IAI7B,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,gBAAgB;IAiBtD,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IAWpD,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB;IAQvE,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB;IAQxE,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAM3F,OAAO,CAAC,SAAS,EAAE,MAAM;IASzB,OAAO,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS;IAIlD,SAAS,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS;IAKpD,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS;IAKrD,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC;CAQxE"}
1
+ {"version":3,"file":"unbalanced_tree_store.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_tree_store.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAOD,qBAAa,mBAAmB,CAAC,CAAC;;gBAIpB,SAAS,EAAE,MAAM;IAI7B,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,gBAAgB;IAiBtD,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IAWpD,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB;IAQvE,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB;IAQxE,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAM3F,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IASzC,OAAO,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS;IAIlD,OAAO,IAAI,CAAC,GAAG,SAAS;IAIxB,SAAS,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS;IAKpD,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS;IAKrD,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC;CAQxE"}
@@ -73,6 +73,12 @@ export class UnbalancedTreeStore {
73
73
  getNode(location) {
74
74
  return this.#nodeMapping.get(this.#getKey(location))?.value;
75
75
  }
76
+ getRoot() {
77
+ return this.getNode({
78
+ level: 0,
79
+ index: 0
80
+ });
81
+ }
76
82
  getParent(location) {
77
83
  const parentLocation = this.getParentLocation(location);
78
84
  return this.getNode(parentLocation);
@@ -14,6 +14,29 @@ export type Writeable<T> = {
14
14
  };
15
15
  /** Removes readonly modifiers for an object. */
16
16
  export declare function unfreeze<T>(obj: T): Writeable<T>;
17
- /** Maybe exists, maybe not. */
18
- export type Maybe<T extends object> = T | unknown;
17
+ /** Resolves a record-like type. Lifted from viem. */
18
+ export type Prettify<T> = {
19
+ [K in keyof T]: T[K];
20
+ } & {};
21
+ /**
22
+ * Type-safe Event Emitter type
23
+ * @example
24
+ * export type ArchiverEmitter = TypedEventEmitter<{
25
+ * [L2BlockSourceEvents.L2PruneDetected]: (args: L2BlockSourceEvent) => void;
26
+ * [L2BlockSourceEvents.L2BlockProven]: (args: L2BlockSourceEvent) => void;
27
+ * }>;
28
+ * class Archiver extends (EventEmitter as new () => ArchiverEmitter) {
29
+ * // ...
30
+ * }
31
+ */
32
+ export interface TypedEventEmitter<TEventMap extends {
33
+ [key in keyof TEventMap]: (...args: any[]) => void;
34
+ }> {
35
+ once<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
36
+ on<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
37
+ off<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
38
+ emit<K extends keyof TEventMap>(event: K, ...args: Parameters<TEventMap[K]>): boolean;
39
+ removeListener<K extends keyof TEventMap>(event: K, listener: TEventMap[K]): this;
40
+ removeAllListeners<K extends keyof TEventMap>(event: K): this;
41
+ }
19
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAEvB,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,kCAAkC;AAClC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAE1B,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,uDAAuD;AACvD,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E,6CAA6C;AAC7C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE9D,gDAAgD;AAChD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhD;AAED,+BAA+B;AAC/B,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,kCAAkC;AAClC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,uDAAuD;AACvD,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E,6CAA6C;AAC7C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE9D,gDAAgD;AAChD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhD;AAED,qDAAqD;AACrD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,GAAG,EAAE,CAAC;AAEP;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAiB,CAAC,SAAS,SAAS;KAAG,GAAG,IAAI,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI;CAAE;IACzG,IAAI,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACxE,EAAE,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACtE,GAAG,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACvE,IAAI,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;IACtF,cAAc,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAClF,kBAAkB,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAE/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/url/index.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AAEH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA4CjD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/url/index.ts"],"names":[],"mappings":"AAmBA;;;;;;GAMG;AAEH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA4CjD"}
package/dest/url/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint-disable */ // Copyright (c) 2014 Nathan Rajlich <nathan@tootallnate.net>
1
+ // Copyright (c) 2014 Nathan Rajlich <nathan@tootallnate.net>
2
2
  // Permission is hereby granted, free of charge, to any person obtaining
3
3
  // a copy of this software and associated documentation files (the
4
4
  // 'Software'), to deal in the Software without restriction, including
package/package.json CHANGED
@@ -1,20 +1,22 @@
1
1
  {
2
2
  "name": "@aztec/foundation",
3
- "version": "0.0.0-test.1",
3
+ "version": "0.0.1-commit.b655e406",
4
4
  "type": "module",
5
5
  "main": "./dest/index.js",
6
6
  "types": "./dest/index.d.ts",
7
7
  "exports": {
8
- "./eslint": "./.eslintrc.cjs",
9
- "./eslint.docs": "./.eslintrc.docs.cjs",
8
+ "./eslint": "./eslint.config.js",
9
+ "./eslint.docs": "./eslint.config.docs.js",
10
10
  "./prettier": "./.prettierrc.json",
11
11
  "./abi": "./dest/abi/index.js",
12
12
  "./async-map": "./dest/async-map/index.js",
13
13
  "./async-pool": "./dest/async-pool/index.js",
14
+ "./bigint": "./dest/bigint/index.js",
14
15
  "./collection": "./dest/collection/index.js",
15
16
  "./config": "./dest/config/index.js",
16
17
  "./crypto": "./dest/crypto/index.js",
17
18
  "./crypto/sync": "./dest/crypto/sync/index.js",
19
+ "./crypto/bls/bn254_keystore": "./dest/crypto/bls/bn254_keystore.js",
18
20
  "./decorators": "./dest/decorators/index.js",
19
21
  "./error": "./dest/error/index.js",
20
22
  "./eth-address": "./dest/eth-address/index.js",
@@ -38,8 +40,6 @@
38
40
  "./timer": "./dest/timer/index.js",
39
41
  "./transport": "./dest/transport/index.js",
40
42
  "./trees": "./dest/trees/index.js",
41
- "./wasm": "./dest/wasm/index.js",
42
- "./worker": "./dest/worker/index.js",
43
43
  "./bigint-buffer": "./dest/bigint-buffer/index.js",
44
44
  "./types": "./dest/types/index.js",
45
45
  "./schemas": "./dest/schemas/index.js",
@@ -48,19 +48,19 @@
48
48
  "./noir": "./dest/noir/index.js",
49
49
  "./testing": "./dest/testing/index.js",
50
50
  "./testing/files": "./dest/testing/files/index.js",
51
+ "./profiler": "./dest/profiler/index.js",
51
52
  "./array": "./dest/array/index.js",
52
53
  "./validation": "./dest/validation/index.js",
53
54
  "./promise": "./dest/promise/index.js",
54
55
  "./string": "./dest/string/index.js",
55
- "./message": "./dest/message/index.js"
56
+ "./message": "./dest/message/index.js",
57
+ "./number": "./dest/number/index.js"
56
58
  },
57
59
  "scripts": {
58
60
  "build": "yarn clean && tsc -b",
59
61
  "build:dev": "tsc -b --watch",
60
62
  "clean": "rm -rf ./dest .tsbuildinfo",
61
63
  "generate": "true",
62
- "formatting": "run -T prettier --check ./src && run -T eslint ./src",
63
- "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
64
64
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
65
65
  },
66
66
  "inherits": [
@@ -96,74 +96,68 @@
96
96
  ],
97
97
  "testTimeout": 120000,
98
98
  "setupFilesAfterEnv": [
99
- "../../foundation/src/jest/setup.mjs"
99
+ "../../foundation/src/jest/setupAfterEnv.mjs"
100
100
  ],
101
101
  "setupFiles": [
102
102
  "../../foundation/src/jest/setup.mjs"
103
- ]
103
+ ],
104
+ "testEnvironment": "../../foundation/src/jest/env.mjs"
104
105
  },
105
106
  "dependencies": {
106
- "@aztec/bb.js": "0.0.0-test.1",
107
+ "@aztec/bb.js": "0.0.1-commit.b655e406",
107
108
  "@koa/cors": "^5.0.0",
108
- "@noble/curves": "^1.2.0",
109
+ "@noble/curves": "=1.7.0",
110
+ "@noble/hashes": "^1.6.1",
111
+ "@scure/bip39": "^2.0.1",
109
112
  "bn.js": "^5.2.1",
110
- "c-kzg": "4.0.0-alpha.1",
111
113
  "colorette": "^2.0.20",
112
- "debug": "^4.3.4",
113
114
  "detect-node": "^2.1.0",
114
- "elliptic": "^6.5.4",
115
115
  "hash.js": "^1.1.7",
116
- "koa": "^2.14.2",
116
+ "koa": "^2.16.1",
117
117
  "koa-bodyparser": "^4.4.0",
118
118
  "koa-compress": "^5.1.0",
119
- "koa-router": "^12.0.0",
119
+ "koa-router": "^13.1.1",
120
120
  "leveldown": "^6.1.1",
121
- "levelup": "^5.1.1",
122
121
  "lodash.chunk": "^4.2.0",
123
122
  "lodash.clonedeepwith": "^4.5.0",
124
- "memdown": "^6.1.1",
125
123
  "pako": "^2.1.0",
126
124
  "pino": "^9.5.0",
127
125
  "pino-pretty": "^13.0.0",
128
126
  "sha3": "^2.1.4",
129
- "undici": "^7.3.0",
127
+ "undici": "^5.28.5",
130
128
  "zod": "^3.23.8"
131
129
  },
132
130
  "devDependencies": {
133
- "@jest/globals": "^29.5.0",
131
+ "@jest/globals": "^30.0.0",
134
132
  "@libp2p/interface": "1.3.1",
135
- "@types/bn.js": "^5.1.3",
136
- "@types/debug": "^4.1.7",
137
133
  "@types/detect-node": "^2.0.0",
138
- "@types/elliptic": "^6.4.16",
139
- "@types/jest": "^29.5.0",
140
- "@types/koa": "^2.13.5",
134
+ "@types/jest": "^30.0.0",
135
+ "@types/koa": "^2.15.0",
141
136
  "@types/koa-bodyparser": "^4.3.10",
142
137
  "@types/koa-compress": "^4.0.3",
143
138
  "@types/koa-router": "^7.4.4",
144
139
  "@types/koa__cors": "^4.0.0",
145
140
  "@types/leveldown": "^4.0.3",
146
- "@types/levelup": "^5.1.2",
147
141
  "@types/lodash.chunk": "^4.2.9",
148
142
  "@types/lodash.clonedeepwith": "^4.5.7",
149
- "@types/memdown": "^3.0.1",
150
- "@types/node": "^18.7.23",
143
+ "@types/node": "^22.15.17",
151
144
  "@types/pako": "^2.0.0",
152
145
  "@types/supertest": "^2.0.12",
153
- "@typescript-eslint/eslint-plugin": "^6.2.1",
154
- "@typescript-eslint/parser": "^6.2.1",
155
146
  "comlink": "^4.4.1",
156
- "eslint": "^8.21.0",
157
- "eslint-config-prettier": "^8.5.0",
158
- "eslint-plugin-jsdoc": "^40.1.0",
159
- "eslint-plugin-no-only-tests": "^3.1.0",
160
- "eslint-plugin-tsdoc": "^0.2.17",
161
- "jest": "^29.5.0",
162
- "prettier": "^2.7.1",
147
+ "eslint": "^9.26.0",
148
+ "eslint-config-prettier": "^10.1.5",
149
+ "eslint-plugin-import": "^2.31.0",
150
+ "eslint-plugin-jsdoc": "^50.6.14",
151
+ "eslint-plugin-no-only-tests": "^3.3.0",
152
+ "eslint-plugin-tsdoc": "^0.4.0",
153
+ "globals": "^16.1.0",
154
+ "jest": "^30.0.0",
155
+ "prettier": "^3.5.3",
163
156
  "supertest": "^6.3.3",
164
157
  "ts-node": "^10.9.1",
165
- "typescript": "^5.0.4",
166
- "viem": "2.22.8"
158
+ "typescript": "^5.3.3",
159
+ "typescript-eslint": "^8.32.1",
160
+ "viem": "npm:@spalladino/viem@2.38.2-eip7594.0"
167
161
  },
168
162
  "files": [
169
163
  "dest",
@@ -171,6 +165,6 @@
171
165
  "!*.test.*"
172
166
  ],
173
167
  "engines": {
174
- "node": ">=18"
168
+ "node": ">=20.10"
175
169
  }
176
170
  }
@@ -148,3 +148,16 @@ export function assertRightPadded<T>(arr: T[], isEmpty: (item: T) => boolean) {
148
148
  }
149
149
  }
150
150
  }
151
+
152
+ /**
153
+ * Shuffles an array in-place using the Fisher-Yates algorith,
154
+ * @param arr - The array to shuffle
155
+ */
156
+ export function shuffle<T>(arr: T[]): void {
157
+ for (let i = arr.length - 1; i > 0; i--) {
158
+ const j = (Math.random() * (i + 1)) | 0;
159
+ const temp = arr[i];
160
+ arr[i] = arr[j];
161
+ arr[j] = temp;
162
+ }
163
+ }
@@ -29,6 +29,7 @@
29
29
  export function asyncPool<T, R>(poolLimit: number, iterable: T[], iteratorFn: (item: T, iterable: T[]) => Promise<R>) {
30
30
  let i = 0;
31
31
  const ret: Promise<R>[] = [];
32
+ // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
32
33
  const executing: Set<Promise<R>> = new Set();
33
34
  const enqueue = (): Promise<any> => {
34
35
  if (i === iterable.length) {
@@ -0,0 +1,20 @@
1
+ /** Returns minimum value across a list of bigints. */
2
+ export function minBigint(...values: bigint[]): bigint {
3
+ if (values.length === 0) {
4
+ throw new Error('Cannot get min of empty array');
5
+ }
6
+ return values.reduce((min, value) => (value < min ? value : min), values[0]);
7
+ }
8
+
9
+ /** Returns maximim value across a list of bigints. */
10
+ export function maxBigint(...values: bigint[]): bigint {
11
+ if (values.length === 0) {
12
+ throw new Error('Cannot get max of empty array');
13
+ }
14
+ return values.reduce((max, value) => (value > max ? value : max), values[0]);
15
+ }
16
+
17
+ /** Sums an array of bigints */
18
+ export function sumBigint(values: bigint[]): bigint {
19
+ return values.reduce((sum, value) => sum + value, 0n);
20
+ }