@aztec/foundation 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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 (473) hide show
  1. package/dest/array/index.d.ts +2 -1
  2. package/dest/array/index.d.ts.map +1 -1
  3. package/dest/array/index.js +1 -0
  4. package/dest/array/sorted_array.d.ts +15 -0
  5. package/dest/array/sorted_array.d.ts.map +1 -0
  6. package/dest/array/sorted_array.js +109 -0
  7. package/dest/bigint-buffer/index.d.ts +1 -1
  8. package/dest/bigint-buffer/index.d.ts.map +1 -1
  9. package/dest/bigint-buffer/index.js +6 -1
  10. package/dest/branded-types/block_number.d.ts +6 -3
  11. package/dest/branded-types/block_number.d.ts.map +1 -1
  12. package/dest/branded-types/block_number.js +18 -4
  13. package/dest/branded-types/buffer32_hash.d.ts +27 -0
  14. package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
  15. package/dest/branded-types/buffer32_hash.js +12 -0
  16. package/dest/branded-types/checkpoint_number.d.ts +17 -3
  17. package/dest/branded-types/checkpoint_number.d.ts.map +1 -1
  18. package/dest/branded-types/checkpoint_number.js +28 -8
  19. package/dest/branded-types/epoch.d.ts +2 -2
  20. package/dest/branded-types/epoch.d.ts.map +1 -1
  21. package/dest/branded-types/index.d.ts +4 -2
  22. package/dest/branded-types/index.d.ts.map +1 -1
  23. package/dest/branded-types/index.js +3 -1
  24. package/dest/branded-types/index_within_checkpoint.d.ts +42 -0
  25. package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -0
  26. package/dest/branded-types/index_within_checkpoint.js +59 -0
  27. package/dest/branded-types/slot.d.ts +5 -2
  28. package/dest/branded-types/slot.d.ts.map +1 -1
  29. package/dest/branded-types/slot.js +3 -0
  30. package/dest/buffer/buffer16.d.ts +7 -2
  31. package/dest/buffer/buffer16.d.ts.map +1 -1
  32. package/dest/buffer/buffer16.js +4 -2
  33. package/dest/buffer/buffer32.d.ts +29 -59
  34. package/dest/buffer/buffer32.d.ts.map +1 -1
  35. package/dest/buffer/buffer32.js +33 -65
  36. package/dest/buffer/index.d.ts +2 -1
  37. package/dest/buffer/index.d.ts.map +1 -1
  38. package/dest/buffer/index.js +1 -0
  39. package/dest/buffer/utils.d.ts +3 -0
  40. package/dest/buffer/utils.d.ts.map +1 -0
  41. package/dest/buffer/utils.js +7 -0
  42. package/dest/collection/array.d.ts +22 -1
  43. package/dest/collection/array.d.ts.map +1 -1
  44. package/dest/collection/array.js +84 -0
  45. package/dest/collection/index.d.ts +3 -1
  46. package/dest/collection/index.d.ts.map +1 -1
  47. package/dest/collection/index.js +2 -0
  48. package/dest/collection/lru_map.d.ts +41 -0
  49. package/dest/collection/lru_map.d.ts.map +1 -0
  50. package/dest/collection/lru_map.js +119 -0
  51. package/dest/collection/lru_set.d.ts +35 -0
  52. package/dest/collection/lru_set.d.ts.map +1 -0
  53. package/dest/collection/lru_set.js +95 -0
  54. package/dest/committable/committable.js +1 -1
  55. package/dest/config/env_var.d.ts +2 -2
  56. package/dest/config/env_var.d.ts.map +1 -1
  57. package/dest/config/index.d.ts +79 -38
  58. package/dest/config/index.d.ts.map +1 -1
  59. package/dest/config/index.js +103 -64
  60. package/dest/config/network_config.d.ts +17 -31
  61. package/dest/config/network_config.d.ts.map +1 -1
  62. package/dest/config/network_config.js +6 -1
  63. package/dest/config/network_name.d.ts +2 -2
  64. package/dest/config/network_name.d.ts.map +1 -1
  65. package/dest/config/network_name.js +3 -3
  66. package/dest/config/parse-env.d.ts +3 -0
  67. package/dest/config/parse-env.d.ts.map +1 -0
  68. package/dest/config/parse-env.js +7 -0
  69. package/dest/config/secret_value.d.ts +2 -2
  70. package/dest/config/secret_value.d.ts.map +1 -1
  71. package/dest/config/secret_value.js +3 -1
  72. package/dest/crypto/aes128/index.d.ts +2 -1
  73. package/dest/crypto/aes128/index.d.ts.map +1 -1
  74. package/dest/crypto/aes128/index.js +11 -2
  75. package/dest/crypto/bls/bn254_keystore.d.ts +10 -177
  76. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
  77. package/dest/crypto/bls/bn254_keystore.js +23 -35
  78. package/dest/crypto/bls/index.js +1 -1
  79. package/dest/crypto/bn254/index.d.ts +35 -51
  80. package/dest/crypto/bn254/index.d.ts.map +1 -1
  81. package/dest/crypto/bn254/index.js +51 -140
  82. package/dest/crypto/ecdsa/signature.d.ts +11 -2
  83. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  84. package/dest/crypto/ecdsa/signature.js +2 -2
  85. package/dest/crypto/grumpkin/index.d.ts +4 -2
  86. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  87. package/dest/crypto/grumpkin/index.js +2 -1
  88. package/dest/crypto/keys/index.d.ts +4 -3
  89. package/dest/crypto/keys/index.d.ts.map +1 -1
  90. package/dest/crypto/keys/index.js +31 -7
  91. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
  92. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  93. package/dest/crypto/pedersen/pedersen.wasm.js +1 -1
  94. package/dest/crypto/poseidon/index.d.ts +2 -3
  95. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  96. package/dest/crypto/poseidon/index.js +41 -43
  97. package/dest/crypto/random/randomness_singleton.d.ts +4 -3
  98. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  99. package/dest/crypto/random/randomness_singleton.js +5 -5
  100. package/dest/crypto/schnorr/index.d.ts +10 -8
  101. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  102. package/dest/crypto/schnorr/index.js +7 -7
  103. package/dest/crypto/schnorr/signature.d.ts +10 -30
  104. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  105. package/dest/crypto/schnorr/signature.js +21 -37
  106. package/dest/crypto/secp256k1-signer/utils.d.ts +12 -1
  107. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  108. package/dest/crypto/secp256k1-signer/utils.js +26 -0
  109. package/dest/crypto/sha256/index.d.ts +2 -2
  110. package/dest/crypto/sha256/index.d.ts.map +1 -1
  111. package/dest/crypto/sha256/index.js +1 -1
  112. package/dest/crypto/sha512/index.d.ts +2 -2
  113. package/dest/crypto/sha512/index.d.ts.map +1 -1
  114. package/dest/crypto/sha512/index.js +1 -1
  115. package/dest/crypto/signature/index.d.ts +2 -2
  116. package/dest/crypto/signature/index.d.ts.map +1 -1
  117. package/dest/crypto/sync/pedersen/index.d.ts +2 -2
  118. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  119. package/dest/crypto/sync/pedersen/index.js +1 -1
  120. package/dest/crypto/sync/poseidon/index.d.ts +2 -3
  121. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  122. package/dest/crypto/sync/poseidon/index.js +1 -9
  123. package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +5 -5
  124. package/dest/curves/bls12/field.d.ts.map +1 -0
  125. package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +11 -13
  126. package/dest/curves/bls12/index.d.ts +3 -0
  127. package/dest/curves/bls12/index.d.ts.map +1 -0
  128. package/dest/curves/bls12/index.js +2 -0
  129. package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +14 -5
  130. package/dest/curves/bls12/point.d.ts.map +1 -0
  131. package/dest/{fields/bls12_point.js → curves/bls12/point.js} +10 -8
  132. package/dest/curves/bn254/field.d.ts +185 -0
  133. package/dest/curves/bn254/field.d.ts.map +1 -0
  134. package/dest/{fields/fields.js → curves/bn254/field.js} +57 -62
  135. package/dest/curves/bn254/index.d.ts +3 -0
  136. package/dest/curves/bn254/index.d.ts.map +1 -0
  137. package/dest/curves/bn254/index.js +2 -0
  138. package/dest/curves/bn254/point.d.ts +54 -0
  139. package/dest/curves/bn254/point.d.ts.map +1 -0
  140. package/dest/curves/bn254/point.js +143 -0
  141. package/dest/curves/grumpkin/index.d.ts +10 -0
  142. package/dest/curves/grumpkin/index.d.ts.map +1 -0
  143. package/dest/curves/grumpkin/index.js +3 -0
  144. package/dest/{fields → curves/grumpkin}/point.d.ts +23 -28
  145. package/dest/curves/grumpkin/point.d.ts.map +1 -0
  146. package/dest/{fields → curves/grumpkin}/point.js +35 -49
  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 +4 -3
  150. package/dest/eth-address/index.d.ts.map +1 -1
  151. package/dest/eth-address/index.js +10 -6
  152. package/dest/eth-signature/eth_signature.d.ts +6 -2
  153. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  154. package/dest/eth-signature/eth_signature.js +7 -2
  155. package/dest/fifo/fifo_frame_reader.d.ts +41 -0
  156. package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
  157. package/dest/fifo/fifo_frame_reader.js +91 -0
  158. package/dest/fifo/index.d.ts +2 -0
  159. package/dest/fifo/index.d.ts.map +1 -0
  160. package/dest/fifo/index.js +1 -0
  161. package/dest/fifo_set/fifo_set.d.ts +15 -0
  162. package/dest/fifo_set/fifo_set.d.ts.map +1 -0
  163. package/dest/fifo_set/fifo_set.js +39 -0
  164. package/dest/fifo_set/index.d.ts +2 -0
  165. package/dest/fifo_set/index.d.ts.map +1 -0
  166. package/dest/fifo_set/index.js +1 -0
  167. package/dest/iterator/filter.d.ts +3 -0
  168. package/dest/iterator/filter.d.ts.map +1 -0
  169. package/dest/iterator/filter.js +7 -0
  170. package/dest/iterator/index.d.ts +2 -0
  171. package/dest/iterator/index.d.ts.map +1 -0
  172. package/dest/iterator/index.js +1 -0
  173. package/dest/jest/setup.js +28 -1
  174. package/dest/json-rpc/client/fetch.d.ts +1 -1
  175. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  176. package/dest/json-rpc/client/fetch.js +4 -3
  177. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
  178. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  179. package/dest/json-rpc/client/safe_json_rpc_client.js +3 -3
  180. package/dest/json-rpc/client/undici.d.ts +1 -1
  181. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  182. package/dest/json-rpc/client/undici.js +23 -4
  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 +4 -8
  188. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -1
  189. package/dest/json-rpc/fixtures/test_state.js +57 -17
  190. package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
  191. package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
  192. package/dest/json-rpc/server/api_key_auth.js +57 -0
  193. package/dest/json-rpc/server/index.d.ts +2 -1
  194. package/dest/json-rpc/server/index.d.ts.map +1 -1
  195. package/dest/json-rpc/server/index.js +1 -0
  196. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +8 -3
  197. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  198. package/dest/json-rpc/server/safe_json_rpc_server.js +28 -14
  199. package/dest/log/bigint-utils.d.ts +5 -0
  200. package/dest/log/bigint-utils.d.ts.map +1 -0
  201. package/dest/log/bigint-utils.js +21 -0
  202. package/dest/log/gcloud-logger-config.d.ts +1 -1
  203. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  204. package/dest/log/gcloud-logger-config.js +3 -0
  205. package/dest/log/libp2p_logger.d.ts +5 -2
  206. package/dest/log/libp2p_logger.d.ts.map +1 -1
  207. package/dest/log/libp2p_logger.js +14 -4
  208. package/dest/log/log-filters.d.ts +17 -4
  209. package/dest/log/log-filters.d.ts.map +1 -1
  210. package/dest/log/log-filters.js +26 -12
  211. package/dest/log/pino-logger-server.d.ts +9 -0
  212. package/dest/log/pino-logger-server.d.ts.map +1 -0
  213. package/dest/log/pino-logger-server.js +18 -0
  214. package/dest/log/pino-logger.d.ts +37 -8
  215. package/dest/log/pino-logger.d.ts.map +1 -1
  216. package/dest/log/pino-logger.js +138 -30
  217. package/dest/noir/noir_package_config.d.ts +19 -104
  218. package/dest/noir/noir_package_config.d.ts.map +1 -1
  219. package/dest/noir/noir_package_config.js +1 -1
  220. package/dest/promise/running-promise.d.ts +5 -4
  221. package/dest/promise/running-promise.d.ts.map +1 -1
  222. package/dest/promise/running-promise.js +7 -3
  223. package/dest/queue/base_memory_queue.d.ts +2 -2
  224. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  225. package/dest/queue/batch_queue.d.ts +1 -1
  226. package/dest/queue/batch_queue.d.ts.map +1 -1
  227. package/dest/queue/batch_queue.js +1 -0
  228. package/dest/queue/semaphore.d.ts +5 -1
  229. package/dest/queue/semaphore.d.ts.map +1 -1
  230. package/dest/retry/index.d.ts +41 -3
  231. package/dest/retry/index.d.ts.map +1 -1
  232. package/dest/retry/index.js +55 -2
  233. package/dest/schemas/api.d.ts +12 -10
  234. package/dest/schemas/api.d.ts.map +1 -1
  235. package/dest/schemas/api.js +7 -1
  236. package/dest/schemas/parse.d.ts +4 -4
  237. package/dest/schemas/parse.d.ts.map +1 -1
  238. package/dest/schemas/parse.js +6 -5
  239. package/dest/schemas/schemas.d.ts +20 -16
  240. package/dest/schemas/schemas.d.ts.map +1 -1
  241. package/dest/schemas/schemas.js +9 -3
  242. package/dest/schemas/types.d.ts +32 -2
  243. package/dest/schemas/types.d.ts.map +1 -1
  244. package/dest/schemas/types.js +25 -1
  245. package/dest/schemas/utils.d.ts +7 -11
  246. package/dest/schemas/utils.d.ts.map +1 -1
  247. package/dest/schemas/utils.js +2 -18
  248. package/dest/serialize/buffer_reader.d.ts +14 -4
  249. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  250. package/dest/serialize/buffer_reader.js +26 -4
  251. package/dest/serialize/buffer_sink.d.ts +134 -0
  252. package/dest/serialize/buffer_sink.d.ts.map +1 -0
  253. package/dest/serialize/buffer_sink.js +297 -0
  254. package/dest/serialize/field_reader.d.ts +2 -2
  255. package/dest/serialize/field_reader.d.ts.map +1 -1
  256. package/dest/serialize/field_reader.js +1 -1
  257. package/dest/serialize/free_funcs.d.ts +2 -2
  258. package/dest/serialize/free_funcs.d.ts.map +1 -1
  259. package/dest/serialize/free_funcs.js +1 -1
  260. package/dest/serialize/index.d.ts +2 -1
  261. package/dest/serialize/index.d.ts.map +1 -1
  262. package/dest/serialize/index.js +1 -0
  263. package/dest/serialize/serialize.d.ts +20 -2
  264. package/dest/serialize/serialize.d.ts.map +1 -1
  265. package/dest/serialize/serialize.js +32 -1
  266. package/dest/sleep/index.d.ts +4 -1
  267. package/dest/sleep/index.d.ts.map +1 -1
  268. package/dest/sleep/index.js +14 -1
  269. package/dest/string/index.js +1 -1
  270. package/dest/testing/files/index.d.ts +2 -3
  271. package/dest/testing/files/index.d.ts.map +1 -1
  272. package/dest/testing/files/index.js +1 -2
  273. package/dest/timer/date.d.ts +26 -1
  274. package/dest/timer/date.d.ts.map +1 -1
  275. package/dest/timer/date.js +36 -0
  276. package/dest/timer/index.d.ts +2 -2
  277. package/dest/timer/index.d.ts.map +1 -1
  278. package/dest/timer/index.js +1 -1
  279. package/dest/timer/timeout.d.ts +3 -1
  280. package/dest/timer/timeout.d.ts.map +1 -1
  281. package/dest/timer/timeout.js +26 -0
  282. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
  283. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
  284. package/dest/transport/index.d.ts +1 -2
  285. package/dest/transport/index.d.ts.map +1 -1
  286. package/dest/transport/index.js +0 -1
  287. package/dest/transport/transport_client.js +2 -2
  288. package/dest/trees/balanced_merkle_tree_root.d.ts +16 -0
  289. package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -0
  290. package/dest/trees/{balanced_merkle_tree.js → balanced_merkle_tree_root.js} +3 -17
  291. package/dest/trees/hasher.d.ts +4 -1
  292. package/dest/trees/hasher.d.ts.map +1 -1
  293. package/dest/trees/hasher.js +10 -5
  294. package/dest/trees/index.d.ts +4 -4
  295. package/dest/trees/index.d.ts.map +1 -1
  296. package/dest/trees/index.js +3 -3
  297. package/dest/trees/indexed_merkle_tree.js +1 -1
  298. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  299. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  300. package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
  301. package/dest/trees/membership_witness.d.ts +9 -3
  302. package/dest/trees/membership_witness.d.ts.map +1 -1
  303. package/dest/trees/membership_witness.js +1 -1
  304. package/dest/trees/merkle_tree_calculator.d.ts +4 -2
  305. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  306. package/dest/trees/merkle_tree_calculator.js +1 -5
  307. package/dest/trees/sibling_path.d.ts +7 -5
  308. package/dest/trees/sibling_path.d.ts.map +1 -1
  309. package/dest/trees/sibling_path.js +11 -9
  310. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +2 -3
  311. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
  312. package/dest/trees/unbalanced_merkle_tree_calculator.js +1 -5
  313. package/dest/trees/{unbalanced_merkle_tree.d.ts → unbalanced_merkle_tree_root.d.ts} +4 -7
  314. package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
  315. package/dest/trees/{unbalanced_merkle_tree.js → unbalanced_merkle_tree_root.js} +12 -51
  316. package/dest/trees/unbalanced_tree_store.d.ts +5 -1
  317. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  318. package/dest/trees/unbalanced_tree_store.js +49 -1
  319. package/dest/types/index.d.ts +28 -2
  320. package/dest/types/index.d.ts.map +1 -1
  321. package/dest/types/index.js +21 -0
  322. package/package.json +50 -9
  323. package/src/array/index.ts +1 -0
  324. package/src/array/sorted_array.ts +138 -0
  325. package/src/bigint-buffer/index.ts +6 -1
  326. package/src/branded-types/block_number.ts +25 -2
  327. package/src/branded-types/buffer32_hash.ts +38 -0
  328. package/src/branded-types/checkpoint_number.ts +37 -7
  329. package/src/branded-types/epoch.ts +1 -1
  330. package/src/branded-types/index.ts +3 -1
  331. package/src/branded-types/index_within_checkpoint.ts +88 -0
  332. package/src/branded-types/slot.ts +6 -1
  333. package/src/buffer/buffer16.ts +5 -2
  334. package/src/buffer/buffer32.ts +41 -70
  335. package/src/buffer/index.ts +1 -0
  336. package/src/buffer/utils.ts +8 -0
  337. package/src/collection/array.ts +86 -0
  338. package/src/collection/index.ts +2 -0
  339. package/src/collection/lru_map.ts +143 -0
  340. package/src/collection/lru_set.ts +115 -0
  341. package/src/committable/committable.ts +1 -1
  342. package/src/config/env_var.ts +127 -34
  343. package/src/config/index.ts +183 -114
  344. package/src/config/network_config.ts +5 -0
  345. package/src/config/network_name.ts +6 -6
  346. package/src/config/parse-env.ts +4 -0
  347. package/src/config/secret_value.ts +1 -1
  348. package/src/crypto/aes128/index.ts +11 -2
  349. package/src/crypto/bls/bn254_keystore.ts +34 -44
  350. package/src/crypto/bls/index.ts +1 -1
  351. package/src/crypto/bn254/index.ts +50 -159
  352. package/src/crypto/ecdsa/signature.ts +2 -2
  353. package/src/crypto/grumpkin/index.ts +3 -1
  354. package/src/crypto/keys/index.ts +21 -5
  355. package/src/crypto/pedersen/pedersen.wasm.ts +1 -1
  356. package/src/crypto/poseidon/index.ts +43 -45
  357. package/src/crypto/random/randomness_singleton.ts +6 -4
  358. package/src/crypto/schnorr/index.ts +11 -9
  359. package/src/crypto/schnorr/signature.ts +18 -47
  360. package/src/crypto/secp256k1-signer/utils.ts +32 -0
  361. package/src/crypto/sha256/index.ts +1 -1
  362. package/src/crypto/sha512/index.ts +1 -1
  363. package/src/crypto/signature/index.ts +1 -1
  364. package/src/crypto/sync/pedersen/index.ts +1 -1
  365. package/src/crypto/sync/poseidon/index.ts +1 -10
  366. package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +5 -12
  367. package/src/curves/bls12/index.ts +2 -0
  368. package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +7 -7
  369. package/src/{fields/fields.ts → curves/bn254/field.ts} +68 -86
  370. package/src/curves/bn254/index.ts +2 -0
  371. package/src/curves/bn254/point.ts +170 -0
  372. package/src/curves/grumpkin/index.ts +11 -0
  373. package/src/{fields → curves/grumpkin}/point.ts +29 -46
  374. package/src/eth-address/index.ts +8 -6
  375. package/src/eth-signature/eth_signature.ts +7 -1
  376. package/src/fifo/fifo_frame_reader.ts +113 -0
  377. package/src/fifo/index.ts +1 -0
  378. package/src/fifo_set/fifo_set.ts +52 -0
  379. package/src/fifo_set/index.ts +1 -0
  380. package/src/iterator/filter.ts +11 -0
  381. package/src/iterator/index.ts +1 -0
  382. package/src/jest/setup.mjs +31 -1
  383. package/src/json-rpc/client/fetch.ts +4 -3
  384. package/src/json-rpc/client/safe_json_rpc_client.ts +4 -2
  385. package/src/json-rpc/client/undici.ts +23 -3
  386. package/src/json-rpc/fixtures/test_state.ts +10 -10
  387. package/src/json-rpc/server/api_key_auth.ts +63 -0
  388. package/src/json-rpc/server/index.ts +1 -0
  389. package/src/json-rpc/server/safe_json_rpc_server.ts +32 -14
  390. package/src/log/bigint-utils.ts +25 -0
  391. package/src/log/gcloud-logger-config.ts +5 -0
  392. package/src/log/libp2p_logger.ts +12 -5
  393. package/src/log/log-filters.ts +29 -11
  394. package/src/log/pino-logger-server.ts +25 -0
  395. package/src/log/pino-logger.ts +162 -40
  396. package/src/noir/noir_package_config.ts +32 -20
  397. package/src/promise/running-promise.ts +8 -5
  398. package/src/queue/base_memory_queue.ts +1 -1
  399. package/src/queue/batch_queue.ts +1 -0
  400. package/src/queue/semaphore.ts +5 -0
  401. package/src/retry/index.ts +84 -4
  402. package/src/schemas/api.ts +25 -25
  403. package/src/schemas/parse.ts +9 -6
  404. package/src/schemas/schemas.ts +17 -6
  405. package/src/schemas/types.ts +34 -1
  406. package/src/schemas/utils.ts +4 -38
  407. package/src/serialize/buffer_reader.ts +36 -9
  408. package/src/serialize/buffer_sink.ts +350 -0
  409. package/src/serialize/field_reader.ts +1 -1
  410. package/src/serialize/free_funcs.ts +1 -1
  411. package/src/serialize/index.ts +1 -0
  412. package/src/serialize/serialize.ts +33 -1
  413. package/src/sleep/index.ts +16 -1
  414. package/src/string/index.ts +1 -1
  415. package/src/testing/files/index.ts +1 -2
  416. package/src/timer/date.ts +52 -0
  417. package/src/timer/index.ts +1 -1
  418. package/src/timer/timeout.ts +31 -0
  419. package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
  420. package/src/transport/index.ts +0 -1
  421. package/src/transport/transport_client.ts +2 -2
  422. package/src/trees/{balanced_merkle_tree.ts → balanced_merkle_tree_root.ts} +3 -20
  423. package/src/trees/hasher.ts +12 -0
  424. package/src/trees/index.ts +3 -3
  425. package/src/trees/indexed_merkle_tree.ts +1 -1
  426. package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
  427. package/src/trees/membership_witness.ts +1 -1
  428. package/src/trees/merkle_tree_calculator.ts +4 -10
  429. package/src/trees/sibling_path.ts +12 -7
  430. package/src/trees/unbalanced_merkle_tree_calculator.ts +1 -12
  431. package/src/trees/{unbalanced_merkle_tree.ts → unbalanced_merkle_tree_root.ts} +17 -64
  432. package/src/trees/unbalanced_tree_store.ts +57 -2
  433. package/src/types/index.ts +58 -1
  434. package/dest/crypto/bn254/bn254_utils.d.ts +0 -39
  435. package/dest/crypto/bn254/bn254_utils.d.ts.map +0 -1
  436. package/dest/crypto/bn254/bn254_utils.js +0 -56
  437. package/dest/crypto/index.d.ts +0 -17
  438. package/dest/crypto/index.d.ts.map +0 -1
  439. package/dest/crypto/index.js +0 -16
  440. package/dest/crypto/serialize.d.ts +0 -51
  441. package/dest/crypto/serialize.d.ts.map +0 -1
  442. package/dest/crypto/serialize.js +0 -68
  443. package/dest/fields/bls12_fields.d.ts.map +0 -1
  444. package/dest/fields/bls12_point.d.ts.map +0 -1
  445. package/dest/fields/coordinate.d.ts +0 -63
  446. package/dest/fields/coordinate.d.ts.map +0 -1
  447. package/dest/fields/coordinate.js +0 -96
  448. package/dest/fields/fields.d.ts +0 -188
  449. package/dest/fields/fields.d.ts.map +0 -1
  450. package/dest/fields/index.d.ts +0 -6
  451. package/dest/fields/index.d.ts.map +0 -1
  452. package/dest/fields/index.js +0 -5
  453. package/dest/fields/point.d.ts.map +0 -1
  454. package/dest/index.d.ts +0 -31
  455. package/dest/index.d.ts.map +0 -1
  456. package/dest/index.js +0 -31
  457. package/dest/json-rpc/server/telemetry.d.ts +0 -2
  458. package/dest/json-rpc/server/telemetry.d.ts.map +0 -1
  459. package/dest/json-rpc/server/telemetry.js +0 -0
  460. package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
  461. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
  462. package/dest/transport/dispatch/create_dispatch_fn.js +0 -17
  463. package/dest/trees/balanced_merkle_tree.d.ts +0 -22
  464. package/dest/trees/balanced_merkle_tree.d.ts.map +0 -1
  465. package/dest/trees/unbalanced_merkle_tree.d.ts.map +0 -1
  466. package/src/crypto/bn254/bn254_utils.ts +0 -64
  467. package/src/crypto/index.ts +0 -16
  468. package/src/crypto/serialize.ts +0 -85
  469. package/src/fields/coordinate.ts +0 -104
  470. package/src/fields/index.ts +0 -5
  471. package/src/index.ts +0 -31
  472. package/src/json-rpc/server/telemetry.ts +0 -0
  473. package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
