@aztec/foundation 0.0.0-test.0 → 0.0.1-fake-c83136db25

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 (498) 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 +14 -3
  21. package/dest/collection/array.d.ts.map +1 -1
  22. package/dest/collection/array.js +45 -0
  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/bn254/index.d.ts +54 -0
  44. package/dest/crypto/bn254/index.d.ts.map +1 -0
  45. package/dest/crypto/bn254/index.js +140 -0
  46. package/dest/crypto/ecdsa/index.d.ts +2 -2
  47. package/dest/crypto/ecdsa/index.d.ts.map +1 -1
  48. package/dest/crypto/ecdsa/index.js +70 -48
  49. package/dest/crypto/ecdsa/signature.d.ts +1 -3
  50. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  51. package/dest/crypto/grumpkin/index.d.ts +6 -13
  52. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  53. package/dest/crypto/grumpkin/index.js +69 -54
  54. package/dest/crypto/index.d.ts +1 -0
  55. package/dest/crypto/index.d.ts.map +1 -1
  56. package/dest/crypto/index.js +1 -0
  57. package/dest/crypto/keccak/index.d.ts +2 -4
  58. package/dest/crypto/keccak/index.d.ts.map +1 -1
  59. package/dest/crypto/keys/index.d.ts +0 -2
  60. package/dest/crypto/keys/index.d.ts.map +1 -1
  61. package/dest/crypto/keys/index.js +9 -4
  62. package/dest/crypto/pedersen/pedersen.noble.d.ts +2 -4
  63. package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -1
  64. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -4
  65. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  66. package/dest/crypto/pedersen/pedersen.wasm.js +29 -13
  67. package/dest/crypto/poseidon/index.d.ts +0 -2
  68. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  69. package/dest/crypto/poseidon/index.js +42 -17
  70. package/dest/crypto/random/index.d.ts +1 -3
  71. package/dest/crypto/random/index.d.ts.map +1 -1
  72. package/dest/crypto/random/index.js +2 -34
  73. package/dest/crypto/random/randomness_singleton.d.ts +0 -2
  74. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  75. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  76. package/dest/crypto/schnorr/index.js +35 -37
  77. package/dest/crypto/schnorr/signature.d.ts +3 -5
  78. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  79. package/dest/crypto/secp256k1/index.d.ts +4 -6
  80. package/dest/crypto/secp256k1/index.d.ts.map +1 -1
  81. package/dest/crypto/secp256k1/index.js +29 -18
  82. package/dest/crypto/secp256k1-signer/utils.d.ts +15 -2
  83. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  84. package/dest/crypto/secp256k1-signer/utils.js +21 -3
  85. package/dest/crypto/serialize.d.ts +4 -6
  86. package/dest/crypto/serialize.d.ts.map +1 -1
  87. package/dest/crypto/sha256/index.d.ts +21 -4
  88. package/dest/crypto/sha256/index.d.ts.map +1 -1
  89. package/dest/crypto/sha256/index.js +42 -0
  90. package/dest/crypto/sha512/index.d.ts +1 -3
  91. package/dest/crypto/sha512/index.d.ts.map +1 -1
  92. package/dest/crypto/signature/index.d.ts +0 -2
  93. package/dest/crypto/signature/index.d.ts.map +1 -1
  94. package/dest/crypto/sync/index.js +3 -1
  95. package/dest/crypto/sync/pedersen/index.d.ts +2 -4
  96. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  97. package/dest/crypto/sync/pedersen/index.js +17 -10
  98. package/dest/crypto/sync/poseidon/index.d.ts +0 -2
  99. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  100. package/dest/crypto/sync/poseidon/index.js +27 -12
  101. package/dest/decorators/memoize.d.ts.map +1 -1
  102. package/dest/eth-address/index.d.ts +6 -7
  103. package/dest/eth-address/index.d.ts.map +1 -1
  104. package/dest/eth-address/index.js +5 -0
  105. package/dest/eth-signature/eth_signature.d.ts +16 -14
  106. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  107. package/dest/eth-signature/eth_signature.js +31 -17
  108. package/dest/fields/bls12_fields.d.ts +148 -0
  109. package/dest/fields/bls12_fields.d.ts.map +1 -0
  110. package/dest/fields/bls12_fields.js +359 -0
  111. package/dest/fields/bls12_point.d.ts +229 -0
  112. package/dest/fields/bls12_point.d.ts.map +1 -0
  113. package/dest/fields/bls12_point.js +398 -0
  114. package/dest/fields/coordinate.d.ts +0 -2
  115. package/dest/fields/coordinate.d.ts.map +1 -1
  116. package/dest/fields/fields.d.ts +6 -3
  117. package/dest/fields/fields.d.ts.map +1 -1
  118. package/dest/fields/fields.js +43 -15
  119. package/dest/fields/index.d.ts +2 -0
  120. package/dest/fields/index.d.ts.map +1 -1
  121. package/dest/fields/index.js +2 -0
  122. package/dest/fields/point.d.ts +2 -4
  123. package/dest/fields/point.d.ts.map +1 -1
  124. package/dest/fields/point.js +3 -3
  125. package/dest/fs/index.d.ts +1 -0
  126. package/dest/fs/index.d.ts.map +1 -1
  127. package/dest/fs/index.js +1 -0
  128. package/dest/fs/try_rm_dir.d.ts +3 -0
  129. package/dest/fs/try_rm_dir.d.ts.map +1 -0
  130. package/dest/fs/try_rm_dir.js +16 -0
  131. package/dest/index.d.ts +1 -2
  132. package/dest/index.d.ts.map +1 -1
  133. package/dest/index.js +1 -2
  134. package/dest/iterable/filter.js +1 -1
  135. package/dest/iterable/map.js +1 -1
  136. package/dest/jest/env.js +48 -0
  137. package/dest/jest/setupAfterEnv.js +3 -0
  138. package/dest/json-rpc/client/fetch.d.ts +2 -2
  139. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  140. package/dest/json-rpc/client/fetch.js +16 -30
  141. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +9 -3
  142. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  143. package/dest/json-rpc/client/safe_json_rpc_client.js +173 -13
  144. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  145. package/dest/json-rpc/client/undici.js +6 -7
  146. package/dest/json-rpc/convert.d.ts +2 -9
  147. package/dest/json-rpc/convert.d.ts.map +1 -1
  148. package/dest/json-rpc/convert.js +1 -9
  149. package/dest/json-rpc/errors.d.ts +4 -0
  150. package/dest/json-rpc/errors.d.ts.map +1 -0
  151. package/dest/json-rpc/errors.js +6 -0
  152. package/dest/json-rpc/fixtures/class_a.d.ts +5 -3
  153. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  154. package/dest/json-rpc/fixtures/class_b.d.ts +5 -3
  155. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  156. package/dest/json-rpc/index.d.ts +2 -1
  157. package/dest/json-rpc/index.d.ts.map +1 -1
  158. package/dest/json-rpc/index.js +2 -1
  159. package/dest/json-rpc/js_utils.d.ts.map +1 -1
  160. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +21 -22
  161. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  162. package/dest/json-rpc/server/safe_json_rpc_server.js +161 -56
  163. package/dest/json-rpc/test/integration.d.ts +1 -2
  164. package/dest/json-rpc/test/integration.d.ts.map +1 -1
  165. package/dest/log/console.d.ts.map +1 -1
  166. package/dest/log/gcloud-logger-config.d.ts +0 -1
  167. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  168. package/dest/log/gcloud-logger-config.js +1 -9
  169. package/dest/log/index.d.ts +4 -4
  170. package/dest/log/index.d.ts.map +1 -1
  171. package/dest/log/index.js +4 -4
  172. package/dest/log/libp2p_logger.js +13 -2
  173. package/dest/log/log_fn.d.ts +1 -1
  174. package/dest/log/log_fn.d.ts.map +1 -1
  175. package/dest/log/noir_debug_log_util.d.ts +14 -0
  176. package/dest/log/noir_debug_log_util.d.ts.map +1 -0
  177. package/dest/log/noir_debug_log_util.js +14 -0
  178. package/dest/log/pino-logger.d.ts +2 -2
  179. package/dest/log/pino-logger.d.ts.map +1 -1
  180. package/dest/log/pino-logger.js +28 -2
  181. package/dest/message/index.d.ts.map +1 -1
  182. package/dest/mutex/mutex_database.d.ts.map +1 -1
  183. package/dest/noir/noir_package_config.d.ts +4 -4
  184. package/dest/number/index.d.ts +3 -0
  185. package/dest/number/index.d.ts.map +1 -0
  186. package/dest/number/index.js +12 -0
  187. package/dest/profiler/index.d.ts +2 -0
  188. package/dest/profiler/index.d.ts.map +1 -0
  189. package/dest/profiler/index.js +1 -0
  190. package/dest/profiler/profiler.d.ts +8 -0
  191. package/dest/profiler/profiler.d.ts.map +1 -0
  192. package/dest/profiler/profiler.js +97 -0
  193. package/dest/promise/running-promise.d.ts +1 -1
  194. package/dest/promise/running-promise.d.ts.map +1 -1
  195. package/dest/promise/running-promise.js +2 -2
  196. package/dest/queue/batch_queue.d.ts +1 -1
  197. package/dest/queue/batch_queue.js +1 -1
  198. package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
  199. package/dest/queue/serial_queue.d.ts +2 -2
  200. package/dest/queue/serial_queue.d.ts.map +1 -1
  201. package/dest/queue/serial_queue.js +7 -5
  202. package/dest/retry/index.d.ts +3 -2
  203. package/dest/retry/index.d.ts.map +1 -1
  204. package/dest/retry/index.js +2 -2
  205. package/dest/schemas/api.d.ts.map +1 -1
  206. package/dest/schemas/parse.js +1 -1
  207. package/dest/schemas/schemas.d.ts +9 -6
  208. package/dest/schemas/schemas.d.ts.map +1 -1
  209. package/dest/schemas/schemas.js +15 -1
  210. package/dest/schemas/utils.d.ts +1 -3
  211. package/dest/schemas/utils.d.ts.map +1 -1
  212. package/dest/serialize/buffer_reader.d.ts +27 -2
  213. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  214. package/dest/serialize/buffer_reader.js +44 -2
  215. package/dest/serialize/field_reader.d.ts +10 -1
  216. package/dest/serialize/field_reader.d.ts.map +1 -1
  217. package/dest/serialize/field_reader.js +18 -1
  218. package/dest/serialize/free_funcs.d.ts +23 -21
  219. package/dest/serialize/free_funcs.d.ts.map +1 -1
  220. package/dest/serialize/free_funcs.js +21 -27
  221. package/dest/serialize/serialize.d.ts +4 -5
  222. package/dest/serialize/serialize.d.ts.map +1 -1
  223. package/dest/string/index.d.ts +3 -2
  224. package/dest/string/index.d.ts.map +1 -1
  225. package/dest/string/index.js +26 -0
  226. package/dest/testing/files/index.d.ts +0 -2
  227. package/dest/testing/files/index.d.ts.map +1 -1
  228. package/dest/testing/files/index.js +2 -2
  229. package/dest/testing/formatting.d.ts +4 -0
  230. package/dest/testing/formatting.d.ts.map +1 -0
  231. package/dest/testing/formatting.js +3 -0
  232. package/dest/testing/index.d.ts +1 -0
  233. package/dest/testing/index.d.ts.map +1 -1
  234. package/dest/testing/index.js +1 -0
  235. package/dest/timer/date.d.ts +2 -1
  236. package/dest/timer/date.d.ts.map +1 -1
  237. package/dest/timer/date.js +5 -3
  238. package/dest/timer/index.d.ts +1 -1
  239. package/dest/timer/index.d.ts.map +1 -1
  240. package/dest/timer/index.js +1 -1
  241. package/dest/timer/timeout.d.ts +18 -5
  242. package/dest/timer/timeout.d.ts.map +1 -1
  243. package/dest/timer/timeout.js +43 -22
  244. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  245. package/dest/transport/index.d.ts +0 -1
  246. package/dest/transport/index.d.ts.map +1 -1
  247. package/dest/transport/index.js +0 -1
  248. package/dest/transport/interface/connector.d.ts.map +1 -1
  249. package/dest/transport/interface/listener.d.ts +0 -1
  250. package/dest/transport/interface/listener.d.ts.map +1 -1
  251. package/dest/transport/interface/socket.d.ts.map +1 -1
  252. package/dest/transport/node/node_connector.d.ts +0 -1
  253. package/dest/transport/node/node_connector.d.ts.map +1 -1
  254. package/dest/transport/node/node_connector_socket.d.ts +0 -1
  255. package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
  256. package/dest/transport/node/node_listener.d.ts +0 -1
  257. package/dest/transport/node/node_listener.d.ts.map +1 -1
  258. package/dest/transport/node/node_listener_socket.d.ts +0 -1
  259. package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
  260. package/dest/transport/transport_client.d.ts +0 -1
  261. package/dest/transport/transport_client.d.ts.map +1 -1
  262. package/dest/transport/transport_server.d.ts.map +1 -1
  263. package/dest/trees/hasher.d.ts +4 -6
  264. package/dest/trees/hasher.d.ts.map +1 -1
  265. package/dest/trees/index.d.ts +1 -0
  266. package/dest/trees/index.d.ts.map +1 -1
  267. package/dest/trees/index.js +1 -0
  268. package/dest/trees/indexed_merkle_tree.d.ts +0 -2
  269. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
  270. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -3
  271. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  272. package/dest/trees/indexed_tree_leaf.d.ts +0 -2
  273. package/dest/trees/indexed_tree_leaf.d.ts.map +1 -1
  274. package/dest/trees/membership_witness.d.ts +19 -3
  275. package/dest/trees/membership_witness.d.ts.map +1 -1
  276. package/dest/trees/membership_witness.js +13 -0
  277. package/dest/trees/merkle_tree.d.ts +0 -2
  278. package/dest/trees/merkle_tree.d.ts.map +1 -1
  279. package/dest/trees/merkle_tree_calculator.d.ts +11 -3
  280. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  281. package/dest/trees/merkle_tree_calculator.js +31 -1
  282. package/dest/trees/sibling_path.d.ts +6 -8
  283. package/dest/trees/sibling_path.d.ts.map +1 -1
  284. package/dest/trees/unbalanced_merkle_tree.d.ts +19 -8
  285. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
  286. package/dest/trees/unbalanced_merkle_tree.js +49 -50
  287. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +48 -0
  288. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -0
  289. package/dest/trees/unbalanced_merkle_tree_calculator.js +162 -0
  290. package/dest/trees/unbalanced_tree_store.d.ts +1 -0
  291. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  292. package/dest/trees/unbalanced_tree_store.js +6 -0
  293. package/dest/types/index.d.ts +25 -2
  294. package/dest/types/index.d.ts.map +1 -1
  295. package/dest/url/index.d.ts.map +1 -1
  296. package/dest/url/index.js +1 -1
  297. package/package.json +32 -41
  298. package/src/array/array.ts +13 -0
  299. package/src/async-pool/index.ts +1 -0
  300. package/src/bigint/index.ts +20 -0
  301. package/src/buffer/buffer16.ts +133 -0
  302. package/src/buffer/buffer32.ts +8 -6
  303. package/src/buffer/index.ts +1 -0
  304. package/src/collection/array.ts +51 -1
  305. package/src/collection/object.ts +37 -0
  306. package/src/config/env_var.ts +142 -52
  307. package/src/config/index.ts +191 -8
  308. package/src/config/network_config.ts +16 -0
  309. package/src/config/network_name.ts +28 -0
  310. package/src/config/secret_value.ts +49 -0
  311. package/src/crypto/aes128/index.ts +19 -10
  312. package/src/crypto/bn254/index.ts +167 -0
  313. package/src/crypto/ecdsa/index.ts +41 -23
  314. package/src/crypto/grumpkin/index.ts +35 -45
  315. package/src/crypto/index.ts +1 -0
  316. package/src/crypto/keys/index.ts +5 -5
  317. package/src/crypto/pedersen/pedersen.wasm.ts +22 -18
  318. package/src/crypto/poseidon/index.ts +32 -24
  319. package/src/crypto/random/index.ts +2 -40
  320. package/src/crypto/schnorr/index.ts +20 -17
  321. package/src/crypto/secp256k1/index.ts +15 -11
  322. package/src/crypto/secp256k1-signer/utils.ts +25 -4
  323. package/src/crypto/sha256/index.ts +47 -0
  324. package/src/crypto/sync/index.ts +1 -1
  325. package/src/crypto/sync/pedersen/index.ts +16 -15
  326. package/src/crypto/sync/poseidon/index.ts +27 -22
  327. package/src/eth-address/index.ts +9 -2
  328. package/src/eth-signature/eth_signature.ts +44 -22
  329. package/src/fields/bls12_fields.ts +463 -0
  330. package/src/fields/bls12_point.ts +450 -0
  331. package/src/fields/fields.ts +37 -9
  332. package/src/fields/index.ts +2 -0
  333. package/src/fields/point.ts +1 -3
  334. package/src/fs/index.ts +1 -0
  335. package/src/fs/try_rm_dir.ts +15 -0
  336. package/src/index.ts +1 -2
  337. package/src/iterable/filter.ts +1 -1
  338. package/src/iterable/map.ts +1 -1
  339. package/src/jest/env.mjs +52 -0
  340. package/src/jest/setupAfterEnv.mjs +3 -0
  341. package/src/json-rpc/client/fetch.ts +14 -33
  342. package/src/json-rpc/client/safe_json_rpc_client.ts +226 -13
  343. package/src/json-rpc/client/undici.ts +8 -15
  344. package/src/json-rpc/convert.ts +3 -12
  345. package/src/json-rpc/errors.ts +6 -0
  346. package/src/json-rpc/fixtures/class_a.ts +4 -1
  347. package/src/json-rpc/fixtures/class_b.ts +4 -1
  348. package/src/json-rpc/index.ts +2 -1
  349. package/src/json-rpc/server/safe_json_rpc_server.ts +141 -48
  350. package/src/json-rpc/test/integration.ts +1 -1
  351. package/src/log/console.ts +4 -1
  352. package/src/log/gcloud-logger-config.ts +3 -7
  353. package/src/log/index.ts +4 -4
  354. package/src/log/libp2p_logger.ts +21 -2
  355. package/src/log/log_fn.ts +1 -1
  356. package/src/log/noir_debug_log_util.ts +21 -0
  357. package/src/log/pino-logger.ts +33 -2
  358. package/src/message/index.ts +5 -1
  359. package/src/mutex/mutex_database.ts +2 -3
  360. package/src/number/index.ts +14 -0
  361. package/src/profiler/index.ts +1 -0
  362. package/src/profiler/profiler.ts +125 -0
  363. package/src/promise/running-promise.ts +2 -2
  364. package/src/queue/batch_queue.ts +1 -1
  365. package/src/queue/bounded_serial_queue.ts +4 -1
  366. package/src/queue/serial_queue.ts +5 -5
  367. package/src/retry/index.ts +10 -5
  368. package/src/schemas/api.ts +4 -4
  369. package/src/schemas/parse.ts +1 -1
  370. package/src/schemas/schemas.ts +19 -1
  371. package/src/serialize/buffer_reader.ts +60 -3
  372. package/src/serialize/field_reader.ts +27 -3
  373. package/src/serialize/free_funcs.ts +25 -31
  374. package/src/serialize/serialize.ts +2 -0
  375. package/src/string/index.ts +33 -1
  376. package/src/testing/files/index.ts +6 -2
  377. package/src/testing/formatting.ts +3 -0
  378. package/src/testing/index.ts +1 -0
  379. package/src/timer/date.ts +9 -3
  380. package/src/timer/index.ts +1 -1
  381. package/src/timer/timeout.ts +54 -19
  382. package/src/transport/index.ts +0 -1
  383. package/src/transport/interface/connector.ts +0 -1
  384. package/src/transport/interface/listener.ts +2 -3
  385. package/src/transport/interface/socket.ts +2 -3
  386. package/src/transport/transport_client.ts +3 -4
  387. package/src/transport/transport_server.ts +4 -1
  388. package/src/trees/hasher.ts +4 -4
  389. package/src/trees/index.ts +1 -0
  390. package/src/trees/indexed_merkle_tree.ts +5 -1
  391. package/src/trees/indexed_merkle_tree_calculator.ts +2 -2
  392. package/src/trees/membership_witness.ts +13 -0
  393. package/src/trees/merkle_tree.ts +4 -1
  394. package/src/trees/merkle_tree_calculator.ts +43 -5
  395. package/src/trees/unbalanced_merkle_tree.ts +50 -42
  396. package/src/trees/unbalanced_merkle_tree_calculator.ts +194 -0
  397. package/src/trees/unbalanced_tree_store.ts +5 -1
  398. package/src/types/index.ts +25 -4
  399. package/src/url/index.ts +0 -1
  400. package/dest/crypto/pedersen/pedersen.elliptic.d.ts +0 -13
  401. package/dest/crypto/pedersen/pedersen.elliptic.d.ts.map +0 -1
  402. package/dest/crypto/pedersen/pedersen.elliptic.js +0 -582
  403. package/dest/log/debug.d.ts +0 -56
  404. package/dest/log/debug.d.ts.map +0 -1
  405. package/dest/log/debug.js +0 -75
  406. package/dest/log/log_history.d.ts +0 -31
  407. package/dest/log/log_history.d.ts.map +0 -1
  408. package/dest/log/log_history.js +0 -38
  409. package/dest/transport/browser/index.d.ts +0 -5
  410. package/dest/transport/browser/index.d.ts.map +0 -1
  411. package/dest/transport/browser/index.js +0 -4
  412. package/dest/transport/browser/message_port_socket.d.ts +0 -37
  413. package/dest/transport/browser/message_port_socket.d.ts.map +0 -1
  414. package/dest/transport/browser/message_port_socket.js +0 -42
  415. package/dest/transport/browser/shared_worker_connector.d.ts +0 -19
  416. package/dest/transport/browser/shared_worker_connector.d.ts.map +0 -1
  417. package/dest/transport/browser/shared_worker_connector.js +0 -19
  418. package/dest/transport/browser/shared_worker_listener.d.ts +0 -38
  419. package/dest/transport/browser/shared_worker_listener.d.ts.map +0 -1
  420. package/dest/transport/browser/shared_worker_listener.js +0 -33
  421. package/dest/transport/browser/worker_connector.d.ts +0 -26
  422. package/dest/transport/browser/worker_connector.d.ts.map +0 -1
  423. package/dest/transport/browser/worker_connector.js +0 -30
  424. package/dest/transport/browser/worker_listener.d.ts +0 -39
  425. package/dest/transport/browser/worker_listener.d.ts.map +0 -1
  426. package/dest/transport/browser/worker_listener.js +0 -35
  427. package/dest/wasm/empty_wasi_sdk.d.ts +0 -130
  428. package/dest/wasm/empty_wasi_sdk.d.ts.map +0 -1
  429. package/dest/wasm/empty_wasi_sdk.js +0 -148
  430. package/dest/wasm/index.d.ts +0 -2
  431. package/dest/wasm/index.d.ts.map +0 -1
  432. package/dest/wasm/index.js +0 -1
  433. package/dest/wasm/wasm_module.d.ts +0 -136
  434. package/dest/wasm/wasm_module.d.ts.map +0 -1
  435. package/dest/wasm/wasm_module.js +0 -196
  436. package/dest/worker/browser/index.d.ts +0 -3
  437. package/dest/worker/browser/index.d.ts.map +0 -1
  438. package/dest/worker/browser/index.js +0 -2
  439. package/dest/worker/browser/start_web_module.d.ts +0 -7
  440. package/dest/worker/browser/start_web_module.d.ts.map +0 -1
  441. package/dest/worker/browser/start_web_module.js +0 -27
  442. package/dest/worker/browser/web_data_store.d.ts +0 -24
  443. package/dest/worker/browser/web_data_store.d.ts.map +0 -1
  444. package/dest/worker/browser/web_data_store.js +0 -29
  445. package/dest/worker/browser/web_worker.d.ts +0 -10
  446. package/dest/worker/browser/web_worker.d.ts.map +0 -1
  447. package/dest/worker/browser/web_worker.js +0 -25
  448. package/dest/worker/data_store.d.ts +0 -21
  449. package/dest/worker/data_store.d.ts.map +0 -1
  450. package/dest/worker/data_store.js +0 -3
  451. package/dest/worker/index.d.ts +0 -3
  452. package/dest/worker/index.d.ts.map +0 -1
  453. package/dest/worker/index.js +0 -1
  454. package/dest/worker/node/index.d.ts +0 -3
  455. package/dest/worker/node/index.d.ts.map +0 -1
  456. package/dest/worker/node/index.js +0 -2
  457. package/dest/worker/node/node_data_store.d.ts +0 -13
  458. package/dest/worker/node/node_data_store.d.ts.map +0 -1
  459. package/dest/worker/node/node_data_store.js +0 -20
  460. package/dest/worker/node/node_worker.d.ts +0 -6
  461. package/dest/worker/node/node_worker.d.ts.map +0 -1
  462. package/dest/worker/node/node_worker.js +0 -22
  463. package/dest/worker/node/start_node_module.d.ts +0 -7
  464. package/dest/worker/node/start_node_module.d.ts.map +0 -1
  465. package/dest/worker/node/start_node_module.js +0 -31
  466. package/dest/worker/wasm_worker.d.ts +0 -9
  467. package/dest/worker/wasm_worker.d.ts.map +0 -1
  468. package/dest/worker/wasm_worker.js +0 -3
  469. package/dest/worker/worker_pool.d.ts +0 -40
  470. package/dest/worker/worker_pool.d.ts.map +0 -1
  471. package/dest/worker/worker_pool.js +0 -51
  472. package/src/crypto/pedersen/pedersen.elliptic.ts +0 -584
  473. package/src/log/debug.ts +0 -104
  474. package/src/log/log_history.ts +0 -44
  475. package/src/transport/browser/index.ts +0 -4
  476. package/src/transport/browser/message_port_socket.ts +0 -48
  477. package/src/transport/browser/shared_worker_connector.ts +0 -21
  478. package/src/transport/browser/shared_worker_listener.ts +0 -53
  479. package/src/transport/browser/worker_connector.ts +0 -30
  480. package/src/transport/browser/worker_listener.ts +0 -54
  481. package/src/wasm/README.md +0 -6
  482. package/src/wasm/empty_wasi_sdk.ts +0 -166
  483. package/src/wasm/fixtures/gcd.wasm +0 -0
  484. package/src/wasm/fixtures/gcd.wat +0 -27
  485. package/src/wasm/index.ts +0 -1
  486. package/src/wasm/wasm_module.ts +0 -260
  487. package/src/worker/browser/index.ts +0 -2
  488. package/src/worker/browser/start_web_module.ts +0 -24
  489. package/src/worker/browser/web_data_store.ts +0 -38
  490. package/src/worker/browser/web_worker.ts +0 -25
  491. package/src/worker/data_store.ts +0 -19
  492. package/src/worker/index.ts +0 -2
  493. package/src/worker/node/index.ts +0 -2
  494. package/src/worker/node/node_data_store.ts +0 -27
  495. package/src/worker/node/node_worker.ts +0 -23
  496. package/src/worker/node/start_node_module.ts +0 -30
  497. package/src/worker/wasm_worker.ts +0 -7
  498. package/src/worker/worker_pool.ts +0 -73
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type EventEmitter from 'events';
3
2
  import type { Socket } from './socket.js';
