@aztec/foundation 3.0.0-canary.a9708bd → 3.0.0-devnet.20251212

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 (451) 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 +5 -1
  39. package/dest/collection/object.d.ts.map +1 -1
  40. package/dest/collection/object.js +6 -0
  41. package/dest/committable/committable.d.ts +1 -1
  42. package/dest/committable/committable.d.ts.map +1 -1
  43. package/dest/committable/index.d.ts +1 -1
  44. package/dest/config/env_var.d.ts +2 -2
  45. package/dest/config/env_var.d.ts.map +1 -1
  46. package/dest/config/index.d.ts +12 -2
  47. package/dest/config/index.d.ts.map +1 -1
  48. package/dest/config/index.js +18 -3
  49. package/dest/config/network_config.d.ts +42 -0
  50. package/dest/config/network_config.d.ts.map +1 -0
  51. package/dest/config/network_config.js +9 -0
  52. package/dest/config/network_name.d.ts +2 -2
  53. package/dest/config/network_name.d.ts.map +1 -1
  54. package/dest/config/network_name.js +10 -2
  55. package/dest/config/secret_value.d.ts +1 -1
  56. package/dest/config/secret_value.d.ts.map +1 -1
  57. package/dest/crypto/aes128/index.d.ts +1 -1
  58. package/dest/crypto/aes128/index.d.ts.map +1 -1
  59. package/dest/crypto/aes128/index.js +19 -6
  60. package/dest/crypto/bls/bn254_keystore.d.ts +296 -0
  61. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -0
  62. package/dest/crypto/bls/bn254_keystore.js +218 -0
  63. package/dest/crypto/bls/index.d.ts +13 -0
  64. package/dest/crypto/bls/index.d.ts.map +1 -0
  65. package/dest/crypto/bls/index.js +87 -0
  66. package/dest/crypto/bn254/index.d.ts +39 -0
  67. package/dest/crypto/bn254/index.d.ts.map +1 -0
  68. package/dest/crypto/bn254/index.js +56 -0
  69. package/dest/crypto/ecdsa/index.d.ts +1 -1
  70. package/dest/crypto/ecdsa/index.d.ts.map +1 -1
  71. package/dest/crypto/ecdsa/index.js +58 -48
  72. package/dest/crypto/ecdsa/signature.d.ts +2 -11
  73. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  74. package/dest/crypto/ecdsa/signature.js +2 -2
  75. package/dest/crypto/grumpkin/index.d.ts +10 -13
  76. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  77. package/dest/crypto/grumpkin/index.js +61 -55
  78. package/dest/crypto/keccak/index.d.ts +1 -1
  79. package/dest/crypto/keys/index.d.ts +2 -2
  80. package/dest/crypto/keys/index.d.ts.map +1 -1
  81. package/dest/crypto/keys/index.js +8 -5
  82. package/dest/crypto/pedersen/index.d.ts +1 -1
  83. package/dest/crypto/pedersen/pedersen.noble.d.ts +1 -1
  84. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
  85. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  86. package/dest/crypto/pedersen/pedersen.wasm.js +24 -14
  87. package/dest/crypto/poseidon/index.d.ts +2 -2
  88. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  89. package/dest/crypto/poseidon/index.js +33 -18
  90. package/dest/crypto/random/index.d.ts +1 -1
  91. package/dest/crypto/random/index.d.ts.map +1 -1
  92. package/dest/crypto/random/randomness_singleton.d.ts +1 -1
  93. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  94. package/dest/crypto/schnorr/index.d.ts +3 -2
  95. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  96. package/dest/crypto/schnorr/index.js +30 -38
  97. package/dest/crypto/schnorr/signature.d.ts +2 -2
  98. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  99. package/dest/crypto/schnorr/signature.js +2 -2
  100. package/dest/crypto/secp256k1/index.d.ts +1 -1
  101. package/dest/crypto/secp256k1/index.d.ts.map +1 -1
  102. package/dest/crypto/secp256k1/index.js +23 -18
  103. package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
  104. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
  105. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
  106. package/dest/crypto/secp256k1-signer/utils.d.ts +49 -3
  107. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  108. package/dest/crypto/secp256k1-signer/utils.js +87 -5
  109. package/dest/crypto/serialize.d.ts +1 -1
  110. package/dest/crypto/sha256/index.d.ts +2 -2
  111. package/dest/crypto/sha256/index.d.ts.map +1 -1
  112. package/dest/crypto/sha256/index.js +1 -1
  113. package/dest/crypto/sha512/index.d.ts +3 -3
  114. package/dest/crypto/sha512/index.d.ts.map +1 -1
  115. package/dest/crypto/sha512/index.js +1 -1
  116. package/dest/crypto/signature/index.d.ts +2 -2
  117. package/dest/crypto/signature/index.d.ts.map +1 -1
  118. package/dest/crypto/sync/index.d.ts +1 -1
  119. package/dest/crypto/sync/index.js +1 -1
  120. package/dest/crypto/sync/pedersen/index.d.ts +2 -2
  121. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  122. package/dest/crypto/sync/pedersen/index.js +18 -11
  123. package/dest/crypto/sync/poseidon/index.d.ts +2 -2
  124. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  125. package/dest/crypto/sync/poseidon/index.js +28 -13
  126. package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
  127. package/dest/curves/bls12/field.d.ts.map +1 -0
  128. package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +6 -6
  129. package/dest/curves/bls12/index.d.ts +3 -0
  130. package/dest/curves/bls12/index.d.ts.map +1 -0
  131. package/dest/curves/bls12/index.js +2 -0
  132. package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +11 -20
  133. package/dest/curves/bls12/point.d.ts.map +1 -0
  134. package/dest/{fields/bls12_point.js → curves/bls12/point.js} +14 -14
  135. package/dest/{fields/fields.d.ts → curves/bn254/field.d.ts} +16 -9
  136. package/dest/curves/bn254/field.d.ts.map +1 -0
  137. package/dest/{fields/fields.js → curves/bn254/field.js} +41 -16
  138. package/dest/curves/bn254/index.d.ts +3 -0
  139. package/dest/curves/bn254/index.d.ts.map +1 -0
  140. package/dest/curves/bn254/index.js +2 -0
  141. package/dest/curves/bn254/point.d.ts +54 -0
  142. package/dest/curves/bn254/point.d.ts.map +1 -0
  143. package/dest/curves/bn254/point.js +143 -0
  144. package/dest/curves/grumpkin/index.d.ts +10 -0
  145. package/dest/curves/grumpkin/index.d.ts.map +1 -0
  146. package/dest/curves/grumpkin/index.js +3 -0
  147. package/dest/{fields → curves/grumpkin}/point.d.ts +13 -13
  148. package/dest/curves/grumpkin/point.d.ts.map +1 -0
  149. package/dest/{fields → curves/grumpkin}/point.js +24 -7
  150. package/dest/decorators/index.d.ts +1 -1
  151. package/dest/decorators/memoize.d.ts +1 -1
  152. package/dest/decorators/memoize.d.ts.map +1 -1
  153. package/dest/error/index.d.ts +4 -4
  154. package/dest/error/index.d.ts.map +1 -1
  155. package/dest/eth-address/index.d.ts +14 -4
  156. package/dest/eth-address/index.d.ts.map +1 -1
  157. package/dest/eth-address/index.js +23 -1
  158. package/dest/eth-signature/eth_signature.d.ts +1 -4
  159. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  160. package/dest/eth-signature/eth_signature.js +2 -4
  161. package/dest/eth-signature/index.d.ts +1 -1
  162. package/dest/fs/index.d.ts +1 -1
  163. package/dest/fs/run_in_dir.d.ts +1 -1
  164. package/dest/fs/try_rm_dir.d.ts +1 -1
  165. package/dest/iterable/all.d.ts +1 -1
  166. package/dest/iterable/filter.d.ts +1 -1
  167. package/dest/iterable/index.d.ts +1 -1
  168. package/dest/iterable/isAsyncIt.d.ts +1 -1
  169. package/dest/iterable/map.d.ts +1 -1
  170. package/dest/iterable/peek.d.ts +1 -1
  171. package/dest/iterable/sort.d.ts +1 -1
  172. package/dest/iterable/take.d.ts +1 -1
  173. package/dest/iterable/toArray.d.ts +1 -1
  174. package/dest/json-rpc/client/fetch.d.ts +1 -1
  175. package/dest/json-rpc/client/index.d.ts +1 -1
  176. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
  177. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  178. package/dest/json-rpc/client/safe_json_rpc_client.js +9 -0
  179. package/dest/json-rpc/client/undici.d.ts +1 -1
  180. package/dest/json-rpc/convert.d.ts +1 -1
  181. package/dest/json-rpc/errors.d.ts +1 -1
  182. package/dest/json-rpc/errors.d.ts.map +1 -1
  183. package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
  184. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  185. package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
  186. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  187. package/dest/json-rpc/fixtures/test_state.d.ts +1 -1
  188. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
  189. package/dest/json-rpc/index.d.ts +1 -1
  190. package/dest/json-rpc/js_utils.d.ts +1 -1
  191. package/dest/json-rpc/js_utils.d.ts.map +1 -1
  192. package/dest/json-rpc/server/index.d.ts +1 -1
  193. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
  194. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  195. package/dest/json-rpc/server/telemetry.d.ts +1 -1
  196. package/dest/json-rpc/test/index.d.ts +1 -1
  197. package/dest/json-rpc/test/integration.d.ts +1 -1
  198. package/dest/log/console.d.ts +1 -1
  199. package/dest/log/gcloud-logger-config.d.ts +1 -1
  200. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  201. package/dest/log/index.d.ts +1 -1
  202. package/dest/log/libp2p_logger.d.ts +1 -1
  203. package/dest/log/log-filters.d.ts +1 -1
  204. package/dest/log/log-levels.d.ts +1 -1
  205. package/dest/log/log_fn.d.ts +2 -2
  206. package/dest/log/log_fn.d.ts.map +1 -1
  207. package/dest/log/noir_debug_log_util.d.ts +1 -1
  208. package/dest/log/pino-logger.d.ts +2 -2
  209. package/dest/log/pino-logger.d.ts.map +1 -1
  210. package/dest/log/pino-logger.js +0 -1
  211. package/dest/message/index.d.ts +1 -1
  212. package/dest/message/index.d.ts.map +1 -1
  213. package/dest/mutex/index.d.ts +1 -1
  214. package/dest/mutex/index.d.ts.map +1 -1
  215. package/dest/mutex/mutex_database.d.ts +1 -1
  216. package/dest/noir/index.d.ts +1 -1
  217. package/dest/noir/noir_package_config.d.ts +9 -9
  218. package/dest/number/index.d.ts +1 -1
  219. package/dest/profiler/index.d.ts +2 -0
  220. package/dest/profiler/index.d.ts.map +1 -0
  221. package/dest/profiler/index.js +1 -0
  222. package/dest/profiler/profiler.d.ts +8 -0
  223. package/dest/profiler/profiler.d.ts.map +1 -0
  224. package/dest/profiler/profiler.js +97 -0
  225. package/dest/promise/index.d.ts +1 -1
  226. package/dest/promise/running-promise.d.ts +1 -1
  227. package/dest/promise/running-promise.d.ts.map +1 -1
  228. package/dest/promise/utils.d.ts +1 -1
  229. package/dest/queue/base_memory_queue.d.ts +1 -1
  230. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  231. package/dest/queue/batch_queue.d.ts +1 -1
  232. package/dest/queue/batch_queue.d.ts.map +1 -1
  233. package/dest/queue/bounded_serial_queue.d.ts +1 -1
  234. package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
  235. package/dest/queue/fifo_memory_queue.d.ts +1 -1
  236. package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
  237. package/dest/queue/index.d.ts +1 -1
  238. package/dest/queue/priority_memory_queue.d.ts +1 -1
  239. package/dest/queue/priority_memory_queue.d.ts.map +1 -1
  240. package/dest/queue/priority_queue.d.ts +1 -1
  241. package/dest/queue/priority_queue.d.ts.map +1 -1
  242. package/dest/queue/semaphore.d.ts +1 -1
  243. package/dest/queue/semaphore.d.ts.map +1 -1
  244. package/dest/queue/serial_queue.d.ts +1 -1
  245. package/dest/queue/serial_queue.d.ts.map +1 -1
  246. package/dest/retry/index.d.ts +1 -1
  247. package/dest/running-promise/index.d.ts +1 -1
  248. package/dest/schemas/api.d.ts +1 -1
  249. package/dest/schemas/index.d.ts +1 -1
  250. package/dest/schemas/parse.d.ts +1 -1
  251. package/dest/schemas/schemas.d.ts +13 -17
  252. package/dest/schemas/schemas.d.ts.map +1 -1
  253. package/dest/schemas/schemas.js +9 -10
  254. package/dest/schemas/types.d.ts +1 -1
  255. package/dest/schemas/utils.d.ts +4 -4
  256. package/dest/schemas/utils.d.ts.map +1 -1
  257. package/dest/schemas/utils.js +15 -5
  258. package/dest/serialize/buffer_reader.d.ts +3 -1
  259. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  260. package/dest/serialize/buffer_reader.js +3 -0
  261. package/dest/serialize/field_reader.d.ts +2 -2
  262. package/dest/serialize/field_reader.d.ts.map +1 -1
  263. package/dest/serialize/field_reader.js +1 -1
  264. package/dest/serialize/free_funcs.d.ts +2 -2
  265. package/dest/serialize/free_funcs.d.ts.map +1 -1
  266. package/dest/serialize/free_funcs.js +1 -1
  267. package/dest/serialize/index.d.ts +1 -1
  268. package/dest/serialize/serialize.d.ts +2 -2
  269. package/dest/serialize/serialize.d.ts.map +1 -1
  270. package/dest/serialize/serialize.js +1 -1
  271. package/dest/serialize/type_registry.d.ts +1 -1
  272. package/dest/serialize/type_registry.d.ts.map +1 -1
  273. package/dest/serialize/types.d.ts +1 -1
  274. package/dest/sleep/index.d.ts +1 -1
  275. package/dest/sleep/index.d.ts.map +1 -1
  276. package/dest/string/index.d.ts +5 -1
  277. package/dest/string/index.d.ts.map +1 -1
  278. package/dest/string/index.js +19 -2
  279. package/dest/testing/files/index.d.ts +2 -1
  280. package/dest/testing/files/index.d.ts.map +1 -1
  281. package/dest/testing/files/index.js +1 -1
  282. package/dest/testing/formatting.d.ts +4 -0
  283. package/dest/testing/formatting.d.ts.map +1 -0
  284. package/dest/testing/formatting.js +3 -0
  285. package/dest/testing/index.d.ts +2 -1
  286. package/dest/testing/index.d.ts.map +1 -1
  287. package/dest/testing/index.js +1 -0
  288. package/dest/testing/port_allocator.d.ts +1 -1
  289. package/dest/testing/snapshot_serializer.d.ts +1 -1
  290. package/dest/testing/test_data.d.ts +1 -1
  291. package/dest/timer/date.d.ts +1 -1
  292. package/dest/timer/date.d.ts.map +1 -1
  293. package/dest/timer/elapsed.d.ts +1 -1
  294. package/dest/timer/index.d.ts +2 -2
  295. package/dest/timer/index.d.ts.map +1 -1
  296. package/dest/timer/index.js +1 -1
  297. package/dest/timer/timeout.d.ts +3 -1
  298. package/dest/timer/timeout.d.ts.map +1 -1
  299. package/dest/timer/timeout.js +9 -0
  300. package/dest/timer/timer.d.ts +1 -1
  301. package/dest/timer/timer.d.ts.map +1 -1
  302. package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
  303. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  304. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +1 -1
  305. package/dest/transport/dispatch/messages.d.ts +1 -1
  306. package/dest/transport/index.d.ts +1 -1
  307. package/dest/transport/interface/connector.d.ts +1 -1
  308. package/dest/transport/interface/listener.d.ts +1 -1
  309. package/dest/transport/interface/socket.d.ts +1 -1
  310. package/dest/transport/interface/transferable.d.ts +1 -1
  311. package/dest/transport/node/index.d.ts +1 -1
  312. package/dest/transport/node/node_connector.d.ts +1 -1
  313. package/dest/transport/node/node_connector.d.ts.map +1 -1
  314. package/dest/transport/node/node_connector_socket.d.ts +1 -1
  315. package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
  316. package/dest/transport/node/node_listener.d.ts +1 -1
  317. package/dest/transport/node/node_listener.d.ts.map +1 -1
  318. package/dest/transport/node/node_listener_socket.d.ts +1 -1
  319. package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
  320. package/dest/transport/transport_client.d.ts +1 -1
  321. package/dest/transport/transport_client.d.ts.map +1 -1
  322. package/dest/transport/transport_server.d.ts +1 -10
  323. package/dest/transport/transport_server.d.ts.map +1 -1
  324. package/dest/trees/balanced_merkle_tree.d.ts +22 -0
  325. package/dest/trees/balanced_merkle_tree.d.ts.map +1 -0
  326. package/dest/trees/balanced_merkle_tree.js +66 -0
  327. package/dest/trees/hasher.d.ts +1 -1
  328. package/dest/trees/index.d.ts +2 -1
  329. package/dest/trees/index.d.ts.map +1 -1
  330. package/dest/trees/index.js +1 -0
  331. package/dest/trees/indexed_merkle_tree.d.ts +1 -1
  332. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
  333. package/dest/trees/indexed_merkle_tree.js +1 -1
  334. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  335. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  336. package/dest/trees/indexed_tree_leaf.d.ts +1 -1
  337. package/dest/trees/membership_witness.d.ts +3 -24
  338. package/dest/trees/membership_witness.d.ts.map +1 -1
  339. package/dest/trees/membership_witness.js +1 -1
  340. package/dest/trees/merkle_tree.d.ts +1 -1
  341. package/dest/trees/merkle_tree.d.ts.map +1 -1
  342. package/dest/trees/merkle_tree_calculator.d.ts +2 -12
  343. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  344. package/dest/trees/merkle_tree_calculator.js +1 -31
  345. package/dest/trees/sibling_path.d.ts +5 -39
  346. package/dest/trees/sibling_path.d.ts.map +1 -1
  347. package/dest/trees/sibling_path.js +2 -2
  348. package/dest/trees/unbalanced_merkle_tree.d.ts +5 -4
  349. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
  350. package/dest/trees/unbalanced_merkle_tree.js +33 -10
  351. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +27 -23
  352. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
  353. package/dest/trees/unbalanced_merkle_tree_calculator.js +123 -97
  354. package/dest/trees/unbalanced_tree_store.d.ts +2 -1
  355. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  356. package/dest/trees/unbalanced_tree_store.js +6 -0
  357. package/dest/types/index.d.ts +1 -1
  358. package/dest/url/index.d.ts +1 -1
  359. package/dest/validation/index.d.ts +1 -1
  360. package/package.json +31 -8
  361. package/src/array/array.ts +0 -16
  362. package/src/branded-types/block_number.ts +112 -0
  363. package/src/branded-types/checkpoint_number.ts +100 -0
  364. package/src/branded-types/epoch.ts +88 -0
  365. package/src/branded-types/index.ts +6 -0
  366. package/src/branded-types/slot.ts +88 -0
  367. package/src/branded-types/types.ts +2 -0
  368. package/src/buffer/buffer16.ts +2 -2
  369. package/src/buffer/buffer32.ts +2 -2
  370. package/src/collection/array.ts +15 -3
  371. package/src/collection/object.ts +8 -0
  372. package/src/config/env_var.ts +38 -21
  373. package/src/config/index.ts +23 -3
  374. package/src/config/network_config.ts +16 -0
  375. package/src/config/network_name.ts +18 -3
  376. package/src/crypto/aes128/index.ts +19 -10
  377. package/src/crypto/bls/bn254_keystore.ts +287 -0
  378. package/src/crypto/bls/index.ts +77 -0
  379. package/src/crypto/bn254/index.ts +64 -0
  380. package/src/crypto/ecdsa/index.ts +40 -37
  381. package/src/crypto/ecdsa/signature.ts +2 -2
  382. package/src/crypto/grumpkin/index.ts +38 -46
  383. package/src/crypto/keys/index.ts +6 -6
  384. package/src/crypto/pedersen/pedersen.wasm.ts +23 -19
  385. package/src/crypto/poseidon/index.ts +33 -25
  386. package/src/crypto/schnorr/index.ts +22 -18
  387. package/src/crypto/schnorr/signature.ts +2 -2
  388. package/src/crypto/secp256k1/index.ts +15 -11
  389. package/src/crypto/secp256k1-signer/utils.ts +115 -7
  390. package/src/crypto/sha256/index.ts +1 -1
  391. package/src/crypto/sha512/index.ts +1 -1
  392. package/src/crypto/signature/index.ts +1 -1
  393. package/src/crypto/sync/index.ts +1 -1
  394. package/src/crypto/sync/pedersen/index.ts +17 -16
  395. package/src/crypto/sync/poseidon/index.ts +28 -23
  396. package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +6 -6
  397. package/src/curves/bls12/index.ts +2 -0
  398. package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +14 -14
  399. package/src/{fields/fields.ts → curves/bn254/field.ts} +41 -19
  400. package/src/curves/bn254/index.ts +2 -0
  401. package/src/curves/bn254/point.ts +170 -0
  402. package/src/curves/grumpkin/index.ts +11 -0
  403. package/src/{fields → curves/grumpkin}/point.ts +26 -7
  404. package/src/eth-address/index.ts +28 -3
  405. package/src/eth-signature/eth_signature.ts +2 -4
  406. package/src/json-rpc/client/safe_json_rpc_client.ts +9 -0
  407. package/src/log/log_fn.ts +1 -1
  408. package/src/log/pino-logger.ts +0 -1
  409. package/src/profiler/index.ts +1 -0
  410. package/src/profiler/profiler.ts +125 -0
  411. package/src/schemas/schemas.ts +16 -13
  412. package/src/schemas/utils.ts +21 -8
  413. package/src/serialize/buffer_reader.ts +5 -0
  414. package/src/serialize/field_reader.ts +1 -1
  415. package/src/serialize/free_funcs.ts +1 -1
  416. package/src/serialize/serialize.ts +1 -1
  417. package/src/string/index.ts +24 -1
  418. package/src/testing/files/index.ts +1 -1
  419. package/src/testing/formatting.ts +3 -0
  420. package/src/testing/index.ts +1 -0
  421. package/src/timer/index.ts +1 -1
  422. package/src/timer/timeout.ts +13 -0
  423. package/src/trees/balanced_merkle_tree.ts +84 -0
  424. package/src/trees/index.ts +1 -0
  425. package/src/trees/indexed_merkle_tree.ts +1 -1
  426. package/src/trees/membership_witness.ts +1 -1
  427. package/src/trees/merkle_tree_calculator.ts +1 -34
  428. package/src/trees/sibling_path.ts +2 -2
  429. package/src/trees/unbalanced_merkle_tree.ts +55 -7
  430. package/src/trees/unbalanced_merkle_tree_calculator.ts +134 -93
  431. package/src/trees/unbalanced_tree_store.ts +5 -1
  432. package/dest/crypto/index.d.ts +0 -15
  433. package/dest/crypto/index.d.ts.map +0 -1
  434. package/dest/crypto/index.js +0 -14
  435. package/dest/fields/bls12_fields.d.ts.map +0 -1
  436. package/dest/fields/bls12_point.d.ts.map +0 -1
  437. package/dest/fields/coordinate.d.ts +0 -66
  438. package/dest/fields/coordinate.d.ts.map +0 -1
  439. package/dest/fields/coordinate.js +0 -96
  440. package/dest/fields/fields.d.ts.map +0 -1
  441. package/dest/fields/index.d.ts +0 -6
  442. package/dest/fields/index.d.ts.map +0 -1
  443. package/dest/fields/index.js +0 -5
  444. package/dest/fields/point.d.ts.map +0 -1
  445. package/dest/index.d.ts +0 -29
  446. package/dest/index.d.ts.map +0 -1
  447. package/dest/index.js +0 -29
  448. package/src/crypto/index.ts +0 -14
  449. package/src/fields/coordinate.ts +0 -104
  450. package/src/fields/index.ts +0 -5
  451. package/src/index.ts +0 -29
