@aztec/foundation 0.0.0-test.1 → 0.0.1-commit.b655e406

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 (510) hide show
  1. package/dest/array/array.d.ts +5 -0
  2. package/dest/array/array.d.ts.map +1 -1
  3. package/dest/array/array.js +11 -0
  4. package/dest/async-pool/index.d.ts.map +1 -1
  5. package/dest/async-pool/index.js +1 -0
  6. package/dest/bigint/index.d.ts +7 -0
  7. package/dest/bigint/index.d.ts.map +1 -0
  8. package/dest/bigint/index.js +15 -0
  9. package/dest/bigint-buffer/index.d.ts +0 -2
  10. package/dest/bigint-buffer/index.d.ts.map +1 -1
  11. package/dest/buffer/buffer16.d.ts +80 -0
  12. package/dest/buffer/buffer16.d.ts.map +1 -0
  13. package/dest/buffer/buffer16.js +100 -0
  14. package/dest/buffer/buffer32.d.ts +3 -7
  15. package/dest/buffer/buffer32.d.ts.map +1 -1
  16. package/dest/buffer/buffer32.js +6 -6
  17. package/dest/buffer/index.d.ts +1 -0
  18. package/dest/buffer/index.d.ts.map +1 -1
  19. package/dest/buffer/index.js +1 -0
  20. package/dest/collection/array.d.ts +16 -3
  21. package/dest/collection/array.d.ts.map +1 -1
  22. package/dest/collection/array.js +57 -3
  23. package/dest/collection/object.d.ts +16 -0
  24. package/dest/collection/object.d.ts.map +1 -1
  25. package/dest/collection/object.js +25 -0
  26. package/dest/config/env_var.d.ts +1 -1
  27. package/dest/config/env_var.d.ts.map +1 -1
  28. package/dest/config/index.d.ts +48 -1
  29. package/dest/config/index.d.ts.map +1 -1
  30. package/dest/config/index.js +115 -7
  31. package/dest/config/network_config.d.ts +42 -0
  32. package/dest/config/network_config.d.ts.map +1 -0
  33. package/dest/config/network_config.js +9 -0
  34. package/dest/config/network_name.d.ts +3 -0
  35. package/dest/config/network_name.d.ts.map +1 -0
  36. package/dest/config/network_name.js +19 -0
  37. package/dest/config/secret_value.d.ts +28 -0
  38. package/dest/config/secret_value.d.ts.map +1 -0
  39. package/dest/config/secret_value.js +34 -0
  40. package/dest/crypto/aes128/index.d.ts +2 -4
  41. package/dest/crypto/aes128/index.d.ts.map +1 -1
  42. package/dest/crypto/aes128/index.js +23 -6
  43. package/dest/crypto/bls/bn254_keystore.d.ts +296 -0
  44. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -0
  45. package/dest/crypto/bls/bn254_keystore.js +218 -0
  46. package/dest/crypto/bls/index.d.ts +13 -0
  47. package/dest/crypto/bls/index.d.ts.map +1 -0
  48. package/dest/crypto/bls/index.js +87 -0
  49. package/dest/crypto/bn254/bn254_utils.d.ts +39 -0
  50. package/dest/crypto/bn254/bn254_utils.d.ts.map +1 -0
  51. package/dest/crypto/bn254/bn254_utils.js +56 -0
  52. package/dest/crypto/bn254/index.d.ts +55 -0
  53. package/dest/crypto/bn254/index.d.ts.map +1 -0
  54. package/dest/crypto/bn254/index.js +142 -0
  55. package/dest/crypto/ecdsa/index.d.ts +2 -2
  56. package/dest/crypto/ecdsa/index.d.ts.map +1 -1
  57. package/dest/crypto/ecdsa/index.js +70 -48
  58. package/dest/crypto/ecdsa/signature.d.ts +1 -3
  59. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  60. package/dest/crypto/grumpkin/index.d.ts +6 -13
  61. package/dest/crypto/grumpkin/index.d.ts.map +1 -1
  62. package/dest/crypto/grumpkin/index.js +69 -54
  63. package/dest/crypto/index.d.ts +2 -0
  64. package/dest/crypto/index.d.ts.map +1 -1
  65. package/dest/crypto/index.js +2 -0
  66. package/dest/crypto/keccak/index.d.ts +2 -4
  67. package/dest/crypto/keccak/index.d.ts.map +1 -1
  68. package/dest/crypto/keys/index.d.ts +0 -2
  69. package/dest/crypto/keys/index.d.ts.map +1 -1
  70. package/dest/crypto/keys/index.js +9 -4
  71. package/dest/crypto/pedersen/pedersen.noble.d.ts +2 -4
  72. package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -1
  73. package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -4
  74. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  75. package/dest/crypto/pedersen/pedersen.wasm.js +29 -13
  76. package/dest/crypto/poseidon/index.d.ts +0 -2
  77. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  78. package/dest/crypto/poseidon/index.js +42 -17
  79. package/dest/crypto/random/index.d.ts +1 -3
  80. package/dest/crypto/random/index.d.ts.map +1 -1
  81. package/dest/crypto/random/index.js +2 -34
  82. package/dest/crypto/random/randomness_singleton.d.ts +0 -2
  83. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  84. package/dest/crypto/schnorr/index.d.ts.map +1 -1
  85. package/dest/crypto/schnorr/index.js +35 -37
  86. package/dest/crypto/schnorr/signature.d.ts +3 -5
  87. package/dest/crypto/schnorr/signature.d.ts.map +1 -1
  88. package/dest/crypto/secp256k1/index.d.ts +4 -6
  89. package/dest/crypto/secp256k1/index.d.ts.map +1 -1
  90. package/dest/crypto/secp256k1/index.js +29 -18
  91. package/dest/crypto/secp256k1-signer/utils.d.ts +55 -4
  92. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  93. package/dest/crypto/secp256k1-signer/utils.js +92 -6
  94. package/dest/crypto/serialize.d.ts +4 -6
  95. package/dest/crypto/serialize.d.ts.map +1 -1
  96. package/dest/crypto/sha256/index.d.ts +21 -4
  97. package/dest/crypto/sha256/index.d.ts.map +1 -1
  98. package/dest/crypto/sha256/index.js +42 -0
  99. package/dest/crypto/sha512/index.d.ts +1 -3
  100. package/dest/crypto/sha512/index.d.ts.map +1 -1
  101. package/dest/crypto/signature/index.d.ts +0 -2
  102. package/dest/crypto/signature/index.d.ts.map +1 -1
  103. package/dest/crypto/sync/index.js +3 -1
  104. package/dest/crypto/sync/pedersen/index.d.ts +2 -4
  105. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
  106. package/dest/crypto/sync/pedersen/index.js +17 -10
  107. package/dest/crypto/sync/poseidon/index.d.ts +0 -2
  108. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  109. package/dest/crypto/sync/poseidon/index.js +27 -12
  110. package/dest/decorators/memoize.d.ts.map +1 -1
  111. package/dest/eth-address/index.d.ts +6 -7
  112. package/dest/eth-address/index.d.ts.map +1 -1
  113. package/dest/eth-address/index.js +5 -0
  114. package/dest/eth-signature/eth_signature.d.ts +16 -14
  115. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  116. package/dest/eth-signature/eth_signature.js +31 -17
  117. package/dest/fields/bls12_fields.d.ts +148 -0
  118. package/dest/fields/bls12_fields.d.ts.map +1 -0
  119. package/dest/fields/bls12_fields.js +359 -0
  120. package/dest/fields/bls12_point.d.ts +229 -0
  121. package/dest/fields/bls12_point.d.ts.map +1 -0
  122. package/dest/fields/bls12_point.js +398 -0
  123. package/dest/fields/coordinate.d.ts +0 -2
  124. package/dest/fields/coordinate.d.ts.map +1 -1
  125. package/dest/fields/fields.d.ts +6 -3
  126. package/dest/fields/fields.d.ts.map +1 -1
  127. package/dest/fields/fields.js +43 -15
  128. package/dest/fields/index.d.ts +2 -0
  129. package/dest/fields/index.d.ts.map +1 -1
  130. package/dest/fields/index.js +2 -0
  131. package/dest/fields/point.d.ts +2 -4
  132. package/dest/fields/point.d.ts.map +1 -1
  133. package/dest/fields/point.js +3 -3
  134. package/dest/fs/index.d.ts +1 -0
  135. package/dest/fs/index.d.ts.map +1 -1
  136. package/dest/fs/index.js +1 -0
  137. package/dest/fs/try_rm_dir.d.ts +3 -0
  138. package/dest/fs/try_rm_dir.d.ts.map +1 -0
  139. package/dest/fs/try_rm_dir.js +16 -0
  140. package/dest/index.d.ts +1 -2
  141. package/dest/index.d.ts.map +1 -1
  142. package/dest/index.js +1 -2
  143. package/dest/iterable/filter.js +1 -1
  144. package/dest/iterable/map.js +1 -1
  145. package/dest/jest/env.js +48 -0
  146. package/dest/jest/setupAfterEnv.js +3 -0
  147. package/dest/json-rpc/client/fetch.d.ts +2 -2
  148. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  149. package/dest/json-rpc/client/fetch.js +16 -30
  150. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +9 -3
  151. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  152. package/dest/json-rpc/client/safe_json_rpc_client.js +173 -13
  153. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  154. package/dest/json-rpc/client/undici.js +6 -7
  155. package/dest/json-rpc/convert.d.ts +2 -9
  156. package/dest/json-rpc/convert.d.ts.map +1 -1
  157. package/dest/json-rpc/convert.js +1 -9
  158. package/dest/json-rpc/errors.d.ts +4 -0
  159. package/dest/json-rpc/errors.d.ts.map +1 -0
  160. package/dest/json-rpc/errors.js +6 -0
  161. package/dest/json-rpc/fixtures/class_a.d.ts +5 -3
  162. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  163. package/dest/json-rpc/fixtures/class_b.d.ts +5 -3
  164. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  165. package/dest/json-rpc/index.d.ts +2 -1
  166. package/dest/json-rpc/index.d.ts.map +1 -1
  167. package/dest/json-rpc/index.js +2 -1
  168. package/dest/json-rpc/js_utils.d.ts.map +1 -1
  169. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +21 -22
  170. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  171. package/dest/json-rpc/server/safe_json_rpc_server.js +161 -56
  172. package/dest/json-rpc/test/integration.d.ts +1 -2
  173. package/dest/json-rpc/test/integration.d.ts.map +1 -1
  174. package/dest/log/console.d.ts.map +1 -1
  175. package/dest/log/gcloud-logger-config.d.ts +0 -1
  176. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  177. package/dest/log/gcloud-logger-config.js +1 -9
  178. package/dest/log/index.d.ts +4 -4
  179. package/dest/log/index.d.ts.map +1 -1
  180. package/dest/log/index.js +4 -4
  181. package/dest/log/libp2p_logger.js +13 -2
  182. package/dest/log/log_fn.d.ts +1 -1
  183. package/dest/log/log_fn.d.ts.map +1 -1
  184. package/dest/log/noir_debug_log_util.d.ts +14 -0
  185. package/dest/log/noir_debug_log_util.d.ts.map +1 -0
  186. package/dest/log/noir_debug_log_util.js +14 -0
  187. package/dest/log/pino-logger.d.ts +2 -2
  188. package/dest/log/pino-logger.d.ts.map +1 -1
  189. package/dest/log/pino-logger.js +28 -2
  190. package/dest/message/index.d.ts.map +1 -1
  191. package/dest/mutex/mutex_database.d.ts.map +1 -1
  192. package/dest/noir/noir_package_config.d.ts +4 -4
  193. package/dest/number/index.d.ts +3 -0
  194. package/dest/number/index.d.ts.map +1 -0
  195. package/dest/number/index.js +12 -0
  196. package/dest/profiler/index.d.ts +2 -0
  197. package/dest/profiler/index.d.ts.map +1 -0
  198. package/dest/profiler/index.js +1 -0
  199. package/dest/profiler/profiler.d.ts +8 -0
  200. package/dest/profiler/profiler.d.ts.map +1 -0
  201. package/dest/profiler/profiler.js +97 -0
  202. package/dest/promise/running-promise.d.ts +1 -1
  203. package/dest/promise/running-promise.d.ts.map +1 -1
  204. package/dest/promise/running-promise.js +2 -2
  205. package/dest/queue/batch_queue.d.ts +1 -1
  206. package/dest/queue/batch_queue.js +1 -1
  207. package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
  208. package/dest/queue/serial_queue.d.ts +2 -2
  209. package/dest/queue/serial_queue.d.ts.map +1 -1
  210. package/dest/queue/serial_queue.js +7 -5
  211. package/dest/retry/index.d.ts +3 -2
  212. package/dest/retry/index.d.ts.map +1 -1
  213. package/dest/retry/index.js +2 -2
  214. package/dest/schemas/api.d.ts.map +1 -1
  215. package/dest/schemas/parse.js +1 -1
  216. package/dest/schemas/schemas.d.ts +9 -6
  217. package/dest/schemas/schemas.d.ts.map +1 -1
  218. package/dest/schemas/schemas.js +15 -1
  219. package/dest/schemas/utils.d.ts +1 -3
  220. package/dest/schemas/utils.d.ts.map +1 -1
  221. package/dest/serialize/buffer_reader.d.ts +27 -2
  222. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  223. package/dest/serialize/buffer_reader.js +44 -2
  224. package/dest/serialize/field_reader.d.ts +10 -1
  225. package/dest/serialize/field_reader.d.ts.map +1 -1
  226. package/dest/serialize/field_reader.js +18 -1
  227. package/dest/serialize/free_funcs.d.ts +23 -21
  228. package/dest/serialize/free_funcs.d.ts.map +1 -1
  229. package/dest/serialize/free_funcs.js +21 -27
  230. package/dest/serialize/serialize.d.ts +4 -5
  231. package/dest/serialize/serialize.d.ts.map +1 -1
  232. package/dest/string/index.d.ts +7 -2
  233. package/dest/string/index.d.ts.map +1 -1
  234. package/dest/string/index.js +27 -1
  235. package/dest/testing/files/index.d.ts +0 -2
  236. package/dest/testing/files/index.d.ts.map +1 -1
  237. package/dest/testing/files/index.js +2 -2
  238. package/dest/testing/formatting.d.ts +4 -0
  239. package/dest/testing/formatting.d.ts.map +1 -0
  240. package/dest/testing/formatting.js +3 -0
  241. package/dest/testing/index.d.ts +1 -0
  242. package/dest/testing/index.d.ts.map +1 -1
  243. package/dest/testing/index.js +1 -0
  244. package/dest/timer/date.d.ts +2 -1
  245. package/dest/timer/date.d.ts.map +1 -1
  246. package/dest/timer/date.js +5 -3
  247. package/dest/timer/index.d.ts +1 -1
  248. package/dest/timer/index.d.ts.map +1 -1
  249. package/dest/timer/index.js +1 -1
  250. package/dest/timer/timeout.d.ts +18 -5
  251. package/dest/timer/timeout.d.ts.map +1 -1
  252. package/dest/timer/timeout.js +43 -22
  253. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  254. package/dest/transport/index.d.ts +0 -1
  255. package/dest/transport/index.d.ts.map +1 -1
  256. package/dest/transport/index.js +0 -1
  257. package/dest/transport/interface/connector.d.ts.map +1 -1
  258. package/dest/transport/interface/listener.d.ts +0 -1
  259. package/dest/transport/interface/listener.d.ts.map +1 -1
  260. package/dest/transport/interface/socket.d.ts.map +1 -1
  261. package/dest/transport/node/node_connector.d.ts +0 -1
  262. package/dest/transport/node/node_connector.d.ts.map +1 -1
  263. package/dest/transport/node/node_connector_socket.d.ts +0 -1
  264. package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
  265. package/dest/transport/node/node_listener.d.ts +0 -1
  266. package/dest/transport/node/node_listener.d.ts.map +1 -1
  267. package/dest/transport/node/node_listener_socket.d.ts +0 -1
  268. package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
  269. package/dest/transport/transport_client.d.ts +0 -1
  270. package/dest/transport/transport_client.d.ts.map +1 -1
  271. package/dest/transport/transport_server.d.ts.map +1 -1
  272. package/dest/trees/hasher.d.ts +4 -6
  273. package/dest/trees/hasher.d.ts.map +1 -1
  274. package/dest/trees/index.d.ts +1 -0
  275. package/dest/trees/index.d.ts.map +1 -1
  276. package/dest/trees/index.js +1 -0
  277. package/dest/trees/indexed_merkle_tree.d.ts +0 -2
  278. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -1
  279. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -3
  280. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  281. package/dest/trees/indexed_tree_leaf.d.ts +0 -2
  282. package/dest/trees/indexed_tree_leaf.d.ts.map +1 -1
  283. package/dest/trees/membership_witness.d.ts +19 -3
  284. package/dest/trees/membership_witness.d.ts.map +1 -1
  285. package/dest/trees/membership_witness.js +13 -0
  286. package/dest/trees/merkle_tree.d.ts +0 -2
  287. package/dest/trees/merkle_tree.d.ts.map +1 -1
  288. package/dest/trees/merkle_tree_calculator.d.ts +11 -3
  289. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  290. package/dest/trees/merkle_tree_calculator.js +31 -1
  291. package/dest/trees/sibling_path.d.ts +6 -8
  292. package/dest/trees/sibling_path.d.ts.map +1 -1
  293. package/dest/trees/unbalanced_merkle_tree.d.ts +19 -8
  294. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
  295. package/dest/trees/unbalanced_merkle_tree.js +49 -50
  296. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +48 -0
  297. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -0
  298. package/dest/trees/unbalanced_merkle_tree_calculator.js +162 -0
  299. package/dest/trees/unbalanced_tree_store.d.ts +1 -0
  300. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  301. package/dest/trees/unbalanced_tree_store.js +6 -0
  302. package/dest/types/index.d.ts +25 -2
  303. package/dest/types/index.d.ts.map +1 -1
  304. package/dest/url/index.d.ts.map +1 -1
  305. package/dest/url/index.js +1 -1
  306. package/package.json +35 -41
  307. package/src/array/array.ts +13 -0
  308. package/src/async-pool/index.ts +1 -0
  309. package/src/bigint/index.ts +20 -0
  310. package/src/buffer/buffer16.ts +133 -0
  311. package/src/buffer/buffer32.ts +8 -6
  312. package/src/buffer/index.ts +1 -0
  313. package/src/collection/array.ts +66 -4
  314. package/src/collection/object.ts +37 -0
  315. package/src/config/env_var.ts +142 -52
  316. package/src/config/index.ts +191 -8
  317. package/src/config/network_config.ts +16 -0
  318. package/src/config/network_name.ts +28 -0
  319. package/src/config/secret_value.ts +49 -0
  320. package/src/crypto/aes128/index.ts +19 -10
  321. package/src/crypto/bls/bn254_keystore.ts +287 -0
  322. package/src/crypto/bls/index.ts +77 -0
  323. package/src/crypto/bn254/bn254_utils.ts +64 -0
  324. package/src/crypto/bn254/index.ts +170 -0
  325. package/src/crypto/ecdsa/index.ts +41 -23
  326. package/src/crypto/grumpkin/index.ts +35 -45
  327. package/src/crypto/index.ts +2 -0
  328. package/src/crypto/keys/index.ts +5 -5
  329. package/src/crypto/pedersen/pedersen.wasm.ts +22 -18
  330. package/src/crypto/poseidon/index.ts +32 -24
  331. package/src/crypto/random/index.ts +2 -40
  332. package/src/crypto/schnorr/index.ts +20 -17
  333. package/src/crypto/secp256k1/index.ts +15 -11
  334. package/src/crypto/secp256k1-signer/utils.ts +120 -7
  335. package/src/crypto/sha256/index.ts +47 -0
  336. package/src/crypto/sync/index.ts +1 -1
  337. package/src/crypto/sync/pedersen/index.ts +16 -15
  338. package/src/crypto/sync/poseidon/index.ts +27 -22
  339. package/src/eth-address/index.ts +9 -2
  340. package/src/eth-signature/eth_signature.ts +44 -22
  341. package/src/fields/bls12_fields.ts +463 -0
  342. package/src/fields/bls12_point.ts +450 -0
  343. package/src/fields/fields.ts +37 -9
  344. package/src/fields/index.ts +2 -0
  345. package/src/fields/point.ts +1 -3
  346. package/src/fs/index.ts +1 -0
  347. package/src/fs/try_rm_dir.ts +15 -0
  348. package/src/index.ts +1 -2
  349. package/src/iterable/filter.ts +1 -1
  350. package/src/iterable/map.ts +1 -1
  351. package/src/jest/env.mjs +52 -0
  352. package/src/jest/setupAfterEnv.mjs +3 -0
  353. package/src/json-rpc/client/fetch.ts +14 -33
  354. package/src/json-rpc/client/safe_json_rpc_client.ts +226 -13
  355. package/src/json-rpc/client/undici.ts +8 -15
  356. package/src/json-rpc/convert.ts +3 -12
  357. package/src/json-rpc/errors.ts +6 -0
  358. package/src/json-rpc/fixtures/class_a.ts +4 -1
  359. package/src/json-rpc/fixtures/class_b.ts +4 -1
  360. package/src/json-rpc/index.ts +2 -1
  361. package/src/json-rpc/server/safe_json_rpc_server.ts +141 -48
  362. package/src/json-rpc/test/integration.ts +1 -1
  363. package/src/log/console.ts +4 -1
  364. package/src/log/gcloud-logger-config.ts +3 -7
  365. package/src/log/index.ts +4 -4
  366. package/src/log/libp2p_logger.ts +21 -2
  367. package/src/log/log_fn.ts +1 -1
  368. package/src/log/noir_debug_log_util.ts +21 -0
  369. package/src/log/pino-logger.ts +33 -2
  370. package/src/message/index.ts +5 -1
  371. package/src/mutex/mutex_database.ts +2 -3
  372. package/src/number/index.ts +14 -0
  373. package/src/profiler/index.ts +1 -0
  374. package/src/profiler/profiler.ts +125 -0
  375. package/src/promise/running-promise.ts +2 -2
  376. package/src/queue/batch_queue.ts +1 -1
  377. package/src/queue/bounded_serial_queue.ts +4 -1
  378. package/src/queue/serial_queue.ts +5 -5
  379. package/src/retry/index.ts +10 -5
  380. package/src/schemas/api.ts +4 -4
  381. package/src/schemas/parse.ts +1 -1
  382. package/src/schemas/schemas.ts +19 -1
  383. package/src/serialize/buffer_reader.ts +60 -3
  384. package/src/serialize/field_reader.ts +27 -3
  385. package/src/serialize/free_funcs.ts +25 -31
  386. package/src/serialize/serialize.ts +2 -0
  387. package/src/string/index.ts +36 -1
  388. package/src/testing/files/index.ts +6 -2
  389. package/src/testing/formatting.ts +3 -0
  390. package/src/testing/index.ts +1 -0
  391. package/src/timer/date.ts +9 -3
  392. package/src/timer/index.ts +1 -1
  393. package/src/timer/timeout.ts +54 -19
  394. package/src/transport/index.ts +0 -1
  395. package/src/transport/interface/connector.ts +0 -1
  396. package/src/transport/interface/listener.ts +2 -3
  397. package/src/transport/interface/socket.ts +2 -3
  398. package/src/transport/transport_client.ts +3 -4
  399. package/src/transport/transport_server.ts +4 -1
  400. package/src/trees/hasher.ts +4 -4
  401. package/src/trees/index.ts +1 -0
  402. package/src/trees/indexed_merkle_tree.ts +5 -1
  403. package/src/trees/indexed_merkle_tree_calculator.ts +2 -2
  404. package/src/trees/membership_witness.ts +13 -0
  405. package/src/trees/merkle_tree.ts +4 -1
  406. package/src/trees/merkle_tree_calculator.ts +43 -5
  407. package/src/trees/unbalanced_merkle_tree.ts +50 -42
  408. package/src/trees/unbalanced_merkle_tree_calculator.ts +194 -0
  409. package/src/trees/unbalanced_tree_store.ts +5 -1
  410. package/src/types/index.ts +25 -4
  411. package/src/url/index.ts +0 -1
  412. package/dest/crypto/pedersen/pedersen.elliptic.d.ts +0 -13
  413. package/dest/crypto/pedersen/pedersen.elliptic.d.ts.map +0 -1
  414. package/dest/crypto/pedersen/pedersen.elliptic.js +0 -582
  415. package/dest/log/debug.d.ts +0 -56
  416. package/dest/log/debug.d.ts.map +0 -1
  417. package/dest/log/debug.js +0 -75
  418. package/dest/log/log_history.d.ts +0 -31
  419. package/dest/log/log_history.d.ts.map +0 -1
  420. package/dest/log/log_history.js +0 -38
  421. package/dest/transport/browser/index.d.ts +0 -5
  422. package/dest/transport/browser/index.d.ts.map +0 -1
  423. package/dest/transport/browser/index.js +0 -4
  424. package/dest/transport/browser/message_port_socket.d.ts +0 -37
  425. package/dest/transport/browser/message_port_socket.d.ts.map +0 -1
  426. package/dest/transport/browser/message_port_socket.js +0 -42
  427. package/dest/transport/browser/shared_worker_connector.d.ts +0 -19
  428. package/dest/transport/browser/shared_worker_connector.d.ts.map +0 -1
  429. package/dest/transport/browser/shared_worker_connector.js +0 -19
  430. package/dest/transport/browser/shared_worker_listener.d.ts +0 -38
  431. package/dest/transport/browser/shared_worker_listener.d.ts.map +0 -1
  432. package/dest/transport/browser/shared_worker_listener.js +0 -33
  433. package/dest/transport/browser/worker_connector.d.ts +0 -26
  434. package/dest/transport/browser/worker_connector.d.ts.map +0 -1
  435. package/dest/transport/browser/worker_connector.js +0 -30
  436. package/dest/transport/browser/worker_listener.d.ts +0 -39
  437. package/dest/transport/browser/worker_listener.d.ts.map +0 -1
  438. package/dest/transport/browser/worker_listener.js +0 -35
  439. package/dest/wasm/empty_wasi_sdk.d.ts +0 -130
  440. package/dest/wasm/empty_wasi_sdk.d.ts.map +0 -1
  441. package/dest/wasm/empty_wasi_sdk.js +0 -148
  442. package/dest/wasm/index.d.ts +0 -2
  443. package/dest/wasm/index.d.ts.map +0 -1
  444. package/dest/wasm/index.js +0 -1
  445. package/dest/wasm/wasm_module.d.ts +0 -136
  446. package/dest/wasm/wasm_module.d.ts.map +0 -1
  447. package/dest/wasm/wasm_module.js +0 -196
  448. package/dest/worker/browser/index.d.ts +0 -3
  449. package/dest/worker/browser/index.d.ts.map +0 -1
  450. package/dest/worker/browser/index.js +0 -2
  451. package/dest/worker/browser/start_web_module.d.ts +0 -7
  452. package/dest/worker/browser/start_web_module.d.ts.map +0 -1
  453. package/dest/worker/browser/start_web_module.js +0 -27
  454. package/dest/worker/browser/web_data_store.d.ts +0 -24
  455. package/dest/worker/browser/web_data_store.d.ts.map +0 -1
  456. package/dest/worker/browser/web_data_store.js +0 -29
  457. package/dest/worker/browser/web_worker.d.ts +0 -10
  458. package/dest/worker/browser/web_worker.d.ts.map +0 -1
  459. package/dest/worker/browser/web_worker.js +0 -25
  460. package/dest/worker/data_store.d.ts +0 -21
  461. package/dest/worker/data_store.d.ts.map +0 -1
  462. package/dest/worker/data_store.js +0 -3
  463. package/dest/worker/index.d.ts +0 -3
  464. package/dest/worker/index.d.ts.map +0 -1
  465. package/dest/worker/index.js +0 -1
  466. package/dest/worker/node/index.d.ts +0 -3
  467. package/dest/worker/node/index.d.ts.map +0 -1
  468. package/dest/worker/node/index.js +0 -2
  469. package/dest/worker/node/node_data_store.d.ts +0 -13
  470. package/dest/worker/node/node_data_store.d.ts.map +0 -1
  471. package/dest/worker/node/node_data_store.js +0 -20
  472. package/dest/worker/node/node_worker.d.ts +0 -6
  473. package/dest/worker/node/node_worker.d.ts.map +0 -1
  474. package/dest/worker/node/node_worker.js +0 -22
  475. package/dest/worker/node/start_node_module.d.ts +0 -7
  476. package/dest/worker/node/start_node_module.d.ts.map +0 -1
  477. package/dest/worker/node/start_node_module.js +0 -31
  478. package/dest/worker/wasm_worker.d.ts +0 -9
  479. package/dest/worker/wasm_worker.d.ts.map +0 -1
  480. package/dest/worker/wasm_worker.js +0 -3
  481. package/dest/worker/worker_pool.d.ts +0 -40
  482. package/dest/worker/worker_pool.d.ts.map +0 -1
  483. package/dest/worker/worker_pool.js +0 -51
  484. package/src/crypto/pedersen/pedersen.elliptic.ts +0 -584
  485. package/src/log/debug.ts +0 -104
  486. package/src/log/log_history.ts +0 -44
  487. package/src/transport/browser/index.ts +0 -4
  488. package/src/transport/browser/message_port_socket.ts +0 -48
  489. package/src/transport/browser/shared_worker_connector.ts +0 -21
  490. package/src/transport/browser/shared_worker_listener.ts +0 -53
  491. package/src/transport/browser/worker_connector.ts +0 -30
  492. package/src/transport/browser/worker_listener.ts +0 -54
  493. package/src/wasm/README.md +0 -6
  494. package/src/wasm/empty_wasi_sdk.ts +0 -166
  495. package/src/wasm/fixtures/gcd.wasm +0 -0
  496. package/src/wasm/fixtures/gcd.wat +0 -27
  497. package/src/wasm/index.ts +0 -1
  498. package/src/wasm/wasm_module.ts +0 -260
  499. package/src/worker/browser/index.ts +0 -2
  500. package/src/worker/browser/start_web_module.ts +0 -24
  501. package/src/worker/browser/web_data_store.ts +0 -38
  502. package/src/worker/browser/web_worker.ts +0 -25
  503. package/src/worker/data_store.ts +0 -19
  504. package/src/worker/index.ts +0 -2
  505. package/src/worker/node/index.ts +0 -2
  506. package/src/worker/node/node_data_store.ts +0 -27
  507. package/src/worker/node/node_worker.ts +0 -23
  508. package/src/worker/node/start_node_module.ts +0 -30
  509. package/src/worker/wasm_worker.ts +0 -7
  510. package/src/worker/worker_pool.ts +0 -73