4
3
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/transport/interface/listener.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,QAAS,SAAQ,YAAY;IAE5C,IAAI,IAAI,IAAI,CAAC;IAEb,KAAK,IAAI,IAAI,CAAC;IAEd,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;CAC5D"}
1
+ {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/transport/interface/listener.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,QAAS,SAAQ,YAAY;IAC5C,IAAI,IAAI,IAAI,CAAC;IAEb,KAAK,IAAI,IAAI,CAAC;IAEd,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;CAC5D"}
@@ -1 +1 @@
1
- {"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../../src/transport/interface/socket.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,MAAM;IAErB,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD,eAAe,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI,CAAC;IAE7C,KAAK,IAAI,IAAI,CAAC;CACf"}
1
+ {"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../../src/transport/interface/socket.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD,eAAe,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI,CAAC;IAE7C,KAAK,IAAI,IAAI,CAAC;CACf"}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { Worker } from 'worker_threads';
3
2
  import type { Connector } from '../interface/connector.js';
4
3
  import { NodeConnectorSocket } from './node_connector_socket.js';
@@ -1 +1 @@
1
- {"version":3,"file":"node_connector.d.ts","sourceRoot":"","sources":["../../../src/transport/node/node_connector.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,qBAAa,aAAc,YAAW,SAAS;IACjC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC;;;;;;OAMG;IACH,YAAY;CAGb"}
1
+ {"version":3,"file":"node_connector.d.ts","sourceRoot":"","sources":["../../../src/transport/node/node_connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,qBAAa,aAAc,YAAW,SAAS;IACjC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC;;;;;;OAMG;IACH,YAAY;CAGb"}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { Worker } from 'worker_threads';
3
2
  import type { Socket } from '../interface/socket.js';
4
3
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"node_connector_socket.d.ts","sourceRoot":"","sources":["../../../src/transport/node/node_connector_socket.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;GASG;AACH,qBAAa,mBAAoB,YAAW,MAAM;IACpC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC;;;;;;;;;OASG;IACH,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,GAAE,YAAY,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5D;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI;IAI5C;;;OAGG;IACH,KAAK;CAIN"}
1
+ {"version":3,"file":"node_connector_socket.d.ts","sourceRoot":"","sources":["../../../src/transport/node/node_connector_socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;GASG;AACH,qBAAa,mBAAoB,YAAW,MAAM;IACpC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC;;;;;;;;;OASG;IACH,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,GAAE,YAAY,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5D;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI;IAI5C;;;OAGG;IACH,KAAK;CAIN"}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import EventEmitter from 'events';
3
2
  import type { Listener } from '../interface/listener.js';
4
3
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"node_listener.d.ts","sourceRoot":"","sources":["../../../src/transport/node/node_listener.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAGlC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGzD;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,YAAa,YAAW,QAAQ;;IAKhE;;;;;OAKG;IACH,IAAI;IAIJ;;;;OAIG;IACH,KAAK;CACN"}
1
+ {"version":3,"file":"node_listener.d.ts","sourceRoot":"","sources":["../../../src/transport/node/node_listener.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAGlC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGzD;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,YAAa,YAAW,QAAQ;;IAKhE;;;;;OAKG;IACH,IAAI;IAIJ;;;;OAIG;IACH,KAAK;CACN"}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { MessagePort } from 'worker_threads';
3
2
  import type { Socket } from '../interface/socket.js';
4
3
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"node_listener_socket.d.ts","sourceRoot":"","sources":["../../../src/transport/node/node_listener_socket.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AAEpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,MAAM;IACnC,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,WAAW;IAErC;;;;;;;;;OASG;IACH,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,GAAE,YAAY,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5D;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI;IAI5C;;;;OAIG;IACH,KAAK;CAKN"}
1
+ {"version":3,"file":"node_listener_socket.d.ts","sourceRoot":"","sources":["../../../src/transport/node/node_listener_socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AAEpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,MAAM;IACnC,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,WAAW;IAErC;;;;;;;;;OASG;IACH,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,GAAE,YAAY,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5D;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI;IAI5C;;;;OAIG;IACH,KAAK;CAKN"}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import EventEmitter from 'events';
3
2
  import type { Connector } from './interface/connector.js';
4
3
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"transport_client.d.ts","sourceRoot":"","sources":["../../src/transport/transport_client.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAKlC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAqB1D;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,OAAO,CAAE,SAAQ,YAAY;IAE7D,EAAE,C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AC,CAAS;gBAEJ,gBAAgB,EAAE,SAAS;IAI/C;;;;;;;;OAQG;IACG,IAAI;IAKV;;;;;OAKG;IACH,KAAK;IAML;;;;;;;;OAQG;IACH,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE;IAanD;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;CAsB5B"}
@@ -1 +1 @@
1
- {"version":3,"file":"transport_server.d.ts","sourceRoot":"","sources":["../../src/transport/transport_server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAIxD;;GAEG;AACH,qBAAa,eAAe,CAAC,OAAO;IAGtB,OAAO,CAAC,QAAQ;IAAY,OAAO,CAAC,YAAY;IAF5D,OAAO,CAAC,OAAO,CAAgB;gBAEX,QAAQ,EAAE,QAAQ,EAAU,YAAY,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC;IAE5F;;;;OAIG;IACH,KAAK;IAKL;;;OAGG;IACH,IAAI;IAIJ;;;;;;;OAOG;IACG,SAAS,CAAC,GAAG,EAAE,OAAO;IAI5B;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;;;;;;;OAQG;YACW,mBAAmB;CAalC"}
1
+ {"version":3,"file":"transport_server.d.ts","sourceRoot":"","sources":["../../src/transport/transport_server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAIxD;;GAEG;AACH,qBAAa,eAAe,CAAC,OAAO;IAIhC,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,YAAY;IAJtB,OAAO,CAAC,OAAO,CAAgB;gBAGrB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC;IAGtD;;;;OAIG;IACH,KAAK;IAKL;;;OAGG;IACH,IAAI;IAIJ;;;;;;;OAOG;IACG,SAAS,CAAC,GAAG,EAAE,OAAO;IAI5B;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;;;;;;;OAQG;YACW,mBAAmB;CAalC"}
@@ -1,5 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  /**
4
2
  * Defines hasher interface used by Merkle trees.
5
3
  */
@@ -10,13 +8,13 @@ export interface Hasher {
10
8
  * @param rhs - The second array.
11
9
  * @returns The new 32-byte hash.
12
10
  */
13
- hash(lhs: Uint8Array, rhs: Uint8Array): Buffer;
11
+ hash(lhs: Uint8Array, rhs: Uint8Array): Buffer<ArrayBuffer>;
14
12
  /**
15
13
  * Hashes an array of buffers.
16
14
  * @param inputs - The array of buffers to hash.
17
15
  * @returns The resulting 32-byte hash.
18
16
  */
19
- hashInputs(inputs: Buffer[]): Buffer;
17
+ hashInputs(inputs: Buffer[]): Buffer<ArrayBuffer>;
20
18
  }
21
19
  /**
22
20
  * Defines an async hasher interface used by Merkle trees.
@@ -28,12 +26,12 @@ export interface AsyncHasher {
28
26
  * @param rhs - The second array.
29
27
  * @returns The new 32-byte hash.
30
28
  */
31
- hash(lhs: Uint8Array, rhs: Uint8Array): Promise<Buffer>;
29
+ hash(lhs: Uint8Array, rhs: Uint8Array): Promise<Buffer<ArrayBuffer>>;
32
30
  /**
33
31
  * Hashes an array of buffers.
34
32
  * @param inputs - The array of buffers to hash.
35
33
  * @returns The resulting 32-byte hash.
36
34
  */
37
- hashInputs(inputs: Buffer[]): Promise<Buffer>;
35
+ hashInputs(inputs: Buffer[]): Promise<Buffer<ArrayBuffer>>;
38
36
  }
39
37
  //# sourceMappingURL=hasher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hasher.d.ts","sourceRoot":"","sources":["../../src/trees/hasher.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;OAKG;IACH,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM,CAAC;IAE/C;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAExD;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/C"}
1
+ {"version":3,"file":"hasher.d.ts","sourceRoot":"","sources":["../../src/trees/hasher.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;OAKG;IACH,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAE5D;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;CACnD;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IAErE;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;CAC5D"}
@@ -8,4 +8,5 @@ export * from './sibling_path.js';
8
8
  export * from './membership_witness.js';
9
9
  export * from './hasher.js';
10
10
  export * from './indexed_tree_leaf.js';
11
+ export * from './unbalanced_merkle_tree_calculator.js';
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/trees/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,qCAAqC,CAAC;AACpD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/trees/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,qCAAqC,CAAC;AACpD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,wCAAwC,CAAC"}
@@ -8,3 +8,4 @@ export * from './sibling_path.js';
8
8
  export * from './membership_witness.js';
9
9
  export * from './hasher.js';
10
10
  export * from './indexed_tree_leaf.js';
11
+ export * from './unbalanced_merkle_tree_calculator.js';
@@ -1,5 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  import type { IndexedTreeLeafPreimage } from './indexed_tree_leaf.js';
4
2
  import { MembershipWitness } from './membership_witness.js';
5
3
  import { MerkleTree } from './merkle_tree.js';
@@ -1 +1 @@
1
- {"version":3,"file":"indexed_merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/indexed_merkle_tree.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,yIAAyI;AACzI,qBAAa,iBAAiB,CAAC,CAAC,SAAS,uBAAuB,EAAE,CAAC,SAAS,MAAM,CAAE,SAAQ,UAAU;aAC5C,aAAa,EAAE,CAAC,EAAE;gBAA9D,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAkB,aAAa,EAAE,CAAC,EAAE;IAInE,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC;IAc5B,oBAAoB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC;CASpF"}
1
+ {"version":3,"file":"indexed_merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/indexed_merkle_tree.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,yIAAyI;AACzI,qBAAa,iBAAiB,CAAC,CAAC,SAAS,uBAAuB,EAAE,CAAC,SAAS,MAAM,CAAE,SAAQ,UAAU;aAIlF,aAAa,EAAE,CAAC,EAAE;gBAFlC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,MAAM,EAAE,EACC,aAAa,EAAE,CAAC,EAAE;IAK7B,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC;IAc5B,oBAAoB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC;CASpF"}
@@ -1,5 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  import type { IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
4
2
  import type { AsyncHasher } from './hasher.js';
5
3
  import { IndexedMerkleTree } from './indexed_merkle_tree.js';
@@ -15,7 +13,7 @@ export declare class IndexedMerkleTreeCalculator<T extends IndexedTreeLeafPreima
15
13
  private hasher;
16
14
  private factory;
17
15
  private constructor();
18
- static create<T extends IndexedTreeLeafPreimage, N extends number>(height: N, hasher: AsyncHasher, factory: LeafPreimageFactory<T>, zeroLeaf?: Buffer): Promise<IndexedMerkleTreeCalculator<T, N>>;
16
+ static create<T extends IndexedTreeLeafPreimage, N extends number>(height: N, hasher: AsyncHasher, factory: LeafPreimageFactory<T>, zeroLeaf?: Buffer<ArrayBuffer>): Promise<IndexedMerkleTreeCalculator<T, N>>;
19
17
  computeTree(values: Buffer[]): Promise<IndexedMerkleTree<T, N>>;
20
18
  computeTreeRoot(leaves?: Buffer[]): Promise<Buffer>;
21
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"indexed_merkle_tree_calculator.d.ts","sourceRoot":"","sources":["../../src/trees/indexed_merkle_tree_calculator.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,UAAU,mBAAmB,CAAC,CAAC,SAAS,uBAAuB;IAC7D,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,qBAAa,2BAA2B,CAAC,CAAC,SAAS,uBAAuB,EAAE,CAAC,SAAS,MAAM;IAExF,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,OAAO;IAJjB,OAAO;WAOM,MAAM,CAAC,CAAC,SAAS,uBAAuB,EAAE,CAAC,SAAS,MAAM,EACrE,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAC/B,QAAQ,SAAmB;IASvB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAuC/D,eAAe,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,MAAM,CAAC;CAmB9D"}
1
+ {"version":3,"file":"indexed_merkle_tree_calculator.d.ts","sourceRoot":"","sources":["../../src/trees/indexed_merkle_tree_calculator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,UAAU,mBAAmB,CAAC,CAAC,SAAS,uBAAuB;IAC7D,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,qBAAa,2BAA2B,CAAC,CAAC,SAAS,uBAAuB,EAAE,CAAC,SAAS,MAAM;IAExF,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,OAAO;IAJjB,OAAO;WAOM,MAAM,CAAC,CAAC,SAAS,uBAAuB,EAAE,CAAC,SAAS,MAAM,EACrE,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAC/B,QAAQ,sBAAmB;IASvB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAuC/D,eAAe,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,MAAM,CAAC;CAmB9D"}
@@ -1,5 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  /**
4
2
  * A leaf of an indexed merkle tree.
5
3
  */
@@ -1 +1 @@
1
- {"version":3,"file":"indexed_tree_leaf.d.ts","sourceRoot":"","sources":["../../src/trees/indexed_tree_leaf.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC;IACjB;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAC;IACnB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,IAAI,eAAe,CAAC;IAC1B;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAC;IACnB;;OAEG;IACH,YAAY,IAAI,MAAM,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,gBAAgB;IAC/D,UAAU,IAAI,MAAM,CAAC;IACrB;;OAEG;IACH,YAAY,IAAI,MAAM,CAAC;CACxB"}
1
+ {"version":3,"file":"indexed_tree_leaf.d.ts","sourceRoot":"","sources":["../../src/trees/indexed_tree_leaf.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC;IACjB;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAC;IACnB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,IAAI,eAAe,CAAC;IAC1B;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAC;IACnB;;OAEG;IACH,YAAY,IAAI,MAAM,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,gBAAgB;IAC/D,UAAU,IAAI,MAAM,CAAC;IACrB;;OAEG;IACH,YAAY,IAAI,MAAM,CAAC;CACxB"}
@@ -1,5 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  import { Fr } from '../fields/fields.js';
4
2
  import { BufferReader, type Tuple } from '../serialize/index.js';
5
3
  import type { SiblingPath } from './sibling_path.js';
@@ -28,7 +26,25 @@ export declare class MembershipWitness<N extends number> {
28
26
  * Sibling path of the leaf in the Merkle tree.
29
27
  */
30
28
  siblingPath: Tuple<Fr, N>);
31
- toBuffer(): Buffer;
29
+ toBuffer(): Buffer<ArrayBufferLike>;
30
+ toJSON(): Buffer<ArrayBufferLike>;
31
+ toFields(): Fr[];
32
+ static schemaFor<N extends number>(size: N): import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Buffer<ArrayBuffer>, string>, import("zod").ZodEffects<import("zod").ZodObject<{
33
+ type: import("zod").ZodLiteral<"Buffer">;
34
+ data: import("zod").ZodArray<import("zod").ZodNumber, "many">;
35
+ }, "strip", import("zod").ZodTypeAny, {
36
+ type: "Buffer";
37
+ data: number[];
38
+ }, {
39
+ type: "Buffer";
40
+ data: number[];
41
+ }>, Buffer<ArrayBuffer>, {
42
+ type: "Buffer";
43
+ data: number[];
44
+ }>]>, MembershipWitness<N>, string | {
45
+ type: "Buffer";
46
+ data: number[];
47
+ }>;
32
48
  /**
33
49
  * Creates a random membership witness. Used for testing purposes.
34
50
  * @param pathSize - Number of fields in the sibling path.
@@ -1 +1 @@
1
- {"version":3,"file":"membership_witness.d.ts","sourceRoot":"","sources":["../../src/trees/membership_witness.ts"],"names":[],"mappings":";;AAEA,O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,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,IAAI,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC;IAOjG;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG;QAAE,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAA;KAAE;IAWnH,MAAM,CAAC,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC;CAG/G"}
@@ -1,6 +1,7 @@
1
1
  import { assertMemberLength } from '../array/array.js';
2
2
  import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
3
3
  import { Fr } from '../fields/fields.js';
4
+ import { schemas } from '../schemas/schemas.js';
4
5
  import { BufferReader, serializeToBuffer } from '../serialize/index.js';
5
6
  /**
6
7
  * Contains information which can be used to prove that a leaf is a member of a Merkle tree.
@@ -21,6 +22,18 @@ import { BufferReader, serializeToBuffer } from '../serialize/index.js';
21
22
  toBuffer() {
22
23
  return serializeToBuffer(toBufferBE(this.leafIndex, 32), ...this.siblingPath);
23
24
  }
25
+ toJSON() {
26
+ return this.toBuffer();
27
+ }
28
+ toFields() {
29
+ return [
30
+ new Fr(this.leafIndex),
31
+ ...this.siblingPath
32
+ ];
33
+ }
34
+ static schemaFor(size) {
35
+ return schemas.Buffer.transform((b)=>MembershipWitness.fromBuffer(b, size));
36
+ }
24
37
  /**
25
38
  * Creates a random membership witness. Used for testing purposes.
26
39
  * @param pathSize - Number of fields in the sibling path.
@@ -1,5 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  /** A simple immutable Merkle tree container. Use a MerkleTreeCalculator to create a new instance from a set of leaves. */
4
2
  export declare class MerkleTree {
5
3
  readonly height: number;
@@ -1 +1 @@
1
- {"version":3,"file":"merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/merkle_tree.ts"],"names":[],"mappings":";;AAAA,0HAA0H;AAC1H,qBAAa,UAAU;aACO,MAAM,EAAE,MAAM;aAAkB,KAAK,EAAE,MAAM,EAAE;gBAA/C,MAAM,EAAE,MAAM,EAAkB,KAAK,EAAE,MAAM,EAAE;IAO3E,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,wFAAwF;IACjF,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAC3C,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAwB7C,kDAAkD;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM;IAI/B,uFAAuF;IAChF,QAAQ,CAAC,QAAQ,SAAI;CAsB7B"}
1
+ {"version":3,"file":"merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/merkle_tree.ts"],"names":[],"mappings":"AAAA,0HAA0H;AAC1H,qBAAa,UAAU;aAEH,MAAM,EAAE,MAAM;aACd,KAAK,EAAE,MAAM,EAAE;gBADf,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EAAE;IAQjC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,wFAAwF;IACjF,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAC3C,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAwB7C,kDAAkD;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM;IAI/B,uFAAuF;IAChF,QAAQ,CAAC,QAAQ,SAAI;CAsB7B"}
@@ -1,5 +1,4 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
1
+ import { sha256Trunc } from '@aztec/foundation/crypto';
3
2
  import { MerkleTree } from './merkle_tree.js';
4
3
  /**
5
4
  * Merkle tree calculator.
@@ -9,8 +8,17 @@ export declare class MerkleTreeCalculator {
9
8
  private zeroHashes;
10
9
  private hasher;
11
10
  private constructor();
12
- static create(height: number, zeroLeaf?: Buffer, hasher?: (left: Buffer, right: Buffer) => Promise<Buffer>): Promise<MerkleTreeCalculator>;
11
+ static create(height: number, zeroLeaf?: Buffer, hasher?: (left: Buffer, right: Buffer) => Promise<Buffer<ArrayBuffer>>): Promise<MerkleTreeCalculator>;
13
12
  computeTree(leaves?: Buffer[]): Promise<MerkleTree>;
14
13
  computeTreeRoot(leaves?: Buffer[]): Promise<Buffer>;
14
+ /**
15
+ * Computes the Merkle root with the provided leaves **synchronously**.
16
+ *
17
+ * This method uses a synchronous hash function (defaults to `sha256Trunc`) and **does not** allow for padding.
18
+ * If the number of leaves is not a power of two, it throws an error.
19
+ * This contrasts with the above non-static async method `computeTreeRoot`, which can handle any number of leaves by
20
+ * padding with zero hashes.
21
+ */
22
+ static computeTreeRootSync(leaves: Buffer[], hasher?: typeof sha256Trunc): Buffer;
15
23
  }
16
24
  //# sourceMappingURL=merkle_tree_calculator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"merkle_tree_calculator.d.ts","sourceRoot":"","sources":["../../src/trees/merkle_tree_calculator.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,qBAAa,oBAAoB;IACX,OAAO,CAAC,MAAM;IAAU,OAAO,CAAC,UAAU;IAAY,OAAO,CAAC,MAAM;IAAxF,OAAO;WAIM,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,QAAQ,SAAmB,EAC3B,MAAM,UAAgB,MAAM,SAAS,MAAM,oBAAmD;IAS1F,WAAW,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAsBvD,eAAe,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,MAAM,CAAC;CAmB9D"}
1
+ {"version":3,"file":"merkle_tree_calculator.d.ts","sourceRoot":"","sources":["../../src/trees/merkle_tree_calculator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGrE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,qBAAa,oBAAoB;IAE7B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IAHhB,OAAO;WAQM,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,MAAyB,EACnC,MAAM,IAAU,MAAM,MAAM,EAAE,OAAO,MAAM,iCAC4B;IASnE,WAAW,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAsBvD,eAAe,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB7D;;;;;;;OAOG;IACH,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,qBAAc,GAAG,MAAM;CAwB3E"}
@@ -1,4 +1,4 @@
1
- import { pedersenHash } from '@aztec/foundation/crypto';
1
+ import { pedersenHash, sha256Trunc } from '@aztec/foundation/crypto';
2
2
  import { MerkleTree } from './merkle_tree.js';
3
3
  /**
4
4
  * Merkle tree calculator.
@@ -58,4 +58,34 @@ import { MerkleTree } from './merkle_tree.js';
58
58
  }
59
59
  return leaves[0];
60
60
  }
61
+ /**
62
+ * Computes the Merkle root with the provided leaves **synchronously**.
63
+ *
64
+ * This method uses a synchronous hash function (defaults to `sha256Trunc`) and **does not** allow for padding.
65
+ * If the number of leaves is not a power of two, it throws an error.
66
+ * This contrasts with the above non-static async method `computeTreeRoot`, which can handle any number of leaves by
67
+ * padding with zero hashes.
68
+ */ static computeTreeRootSync(leaves, hasher = sha256Trunc) {
69
+ if (leaves.length === 0) {
70
+ throw new Error('Cannot compute a Merkle root with no leaves');
71
+ }
72
+ const height = Math.log2(leaves.length);
73
+ if (!Number.isInteger(height)) {
74
+ throw new Error('Cannot compute a Merkle root with a non-power-of-two number of leaves');
75
+ }
76
+ let nodes = leaves.slice();
77
+ for(let i = 0; i < height; ++i){
78
+ let j = 0;
79
+ for(; j < nodes.length / 2; ++j){
80
+ const l = nodes[j * 2];
81
+ const r = nodes[j * 2 + 1];
82
+ nodes[j] = hasher(Buffer.concat([
83
+ l,
84
+ r
85
+ ]));
86
+ }
87
+ nodes = nodes.slice(0, j);
88
+ }
89
+ return nodes[0];
90
+ }
61
91
  }
@@ -1,5 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  import { Fr } from '../fields/index.js';
4
2
  import { type Tuple } from '../serialize/index.js';
5
3
  import type { Hasher } from './hasher.js';
@@ -27,7 +25,7 @@ export declare class SiblingPath<N extends number> {
27
25
  pathSize: N,
28
26
  /** The sibling path data. */
29
27
  path: Buffer[]);
30
- static get schema(): import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Buffer, string>, import("zod").ZodEffects<import("zod").ZodObject<{
28
+ static get schema(): import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Buffer<ArrayBuffer>, string>, import("zod").ZodEffects<import("zod").ZodObject<{
31
29
  type: import("zod").ZodLiteral<"Buffer">;
32
30
  data: import("zod").ZodArray<import("zod").ZodNumber, "many">;
33
31
  }, "strip", import("zod").ZodTypeAny, {
@@ -36,14 +34,14 @@ export declare class SiblingPath<N extends number> {
36
34
  }, {
37
35
  type: "Buffer";
38
36
  data: number[];
39
- }>, Buffer, {
37
+ }>, Buffer<ArrayBuffer>, {
40
38
  type: "Buffer";
41
39
  data: number[];
42
40
  }>]>, SiblingPath<number>, string | {
43
41
  type: "Buffer";
44
42
  data: number[];
45
43
  }>;
46
- static schemaFor<N extends number>(size: N): import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Buffer, string>, import("zod").ZodEffects<import("zod").ZodObject<{
44
+ static schemaFor<N extends number>(size: N): import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Buffer<ArrayBuffer>, string>, import("zod").ZodEffects<import("zod").ZodObject<{
47
45
  type: import("zod").ZodLiteral<"Buffer">;
48
46
  data: import("zod").ZodArray<import("zod").ZodNumber, "many">;
49
47
  }, "strip", import("zod").ZodTypeAny, {
@@ -52,7 +50,7 @@ export declare class SiblingPath<N extends number> {
52
50
  }, {
53
51
  type: "Buffer";
54
52
  data: number[];
55
- }>, Buffer, {
53
+ }>, Buffer<ArrayBuffer>, {
56
54
  type: "Buffer";
57
55
  data: number[];
58
56
  }>]>, SiblingPath<N>, string | {
@@ -62,7 +60,7 @@ export declare class SiblingPath<N extends number> {
62
60
  type: "Buffer";
63
61
  data: number[];
64
62
  }>;
65
- toJSON(): Buffer;
63
+ toJSON(): Buffer<ArrayBufferLike>;
66
64
  /**
67
65
  * Returns sibling path hashed up from the a element.
68
66
  * @param size - The number of elements in a given path.
@@ -128,5 +126,5 @@ export declare class SiblingPath<N extends number> {
128
126
  getSubtreeSiblingPath<SubtreeHeight extends number, SubtreeSiblingPathHeight extends number>(subtreeHeight: SubtreeHeight): SiblingPath<SubtreeSiblingPathHeight>;
129
127
  }
130
128
  /** Computes the expected root of a merkle tree given a leaf and its sibling path. */
131
- export declare function computeRootFromSiblingPath(leaf: Buffer, siblingPath: Buffer[], index: number, hasher?: (left: Buffer, right: Buffer) => Promise<Buffer>): Promise<Buffer>;
129
+ export declare function computeRootFromSiblingPath(leaf: Buffer, siblingPath: Buffer[], index: number, hasher?: (left: Buffer, right: Buffer) => Promise<Buffer<ArrayBufferLike>>): Promise<Buffer<ArrayBufferLike>>;
132
130
  //# sourceMappingURL=sibling_path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sibling_path.d.ts","sourceRoot":"","sources":["../../src/trees/sibling_path.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAExC,OAAO,EACL,KAAK,KAAK,EAIX,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;GASG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS,MAAM;IASrC,+DAA+D;IACxD,QAAQ,EAAE,CAAC;IATpB,OAAO,CAAC,IAAI,CAAmB;IAE/B;;;;OAIG;;IAED,+DAA+D;IACxD,QAAQ,EAAE,CAAC;IAClB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,EAAE;IAKhB,MAAM,KAAK,MAAM;;;;;;;;;;;;;;;OAEhB;IAED,MAAM,CAAC,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC;;;;;;;;;;;;;;;;;;;IAO1C,MAAM;IAIN;;;;;;OAMG;WACW,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC;IAUlG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC;IAKzC;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAIzB;;;OAGG;IACI,aAAa,IAAI,MAAM,EAAE;IAIhC;;;OAGG;IACI,QAAQ,IAAI,EAAE,EAAE;IAIvB;;;OAGG;IACI,OAAO,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IAK9B;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS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types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  import { sha256Trunc } from '../crypto/sha256/index.js';
4
2
  /**
5
- * Computes the merkle root for an unbalanced tree.
3
+ * Computes the Merkle root of an unbalanced tree.
6
4
  *
7
- * @dev Adapted from unbalanced_tree.ts.
8
- * Calculates the tree upwards layer by layer until we reach the root.
9
- * The L1 calculation instead computes the tree from right to left (slightly cheaper gas).
10
- * TODO: A more thorough investigation of which method is cheaper, then use that method everywhere.
5
+ * Unlike a balanced Merkle tree, which requires the number of leaves to be a power of two, an unbalanced tree can have
6
+ * any number of leaves.
7
+ *
8
+ * The tree is constructed by iteratively extracting the smallest power-of-two-sized subtrees from **right to left**.
9
+ * For each such subtree, it computes the subtree root and then combines all subtree roots (again from right to left)
10
+ * into a single root using the provided hash function.
11
+ *
12
+ * Note: We need the final tree to be as shallow as possible, to minimize the size of the sibling path required to prove
13
+ * membership of a leaf. Therefor, the computation proceeds from right to left - smaller subtrees must always be
14
+ * combined before being merged with a larger sibling on their left.
15
+ *
16
+ * For example, consider an unbalanced tree made of three subtrees of sizes 2, 4, and 8. If we combine the size-2 and
17
+ * size-4 subtrees first (producing a subtree of depth 3), and then merge it with the size-8 subtree (also depth 3), the
18
+ * resulting tree has a maximum depth of 4.
19
+ *
20
+ * But if we instead combine the size-4 and size-8 subtrees first (depth 4), and then merge with the size-2 subtree
21
+ * (depth 1), the final tree has a depth of 5.
11
22
  */
12
- export declare function computeUnbalancedMerkleRoot(leaves: Buffer[], emptyLeaf?: Buffer, hasher?: typeof sha256Trunc): Buffer;
23
+ export declare function computeUnbalancedMerkleTreeRoot(leaves: Buffer[], hasher?: typeof sha256Trunc): Buffer;
13
24
  export declare function findLeafLevelAndIndex(numLeaves: number, leafIndex: number): {
14
25
  level: number;
15
26
  indexAtLevel: number;
@@ -1 +1 @@
1
- {"version":3,"file":"unbalanced_merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,qBAAc,GAAG,MAAM,CAwC9G;AAgDD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;EAGzE"}
1
+ {"version":3,"file":"unbalanced_merkle_tree.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,qBAAc,GAAG,MAAM,CA6B9F;AAsDD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;WAhC9D,MAAM;kBAAgB,MAAM;EAmCvC"}
@@ -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) {