@@ -1,6 +1,6 @@
1
- import { BarretenbergSync, Fr as FrBarretenberg } from '@aztec/bb.js';
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,13 +12,11 @@ export 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
- const point = BarretenbergSync.getSingleton().pedersenCommit(
16
- input.map(i => new FrBarretenberg(i)),
17
- offset,
18
- );
19
- // toBuffer returns Uint8Arrays (browser/worker-boundary friendly).
20
- // TODO: rename toTypedArray()?
21
- return [Buffer.from(point.x.toBuffer()), Buffer.from(point.y.toBuffer())];
15
+ const response = BarretenbergSync.getSingleton().pedersenCommit({
16
+ inputs: input,
17
+ hashIndex: offset,
18
+ });
19
+ return [Buffer.from(response.point.x), Buffer.from(response.point.y)];
22
20
  }
23
21
 
24
22
  /**
@@ -29,17 +27,20 @@ export function pedersenCommit(input: Buffer[], offset = 0) {
29
27
  */
30
28
  export function pedersenHash(input: Fieldable[], index = 0): Fr {
31
29
  const inputFields = serializeToFields(input);
32
- const hash = BarretenbergSync.getSingleton().pedersenHash(
33
- inputFields.map(i => new FrBarretenberg(i.toBuffer())), // TODO(#4189): remove this stupid conversion
34
- index,
35
- );
36
- return Fr.fromBuffer(Buffer.from(hash.toBuffer()));
30
+ const response = BarretenbergSync.getSingleton().pedersenHash({
31
+ inputs: inputFields.map(i => i.toBuffer()),
32
+ hashIndex: index,
33
+ });
34
+ return Fr.fromBuffer(Buffer.from(response.hash));
37
35
  }