@@ -1,173 +1,64 @@
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 '../../fields/fields.js';
1
+ import { Fr } from '../../curves/bn254/field.js';
2
+ import { Bn254G1Point, Bn254G2Point } from '../../curves/bn254/point.js';
10
3
 
11
4
  /**
12
- * BN254 G1 point using foundation field classes.
13
- * Represents a point on the BN254 elliptic curve in affine coordinates.
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.
14
8
  */
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
9
 
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
- }
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;
99
19
 
100
- equals(other: Bn254G1Point): boolean {
101
- return this.x.equals(other.x) && this.y.equals(other.y);
102
- }
20
+ // Generate G1 point on BN254 curve using bb.js
21
+ const scalar = Fr.fromString(skReduced.toString());
22
+ const pk1 = await Bn254G1Point.generator(scalar);
103
23
 
104
- toString(): string {
105
- return `Bn254G1Point(x: ${this.x.toString()}, y: ${this.y.toString()})`;
106
- }
24
+ // Compress the point using the primitive method
25
+ return '0x' + pk1.compress().toString('hex');
107
26
  }
108
27
 
109
28
  /**
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).
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
113
33
  */
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();
34
+ export async function computeBn254G1PublicKey(privateKeyHex: string): Promise<{ x: bigint; y: bigint }> {
35
+ const sk = BigInt(privateKeyHex);
36
+ const skReduced = sk % Fr.MODULUS;
149
37
 
150
- const response = api.bn254G2Mul({
151
- point: BN254_G2_GENERATOR as BbApiBn254G2Point,
152
- scalar: scalar.toBuffer(),
153
- });
38
+ const scalar = Fr.fromString(skReduced.toString());
39
+ const pk1 = await Bn254G1Point.generator(scalar);
154
40
 
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
- }
41
+ return { x: pk1.x.toBigInt(), y: pk1.y.toBigInt() };
170
42
  }
