@aztec/foundation 0.0.1-commit.b655e406 → 0.0.1-commit.c0b82b2

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 (508) 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 +2 -1
  5. package/dest/array/index.d.ts.map +1 -1
  6. package/dest/array/index.js +1 -0
  7. package/dest/array/sorted_array.d.ts +15 -0
  8. package/dest/array/sorted_array.d.ts.map +1 -0
  9. package/dest/array/sorted_array.js +109 -0
  10. package/dest/async-map/index.d.ts +1 -1
  11. package/dest/async-pool/index.d.ts +1 -1
  12. package/dest/bigint/index.d.ts +1 -1
  13. package/dest/bigint-buffer/index.d.ts +1 -1
  14. package/dest/branded-types/block_number.d.ts +56 -0
  15. package/dest/branded-types/block_number.d.ts.map +1 -0
  16. package/dest/branded-types/block_number.js +78 -0
  17. package/dest/branded-types/checkpoint_number.d.ts +54 -0
  18. package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
  19. package/dest/branded-types/checkpoint_number.js +77 -0
  20. package/dest/branded-types/epoch.d.ts +42 -0
  21. package/dest/branded-types/epoch.d.ts.map +1 -0
  22. package/dest/branded-types/epoch.js +59 -0
  23. package/dest/branded-types/index.d.ts +7 -0
  24. package/dest/branded-types/index.d.ts.map +1 -0
  25. package/dest/branded-types/index.js +5 -0
  26. package/dest/branded-types/index_within_checkpoint.d.ts +42 -0
  27. package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -0
  28. package/dest/branded-types/index_within_checkpoint.js +59 -0
  29. package/dest/branded-types/slot.d.ts +42 -0
  30. package/dest/branded-types/slot.d.ts.map +1 -0
  31. package/dest/branded-types/slot.js +59 -0
  32. package/dest/branded-types/types.d.ts +5 -0
  33. package/dest/branded-types/types.d.ts.map +1 -0
  34. package/dest/branded-types/types.js +1 -0
  35. package/dest/buffer/buffer16.d.ts +2 -2
  36. package/dest/buffer/buffer16.d.ts.map +1 -1
  37. package/dest/buffer/buffer16.js +4 -2
  38. package/dest/buffer/buffer32.d.ts +2 -2
  39. package/dest/buffer/buffer32.d.ts.map +1 -1
  40. package/dest/buffer/buffer32.js +4 -2
  41. package/dest/buffer/index.d.ts +1 -1
  42. package/dest/collection/array.d.ts +12 -1
  43. package/dest/collection/array.d.ts.map +1 -1
  44. package/dest/collection/array.js +51 -0
  45. package/dest/collection/index.d.ts +1 -1
  46. package/dest/collection/object.d.ts +1 -1
  47. package/dest/committable/committable.d.ts +1 -1
  48. package/dest/committable/committable.d.ts.map +1 -1
  49. package/dest/committable/index.d.ts +1 -1
  50. package/dest/config/env_var.d.ts +2 -2
  51. package/dest/config/env_var.d.ts.map +1 -1
  52. package/dest/config/index.d.ts +15 -4
  53. package/dest/config/index.d.ts.map +1 -1
  54. package/dest/config/index.js +32 -9
  55. package/dest/config/network_config.d.ts +13 -1
  56. package/dest/config/network_config.d.ts.map +1 -1
  57. package/dest/config/network_config.js +3 -1
  58. package/dest/config/network_name.d.ts +2 -2
  59. package/dest/config/network_name.d.ts.map +1 -1
  60. package/dest/config/network_name.js +2 -0
  61. package/dest/config/parse-env.d.ts +3 -0
  62. package/dest/config/parse-env.d.ts.map +1 -0
  63. package/dest/config/parse-env.js +7 -0
  64. package/dest/config/secret_value.d.ts +1 -1
  65. package/dest/config/secret_value.d.ts.map +1 -1
  66. package/dest/config/secret_value.js +3 -1
  67. package/dest/crypto/aes128/index.d.ts +1 -1
  68. package/dest/crypto/aes128/index.d.ts.map +1 -1
  69. package/dest/crypto/aes128/index.js +2 -6
  70. package/dest/crypto/bls/bn254_keystore.d.ts +15 -15
  71. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
  72. package/dest/crypto/bls/bn254_keystore.js +1 -1
  73. package/dest/crypto/bls/index.d.ts +1 -1
  74. package/dest/crypto/bls/index.js +1 -1
  75. package/dest/crypto/bn254/index.d.ts +35 -51
  76. package/dest/crypto/bn254/index.d.ts.map +1 -1
  77. package/dest/crypto/bn254/index.js +51 -137
  78. package/dest/crypto/ecdsa/index.d.ts +1 -1
  79. package/dest/crypto/ecdsa/index.d.ts.map +1 -1
  80. package/dest/crypto/ecdsa/index.js +4 -12
  81. package/dest/crypto/ecdsa/signature.d.ts +2 -2
  82. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  83. package/dest/crypto/ecdsa/signature.js +2 -2
  84. package/dest/crypto/grumpkin/index.d.ts +4 -2
  85. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  86. package/dest/crypto/grumpkin/index.js +7 -16
  87. package/dest/crypto/keccak/index.d.ts +1 -1
  88. package/dest/crypto/keys/index.d.ts +2 -2
  89. package/dest/crypto/keys/index.d.ts.map +1 -1
  90. package/dest/crypto/keys/index.js +2 -4
  91. package/dest/crypto/pedersen/index.d.ts +1 -1
  92. package/dest/crypto/pedersen/pedersen.noble.d.ts +1 -1
  93. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
  94. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  95. package/dest/crypto/pedersen/pedersen.wasm.js +4 -10
  96. package/dest/crypto/poseidon/index.d.ts +2 -3
  97. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  98. package/dest/crypto/poseidon/index.js +14 -33
  99. package/dest/crypto/random/index.d.ts +1 -1
  100. package/dest/crypto/random/index.d.ts.map +1 -1
  101. package/dest/crypto/random/randomness_singleton.d.ts +4 -3
  102. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  103. package/dest/crypto/random/randomness_singleton.js +5 -5
  104. package/dest/crypto/schnorr/index.d.ts +3 -2
  105. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  106. package/dest/crypto/schnorr/index.js +4 -10
  107. package/dest/crypto/schnorr/signature.d.ts +2 -2
  108. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  109. package/dest/crypto/schnorr/signature.js +2 -2
  110. package/dest/crypto/secp256k1/index.d.ts +1 -1
  111. package/dest/crypto/secp256k1/index.d.ts.map +1 -1
  112. package/dest/crypto/secp256k1/index.js +3 -9
  113. package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
  114. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
  115. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
  116. package/dest/crypto/secp256k1-signer/utils.d.ts +1 -1
  117. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  118. package/dest/crypto/serialize.d.ts +1 -1
  119. package/dest/crypto/sha256/index.d.ts +2 -2
  120. package/dest/crypto/sha256/index.d.ts.map +1 -1
  121. package/dest/crypto/sha256/index.js +1 -1
  122. package/dest/crypto/sha512/index.d.ts +3 -3
  123. package/dest/crypto/sha512/index.d.ts.map +1 -1
  124. package/dest/crypto/sha512/index.js +1 -1
  125. package/dest/crypto/signature/index.d.ts +2 -2
  126. package/dest/crypto/signature/index.d.ts.map +1 -1
  127. package/dest/crypto/sync/index.d.ts +1 -1
  128. package/dest/crypto/sync/index.js +1 -3
  129. package/dest/crypto/sync/pedersen/index.d.ts +2 -2
  130. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  131. package/dest/crypto/sync/pedersen/index.js +1 -1
  132. package/dest/crypto/sync/poseidon/index.d.ts +2 -3
  133. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  134. package/dest/crypto/sync/poseidon/index.js +1 -9
  135. package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
  136. package/dest/curves/bls12/field.d.ts.map +1 -0
  137. package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +12 -9
  138. package/dest/curves/bls12/index.d.ts +3 -0
  139. package/dest/curves/bls12/index.d.ts.map +1 -0
  140. package/dest/curves/bls12/index.js +2 -0
  141. package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +4 -4
  142. package/dest/curves/bls12/point.d.ts.map +1 -0
  143. package/dest/{fields/bls12_point.js → curves/bls12/point.js} +10 -8
  144. package/dest/curves/bn254/field.d.ts +181 -0
  145. package/dest/curves/bn254/field.d.ts.map +1 -0
  146. package/dest/{fields/fields.js → curves/bn254/field.js} +52 -49
  147. package/dest/curves/bn254/index.d.ts +3 -0
  148. package/dest/curves/bn254/index.d.ts.map +1 -0
  149. package/dest/curves/bn254/index.js +2 -0
  150. package/dest/curves/bn254/point.d.ts +54 -0
  151. package/dest/curves/bn254/point.d.ts.map +1 -0
  152. package/dest/curves/bn254/point.js +143 -0
  153. package/dest/curves/grumpkin/index.d.ts +10 -0
  154. package/dest/curves/grumpkin/index.d.ts.map +1 -0
  155. package/dest/curves/grumpkin/index.js +3 -0
  156. package/dest/{fields → curves/grumpkin}/point.d.ts +12 -3
  157. package/dest/curves/grumpkin/point.d.ts.map +1 -0
  158. package/dest/{fields → curves/grumpkin}/point.js +24 -7
  159. package/dest/decorators/index.d.ts +1 -1
  160. package/dest/decorators/memoize.d.ts +1 -1
  161. package/dest/decorators/memoize.d.ts.map +1 -1
  162. package/dest/error/index.d.ts +1 -1
  163. package/dest/eth-address/index.d.ts +12 -2
  164. package/dest/eth-address/index.d.ts.map +1 -1
  165. package/dest/eth-address/index.js +27 -3
  166. package/dest/eth-signature/eth_signature.d.ts +1 -1
  167. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  168. package/dest/eth-signature/index.d.ts +1 -1
  169. package/dest/fs/index.d.ts +1 -1
  170. package/dest/fs/run_in_dir.d.ts +1 -1
  171. package/dest/fs/try_rm_dir.d.ts +1 -1
  172. package/dest/iterable/all.d.ts +1 -1
  173. package/dest/iterable/filter.d.ts +1 -1
  174. package/dest/iterable/index.d.ts +1 -1
  175. package/dest/iterable/isAsyncIt.d.ts +1 -1
  176. package/dest/iterable/map.d.ts +1 -1
  177. package/dest/iterable/peek.d.ts +1 -1
  178. package/dest/iterable/sort.d.ts +1 -1
  179. package/dest/iterable/take.d.ts +1 -1
  180. package/dest/iterable/toArray.d.ts +1 -1
  181. package/dest/iterator/filter.d.ts +3 -0
  182. package/dest/iterator/filter.d.ts.map +1 -0
  183. package/dest/iterator/filter.js +7 -0
  184. package/dest/iterator/index.d.ts +2 -0
  185. package/dest/iterator/index.d.ts.map +1 -0
  186. package/dest/iterator/index.js +1 -0
  187. package/dest/jest/setup.js +28 -1
  188. package/dest/json-rpc/client/fetch.d.ts +1 -1
  189. package/dest/json-rpc/client/index.d.ts +1 -1
  190. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
  191. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  192. package/dest/json-rpc/client/safe_json_rpc_client.js +1 -1
  193. package/dest/json-rpc/client/undici.d.ts +1 -1
  194. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  195. package/dest/json-rpc/client/undici.js +21 -4
  196. package/dest/json-rpc/convert.d.ts +1 -1
  197. package/dest/json-rpc/errors.d.ts +1 -1
  198. package/dest/json-rpc/errors.d.ts.map +1 -1
  199. package/dest/json-rpc/fixtures/class_a.d.ts +1 -1
  200. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  201. package/dest/json-rpc/fixtures/class_b.d.ts +1 -1
  202. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  203. package/dest/json-rpc/fixtures/test_state.d.ts +1 -1
  204. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
  205. package/dest/json-rpc/index.d.ts +1 -1
  206. package/dest/json-rpc/js_utils.d.ts +1 -1
  207. package/dest/json-rpc/js_utils.d.ts.map +1 -1
  208. package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
  209. package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
  210. package/dest/json-rpc/server/api_key_auth.js +57 -0
  211. package/dest/json-rpc/server/index.d.ts +2 -1
  212. package/dest/json-rpc/server/index.d.ts.map +1 -1
  213. package/dest/json-rpc/server/index.js +1 -0
  214. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
  215. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  216. package/dest/json-rpc/server/safe_json_rpc_server.js +1 -1
  217. package/dest/json-rpc/test/index.d.ts +1 -1
  218. package/dest/json-rpc/test/integration.d.ts +1 -1
  219. package/dest/log/bigint-utils.d.ts +5 -0
  220. package/dest/log/bigint-utils.d.ts.map +1 -0
  221. package/dest/log/bigint-utils.js +18 -0
  222. package/dest/log/console.d.ts +1 -1
  223. package/dest/log/gcloud-logger-config.d.ts +1 -1
  224. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  225. package/dest/log/gcloud-logger-config.js +3 -0
  226. package/dest/log/index.d.ts +1 -1
  227. package/dest/log/libp2p_logger.d.ts +5 -2
  228. package/dest/log/libp2p_logger.d.ts.map +1 -1
  229. package/dest/log/libp2p_logger.js +14 -4
  230. package/dest/log/log-filters.d.ts +17 -4
  231. package/dest/log/log-filters.d.ts.map +1 -1
  232. package/dest/log/log-filters.js +26 -12
  233. package/dest/log/log-levels.d.ts +1 -1
  234. package/dest/log/log_fn.d.ts +1 -1
  235. package/dest/log/noir_debug_log_util.d.ts +1 -1
  236. package/dest/log/pino-logger-server.d.ts +9 -0
  237. package/dest/log/pino-logger-server.d.ts.map +1 -0
  238. package/dest/log/pino-logger-server.js +18 -0
  239. package/dest/log/pino-logger.d.ts +38 -9
  240. package/dest/log/pino-logger.d.ts.map +1 -1
  241. package/dest/log/pino-logger.js +122 -29
  242. package/dest/message/index.d.ts +1 -1
  243. package/dest/message/index.d.ts.map +1 -1
  244. package/dest/mutex/index.d.ts +1 -1
  245. package/dest/mutex/index.d.ts.map +1 -1
  246. package/dest/mutex/mutex_database.d.ts +1 -1
  247. package/dest/noir/index.d.ts +1 -1
  248. package/dest/noir/noir_package_config.d.ts +9 -9
  249. package/dest/number/index.d.ts +1 -1
  250. package/dest/profiler/index.d.ts +1 -1
  251. package/dest/profiler/profiler.d.ts +1 -1
  252. package/dest/promise/index.d.ts +1 -1
  253. package/dest/promise/running-promise.d.ts +1 -1
  254. package/dest/promise/running-promise.d.ts.map +1 -1
  255. package/dest/promise/utils.d.ts +1 -1
  256. package/dest/queue/base_memory_queue.d.ts +2 -2
  257. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  258. package/dest/queue/batch_queue.d.ts +1 -1
  259. package/dest/queue/batch_queue.d.ts.map +1 -1
  260. package/dest/queue/bounded_serial_queue.d.ts +1 -1
  261. package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
  262. package/dest/queue/fifo_memory_queue.d.ts +1 -1
  263. package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
  264. package/dest/queue/index.d.ts +1 -1
  265. package/dest/queue/priority_memory_queue.d.ts +1 -1
  266. package/dest/queue/priority_memory_queue.d.ts.map +1 -1
  267. package/dest/queue/priority_queue.d.ts +1 -1
  268. package/dest/queue/priority_queue.d.ts.map +1 -1
  269. package/dest/queue/semaphore.d.ts +5 -1
  270. package/dest/queue/semaphore.d.ts.map +1 -1
  271. package/dest/queue/serial_queue.d.ts +1 -1
  272. package/dest/queue/serial_queue.d.ts.map +1 -1
  273. package/dest/retry/index.d.ts +11 -1
  274. package/dest/retry/index.d.ts.map +1 -1
  275. package/dest/retry/index.js +11 -0
  276. package/dest/running-promise/index.d.ts +1 -1
  277. package/dest/schemas/api.d.ts +1 -1
  278. package/dest/schemas/index.d.ts +1 -1
  279. package/dest/schemas/parse.d.ts +1 -1
  280. package/dest/schemas/schemas.d.ts +15 -17
  281. package/dest/schemas/schemas.d.ts.map +1 -1
  282. package/dest/schemas/schemas.js +14 -10
  283. package/dest/schemas/types.d.ts +31 -1
  284. package/dest/schemas/types.d.ts.map +1 -1
  285. package/dest/schemas/types.js +25 -1
  286. package/dest/schemas/utils.d.ts +4 -4
  287. package/dest/schemas/utils.d.ts.map +1 -1
  288. package/dest/schemas/utils.js +15 -5
  289. package/dest/serialize/buffer_reader.d.ts +14 -4
  290. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  291. package/dest/serialize/buffer_reader.js +26 -4
  292. package/dest/serialize/field_reader.d.ts +2 -2
  293. package/dest/serialize/field_reader.d.ts.map +1 -1
  294. package/dest/serialize/field_reader.js +1 -1
  295. package/dest/serialize/free_funcs.d.ts +2 -2
  296. package/dest/serialize/free_funcs.d.ts.map +1 -1
  297. package/dest/serialize/free_funcs.js +1 -1
  298. package/dest/serialize/index.d.ts +1 -1
  299. package/dest/serialize/serialize.d.ts +20 -2
  300. package/dest/serialize/serialize.d.ts.map +1 -1
  301. package/dest/serialize/serialize.js +32 -1
  302. package/dest/serialize/type_registry.d.ts +1 -1
  303. package/dest/serialize/type_registry.d.ts.map +1 -1
  304. package/dest/serialize/types.d.ts +1 -1
  305. package/dest/sleep/index.d.ts +4 -1
  306. package/dest/sleep/index.d.ts.map +1 -1
  307. package/dest/sleep/index.js +14 -1
  308. package/dest/string/index.d.ts +1 -1
  309. package/dest/testing/files/index.d.ts +2 -1
  310. package/dest/testing/files/index.d.ts.map +1 -1
  311. package/dest/testing/files/index.js +1 -1
  312. package/dest/testing/formatting.d.ts +1 -1
  313. package/dest/testing/index.d.ts +1 -1
  314. package/dest/testing/port_allocator.d.ts +1 -1
  315. package/dest/testing/snapshot_serializer.d.ts +1 -1
  316. package/dest/testing/test_data.d.ts +1 -1
  317. package/dest/timer/date.d.ts +26 -1
  318. package/dest/timer/date.d.ts.map +1 -1
  319. package/dest/timer/date.js +36 -0
  320. package/dest/timer/elapsed.d.ts +1 -1
  321. package/dest/timer/index.d.ts +1 -1
  322. package/dest/timer/timeout.d.ts +1 -1
  323. package/dest/timer/timeout.d.ts.map +1 -1
  324. package/dest/timer/timer.d.ts +1 -1
  325. package/dest/timer/timer.d.ts.map +1 -1
  326. package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
  327. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  328. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +1 -1
  329. package/dest/transport/dispatch/messages.d.ts +1 -1
  330. package/dest/transport/index.d.ts +1 -1
  331. package/dest/transport/interface/connector.d.ts +1 -1
  332. package/dest/transport/interface/listener.d.ts +1 -1
  333. package/dest/transport/interface/socket.d.ts +1 -1
  334. package/dest/transport/interface/transferable.d.ts +1 -1
  335. package/dest/transport/node/index.d.ts +1 -1
  336. package/dest/transport/node/node_connector.d.ts +1 -1
  337. package/dest/transport/node/node_connector.d.ts.map +1 -1
  338. package/dest/transport/node/node_connector_socket.d.ts +1 -1
  339. package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
  340. package/dest/transport/node/node_listener.d.ts +1 -1
  341. package/dest/transport/node/node_listener.d.ts.map +1 -1
  342. package/dest/transport/node/node_listener_socket.d.ts +1 -1
  343. package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
  344. package/dest/transport/transport_client.d.ts +1 -1
  345. package/dest/transport/transport_client.d.ts.map +1 -1
  346. package/dest/transport/transport_client.js +2 -2
  347. package/dest/transport/transport_server.d.ts +1 -10
  348. package/dest/transport/transport_server.d.ts.map +1 -1
  349. package/dest/trees/balanced_merkle_tree_root.d.ts +17 -0
  350. package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -0
  351. package/dest/trees/balanced_merkle_tree_root.js +51 -0
  352. package/dest/trees/hasher.d.ts +3 -1
  353. package/dest/trees/hasher.d.ts.map +1 -1
  354. package/dest/trees/hasher.js +10 -5
  355. package/dest/trees/index.d.ts +4 -3
  356. package/dest/trees/index.d.ts.map +1 -1
  357. package/dest/trees/index.js +3 -2
  358. package/dest/trees/indexed_merkle_tree.d.ts +1 -1
  359. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
  360. package/dest/trees/indexed_merkle_tree.js +1 -1
  361. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  362. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  363. package/dest/trees/indexed_tree_leaf.d.ts +1 -1
  364. package/dest/trees/membership_witness.d.ts +7 -18
  365. package/dest/trees/membership_witness.d.ts.map +1 -1
  366. package/dest/trees/membership_witness.js +10 -1
  367. package/dest/trees/merkle_tree.d.ts +1 -1
  368. package/dest/trees/merkle_tree.d.ts.map +1 -1
  369. package/dest/trees/merkle_tree_calculator.d.ts +2 -12
  370. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  371. package/dest/trees/merkle_tree_calculator.js +2 -32
  372. package/dest/trees/sibling_path.d.ts +5 -38
  373. package/dest/trees/sibling_path.d.ts.map +1 -1
  374. package/dest/trees/sibling_path.js +3 -3
  375. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +6 -6
  376. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
  377. package/dest/trees/unbalanced_merkle_tree_calculator.js +34 -42
  378. package/dest/trees/unbalanced_merkle_tree_root.d.ts +28 -0
  379. package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
  380. package/dest/trees/unbalanced_merkle_tree_root.js +84 -0
  381. package/dest/trees/unbalanced_tree_store.d.ts +5 -1
  382. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  383. package/dest/trees/unbalanced_tree_store.js +49 -1
  384. package/dest/types/index.d.ts +6 -2
  385. package/dest/types/index.d.ts.map +1 -1
  386. package/dest/types/index.js +6 -0
  387. package/dest/url/index.d.ts +1 -1
  388. package/dest/validation/index.d.ts +1 -1
  389. package/package.json +50 -9
  390. package/src/array/array.ts +0 -16
  391. package/src/array/index.ts +1 -0
  392. package/src/array/sorted_array.ts +138 -0
  393. package/src/branded-types/block_number.ts +117 -0
  394. package/src/branded-types/checkpoint_number.ts +115 -0
  395. package/src/branded-types/epoch.ts +88 -0
  396. package/src/branded-types/index.ts +7 -0
  397. package/src/branded-types/index_within_checkpoint.ts +88 -0
  398. package/src/branded-types/slot.ts +88 -0
  399. package/src/branded-types/types.ts +2 -0
  400. package/src/buffer/buffer16.ts +2 -2
  401. package/src/buffer/buffer32.ts +2 -2
  402. package/src/collection/array.ts +52 -0
  403. package/src/config/env_var.ts +82 -15
  404. package/src/config/index.ts +39 -6
  405. package/src/config/network_config.ts +2 -0
  406. package/src/config/network_name.ts +4 -1
  407. package/src/config/parse-env.ts +4 -0
  408. package/src/crypto/aes128/index.ts +2 -2
  409. package/src/crypto/bls/bn254_keystore.ts +1 -1
  410. package/src/crypto/bls/index.ts +1 -1
  411. package/src/crypto/bn254/index.ts +50 -156
  412. package/src/crypto/ecdsa/index.ts +4 -4
  413. package/src/crypto/ecdsa/signature.ts +2 -2
  414. package/src/crypto/grumpkin/index.ts +8 -6
  415. package/src/crypto/keys/index.ts +2 -2
  416. package/src/crypto/pedersen/pedersen.wasm.ts +4 -4
  417. package/src/crypto/poseidon/index.ts +14 -24
  418. package/src/crypto/random/randomness_singleton.ts +6 -4
  419. package/src/crypto/schnorr/index.ts +5 -4
  420. package/src/crypto/schnorr/signature.ts +2 -2
  421. package/src/crypto/secp256k1/index.ts +3 -3
  422. package/src/crypto/sha256/index.ts +1 -1
  423. package/src/crypto/sha512/index.ts +1 -1
  424. package/src/crypto/signature/index.ts +1 -1
  425. package/src/crypto/sync/index.ts +1 -1
  426. package/src/crypto/sync/pedersen/index.ts +1 -1
  427. package/src/crypto/sync/poseidon/index.ts +1 -10
  428. package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +6 -6
  429. package/src/curves/bls12/index.ts +2 -0
  430. package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +7 -7
  431. package/src/{fields/fields.ts → curves/bn254/field.ts} +53 -56
  432. package/src/curves/bn254/index.ts +2 -0
  433. package/src/curves/bn254/point.ts +170 -0
  434. package/src/curves/grumpkin/index.ts +11 -0
  435. package/src/{fields → curves/grumpkin}/point.ts +26 -7
  436. package/src/eth-address/index.ts +27 -2
  437. package/src/iterator/filter.ts +11 -0
  438. package/src/iterator/index.ts +1 -0
  439. package/src/jest/setup.mjs +31 -1
  440. package/src/json-rpc/client/safe_json_rpc_client.ts +2 -0
  441. package/src/json-rpc/client/undici.ts +21 -3
  442. package/src/json-rpc/server/api_key_auth.ts +63 -0
  443. package/src/json-rpc/server/index.ts +1 -0
  444. package/src/json-rpc/server/safe_json_rpc_server.ts +1 -1
  445. package/src/log/bigint-utils.ts +22 -0
  446. package/src/log/gcloud-logger-config.ts +5 -0
  447. package/src/log/libp2p_logger.ts +12 -5
  448. package/src/log/log-filters.ts +29 -11
  449. package/src/log/pino-logger-server.ts +25 -0
  450. package/src/log/pino-logger.ts +144 -39
  451. package/src/queue/base_memory_queue.ts +1 -1
  452. package/src/queue/semaphore.ts +5 -0
  453. package/src/retry/index.ts +18 -0
  454. package/src/schemas/schemas.ts +24 -13
  455. package/src/schemas/types.ts +33 -0
  456. package/src/schemas/utils.ts +21 -8
  457. package/src/serialize/buffer_reader.ts +36 -9
  458. package/src/serialize/field_reader.ts +1 -1
  459. package/src/serialize/free_funcs.ts +1 -1
  460. package/src/serialize/serialize.ts +33 -1
  461. package/src/sleep/index.ts +16 -1
  462. package/src/testing/files/index.ts +1 -1
  463. package/src/timer/date.ts +52 -0
  464. package/src/transport/transport_client.ts +2 -2
  465. package/src/trees/balanced_merkle_tree_root.ts +68 -0
  466. package/src/trees/hasher.ts +9 -0
  467. package/src/trees/index.ts +3 -2
  468. package/src/trees/indexed_merkle_tree.ts +1 -1
  469. package/src/trees/membership_witness.ts +9 -1
  470. package/src/trees/merkle_tree_calculator.ts +2 -35
  471. package/src/trees/sibling_path.ts +3 -3
  472. package/src/trees/unbalanced_merkle_tree_calculator.ts +32 -50
  473. package/src/trees/unbalanced_merkle_tree_root.ts +115 -0
  474. package/src/trees/unbalanced_tree_store.ts +57 -2
  475. package/src/types/index.ts +11 -1
  476. package/dest/crypto/bn254/bn254_utils.d.ts +0 -39
  477. package/dest/crypto/bn254/bn254_utils.d.ts.map +0 -1
  478. package/dest/crypto/bn254/bn254_utils.js +0 -56
  479. package/dest/crypto/index.d.ts +0 -17
  480. package/dest/crypto/index.d.ts.map +0 -1
  481. package/dest/crypto/index.js +0 -16
  482. package/dest/fields/bls12_fields.d.ts.map +0 -1
  483. package/dest/fields/bls12_point.d.ts.map +0 -1
  484. package/dest/fields/coordinate.d.ts +0 -66
  485. package/dest/fields/coordinate.d.ts.map +0 -1
  486. package/dest/fields/coordinate.js +0 -96
  487. package/dest/fields/fields.d.ts +0 -179
  488. package/dest/fields/fields.d.ts.map +0 -1
  489. package/dest/fields/index.d.ts +0 -6
  490. package/dest/fields/index.d.ts.map +0 -1
  491. package/dest/fields/index.js +0 -5
  492. package/dest/fields/point.d.ts.map +0 -1
  493. package/dest/index.d.ts +0 -30
  494. package/dest/index.d.ts.map +0 -1
  495. package/dest/index.js +0 -30
  496. package/dest/json-rpc/server/telemetry.d.ts +0 -2
  497. package/dest/json-rpc/server/telemetry.d.ts.map +0 -1
  498. package/dest/json-rpc/server/telemetry.js +0 -0
  499. package/dest/trees/unbalanced_merkle_tree.d.ts +0 -28
  500. package/dest/trees/unbalanced_merkle_tree.d.ts.map +0 -1
  501. package/dest/trees/unbalanced_merkle_tree.js +0 -99
  502. package/src/crypto/bn254/bn254_utils.ts +0 -64
  503. package/src/crypto/index.ts +0 -16
  504. package/src/fields/coordinate.ts +0 -104
  505. package/src/fields/index.ts +0 -5
  506. package/src/index.ts +0 -30
  507. package/src/json-rpc/server/telemetry.ts +0 -0
  508. package/src/trees/unbalanced_merkle_tree.ts +0 -111