38
36
 
39
37
  /**
40
38
  * Create a pedersen hash from an arbitrary length buffer.
41
39
  */
42
40
  export function pedersenHashBuffer(input: Buffer, index = 0) {
43
- const result = BarretenbergSync.getSingleton().pedersenHashBuffer(input, index);
44
- return Buffer.from(result.toBuffer());
41
+ const response = BarretenbergSync.getSingleton().pedersenHashBuffer({
42
+ input,
43
+ hashIndex: index,
44
+ });
45
+ return Buffer.from(response.hash);
45
46
  }
@@ -1,6 +1,6 @@
1
- import { BarretenbergSync, Fr as FrBarretenberg } from '@aztec/bb.js';
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
  /**
@@ -10,10 +10,11 @@ import { type Fieldable, serializeToFields } from '../../../serialize/serialize.
10
10
  */
11
11
  export function poseidon2Hash(input: Fieldable[]): Fr {
12
12
  const inputFields = serializeToFields(input);
13
- const hash = BarretenbergSync.getSingleton().poseidon2Hash(
14
- inputFields.map(i => new FrBarretenberg(i.toBuffer())), // TODO(#4189): remove this stupid conversion
15
- );
16
- return Fr.fromBuffer(Buffer.from(hash.toBuffer()));
13
+ const api = BarretenbergSync.getSingleton();
14
+ const response = api.poseidon2Hash({
15
+ inputs: inputFields.map(i => i.toBuffer()),
16
+ });
17
+ return Fr.fromBuffer(Buffer.from(response.hash));
17
18
  }
