@aztec/foundation 3.0.0-devnet.6 → 3.0.0-devnet.6-patch.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (411) hide show
  1. package/dest/array/array.d.ts +1 -9
  2. package/dest/array/array.d.ts.map +1 -1
  3. package/dest/array/array.js +0 -11
  4. package/dest/array/index.d.ts +1 -1
  5. package/dest/async-map/index.d.ts +1 -1
  6. package/dest/async-pool/index.d.ts +1 -1
  7. package/dest/bigint/index.d.ts +1 -1
  8. package/dest/bigint-buffer/index.d.ts +1 -1
  9. package/dest/branded-types/block_number.d.ts +53 -0
  10. package/dest/branded-types/block_number.d.ts.map +1 -0
  11. package/dest/branded-types/block_number.js +75 -0
  12. package/dest/branded-types/checkpoint_number.d.ts +46 -0
  13. package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
  14. package/dest/branded-types/checkpoint_number.js +68 -0
  15. package/dest/branded-types/epoch.d.ts +42 -0
  16. package/dest/branded-types/epoch.d.ts.map +1 -0
  17. package/dest/branded-types/epoch.js +59 -0
  18. package/dest/branded-types/index.d.ts +6 -0
  19. package/dest/branded-types/index.d.ts.map +1 -0
  20. package/dest/branded-types/index.js +4 -0
  21. package/dest/branded-types/slot.d.ts +42 -0
  22. package/dest/branded-types/slot.d.ts.map +1 -0
  23. package/dest/branded-types/slot.js +59 -0
  24. package/dest/branded-types/types.d.ts +5 -0
  25. package/dest/branded-types/types.d.ts.map +1 -0
  26. package/dest/branded-types/types.js +1 -0
  27. package/dest/buffer/buffer16.d.ts +2 -5
  28. package/dest/buffer/buffer16.d.ts.map +1 -1
  29. package/dest/buffer/buffer16.js +1 -1
  30. package/dest/buffer/buffer32.d.ts +2 -5
  31. package/dest/buffer/buffer32.d.ts.map +1 -1
  32. package/dest/buffer/buffer32.js +1 -1
  33. package/dest/buffer/index.d.ts +1 -1
  34. package/dest/collection/array.d.ts +3 -1
  35. package/dest/collection/array.d.ts.map +1 -1
  36. package/dest/collection/array.js +12 -3
  37. package/dest/collection/index.d.ts +1 -1
  38. package/dest/collection/object.d.ts +1 -1
  39. package/dest/committable/committable.d.ts +1 -1
  40. package/dest/committable/committable.d.ts.map +1 -1
  41. package/dest/committable/index.d.ts +1 -1
  42. package/dest/config/env_var.d.ts +2 -2
  43. package/dest/config/env_var.d.ts.map +1 -1
  44. package/dest/config/index.d.ts +10 -2
  45. package/dest/config/index.d.ts.map +1 -1
  46. package/dest/config/index.js +16 -2
  47. package/dest/config/network_config.d.ts +1 -1
  48. package/dest/config/network_name.d.ts +1 -1
  49. package/dest/config/secret_value.d.ts +1 -1
  50. package/dest/config/secret_value.d.ts.map +1 -1
  51. package/dest/crypto/aes128/index.d.ts +1 -1
  52. package/dest/crypto/aes128/index.d.ts.map +1 -1
  53. package/dest/crypto/aes128/index.js +2 -6
  54. package/dest/crypto/bls/bn254_keystore.d.ts +296 -0
  55. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -0
  56. package/dest/crypto/bls/bn254_keystore.js +218 -0
  57. package/dest/crypto/bls/index.d.ts +13 -0
  58. package/dest/crypto/bls/index.d.ts.map +1 -0
  59. package/dest/crypto/bls/index.js +87 -0
  60. package/dest/crypto/bn254/index.d.ts +39 -0
  61. package/dest/crypto/bn254/index.d.ts.map +1 -0
  62. package/dest/crypto/bn254/index.js +56 -0
  63. package/dest/crypto/ecdsa/index.d.ts +1 -1
  64. package/dest/crypto/ecdsa/index.d.ts.map +1 -1
  65. package/dest/crypto/ecdsa/index.js +4 -12
  66. package/dest/crypto/ecdsa/signature.d.ts +2 -11
  67. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  68. package/dest/crypto/ecdsa/signature.js +2 -2
  69. package/dest/crypto/grumpkin/index.d.ts +10 -13
  70. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  71. package/dest/crypto/grumpkin/index.js +12 -27
  72. package/dest/crypto/keccak/index.d.ts +1 -1
  73. package/dest/crypto/keys/index.d.ts +2 -2
  74. package/dest/crypto/keys/index.d.ts.map +1 -1
  75. package/dest/crypto/keys/index.js +2 -4
  76. package/dest/crypto/pedersen/index.d.ts +1 -1
  77. package/dest/crypto/pedersen/pedersen.noble.d.ts +1 -1
  78. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
  79. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  80. package/dest/crypto/pedersen/pedersen.wasm.js +4 -10
  81. package/dest/crypto/poseidon/index.d.ts +2 -2
  82. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  83. package/dest/crypto/poseidon/index.js +6 -16
  84. package/dest/crypto/random/index.d.ts +1 -1
  85. package/dest/crypto/random/index.d.ts.map +1 -1
  86. package/dest/crypto/random/randomness_singleton.d.ts +1 -1
  87. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  88. package/dest/crypto/schnorr/index.d.ts +3 -2
  89. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  90. package/dest/crypto/schnorr/index.js +4 -10
  91. package/dest/crypto/schnorr/signature.d.ts +2 -2
  92. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  93. package/dest/crypto/schnorr/signature.js +2 -2
  94. package/dest/crypto/secp256k1/index.d.ts +1 -1
  95. package/dest/crypto/secp256k1/index.d.ts.map +1 -1
  96. package/dest/crypto/secp256k1/index.js +3 -9
  97. package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
  98. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
  99. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
  100. package/dest/crypto/secp256k1-signer/utils.d.ts +43 -5
  101. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  102. package/dest/crypto/secp256k1-signer/utils.js +76 -8
  103. package/dest/crypto/serialize.d.ts +1 -1
  104. package/dest/crypto/sha256/index.d.ts +2 -2
  105. package/dest/crypto/sha256/index.d.ts.map +1 -1
  106. package/dest/crypto/sha256/index.js +1 -1
  107. package/dest/crypto/sha512/index.d.ts +3 -3
  108. package/dest/crypto/sha512/index.d.ts.map +1 -1
  109. package/dest/crypto/sha512/index.js +1 -1
  110. package/dest/crypto/signature/index.d.ts +2 -2
  111. package/dest/crypto/signature/index.d.ts.map +1 -1
  112. package/dest/crypto/sync/index.d.ts +1 -1
  113. package/dest/crypto/sync/index.js +1 -3
  114. package/dest/crypto/sync/pedersen/index.d.ts +2 -2
  115. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  116. package/dest/crypto/sync/pedersen/index.js +1 -1
  117. package/dest/crypto/sync/poseidon/index.d.ts +2 -2
  118. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  119. package/dest/crypto/sync/poseidon/index.js +1 -1
  120. package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
  121. package/dest/curves/bls12/field.d.ts.map +1 -0
  122. package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +6 -6
  123. package/dest/curves/bls12/index.d.ts +3 -0
  124. package/dest/curves/bls12/index.d.ts.map +1 -0
  125. package/dest/curves/bls12/index.js +2 -0
  126. package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +4 -13
  127. package/dest/curves/bls12/point.d.ts.map +1 -0
  128. package/dest/{fields/bls12_point.js → curves/bls12/point.js} +7 -7
  129. package/dest/{fields/fields.d.ts → curves/bn254/field.d.ts} +16 -9
  130. package/dest/curves/bn254/field.d.ts.map +1 -0
  131. package/dest/{fields/fields.js → curves/bn254/field.js} +35 -9
  132. package/dest/curves/bn254/index.d.ts +3 -0
  133. package/dest/curves/bn254/index.d.ts.map +1 -0
  134. package/dest/curves/bn254/index.js +2 -0
  135. package/dest/curves/bn254/point.d.ts +54 -0
  136. package/dest/curves/bn254/point.d.ts.map +1 -0
  137. package/dest/curves/bn254/point.js +143 -0
  138. package/dest/curves/grumpkin/index.d.ts +10 -0
  139. package/dest/curves/grumpkin/index.d.ts.map +1 -0
  140. package/dest/curves/grumpkin/index.js +3 -0
  141. package/dest/{fields → curves/grumpkin}/point.d.ts +13 -13
  142. package/dest/curves/grumpkin/point.d.ts.map +1 -0
  143. package/dest/{fields → curves/grumpkin}/point.js +24 -7
  144. package/dest/decorators/index.d.ts +1 -1
  145. package/dest/decorators/memoize.d.ts +1 -1
  146. package/dest/decorators/memoize.d.ts.map +1 -1
  147. package/dest/error/index.d.ts +4 -4
  148. package/dest/error/index.d.ts.map +1 -1
  149. package/dest/eth-address/index.d.ts +12 -2
  150. package/dest/eth-address/index.d.ts.map +1 -1
  151. package/dest/eth-address/index.js +23 -1
  152. package/dest/eth-signature/eth_signature.d.ts +1 -4
  153. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  154. package/dest/eth-signature/index.d.ts +1 -1
  155. package/dest/fs/index.d.ts +1 -1
  156. package/dest/fs/run_in_dir.d.ts +1 -1
  157. package/dest/fs/try_rm_dir.d.ts +1 -1
  158. package/dest/iterable/all.d.ts +1 -1
  159. package/dest/iterable/filter.d.ts +1 -1
  160. package/dest/iterable/index.d.ts +1 -1
  161. package/dest/iterable/isAsyncIt.d.ts +1 -1
  162. package/dest/iterable/map.d.ts +1 -1
  163. package/dest/iterable/peek.d.ts +1 -1
  164. package/dest/iterable/sort.d.ts +1 -1
  165. package/dest/iterable/take.d.ts +1 -1
  166. package/dest/iterable/toArray.d.ts +1 -1
  167. package/dest/json-rpc/client/fetch.d.ts +1 -1
  168. package/dest/json-rpc/client/index.d.ts +1 -1
  169. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
  170. package/dest/json-rpc/client/undici.d.ts +1 -1
  171. package/dest/json-rpc/convert.d.ts +1 -1
  172. package/dest/json-rpc/errors.d.ts +1 -1
  173. package/dest/json-rpc/errors.d.ts.map +1 -1
  174. package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
  175. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  176. package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
  177. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  178. package/dest/json-rpc/fixtures/test_state.d.ts +1 -1
  179. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
  180. package/dest/json-rpc/index.d.ts +1 -1
  181. package/dest/json-rpc/js_utils.d.ts +1 -1
  182. package/dest/json-rpc/js_utils.d.ts.map +1 -1
  183. package/dest/json-rpc/server/index.d.ts +1 -1
  184. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
  185. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  186. package/dest/json-rpc/server/telemetry.d.ts +1 -1
  187. package/dest/json-rpc/test/index.d.ts +1 -1
  188. package/dest/json-rpc/test/integration.d.ts +1 -1
  189. package/dest/log/console.d.ts +1 -1
  190. package/dest/log/gcloud-logger-config.d.ts +1 -1
  191. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  192. package/dest/log/index.d.ts +1 -1
  193. package/dest/log/libp2p_logger.d.ts +1 -1
  194. package/dest/log/log-filters.d.ts +1 -1
  195. package/dest/log/log-levels.d.ts +1 -1
  196. package/dest/log/log_fn.d.ts +1 -1
  197. package/dest/log/noir_debug_log_util.d.ts +1 -1
  198. package/dest/log/pino-logger.d.ts +2 -2
  199. package/dest/message/index.d.ts +1 -1
  200. package/dest/message/index.d.ts.map +1 -1
  201. package/dest/mutex/index.d.ts +1 -1
  202. package/dest/mutex/index.d.ts.map +1 -1
  203. package/dest/mutex/mutex_database.d.ts +1 -1
  204. package/dest/noir/index.d.ts +1 -1
  205. package/dest/noir/noir_package_config.d.ts +9 -9
  206. package/dest/number/index.d.ts +1 -1
  207. package/dest/profiler/index.d.ts +1 -1
  208. package/dest/profiler/profiler.d.ts +1 -1
  209. package/dest/promise/index.d.ts +1 -1
  210. package/dest/promise/running-promise.d.ts +1 -1
  211. package/dest/promise/running-promise.d.ts.map +1 -1
  212. package/dest/promise/utils.d.ts +1 -1
  213. package/dest/queue/base_memory_queue.d.ts +1 -1
  214. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  215. package/dest/queue/batch_queue.d.ts +1 -1
  216. package/dest/queue/batch_queue.d.ts.map +1 -1
  217. package/dest/queue/bounded_serial_queue.d.ts +1 -1
  218. package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
  219. package/dest/queue/fifo_memory_queue.d.ts +1 -1
  220. package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
  221. package/dest/queue/index.d.ts +1 -1
  222. package/dest/queue/priority_memory_queue.d.ts +1 -1
  223. package/dest/queue/priority_memory_queue.d.ts.map +1 -1
  224. package/dest/queue/priority_queue.d.ts +1 -1
  225. package/dest/queue/priority_queue.d.ts.map +1 -1
  226. package/dest/queue/semaphore.d.ts +1 -1
  227. package/dest/queue/semaphore.d.ts.map +1 -1
  228. package/dest/queue/serial_queue.d.ts +1 -1
  229. package/dest/queue/serial_queue.d.ts.map +1 -1
  230. package/dest/retry/index.d.ts +1 -1
  231. package/dest/running-promise/index.d.ts +1 -1
  232. package/dest/schemas/api.d.ts +1 -1
  233. package/dest/schemas/index.d.ts +1 -1
  234. package/dest/schemas/parse.d.ts +1 -1
  235. package/dest/schemas/schemas.d.ts +13 -17
  236. package/dest/schemas/schemas.d.ts.map +1 -1
  237. package/dest/schemas/schemas.js +9 -10
  238. package/dest/schemas/types.d.ts +1 -1
  239. package/dest/schemas/utils.d.ts +4 -4
  240. package/dest/schemas/utils.d.ts.map +1 -1
  241. package/dest/schemas/utils.js +15 -5
  242. package/dest/serialize/buffer_reader.d.ts +1 -1
  243. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  244. package/dest/serialize/field_reader.d.ts +2 -2
  245. package/dest/serialize/field_reader.d.ts.map +1 -1
  246. package/dest/serialize/field_reader.js +1 -1
  247. package/dest/serialize/free_funcs.d.ts +2 -2
  248. package/dest/serialize/free_funcs.d.ts.map +1 -1
  249. package/dest/serialize/free_funcs.js +1 -1
  250. package/dest/serialize/index.d.ts +1 -1
  251. package/dest/serialize/serialize.d.ts +2 -2
  252. package/dest/serialize/serialize.d.ts.map +1 -1
  253. package/dest/serialize/serialize.js +1 -1
  254. package/dest/serialize/type_registry.d.ts +1 -1
  255. package/dest/serialize/type_registry.d.ts.map +1 -1
  256. package/dest/serialize/types.d.ts +1 -1
  257. package/dest/sleep/index.d.ts +1 -1
  258. package/dest/sleep/index.d.ts.map +1 -1
  259. package/dest/string/index.d.ts +5 -1
  260. package/dest/string/index.d.ts.map +1 -1
  261. package/dest/string/index.js +1 -1
  262. package/dest/testing/files/index.d.ts +2 -1
  263. package/dest/testing/files/index.d.ts.map +1 -1
  264. package/dest/testing/files/index.js +1 -1
  265. package/dest/testing/formatting.d.ts +1 -1
  266. package/dest/testing/index.d.ts +1 -1
  267. package/dest/testing/port_allocator.d.ts +1 -1
  268. package/dest/testing/snapshot_serializer.d.ts +1 -1
  269. package/dest/testing/test_data.d.ts +1 -1
  270. package/dest/timer/date.d.ts +1 -1
  271. package/dest/timer/date.d.ts.map +1 -1
  272. package/dest/timer/elapsed.d.ts +1 -1
  273. package/dest/timer/index.d.ts +1 -1
  274. package/dest/timer/timeout.d.ts +1 -1
  275. package/dest/timer/timeout.d.ts.map +1 -1
  276. package/dest/timer/timer.d.ts +1 -1
  277. package/dest/timer/timer.d.ts.map +1 -1
  278. package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
  279. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  280. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +1 -1
  281. package/dest/transport/dispatch/messages.d.ts +1 -1
  282. package/dest/transport/index.d.ts +1 -1
  283. package/dest/transport/interface/connector.d.ts +1 -1
  284. package/dest/transport/interface/listener.d.ts +1 -1
  285. package/dest/transport/interface/socket.d.ts +1 -1
  286. package/dest/transport/interface/transferable.d.ts +1 -1
  287. package/dest/transport/node/index.d.ts +1 -1
  288. package/dest/transport/node/node_connector.d.ts +1 -1
  289. package/dest/transport/node/node_connector.d.ts.map +1 -1
  290. package/dest/transport/node/node_connector_socket.d.ts +1 -1
  291. package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
  292. package/dest/transport/node/node_listener.d.ts +1 -1
  293. package/dest/transport/node/node_listener.d.ts.map +1 -1
  294. package/dest/transport/node/node_listener_socket.d.ts +1 -1
  295. package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
  296. package/dest/transport/transport_client.d.ts +1 -1
  297. package/dest/transport/transport_client.d.ts.map +1 -1
  298. package/dest/transport/transport_server.d.ts +1 -10
  299. package/dest/transport/transport_server.d.ts.map +1 -1
  300. package/dest/trees/balanced_merkle_tree.d.ts +22 -0
  301. package/dest/trees/balanced_merkle_tree.d.ts.map +1 -0
  302. package/dest/trees/balanced_merkle_tree.js +66 -0
  303. package/dest/trees/hasher.d.ts +1 -1
  304. package/dest/trees/index.d.ts +2 -1
  305. package/dest/trees/index.d.ts.map +1 -1
  306. package/dest/trees/index.js +1 -0
  307. package/dest/trees/indexed_merkle_tree.d.ts +1 -1
  308. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
  309. package/dest/trees/indexed_merkle_tree.js +1 -1
  310. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  311. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  312. package/dest/trees/indexed_tree_leaf.d.ts +1 -1
  313. package/dest/trees/membership_witness.d.ts +3 -24
  314. package/dest/trees/membership_witness.d.ts.map +1 -1
  315. package/dest/trees/membership_witness.js +1 -1
  316. package/dest/trees/merkle_tree.d.ts +1 -1
  317. package/dest/trees/merkle_tree.d.ts.map +1 -1
  318. package/dest/trees/merkle_tree_calculator.d.ts +2 -12
  319. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  320. package/dest/trees/merkle_tree_calculator.js +1 -31
  321. package/dest/trees/sibling_path.d.ts +5 -39
  322. package/dest/trees/sibling_path.d.ts.map +1 -1
  323. package/dest/trees/sibling_path.js +2 -2
  324. package/dest/trees/unbalanced_merkle_tree.d.ts +5 -3
  325. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
  326. package/dest/trees/unbalanced_merkle_tree.js +32 -9
  327. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +6 -5
  328. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
  329. package/dest/trees/unbalanced_merkle_tree_calculator.js +36 -40
  330. package/dest/trees/unbalanced_tree_store.d.ts +1 -1
  331. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  332. package/dest/types/index.d.ts +1 -1
  333. package/dest/url/index.d.ts +1 -1
  334. package/dest/validation/index.d.ts +1 -1
  335. package/package.json +29 -7
  336. package/src/array/array.ts +0 -16
  337. package/src/branded-types/block_number.ts +112 -0
  338. package/src/branded-types/checkpoint_number.ts +100 -0
  339. package/src/branded-types/epoch.ts +88 -0
  340. package/src/branded-types/index.ts +6 -0
  341. package/src/branded-types/slot.ts +88 -0
  342. package/src/branded-types/types.ts +2 -0
  343. package/src/buffer/buffer16.ts +2 -2
  344. package/src/buffer/buffer32.ts +2 -2
  345. package/src/collection/array.ts +15 -3
  346. package/src/config/env_var.ts +20 -2
  347. package/src/config/index.ts +20 -2
  348. package/src/crypto/aes128/index.ts +2 -2
  349. package/src/crypto/bls/bn254_keystore.ts +287 -0
  350. package/src/crypto/bls/index.ts +77 -0
  351. package/src/crypto/bn254/index.ts +64 -0
  352. package/src/crypto/ecdsa/index.ts +4 -4
  353. package/src/crypto/ecdsa/signature.ts +2 -2
  354. package/src/crypto/grumpkin/index.ts +14 -20
  355. package/src/crypto/keys/index.ts +2 -2
  356. package/src/crypto/pedersen/pedersen.wasm.ts +4 -4
  357. package/src/crypto/poseidon/index.ts +6 -6
  358. package/src/crypto/schnorr/index.ts +5 -4
  359. package/src/crypto/schnorr/signature.ts +2 -2
  360. package/src/crypto/secp256k1/index.ts +3 -3
  361. package/src/crypto/secp256k1-signer/utils.ts +102 -10
  362. package/src/crypto/sha256/index.ts +1 -1
  363. package/src/crypto/sha512/index.ts +1 -1
  364. package/src/crypto/signature/index.ts +1 -1
  365. package/src/crypto/sync/index.ts +1 -1
  366. package/src/crypto/sync/pedersen/index.ts +1 -1
  367. package/src/crypto/sync/poseidon/index.ts +1 -1
  368. package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +6 -6
  369. package/src/curves/bls12/index.ts +2 -0
  370. package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +7 -7
  371. package/src/{fields/fields.ts → curves/bn254/field.ts} +37 -14
  372. package/src/curves/bn254/index.ts +2 -0
  373. package/src/curves/bn254/point.ts +170 -0
  374. package/src/curves/grumpkin/index.ts +11 -0
  375. package/src/{fields → curves/grumpkin}/point.ts +26 -7
  376. package/src/eth-address/index.ts +26 -1
  377. package/src/schemas/schemas.ts +16 -13
  378. package/src/schemas/utils.ts +21 -8
  379. package/src/serialize/field_reader.ts +1 -1
  380. package/src/serialize/free_funcs.ts +1 -1
  381. package/src/serialize/serialize.ts +1 -1
  382. package/src/string/index.ts +3 -0
  383. package/src/testing/files/index.ts +1 -1
  384. package/src/trees/balanced_merkle_tree.ts +84 -0
  385. package/src/trees/index.ts +1 -0
  386. package/src/trees/indexed_merkle_tree.ts +1 -1
  387. package/src/trees/membership_witness.ts +1 -1
  388. package/src/trees/merkle_tree_calculator.ts +1 -34
  389. package/src/trees/sibling_path.ts +2 -2
  390. package/src/trees/unbalanced_merkle_tree.ts +54 -6
  391. package/src/trees/unbalanced_merkle_tree_calculator.ts +34 -41
  392. package/dest/crypto/index.d.ts +0 -15
  393. package/dest/crypto/index.d.ts.map +0 -1
  394. package/dest/crypto/index.js +0 -14
  395. package/dest/fields/bls12_fields.d.ts.map +0 -1
  396. package/dest/fields/bls12_point.d.ts.map +0 -1
  397. package/dest/fields/coordinate.d.ts +0 -66
  398. package/dest/fields/coordinate.d.ts.map +0 -1
  399. package/dest/fields/coordinate.js +0 -96
  400. package/dest/fields/fields.d.ts.map +0 -1
  401. package/dest/fields/index.d.ts +0 -6
  402. package/dest/fields/index.d.ts.map +0 -1
  403. package/dest/fields/index.js +0 -5
  404. package/dest/fields/point.d.ts.map +0 -1
  405. package/dest/index.d.ts +0 -30
  406. package/dest/index.d.ts.map +0 -1
  407. package/dest/index.js +0 -30
  408. package/src/crypto/index.ts +0 -14
  409. package/src/fields/coordinate.ts +0 -104
  410. package/src/fields/index.ts +0 -5
  411. package/src/index.ts +0 -30