171
43
 
172
- // Re-export BN254 point utility functions
173
- export { computeBn254G1PublicKeyCompressed, computeBn254G1PublicKey, computeBn254G2PublicKey } from './bn254_utils.js';
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
+ }
@@ -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,5 +1,7 @@
1
1
  import { BarretenbergSync } from '@aztec/bb.js';
2
- import { Fr, type GrumpkinScalar, Point } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
4
+ import { Point } from '@aztec/foundation/curves/grumpkin';
3
5
 
4
6
  /**
5
7
  * Grumpkin elliptic curve operations.
@@ -1,10 +1,26 @@
1
- import { BarretenbergSync } from '@aztec/bb.js';
1
+ import { BarretenbergSync, CircuitKind } from '@aztec/bb.js';
2
2
 
3
- import { Fr } from '../../fields/fields.js';
3
+ import { Fr } from '../../curves/bn254/field.js';
4
4
 
5
- export async function vkAsFieldsMegaHonk(input: Buffer): Promise<Fr[]> {
5
+ export async function vkAsFields(input: Buffer, kind: CircuitKind): Promise<Fr[]> {
6
6
  await BarretenbergSync.initSingleton();
7
7
  const api = BarretenbergSync.getSingleton();
8
- const response = api.megaVkAsFields({ verificationKey: input });
9
- return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
8
+ switch (kind) {
9
+ case CircuitKind.App: {
10
+ const response = api.megaAppVkAsFields({ verificationKey: input });
11
+ return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
12
+ }
13
+ case CircuitKind.Kernel: {
14
+ const response = api.megaKernelVkAsFields({ verificationKey: input });
15
+ return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
16
+ }
17
+ case CircuitKind.HidingKernel: {
18
+ const response = api.megaZKVkAsFields({ verificationKey: input });
19
+ return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
20
+ }
21
+ default: {
22
+ const _exhaustive: never = kind;
23
+ throw new Error(`vkAsFields: unhandled CircuitKind ${_exhaustive}`);
24
+ }
25
+ }
10
26
  }
@@ -1,6 +1,6 @@
1
1
  import { BarretenbergSync } from '@aztec/bb.js';
2
2
 
3
- import { Fr } from '../../fields/fields.js';
3
+ import { Fr } from '../../curves/bn254/field.js';
4
4
  import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
5
5
 
6
6
  /**
@@ -1,21 +1,35 @@
1
- import { BarretenbergSync } from '@aztec/bb.js';
1
+ import { Barretenberg, 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
+ const IS_BROWSER = typeof self !== 'undefined';
7
+
8
+ async function poseidon2HashFields(inputFields: Fr[]): Promise<Fr> {
9
+ if (IS_BROWSER) {
10
+ await BarretenbergSync.initSingleton();
11
+ const api = BarretenbergSync.getSingleton();
12
+ const response = api.poseidon2Hash({
13
+ inputs: inputFields.map(i => i.toBuffer()),
14
+ });
15
+ return Fr.fromBuffer(Buffer.from(response.hash));
16
+ } else {
17
+ await Barretenberg.initSingleton();
18
+ const api = Barretenberg.getSingleton();
19
+ const response = await api.poseidon2Hash({
20
+ inputs: inputFields.map(i => i.toBuffer()),
21
+ });
22
+ return Fr.fromBuffer(Buffer.from(response.hash));
23
+ }
24
+ }
25
+
6
26
  /**
7
27
  * Create a poseidon hash (field) from an array of input fields.
8
28
  * @param input - The input fields to hash.
9
29
  * @returns The poseidon hash.
10
30
  */