@@ -1,6 +1,12 @@
1
+ import { Fq, Fr } from '../fields/fields.js';
1
2
  import type { EnvVar } from './env_var.js';
3
+ import { type NetworkNames, getActiveNetworkName } from './network_name.js';
4
+ import { SecretValue } from './secret_value.js';
2
5
 
3
- export { type EnvVar } from './env_var.js';
6
+ export { SecretValue, getActiveNetworkName };
7
+ export type { EnvVar, NetworkNames };
8
+ export type { NetworkConfig, NetworkConfigMap } from './network_config.js';
9
+ export { NetworkConfigMapSchema, NetworkConfigSchema } from './network_config.js';
4
10
 
5
11
  export interface ConfigMapping {
6
12
  env?: EnvVar;
@@ -10,6 +16,7 @@ export interface ConfigMapping {
10
16
  description: string;
11
17
  isBoolean?: boolean;
12
18
  nested?: Record<string, ConfigMapping>;
19
+ fallback?: EnvVar[];
13
20
  }
14
21
 
15
22
  export function isBooleanConfigValue<T>(obj: T, key: keyof T): boolean {
@@ -18,20 +25,59 @@ export function isBooleanConfigValue<T>(obj: T, key: keyof T): boolean {
18
25
 
19
26
  export type ConfigMappingsType<T> = Record<keyof T, ConfigMapping>;
20
27
 
28
+ /**
29
+ * Shared utility function to get a value from environment variables with fallback support.
30
+ * This can be used by both getConfigFromMappings and CLI utilities.
31
+ *
32
+ * @param env - The primary environment variable name
33
+ * @param fallback - Optional array of fallback environment variable names
34
+ * @param parseFunc - Optional function to parse the environment variable value
35
+ * @param defaultValue - Optional default value to use if no environment variable is set
36
+ * @returns The parsed value from environment variables or the default value
37
+ */
38
+ export function getValueFromEnvWithFallback<T>(
39
+ env: EnvVar | undefined,
40
+ parseFunc: ((val: string) => T) | undefined,
41
+ defaultValue: T | undefined,
42
+ fallback?: EnvVar[],
43
+ ): T | undefined {
44
+ let value: string | undefined;
45
+
46
+ // Try primary env var
47
+ if (env) {
48
+ value = process.env[env];
49
+ }
50
+
51
+ // If primary not found, try fallbacks
52
+ if (value === undefined && fallback && fallback.length > 0) {
53
+ for (const fallbackEnv of fallback) {
54
+ const fallbackVal = process.env[fallbackEnv];
55
+ if (fallbackVal !== undefined) {
56
+ value = fallbackVal;
57
+ break;
58
+ }
59
+ }
60
+ }
61
+
62
+ // Parse the value if needed
63
+ if (value !== undefined) {
64
+ return parseFunc ? parseFunc(value) : (value as unknown as T);
65
+ }
66
+
67
+ // Return default if no env var found
68
+ return defaultValue;
69
+ }
70
+
21
71
  export function getConfigFromMappings<T>(configMappings: ConfigMappingsType<T>): T {
22
72
  const config = {} as T;
23
73
 
24
74
  for (const key in configMappings) {
25
- const { env, parseEnv, defaultValue: def, nested } = configMappings[key];
75
+ const { env, parseEnv, defaultValue, nested, fallback } = configMappings[key];
26
76
  if (nested) {
27
77
  (config as any)[key] = getConfigFromMappings(nested);
28
78
  } else {
29
- const val = env ? process.env[env] : undefined;
30
- if (val !== undefined) {
31
- (config as any)[key] = parseEnv ? parseEnv(val) : val;
32
- } else if (def !== undefined) {
33
- (config as any)[key] = def;
34
- }
79
+ // Use the shared utility function
80
+ (config as any)[key] = getValueFromEnvWithFallback(env, parseEnv, defaultValue, fallback);
35
81
  }
36
82
  }
37
83
 
@@ -65,6 +111,25 @@ export function numberConfigHelper(defaultVal: number): Pick<ConfigMapping, 'par
65
111
  };
66
112
  }
67
113
 
114
+ /**
115
+ * Generates parseEnv and default values for a numerical config value.
116
+ * @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
117
+ * @returns Object with parseEnv and default values for a numerical config value
118
+ */
119
+ export function floatConfigHelper(
120
+ defaultVal: number,
121
+ validationFn?: (val: number) => void,
122
+ ): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
123
+ return {
124
+ parseEnv: (val: string): number => {
125
+ const parsed = safeParseFloat(val, defaultVal);
126
+ validationFn?.(parsed);
127
+ return parsed;
128
+ },
129
+ defaultValue: defaultVal,
130
+ };
131
+ }
132
+
68
133
  /**
69
134
  * Generates parseEnv and default values for a numerical config value.
70
135
  * @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
@@ -97,6 +162,26 @@ export function optionalNumberConfigHelper(): Pick<ConfigMapping, 'parseEnv'> {
97
162
  };
98
163
  }
99
164
 
165
+ /** Generates parseEnv for an enum-like config value. */
166
+ export function enumConfigHelper<T extends string>(
167
+ values: T[],
168
+ defaultValue?: NoInfer<T>,
169
+ ): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
170
+ return {
171
+ parseEnv: (val: string) => {
172
+ const sanitizedVal = (val ?? '').trim().toLowerCase();
173
+ if (values.includes(sanitizedVal as T)) {
174
+ return sanitizedVal as T;
175
+ }
176
+ if (!val && defaultValue) {
177
+ return defaultValue;
178
+ }
179
+ throw new Error(`Invalid config value '${val}' (must be one of ${values.join(', ')})`);
180
+ },
181
+ defaultValue,
182
+ };
183
+ }
184
+
100
185
  /**
101
186
  * Generates parseEnv and default values for a boolean config value.
102
187
  * @param defaultVal - The default value to use if the environment variable is not set or is invalid
@@ -114,11 +199,97 @@ export function booleanConfigHelper(
114
199
  };
115
200
  }
116
201
 
202
+ export function secretValueConfigHelper<T>(parse: (val: string | undefined) => T): Required<
203
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
204
+ parseVal: (val: string) => SecretValue<T>;
205
+ }
206
+ > {
207
+ const wrap = (val: string) => new SecretValue(parse(val));
208
+ return {
209
+ parseEnv: wrap,
210
+ parseVal: wrap,
211
+ defaultValue: new SecretValue(parse(undefined)),
212
+ isBoolean: true,
213
+ };
214
+ }
215
+
117
216
  /** Parses an env var as boolean. Returns true only if value is 1, true, or TRUE. */