@@ -1,5 +1,7 @@
1
1
  import { BarretenbergSync } from '@aztec/bb.js';
2
- import { Fr, type GrumpkinScalar, Point } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
4
+ import { Point } from '@aztec/foundation/curves/grumpkin';
3
5
 
4
6
  /**
5
7
  * Grumpkin elliptic curve operations.
@@ -20,7 +22,7 @@ export class Grumpkin {
20
22
  * @returns Result of the multiplication.
21
23
  */
22
24
  public static async mul(point: Point, scalar: GrumpkinScalar): Promise<Point> {
23
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
25
+ await BarretenbergSync.initSingleton();
24
26
  const api = BarretenbergSync.getSingleton();
25
27
  const response = api.grumpkinMul({
26
28
  point: { x: point.x.toBuffer(), y: point.y.toBuffer() },
@@ -36,7 +38,7 @@ export class Grumpkin {
36
38
  * @returns Result of the addition.
37
39
  */
38
40
  public static async add(a: Point, b: Point): Promise<Point> {
39
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
41
+ await BarretenbergSync.initSingleton();
40
42
  const api = BarretenbergSync.getSingleton();
41
43
  const response = api.grumpkinAdd({
42
44
  pointA: { x: a.x.toBuffer(), y: a.y.toBuffer() },
@@ -52,7 +54,7 @@ export class Grumpkin {
52
54
  * @returns Points multiplied by the scalar.
53
55
  */
54
56
  public static async batchMul(points: Point[], scalar: GrumpkinScalar) {
55
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
57
+ await BarretenbergSync.initSingleton();
56
58
  const api = BarretenbergSync.getSingleton();
57
59
  const response = api.grumpkinBatchMul({
58
60
  points: points.map(p => ({ x: p.x.toBuffer(), y: p.y.toBuffer() })),
@@ -67,7 +69,7 @@ export class Grumpkin {
67
69
  * @returns Random field element.
68
70
  */
69
71
  public static async getRandomFr(): Promise<Fr> {
70
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
72
+ await BarretenbergSync.initSingleton();
71
73
  const api = BarretenbergSync.getSingleton();
72
74
  const response = api.grumpkinGetRandomFr({ dummy: 0 });
73
75
  return Fr.fromBuffer(Buffer.from(response.value));
@@ -79,7 +81,7 @@ export class Grumpkin {
79
81
  * @returns Buffer representation of the field element.
80
82
  */
81
83
  public static async reduce512BufferToFr(uint512Buf: Buffer): Promise<Fr> {
82
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
84
+ await BarretenbergSync.initSingleton();
83
85
  const api = BarretenbergSync.getSingleton();
84
86
  const response = api.grumpkinReduce512({ input: uint512Buf });
85
87
  return Fr.fromBuffer(Buffer.from(response.value));
@@ -1,9 +1,9 @@
1
1
  import { BarretenbergSync } from '@aztec/bb.js';
2
2
 
3
- import { Fr } from '../../fields/fields.js';
3
+ import { Fr } from '../../curves/bn254/field.js';
4
4
 
5
5
  export async function vkAsFieldsMegaHonk(input: Buffer): Promise<Fr[]> {
6
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
6
+ await BarretenbergSync.initSingleton();
7
7
  const api = BarretenbergSync.getSingleton();
8
8
  const response = api.megaVkAsFields({ verificationKey: input });
9
9
  return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
@@ -1,6 +1,6 @@
1
1
  import { BarretenbergSync } from '@aztec/bb.js';
2
2
 
3
- import { Fr } from '../../fields/fields.js';
3
+ import { Fr } from '../../curves/bn254/field.js';
4
4
  import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
5
5
 
6
6
  /**
@@ -12,7 +12,7 @@ export async function pedersenCommit(input: Buffer[], offset = 0) {
12
12
  throw new Error('All Pedersen Commit input buffers must be <= 32 bytes.');
13
13
  }
14
14
  input = input.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i));
15
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
15
+ await BarretenbergSync.initSingleton();
16
16
  const api = BarretenbergSync.getSingleton();
17
17
  const response = api.pedersenCommit({
18
18
  inputs: input,
@@ -29,7 +29,7 @@ export async function pedersenCommit(input: Buffer[], offset = 0) {
29
29
  */
30
30
  export async function pedersenHash(input: Fieldable[], index = 0): Promise<Fr> {
31
31
  const inputFields = serializeToFields(input);
32
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
32
+ await BarretenbergSync.initSingleton();
33
33
  const api = BarretenbergSync.getSingleton();
34
34
  const response = api.pedersenHash({
35
35
  inputs: inputFields.map(i => i.toBuffer()),
@@ -42,7 +42,7 @@ export async function pedersenHash(input: Fieldable[], index = 0): Promise<Fr> {
42
42
  * Create a pedersen hash from an arbitrary length buffer.
43
43
  */
44
44
  export async function pedersenHashBuffer(input: Buffer, index = 0) {
45
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
45
+ await BarretenbergSync.initSingleton();
46
46
  const api = BarretenbergSync.getSingleton();
47
47
  const response = api.pedersenHashBuffer({
48
48
  input,
@@ -1,6 +1,6 @@
1
- import { BarretenbergSync } from '@aztec/bb.js';
1
+ import { Barretenberg } from '@aztec/bb.js';
2
2
 
3
- import { Fr } from '../../fields/fields.js';
3
+ import { Fr } from '../../curves/bn254/field.js';
4
4
  import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
5
5
 
6
6
  /**
@@ -10,9 +10,9 @@ import { type Fieldable, serializeToFields } from '../../serialize/serialize.js'
10
10
  */
11
11
  export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
12
12
  const inputFields = serializeToFields(input);
13
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
14
- const api = BarretenbergSync.getSingleton();
15
- const response = api.poseidon2Hash({
13
+ await Barretenberg.initSingleton();
14
+ const api = Barretenberg.getSingleton();
15
+ const response = await api.poseidon2Hash({
16
16
  inputs: inputFields.map(i => i.toBuffer()),
17
17
  });
18
18
  return Fr.fromBuffer(Buffer.from(response.hash));
@@ -27,19 +27,9 @@ export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
27
27
  export async function poseidon2HashWithSeparator(input: Fieldable[], separator: number): Promise<Fr> {
28
28
  const inputFields = serializeToFields(input);
29
29
  inputFields.unshift(new Fr(separator));
30
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
31
- const api = BarretenbergSync.getSingleton();
32
- const response = api.poseidon2Hash({
33
- inputs: inputFields.map(i => i.toBuffer()),
34
- });
35
- return Fr.fromBuffer(Buffer.from(response.hash));
36
- }
37
-
38
- export async function poseidon2HashAccumulate(input: Fieldable[]): Promise<Fr> {
39
- const inputFields = serializeToFields(input);
40
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
41
- const api = BarretenbergSync.getSingleton();
42
- const response = api.poseidon2HashAccumulate({
30
+ await Barretenberg.initSingleton();
31
+ const api = Barretenberg.getSingleton();
32
+ const response = await api.poseidon2Hash({
43
33
  inputs: inputFields.map(i => i.toBuffer()),
44
34
  });
45
35
  return Fr.fromBuffer(Buffer.from(response.hash));
@@ -54,9 +44,9 @@ export async function poseidon2Permutation(input: Fieldable[]): Promise<Fr[]> {
54
44
  const inputFields = serializeToFields(input);
55
45
  // We'd like this assertion but it's not possible to use it in the browser.
56
46
  // assert(input.length === 4, 'Input state must be of size 4');
57
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
58
- const api = BarretenbergSync.getSingleton();
59
- const response = api.poseidon2Permutation({
47
+ await Barretenberg.initSingleton();
48
+ const api = Barretenberg.getSingleton();
49
+ const response = await api.poseidon2Permutation({
60
50
  inputs: inputFields.map(i => i.toBuffer()),
61
51
  });
62
52
  // We'd like this assertion but it's not possible to use it in the browser.
@@ -75,9 +65,9 @@ export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
75
65
  inputFields.push(Fr.fromBuffer(fieldBytes));
76
66
  }
77
67
 
78
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
79
- const api = BarretenbergSync.getSingleton();
80
- const response = api.poseidon2Hash({
68
+ await Barretenberg.initSingleton();
69
+ const api = Barretenberg.getSingleton();
70
+ const response = await api.poseidon2Hash({
81
71
  inputs: inputFields.map(i => i.toBuffer()),
82
72
  });
83
73
 
@@ -1,4 +1,4 @@
1
- import { createLogger } from '../../log/pino-logger.js';
1
+ import { type Logger, type LoggerBindings, createLogger } from '../../log/pino-logger.js';
2
2
 
3
3
  /**
4
4
  * A number generator which is used as a source of randomness in the system. If the SEED env variable is set, the
@@ -12,11 +12,13 @@ export class RandomnessSingleton {
12
12
  private static instance: RandomnessSingleton;
13
13
 
14
14
  private counter = 0;
15
+ private log: Logger;
15
16
 
16
17
  private constructor(
17
18
  private readonly seed?: number,
18
- private readonly log = createLogger('foundation:randomness_singleton'),
19
+ bindings?: LoggerBindings,
19
20
  ) {
21
+ this.log = createLogger('foundation:randomness_singleton', bindings);
20
22
  if (seed !== undefined) {
21
23
  this.log.debug(`Using pseudo-randomness with seed: ${seed}`);
22
24
  this.counter = seed;
@@ -25,10 +27,10 @@ export class RandomnessSingleton {
25
27
  }
26
28
  }
27
29
 
28
- public static getInstance(): RandomnessSingleton {
30
+ public static getInstance(bindings?: LoggerBindings): RandomnessSingleton {
29
31
  if (!RandomnessSingleton.instance) {
30
32
  const seed = process.env.SEED ? Number(process.env.SEED) : undefined;
31
- RandomnessSingleton.instance = new RandomnessSingleton(seed);
33
+ RandomnessSingleton.instance = new RandomnessSingleton(seed, bindings);
32
34
  }
33
35
 
34
36
  return RandomnessSingleton.instance;
@@ -1,5 +1,6 @@
1
1
  import { BarretenbergSync } from '@aztec/bb.js';
2
- import { type GrumpkinScalar, Point } from '@aztec/foundation/fields';
2
+ import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
3
+ import { Point } from '@aztec/foundation/curves/grumpkin';
3
4
 
4
5
  import { SchnorrSignature } from './signature.js';
5
6
 
@@ -15,7 +16,7 @@ export class Schnorr {
15
16
  * @returns A grumpkin public key.
16
17
  */
17
18
  public async computePublicKey(privateKey: GrumpkinScalar): Promise<Point> {
18
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
19
+ await BarretenbergSync.initSingleton();
19
20
  const api = BarretenbergSync.getSingleton();
20
21
  const response = api.schnorrComputePublicKey({ privateKey: privateKey.toBuffer() });
21
22
  return Point.fromBuffer(Buffer.concat([Buffer.from(response.publicKey.x), Buffer.from(response.publicKey.y)]));
@@ -28,7 +29,7 @@ export class Schnorr {
28
29
  * @returns A Schnorr signature of the form (s, e).
29
30
  */
30
31
  public async constructSignature(msg: Uint8Array, privateKey: GrumpkinScalar) {
31
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
32
+ await BarretenbergSync.initSingleton();
32
33
  const api = BarretenbergSync.getSingleton();
33
34
  const response = api.schnorrConstructSignature({
34
35
  message: msg,
@@ -45,7 +46,7 @@ export class Schnorr {
45
46
  * @returns True or false.
46
47
  */
47
48
  public async verifySignature(msg: Uint8Array, pubKey: Point, sig: SchnorrSignature) {
48
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
49
+ await BarretenbergSync.initSingleton();
49
50
  const api = BarretenbergSync.getSingleton();
50
51
  const response = api.schnorrVerifySignature({
51
52
  message: msg,
@@ -1,5 +1,5 @@
1
- import { randomBytes } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
1
+ import { randomBytes } from '@aztec/foundation/crypto/random';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { BufferReader, mapTuple } from '@aztec/foundation/serialize';
4
4
 
5
5
  import type { Signature } from '../signature/index.js';
@@ -27,7 +27,7 @@ export class Secp256k1 {
27
27
  * @returns Result of the multiplication.
28
28
  */
29
29
  public async mul(point: Uint8Array, scalar: Uint8Array) {
30
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
30
+ await BarretenbergSync.initSingleton();
31
31
  const api = BarretenbergSync.getSingleton();
32
32
  const response = api.secp256k1Mul({
33
33
  point: { x: point.subarray(0, 32), y: point.subarray(32, 64) },
@@ -41,7 +41,7 @@ export class Secp256k1 {
41
41
  * @returns Random field element.
42
42
  */
43
43
  public async getRandomFr() {
44
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
44
+ await BarretenbergSync.initSingleton();
45
45
  const api = BarretenbergSync.getSingleton();
46
46
  const response = api.secp256k1GetRandomFr({ dummy: 0 });
47
47
  return Buffer.from(response.value);
@@ -53,7 +53,7 @@ export class Secp256k1 {
53
53
  * @returns Buffer representation of the field element.
54
54
  */
55
55
  public async reduce512BufferToFr(uint512Buf: Buffer) {
56
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
56
+ await BarretenbergSync.initSingleton();
57
57
  const api = BarretenbergSync.getSingleton();
58
58
  const response = api.secp256k1Reduce512({ input: uint512Buf });
59
59
  return Buffer.from(response.value);
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable camelcase */
2
2
  import { default as hash } from 'hash.js';
3
3
 
4
- import { Fr } from '../../fields/fields.js';
4
+ import { Fr } from '../../curves/bn254/field.js';
5
5
  import { truncateAndPad } from '../../serialize/free_funcs.js';
6
6
  import { type Bufferable, serializeToBuffer } from '../../serialize/serialize.js';
7
7
  import type { Hasher } from '../../trees/hasher.js';
@@ -1,6 +1,6 @@
1
1
  import { default as hash } from 'hash.js';
2
2
 
3
- import { GrumpkinScalar } from '../../fields/fields.js';
3
+ import { GrumpkinScalar } from '../../curves/grumpkin/index.js';
4
4
  import { type Bufferable, serializeToBuffer } from '../../serialize/serialize.js';
5
5
 
6
6
  export const sha512 = (data: Buffer) => Buffer.from(hash.sha512().update(data).digest());
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  /**
4
4
  * Interface to represent a signature.
@@ -3,4 +3,4 @@ import { BarretenbergSync } from '@aztec/bb.js';
3
3
  export * from './poseidon/index.js';
4
4
  export * from './pedersen/index.js';
5
5
 
6
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
6
+ await BarretenbergSync.initSingleton();
@@ -1,6 +1,6 @@
1
1
  import { BarretenbergSync } from '@aztec/bb.js';
2
2
 
3
- import { Fr } from '../../../fields/fields.js';
3
+ import { Fr } from '../../../curves/bn254/field.js';
4
4
  import { type Fieldable, serializeToFields } from '../../../serialize/serialize.js';
5
5
 
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import { BarretenbergSync } from '@aztec/bb.js';
2
2
 
3
- import { Fr } from '../../../fields/fields.js';
3
+ import { Fr } from '../../../curves/bn254/field.js';
4
4
  import { type Fieldable, serializeToFields } from '../../../serialize/serialize.js';
5
5
 
6
6
  /**
@@ -34,15 +34,6 @@ export function poseidon2HashWithSeparator(input: Fieldable[], separator: number
34
34
  return Fr.fromBuffer(Buffer.from(response.hash));
35
35
  }
36
36
 
37
- export function poseidon2HashAccumulate(input: Fieldable[]): Fr {
38
- const inputFields = serializeToFields(input);
39
- const api = BarretenbergSync.getSingleton();
40
- const response = api.poseidon2HashAccumulate({
41
- inputs: inputFields.map(i => i.toBuffer()),
42
- });
43
- return Fr.fromBuffer(Buffer.from(response.hash));
44
- }
45
-
46
37
  /**
47
38
  * Runs a Poseidon2 permutation.
48
39
  * @param input the input state. Expected to be of size 4.
@@ -2,12 +2,12 @@
2
2
  import { bls12_381 } from '@noble/curves/bls12-381';
3
3
  import { inspect } from 'util';
4
4
 
5
- import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
6
- import { randomBytes } from '../crypto/random/index.js';
7
- import { hexSchemaFor } from '../schemas/utils.js';
8
- import { BufferReader } from '../serialize/buffer_reader.js';
9
- import { TypeRegistry } from '../serialize/type_registry.js';
10
- import { Fr } from './fields.js';
5
+ import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js';
6
+ import { randomBytes } from '../../crypto/random/index.js';
7
+ import { hexSchemaFor } from '../../schemas/utils.js';
8
+ import { BufferReader } from '../../serialize/buffer_reader.js';
9
+ import { TypeRegistry } from '../../serialize/type_registry.js';
10
+ import { Fr } from '../bn254/field.js';
11
11
 
12
12
  /**
13
13
  * Represents a field derived from BLS12Field.
@@ -0,0 +1,2 @@
1
+ export * from './field.js';
2
+ export * from './point.js';
@@ -3,13 +3,13 @@ import type { ProjPointType } from '@noble/curves/abstract/weierstrass';
3
3
  import { bls12_381 } from '@noble/curves/bls12-381';
4
4
  import { inspect } from 'util';
5
5
 
6
- import { toBufferBE } from '../bigint-buffer/index.js';
7
- import { randomBoolean } from '../crypto/random/index.js';
8
- import { hexSchemaFor } from '../schemas/utils.js';
9
- import { BufferReader, serializeToBuffer } from '../serialize/index.js';
10
- import { bufferToHex, hexToBuffer } from '../string/index.js';
11
- import { BLS12Fq, BLS12Fr } from './bls12_fields.js';
12
- import { Fr } from './fields.js';
6
+ import { toBufferBE } from '../../bigint-buffer/index.js';
7
+ import { randomBoolean } from '../../crypto/random/index.js';
8
+ import { hexSchemaFor } from '../../schemas/utils.js';
9
+ import { BufferReader, serializeToBuffer } from '../../serialize/index.js';
10
+ import { bufferToHex, hexToBuffer } from '../../string/index.js';
11
+ import { Fr } from '../bn254/field.js';
12
+ import { BLS12Fq, BLS12Fr } from './field.js';
13
13
 
14
14
  /**
15
15
  * Represents a Point on an elliptic curve with x and y coordinates.
@@ -2,13 +2,11 @@ import { BarretenbergSync } from '@aztec/bb.js';
2
2
 
3
3
  import { inspect } from 'util';
4
4
 
5
- import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
6
- import { randomBytes } from '../crypto/random/index.js';
7
- import { hexSchemaFor } from '../schemas/utils.js';
8
- import { BufferReader } from '../serialize/buffer_reader.js';
9
- import { TypeRegistry } from '../serialize/type_registry.js';
10
-
11
- const ZERO_BUFFER = Buffer.alloc(32);
5
+ import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js';
6
+ import { randomBytes } from '../../crypto/random/index.js';
7
+ import { hexSchemaFor } from '../../schemas/utils.js';
8
+ import { BufferReader } from '../../serialize/buffer_reader.js';
9
+ import { TypeRegistry } from '../../serialize/type_registry.js';
12
10
 
13
11
  /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
14
12
 
@@ -25,14 +23,12 @@ type DerivedField<T extends BaseField> = {
25
23
 
26
24
  /**
27
25
  * Base field class.
28
- * Conversions from Buffer to BigInt and vice-versa are not cheap.
29
- * We allow construction with either form and lazily convert to other as needed.
30
- * We only check we are within the field modulus when initializing with bigint.
26
+ * Uses bigint as the internal representation.
27
+ * Buffers are generated on demand from the bigint value.
31
28
  */
32
29
  abstract class BaseField {
33
30
  static SIZE_IN_BYTES = 32;
34
- private asBuffer?: Buffer;
35
- private asBigInt?: bigint;
31
+ private readonly asBigInt: bigint;
36
32
 
37
33
  /**
38
34
  * Return bigint representation.
@@ -52,53 +48,41 @@ abstract class BaseField {
52
48
  if (value.length > BaseField.SIZE_IN_BYTES) {
53
49
  throw new Error(`Value length ${value.length} exceeds ${BaseField.SIZE_IN_BYTES}`);
54
50
  }
55
- this.asBuffer =
56
- value.length === BaseField.SIZE_IN_BYTES
57
- ? value
58
- : Buffer.concat([Buffer.alloc(BaseField.SIZE_IN_BYTES - value.length), value]);
51
+ this.asBigInt = toBigIntBE(value);
59
52
  } else if (typeof value === 'bigint' || typeof value === 'number' || typeof value === 'boolean') {
60
53
  this.asBigInt = BigInt(value);
61
- if (this.asBigInt >= this.modulus()) {
62
- throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
63
- } else if (this.asBigInt < 0n) {
64
- throw new Error(`Value 0x${this.asBigInt.toString(16)} is negative.`);
65
- }
66
54
  } else if (value instanceof BaseField) {
67
- this.asBuffer = value.asBuffer;
68
55
  this.asBigInt = value.asBigInt;
69
56
  } else {
70
57
  throw new Error(`Type '${typeof value}' with value '${value}' passed to BaseField ctor.`);
71
58
  }
59
+
60
+ if (this.asBigInt < 0n) {
61
+ throw new Error(`Value 0x${this.asBigInt.toString(16)} is negative.`);
62
+ } else if (this.asBigInt >= this.modulus()) {
63
+ throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
64
+ }
72
65
  }
73
66
 
74
67
  protected abstract modulus(): bigint;
75
68
 
76
69
  /**
77
- * We return a copy of the Buffer to ensure this remains immutable.
70
+ * Converts the bigint to a Buffer.
78
71
  */
79
72
  toBuffer(): Buffer {
80
- if (!this.asBuffer) {
81
- this.asBuffer = toBufferBE(this.asBigInt!, 32);
82
- }
83
- return Buffer.from(this.asBuffer);
73
+ return toBufferBE(this.asBigInt, 32);
84
74
  }
85
75
 
86
76
  toString(): `0x${string}` {
87
- return `0x${this.toBuffer().toString('hex')}`;
77
+ return `0x${this.asBigInt.toString(16).padStart(64, '0')}`;
88
78
  }
89
79
 
90
80
  toBigInt(): bigint {
91
- if (this.asBigInt === undefined) {
92
- this.asBigInt = toBigIntBE(this.asBuffer!);
93
- if (this.asBigInt >= this.modulus()) {
94
- throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
95
- }
96
- }
97
81
  return this.asBigInt;
98
82
  }
99
83
 
100
84
  toBool(): boolean {
101
- return Boolean(this.toBigInt());
85
+ return this.asBigInt !== 0n;
102
86
  }
103
87
 
104
88
  /**
@@ -106,11 +90,10 @@ abstract class BaseField {
106
90
  * Throws if the underlying value is greater than MAX_SAFE_INTEGER.
107
91
  */
108
92
  toNumber(): number {
109
- const value = this.toBigInt();
110
- if (value > Number.MAX_SAFE_INTEGER) {
111
- throw new Error(`Value ${value.toString(16)} greater than than max safe integer`);
93
+ if (this.asBigInt > Number.MAX_SAFE_INTEGER) {
94
+ throw new Error(`Value ${this.asBigInt.toString(16)} greater than than max safe integer`);
112
95
  }
113
- return Number(value);
96
+ return Number(this.asBigInt);
114
97
  }
115
98
 
116
99
  /**
@@ -118,8 +101,7 @@ abstract class BaseField {
118
101
  * May cause loss of precision if the underlying value is greater than MAX_SAFE_INTEGER.
119
102
  */
120
103
  toNumberUnsafe(): number {
121
- const value = this.toBigInt();
122
- return Number(value);
104
+ return Number(this.asBigInt);
123
105
  }
124
106
 
125
107
  toShortString(): string {
@@ -128,21 +110,28 @@ abstract class BaseField {
128
110
  }
129
111
 
130
112
  equals(rhs: BaseField): boolean {
131
- return this.toBuffer().equals(rhs.toBuffer());
113
+ return this.asBigInt === rhs.asBigInt;
132
114
  }
133
115
 
134
116
  lt(rhs: BaseField): boolean {
135
- return this.toBigInt() < rhs.toBigInt();
117
+ return this.asBigInt < rhs.asBigInt;
136
118
  }
137
119
 
138
120
  cmp(rhs: BaseField): -1 | 0 | 1 {
139
- const lhsBigInt = this.toBigInt();
140
- const rhsBigInt = rhs.toBigInt();
141
- return lhsBigInt === rhsBigInt ? 0 : lhsBigInt < rhsBigInt ? -1 : 1;
121
+ return BaseField.cmpAsBigInt(this.asBigInt, rhs.asBigInt);
122
+ }
123
+
124
+ static cmp(lhs: BaseField, rhs: BaseField): -1 | 0 | 1 {
125
+ return lhs.cmp(rhs);
126
+ }
127
+
128
+ // Actual bigint comparison. Arguments must have been validated previously.
129
+ static cmpAsBigInt(lhs: bigint, rhs: bigint): -1 | 0 | 1 {
130
+ return lhs === rhs ? 0 : lhs < rhs ? -1 : 1;
142
131
  }
143
132
 
144
133
  isZero(): boolean {
145
- return this.toBuffer().equals(ZERO_BUFFER);
134
+ return this.asBigInt === 0n;
146
135
  }
147
136
 
148
137
  isEmpty(): boolean {
@@ -195,7 +184,7 @@ function fromHexString<T extends BaseField>(buf: string, f: DerivedField<T>) {
195
184
 
196
185
  const buffer = Buffer.from(checked.length % 2 === 1 ? '0' + checked : checked, 'hex');
197
186
 
198
- return new f(buffer);
187
+ return new f(toBigIntBE(buffer));
199
188
  }
200
189
 
201
190
  /** Branding to ensure fields are not interchangeable types. */
@@ -335,7 +324,23 @@ export class Fr extends BaseField {
335
324
  return this.toString();
336
325
  }
337
326
 
327
+ /**
328
+ * Creates an Fr instance from a plain object without Zod validation.
329
+ * This method is optimized for performance and skips validation, making it suitable
330
+ * for deserializing trusted data (e.g., from C++ via MessagePack).
331
+ * Handles buffers, strings, numbers, bigints, or existing instances.
332
+ * @param obj - Plain object, buffer, string, number, bigint, boolean, or Fr instance
333
+ * @returns An Fr instance
334
+ */
335
+ static fromPlainObject(obj: any): Fr {
336
+ if (obj instanceof Fr) {
337
+ return obj;
338
+ }
339
+ return new Fr(obj);
340
+ }
341
+
338
342
  static get schema() {
343
+ // Serialization from hex string.
339
344
  return hexSchemaFor(Fr);
340
345
  }
341
346
  }
@@ -495,14 +500,6 @@ function extendedEuclidean(a: bigint, modulus: bigint): [bigint, bigint, bigint]
495
500
  }
496
501
  }
497
502
 
498
- /**
499
- * GrumpkinScalar is an Fq.
500
- * @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
501
- * the Aztec Protocol Specs.
502
- */
503
- export type GrumpkinScalar = Fq;
504
- export const GrumpkinScalar = Fq;
505
-
506
503
  /** Wraps a function that returns a buffer so that all results are reduced into a field of the given type. */
507
504
  export function reduceFn<TInput, TField extends BaseField>(fn: (input: TInput) => Buffer, field: DerivedField<TField>) {
508
505
  return (input: TInput) => fromBufferReduce(fn(input), field);
@@ -0,0 +1,2 @@
1
+ export * from './field.js';
2
+ export * from './point.js';