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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (411) hide show
  1. package/dest/array/array.d.ts +1 -9
  2. package/dest/array/array.d.ts.map +1 -1
  3. package/dest/array/array.js +0 -11
  4. package/dest/array/index.d.ts +1 -1
  5. package/dest/async-map/index.d.ts +1 -1
  6. package/dest/async-pool/index.d.ts +1 -1
  7. package/dest/bigint/index.d.ts +1 -1
  8. package/dest/bigint-buffer/index.d.ts +1 -1
  9. package/dest/branded-types/block_number.d.ts +53 -0
  10. package/dest/branded-types/block_number.d.ts.map +1 -0
  11. package/dest/branded-types/block_number.js +75 -0
  12. package/dest/branded-types/checkpoint_number.d.ts +46 -0
  13. package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
  14. package/dest/branded-types/checkpoint_number.js +68 -0
  15. package/dest/branded-types/epoch.d.ts +42 -0
  16. package/dest/branded-types/epoch.d.ts.map +1 -0
  17. package/dest/branded-types/epoch.js +59 -0
  18. package/dest/branded-types/index.d.ts +6 -0
  19. package/dest/branded-types/index.d.ts.map +1 -0
  20. package/dest/branded-types/index.js +4 -0
  21. package/dest/branded-types/slot.d.ts +42 -0
  22. package/dest/branded-types/slot.d.ts.map +1 -0
  23. package/dest/branded-types/slot.js +59 -0
  24. package/dest/branded-types/types.d.ts +5 -0
  25. package/dest/branded-types/types.d.ts.map +1 -0
  26. package/dest/branded-types/types.js +1 -0
  27. package/dest/buffer/buffer16.d.ts +2 -5
  28. package/dest/buffer/buffer16.d.ts.map +1 -1
  29. package/dest/buffer/buffer16.js +1 -1
  30. package/dest/buffer/buffer32.d.ts +2 -5
  31. package/dest/buffer/buffer32.d.ts.map +1 -1
  32. package/dest/buffer/buffer32.js +1 -1
  33. package/dest/buffer/index.d.ts +1 -1
  34. package/dest/collection/array.d.ts +3 -1
  35. package/dest/collection/array.d.ts.map +1 -1
  36. package/dest/collection/array.js +12 -3
  37. package/dest/collection/index.d.ts +1 -1
  38. package/dest/collection/object.d.ts +1 -1
  39. package/dest/committable/committable.d.ts +1 -1
  40. package/dest/committable/committable.d.ts.map +1 -1
  41. package/dest/committable/index.d.ts +1 -1
  42. package/dest/config/env_var.d.ts +2 -2
  43. package/dest/config/env_var.d.ts.map +1 -1
  44. package/dest/config/index.d.ts +10 -2
  45. package/dest/config/index.d.ts.map +1 -1
  46. package/dest/config/index.js +16 -2
  47. package/dest/config/network_config.d.ts +1 -1
  48. package/dest/config/network_name.d.ts +1 -1
  49. package/dest/config/secret_value.d.ts +1 -1
  50. package/dest/config/secret_value.d.ts.map +1 -1
  51. package/dest/crypto/aes128/index.d.ts +1 -1
  52. package/dest/crypto/aes128/index.d.ts.map +1 -1
  53. package/dest/crypto/aes128/index.js +2 -6
  54. package/dest/crypto/bls/bn254_keystore.d.ts +296 -0
  55. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -0
  56. package/dest/crypto/bls/bn254_keystore.js +218 -0
  57. package/dest/crypto/bls/index.d.ts +13 -0
  58. package/dest/crypto/bls/index.d.ts.map +1 -0
  59. package/dest/crypto/bls/index.js +87 -0
  60. package/dest/crypto/bn254/index.d.ts +39 -0
  61. package/dest/crypto/bn254/index.d.ts.map +1 -0
  62. package/dest/crypto/bn254/index.js +56 -0
  63. package/dest/crypto/ecdsa/index.d.ts +1 -1
  64. package/dest/crypto/ecdsa/index.d.ts.map +1 -1
  65. package/dest/crypto/ecdsa/index.js +4 -12
  66. package/dest/crypto/ecdsa/signature.d.ts +2 -11
  67. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  68. package/dest/crypto/ecdsa/signature.js +2 -2
  69. package/dest/crypto/grumpkin/index.d.ts +10 -13
  70. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  71. package/dest/crypto/grumpkin/index.js +12 -27
  72. package/dest/crypto/keccak/index.d.ts +1 -1
  73. package/dest/crypto/keys/index.d.ts +2 -2
  74. package/dest/crypto/keys/index.d.ts.map +1 -1
  75. package/dest/crypto/keys/index.js +2 -4
  76. package/dest/crypto/pedersen/index.d.ts +1 -1
  77. package/dest/crypto/pedersen/pedersen.noble.d.ts +1 -1
  78. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
  79. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  80. package/dest/crypto/pedersen/pedersen.wasm.js +4 -10
  81. package/dest/crypto/poseidon/index.d.ts +2 -2
  82. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  83. package/dest/crypto/poseidon/index.js +6 -16
  84. package/dest/crypto/random/index.d.ts +1 -1
  85. package/dest/crypto/random/index.d.ts.map +1 -1
  86. package/dest/crypto/random/randomness_singleton.d.ts +1 -1
  87. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  88. package/dest/crypto/schnorr/index.d.ts +3 -2
  89. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  90. package/dest/crypto/schnorr/index.js +4 -10
  91. package/dest/crypto/schnorr/signature.d.ts +2 -2
  92. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  93. package/dest/crypto/schnorr/signature.js +2 -2
  94. package/dest/crypto/secp256k1/index.d.ts +1 -1
  95. package/dest/crypto/secp256k1/index.d.ts.map +1 -1
  96. package/dest/crypto/secp256k1/index.js +3 -9
  97. package/dest/crypto/secp256k1-signer/index.d.ts +1 -1
  98. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +1 -1
  99. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
  100. package/dest/crypto/secp256k1-signer/utils.d.ts +43 -5
  101. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  102. package/dest/crypto/secp256k1-signer/utils.js +76 -8
  103. package/dest/crypto/serialize.d.ts +1 -1
  104. package/dest/crypto/sha256/index.d.ts +2 -2
  105. package/dest/crypto/sha256/index.d.ts.map +1 -1
  106. package/dest/crypto/sha256/index.js +1 -1
  107. package/dest/crypto/sha512/index.d.ts +3 -3
  108. package/dest/crypto/sha512/index.d.ts.map +1 -1
  109. package/dest/crypto/sha512/index.js +1 -1
  110. package/dest/crypto/signature/index.d.ts +2 -2
  111. package/dest/crypto/signature/index.d.ts.map +1 -1
  112. package/dest/crypto/sync/index.d.ts +1 -1
  113. package/dest/crypto/sync/index.js +1 -3
  114. package/dest/crypto/sync/pedersen/index.d.ts +2 -2
  115. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  116. package/dest/crypto/sync/pedersen/index.js +1 -1
  117. package/dest/crypto/sync/poseidon/index.d.ts +2 -2
  118. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  119. package/dest/crypto/sync/poseidon/index.js +1 -1
  120. package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
  121. package/dest/curves/bls12/field.d.ts.map +1 -0
  122. package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +6 -6
  123. package/dest/curves/bls12/index.d.ts +3 -0
  124. package/dest/curves/bls12/index.d.ts.map +1 -0
  125. package/dest/curves/bls12/index.js +2 -0
  126. package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +4 -13
  127. package/dest/curves/bls12/point.d.ts.map +1 -0
  128. package/dest/{fields/bls12_point.js → curves/bls12/point.js} +7 -7
  129. package/dest/{fields/fields.d.ts → curves/bn254/field.d.ts} +16 -9
  130. package/dest/curves/bn254/field.d.ts.map +1 -0
  131. package/dest/{fields/fields.js → curves/bn254/field.js} +35 -9
  132. package/dest/curves/bn254/index.d.ts +3 -0
  133. package/dest/curves/bn254/index.d.ts.map +1 -0
  134. package/dest/curves/bn254/index.js +2 -0
  135. package/dest/curves/bn254/point.d.ts +54 -0
  136. package/dest/curves/bn254/point.d.ts.map +1 -0
  137. package/dest/curves/bn254/point.js +143 -0
  138. package/dest/curves/grumpkin/index.d.ts +10 -0
  139. package/dest/curves/grumpkin/index.d.ts.map +1 -0
  140. package/dest/curves/grumpkin/index.js +3 -0
  141. package/dest/{fields → curves/grumpkin}/point.d.ts +13 -13
  142. package/dest/curves/grumpkin/point.d.ts.map +1 -0
  143. package/dest/{fields → curves/grumpkin}/point.js +24 -7
  144. package/dest/decorators/index.d.ts +1 -1
  145. package/dest/decorators/memoize.d.ts +1 -1
  146. package/dest/decorators/memoize.d.ts.map +1 -1
  147. package/dest/error/index.d.ts +4 -4
  148. package/dest/error/index.d.ts.map +1 -1
  149. package/dest/eth-address/index.d.ts +12 -2
  150. package/dest/eth-address/index.d.ts.map +1 -1
  151. package/dest/eth-address/index.js +23 -1
  152. package/dest/eth-signature/eth_signature.d.ts +1 -4
  153. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  154. package/dest/eth-signature/index.d.ts +1 -1
  155. package/dest/fs/index.d.ts +1 -1
  156. package/dest/fs/run_in_dir.d.ts +1 -1
  157. package/dest/fs/try_rm_dir.d.ts +1 -1
  158. package/dest/iterable/all.d.ts +1 -1
  159. package/dest/iterable/filter.d.ts +1 -1
  160. package/dest/iterable/index.d.ts +1 -1
  161. package/dest/iterable/isAsyncIt.d.ts +1 -1
  162. package/dest/iterable/map.d.ts +1 -1
  163. package/dest/iterable/peek.d.ts +1 -1
  164. package/dest/iterable/sort.d.ts +1 -1
  165. package/dest/iterable/take.d.ts +1 -1
  166. package/dest/iterable/toArray.d.ts +1 -1
  167. package/dest/json-rpc/client/fetch.d.ts +1 -1
  168. package/dest/json-rpc/client/index.d.ts +1 -1
  169. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
  170. package/dest/json-rpc/client/undici.d.ts +1 -1
  171. package/dest/json-rpc/convert.d.ts +1 -1
  172. package/dest/json-rpc/errors.d.ts +1 -1
  173. package/dest/json-rpc/errors.d.ts.map +1 -1
  174. package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
  175. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  176. package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
  177. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  178. package/dest/json-rpc/fixtures/test_state.d.ts +1 -1
  179. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
  180. package/dest/json-rpc/index.d.ts +1 -1
  181. package/dest/json-rpc/js_utils.d.ts +1 -1
  182. package/dest/json-rpc/js_utils.d.ts.map +1 -1
  183. package/dest/json-rpc/server/index.d.ts +1 -1
  184. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
  185. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  186. package/dest/json-rpc/server/telemetry.d.ts +1 -1
  187. package/dest/json-rpc/test/index.d.ts +1 -1
  188. package/dest/json-rpc/test/integration.d.ts +1 -1
  189. package/dest/log/console.d.ts +1 -1
  190. package/dest/log/gcloud-logger-config.d.ts +1 -1
  191. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  192. package/dest/log/index.d.ts +1 -1
  193. package/dest/log/libp2p_logger.d.ts +1 -1
  194. package/dest/log/log-filters.d.ts +1 -1
  195. package/dest/log/log-levels.d.ts +1 -1
  196. package/dest/log/log_fn.d.ts +1 -1
  197. package/dest/log/noir_debug_log_util.d.ts +1 -1
  198. package/dest/log/pino-logger.d.ts +2 -2
  199. package/dest/message/index.d.ts +1 -1
  200. package/dest/message/index.d.ts.map +1 -1
  201. package/dest/mutex/index.d.ts +1 -1
  202. package/dest/mutex/index.d.ts.map +1 -1
  203. package/dest/mutex/mutex_database.d.ts +1 -1
  204. package/dest/noir/index.d.ts +1 -1
  205. package/dest/noir/noir_package_config.d.ts +9 -9
  206. package/dest/number/index.d.ts +1 -1
  207. package/dest/profiler/index.d.ts +1 -1
  208. package/dest/profiler/profiler.d.ts +1 -1
  209. package/dest/promise/index.d.ts +1 -1
  210. package/dest/promise/running-promise.d.ts +1 -1
  211. package/dest/promise/running-promise.d.ts.map +1 -1
  212. package/dest/promise/utils.d.ts +1 -1
  213. package/dest/queue/base_memory_queue.d.ts +1 -1
  214. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  215. package/dest/queue/batch_queue.d.ts +1 -1
  216. package/dest/queue/batch_queue.d.ts.map +1 -1
  217. package/dest/queue/bounded_serial_queue.d.ts +1 -1
  218. package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
  219. package/dest/queue/fifo_memory_queue.d.ts +1 -1
  220. package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
  221. package/dest/queue/index.d.ts +1 -1
  222. package/dest/queue/priority_memory_queue.d.ts +1 -1
  223. package/dest/queue/priority_memory_queue.d.ts.map +1 -1
  224. package/dest/queue/priority_queue.d.ts +1 -1
  225. package/dest/queue/priority_queue.d.ts.map +1 -1
  226. package/dest/queue/semaphore.d.ts +1 -1
  227. package/dest/queue/semaphore.d.ts.map +1 -1
  228. package/dest/queue/serial_queue.d.ts +1 -1
  229. package/dest/queue/serial_queue.d.ts.map +1 -1
  230. package/dest/retry/index.d.ts +1 -1
  231. package/dest/running-promise/index.d.ts +1 -1
  232. package/dest/schemas/api.d.ts +1 -1
  233. package/dest/schemas/index.d.ts +1 -1
  234. package/dest/schemas/parse.d.ts +1 -1
  235. package/dest/schemas/schemas.d.ts +13 -17
  236. package/dest/schemas/schemas.d.ts.map +1 -1
  237. package/dest/schemas/schemas.js +9 -10
  238. package/dest/schemas/types.d.ts +1 -1
  239. package/dest/schemas/utils.d.ts +4 -4
  240. package/dest/schemas/utils.d.ts.map +1 -1
  241. package/dest/schemas/utils.js +15 -5
  242. package/dest/serialize/buffer_reader.d.ts +1 -1
  243. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  244. package/dest/serialize/field_reader.d.ts +2 -2
  245. package/dest/serialize/field_reader.d.ts.map +1 -1
  246. package/dest/serialize/field_reader.js +1 -1
  247. package/dest/serialize/free_funcs.d.ts +2 -2
  248. package/dest/serialize/free_funcs.d.ts.map +1 -1
  249. package/dest/serialize/free_funcs.js +1 -1
  250. package/dest/serialize/index.d.ts +1 -1
  251. package/dest/serialize/serialize.d.ts +2 -2
  252. package/dest/serialize/serialize.d.ts.map +1 -1
  253. package/dest/serialize/serialize.js +1 -1
  254. package/dest/serialize/type_registry.d.ts +1 -1
  255. package/dest/serialize/type_registry.d.ts.map +1 -1
  256. package/dest/serialize/types.d.ts +1 -1
  257. package/dest/sleep/index.d.ts +1 -1
  258. package/dest/sleep/index.d.ts.map +1 -1
  259. package/dest/string/index.d.ts +5 -1
  260. package/dest/string/index.d.ts.map +1 -1
  261. package/dest/string/index.js +1 -1
  262. package/dest/testing/files/index.d.ts +2 -1
  263. package/dest/testing/files/index.d.ts.map +1 -1
  264. package/dest/testing/files/index.js +1 -1
  265. package/dest/testing/formatting.d.ts +1 -1
  266. package/dest/testing/index.d.ts +1 -1
  267. package/dest/testing/port_allocator.d.ts +1 -1
  268. package/dest/testing/snapshot_serializer.d.ts +1 -1
  269. package/dest/testing/test_data.d.ts +1 -1
  270. package/dest/timer/date.d.ts +1 -1
  271. package/dest/timer/date.d.ts.map +1 -1
  272. package/dest/timer/elapsed.d.ts +1 -1
  273. package/dest/timer/index.d.ts +1 -1
  274. package/dest/timer/timeout.d.ts +1 -1
  275. package/dest/timer/timeout.d.ts.map +1 -1
  276. package/dest/timer/timer.d.ts +1 -1
  277. package/dest/timer/timer.d.ts.map +1 -1
  278. package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
  279. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  280. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +1 -1
  281. package/dest/transport/dispatch/messages.d.ts +1 -1
  282. package/dest/transport/index.d.ts +1 -1
  283. package/dest/transport/interface/connector.d.ts +1 -1
  284. package/dest/transport/interface/listener.d.ts +1 -1
  285. package/dest/transport/interface/socket.d.ts +1 -1
  286. package/dest/transport/interface/transferable.d.ts +1 -1
  287. package/dest/transport/node/index.d.ts +1 -1
  288. package/dest/transport/node/node_connector.d.ts +1 -1
  289. package/dest/transport/node/node_connector.d.ts.map +1 -1
  290. package/dest/transport/node/node_connector_socket.d.ts +1 -1
  291. package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
  292. package/dest/transport/node/node_listener.d.ts +1 -1
  293. package/dest/transport/node/node_listener.d.ts.map +1 -1
  294. package/dest/transport/node/node_listener_socket.d.ts +1 -1
  295. package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
  296. package/dest/transport/transport_client.d.ts +1 -1
  297. package/dest/transport/transport_client.d.ts.map +1 -1
  298. package/dest/transport/transport_server.d.ts +1 -10
  299. package/dest/transport/transport_server.d.ts.map +1 -1
  300. package/dest/trees/balanced_merkle_tree.d.ts +22 -0
  301. package/dest/trees/balanced_merkle_tree.d.ts.map +1 -0
  302. package/dest/trees/balanced_merkle_tree.js +66 -0
  303. package/dest/trees/hasher.d.ts +1 -1
  304. package/dest/trees/index.d.ts +2 -1
  305. package/dest/trees/index.d.ts.map +1 -1
  306. package/dest/trees/index.js +1 -0
  307. package/dest/trees/indexed_merkle_tree.d.ts +1 -1
  308. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
  309. package/dest/trees/indexed_merkle_tree.js +1 -1
  310. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  311. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  312. package/dest/trees/indexed_tree_leaf.d.ts +1 -1
  313. package/dest/trees/membership_witness.d.ts +3 -24
  314. package/dest/trees/membership_witness.d.ts.map +1 -1
  315. package/dest/trees/membership_witness.js +1 -1
  316. package/dest/trees/merkle_tree.d.ts +1 -1
  317. package/dest/trees/merkle_tree.d.ts.map +1 -1
  318. package/dest/trees/merkle_tree_calculator.d.ts +2 -12
  319. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  320. package/dest/trees/merkle_tree_calculator.js +1 -31
  321. package/dest/trees/sibling_path.d.ts +5 -39
  322. package/dest/trees/sibling_path.d.ts.map +1 -1
  323. package/dest/trees/sibling_path.js +2 -2
  324. package/dest/trees/unbalanced_merkle_tree.d.ts +5 -3
  325. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
  326. package/dest/trees/unbalanced_merkle_tree.js +32 -9
  327. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +6 -5
  328. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
  329. package/dest/trees/unbalanced_merkle_tree_calculator.js +36 -40
  330. package/dest/trees/unbalanced_tree_store.d.ts +1 -1
  331. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  332. package/dest/types/index.d.ts +1 -1
  333. package/dest/url/index.d.ts +1 -1
  334. package/dest/validation/index.d.ts +1 -1
  335. package/package.json +29 -7
  336. package/src/array/array.ts +0 -16
  337. package/src/branded-types/block_number.ts +112 -0
  338. package/src/branded-types/checkpoint_number.ts +100 -0
  339. package/src/branded-types/epoch.ts +88 -0
  340. package/src/branded-types/index.ts +6 -0
  341. package/src/branded-types/slot.ts +88 -0
  342. package/src/branded-types/types.ts +2 -0
  343. package/src/buffer/buffer16.ts +2 -2
  344. package/src/buffer/buffer32.ts +2 -2
  345. package/src/collection/array.ts +15 -3
  346. package/src/config/env_var.ts +20 -2
  347. package/src/config/index.ts +20 -2
  348. package/src/crypto/aes128/index.ts +2 -2
  349. package/src/crypto/bls/bn254_keystore.ts +287 -0
  350. package/src/crypto/bls/index.ts +77 -0
  351. package/src/crypto/bn254/index.ts +64 -0
  352. package/src/crypto/ecdsa/index.ts +4 -4
  353. package/src/crypto/ecdsa/signature.ts +2 -2
  354. package/src/crypto/grumpkin/index.ts +14 -20
  355. package/src/crypto/keys/index.ts +2 -2
  356. package/src/crypto/pedersen/pedersen.wasm.ts +4 -4
  357. package/src/crypto/poseidon/index.ts +6 -6
  358. package/src/crypto/schnorr/index.ts +5 -4
  359. package/src/crypto/schnorr/signature.ts +2 -2
  360. package/src/crypto/secp256k1/index.ts +3 -3
  361. package/src/crypto/secp256k1-signer/utils.ts +102 -10
  362. package/src/crypto/sha256/index.ts +1 -1
  363. package/src/crypto/sha512/index.ts +1 -1
  364. package/src/crypto/signature/index.ts +1 -1
  365. package/src/crypto/sync/index.ts +1 -1
  366. package/src/crypto/sync/pedersen/index.ts +1 -1
  367. package/src/crypto/sync/poseidon/index.ts +1 -1
  368. package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +6 -6
  369. package/src/curves/bls12/index.ts +2 -0
  370. package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +7 -7
  371. package/src/{fields/fields.ts → curves/bn254/field.ts} +37 -14
  372. package/src/curves/bn254/index.ts +2 -0
  373. package/src/curves/bn254/point.ts +170 -0
  374. package/src/curves/grumpkin/index.ts +11 -0
  375. package/src/{fields → curves/grumpkin}/point.ts +26 -7
  376. package/src/eth-address/index.ts +26 -1
  377. package/src/schemas/schemas.ts +16 -13
  378. package/src/schemas/utils.ts +21 -8
  379. package/src/serialize/field_reader.ts +1 -1
  380. package/src/serialize/free_funcs.ts +1 -1
  381. package/src/serialize/serialize.ts +1 -1
  382. package/src/string/index.ts +3 -0
  383. package/src/testing/files/index.ts +1 -1
  384. package/src/trees/balanced_merkle_tree.ts +84 -0
  385. package/src/trees/index.ts +1 -0
  386. package/src/trees/indexed_merkle_tree.ts +1 -1
  387. package/src/trees/membership_witness.ts +1 -1
  388. package/src/trees/merkle_tree_calculator.ts +1 -34
  389. package/src/trees/sibling_path.ts +2 -2
  390. package/src/trees/unbalanced_merkle_tree.ts +54 -6
  391. package/src/trees/unbalanced_merkle_tree_calculator.ts +34 -41
  392. package/dest/crypto/index.d.ts +0 -15
  393. package/dest/crypto/index.d.ts.map +0 -1
  394. package/dest/crypto/index.js +0 -14
  395. package/dest/fields/bls12_fields.d.ts.map +0 -1
  396. package/dest/fields/bls12_point.d.ts.map +0 -1
  397. package/dest/fields/coordinate.d.ts +0 -66
  398. package/dest/fields/coordinate.d.ts.map +0 -1
  399. package/dest/fields/coordinate.js +0 -96
  400. package/dest/fields/fields.d.ts.map +0 -1
  401. package/dest/fields/index.d.ts +0 -6
  402. package/dest/fields/index.d.ts.map +0 -1
  403. package/dest/fields/index.js +0 -5
  404. package/dest/fields/point.d.ts.map +0 -1
  405. package/dest/index.d.ts +0 -30
  406. package/dest/index.d.ts.map +0 -1
  407. package/dest/index.js +0 -30
  408. package/src/crypto/index.ts +0 -14
  409. package/src/fields/coordinate.ts +0 -104
  410. package/src/fields/index.ts +0 -5
  411. package/src/index.ts +0 -30
