@aztec/foundation 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05

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 (405) 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/branded-types/block_number.d.ts +56 -0
  8. package/dest/branded-types/block_number.d.ts.map +1 -0
  9. package/dest/branded-types/block_number.js +78 -0
  10. package/dest/branded-types/buffer32_hash.d.ts +24 -0
  11. package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
  12. package/dest/branded-types/buffer32_hash.js +19 -0
  13. package/dest/branded-types/checkpoint_number.d.ts +57 -0
  14. package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
  15. package/dest/branded-types/checkpoint_number.js +80 -0
  16. package/dest/branded-types/index.d.ts +5 -1
  17. package/dest/branded-types/index.d.ts.map +1 -1
  18. package/dest/branded-types/index.js +4 -0
  19. package/dest/branded-types/index_within_checkpoint.d.ts +42 -0
  20. package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -0
  21. package/dest/branded-types/index_within_checkpoint.js +59 -0
  22. package/dest/branded-types/slot.d.ts +4 -1
  23. package/dest/branded-types/slot.d.ts.map +1 -1
  24. package/dest/branded-types/slot.js +3 -0
  25. package/dest/buffer/buffer16.d.ts +7 -2
  26. package/dest/buffer/buffer16.d.ts.map +1 -1
  27. package/dest/buffer/buffer16.js +4 -2
  28. package/dest/buffer/buffer32.d.ts +29 -59
  29. package/dest/buffer/buffer32.d.ts.map +1 -1
  30. package/dest/buffer/buffer32.js +30 -62
  31. package/dest/buffer/index.d.ts +2 -1
  32. package/dest/buffer/index.d.ts.map +1 -1
  33. package/dest/buffer/index.js +1 -0
  34. package/dest/buffer/utils.d.ts +3 -0
  35. package/dest/buffer/utils.d.ts.map +1 -0
  36. package/dest/buffer/utils.js +7 -0
  37. package/dest/collection/array.d.ts +14 -1
  38. package/dest/collection/array.d.ts.map +1 -1
  39. package/dest/collection/array.js +66 -0
  40. package/dest/collection/index.d.ts +2 -1
  41. package/dest/collection/index.d.ts.map +1 -1
  42. package/dest/collection/index.js +1 -0
  43. package/dest/collection/lru_set.d.ts +35 -0
  44. package/dest/collection/lru_set.d.ts.map +1 -0
  45. package/dest/collection/lru_set.js +95 -0
  46. package/dest/config/env_var.d.ts +2 -2
  47. package/dest/config/env_var.d.ts.map +1 -1
  48. package/dest/config/index.d.ts +61 -32
  49. package/dest/config/index.d.ts.map +1 -1
  50. package/dest/config/index.js +66 -37
  51. package/dest/config/network_config.d.ts +31 -1
  52. package/dest/config/network_config.d.ts.map +1 -1
  53. package/dest/config/network_config.js +6 -1
  54. package/dest/config/network_name.d.ts +2 -2
  55. package/dest/config/network_name.d.ts.map +1 -1
  56. package/dest/config/network_name.js +2 -0
  57. package/dest/config/parse-env.d.ts +3 -0
  58. package/dest/config/parse-env.d.ts.map +1 -0
  59. package/dest/config/parse-env.js +7 -0
  60. package/dest/config/secret_value.js +3 -1
  61. package/dest/crypto/aes128/index.d.ts +2 -1
  62. package/dest/crypto/aes128/index.d.ts.map +1 -1
  63. package/dest/crypto/aes128/index.js +11 -2
  64. package/dest/crypto/bls/bn254_keystore.d.ts +1 -10
  65. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
  66. package/dest/crypto/bls/bn254_keystore.js +1 -18
  67. package/dest/crypto/bls/index.js +1 -1
  68. package/dest/crypto/bn254/index.d.ts +35 -51
  69. package/dest/crypto/bn254/index.d.ts.map +1 -1
  70. package/dest/crypto/bn254/index.js +51 -140
  71. package/dest/crypto/ecdsa/signature.d.ts +11 -2
  72. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  73. package/dest/crypto/ecdsa/signature.js +2 -2
  74. package/dest/crypto/grumpkin/index.d.ts +4 -2
  75. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  76. package/dest/crypto/grumpkin/index.js +2 -1
  77. package/dest/crypto/keys/index.d.ts +2 -2
  78. package/dest/crypto/keys/index.d.ts.map +1 -1
  79. package/dest/crypto/keys/index.js +1 -1
  80. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
  81. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  82. package/dest/crypto/pedersen/pedersen.wasm.js +1 -1
  83. package/dest/crypto/poseidon/index.d.ts +2 -3
  84. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  85. package/dest/crypto/poseidon/index.js +41 -43
  86. package/dest/crypto/random/randomness_singleton.d.ts +4 -3
  87. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  88. package/dest/crypto/random/randomness_singleton.js +5 -5
  89. package/dest/crypto/schnorr/index.d.ts +3 -2
  90. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  91. package/dest/crypto/schnorr/index.js +1 -1
  92. package/dest/crypto/schnorr/signature.d.ts +2 -2
  93. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  94. package/dest/crypto/schnorr/signature.js +2 -2
  95. package/dest/crypto/secp256k1-signer/utils.d.ts +12 -1
  96. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  97. package/dest/crypto/secp256k1-signer/utils.js +26 -0
  98. package/dest/crypto/sha256/index.d.ts +2 -2
  99. package/dest/crypto/sha256/index.d.ts.map +1 -1
  100. package/dest/crypto/sha256/index.js +1 -1
  101. package/dest/crypto/sha512/index.d.ts +2 -2
  102. package/dest/crypto/sha512/index.d.ts.map +1 -1
  103. package/dest/crypto/sha512/index.js +1 -1
  104. package/dest/crypto/signature/index.d.ts +2 -2
  105. package/dest/crypto/signature/index.d.ts.map +1 -1
  106. package/dest/crypto/sync/pedersen/index.d.ts +2 -2
  107. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  108. package/dest/crypto/sync/pedersen/index.js +1 -1
  109. package/dest/crypto/sync/poseidon/index.d.ts +2 -3
  110. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  111. package/dest/crypto/sync/poseidon/index.js +1 -9
  112. package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
  113. package/dest/curves/bls12/field.d.ts.map +1 -0
  114. package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +11 -13
  115. package/dest/curves/bls12/index.d.ts +3 -0
  116. package/dest/curves/bls12/index.d.ts.map +1 -0
  117. package/dest/curves/bls12/index.js +2 -0
  118. package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +13 -4
  119. package/dest/curves/bls12/point.d.ts.map +1 -0
  120. package/dest/{fields/bls12_point.js → curves/bls12/point.js} +10 -8
  121. package/dest/{fields/fields.d.ts → curves/bn254/field.d.ts} +24 -30
  122. package/dest/curves/bn254/field.d.ts.map +1 -0
  123. package/dest/{fields/fields.js → curves/bn254/field.js} +55 -61
  124. package/dest/curves/bn254/index.d.ts +3 -0
  125. package/dest/curves/bn254/index.d.ts.map +1 -0
  126. package/dest/curves/bn254/index.js +2 -0
  127. package/dest/curves/bn254/point.d.ts +54 -0
  128. package/dest/curves/bn254/point.d.ts.map +1 -0
  129. package/dest/curves/bn254/point.js +143 -0
  130. package/dest/curves/grumpkin/index.d.ts +10 -0
  131. package/dest/curves/grumpkin/index.d.ts.map +1 -0
  132. package/dest/curves/grumpkin/index.js +3 -0
  133. package/dest/{fields → curves/grumpkin}/point.d.ts +16 -7
  134. package/dest/curves/grumpkin/point.d.ts.map +1 -0
  135. package/dest/{fields → curves/grumpkin}/point.js +14 -11
  136. package/dest/error/index.d.ts +4 -4
  137. package/dest/error/index.d.ts.map +1 -1
  138. package/dest/eth-address/index.d.ts +3 -2
  139. package/dest/eth-address/index.d.ts.map +1 -1
  140. package/dest/eth-address/index.js +10 -6
  141. package/dest/eth-signature/eth_signature.d.ts +5 -1
  142. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  143. package/dest/eth-signature/eth_signature.js +7 -2
  144. package/dest/fifo/fifo_frame_reader.d.ts +41 -0
  145. package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
  146. package/dest/fifo/fifo_frame_reader.js +74 -0
  147. package/dest/fifo/index.d.ts +2 -0
  148. package/dest/fifo/index.d.ts.map +1 -0
  149. package/dest/fifo/index.js +1 -0
  150. package/dest/iterator/filter.d.ts +3 -0
  151. package/dest/iterator/filter.d.ts.map +1 -0
  152. package/dest/iterator/filter.js +7 -0
  153. package/dest/iterator/index.d.ts +2 -0
  154. package/dest/iterator/index.d.ts.map +1 -0
  155. package/dest/iterator/index.js +1 -0
  156. package/dest/jest/setup.js +28 -1
  157. package/dest/json-rpc/client/fetch.d.ts +1 -1
  158. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  159. package/dest/json-rpc/client/fetch.js +4 -3
  160. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
  161. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  162. package/dest/json-rpc/client/safe_json_rpc_client.js +1 -1
  163. package/dest/json-rpc/client/undici.d.ts +1 -1
  164. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  165. package/dest/json-rpc/client/undici.js +23 -4
  166. package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
  167. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  168. package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
  169. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  170. package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
  171. package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
  172. package/dest/json-rpc/server/api_key_auth.js +57 -0
  173. package/dest/json-rpc/server/index.d.ts +2 -1
  174. package/dest/json-rpc/server/index.d.ts.map +1 -1
  175. package/dest/json-rpc/server/index.js +1 -0
  176. package/dest/json-rpc/server/safe_json_rpc_server.js +1 -1
  177. package/dest/log/bigint-utils.d.ts +5 -0
  178. package/dest/log/bigint-utils.d.ts.map +1 -0
  179. package/dest/log/bigint-utils.js +21 -0
  180. package/dest/log/gcloud-logger-config.d.ts +1 -1
  181. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  182. package/dest/log/gcloud-logger-config.js +3 -0
  183. package/dest/log/libp2p_logger.d.ts +5 -2
  184. package/dest/log/libp2p_logger.d.ts.map +1 -1
  185. package/dest/log/libp2p_logger.js +14 -4
  186. package/dest/log/log-filters.d.ts +17 -4
  187. package/dest/log/log-filters.d.ts.map +1 -1
  188. package/dest/log/log-filters.js +26 -12
  189. package/dest/log/pino-logger-server.d.ts +9 -0
  190. package/dest/log/pino-logger-server.d.ts.map +1 -0
  191. package/dest/log/pino-logger-server.js +18 -0
  192. package/dest/log/pino-logger.d.ts +37 -8
  193. package/dest/log/pino-logger.d.ts.map +1 -1
  194. package/dest/log/pino-logger.js +138 -30
  195. package/dest/queue/base_memory_queue.d.ts +2 -2
  196. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  197. package/dest/queue/batch_queue.d.ts +1 -1
  198. package/dest/queue/batch_queue.d.ts.map +1 -1
  199. package/dest/queue/batch_queue.js +1 -0
  200. package/dest/queue/semaphore.d.ts +5 -1
  201. package/dest/queue/semaphore.d.ts.map +1 -1
  202. package/dest/retry/index.d.ts +22 -1
  203. package/dest/retry/index.d.ts.map +1 -1
  204. package/dest/retry/index.js +32 -0
  205. package/dest/schemas/api.d.ts +2 -2
  206. package/dest/schemas/api.d.ts.map +1 -1
  207. package/dest/schemas/schemas.d.ts +7 -3
  208. package/dest/schemas/schemas.d.ts.map +1 -1
  209. package/dest/schemas/schemas.js +9 -3
  210. package/dest/schemas/types.d.ts +31 -1
  211. package/dest/schemas/types.d.ts.map +1 -1
  212. package/dest/schemas/types.js +25 -1
  213. package/dest/serialize/buffer_reader.d.ts +14 -4
  214. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  215. package/dest/serialize/buffer_reader.js +26 -4
  216. package/dest/serialize/field_reader.d.ts +2 -2
  217. package/dest/serialize/field_reader.d.ts.map +1 -1
  218. package/dest/serialize/field_reader.js +1 -1
  219. package/dest/serialize/free_funcs.d.ts +2 -2
  220. package/dest/serialize/free_funcs.d.ts.map +1 -1
  221. package/dest/serialize/free_funcs.js +1 -1
  222. package/dest/serialize/serialize.d.ts +20 -2
  223. package/dest/serialize/serialize.d.ts.map +1 -1
  224. package/dest/serialize/serialize.js +32 -1
  225. package/dest/sleep/index.d.ts +4 -1
  226. package/dest/sleep/index.d.ts.map +1 -1
  227. package/dest/sleep/index.js +14 -1
  228. package/dest/string/index.js +1 -1
  229. package/dest/timer/date.d.ts +26 -1
  230. package/dest/timer/date.d.ts.map +1 -1
  231. package/dest/timer/date.js +36 -0
  232. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
  233. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
  234. package/dest/transport/index.d.ts +1 -2
  235. package/dest/transport/index.d.ts.map +1 -1
  236. package/dest/transport/index.js +0 -1
  237. package/dest/transport/transport_client.js +2 -2
  238. package/dest/trees/balanced_merkle_tree_root.d.ts +16 -0
  239. package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -0
  240. package/dest/trees/{balanced_merkle_tree.js → balanced_merkle_tree_root.js} +3 -17
  241. package/dest/trees/hasher.d.ts +4 -1
  242. package/dest/trees/hasher.d.ts.map +1 -1
  243. package/dest/trees/hasher.js +10 -5
  244. package/dest/trees/index.d.ts +4 -4
  245. package/dest/trees/index.d.ts.map +1 -1
  246. package/dest/trees/index.js +3 -3
  247. package/dest/trees/indexed_merkle_tree.js +1 -1
  248. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  249. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  250. package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
  251. package/dest/trees/membership_witness.d.ts +12 -2
  252. package/dest/trees/membership_witness.d.ts.map +1 -1
  253. package/dest/trees/membership_witness.js +10 -1
  254. package/dest/trees/merkle_tree_calculator.d.ts +4 -2
  255. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  256. package/dest/trees/merkle_tree_calculator.js +1 -5
  257. package/dest/trees/sibling_path.d.ts +4 -3
  258. package/dest/trees/sibling_path.d.ts.map +1 -1
  259. package/dest/trees/sibling_path.js +2 -6
  260. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +2 -3
  261. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
  262. package/dest/trees/unbalanced_merkle_tree_calculator.js +1 -5
  263. package/dest/trees/{unbalanced_merkle_tree.d.ts → unbalanced_merkle_tree_root.d.ts} +4 -7
  264. package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
  265. package/dest/trees/{unbalanced_merkle_tree.js → unbalanced_merkle_tree_root.js} +12 -51
  266. package/dest/trees/unbalanced_tree_store.d.ts +5 -1
  267. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  268. package/dest/trees/unbalanced_tree_store.js +49 -1
  269. package/dest/types/index.d.ts +14 -2
  270. package/dest/types/index.d.ts.map +1 -1
  271. package/dest/types/index.js +6 -0
  272. package/package.json +49 -9
  273. package/src/array/index.ts +1 -0
  274. package/src/array/sorted_array.ts +138 -0
  275. package/src/branded-types/block_number.ts +117 -0
  276. package/src/branded-types/buffer32_hash.ts +42 -0
  277. package/src/branded-types/checkpoint_number.ts +120 -0
  278. package/src/branded-types/index.ts +4 -0
  279. package/src/branded-types/index_within_checkpoint.ts +88 -0
  280. package/src/branded-types/slot.ts +5 -0
  281. package/src/buffer/buffer16.ts +5 -2
  282. package/src/buffer/buffer32.ts +38 -67
  283. package/src/buffer/index.ts +1 -0
  284. package/src/buffer/utils.ts +8 -0
  285. package/src/collection/array.ts +66 -0
  286. package/src/collection/index.ts +1 -0
  287. package/src/collection/lru_set.ts +115 -0
  288. package/src/config/env_var.ts +96 -24
  289. package/src/config/index.ts +148 -88
  290. package/src/config/network_config.ts +5 -0
  291. package/src/config/network_name.ts +4 -1
  292. package/src/config/parse-env.ts +4 -0
  293. package/src/crypto/aes128/index.ts +11 -2
  294. package/src/crypto/bls/bn254_keystore.ts +1 -24
  295. package/src/crypto/bls/index.ts +1 -1
  296. package/src/crypto/bn254/index.ts +50 -159
  297. package/src/crypto/ecdsa/signature.ts +2 -2
  298. package/src/crypto/grumpkin/index.ts +3 -1
  299. package/src/crypto/keys/index.ts +1 -1
  300. package/src/crypto/pedersen/pedersen.wasm.ts +1 -1
  301. package/src/crypto/poseidon/index.ts +43 -45
  302. package/src/crypto/random/randomness_singleton.ts +6 -4
  303. package/src/crypto/schnorr/index.ts +2 -1
  304. package/src/crypto/schnorr/signature.ts +2 -2
  305. package/src/crypto/secp256k1-signer/utils.ts +32 -0
  306. package/src/crypto/sha256/index.ts +1 -1
  307. package/src/crypto/sha512/index.ts +1 -1
  308. package/src/crypto/signature/index.ts +1 -1
  309. package/src/crypto/sync/pedersen/index.ts +1 -1
  310. package/src/crypto/sync/poseidon/index.ts +1 -10
  311. package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +5 -12
  312. package/src/curves/bls12/index.ts +2 -0
  313. package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +7 -7
  314. package/src/{fields/fields.ts → curves/bn254/field.ts} +61 -86
  315. package/src/curves/bn254/index.ts +2 -0
  316. package/src/curves/bn254/point.ts +170 -0
  317. package/src/curves/grumpkin/index.ts +11 -0
  318. package/src/{fields → curves/grumpkin}/point.ts +13 -10
  319. package/src/eth-address/index.ts +8 -6
  320. package/src/eth-signature/eth_signature.ts +7 -1
  321. package/src/fifo/fifo_frame_reader.ts +98 -0
  322. package/src/fifo/index.ts +1 -0
  323. package/src/iterator/filter.ts +11 -0
  324. package/src/iterator/index.ts +1 -0
  325. package/src/jest/setup.mjs +31 -1
  326. package/src/json-rpc/client/fetch.ts +4 -3
  327. package/src/json-rpc/client/safe_json_rpc_client.ts +2 -0
  328. package/src/json-rpc/client/undici.ts +23 -3
  329. package/src/json-rpc/server/api_key_auth.ts +63 -0
  330. package/src/json-rpc/server/index.ts +1 -0
  331. package/src/json-rpc/server/safe_json_rpc_server.ts +1 -1
  332. package/src/log/bigint-utils.ts +25 -0
  333. package/src/log/gcloud-logger-config.ts +5 -0
  334. package/src/log/libp2p_logger.ts +12 -5
  335. package/src/log/log-filters.ts +29 -11
  336. package/src/log/pino-logger-server.ts +25 -0
  337. package/src/log/pino-logger.ts +162 -40
  338. package/src/queue/base_memory_queue.ts +1 -1
  339. package/src/queue/batch_queue.ts +1 -0
  340. package/src/queue/semaphore.ts +5 -0
  341. package/src/retry/index.ts +48 -0
  342. package/src/schemas/api.ts +4 -1
  343. package/src/schemas/schemas.ts +14 -3
  344. package/src/schemas/types.ts +33 -0
  345. package/src/serialize/buffer_reader.ts +36 -9
  346. package/src/serialize/field_reader.ts +1 -1
  347. package/src/serialize/free_funcs.ts +1 -1
  348. package/src/serialize/serialize.ts +33 -1
  349. package/src/sleep/index.ts +16 -1
  350. package/src/string/index.ts +1 -1
  351. package/src/timer/date.ts +52 -0
  352. package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
  353. package/src/transport/index.ts +0 -1
  354. package/src/transport/transport_client.ts +2 -2
  355. package/src/trees/{balanced_merkle_tree.ts → balanced_merkle_tree_root.ts} +3 -20
  356. package/src/trees/hasher.ts +12 -0
  357. package/src/trees/index.ts +3 -3
  358. package/src/trees/indexed_merkle_tree.ts +1 -1
  359. package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
  360. package/src/trees/membership_witness.ts +9 -1
  361. package/src/trees/merkle_tree_calculator.ts +4 -10
  362. package/src/trees/sibling_path.ts +2 -3
  363. package/src/trees/unbalanced_merkle_tree_calculator.ts +1 -12
  364. package/src/trees/{unbalanced_merkle_tree.ts → unbalanced_merkle_tree_root.ts} +17 -64
  365. package/src/trees/unbalanced_tree_store.ts +57 -2
  366. package/src/types/index.ts +25 -1
  367. package/dest/crypto/bn254/bn254_utils.d.ts +0 -39
  368. package/dest/crypto/bn254/bn254_utils.d.ts.map +0 -1
  369. package/dest/crypto/bn254/bn254_utils.js +0 -56
  370. package/dest/crypto/index.d.ts +0 -17
  371. package/dest/crypto/index.d.ts.map +0 -1
  372. package/dest/crypto/index.js +0 -16
  373. package/dest/crypto/serialize.d.ts +0 -51
  374. package/dest/crypto/serialize.d.ts.map +0 -1
  375. package/dest/crypto/serialize.js +0 -68
  376. package/dest/fields/bls12_fields.d.ts.map +0 -1
  377. package/dest/fields/bls12_point.d.ts.map +0 -1
  378. package/dest/fields/coordinate.d.ts +0 -63
  379. package/dest/fields/coordinate.d.ts.map +0 -1
  380. package/dest/fields/coordinate.js +0 -96
  381. package/dest/fields/fields.d.ts.map +0 -1
  382. package/dest/fields/index.d.ts +0 -6
  383. package/dest/fields/index.d.ts.map +0 -1
  384. package/dest/fields/index.js +0 -5
  385. package/dest/fields/point.d.ts.map +0 -1
  386. package/dest/index.d.ts +0 -31
  387. package/dest/index.d.ts.map +0 -1
  388. package/dest/index.js +0 -31
  389. package/dest/json-rpc/server/telemetry.d.ts +0 -2
  390. package/dest/json-rpc/server/telemetry.d.ts.map +0 -1
  391. package/dest/json-rpc/server/telemetry.js +0 -0
  392. package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
  393. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
  394. package/dest/transport/dispatch/create_dispatch_fn.js +0 -17
  395. package/dest/trees/balanced_merkle_tree.d.ts +0 -22
  396. package/dest/trees/balanced_merkle_tree.d.ts.map +0 -1
  397. package/dest/trees/unbalanced_merkle_tree.d.ts.map +0 -1
  398. package/src/crypto/bn254/bn254_utils.ts +0 -64
  399. package/src/crypto/index.ts +0 -16
  400. package/src/crypto/serialize.ts +0 -85
  401. package/src/fields/coordinate.ts +0 -104
  402. package/src/fields/index.ts +0 -5
  403. package/src/index.ts +0 -31
  404. package/src/json-rpc/server/telemetry.ts +0 -0
  405. package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