118
217
  export function parseBooleanEnv(val: string | undefined): boolean {
119
218
  return val !== undefined && ['1', 'true', 'TRUE'].includes(val);
120
219
  }
121
220
 
221
+ export function secretStringConfigHelper(): Required<
222
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
223
+ parseVal: (val: string) => SecretValue<string | undefined>;
224
+ }
225
+ >;
226
+ export function secretStringConfigHelper(defaultValue: string): Required<
227
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
228
+ parseVal: (val: string) => SecretValue<string>;
229
+ }
230
+ >;
231
+ export function secretStringConfigHelper(defaultValue?: string): Required<
232
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
233
+ parseVal: (val: string) => SecretValue<string | typeof defaultValue>;
234
+ }
235
+ > {
236
+ const parse = (val: string) => new SecretValue(val);
237
+ return {
238
+ parseEnv: parse,
239
+ parseVal: parse,
240
+ defaultValue: defaultValue !== undefined ? new SecretValue(defaultValue) : undefined,
241
+ isBoolean: true,
242
+ };
243
+ }
244
+
245
+ export function secretFrConfigHelper(): Required<
246
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
247
+ parseVal: (val: string) => SecretValue<Fr | undefined>;
248
+ }
249
+ >;
250
+ export function secretFrConfigHelper(defaultValue: Fr): Required<
251
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
252
+ parseVal: (val: string) => SecretValue<Fr>;
253
+ }
254
+ >;
255
+ export function secretFrConfigHelper(defaultValue?: Fr): Required<
256
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
257
+ parseVal: (val: string) => SecretValue<Fr | typeof defaultValue>;
258
+ }
259
+ > {
260
+ const parse = (val: string) => new SecretValue(Fr.fromHexString(val));
261
+ return {
262
+ parseEnv: parse,
263
+ parseVal: parse,
264
+ defaultValue: defaultValue !== undefined ? new SecretValue(defaultValue) : undefined,
265
+ isBoolean: true,
266
+ };
267
+ }
268
+
269
+ export function secretFqConfigHelper(defaultValue: Fq): Required<
270
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
271
+ parseVal: (val: string) => SecretValue<Fq>;
272
+ }
273
+ >;
274
+ export function secretFqConfigHelper(): Required<
275
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
276
+ parseVal: (val: string) => SecretValue<Fq | undefined>;
277
+ }
278
+ >;
279
+ export function secretFqConfigHelper(defaultValue?: Fq): Required<
280
+ Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
281
+ parseVal: (val: string) => SecretValue<Fq | typeof defaultValue>;
282
+ }
283
+ > {
284
+ const parse = (val: string) => new SecretValue(Fq.fromHexString(val));
285
+ return {
286
+ parseEnv: parse,
287
+ parseVal: parse,
288
+ defaultValue: typeof defaultValue !== 'undefined' ? new SecretValue(defaultValue) : undefined,
289
+ isBoolean: true,
290
+ };
291
+ }
292
+
122
293
  /**
123
294
  * Safely parses a number from a string.
124
295
  * If the value is not a number or is not a safe integer, the default value is returned.
@@ -131,6 +302,18 @@ function safeParseNumber(value: string, defaultValue: number): number {
131
302
  return Number.isSafeInteger(parsedValue) ? parsedValue : defaultValue;
132
303
  }
133
304
 
305
+ /**
306
+ * Safely parses a floating point number from a string.
307
+ * If the value is not a number, the default value is returned.
308
+ * @param value - The string value to parse
309
+ * @param defaultValue - The default value to return
310
+ * @returns Either parsed value or default value
311
+ */
312
+ function safeParseFloat(value: string, defaultValue: number): number {
313
+ const parsedValue = parseFloat(value);
314
+ return Number.isNaN(parsedValue) ? defaultValue : parsedValue;
315
+ }
316
+
134
317
  /**
135
318
  * Picks specific keys from the given configuration mappings.
136
319
  *
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod';
2
+
3
+ export const NetworkConfigSchema = z
4
+ .object({
5
+ bootnodes: z.array(z.string()),
6
+ snapshots: z.array(z.string()),
7
+ registryAddress: z.string(),
8
+ feeAssetHandlerAddress: z.string().optional(),
9
+ l1ChainId: z.number(),
10
+ })
11
+ .passthrough(); // Allow additional unknown fields to pass through
12
+
13
+ export const NetworkConfigMapSchema = z.record(z.string(), NetworkConfigSchema);
14
+
15
+ export type NetworkConfig = z.infer<typeof NetworkConfigSchema>;
16
+ export type NetworkConfigMap = z.infer<typeof NetworkConfigMapSchema>;
@@ -0,0 +1,28 @@
1
+ export type NetworkNames =
2
+ | 'local'
3
+ | 'staging-ignition'
4
+ | 'staging-public'
5
+ | 'testnet'
6
+ | 'mainnet'
7
+ | 'next-net'
8
+ | 'devnet';
9
+
10
+ export function getActiveNetworkName(name?: string): NetworkNames {
11
+ const network = name || process.env.NETWORK;
12
+ if (!network || network === '' || network === 'local') {
13
+ return 'local';
14
+ } else if (network === 'staging-ignition') {
15
+ return network;
16
+ } else if (network === 'staging-public') {
17
+ return network;
18
+ } else if (network === 'testnet' || network === 'alpha-testnet') {
19
+ return 'testnet';
20
+ } else if (network === 'mainnet') {
21
+ return 'mainnet';
22
+ } else if (network === 'next-net') {
23
+ return 'next-net';
24
+ } else if (network === 'devnet') {
25
+ return 'devnet';
26
+ }
27
+ throw new Error(`Unknown network: ${network}`);
28
+ }
@@ -0,0 +1,49 @@
1
+ import { inspect } from 'util';
2
+ import type { ZodType } from 'zod';
3
+
4
+ /**
5
+ * A class wrapping a secret value to protect it from accidently being leaked in logs
6
+ */
7
+ export class SecretValue<T> {
8
+ /** The secret value. Use a private member field so that it's not visible to the outside */
9
+ #value: T;
10
+
11
+ constructor(
12
+ value: T,
13
+ private readonly redactedValue = '[Redacted]',
14
+ ) {
15
+ this.#value = value;
16
+ }
17
+
18
+ /**
19
+ * Returns the wrapped value
20
+ */
21
+ public getValue(): T {
22
+ return this.#value;
23
+ }
24
+
25
+ /**
26
+ * Returns a redacted string representation of the value
27
+ */
28
+ public toString(): string {
29
+ return this.redactedValue;
30
+ }
31
+
32
+ /**
33
+ * Returns a redacted string representation of the value
34
+ */
35
+ public toJSON(): string {
36
+ return this.redactedValue;
37
+ }
38
+
39
+ public [inspect.custom]() {
40
+ return this.toString();
41
+ }
42
+
43
+ /**
44
+ * Returns a Zod schema
45
+ */
46
+ static schema<O>(valueSchema: ZodType<O, any, any>): ZodType<SecretValue<O>, any, any> {
47
+ return valueSchema.transform(value => new SecretValue<O>(value));
48
+ }
49
+ }
@@ -1,4 +1,4 @@
1
- import { BarretenbergSync, RawBuffer } from '@aztec/bb.js';
1
+ import { BarretenbergSync } from '@aztec/bb.js';
2
2
 