@@ -2,7 +2,7 @@ import { inspect } from 'util';
2
2
 
3
3
  import { keccak256String } from '../crypto/keccak/index.js';
4
4
  import { randomBytes } from '../crypto/random/index.js';
5
- import { Fr } from '../fields/index.js';
5
+ import { Fr } from '../curves/bn254/index.js';
6
6
  import { hexSchemaFor } from '../schemas/utils.js';
7
7
  import { BufferReader, FieldReader } from '../serialize/index.js';
8
8
  import { TypeRegistry } from '../serialize/type_registry.js';
@@ -41,6 +41,24 @@ export class EthAddress {
41
41
  return new EthAddress(Buffer.from(address.replace(/^0x/i, ''), 'hex'));
42
42
  }
43
43
 
44
+ /**
45
+ * Creates an EthAddress from a plain object without Zod validation.
46
+ * This method is optimized for performance and skips validation, making it suitable
47
+ * for deserializing trusted data (e.g., from C++ via MessagePack).
48
+ * Handles buffers (20 or 32 bytes), strings, or existing instances.
49
+ * @param obj - Plain object, buffer, string, or EthAddress instance
50
+ * @returns An EthAddress instance
51
+ */
52
+ public static fromPlainObject(obj: any): EthAddress {
53
+ if (obj instanceof EthAddress) {
54
+ return obj;
55
+ }
56
+ if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
57
+ return obj.length === 20 ? new EthAddress(obj) : EthAddress.fromField(new Fr(obj));
58
+ }
59
+ return EthAddress.fromString(obj);
60
+ }
61
+
44
62
  /**
45
63
  * Create a random EthAddress instance with 20 random bytes.
46
64
  * This method generates a new Ethereum address with a randomly generated set of 20 bytes.
@@ -240,8 +258,15 @@ export class EthAddress {
240
258
  }
241
259
 
242
260
  static get schema() {
261
+ // Serialization from hex string.
243
262
  return hexSchemaFor(EthAddress, EthAddress.isAddress);
244
263
  }
264
+
265
+ static areEqual(a: EthAddress | string, b: EthAddress | string) {
266
+ const addrA = typeof a === 'string' ? EthAddress.fromString(a) : a;
267
+ const addrB = typeof b === 'string' ? EthAddress.fromString(b) : b;
268
+ return addrA.equals(addrB);
269
+ }
245
270
  }
246
271
 
247
272
  // For deserializing JSON.
@@ -1,14 +1,22 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ import { EpochNumber, EpochNumberSchema } from '../branded-types/epoch.js';
4
+ import { SlotNumber, SlotNumberSchema } from '../branded-types/slot.js';
3
5
  import { Buffer32 } from '../buffer/buffer32.js';
4
6
  import { SecretValue } from '../config/secret_value.js';
7
+ import { Fq, Fr } from '../curves/bn254/field.js';
8
+ import { Point } from '../curves/grumpkin/point.js';
5
9
  import { EthAddress } from '../eth-address/index.js';
6
- import { Fq, Fr } from '../fields/fields.js';
7
- import { Point } from '../fields/point.js';
8
- import { isHex, withoutHexPrefix } from '../string/index.js';
10
+ import { isHex, withHexPrefix, withoutHexPrefix } from '../string/index.js';
9
11
  import { bufferSchema, hexSchema } from './utils.js';
10
12
 
11
13
  export const schemas = {
14
+ /** Accepts a number, bigint, or string as an EpochNumber. */
15
+ EpochNumber: EpochNumberSchema,
16
+
17
+ /** Accepts a number, bigint, or string as a SlotNumber. */
18
+ SlotNumber: SlotNumberSchema,
19
+
12
20
  /** Accepts a hex string. */