18
19
 
19
20
  /**
@@ -26,18 +27,20 @@ export function poseidon2HashWithSeparator(input: Fieldable[], separator: number
26
27
  const inputFields = serializeToFields(input);
27
28
  inputFields.unshift(new Fr(separator));
28
29
 
29
- const hash = BarretenbergSync.getSingleton().poseidon2Hash(
30
- inputFields.map(i => new FrBarretenberg(i.toBuffer())), // TODO(#4189): remove this stupid conversion
31
- );
32
- return Fr.fromBuffer(Buffer.from(hash.toBuffer()));
30
+ const api = BarretenbergSync.getSingleton();
31
+ const response = api.poseidon2Hash({
32
+ inputs: inputFields.map(i => i.toBuffer()),
33
+ });
34
+ return Fr.fromBuffer(Buffer.from(response.hash));
33
35
  }
34
36
 
35
37
  export function poseidon2HashAccumulate(input: Fieldable[]): Fr {
36
38
  const inputFields = serializeToFields(input);
37
- const result = BarretenbergSync.getSingleton().poseidon2HashAccumulate(
38
- inputFields.map(i => new FrBarretenberg(i.toBuffer())),
39
- );
40
- return Fr.fromBuffer(Buffer.from(result.toBuffer()));
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));
41
44
  }
42
45
 
43
46
  /**
@@ -49,12 +52,13 @@ export function poseidon2Permutation(input: Fieldable[]): Fr[] {
49
52
  const inputFields = serializeToFields(input);
50
53
  // We'd like this assertion but it's not possible to use it in the browser.
51
54
  // assert(input.length === 4, 'Input state must be of size 4');
52
- const res = BarretenbergSync.getSingleton().poseidon2Permutation(
53
- inputFields.map(i => new FrBarretenberg(i.toBuffer())),
54
- );
55
+ const api = BarretenbergSync.getSingleton();
56
+ const response = api.poseidon2Permutation({
57
+ inputs: inputFields.map(i => i.toBuffer()),
58
+ });
55
59
  // We'd like this assertion but it's not possible to use it in the browser.
56
- // assert(res.length === 4, 'Output state must be of size 4');
57
- return res.map(o => Fr.fromBuffer(Buffer.from(o.toBuffer())));
60
+ // assert(response.outputs.length === 4, 'Output state must be of size 4');
61
+ return response.outputs.map(o => Fr.fromBuffer(Buffer.from(o)));
58
62
  }
59
63
 
60
64
  export function poseidon2HashBytes(input: Buffer): Fr {
@@ -68,9 +72,10 @@ export function poseidon2HashBytes(input: Buffer): Fr {
68
72
  inputFields.push(Fr.fromBuffer(fieldBytes));
69
73
  }
70
74
 
71
- const res = BarretenbergSync.getSingleton().poseidon2Hash(
72
- inputFields.map(i => new FrBarretenberg(i.toBuffer())), // TODO(#4189): remove this stupid conversion
73
- );
75
+ const api = BarretenbergSync.getSingleton();
76
+ const response = api.poseidon2Hash({
77
+ inputs: inputFields.map(i => i.toBuffer()),
78
+ });
74
79
 
75
- return Fr.fromBuffer(Buffer.from(res.toBuffer()));
80
+ return Fr.fromBuffer(Buffer.from(response.hash));
76
81
  }
@@ -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.
@@ -158,13 +158,13 @@ export class BLS12Point {
158
158
  }
159
159
 
160
160
  /**
161
- * Converts a Point to two BN254 Fr elements by storing its compressed form as:
162
- * +------------------+------------------+
163
- * | Field Element 1 | Field Element 2 |
164
- * | [bytes 0-31] | [bytes 32-47] |
165
- * +------------------+------------------+
166
- * | 32 bytes | 16 bytes |
167
- * +------------------+------------------+
161
+ * Converts a Point to two BN254 Fr elements by storing its compressed form (48 bytes) as:
162
+ * +-------------------+------------------------+
163
+ * | 31 bytes | 17 bytes |
164
+ * +-------------------+------------------------+
165
+ * | Field Element 1 | Field Element 2 |
166
+ * | [0][bytes 0-30] | [0...0][bytes 31-47] |
167
+ * +-------------------+------------------------+
168
168
  * Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
169
169
  * @param point - A BLS12Point instance.
170
170
  * @returns The point fields.
@@ -2,11 +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';
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
10
 
11
11
  const ZERO_BUFFER = Buffer.alloc(32);
12
12
 
@@ -321,22 +321,37 @@ export class Fr extends BaseField {
321
321
  * @returns A square root of the field element (null if it does not exist).
322
322
  */