@@ -2,15 +2,10 @@ import { BarretenbergSync } from '@aztec/bb.js';
2
2
 
3
3
  import { inspect } from 'util';
4
4
 
5
- import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
6
- import { randomBytes } from '../crypto/random/index.js';
7
- import { hexSchemaFor } from '../schemas/utils.js';
8
- import { BufferReader } from '../serialize/buffer_reader.js';
9
- import { TypeRegistry } from '../serialize/type_registry.js';
10
-
11
- const ZERO_BUFFER = Buffer.alloc(32);
12
-
13
- /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
5
+ import { toBigIntBE, toBufferBE } from '../../bigint-buffer/index.js';
6
+ import { randomBytes } from '../../crypto/random/index.js';
7
+ import { hexSchemaFor } from '../../schemas/utils.js';
8
+ import { BufferReader } from '../../serialize/buffer_reader.js';
14
9
 
15
10
  /**
16
11
  * Represents a field derived from BaseField.
@@ -25,14 +20,12 @@ type DerivedField<T extends BaseField> = {
25
20
 
26
21
  /**
27
22
  * Base field class.
28
- * Conversions from Buffer to BigInt and vice-versa are not cheap.
29
- * We allow construction with either form and lazily convert to other as needed.
30
- * We only check we are within the field modulus when initializing with bigint.
23
+ * Uses bigint as the internal representation.
24
+ * Buffers are generated on demand from the bigint value.
31
25
  */