@@ -0,0 +1,287 @@
1
+ import { randomBytes } from '@aztec/foundation/crypto/random';
2
+
3
+ import { createCipheriv, createDecipheriv, createHash, pbkdf2Sync, randomUUID } from 'crypto';
4
+ import { readFileSync } from 'fs';
5
+ import { z } from 'zod';
6
+
7
+ /**
8
+ * BN254 Keystore Format
9
+ *
10
+ * Implements encryption and decryption of keystores for BN254 BLS private keys
11
+ * using PBKDF2 and AES-128-CTR. This format is inspired by EIP-2335 but adapted
12
+ * for BN254 keys rather than BLS12-381.
13
+ *
14
+ * @see https://eips.ethereum.org/EIPS/eip-2335
15
+ */
16
+
17
+ /**
18
+ * Zod schema for validating BN254 keystore structure
19
+ */
20
+ const bn254KeystoreSchema = z.object({
21
+ crypto: z.object({
22
+ kdf: z.object({
23
+ function: z.literal('pbkdf2'),
24
+ params: z.object({
25
+ dklen: z.number(),
26
+ c: z.number(),
27
+ prf: z.string(),
28
+ salt: z.string(),
29
+ }),
30
+ message: z.string(),
31
+ }),
32
+ checksum: z.object({
33
+ function: z.literal('sha256'),
34
+ params: z.object({}),
35
+ message: z.string(),
36
+ }),
37
+ cipher: z.object({
38
+ function: z.literal('aes-128-ctr'),
39
+ params: z.object({
40
+ iv: z.string(),
41
+ }),
42
+ message: z.string(),
43
+ }),
44
+ }),
45
+ description: z.string().optional(),
46
+ pubkey: z.string(),
47
+ path: z.string(),
48
+ uuid: z.string(),
49
+ version: z.number(),
50
+ });
51
+
52
+ /**
53
+ * Error thrown when BN254 keystore operations fail
54
+ */
55
+ export class Bn254KeystoreError extends Error {
56
+ constructor(
57
+ message: string,
58
+ public override cause?: Error,
59
+ ) {
60
+ super(message);
61
+ this.name = 'Bn254KeystoreError';
62
+ }
63
+ }
64
+
65
+ export type Bn254Keystore = z.infer<typeof bn254KeystoreSchema>;
66
+
67
+ /**
68
+ * The JSON structure of a BN254 keystore file.
69
+ * @deprecated Use the inferred type from bn254KeystoreSchema instead
70
+ */
71
+ export interface Bn254KeystoreInterface {
72
+ crypto: {
73
+ kdf: {
74
+ function: 'pbkdf2';
75
+ params: {
76
+ dklen: number;
77
+ c: number;
78
+ prf: string;
79
+ salt: string;
80
+ };
81
+ message: string;
82
+ };
83
+ checksum: {
84
+ function: 'sha256';
85
+ params: Record<string, never>;
86
+ message: string;
87
+ };
88
+ cipher: {
89
+ function: 'aes-128-ctr';
90
+ params: {
91
+ iv: string;
92
+ };
93
+ message: string;
94
+ };
95
+ };
96
+ description: string;
97
+ pubkey: string;
98
+ path: string;
99
+ uuid: string;
100
+ version: number;
101
+ }
102
+
103
+ /**
104
+ * Creates a BN254 keystore object for a BN254 BLS private key.
105
+ *
106
+ * Uses PBKDF2 with SHA-256 for key derivation and AES-128-CTR for encryption,
107
+ * following the EIP-2335 specification format.
108
+ *
109
+ * @param password - Password for encrypting the private key
110
+ * @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
111
+ * @param pubkeyHex - Public key as hex string (compressed or uncompressed)
112
+ * @param derivationPath - BIP-44 style derivation path (e.g., "m/12381/3600/0/0/0")
113
+ * @returns BN254 keystore object ready to be serialized to JSON
114
+ * @throws Error if private key is not 32-byte hex
115
+ */
116
+ export function createBn254Keystore(
117
+ password: string,
118
+ privateKeyHex: string,
119
+ pubkeyHex: string,
120
+ derivationPath: string,
121
+ ): Bn254Keystore {
122
+ const ensureHex = (hex: string) => hex.replace(/^0x/i, '');
123
+ const privHex = ensureHex(privateKeyHex);
124
+ if (!/^[0-9a-fA-F]{64}$/.test(privHex)) {
125
+ throw new Error('BLS private key must be 32-byte hex');
126
+ }
127
+
128
+ const salt = randomBytes(32);
129
+ const iv = randomBytes(16);
130
+ const dk = pbkdf2Sync(Buffer.from(password.normalize('NFKD'), 'utf8'), salt, 262144, 32, 'sha256');
131
+ const cipherKey = dk.subarray(0, 16);
132
+
133
+ const cipher = createCipheriv('aes-128-ctr', cipherKey, iv);
134
+ const plaintext = Buffer.from(privHex, 'hex');
135
+ const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
136
+
137
+ const checksum = createHash('sha256')
138
+ .update(Buffer.concat([dk.subarray(16, 32), ciphertext]))
139
+ .digest();
140
+
141
+ const uuid = randomUUID();
142
+
143
+ return {
144
+ crypto: {
145
+ kdf: {
146
+ function: 'pbkdf2',
147
+ params: { dklen: 32, c: 262144, prf: 'hmac-sha256', salt: salt.toString('hex') },
148
+ message: '',
149
+ },
150
+ checksum: {
151
+ function: 'sha256',
152
+ params: {},
153
+ message: checksum.toString('hex'),
154
+ },
155
+ cipher: {
156
+ function: 'aes-128-ctr',
157
+ params: { iv: iv.toString('hex') },
158
+ message: ciphertext.toString('hex'),
159
+ },
160
+ },
161
+ description: ensureHex(pubkeyHex),
162
+ pubkey: pubkeyHex,
163
+ path: derivationPath ?? '',
164
+ uuid,
165
+ version: 4,
166
+ };
167
+ }
168
+
169
+ /**
170
+ * Loads and validates a BN254 keystore file.
171
+ *
172
+ * @param filePath - Path to the BN254 keystore JSON file
173
+ * @returns Validated keystore object
174
+ * @throws Bn254KeystoreError if file cannot be read or validated
175
+ */
176
+ export function loadBn254Keystore(filePath: string): Bn254Keystore {
177
+ try {
178
+ const content = readFileSync(filePath, 'utf-8');
179
+ const json = JSON.parse(content);
180
+ return bn254KeystoreSchema.parse(json);
181
+ } catch (error) {
182
+ if (error instanceof SyntaxError) {
183
+ throw new Bn254KeystoreError(`Invalid JSON in keystore file: ${filePath}`, error);
184
+ }
185
+ if (error && typeof error === 'object' && 'issues' in error) {
186
+ const issues = (error as any).issues ?? [];
187
+ const message = issues.map((e: any) => `${e.message} at ${e.path?.join('.') ?? 'root'}`).join('; ');
188
+ throw new Bn254KeystoreError(`Invalid BN254 keystore format: ${message}`);
189
+ }
190
+ throw new Bn254KeystoreError(`Failed to load keystore from ${filePath}: ${String(error)}`, error as Error);
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Decrypts a BN254 BLS private key from a keystore file.
196
+ *
197
+ * @param filePath - Path to the BN254 keystore JSON file
198
+ * @param password - Password to decrypt the keystore
199
+ * @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
200
+ * @throws Bn254KeystoreError if decryption fails or checksum is invalid
201
+ */
202
+ export function decryptBn254Keystore(filePath: string, password: string): string {
203
+ const keystore = loadBn254Keystore(filePath);
204
+ return decryptBn254KeystoreFromObject(keystore, password);
205
+ }
206
+
207
+ /**
208
+ * Decrypts a BN254 BLS private key from a keystore object.
209
+ *
210
+ * @param keystore - BN254 keystore object
211
+ * @param password - Password to decrypt the keystore
212
+ * @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
213
+ * @throws Bn254KeystoreError if decryption fails or checksum is invalid
214
+ */
215
+ export function decryptBn254KeystoreFromObject(keystore: Bn254Keystore, password: string): string {
216
+ try {
217
+ const { crypto } = keystore;
218
+
219
+ // Only support PBKDF2 + AES-128-CTR (as per our implementation)
220
+ if (crypto.kdf.function !== 'pbkdf2') {
221
+ throw new Bn254KeystoreError(`Unsupported KDF function: ${crypto.kdf.function}`);
222
+ }
223
+ if (crypto.cipher.function !== 'aes-128-ctr') {
224
+ throw new Bn254KeystoreError(`Unsupported cipher function: ${crypto.cipher.function}`);
225
+ }
226
+
227
+ // Derive decryption key using PBKDF2
228
+ const salt = Buffer.from(crypto.kdf.params.salt, 'hex');
229
+ const dk = pbkdf2Sync(
230
+ Buffer.from(password.normalize('NFKD'), 'utf8'),
231
+ salt,
232
+ crypto.kdf.params.c,
233
+ crypto.kdf.params.dklen,
234
+ 'sha256',
235
+ );
236
+
237
+ const cipherKey = dk.subarray(0, 16);
238
+ const checksumKey = dk.subarray(16, 32);
239
+
240
+ // Decrypt the ciphertext
241
+ const iv = Buffer.from(crypto.cipher.params.iv, 'hex');
242
+ const ciphertext = Buffer.from(crypto.cipher.message, 'hex');
243
+ const decipher = createDecipheriv('aes-128-ctr', cipherKey, iv);
244
+ const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
245
+
246
+ // Verify checksum
247
+ const computedChecksum = createHash('sha256')
248
+ .update(Buffer.concat([checksumKey, ciphertext]))
249
+ .digest();
250
+ const expectedChecksum = Buffer.from(crypto.checksum.message, 'hex');
251
+
252
+ if (!computedChecksum.equals(expectedChecksum)) {
253
+ throw new Bn254KeystoreError('Checksum verification failed - incorrect password or corrupted keystore');
254
+ }
255
+
256
+ // Return as 0x-prefixed hex
257
+ return '0x' + decrypted.toString('hex');
258
+ } catch (error) {
259
+ if (error instanceof Bn254KeystoreError) {
260
+ throw error;
261
+ }
262
+ throw new Bn254KeystoreError(`Failed to decrypt keystore: ${String(error)}`, error as Error);
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Validates that a decrypted private key matches the public key in the keystore.
268
+ *
269
+ * @param privateKeyHex - Decrypted private key (0x-prefixed)
270
+ * @param expectedPubkey - Expected public key from keystore
271
+ * @param computePublicKey - Function to compute public key from private key
272
+ * @returns true if keys match, false otherwise
273
+ */
274
+ export function verifyBn254Keypair(
275
+ privateKeyHex: string,
276
+ expectedPubkey: string,
277
+ computePublicKey: (privateKey: string) => string,
278
+ ): boolean {
279
+ try {
280
+ const computedPubkey = computePublicKey(privateKeyHex);
281
+ const normalizedExpected = expectedPubkey.toLowerCase().replace(/^0x/i, '');
282
+ const normalizedComputed = computedPubkey.toLowerCase().replace(/^0x/i, '');
283
+ return normalizedExpected === normalizedComputed;
284
+ } catch {
285
+ return false;
286
+ }
287
+ }
@@ -0,0 +1,77 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { Hex } from '@aztec/foundation/string';
3
+
4
+ import { mod } from '@noble/curves/abstract/modular';
5
+ import { bytesToNumberBE } from '@noble/curves/abstract/utils';
6
+ import { hmac } from '@noble/hashes/hmac';
7
+ import { sha512 } from '@noble/hashes/sha2';
8
+ import { mnemonicToSeedSync } from '@scure/bip39';
9
+
10
+ export function deriveBlsPrivateKey(mnemonic: string | undefined, ikm: string | undefined, path: string): Hex<32> {
11
+ if (ikm) {
12
+ return deriveBlsKeyFromEntropy(ikm, path) as Hex<32>;
13
+ }
14
+ if (!mnemonic) {
15
+ throw new Error('Either mnemonic or ikm must be provided for BLS derivation');
16
+ }
17
+ return deriveBlsKeyFromMnemonic(mnemonic, path) as Hex<32>;
18
+ }
19
+
20
+ /**
21
+ * Deterministically derive a BN254 BLS private key from mnemonic and derivation path.
22
+ * Returns a 0x-prefixed 32-byte hex string representing an Fr in [1, r-1].
23
+ */
24
+ export function deriveBlsKeyFromMnemonic(mnemonic: string, derivationPath: string, passphrase = ''): string {
25
+ const seed = Buffer.from(mnemonicToSeedSync(mnemonic, passphrase)); // 64 bytes
26
+ const data = Buffer.concat([Buffer.from([0x00]), seed, Buffer.from(derivationPath, 'utf8')]);
27
+ const sk = deriveBn254ScalarFromData(data);
28
+ return `0x${toFixed32(sk).toString('hex')}`;
29
+ }
30
+
31
+ /**
32
+ * Deterministically derive a BN254 BLS private key from input keying material (IKM) and derivation path.
33
+ * Returns a 0x-prefixed 32-byte hex string representing an Fr in [1, r-1].
34
+ */
35
+ export function deriveBlsKeyFromEntropy(ikm: string, derivationPath: string): string {
36
+ const ikmBytes = parseIkm(ikm);
37
+ const data = Buffer.concat([Buffer.from([0x01]), ikmBytes, Buffer.from(derivationPath, 'utf8')]);
38
+ const sk = deriveBn254ScalarFromData(data);
39
+ return `0x${toFixed32(sk).toString('hex')}`;
40
+ }
41
+
42
+ function deriveBn254ScalarFromData(data: Buffer): bigint {
43
+ // Domain-separated HMAC-SHA512, then map to BN254 Fr using noble modular math. Retry on zero.
44
+ const domainKey = Buffer.from('Aztec bn254 key', 'utf8');
45
+ for (let counter = 0; ; counter = (counter + 1) & 0xff) {
46
+ const msg = counter === 0 ? data : Buffer.concat([data, Buffer.from([counter])]);
47
+ const digest = hmac(sha512, domainKey, msg); // 64 bytes
48
+ const x = bytesToNumberBE(digest);
49
+ const sk = mod(x, Fr.MODULUS);
50
+ if (sk !== 0n) {
51
+ return sk;
52
+ }
53
+ }
54
+ }
55
+
56
+ function parseIkm(ikm: string): Buffer {
57
+ const hexMatch = ikm.replace(/^0x/i, '');
58
+ if (/^[0-9a-fA-F]+$/.test(hexMatch) && hexMatch.length >= 2) {
59
+ const normalized = hexMatch.length % 2 === 1 ? `0${hexMatch}` : hexMatch;
60
+ return Buffer.from(normalized, 'hex');
61
+ }
62
+ return Buffer.from(ikm, 'utf8');
63
+ }
64
+
65
+ function toFixed32(x: bigint): Buffer {
66
+ const hex = x.toString(16);
67
+ const padded = hex.length % 2 === 1 ? `0${hex}` : hex;
68
+ const buf = Buffer.from(padded, 'hex');
69
+ if (buf.length === 32) {
70
+ return buf;
71
+ }
72
+ if (buf.length < 32) {
73
+ return Buffer.concat([Buffer.alloc(32 - buf.length, 0), buf]);
74
+ }
75
+ // Should never happen since x < bn254.Fr.ORDER < 2^256, but guard anyway
76
+ return buf.subarray(buf.length - 32);
77
+ }
@@ -0,0 +1,64 @@
1
+ import { Fr } from '../../curves/bn254/field.js';
2
+ import { Bn254G1Point, Bn254G2Point } from '../../curves/bn254/point.js';
3
+
4
+ /**
5
+ * BN254 utility functions for point operations.
6
+ * Provides compression, decompression, and public key generation for the BN254 curve.
7
+ * Uses the bb.js Barretenberg backend for point operations.
8
+ */
9
+
10
+ /**
11
+ * Generate a compressed BN254 G1 public key from a private key.
12
+ *
13
+ * @param privateKeyHex - Private key as 0x-prefixed hex string
14
+ * @returns Compressed G1 point (32 bytes with sign bit in MSB)
15
+ */
16
+ export async function computeBn254G1PublicKeyCompressed(privateKeyHex: string): Promise<string> {
17
+ const sk = BigInt(privateKeyHex);
18
+ const skReduced = sk % Fr.MODULUS;
19
+
20
+ // Generate G1 point on BN254 curve using bb.js
21
+ const scalar = Fr.fromString(skReduced.toString());
22
+ const pk1 = await Bn254G1Point.generator(scalar);
23
+
24
+ // Compress the point using the primitive method
25
+ return '0x' + pk1.compress().toString('hex');
26
+ }
27
+
28
+ /**
29
+ * Generate uncompressed BN254 G1 public key from a private key.
30
+ *
31
+ * @param privateKeyHex - Private key as 0x-prefixed hex string
32
+ * @returns G1 point in affine coordinates
33
+ */
34
+ export async function computeBn254G1PublicKey(privateKeyHex: string): Promise<{ x: bigint; y: bigint }> {
35
+ const sk = BigInt(privateKeyHex);
36
+ const skReduced = sk % Fr.MODULUS;
37
+
38
+ const scalar = Fr.fromString(skReduced.toString());
39
+ const pk1 = await Bn254G1Point.generator(scalar);
40
+
41
+ return { x: pk1.x.toBigInt(), y: pk1.y.toBigInt() };
42
+ }
43
+
44
+ /**
45
+ * Generate BN254 G2 public key from a private key.
46
+ *
47
+ * @param privateKeyHex - Private key as 0x-prefixed hex string
48
+ * @returns G2 point in affine coordinates
49
+ */
50
+ export async function computeBn254G2PublicKey(privateKeyHex: string): Promise<{
51
+ x: { c0: bigint; c1: bigint };
52
+ y: { c0: bigint; c1: bigint };
53
+ }> {
54
+ const sk = BigInt(privateKeyHex);
55
+ const skReduced = sk % Fr.MODULUS;
56
+
57
+ const scalar = Fr.fromString(skReduced.toString());
58
+ const pk2 = await Bn254G2Point.generator(scalar);
59
+
60
+ return {
61
+ x: { c0: pk2.x[0].toBigInt(), c1: pk2.x[1].toBigInt() },
62
+ y: { c0: pk2.y[0].toBigInt(), c1: pk2.y[1].toBigInt() },
63
+ };
64
+ }
@@ -16,7 +16,7 @@ export class Ecdsa {
16
16
  * @returns A secp256k1 public key.
17
17
  */
18
18
  public async computePublicKey(privateKey: Buffer): Promise<Buffer> {
19
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
19
+ await BarretenbergSync.initSingleton();
20
20
  const api = BarretenbergSync.getSingleton();
21
21
  const response =
22
22
  this.curve === 'secp256r1'
@@ -32,7 +32,7 @@ export class Ecdsa {
32
32
  * @returns An ECDSA signature of the form (r, s, v).
33
33
  */
34
34
  public async constructSignature(msg: Uint8Array, privateKey: Buffer) {
35
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
35
+ await BarretenbergSync.initSingleton();
36
36
  const api = BarretenbergSync.getSingleton();
37
37
  const response =
38
38
  this.curve === 'secp256r1'
@@ -48,7 +48,7 @@ export class Ecdsa {
48
48
  * @returns The secp256k1 public key of the signer.
49
49
  */
50
50
  public async recoverPublicKey(msg: Uint8Array, sig: EcdsaSignature): Promise<Buffer> {
51
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
51
+ await BarretenbergSync.initSingleton();
52
52
  const api = BarretenbergSync.getSingleton();
53
53
  const response =
54
54
  this.curve === 'secp256r1'
@@ -65,7 +65,7 @@ export class Ecdsa {
65
65
  * @returns True or false.
66
66
  */
67
67
  public async verifySignature(msg: Uint8Array, pubKey: Buffer, sig: EcdsaSignature) {
68
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
68
+ await BarretenbergSync.initSingleton();
69
69
  const api = BarretenbergSync.getSingleton();
70
70
  const response =
71
71
  this.curve === 'secp256r1'
@@ -1,6 +1,6 @@
1
1
  import { toBufferBE } from '@aztec/foundation/bigint-buffer';
2
- import { randomBytes } from '@aztec/foundation/crypto';
3
- import { Fr } from '@aztec/foundation/fields';
2
+ import { randomBytes } from '@aztec/foundation/crypto/random';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { mapTuple } from '@aztec/foundation/serialize';
5
5
 
6
6
  import type { Signature } from '../signature/index.js';
@@ -1,34 +1,28 @@
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.
6
8
  */
7
9
  export class Grumpkin {
8
10
  // prettier-ignore
9
- static generator = Point.fromBuffer(Buffer.from([
11
+ static readonly generator = Point.fromBuffer(Buffer.from([
10
12
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
11
13
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
12
14
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xcf, 0x13, 0x5e, 0x75, 0x06, 0xa4, 0x5d, 0x63,
13
15
  0x2d, 0x27, 0x0d, 0x45, 0xf1, 0x18, 0x12, 0x94, 0x83, 0x3f, 0xc4, 0x8d, 0x82, 0x3f, 0x27, 0x2c,
14
16
  ]));
15
17
 
16
- /**
17
- * Point generator
18
- * @returns The generator for the curve.
19
- */
20
- public generator(): Point {
21
- return Grumpkin.generator;
22
- }
23
-
24
18
  /**
25
19
  * Multiplies a point by a scalar (adds the point `scalar` amount of times).
26
20
  * @param point - Point to multiply.
27
21
  * @param scalar - Scalar to multiply by.
28
22
  * @returns Result of the multiplication.
29
23
  */
30
- public async mul(point: Point, scalar: GrumpkinScalar): Promise<Point> {
31
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
24
+ public static async mul(point: Point, scalar: GrumpkinScalar): Promise<Point> {
25
+ await BarretenbergSync.initSingleton();
32
26
  const api = BarretenbergSync.getSingleton();
33
27
  const response = api.grumpkinMul({
34
28
  point: { x: point.x.toBuffer(), y: point.y.toBuffer() },
@@ -43,8 +37,8 @@ export class Grumpkin {
43
37
  * @param b - Point b to add to a
44
38
  * @returns Result of the addition.
45
39
  */
46
- public async add(a: Point, b: Point): Promise<Point> {
47
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
40
+ public static async add(a: Point, b: Point): Promise<Point> {
41
+ await BarretenbergSync.initSingleton();
48
42
  const api = BarretenbergSync.getSingleton();
49
43
  const response = api.grumpkinAdd({
50
44
  pointA: { x: a.x.toBuffer(), y: a.y.toBuffer() },
@@ -59,8 +53,8 @@ export class Grumpkin {
59
53
  * @param scalar - Scalar to multiply by.
60
54
  * @returns Points multiplied by the scalar.
61
55
  */
62
- public async batchMul(points: Point[], scalar: GrumpkinScalar) {
63
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
56
+ public static async batchMul(points: Point[], scalar: GrumpkinScalar) {
57
+ await BarretenbergSync.initSingleton();
64
58
  const api = BarretenbergSync.getSingleton();
65
59
  const response = api.grumpkinBatchMul({
66
60
  points: points.map(p => ({ x: p.x.toBuffer(), y: p.y.toBuffer() })),
@@ -74,8 +68,8 @@ export class Grumpkin {
74
68
  * Gets a random field element.
75
69
  * @returns Random field element.
76
70
  */
77
- public async getRandomFr(): Promise<Fr> {
78
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
71
+ public static async getRandomFr(): Promise<Fr> {
72
+ await BarretenbergSync.initSingleton();
79
73
  const api = BarretenbergSync.getSingleton();
80
74
  const response = api.grumpkinGetRandomFr({ dummy: 0 });
81
75
  return Fr.fromBuffer(Buffer.from(response.value));
@@ -86,8 +80,8 @@ export class Grumpkin {
86
80
  * @param uint512Buf - The buffer to convert.
87
81
  * @returns Buffer representation of the field element.
88
82
  */
89
- public async reduce512BufferToFr(uint512Buf: Buffer): Promise<Fr> {
90
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
83
+ public static async reduce512BufferToFr(uint512Buf: Buffer): Promise<Fr> {
84
+ await BarretenbergSync.initSingleton();
91
85
  const api = BarretenbergSync.getSingleton();
92
86
  const response = api.grumpkinReduce512({ input: uint512Buf });
93
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
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,7 +10,7 @@ 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 });
13
+ await BarretenbergSync.initSingleton();
14
14
  const api = BarretenbergSync.getSingleton();
15
15
  const response = api.poseidon2Hash({
16
16
  inputs: inputFields.map(i => i.toBuffer()),
@@ -27,7 +27,7 @@ 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 });
30
+ await BarretenbergSync.initSingleton();
31
31
  const api = BarretenbergSync.getSingleton();
32
32
  const response = api.poseidon2Hash({
33
33
  inputs: inputFields.map(i => i.toBuffer()),
@@ -37,7 +37,7 @@ export async function poseidon2HashWithSeparator(input: Fieldable[], separator:
37
37
 
38
38
  export async function poseidon2HashAccumulate(input: Fieldable[]): Promise<Fr> {
39
39
  const inputFields = serializeToFields(input);
40
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
40
+ await BarretenbergSync.initSingleton();
41
41
  const api = BarretenbergSync.getSingleton();
42
42
  const response = api.poseidon2HashAccumulate({
43
43
  inputs: inputFields.map(i => i.toBuffer()),
@@ -54,7 +54,7 @@ export async function poseidon2Permutation(input: Fieldable[]): Promise<Fr[]> {
54
54
  const inputFields = serializeToFields(input);
55
55
  // We'd like this assertion but it's not possible to use it in the browser.
56
56
  // assert(input.length === 4, 'Input state must be of size 4');
57
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
57
+ await BarretenbergSync.initSingleton();
58
58
  const api = BarretenbergSync.getSingleton();
59
59
  const response = api.poseidon2Permutation({
60
60
  inputs: inputFields.map(i => i.toBuffer()),
@@ -75,7 +75,7 @@ export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
75
75
  inputFields.push(Fr.fromBuffer(fieldBytes));
76
76
  }
77
77
 
78
- await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
78
+ await BarretenbergSync.initSingleton();
79
79
  const api = BarretenbergSync.getSingleton();
80
80
  const response = api.poseidon2Hash({
81
81
  inputs: inputFields.map(i => i.toBuffer()),