13
21
  EthAddress: EthAddress.schema,
14
22
 
@@ -54,15 +62,7 @@ export const schemas = {
54
62
  Buffer32: z.string().refine(isHex, 'Not a valid hex string').transform(Buffer32.fromString),
55
63
 
56
64
  /** Accepts a base64 string or an object `{ type: 'Buffer', data: [byte, byte...] }` as a buffer. */
57
- Buffer: z.union([
58
- bufferSchema,
59
- z
60
- .object({
61
- type: z.literal('Buffer'),
62
- data: z.array(z.number().int().min(0).max(255)),
63
- })
64
- .transform(({ data }) => Buffer.from(data)),
65
- ]),
65
+ Buffer: bufferSchema,
66
66
 
67
67
  /** Accepts a hex string as a buffer. */
68
68
  BufferHex: z
@@ -74,9 +74,12 @@ export const schemas = {
74
74
  /** Hex string with an optional 0x prefix which gets removed as part of the parsing. */
75
75
  HexString: hexSchema,
76
76
 
77
+ /** Hex string with an optional 0x prefix which gets enforced as part of the parsing. */
78
+ HexStringWith0x: z.string().refine(isHex, 'Not a valid hex string').transform(withHexPrefix),
79
+
77
80
  /** A secret config value */
78
81
  SecretValue: SecretValue.schema,
79
82
  };
80
83
 
81
84
  // These are needed to avoid errors such as: "The inferred type of 'YourClassSchema' cannot be named without a reference to..."
82
- export type { EthAddress, Fq, Fr, Point };
85
+ export type { EpochNumber, EthAddress, Fq, Fr, Point, SlotNumber };
@@ -21,13 +21,25 @@ export const hexSchema = z.string().refine(isHex, 'Not a valid hex string').tran
21
21
  // Copied from zod internals, which was copied from https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
22
22
  const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
23
23
 
24
- /** Schema for a buffer represented as a base64 string. */
25
- export const bufferSchema = z
26
- .string()
27
- // We only test the str for base64 if it's shorter than 1024 bytes, otherwise we've run into maximum
28
- // stack size exceeded errors when trying to validate excessively long strings (such as contract bytecode).
29
- .refine(str => str.length > 1024 || base64Regex.test(str), 'Not a valid base64 string')
30
- .transform(data => Buffer.from(data, 'base64'));
24
+ /** Schema for a buffer represented as a base64 string or a Buffer object. */
25
+ export const bufferSchema: ZodFor<Buffer> = z.union([
26
+ // Serialization from base64 string.
27
+ z
28
+ .string()
29
+ // We only test the str for base64 if it's shorter than 1024 bytes, otherwise we've run into maximum
30
+ // stack size exceeded errors when trying to validate excessively long strings (such as contract bytecode).
31
+ .refine(str => str.length > 1024 || base64Regex.test(str), 'Not a valid base64 string')
32
+ .transform(data => Buffer.from(data, 'base64')),
33
+ // Serialization from Buffer-annotated object.
34
+ z
35
+ .object({
36
+ type: z.literal('Buffer'),
37
+ data: z.array(z.number().int().min(0).max(255)),
38
+ })
39
+ .transform(({ data }) => Buffer.from(data)),
40
+ // Serialization from Buffer
41
+ z.instanceof(Buffer),
42
+ ]);
31
43
 
32
44
  export class ZodNullableOptional<T extends ZodTypeAny> extends ZodOptional<T> {
33
45
  _isNullableOptional = true;
@@ -88,12 +100,13 @@ export function hexSchemaFor<TClass extends { fromString(str: string): any } | {
88
100
  */
89
101
  export function bufferSchemaFor<TClass extends { fromBuffer(buf: Buffer): any }>(
90
102
  klazz: TClass,
103
+ refinement?: (buf: Buffer) => boolean,
91
104
  ): ZodType<
92
105
  TClass extends { fromBuffer(buf: Buffer): infer TInstance } ? ToJsonIs<TInstance, Buffer> : never,
93
106
  any,
94
107
  string
95
108
  > {
96
- return bufferSchema.transform(klazz.fromBuffer.bind(klazz));
109
+ return bufferSchema.refine(refinement ?? (() => true), 'Not a valid buffer').transform(klazz.fromBuffer.bind(klazz));
97
110
  }
98
111
 
99
112
  /** Creates a schema for a js Map type that matches the serialization used in jsonStringify. */
@@ -1,4 +1,4 @@
1
- import { Fq, type Fr } from '../fields/fields.js';
1
+ import { Fq, type Fr } from '../curves/bn254/field.js';
2
2
  import type { Tuple } from './types.js';
3
3
 
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { toBufferBE } from '../bigint-buffer/index.js';
2
- import { Fr } from '../fields/fields.js';
2
+ import { Fr } from '../curves/bn254/field.js';
3
3
  import type { Tuple } from './types.js';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
2
- import { Fr } from '../fields/fields.js';
2
+ import { Fr } from '../curves/bn254/field.js';
3
3
  import { numToUInt32BE } from './free_funcs.js';
4
4
 
5
5
  /**
@@ -1,3 +1,6 @@
1
+ /** Parameterized hex string type for specific byte lengths */
2
+ export type Hex<TByteLength extends number> = `0x${string}` & { readonly _length: TByteLength };
3
+
1
4
  export function hasHexPrefix(str: string): str is `0x${string}` {
2
5
  return str.startsWith('0x');
3
6
  }
@@ -63,7 +63,7 @@ export function updateProtocolCircuitSampleInputs(circuitName: string, value: st
63
63
  logger(`Updated test data in ${targetFile} for ${circuitName}`);
64
64
  }
65
65
 
66
- function getPathToFile(targetFileFromRepoRoot: string) {
66
+ export function getPathToFile(targetFileFromRepoRoot: string) {
67
67
  const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../../../../');
68
68
  if (!existsSync(join(repoRoot, 'CODEOWNERS'))) {
69
69
  throw new Error(`Path to repo root is incorrect (got ${repoRoot})`);
@@ -0,0 +1,84 @@
1
+ import { pedersenHash as pedersenHashArray } from '@aztec/foundation/crypto/pedersen';
2
+ import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
3
+ import { sha256Trunc } from '@aztec/foundation/crypto/sha256';
4
+
5
+ import type { AsyncHasher, Hasher } from './hasher.js';
6
+
7
+ export const shaMerkleHash: Hasher['hash'] = (left: Buffer, right: Buffer) =>
8
+ sha256Trunc(Buffer.concat([left, right])) as Buffer<ArrayBuffer>;
9
+
10
+ export const pedersenMerkleHash: AsyncHasher['hash'] = async (left: Buffer, right: Buffer) =>
11
+ (await pedersenHashArray([left, right])).toBuffer() as Buffer<ArrayBuffer>;
12
+
13
+ export const poseidonMerkleHash: AsyncHasher['hash'] = async (left: Buffer, right: Buffer) =>
14
+ (await poseidon2Hash([left, right])).toBuffer() as Buffer<ArrayBuffer>;
15
+
16
+ export const computeBalancedShaRoot = (leaves: Buffer[]) => computeBalancedMerkleTreeRoot(leaves);
17
+
18
+ export const computeBalancedPedersenRoot = async (leaves: Buffer[]) =>
19
+ await computeBalancedMerkleTreeRootAsync(leaves, pedersenMerkleHash);
20
+
21
+ export const computeBalancedPoseidonRoot = async (leaves: Buffer[]) =>
22
+ await computeBalancedMerkleTreeRootAsync(leaves, poseidonMerkleHash);
23
+
24
+ /**
25
+ * Computes the Merkle root with the provided leaves **synchronously**.
26
+ * This method uses a synchronous hash function (defaults to `sha256Trunc`).
27
+ *
28
+ * @throws If the number of leaves is not a power of two.
29
+ */
30
+ export function computeBalancedMerkleTreeRoot(leaves: Buffer[], hasher = shaMerkleHash): Buffer {
31
+ const height = getTreeHeight(leaves);
32
+ let nodes = leaves.slice();
33
+
34
+ for (let i = 0; i < height; ++i) {
35
+ let j = 0;
36
+ for (; j < nodes.length / 2; ++j) {
37
+ const l = nodes[j * 2];
38
+ const r = nodes[j * 2 + 1];
39
+ nodes[j] = hasher(l, r);
40
+ }
41
+ nodes = nodes.slice(0, j);
42
+ }
43
+
44
+ return nodes[0];
45
+ }
46
+
47
+ /**
48
+ * Computes the Merkle root with the provided leaves **asynchronously**.
49
+ * This method uses an asynchronous hash function (defaults to `pedersenHash`).
50
+ *
51
+ * @throws If the number of leaves is not a power of two.
52
+ */
53
+ export async function computeBalancedMerkleTreeRootAsync(
54
+ leaves: Buffer[],
55
+ hasher = poseidonMerkleHash,
56
+ ): Promise<Buffer> {
57
+ const height = getTreeHeight(leaves);
58
+ let nodes = leaves.slice();
59
+
60
+ for (let i = 0; i < height; ++i) {
61
+ let j = 0;
62
+ for (; j < nodes.length / 2; ++j) {
63
+ const l = nodes[j * 2];
64
+ const r = nodes[j * 2 + 1];
65
+ nodes[j] = await hasher(l, r);
66
+ }
67
+ nodes = nodes.slice(0, j);
68
+ }
69
+
70
+ return nodes[0];
71
+ }
72
+
73
+ function getTreeHeight(leaves: Buffer[]) {
74
+ if (leaves.length === 0) {
75
+ throw new Error('Cannot compute a Merkle root with no leaves');
76
+ }
77
+
78
+ const height = Math.log2(leaves.length);
79
+ if (!Number.isInteger(height)) {
80
+ throw new Error('Cannot compute a Merkle root with a non-power-of-two number of leaves');
81
+ }
82
+
83
+ return height;
84
+ }
@@ -1,3 +1,4 @@
1
+ export * from './balanced_merkle_tree.js';
1
2
  export * from './unbalanced_merkle_tree.js';
2
3
  export * from './unbalanced_tree_store.js';
3
4
  export * from './merkle_tree_calculator.js';
@@ -1,4 +1,4 @@
1
- import { Fr } from '../fields/index.js';
1
+ import { Fr } from '../curves/bn254/index.js';
2
2
  import { assertLength } from '../serialize/index.js';
3
3
  import type { IndexedTreeLeafPreimage } from './indexed_tree_leaf.js';
4
4
  import { MembershipWitness } from './membership_witness.js';
@@ -1,6 +1,6 @@
1
1
  import { assertMemberLength } from '../array/array.js';
2
2
  import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
3
- import { Fr } from '../fields/fields.js';
3
+ import { Fr } from '../curves/bn254/field.js';
4
4
  import { schemas } from '../schemas/schemas.js';
5
5
  import { BufferReader, type Tuple, serializeToBuffer } from '../serialize/index.js';
6
6
  import type { SiblingPath } from './sibling_path.js';
@@ -1,4 +1,4 @@
1
- import { pedersenHash, sha256Trunc } from '@aztec/foundation/crypto';
1
+ import { pedersenHash } from '@aztec/foundation/crypto/pedersen';
2
2
 
3
3
  import type { AsyncHasher } from './hasher.js';
4
4
  import { MerkleTree } from './merkle_tree.js';
@@ -69,37 +69,4 @@ export class MerkleTreeCalculator {
69
69
 
70
70
  return leaves[0];
71
71
  }
72
-
73
- /**
74
- * Computes the Merkle root with the provided leaves **synchronously**.
75
- *
76
- * This method uses a synchronous hash function (defaults to `sha256Trunc`) and **does not** allow for padding.
77
- * If the number of leaves is not a power of two, it throws an error.
78
- * This contrasts with the above non-static async method `computeTreeRoot`, which can handle any number of leaves by
79
- * padding with zero hashes.
80
- */
81
- static computeTreeRootSync(leaves: Buffer[], hasher = sha256Trunc): Buffer {
82
- if (leaves.length === 0) {
83
- throw new Error('Cannot compute a Merkle root with no leaves');
84
- }
85
-
86
- const height = Math.log2(leaves.length);
87
- if (!Number.isInteger(height)) {
88
- throw new Error('Cannot compute a Merkle root with a non-power-of-two number of leaves');
89
- }
90
-
91
- let nodes = leaves.slice();
92
-
93
- for (let i = 0; i < height; ++i) {
94
- let j = 0;
95
- for (; j < nodes.length / 2; ++j) {
96
- const l = nodes[j * 2];
97
- const r = nodes[j * 2 + 1];
98
- nodes[j] = hasher(Buffer.concat([l, r]));
99
- }
100
- nodes = nodes.slice(0, j);
101
- }
102
-
103
- return nodes[0];
104
- }
105
72
  }
@@ -1,6 +1,6 @@
1
1
  import { makeTuple } from '../array/array.js';
2
- import { pedersenHash } from '../crypto/index.js';
3
- import { Fr } from '../fields/index.js';
2
+ import { pedersenHash } from '../crypto/pedersen/index.js';
3
+ import { Fr } from '../curves/bn254/index.js';
4
4
  import { schemas } from '../schemas/index.js';
5
5
  import {
6
6
  type Tuple,
@@ -1,5 +1,14 @@
1
- import { sha256Trunc } from '../crypto/sha256/index.js';
2
- import { MerkleTreeCalculator } from './merkle_tree_calculator.js';
1
+ import {
2
+ computeBalancedMerkleTreeRoot,
3
+ computeBalancedMerkleTreeRootAsync,
4
+ poseidonMerkleHash,
5
+ shaMerkleHash,
6
+ } from './balanced_merkle_tree.js';
7
+
8
+ export const computeUnbalancedShaRoot = (leaves: Buffer[]) => computeUnbalancedMerkleTreeRoot(leaves, shaMerkleHash);
9
+
10
+ export const computeUnbalancedPoseidonRoot = async (leaves: Buffer[]) =>
11
+ await computeUnbalancedMerkleTreeRootAsync(leaves, poseidonMerkleHash);
3
12
 
4
13
  /**
5
14
  * Computes the Merkle root of an unbalanced tree.
@@ -22,9 +31,48 @@ import { MerkleTreeCalculator } from './merkle_tree_calculator.js';
22
31
  * But if we instead combine the size-4 and size-8 subtrees first (depth 4), and then merge with the size-2 subtree
23
32
  * (depth 1), the final tree has a depth of 5.
24
33
  */
25
- export function computeUnbalancedMerkleTreeRoot(leaves: Buffer[], hasher = sha256Trunc): Buffer {
34
+ export function computeUnbalancedMerkleTreeRoot(
35
+ leaves: Buffer[],
36
+ hasher = shaMerkleHash,
37
+ emptyRoot = Buffer.alloc(32),
38
+ ): Buffer {
39
+ if (!leaves.length) {
40
+ return emptyRoot;
41
+ }
42
+
43
+ if (leaves.length === 1) {
44
+ return leaves[0];
45
+ }
46
+
47
+ let numRemainingLeaves = leaves.length;
48
+ let subtreeSize = 1;
49
+ let root: Buffer | undefined;
50
+ while (numRemainingLeaves > 1) {
51
+ if ((numRemainingLeaves & subtreeSize) !== 0) {
52
+ const subtreeLeaves = leaves.slice(numRemainingLeaves - subtreeSize, numRemainingLeaves);
53
+ const subtreeRoot = computeBalancedMerkleTreeRoot(subtreeLeaves, hasher);
54
+ if (!root) {
55
+ root = subtreeRoot;
56
+ } else {
57
+ root = hasher(subtreeRoot, root);
58
+ }
59
+
60
+ numRemainingLeaves -= subtreeSize;
61
+ }
62
+
63
+ subtreeSize *= 2;
64
+ }
65
+
66
+ return root!;
67
+ }
68
+
69
+ export async function computeUnbalancedMerkleTreeRootAsync(
70
+ leaves: Buffer[],
71
+ hasher = poseidonMerkleHash,
72
+ emptyRoot = Buffer.alloc(32),
73
+ ): Promise<Buffer> {
26
74
  if (!leaves.length) {
27
- throw new Error('Cannot compute a Merkle root with no leaves');
75
+ return emptyRoot;
28
76
  }
29
77
 
30
78
  if (leaves.length === 1) {
@@ -37,11 +85,11 @@ export function computeUnbalancedMerkleTreeRoot(leaves: Buffer[], hasher = sha25
37
85
  while (numRemainingLeaves > 1) {
38
86
  if ((numRemainingLeaves & subtreeSize) !== 0) {
39
87
  const subtreeLeaves = leaves.slice(numRemainingLeaves - subtreeSize, numRemainingLeaves);
40
- const subtreeRoot = MerkleTreeCalculator.computeTreeRootSync(subtreeLeaves, hasher);
88
+ const subtreeRoot = await computeBalancedMerkleTreeRootAsync(subtreeLeaves, hasher);
41
89
  if (!root) {
42
90
  root = subtreeRoot;
43
91
  } else {
44
- root = hasher(Buffer.concat([subtreeRoot, root]));
92
+ root = await hasher(subtreeRoot, root);
45
93
  }
46
94
 
47
95
  numRemainingLeaves -= subtreeSize;
@@ -1,4 +1,4 @@
1
- import { sha256Trunc } from '../crypto/index.js';
1
+ import { shaMerkleHash } from './balanced_merkle_tree.js';
2
2
  import type { Hasher } from './hasher.js';
3
3
  import { SiblingPath } from './sibling_path.js';
4
4
  import { type TreeNodeLocation, UnbalancedTreeStore } from './unbalanced_tree_store.js';
@@ -6,9 +6,10 @@ import { type TreeNodeLocation, UnbalancedTreeStore } from './unbalanced_tree_st
6
6
  export function computeCompressedUnbalancedMerkleTreeRoot(
7
7
  leaves: Buffer[],
8
8
  valueToCompress = Buffer.alloc(32),
9
+ emptyRoot = Buffer.alloc(32),
9
10
  hasher?: Hasher['hash'],
10
11
  ): Buffer {
11
- const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, hasher);
12
+ const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, emptyRoot, hasher);
12
13
  return calculator.getRoot();
13
14
  }
14
15
 
@@ -32,12 +33,9 @@ export class UnbalancedMerkleTreeCalculator {
32
33
  public constructor(
33
34
  private readonly leaves: Buffer[],
34
35
  private readonly valueToCompress: Buffer,
36
+ private readonly emptyRoot: Buffer,
35
37
  private readonly hasher: Hasher['hash'],
36
38
  ) {
37
- if (leaves.length === 0) {
38
- throw Error('Cannot create a compressed unbalanced tree with 0 leaves.');
39
- }
40
-
41
39
  this.store = new UnbalancedTreeStore(leaves.length);
42
40
  this.buildTree();
43
41
  }
@@ -45,9 +43,10 @@ export class UnbalancedMerkleTreeCalculator {
45
43
  static create(
46
44
  leaves: Buffer[],
47
45
  valueToCompress = Buffer.alloc(0),
48
- hasher = (left: Buffer, right: Buffer) => sha256Trunc(Buffer.concat([left, right])) as Buffer<ArrayBuffer>,
46
+ emptyRoot = Buffer.alloc(32),
47
+ hasher = shaMerkleHash,
49
48
  ) {
50
- return new UnbalancedMerkleTreeCalculator(leaves, valueToCompress, hasher);
49
+ return new UnbalancedMerkleTreeCalculator(leaves, valueToCompress, emptyRoot, hasher);
51
50
  }
52
51
 
53
52
  /**
@@ -113,8 +112,8 @@ export class UnbalancedMerkleTreeCalculator {
113
112
  // Start with the leaves that are not compressed.
114
113
  let toProcess = this.leafLocations.filter((_, i) => !this.leaves[i].equals(this.valueToCompress));
115
114
  if (!toProcess.length) {
116
- // All leaves are compressed. Set 0 to the root.
117
- this.store.setNode({ level: 0, index: 0 }, { value: Buffer.alloc(32) });
115
+ // All leaves are compressed. Set empty root to the root.
116
+ this.store.setNode({ level: 0, index: 0 }, { value: this.emptyRoot });
118
117
  return;
119
118
  }
120
119
 
@@ -138,10 +137,7 @@ export class UnbalancedMerkleTreeCalculator {
138
137
  const shouldShiftUp = !sibling || sibling.value.equals(this.valueToCompress);
139
138
  if (shouldShiftUp) {
140
139
  // The node becomes the parent if the sibling is a compressed leaf.
141
- const isLeaf = this.shiftNodeUp(location, parentLocation);
142
- if (!isLeaf) {
143
- this.shiftChildrenUp(location);
144
- }
140
+ this.shiftNodeUp(location, parentLocation);
145
141
  } else {
146
142
  // Hash the value with the (right) sibling and update the parent node.
147
143
  const node = this.store.getNode(location)!;
@@ -157,38 +153,35 @@ export class UnbalancedMerkleTreeCalculator {
157
153
  }
158
154
  }
159
155
 
160
- private shiftNodeUp(fromLocation: TreeNodeLocation, toLocation: TreeNodeLocation): boolean {
161
- const node = this.store.getNode(fromLocation)!;
162
-
163
- this.store.setNode(toLocation, node);
164
-
165
- const isLeaf = node.leafIndex !== undefined;
166
- if (isLeaf) {
167
- // Update the location if the node is a leaf.
168
- this.leafLocations[node.leafIndex!] = toLocation;
156
+ private shiftNodeUp(from: TreeNodeLocation, to: TreeNodeLocation) {
157
+ // Collect all nodes that need to shift.
158
+ const nodesToShift = this.collectNodesToShift(from, to);
159
+ // Move all nodes to their new locations.
160
+ for (const { node, newLocation } of nodesToShift) {
161
+ this.store.setNode(newLocation, node);
162
+ if (node.leafIndex !== undefined) {
163
+ this.leafLocations[node.leafIndex] = newLocation;
164
+ }
169
165
  }
170
-
171
- return isLeaf;
172
166
  }
173
167
 
174
- private shiftChildrenUp(parent: TreeNodeLocation) {
175
- const [left, right] = this.store.getChildLocations(parent);
176
-
177
- const level = parent.level;
178
- const groupSize = 2 ** level;
179
- const computeNewLocation = (index: number) => ({
180
- level,
181
- index: Math.floor(index / (groupSize * 2)) * groupSize + (index % groupSize),
182
- });
168
+ private collectNodesToShift(from: TreeNodeLocation, to: TreeNodeLocation) {
169
+ const node = this.store.getNode(from);
170
+ if (!node) {
171
+ return [];
172
+ }
183
173
 
184
- const isLeftLeaf = this.shiftNodeUp(left, computeNewLocation(left.index));
185
- const isRightLeaf = this.shiftNodeUp(right, computeNewLocation(right.index));
174
+ let result = [{ node, newLocation: to }];
186
175
 
187
- if (!isLeftLeaf) {
188
- this.shiftChildrenUp(left);
189
- }
190
- if (!isRightLeaf) {
191
- this.shiftChildrenUp(right);
176
+ // If not a leaf, collect its children.
177
+ if (node.leafIndex === undefined) {
178
+ const [leftChild, rightChild] = this.store.getChildLocations(from);
179
+ const [leftChildNew, rightChildNew] = this.store.getChildLocations(to);
180
+ result = result
181
+ .concat(this.collectNodesToShift(leftChild, leftChildNew))
182
+ .concat(this.collectNodesToShift(rightChild, rightChildNew));
192
183
  }
184
+
185
+ return result;
193
186
  }
194
187
  }
@@ -1,15 +0,0 @@
1
- export * from './keccak/index.js';
2
- export * from './random/index.js';
3
- export * from './sha256/index.js';
4
- export * from './sha512/index.js';
5
- export * from './pedersen/index.js';
6
- export * from './poseidon/index.js';
7
- export * from './secp256k1-signer/index.js';
8
- export * from './keys/index.js';
9
- export * from './aes128/index.js';
10
- export * from './grumpkin/index.js';
11
- export * from './ecdsa/index.js';
12
- export * from './secp256k1/index.js';
13
- export * from './schnorr/index.js';
14
- export * from './signature/index.js';
15
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
@@ -1,14 +0,0 @@
1
- export * from './keccak/index.js';
2
- export * from './random/index.js';
3
- export * from './sha256/index.js';
4
- export * from './sha512/index.js';
5
- export * from './pedersen/index.js';
6
- export * from './poseidon/index.js';
7
- export * from './secp256k1-signer/index.js';
8
- export * from './keys/index.js';
9
- export * from './aes128/index.js';
10
- export * from './grumpkin/index.js';
11
- export * from './ecdsa/index.js';
12
- export * from './secp256k1/index.js';
13
- export * from './schnorr/index.js';
14
- export * from './signature/index.js';
@@ -1 +0,0 @@
1
- {"version":3,"file":"bls12_fields.d.ts","sourceRoot":"","sources":["../../src/fields/bls12_fields.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAK/B,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAcjC;;GAEG;AACH,8BAAsB,UAAU;IAC9B,OAAO,CAAC,QAAQ,CAAC,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,CAAS;IAE1B,SAAS,aAAa,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAmBrD,SAAS,CAAC,QAAQ,CAAC,OAAO,IAAI,MAAM;IACpC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,MAAM;IAEjC;;OAEG;IACH,QAAQ,IAAI,MAAM;IAOlB,QAAQ,IAAI,KAAK,MAAM,EAAE;IAIzB,QAAQ,IAAI,MAAM;IAUlB,YAAY,IAAI;QAAE,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE;IAYnC,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO;IAIhC,EAAE,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO;IAI5B,MAAM,IAAI,OAAO;IAIjB,OAAO,IAAI,OAAO;IAIlB,UAAU,IAAI,OAAO;IAMrB,cAAc,IAAI,MAAM;IAIxB,OAAO;CAGR;AA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