11
- export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
12
- const inputFields = serializeToFields(input);
13
- await BarretenbergSync.initSingleton();
14
- const api = BarretenbergSync.getSingleton();
15
- const response = api.poseidon2Hash({
16
- inputs: inputFields.map(i => i.toBuffer()),
17
- });
18
- return Fr.fromBuffer(Buffer.from(response.hash));
31
+ export function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
32
+ return poseidon2HashFields(serializeToFields(input));
19
33
  }
20
34
 
21
35
  /**
@@ -24,25 +38,10 @@ export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
24
38
  * @param separator - The domain separator.
25
39
  * @returns The poseidon hash.
26
40
  */
27
- export async function poseidon2HashWithSeparator(input: Fieldable[], separator: number): Promise<Fr> {
41
+ export function poseidon2HashWithSeparator(input: Fieldable[], separator: number): Promise<Fr> {
28
42
  const inputFields = serializeToFields(input);
29
43
  inputFields.unshift(new Fr(separator));
30
- await BarretenbergSync.initSingleton();
31
- const api = BarretenbergSync.getSingleton();
32
- const response = api.poseidon2Hash({
33
- inputs: inputFields.map(i => i.toBuffer()),
34
- });
35
- return Fr.fromBuffer(Buffer.from(response.hash));
36
- }
37
-
38
- export async function poseidon2HashAccumulate(input: Fieldable[]): Promise<Fr> {
39
- const inputFields = serializeToFields(input);
40
- await BarretenbergSync.initSingleton();
41
- const api = BarretenbergSync.getSingleton();
42
- const response = api.poseidon2HashAccumulate({
43
- inputs: inputFields.map(i => i.toBuffer()),
44
- });
45
- return Fr.fromBuffer(Buffer.from(response.hash));
44
+ return poseidon2HashFields(inputFields);
46
45
  }
47
46
 
48
47
  /**
@@ -52,19 +51,24 @@ export async function poseidon2HashAccumulate(input: Fieldable[]): Promise<Fr> {
52
51
  */
53
52
  export async function poseidon2Permutation(input: Fieldable[]): Promise<Fr[]> {
54
53
  const inputFields = serializeToFields(input);
55
- // We'd like this assertion but it's not possible to use it in the browser.
56
- // assert(input.length === 4, 'Input state must be of size 4');
57
- await BarretenbergSync.initSingleton();
58
- const api = BarretenbergSync.getSingleton();
59
- const response = api.poseidon2Permutation({
60
- inputs: inputFields.map(i => i.toBuffer()),
61
- });
62
- // We'd like this assertion but it's not possible to use it in the browser.
63
- // assert(response.outputs.length === 4, 'Output state must be of size 4');
64
- return response.outputs.map(o => Fr.fromBuffer(Buffer.from(o)));
54
+ if (IS_BROWSER) {
55
+ await BarretenbergSync.initSingleton();
56
+ const api = BarretenbergSync.getSingleton();
57
+ const response = api.poseidon2Permutation({
58
+ inputs: inputFields.map(i => i.toBuffer()),
59
+ });
60
+ return response.outputs.map(o => Fr.fromBuffer(Buffer.from(o)));
61
+ } else {
62
+ await Barretenberg.initSingleton();
63
+ const api = Barretenberg.getSingleton();
64
+ const response = await api.poseidon2Permutation({
65
+ inputs: inputFields.map(i => i.toBuffer()),
66
+ });
67
+ return response.outputs.map(o => Fr.fromBuffer(Buffer.from(o)));
68
+ }
65
69
  }
66
70
 
67
- export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
71
+ export function poseidon2HashBytes(input: Buffer): Promise<Fr> {
68
72
  const inputFields = [];
69
73
  for (let i = 0; i < input.length; i += 31) {
70
74
  const fieldBytes = Buffer.alloc(32, 0);
@@ -75,11 +79,5 @@ export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
75
79
  inputFields.push(Fr.fromBuffer(fieldBytes));
76
80
  }
77
81
 
78
- await BarretenbergSync.initSingleton();
79
- const api = BarretenbergSync.getSingleton();
80
- const response = api.poseidon2Hash({
81
- inputs: inputFields.map(i => i.toBuffer()),
82
- });
83
-
84
- return Fr.fromBuffer(Buffer.from(response.hash));
82
+ return poseidon2HashFields(inputFields);
85
83
  }
@@ -1,4 +1,4 @@
1
- import { createLogger } from '../../log/pino-logger.js';
1
+ import { type Logger, type LoggerBindings, createLogger } from '../../log/pino-logger.js';
2
2
 
3
3
  /**
4
4
  * A number generator which is used as a source of randomness in the system. If the SEED env variable is set, the
@@ -12,11 +12,13 @@ export class RandomnessSingleton {
12
12
  private static instance: RandomnessSingleton;
13
13
 
14
14
  private counter = 0;
15
+ private log: Logger;
15
16
 
16
17
  private constructor(
17
18
  private readonly seed?: number,
18
- private readonly log = createLogger('foundation:randomness_singleton'),
19
+ bindings?: LoggerBindings,
19
20
  ) {
21
+ this.log = createLogger('foundation:randomness_singleton', bindings);
20
22
  if (seed !== undefined) {
21
23
  this.log.debug(`Using pseudo-randomness with seed: ${seed}`);
22
24
  this.counter = seed;
@@ -25,10 +27,10 @@ export class RandomnessSingleton {
25
27
  }
26
28
  }
27
29
 
28
- public static getInstance(): RandomnessSingleton {
30
+ public static getInstance(bindings?: LoggerBindings): RandomnessSingleton {
29
31
  if (!RandomnessSingleton.instance) {
30
32
  const seed = process.env.SEED ? Number(process.env.SEED) : undefined;
31
- RandomnessSingleton.instance = new RandomnessSingleton(seed);
33
+ RandomnessSingleton.instance = new RandomnessSingleton(seed, bindings);
32
34
  }
33
35
 
34
36
  return RandomnessSingleton.instance;
@@ -1,5 +1,7 @@
1
1
  import { BarretenbergSync } from '@aztec/bb.js';
2
- import { type GrumpkinScalar, Point } from '@aztec/foundation/fields';
2
+ import type { 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
  import { SchnorrSignature } from './signature.js';
5
7
 
@@ -22,33 +24,33 @@ export class Schnorr {
22
24
  }
23
25
 
24
26
  /**
25
- * Constructs a Schnorr signature given a msg and a private key.
26
- * @param msg - Message over which the signature is constructed.
27
+ * Constructs a Schnorr signature over a 32-byte message field element.
28
+ * @param msg - The message hash, as a grumpkin base field element.
27
29
  * @param privateKey - The private key of the signer.
28
30
  * @returns A Schnorr signature of the form (s, e).
29
31
  */
30
- public async constructSignature(msg: Uint8Array, privateKey: GrumpkinScalar) {
32
+ public async constructSignature(msg: Fr, privateKey: GrumpkinScalar) {
31
33
  await BarretenbergSync.initSingleton();
32
34
  const api = BarretenbergSync.getSingleton();
33
35
  const response = api.schnorrConstructSignature({
34
- message: msg,
36
+ messageField: msg.toBuffer(),
35
37
  privateKey: privateKey.toBuffer(),
36
38
  });
37
39
  return new SchnorrSignature(Buffer.from([...response.s, ...response.e]));
38
40
  }
39
41
 
40
42
  /**
41
- * Verifies a Schnorr signature given a Grumpkin public key.
42
- * @param msg - Message over which the signature was constructed.
43
+ * Verifies a Schnorr signature against a Grumpkin public key.
44
+ * @param msg - The message hash, as a grumpkin base field element.
43
45
  * @param pubKey - The Grumpkin public key of the signer.
44
46
  * @param sig - The Schnorr signature.
45
47
  * @returns True or false.
46
48
  */
47
- public async verifySignature(msg: Uint8Array, pubKey: Point, sig: SchnorrSignature) {
49
+ public async verifySignature(msg: Fr, pubKey: Point, sig: SchnorrSignature) {
48
50
  await BarretenbergSync.initSingleton();
49
51
  const api = BarretenbergSync.getSingleton();
50
52
  const response = api.schnorrVerifySignature({
51
- message: msg,
53
+ messageField: msg.toBuffer(),
52
54
  publicKey: { x: pubKey.x.toBuffer(), y: pubKey.y.toBuffer() },
53
55
  s: sig.s,
54
56
  e: sig.e,
@@ -1,6 +1,5 @@
1
- import { randomBytes } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { BufferReader, mapTuple } from '@aztec/foundation/serialize';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { mapTuple } from '@aztec/foundation/serialize';
4
3
 
5
4
  import type { Signature } from '../signature/index.js';
6
5
 
@@ -14,46 +13,12 @@ export class SchnorrSignature implements Signature {
14
13
  */
15
14
  public static SIZE = 64;
16
15
 
17
- /**
18
- * An empty signature.
19
- */
20
- public static EMPTY = new SchnorrSignature(Buffer.alloc(64));
21
-
22
16
  constructor(private buffer: Buffer) {
23
17
  if (buffer.length !== SchnorrSignature.SIZE) {
24
18
  throw new Error(`Invalid signature buffer of length ${buffer.length}.`);
25
19
  }
26
20
  }
27
21
 
28
- /**
29
- * Determines if the provided signature is valid or not.
30
- * @param signature - The data to be checked.
31
- * @returns Boolean indicating if the provided data is a valid schnorr signature.
32
- */
33
- public static isSignature(signature: string) {
34
- return /^(0x)?[0-9a-f]{128}$/i.test(signature);
35
- }
36
-
37
- /**
38
- * Constructs a SchnorrSignature from the provided string.
39
- * @param signature - The string to be converted to a schnorr signature.
40
- * @returns The constructed schnorr signature.
41
- */
42
- public static fromString(signature: string) {
43
- if (!SchnorrSignature.isSignature(signature)) {
44
- throw new Error(`Invalid signature string: ${signature}`);
45
- }
46
- return new SchnorrSignature(Buffer.from(signature.replace(/^0x/i, ''), 'hex'));
47
- }
48
-
49
- /**
50
- * Generates a random schnorr signature.
51
- * @returns The randomly constructed signature.
52
- */
53
- public static random() {
54
- return new SchnorrSignature(randomBytes(64));
55
- }
56
-
57
22
  /**
58
23
  * Returns the 's' component of the signature.
59
24
  * @returns A buffer containing the signature's 's' component.
@@ -78,16 +43,6 @@ export class SchnorrSignature implements Signature {
78
43
  return this.buffer;
79
44
  }
80
45
 
81
- /**
82
- * Deserializes from a buffer.
83
- * @param buffer - The buffer representation of the object.
84
- * @returns The new object.
85
- */
86
- static fromBuffer(buffer: Buffer | BufferReader): SchnorrSignature {
87
- const reader = BufferReader.asReader(buffer);
88
- return new SchnorrSignature(reader.readBytes(SchnorrSignature.SIZE));
89
- }
90
-
91
46
  /**
92
47
  * Returns the full signature as a hex string.
93
48
  * @returns A string containing the signature in hex format.
@@ -113,4 +68,20 @@ export class SchnorrSignature implements Signature {
113
68
 
114
69
  return mapTuple([buf1, buf2, buf3], Fr.fromBuffer);
115
70
  }
71
+
72
+ /**
73
+ * Splits the signature into the four 128-bit limbs that Noir's `EmbeddedCurveScalar` consumes:
74
+ * `[s.lo, s.hi, e.lo, e.hi]`, where each component scalar is encoded as `lo + hi * 2^128`.
75
+ *
76
+ * Each 32-byte big-endian component is sliced into its top 16 bytes (`hi`) and bottom 16 bytes
77
+ * (`lo`); each half is zero-padded into a 32-byte buffer and decoded as `Fr` (big-endian).
78
+ */
79
+ toLimbFields(): [Fr, Fr, Fr, Fr] {
80
+ const limb = (start: number) => {
81
+ const buf = Buffer.alloc(32);
82
+ this.buffer.copy(buf, 16, start, start + 16);
83
+ return Fr.fromBuffer(buf);
84
+ };
85
+ return [limb(16), limb(0), limb(48), limb(32)];
86
+ }
116
87
  }
@@ -210,3 +210,35 @@ export function recoverPublicKey(hash: Buffer32, signature: Signature, opts: Rec
210
210
  const publicKey = sig.recoverPublicKey(hash.buffer).toHex(false);
211
211
  return Buffer.from(publicKey, 'hex');
212
212
  }
213
+
214
+ /** Arbitrary hash used for testing signature recoverability. */
215
+ const PROBE_HASH = Buffer32.fromBuffer(keccak256(Buffer.from('signature-recoverability-probe')));
216
+
217
+ /**
218
+ * Generates a random valid ECDSA signature that is recoverable to some address.
219
+ * Since Signature.random() produces real signatures via secp256k1 signing, the result is always
220
+ * recoverable, but we verify defensively by checking tryRecoverAddress.
221
+ */
222
+ export function generateRecoverableSignature(): Signature {
223
+ for (let i = 0; i < 100; i++) {
224
+ const sig = Signature.random();
225
+ if (tryRecoverAddress(PROBE_HASH, sig) !== undefined) {
226
+ return sig;
227
+ }
228
+ }
229
+ throw new Secp256k1Error('Failed to generate a recoverable signature after 100 attempts');
230
+ }
231
+
232
+ /**
233
+ * Generates a random signature where ECDSA address recovery fails.
234
+ * Uses random r/s values (not from real signing) so that r is unlikely to be a valid secp256k1 x-coordinate.
235
+ */
236
+ export function generateUnrecoverableSignature(): Signature {
237
+ for (let i = 0; i < 100; i++) {
238
+ const sig = new Signature(Buffer32.random(), Buffer32.random(), 27);
239
+ if (tryRecoverAddress(PROBE_HASH, sig) === undefined) {
240
+ return sig;
241
+ }
242
+ }
243
+ throw new Secp256k1Error('Failed to generate an unrecoverable signature after 100 attempts');
244
+ }
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable camelcase */
2
2
  import { default as hash } from 'hash.js';
3
3
 
4
- import { Fr } from '../../fields/fields.js';
4
+ import { Fr } from '../../curves/bn254/field.js';
5
5
  import { truncateAndPad } from '../../serialize/free_funcs.js';
6
6
  import { type Bufferable, serializeToBuffer } from '../../serialize/serialize.js';
7
7
  import type { Hasher } from '../../trees/hasher.js';
@@ -1,6 +1,6 @@
1
1
  import { default as hash } from 'hash.js';
2
2
 
3
- import { GrumpkinScalar } from '../../fields/fields.js';
3
+ import { GrumpkinScalar } from '../../curves/grumpkin/index.js';
4
4
  import { type Bufferable, serializeToBuffer } from '../../serialize/serialize.js';
5
5
 
6
6
  export const sha512 = (data: Buffer) => Buffer.from(hash.sha512().update(data).digest());
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  /**
4
4
  * Interface to represent a signature.
@@ -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
  /**