32
26
  abstract class BaseField {
33
27
  static SIZE_IN_BYTES = 32;
34
- private asBuffer?: Buffer;
35
- private asBigInt?: bigint;
28
+ private readonly asBigInt: bigint;
36
29
 
37
30
  /**
38
31
  * Return bigint representation.
@@ -52,53 +45,41 @@ abstract class BaseField {
52
45
  if (value.length > BaseField.SIZE_IN_BYTES) {
53
46
  throw new Error(`Value length ${value.length} exceeds ${BaseField.SIZE_IN_BYTES}`);
54
47
  }
55
- this.asBuffer =
56
- value.length === BaseField.SIZE_IN_BYTES
57
- ? value
58
- : Buffer.concat([Buffer.alloc(BaseField.SIZE_IN_BYTES - value.length), value]);
48
+ this.asBigInt = toBigIntBE(value);
59
49
  } else if (typeof value === 'bigint' || typeof value === 'number' || typeof value === 'boolean') {
60
50
  this.asBigInt = BigInt(value);
61
- if (this.asBigInt >= this.modulus()) {
62
- throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
63
- } else if (this.asBigInt < 0n) {
64
- throw new Error(`Value 0x${this.asBigInt.toString(16)} is negative.`);
65
- }
66
51
  } else if (value instanceof BaseField) {
67
- this.asBuffer = value.asBuffer;
68
52
  this.asBigInt = value.asBigInt;
69
53
  } else {
70
54
  throw new Error(`Type '${typeof value}' with value '${value}' passed to BaseField ctor.`);
71
55
  }
56
+
57
+ if (this.asBigInt < 0n) {
58
+ throw new Error(`Value 0x${this.asBigInt.toString(16)} is negative.`);
59
+ } else if (this.asBigInt >= this.modulus()) {
60
+ throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
61
+ }
72
62
  }
73
63
 
74
64
  protected abstract modulus(): bigint;
75
65
 
76
66
  /**
77
- * We return a copy of the Buffer to ensure this remains immutable.
67
+ * Converts the bigint to a Buffer.
78
68
  */
79
69
  toBuffer(): Buffer {
80
- if (!this.asBuffer) {
81
- this.asBuffer = toBufferBE(this.asBigInt!, 32);
82
- }
83
- return Buffer.from(this.asBuffer);
70
+ return toBufferBE(this.asBigInt, 32);
84
71
  }
85
72
 
86
73
  toString(): `0x${string}` {
87
- return `0x${this.toBuffer().toString('hex')}`;
74
+ return `0x${this.asBigInt.toString(16).padStart(64, '0')}`;
88
75
  }
89
76
 
90
77
  toBigInt(): bigint {
91
- if (this.asBigInt === undefined) {
92
- this.asBigInt = toBigIntBE(this.asBuffer!);
93
- if (this.asBigInt >= this.modulus()) {
94
- throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
95
- }
96
- }
97
78
  return this.asBigInt;
98
79
  }
99
80
 
100
81
  toBool(): boolean {
101
- return Boolean(this.toBigInt());
82
+ return this.asBigInt !== 0n;
102
83
  }
103
84
 
104
85
  /**
@@ -106,11 +87,10 @@ abstract class BaseField {
106
87
  * Throws if the underlying value is greater than MAX_SAFE_INTEGER.
107
88
  */
108
89
  toNumber(): number {
109
- const value = this.toBigInt();
110
- if (value > Number.MAX_SAFE_INTEGER) {
111
- throw new Error(`Value ${value.toString(16)} greater than than max safe integer`);
90
+ if (this.asBigInt > Number.MAX_SAFE_INTEGER) {
91
+ throw new Error(`Value ${this.asBigInt.toString(16)} greater than than max safe integer`);
112
92
  }
113
- return Number(value);
93
+ return Number(this.asBigInt);
114
94
  }
115
95
 
116
96
  /**
@@ -118,8 +98,7 @@ abstract class BaseField {
118
98
  * May cause loss of precision if the underlying value is greater than MAX_SAFE_INTEGER.
119
99
  */
120
100
  toNumberUnsafe(): number {
121
- const value = this.toBigInt();
122
- return Number(value);
101
+ return Number(this.asBigInt);
123
102
  }
124
103
 
125
104
  toShortString(): string {
@@ -128,21 +107,28 @@ abstract class BaseField {
128
107
  }
129
108
 
130
109
  equals(rhs: BaseField): boolean {
131
- return this.toBuffer().equals(rhs.toBuffer());
110
+ return this.asBigInt === rhs.asBigInt;
132
111
  }
133
112
 
134
113
  lt(rhs: BaseField): boolean {
135
- return this.toBigInt() < rhs.toBigInt();
114
+ return this.asBigInt < rhs.asBigInt;
136
115
  }
137
116
 
138
117
  cmp(rhs: BaseField): -1 | 0 | 1 {
139
- const lhsBigInt = this.toBigInt();
140
- const rhsBigInt = rhs.toBigInt();
141
- return lhsBigInt === rhsBigInt ? 0 : lhsBigInt < rhsBigInt ? -1 : 1;
118
+ return BaseField.cmpAsBigInt(this.asBigInt, rhs.asBigInt);
119
+ }
120
+
121
+ static cmp(lhs: BaseField, rhs: BaseField): -1 | 0 | 1 {
122
+ return lhs.cmp(rhs);
123
+ }
124
+
125
+ // Actual bigint comparison. Arguments must have been validated previously.
126
+ static cmpAsBigInt(lhs: bigint, rhs: bigint): -1 | 0 | 1 {
127
+ return lhs === rhs ? 0 : lhs < rhs ? -1 : 1;
142
128
  }
143
129
 
144
130
  isZero(): boolean {
145
- return this.toBuffer().equals(ZERO_BUFFER);
131
+ return this.asBigInt === 0n;
146
132
  }
147
133
 
148
134
  isEmpty(): boolean {
@@ -195,13 +181,28 @@ function fromHexString<T extends BaseField>(buf: string, f: DerivedField<T>) {
195
181
 
196
182
  const buffer = Buffer.from(checked.length % 2 === 1 ? '0' + checked : checked, 'hex');
197
183
 
198
- return new f(buffer);
184
+ return new f(toBigIntBE(buffer));
199
185
  }
200
186
 
201
- /** Branding to ensure fields are not interchangeable types. */
202
- export interface Fr {
203
- /** Brand. */
204
- _branding: 'Fr';
187
+ /**
188
+ * Abstract unbranded base class for BN254 scalar field elements.
189
+ * Extend this instead of Fr when defining a branded subtype (e.g. BlockHash)
190
+ * to avoid inheriting Fr's `_branding`.
191
+ */
192
+ export abstract class BaseFr extends BaseField {
193
+ static MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n;
194
+
195
+ constructor(value: number | bigint | boolean | BaseField | Buffer) {
196
+ super(value);
197
+ }
198
+
199
+ protected modulus() {
200
+ return BaseFr.MODULUS;
201
+ }
202
+
203
+ toJSON() {
204
+ return this.toString();
205
+ }
205
206
  }
206
207
 
207
208
  /**
@@ -209,10 +210,12 @@ export interface Fr {
209
210
  * @dev This class is used to represent elements of BN254 scalar field or elements in the base field of Grumpkin.
210
211
  * (Grumpkin's scalar field corresponds to BN254's base field and vice versa.)
211
212
  */
212
- export class Fr extends BaseField {
213
+ export class Fr extends BaseFr {
214
+ /** Branding for nominal typing. */
215
+ declare private readonly _branding: 'Fr';
216
+ static override MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n;
213
217
  static ZERO = new Fr(0n);
214
218
  static ONE = new Fr(1n);
215
- static MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n;
216
219
  static MAX_FIELD_VALUE = new Fr(this.MODULUS - 1n);
217
220
 
218
221
  constructor(value: number | bigint | boolean | Fr | Buffer) {
@@ -223,10 +226,6 @@ export class Fr extends BaseField {
223
226
  return `Fr<${this.toString()}>`;
224
227
  }
225
228
 
226
- protected modulus() {
227
- return Fr.MODULUS;
228
- }
229
-
230
229
  static random() {
231
230
  return random(Fr);
232
231
  }
@@ -331,10 +330,6 @@ export class Fr extends BaseField {
331
330
  return Fr.fromBuffer(Buffer.from(response.value));
332
331
  }
333
332
 
334
- toJSON() {
335
- return this.toString();
336
- }
337
-
338
333
  /**
339
334
  * Creates an Fr instance from a plain object without Zod validation.
340
335
  * This method is optimized for performance and skips validation, making it suitable
@@ -356,23 +351,14 @@ export class Fr extends BaseField {
356
351
  }
357
352
  }
358
353
 
359
- // For deserializing JSON.
360
- TypeRegistry.register('Fr', Fr);
361
-
362
- /**
363
- * Branding to ensure fields are not interchangeable types.
364
- */
365
- export interface Fq {
366
- /** Brand. */
367
- _branding: 'Fq';
368
- }
369
-
370
354
  /**
371
355
  * Fq field class.
372
356
  * @dev This class is used to represent elements of BN254 base field or elements in the scalar field of Grumpkin.
373
357
  * (Grumpkin's scalar field corresponds to BN254's base field and vice versa.)
374
358
  */
375
359
  export class Fq extends BaseField {
360
+ /** Branding for nominal typing. */
361
+ declare private readonly _branding: 'Fq';
376
362
  static ZERO = new Fq(0n);
377
363
  static MODULUS = 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47n;
378
364
  private static HIGH_SHIFT = BigInt((BaseField.SIZE_IN_BYTES / 2) * 8);
@@ -481,9 +467,6 @@ export class Fq extends BaseField {
481
467
  }
482
468
  }
483
469
 
484
- // For deserializing JSON.
485
- TypeRegistry.register('Fq', Fq);
486
-
487
470
  // Beware: Performance bottleneck below
488
471
 
489
472
  /**
@@ -511,14 +494,6 @@ function extendedEuclidean(a: bigint, modulus: bigint): [bigint, bigint, bigint]
511
494
  }
512
495
  }
513
496
 
514
- /**
515
- * GrumpkinScalar is an Fq.
516
- * @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
517
- * the Aztec Protocol Specs.
518
- */
519
- export type GrumpkinScalar = Fq;
520
- export const GrumpkinScalar = Fq;
521
-
522
497
  /** Wraps a function that returns a buffer so that all results are reduced into a field of the given type. */
523
498
  export function reduceFn<TInput, TField extends BaseField>(fn: (input: TInput) => Buffer, field: DerivedField<TField>) {
524
499
  return (input: TInput) => fromBufferReduce(fn(input), field);
@@ -0,0 +1,2 @@
1
+ export * from './field.js';
2
+ export * from './point.js';
@@ -0,0 +1,170 @@
1
+ import {
2
+ BN254_G1_GENERATOR,
3
+ BN254_G2_GENERATOR,
4
+ BarretenbergSync,
5
+ type Bn254G1Point as BbApiBn254G1Point,
6
+ type Bn254G2Point as BbApiBn254G2Point,
7
+ } from '@aztec/bb.js';
8
+
9
+ import { Fq, Fr } from './field.js';
10
+
11
+ /**
12
+ * BN254 G1 point using foundation field classes.
13
+ * Represents a point on the BN254 elliptic curve in affine coordinates.
14
+ */
15
+ export class Bn254G1Point {
16
+ constructor(
17
+ public readonly x: Fq,
18
+ public readonly y: Fq,
19
+ ) {}
20
+
21
+ private toBbApiPoint(): BbApiBn254G1Point {
22
+ return {
23
+ x: this.x.toBuffer(),
24
+ y: this.y.toBuffer(),
25
+ };
26
+ }
27
+
28
+ private static fromBbApiPoint(point: BbApiBn254G1Point): Bn254G1Point {
29
+ return new Bn254G1Point(Fq.fromBuffer(Buffer.from(point.x)), Fq.fromBuffer(Buffer.from(point.y)));
30
+ }
31
+
32
+ async isOnCurve(): Promise<boolean> {
33
+ await BarretenbergSync.initSingleton();
34
+ const api = BarretenbergSync.getSingleton();
35
+
36
+ const apiPoint = this.toBbApiPoint();
37
+ const response = api.bn254G1IsOnCurve({ point: apiPoint });
38
+ return response.isOnCurve;
39
+ }
40
+
41
+ /**
42
+ * Get the generator point for BN254 G1, or perform scalar multiplication.
43
+ * When called without arguments, returns the base generator point.
44
+ * When called with a scalar, returns scalar * generator (useful for public key derivation).
45
+ */
46
+ static async generator(scalar?: Fr): Promise<Bn254G1Point> {
47
+ if (!scalar) {
48
+ return new Bn254G1Point(
49
+ Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.x)),
50
+ Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.y)),
51
+ );
52
+ }
53
+
54
+ await BarretenbergSync.initSingleton();
55
+ const api = BarretenbergSync.getSingleton();
56
+
57
+ const response = api.bn254G1Mul({
58
+ point: BN254_G1_GENERATOR,
59
+ scalar: scalar.toBuffer(),
60
+ });
61
+
62
+ return Bn254G1Point.fromBbApiPoint(response.point);
63
+ }
64
+
65
+ /**
66
+ * Decompress a BN254 G1 point from compressed form (32 bytes).
67
+ * The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
68
+ * in the most significant bit.
69
+ */
70
+ static async fromCompressed(compressed: Buffer): Promise<Bn254G1Point> {
71
+ if (compressed.length !== 32) {
72
+ throw new Error('Invalid compressed point length');
73
+ }
74
+ await BarretenbergSync.initSingleton();
75
+ const api = BarretenbergSync.getSingleton();
76
+
77
+ const response = api.bn254G1FromCompressed({
78
+ compressed: new Uint8Array(compressed),
79
+ });
80
+
81
+ return Bn254G1Point.fromBbApiPoint(response.point);
82
+ }
83
+
84
+ /**
85
+ * Compress this BN254 G1 point to 32 bytes.
86
+ * The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
87
+ * in the most significant bit (bit 255).
88
+ */
89
+ compress(): Buffer {
90
+ const xBytes = this.x.toBuffer();
91
+ // Get the least significant bit of y to determine the sign
92
+ const yLsb = this.y.toBigInt() & 1n;
93
+ // If y is odd, set the most significant bit (bit 255) of the output
94
+ if (yLsb === 1n) {
95
+ xBytes[0] |= 0x80;
96
+ }
97
+ return xBytes;
98
+ }
99
+
100
+ equals(other: Bn254G1Point): boolean {
101
+ return this.x.equals(other.x) && this.y.equals(other.y);
102
+ }
103
+
104
+ toString(): string {
105
+ return `Bn254G1Point(x: ${this.x.toString()}, y: ${this.y.toString()})`;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * BN254 G2 point using foundation field classes.
111
+ * Represents a point on the BN254 G2 curve (twist curve) in affine coordinates.
112
+ * G2 points use extension field coordinates (Fq2).
113
+ */
114
+ export class Bn254G2Point {
115
+ constructor(
116
+ public readonly x: [Fq, Fq],
117
+ public readonly y: [Fq, Fq],
118
+ ) {}
119
+
120
+ private toBbApiPoint(): BbApiBn254G2Point {
121
+ return {
122
+ x: [this.x[0].toBuffer(), this.x[1].toBuffer()],
123
+ y: [this.y[0].toBuffer(), this.y[1].toBuffer()],
124
+ };
125
+ }
126
+
127
+ private static fromBbApiPoint(point: BbApiBn254G2Point): Bn254G2Point {
128
+ return new Bn254G2Point(
129
+ [Fq.fromBuffer(Buffer.from(point.x[0])), Fq.fromBuffer(Buffer.from(point.x[1]))],
130
+ [Fq.fromBuffer(Buffer.from(point.y[0])), Fq.fromBuffer(Buffer.from(point.y[1]))],
131
+ );
132
+ }
133
+
134
+ /**
135
+ * Get the generator point for BN254 G2, or perform scalar multiplication.
136
+ * When called without arguments, returns the base generator point.
137
+ * When called with a scalar, returns scalar * generator.
138
+ */
139
+ static async generator(scalar?: Fr): Promise<Bn254G2Point> {
140
+ if (!scalar) {
141
+ return new Bn254G2Point(
142
+ [Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[1]))],
143
+ [Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[1]))],
144
+ );
145
+ }
146
+
147
+ await BarretenbergSync.initSingleton();
148
+ const api = BarretenbergSync.getSingleton();
149
+
150
+ const response = api.bn254G2Mul({
151
+ point: BN254_G2_GENERATOR as BbApiBn254G2Point,
152
+ scalar: scalar.toBuffer(),
153
+ });
154
+
155
+ return Bn254G2Point.fromBbApiPoint(response.point);
156
+ }
157
+
158
+ equals(other: Bn254G2Point): boolean {
159
+ return (
160
+ this.x[0].equals(other.x[0]) &&
161
+ this.x[1].equals(other.x[1]) &&
162
+ this.y[0].equals(other.y[0]) &&
163
+ this.y[1].equals(other.y[1])
164
+ );
165
+ }
166
+
167
+ toString(): string {
168
+ return `Bn254G2Point(x: (${this.x[0].toString()}, ${this.x[1].toString()}), y: (${this.y[0].toString()}, ${this.y[1].toString()}))`;
169
+ }
170
+ }
@@ -0,0 +1,11 @@
1
+ import { Fq } from '../bn254/field.js';
2
+
3
+ export * from './point.js';
4
+
5
+ /**
6
+ * GrumpkinScalar is an Fq.
7
+ * @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
8
+ * the Aztec Protocol Specs.
9
+ */
10
+ export type GrumpkinScalar = Fq;
11
+ export const GrumpkinScalar = Fq;
@@ -1,10 +1,10 @@
1
- import { toBigIntBE } from '../bigint-buffer/index.js';
2
- import { poseidon2Hash } from '../crypto/poseidon/index.js';
3
- import { randomBoolean } from '../crypto/random/index.js';
4
- import { hexSchemaFor } from '../schemas/utils.js';
5
- import { BufferReader, FieldReader, serializeToBuffer } from '../serialize/index.js';
6
- import { bufferToHex, hexToBuffer } from '../string/index.js';
7
- import { Fr } from './fields.js';
1
+ import { toBigIntBE } from '../../bigint-buffer/index.js';
2
+ import { poseidon2Hash } from '../../crypto/poseidon/index.js';
3
+ import { randomBoolean } from '../../crypto/random/index.js';
4
+ import { hexSchemaFor } from '../../schemas/utils.js';
5
+ import { BufferReader, FieldReader, serializeToBuffer } from '../../serialize/index.js';
6
+ import { bufferToHex, hexToBuffer } from '../../string/index.js';
7
+ import { Fr } from '../bn254/field.js';
8
8
 
9
9
  /**
10
10
  * Represents a Point on an elliptic curve with x and y coordinates.
@@ -65,7 +65,7 @@ export class Point {
65
65
  }
66
66
 
67
67
  /**
68
- * Generate a random Point instance.
68
+ * Generate a random Point instance that is on the curve.
69
69
  *
70
70
  * @returns A randomly generated Point instance.
71
71
  */
@@ -125,9 +125,12 @@ export class Point {
125
125
  }
126
126
 
127
127
  /**
128
- * Returns the contents of the point as an array of 2 fields.
129
- * @returns The point as an array of 2 fields
128
+ * Returns the contents of the point as an array of 3 fields.
129
+ * @returns The point as an array of 3 fields
130
130
  */
131
+ // TODO(F-553): Once we take the breaking change and drop the custom Noir `Point` wrapper in
132
+ // `noir-projects/noir-protocol-circuits/crates/types/src/point.nr`, revert this to serialize as `[x, y]` (2 fields)
133
+ // and drop the `is_infinite` flag from `fromFields` / `toNoirStruct` below.
131
134
  toFields() {
132
135
  return [this.x, this.y, new Fr(this.isInfinite)];
133
136
  }
@@ -2,10 +2,9 @@ import { inspect } from 'util';
2
2
 
3
3
  import { keccak256String } from '../crypto/keccak/index.js';
4
4
  import { randomBytes } from '../crypto/random/index.js';
5
- import { Fr } from '../fields/index.js';
5
+ import { Fr } from '../curves/bn254/index.js';
6
6
  import { hexSchemaFor } from '../schemas/utils.js';
7
7
  import { BufferReader, FieldReader } from '../serialize/index.js';
8
- import { TypeRegistry } from '../serialize/type_registry.js';
9
8
  import { bufferToHex } from '../string/index.js';
10
9
 
11
10
  /**
@@ -249,7 +248,7 @@ export class EthAddress {
249
248
  /** Converts a number into an address. Useful for testing. */
250
249
  static fromNumber(num: bigint | number): EthAddress {
251
250
  const buffer = Buffer.alloc(EthAddress.SIZE_IN_BYTES);
252
- buffer.writeBigUInt64BE(BigInt(num), 0);
251
+ buffer.writeBigUInt64BE(BigInt(num), EthAddress.SIZE_IN_BYTES - 8);
253
252
  return new EthAddress(buffer);
254
253
  }
255
254
 
@@ -261,7 +260,10 @@ export class EthAddress {
261
260
  // Serialization from hex string.
262
261
  return hexSchemaFor(EthAddress, EthAddress.isAddress);
263
262
  }
264
- }
265
263
 
266
- // For deserializing JSON.
267
- TypeRegistry.register('EthAddress', EthAddress);
264
+ static areEqual(a: EthAddress | string, b: EthAddress | string) {
265
+ const addrA = typeof a === 'string' ? EthAddress.fromString(a) : a;
266
+ const addrB = typeof b === 'string' ? EthAddress.fromString(b) : b;
267
+ return addrA.equals(addrB);
268
+ }
269
+ }
@@ -1,8 +1,10 @@
1
1
  import { Buffer32 } from '@aztec/foundation/buffer';
2
2
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
3
 
4
+ import { secp256k1 } from '@noble/curves/secp256k1';
4
5
  import { z } from 'zod';
5
6
 
7
+ import { randomBytes } from '../crypto/random/index.js';
6
8
  import { hasHexPrefix, hexToBuffer } from '../string/index.js';
7
9
 
8
10
  /**
@@ -77,8 +79,12 @@ export class Signature {
77
79
  return new Signature(Buffer32.fromBuffer(hexToBuffer(sig.r)), Buffer32.fromBuffer(hexToBuffer(sig.s)), sig.yParity);
78
80
  }
79
81
 
82
+ /** Generates a random valid ECDSA signature with a low s-value by signing a random message with a random key. */
80
83
  static random(): Signature {
81
- return new Signature(Buffer32.random(), Buffer32.random(), 1);
84
+ const privateKey = randomBytes(32);
85
+ const message = randomBytes(32);
86
+ const { r, s, recovery } = secp256k1.sign(message, privateKey);
87
+ return new Signature(Buffer32.fromBigInt(r), Buffer32.fromBigInt(s), recovery ? 28 : 27);
82
88
  }
83
89
 
84
90
  static empty(): Signature {
@@ -0,0 +1,98 @@
1
+ import EventEmitter from 'node:events';
2
+ import * as fs from 'node:fs';
3
+ import type { Readable } from 'node:stream';
4
+
5
+ /**
6
+ * Events emitted by FifoFrameReader.
7
+ *
8
+ * - `frame`: A complete frame payload (without the 4-byte length header).
9
+ * - `error`: An unrecoverable error (invalid frame length, stream error).
10
+ * - `end`: The underlying stream has ended.
11
+ */
12
+ export interface FifoFrameReaderEvents {
13
+ frame: [payload: Buffer];
14
+ error: [error: Error];
15
+ end: [];
16
+ }
17
+
18
+ /**
19
+ * Reads length-delimited frames from a readable stream (typically a named FIFO pipe).
20
+ *
21
+ * Wire format: `[4-byte big-endian payload length][payload bytes]`
22
+ *
23
+ * Emits a `frame` event for each complete frame with the raw payload buffer.
24
+ * Callers are responsible for deserializing the payload (e.g., via msgpack).
25
+ *
26
+ * On encountering an invalid payload length (0 or >maxPayloadSize), emits `error`
27
+ * and destroys the stream.
28
+ */
29
+ export class FifoFrameReader extends EventEmitter<FifoFrameReaderEvents> {
30
+ private stream: Readable | null = null;
31
+ private pendingBuf: Buffer = Buffer.alloc(0);
32
+ private running = false;
33
+
34
+ constructor(private readonly maxPayloadSize = 10 * 1024 * 1024) {
35
+ super();
36
+ }
37
+
38
+ /** Open a FIFO at the given path and start reading frames. */
39
+ start(fifoPath: string, highWaterMark = 64 * 1024): void {
40
+ this.startFromStream(fs.createReadStream(fifoPath, { highWaterMark }));
41
+ }
42
+
43
+ /** Start reading frames from an existing readable stream. */
44
+ startFromStream(stream: Readable): void {
45
+ if (this.running) {
46
+ throw new Error('FifoFrameReader is already running');
47
+ }
48
+ this.running = true;
49
+ this.pendingBuf = Buffer.alloc(0);
50
+ this.stream = stream;
51
+
52
+ stream.on('data', (chunk: Buffer | string) => {
53
+ const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
54
+ this.pendingBuf = this.pendingBuf.length > 0 ? Buffer.concat([this.pendingBuf, buf]) : buf;
55
+ this.drainFrames();
56
+ });
57
+
58
+ stream.on('error', (err: Error) => {
59
+ if (this.running) {
60
+ this.emit('error', err);
61
+ }
62
+ });
63
+
64
+ stream.on('end', () => {
65
+ this.emit('end');
66
+ });
67
+ }
68
+
69
+ /** Stop reading and destroy the underlying stream. */
70
+ stop(): void {
71
+ this.running = false;
72
+ if (this.stream) {
73
+ this.stream.destroy();
74
+ this.stream = null;
75
+ }
76
+ }
77
+
78
+ /** Parse complete frames out of the pending buffer. */
79
+ private drainFrames(): void {
80
+ while (this.pendingBuf.length >= 4) {
81
+ const payloadLen = this.pendingBuf.readUInt32BE(0);
82
+ if (payloadLen === 0 || payloadLen > this.maxPayloadSize) {
83
+ this.emit('error', new Error(`Invalid payload length: ${payloadLen}`));
84
+ this.stop();
85
+ return;
86
+ }
87
+
88
+ const frameLen = 4 + payloadLen;
89
+ if (this.pendingBuf.length < frameLen) {
90
+ break; // Wait for more data
91
+ }
92
+
93
+ const payload = this.pendingBuf.subarray(4, frameLen);
94
+ this.pendingBuf = this.pendingBuf.subarray(frameLen);
95
+ this.emit('frame', Buffer.from(payload));
96
+ }
97
+ }
98
+ }
@@ -0,0 +1 @@
1
+ export { FifoFrameReader } from './fifo_frame_reader.js';
@@ -0,0 +1,11 @@
1
+ /** Wraps an async iterable iterator such that it filters values based on a predicate. */
2
+ export async function* filter<T>(
3
+ iterator: AsyncIterableIterator<T>,
4
+ predicate: (item: T) => boolean | Promise<boolean>,
5
+ ): AsyncIterableIterator<T> {
6
+ for await (const item of iterator) {
7
+ if (await predicate(item)) {
8
+ yield item;
9
+ }
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ export { filter } from './filter.js';