3
3
  import { Buffer } from 'buffer';
4
4
 
@@ -22,10 +22,15 @@ export class Aes128 {
22
22
  paddingBuffer.fill(numPaddingBytes);
23
23
  const input = Buffer.concat([data, paddingBuffer]);
24
24
 
25
- const api = await BarretenbergSync.initSingleton(process.env.BB_WASM_PATH);
26
- return Buffer.from(
27
- api.aesEncryptBufferCbc(new RawBuffer(input), new RawBuffer(iv), new RawBuffer(key), input.length),
28
- );
25
+ await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
26
+ const api = BarretenbergSync.getSingleton();
27
+ const response = api.aesEncrypt({
28
+ plaintext: input,
29
+ iv,
30
+ key,
31
+ length: input.length,
32
+ });
33
+ return Buffer.from(response.ciphertext);
29
34
  }
30
35
 
31
36
  /**
@@ -37,11 +42,15 @@ export class Aes128 {
37
42
  * @returns Decrypted data.
38
43
  */
39
44
  public async decryptBufferCBCKeepPadding(data: Uint8Array, iv: Uint8Array, key: Uint8Array): Promise<Buffer> {
40
- const api = await BarretenbergSync.initSingleton(process.env.BB_WASM_PATH);
41
- const paddedBuffer = Buffer.from(
42
- api.aesDecryptBufferCbc(new RawBuffer(data), new RawBuffer(iv), new RawBuffer(key), data.length),
43
- );
44
- return paddedBuffer;
45
+ await BarretenbergSync.initSingleton({ wasmPath: process.env.BB_WASM_PATH });
46
+ const api = BarretenbergSync.getSingleton();
47
+ const response = api.aesDecrypt({
48
+ ciphertext: data,
49
+ iv,
50
+ key,
51
+ length: data.length,
52
+ });
53
+ return Buffer.from(response.plaintext);
45
54
  }