323
323
  async sqrt(): Promise<Fr | null> {
324
- const api = await BarretenbergSync.initSingleton(process.env.BB_WASM_PATH);
325
- const wasm = api.getWasm();
326
- const [buf] = wasm.callWasmExport('bn254_fr_sqrt', [this.toBuffer()], [Fr.SIZE_IN_BYTES + 1]);
327
- const isSqrt = buf[0] === 1;
328
- if (!isSqrt) {
324
+ await BarretenbergSync.initSingleton();
325
+ const api = BarretenbergSync.getSingleton();
326
+ const response = api.bn254FrSqrt({ input: this.toBuffer() });
327
+ if (!response.isSquareRoot) {
329
328
  // Field element is not a quadratic residue mod p so it has no square root.
330
329
  return null;
331
330
  }
332
- return new Fr(Buffer.from(buf.slice(1)));
331
+ return Fr.fromBuffer(Buffer.from(response.value));
333
332
  }
334
333
 
335
334
  toJSON() {
336
335
  return this.toString();
337
336
  }
338
337
 
338
+ /**
339
+ * Creates an Fr instance from a plain object without Zod validation.
340
+ * This method is optimized for performance and skips validation, making it suitable
341
+ * for deserializing trusted data (e.g., from C++ via MessagePack).
342
+ * Handles buffers, strings, numbers, bigints, or existing instances.
343
+ * @param obj - Plain object, buffer, string, number, bigint, boolean, or Fr instance
344
+ * @returns An Fr instance
345
+ */
346
+ static fromPlainObject(obj: any): Fr {
347
+ if (obj instanceof Fr) {
348
+ return obj;
349
+ }
350
+ return new Fr(obj);
351
+ }
352
+
339
353
  static get schema() {
354
+ // Serialization from hex string.
340
355
  return hexSchemaFor(Fr);
341
356
  }
342
357
  }
@@ -435,6 +450,21 @@ export class Fq extends BaseField {
435
450
  return new Fq((this.toBigInt() + rhs.toBigInt()) % Fq.MODULUS);
436
451
  }
437
452
 
453
+ /**
454
+ * Computes a square root of the field element.
455
+ * @returns A square root of the field element (null if it does not exist).
456
+ */
457
+ async sqrt(): Promise<Fq | null> {
458
+ await BarretenbergSync.initSingleton();
459
+ const api = BarretenbergSync.getSingleton();
460
+ const response = api.bn254FqSqrt({ input: this.toBuffer() });
461
+ if (!response.isSquareRoot) {
462
+ // Field element is not a quadratic residue mod p so it has no square root.
463
+ return null;
464
+ }
465
+ return Fq.fromBuffer(Buffer.from(response.value));
466
+ }
467
+
438
468
  toJSON() {
439
469
  return this.toString();
440
470
  }
@@ -481,14 +511,6 @@ function extendedEuclidean(a: bigint, modulus: bigint): [bigint, bigint, bigint]
481
511
  }
482
512
  }
483
513
 
484
- /**
485
- * GrumpkinScalar is an Fq.
486
- * @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
487
- * the Aztec Protocol Specs.
488
- */
489
- export type GrumpkinScalar = Fq;
490
- export const GrumpkinScalar = Fq;
491
-
492
514
  /** Wraps a function that returns a buffer so that all results are reduced into a field of the given type. */