46
55
 
47
56
  /**
@@ -0,0 +1,287 @@
1
+ import { randomBytes } from '@aztec/foundation/crypto';
2
+
3
+ import { createCipheriv, createDecipheriv, createHash, pbkdf2Sync, randomUUID } from 'crypto';
4
+ import { readFileSync } from 'fs';
5
+ import { z } from 'zod';
6
+
7
+ /**
8
+ * BN254 Keystore Format
9
+ *
10
+ * Implements encryption and decryption of keystores for BN254 BLS private keys
11
+ * using PBKDF2 and AES-128-CTR. This format is inspired by EIP-2335 but adapted
12
+ * for BN254 keys rather than BLS12-381.
13
+ *
14
+ * @see https://eips.ethereum.org/EIPS/eip-2335
15
+ */
16
+
17
+ /**
18
+ * Zod schema for validating BN254 keystore structure
19
+ */
20
+ const bn254KeystoreSchema = z.object({
21
+ crypto: z.object({
22
+ kdf: z.object({
23
+ function: z.literal('pbkdf2'),
24
+ params: z.object({
25
+ dklen: z.number(),
26
+ c: z.number(),
27
+ prf: z.string(),
28
+ salt: z.string(),
29
+ }),
30
+ message: z.string(),
31
+ }),
32
+ checksum: z.object({
33
+ function: z.literal('sha256'),
34
+ params: z.object({}),
35
+ message: z.string(),
36
+ }),
37
+ cipher: z.object({
38
+ function: z.literal('aes-128-ctr'),
39
+ params: z.object({
40
+ iv: z.string(),
41
+ }),
42
+ message: z.string(),
43
+ }),
44
+ }),
45
+ description: z.string().optional(),
46
+ pubkey: z.string(),
47
+ path: z.string(),
48
+ uuid: z.string(),
49
+ version: z.number(),
50
+ });
51
+
52
+ /**
53
+ * Error thrown when BN254 keystore operations fail
54
+ */
55
+ export class Bn254KeystoreError extends Error {
56
+ constructor(
57
+ message: string,
58
+ public override cause?: Error,
59
+ ) {
60
+ super(message);
61
+ this.name = 'Bn254KeystoreError';
62
+ }
63
+ }
64
+
65
+ export type Bn254Keystore = z.infer<typeof bn254KeystoreSchema>;
66
+
67
+ /**
68
+ * The JSON structure of a BN254 keystore file.
69
+ * @deprecated Use the inferred type from bn254KeystoreSchema instead
70
+ */
71
+ export interface Bn254KeystoreInterface {
72
+ crypto: {
73
+ kdf: {
74
+ function: 'pbkdf2';
75
+ params: {
76
+ dklen: number;
77
+ c: number;
78
+ prf: string;
79
+ salt: string;
80
+ };
81
+ message: string;
82
+ };
83
+ checksum: {
84
+ function: 'sha256';
85
+ params: Record<string, never>;
86
+ message: string;
87
+ };
88
+ cipher: {
89
+ function: 'aes-128-ctr';
90
+ params: {
91
+ iv: string;
92
+ };
93
+ message: string;
94
+ };
95
+ };
96
+ description: string;
97
+ pubkey: string;
98
+ path: string;
99
+ uuid: string;
100
+ version: number;
101
+ }
102
+
103
+ /**
104
+ * Creates a BN254 keystore object for a BN254 BLS private key.
105
+ *
106
+ * Uses PBKDF2 with SHA-256 for key derivation and AES-128-CTR for encryption,
107
+ * following the EIP-2335 specification format.
108
+ *
109
+ * @param password - Password for encrypting the private key
110
+ * @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
111
+ * @param pubkeyHex - Public key as hex string (compressed or uncompressed)
112
+ * @param derivationPath - BIP-44 style derivation path (e.g., "m/12381/3600/0/0/0")
113
+ * @returns BN254 keystore object ready to be serialized to JSON
114
+ * @throws Error if private key is not 32-byte hex
115
+ */
116
+ export function createBn254Keystore(
117
+ password: string,
118
+ privateKeyHex: string,
119
+ pubkeyHex: string,
120
+ derivationPath: string,
121
+ ): Bn254Keystore {
122
+ const ensureHex = (hex: string) => hex.replace(/^0x/i, '');
123
+ const privHex = ensureHex(privateKeyHex);
124
+ if (!/^[0-9a-fA-F]{64}$/.test(privHex)) {
125
+ throw new Error('BLS private key must be 32-byte hex');
126
+ }
127
+
128
+ const salt = randomBytes(32);
129
+ const iv = randomBytes(16);
130
+ const dk = pbkdf2Sync(Buffer.from(password.normalize('NFKD'), 'utf8'), salt, 262144, 32, 'sha256');
131
+ const cipherKey = dk.subarray(0, 16);
132
+
133
+ const cipher = createCipheriv('aes-128-ctr', cipherKey, iv);
134
+ const plaintext = Buffer.from(privHex, 'hex');
135
+ const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
136
+
137
+ const checksum = createHash('sha256')
138
+ .update(Buffer.concat([dk.subarray(16, 32), ciphertext]))
139
+ .digest();
140
+
141
+ const uuid = randomUUID();
142
+
143
+ return {
144
+ crypto: {
145
+ kdf: {
146
+ function: 'pbkdf2',
147
+ params: { dklen: 32, c: 262144, prf: 'hmac-sha256', salt: salt.toString('hex') },
148
+ message: '',
149
+ },
150
+ checksum: {
151
+ function: 'sha256',
152
+ params: {},
153
+ message: checksum.toString('hex'),
154
+ },
155
+ cipher: {
156
+ function: 'aes-128-ctr',
157
+ params: { iv: iv.toString('hex') },
158
+ message: ciphertext.toString('hex'),
159
+ },
160
+ },
161
+ description: ensureHex(pubkeyHex),
162
+ pubkey: pubkeyHex,
163
+ path: derivationPath ?? '',
164
+ uuid,
165
+ version: 4,
166
+ };
167
+ }
168
+
169
+ /**
170
+ * Loads and validates a BN254 keystore file.
171
+ *
172
+ * @param filePath - Path to the BN254 keystore JSON file
173
+ * @returns Validated keystore object
174
+ * @throws Bn254KeystoreError if file cannot be read or validated
175
+ */
176
+ export function loadBn254Keystore(filePath: string): Bn254Keystore {
177
+ try {
178
+ const content = readFileSync(filePath, 'utf-8');
179
+ const json = JSON.parse(content);
180
+ return bn254KeystoreSchema.parse(json);
181
+ } catch (error) {
182
+ if (error instanceof SyntaxError) {
183
+ throw new Bn254KeystoreError(`Invalid JSON in keystore file: ${filePath}`, error);
184
+ }
185
+ if (error && typeof error === 'object' && 'issues' in error) {
186
+ const issues = (error as any).issues ?? [];
187
+ const message = issues.map((e: any) => `${e.message} at ${e.path?.join('.') ?? 'root'}`).join('; ');
188
+ throw new Bn254KeystoreError(`Invalid BN254 keystore format: ${message}`);
189
+ }
190
+ throw new Bn254KeystoreError(`Failed to load keystore from ${filePath}: ${String(error)}`, error as Error);
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Decrypts a BN254 BLS private key from a keystore file.
196
+ *
197
+ * @param filePath - Path to the BN254 keystore JSON file
198
+ * @param password - Password to decrypt the keystore
199
+ * @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
200
+ * @throws Bn254KeystoreError if decryption fails or checksum is invalid
201
+ */
202
+ export function decryptBn254Keystore(filePath: string, password: string): string {
203
+ const keystore = loadBn254Keystore(filePath);
204
+ return decryptBn254KeystoreFromObject(keystore, password);
205
+ }
206
+
207
+ /**
208
+ * Decrypts a BN254 BLS private key from a keystore object.
209
+ *
210
+ * @param keystore - BN254 keystore object
211
+ * @param password - Password to decrypt the keystore
212
+ * @returns Decrypted private key as 0x-prefixed hex string (32 bytes)
213
+ * @throws Bn254KeystoreError if decryption fails or checksum is invalid
214
+ */
215
+ export function decryptBn254KeystoreFromObject(keystore: Bn254Keystore, password: string): string {
216
+ try {
217
+ const { crypto } = keystore;
218
+
219
+ // Only support PBKDF2 + AES-128-CTR (as per our implementation)
220
+ if (crypto.kdf.function !== 'pbkdf2') {
221
+ throw new Bn254KeystoreError(`Unsupported KDF function: ${crypto.kdf.function}`);
222
+ }
223
+ if (crypto.cipher.function !== 'aes-128-ctr') {
224
+ throw new Bn254KeystoreError(`Unsupported cipher function: ${crypto.cipher.function}`);
225
+ }
226
+
227
+ // Derive decryption key using PBKDF2
228
+ const salt = Buffer.from(crypto.kdf.params.salt, 'hex');
229
+ const dk = pbkdf2Sync(
230
+ Buffer.from(password.normalize('NFKD'), 'utf8'),
231
+ salt,
232
+ crypto.kdf.params.c,
233
+ crypto.kdf.params.dklen,
234
+ 'sha256',
235
+ );
236
+
237
+ const cipherKey = dk.subarray(0, 16);
238
+ const checksumKey = dk.subarray(16, 32);
239
+
240
+ // Decrypt the ciphertext
241
+ const iv = Buffer.from(crypto.cipher.params.iv, 'hex');
242
+ const ciphertext = Buffer.from(crypto.cipher.message, 'hex');
243
+ const decipher = createDecipheriv('aes-128-ctr', cipherKey, iv);
244
+ const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
245
+
246
+ // Verify checksum
247
+ const computedChecksum = createHash('sha256')
248
+ .update(Buffer.concat([checksumKey, ciphertext]))
249
+ .digest();
250
+ const expectedChecksum = Buffer.from(crypto.checksum.message, 'hex');
251
+
252
+ if (!computedChecksum.equals(expectedChecksum)) {
253
+ throw new Bn254KeystoreError('Checksum verification failed - incorrect password or corrupted keystore');
254
+ }
255
+
256
+ // Return as 0x-prefixed hex
257
+ return '0x' + decrypted.toString('hex');
258
+ } catch (error) {
259
+ if (error instanceof Bn254KeystoreError) {
260
+ throw error;
261
+ }
262
+ throw new Bn254KeystoreError(`Failed to decrypt keystore: ${String(error)}`, error as Error);
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Validates that a decrypted private key matches the public key in the keystore.
268
+ *
269
+ * @param privateKeyHex - Decrypted private key (0x-prefixed)
270
+ * @param expectedPubkey - Expected public key from keystore
271
+ * @param computePublicKey - Function to compute public key from private key
272
+ * @returns true if keys match, false otherwise
273
+ */
274
+ export function verifyBn254Keypair(
275
+ privateKeyHex: string,
276
+ expectedPubkey: string,
277
+ computePublicKey: (privateKey: string) => string,
278
+ ): boolean {
279
+ try {
280
+ const computedPubkey = computePublicKey(privateKeyHex);
281
+ const normalizedExpected = expectedPubkey.toLowerCase().replace(/^0x/i, '');
282
+ const normalizedComputed = computedPubkey.toLowerCase().replace(/^0x/i, '');
283
+ return normalizedExpected === normalizedComputed;
284
+ } catch {
285
+ return false;
286
+ }
287
+ }