493
515
  export function reduceFn<TInput, TField extends BaseField>(fn: (input: TInput) => Buffer, field: DerivedField<TField>) {
494
516
  return (input: TInput) => fromBufferReduce(fn(input), field);
@@ -0,0 +1,2 @@
1
+ export * from './field.js';
2
+ export * from './point.js';
@@ -0,0 +1,170 @@
1
+ import {
2
+ BN254_G1_GENERATOR,
3
+ BN254_G2_GENERATOR,
4
+ BarretenbergSync,
5
+ type Bn254G1Point as BbApiBn254G1Point,
6
+ type Bn254G2Point as BbApiBn254G2Point,
7
+ } from '@aztec/bb.js';
8
+
9
+ import { Fq, Fr } from './field.js';
10
+
11
+ /**
12
+ * BN254 G1 point using foundation field classes.
13
+ * Represents a point on the BN254 elliptic curve in affine coordinates.
14
+ */
15
+ export class Bn254G1Point {
16
+ constructor(
17
+ public readonly x: Fq,
18
+ public readonly y: Fq,
19
+ ) {}
20
+
21
+ private toBbApiPoint(): BbApiBn254G1Point {
22
+ return {
23
+ x: this.x.toBuffer(),
24
+ y: this.y.toBuffer(),
25
+ };
26
+ }
27
+
28
+ private static fromBbApiPoint(point: BbApiBn254G1Point): Bn254G1Point {
29
+ return new Bn254G1Point(Fq.fromBuffer(Buffer.from(point.x)), Fq.fromBuffer(Buffer.from(point.y)));
30
+ }
31
+
32
+ async isOnCurve(): Promise<boolean> {
33
+ await BarretenbergSync.initSingleton();
34
+ const api = BarretenbergSync.getSingleton();
35
+
36
+ const apiPoint = this.toBbApiPoint();
37
+ const response = api.bn254G1IsOnCurve({ point: apiPoint });
38
+ return response.isOnCurve;
39
+ }
40
+
41
+ /**
42
+ * Get the generator point for BN254 G1, or perform scalar multiplication.
43
+ * When called without arguments, returns the base generator point.
44
+ * When called with a scalar, returns scalar * generator (useful for public key derivation).
45
+ */
46
+ static async generator(scalar?: Fr): Promise<Bn254G1Point> {
47
+ if (!scalar) {
48
+ return new Bn254G1Point(
49
+ Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.x)),
50
+ Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.y)),
51
+ );
52
+ }
53
+
54
+ await BarretenbergSync.initSingleton();
55
+ const api = BarretenbergSync.getSingleton();
56
+
57
+ const response = api.bn254G1Mul({
58
+ point: BN254_G1_GENERATOR,
59
+ scalar: scalar.toBuffer(),
60
+ });
61
+
62
+ return Bn254G1Point.fromBbApiPoint(response.point);
63
+ }
64
+
65
+ /**
66
+ * Decompress a BN254 G1 point from compressed form (32 bytes).
67
+ * The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
68
+ * in the most significant bit.
69
+ */
70
+ static async fromCompressed(compressed: Buffer): Promise<Bn254G1Point> {
71
+ if (compressed.length !== 32) {
72
+ throw new Error('Invalid compressed point length');
73
+ }
74
+ await BarretenbergSync.initSingleton();
75
+ const api = BarretenbergSync.getSingleton();
76
+
77
+ const response = api.bn254G1FromCompressed({
78
+ compressed: new Uint8Array(compressed),
79
+ });
80
+
81
+ return Bn254G1Point.fromBbApiPoint(response.point);
82
+ }
83
+
84
+ /**
85
+ * Compress this BN254 G1 point to 32 bytes.
86
+ * The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
87
+ * in the most significant bit (bit 255).
88
+ */
89
+ compress(): Buffer {
90
+ const xBytes = this.x.toBuffer();
91
+ // Get the least significant bit of y to determine the sign
92
+ const yLsb = this.y.toBigInt() & 1n;
93
+ // If y is odd, set the most significant bit (bit 255) of the output
94
+ if (yLsb === 1n) {
95
+ xBytes[0] |= 0x80;
96
+ }
97
+ return xBytes;
98
+ }
99
+
100
+ equals(other: Bn254G1Point): boolean {
101
+ return this.x.equals(other.x) && this.y.equals(other.y);
102
+ }
103
+
104
+ toString(): string {
105
+ return `Bn254G1Point(x: ${this.x.toString()}, y: ${this.y.toString()})`;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * BN254 G2 point using foundation field classes.
111
+ * Represents a point on the BN254 G2 curve (twist curve) in affine coordinates.
112
+ * G2 points use extension field coordinates (Fq2).
113
+ */
114
+ export class Bn254G2Point {
115
+ constructor(
116
+ public readonly x: [Fq, Fq],
117
+ public readonly y: [Fq, Fq],
118
+ ) {}
119
+
120
+ private toBbApiPoint(): BbApiBn254G2Point {
121
+ return {
122
+ x: [this.x[0].toBuffer(), this.x[1].toBuffer()],
123
+ y: [this.y[0].toBuffer(), this.y[1].toBuffer()],
124
+ };
125
+ }
126
+
127
+ private static fromBbApiPoint(point: BbApiBn254G2Point): Bn254G2Point {
128
+ return new Bn254G2Point(
129
+ [Fq.fromBuffer(Buffer.from(point.x[0])), Fq.fromBuffer(Buffer.from(point.x[1]))],
130
+ [Fq.fromBuffer(Buffer.from(point.y[0])), Fq.fromBuffer(Buffer.from(point.y[1]))],
131
+ );
132
+ }
133
+
134
+ /**
135
+ * Get the generator point for BN254 G2, or perform scalar multiplication.
136
+ * When called without arguments, returns the base generator point.
137
+ * When called with a scalar, returns scalar * generator.
138
+ */
139
+ static async generator(scalar?: Fr): Promise<Bn254G2Point> {
140
+ if (!scalar) {
141
+ return new Bn254G2Point(
142
+ [Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[1]))],
143
+ [Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[1]))],
144
+ );
145
+ }
146
+
147
+ await BarretenbergSync.initSingleton();
148
+ const api = BarretenbergSync.getSingleton();
149
+
150
+ const response = api.bn254G2Mul({
151
+ point: BN254_G2_GENERATOR as BbApiBn254G2Point,
152
+ scalar: scalar.toBuffer(),
153
+ });
154
+
155
+ return Bn254G2Point.fromBbApiPoint(response.point);
156
+ }
157
+
158
+ equals(other: Bn254G2Point): boolean {
159
+ return (
160
+ this.x[0].equals(other.x[0]) &&
161
+ this.x[1].equals(other.x[1]) &&
162
+ this.y[0].equals(other.y[0]) &&
163
+ this.y[1].equals(other.y[1])
164
+ );
165
+ }
166
+
167
+ toString(): string {
168
+ return `Bn254G2Point(x: (${this.x[0].toString()}, ${this.x[1].toString()}), y: (${this.y[0].toString()}, ${this.y[1].toString()}))`;
169
+ }
170
+ }
@@ -0,0 +1,11 @@
1
+ import { Fq } from '../bn254/field.js';
2
+
3
+ export * from './point.js';
4
+
5
+ /**
6
+ * GrumpkinScalar is an Fq.
7
+ * @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
8
+ * the Aztec Protocol Specs.
9
+ */
10
+ export type GrumpkinScalar = Fq;
11
+ export const GrumpkinScalar = Fq;
@@ -1,10 +1,10 @@
1
- import { toBigIntBE } from '../bigint-buffer/index.js';
2
- import { poseidon2Hash } from '../crypto/poseidon/index.js';
3
- import { randomBoolean } from '../crypto/random/index.js';
4
- import { hexSchemaFor } from '../schemas/utils.js';
5
- import { BufferReader, FieldReader, serializeToBuffer } from '../serialize/index.js';
6
- import { bufferToHex, hexToBuffer } from '../string/index.js';
7
- import { Fr } from './fields.js';
1
+ import { toBigIntBE } from '../../bigint-buffer/index.js';
2
+ import { poseidon2Hash } from '../../crypto/poseidon/index.js';
3
+ import { randomBoolean } from '../../crypto/random/index.js';
4
+ import { hexSchemaFor } from '../../schemas/utils.js';
5
+ import { BufferReader, FieldReader, serializeToBuffer } from '../../serialize/index.js';
6
+ import { bufferToHex, hexToBuffer } from '../../string/index.js';
7
+ import { Fr } from '../bn254/field.js';
8
8
 
9
9
  /**
10
10
  * Represents a Point on an elliptic curve with x and y coordinates.
@@ -42,9 +42,28 @@ export class Point {
42
42
  }
43
43
 
44
44
  static get schema() {
45
+ // Serialization from hex string.
45
46
  return hexSchemaFor(Point);
46
47
  }
47
48
 
49
+ /**
50
+ * Creates a Point from a plain object without Zod validation.
51
+ * This method is optimized for performance and skips validation, making it suitable
52
+ * for deserializing trusted data (e.g., from C++ via MessagePack).
53
+ * Handles buffers, existing instances, or objects with x, y, and isInfinite fields.
54
+ * @param obj - Plain object, buffer, or Point instance
55
+ * @returns A Point instance
56
+ */
57
+ static fromPlainObject(obj: any): Point {
58
+ if (obj instanceof Point) {
59
+ return obj;
60
+ }
61
+ if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
62
+ return Point.fromBuffer(obj);
63
+ }
64
+ return new Point(Fr.fromPlainObject(obj.x), Fr.fromPlainObject(obj.y), obj.isInfinite ?? false);
65
+ }
66
+
48
67
  /**
49
68
  * Generate a random Point instance.
50
69
  *
@@ -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.
@@ -117,14 +135,14 @@ export class EthAddress {
117
135
  * @param address - The Ethereum address as a hex-encoded string.
118
136
  * @returns The Ethereum address in its checksum format.
119
137
  */
120
- public static toChecksumAddress(address: string) {
138
+ public static toChecksumAddress(address: string): `0x${string}` {
121
139
  if (!EthAddress.isAddress(address)) {
122
140
  throw new Error('Invalid address string.');
123
141
  }
124
142
 
125
143
  address = address.toLowerCase().replace(/^0x/i, '');
126
144
  const addressHash = keccak256String(address);
127
- let checksumAddress = '0x';
145
+ let checksumAddress: `0x${string}` = '0x';
128
146
 
129
147
  for (let i = 0; i < address.length; i++) {
130
148
  // If ith character is 9 to f then make it uppercase.
@@ -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.
@@ -78,7 +78,7 @@ export class Signature {
78
78
  }
79
79
 
80
80
  static random(): Signature {
81
- return new Signature(Buffer32.random(), Buffer32.random(), Math.floor(Math.random() * 2));
81
+ return new Signature(Buffer32.random(), Buffer32.random(), 1);
82
82
  }
83
83
 
84
84
  static empty(): Signature {
@@ -94,9 +94,7 @@ export class Signature {
94
94
  }
95
95
 
96
96
  toBuffer(): Buffer {
97
- const buffer = serializeToBuffer([this.r, this.s, this.v]);
98
- this.size = buffer.length;
99
- return buffer;
97
+ return serializeToBuffer([this.r, this.s, this.v]);
100
98
  }
101
99
 
102
100
  getSize(): number {
@@ -178,6 +178,15 @@ export function createSafeJsonRpcClient<T extends object>(
178
178
  }
179
179
  }
180
180
  } catch (err) {
181
+ // Re-throw ComponentsVersionsError immediately without converting to JSON-RPC error
182
+ // This ensures version mismatch errors are surfaced to the user instead of being hidden
183
+ if (err && typeof err === 'object' && 'name' in err && err.name === 'ComponentsVersionsError') {
184
+ // Reject all pending requests with the version error
185
+ for (let i = 0; i < rpcCalls.length; i++) {
186
+ rpcCalls[i].deferred.reject(err);
187
+ }
188
+ return; // Return early, the promises are already rejected
189
+ }
181
190
  log.warn(`Failed to fetch from the remote server`, err);
182
191
  for (let i = 0; i < rpcCalls.length; i++) {
183
192
  const { request, deferred } = rpcCalls[i];
package/src/log/log_fn.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Structured log data to include with the message. */
2
- export type LogData = Record<string, string | number | bigint | boolean | { toString(): string } | undefined>;
2
+ export type LogData = Record<string, string | number | bigint | boolean | { toString(): string } | undefined | null>;
3
3
 
4
4
  /** A callable logger instance. */
5
5
  export type LogFn = (msg: string, data?: unknown) => void;
@@ -111,7 +111,6 @@ const redactedPaths = [
111
111
  // bot keys
112
112
  'l1PrivateKey',
113
113
  'senderPrivateKey',
114
- 'recipientEncryptionSecret',
115
114
  // blob sink
116
115
  'l1ConsensusHostApiKeys',
117
116
  // sensitive options used in the CLI
@@ -0,0 +1 @@
1
+ export * from './profiler.js';