@aztec/foundation 0.0.0-test.0

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 (736) hide show
  1. package/README.md +1 -0
  2. package/dest/array/array.d.ts +71 -0
  3. package/dest/array/array.d.ts.map +1 -0
  4. package/dest/array/array.js +100 -0
  5. package/dest/array/index.d.ts +2 -0
  6. package/dest/array/index.d.ts.map +1 -0
  7. package/dest/array/index.js +1 -0
  8. package/dest/async-map/index.d.ts +13 -0
  9. package/dest/async-map/index.d.ts.map +1 -0
  10. package/dest/async-map/index.js +17 -0
  11. package/dest/async-pool/index.d.ts +3 -0
  12. package/dest/async-pool/index.d.ts.map +1 -0
  13. package/dest/async-pool/index.js +47 -0
  14. package/dest/bigint-buffer/index.d.ts +42 -0
  15. package/dest/bigint-buffer/index.d.ts.map +1 -0
  16. package/dest/bigint-buffer/index.js +76 -0
  17. package/dest/buffer/buffer32.d.ts +91 -0
  18. package/dest/buffer/buffer32.d.ts.map +1 -0
  19. package/dest/buffer/buffer32.js +115 -0
  20. package/dest/buffer/index.d.ts +2 -0
  21. package/dest/buffer/index.d.ts.map +1 -0
  22. package/dest/buffer/index.js +1 -0
  23. package/dest/collection/array.d.ts +101 -0
  24. package/dest/collection/array.d.ts.map +1 -0
  25. package/dest/collection/array.js +164 -0
  26. package/dest/collection/index.d.ts +3 -0
  27. package/dest/collection/index.d.ts.map +1 -0
  28. package/dest/collection/index.js +2 -0
  29. package/dest/collection/object.d.ts +14 -0
  30. package/dest/collection/object.d.ts.map +1 -0
  31. package/dest/collection/object.js +32 -0
  32. package/dest/committable/committable.d.ts +28 -0
  33. package/dest/committable/committable.d.ts.map +1 -0
  34. package/dest/committable/committable.js +36 -0
  35. package/dest/committable/index.d.ts +2 -0
  36. package/dest/committable/index.d.ts.map +1 -0
  37. package/dest/committable/index.js +1 -0
  38. package/dest/config/env_var.d.ts +2 -0
  39. package/dest/config/env_var.d.ts.map +1 -0
  40. package/dest/config/env_var.js +1 -0
  41. package/dest/config/index.d.ts +66 -0
  42. package/dest/config/index.d.ts.map +1 -0
  43. package/dest/config/index.js +125 -0
  44. package/dest/crypto/aes128/index.d.ts +34 -0
  45. package/dest/crypto/aes128/index.d.ts.map +1 -0
  46. package/dest/crypto/aes128/index.js +49 -0
  47. package/dest/crypto/ecdsa/index.d.ts +39 -0
  48. package/dest/crypto/ecdsa/index.d.ts.map +1 -0
  49. package/dest/crypto/ecdsa/index.js +88 -0
  50. package/dest/crypto/ecdsa/signature.d.ts +71 -0
  51. package/dest/crypto/ecdsa/signature.d.ts.map +1 -0
  52. package/dest/crypto/ecdsa/signature.js +92 -0
  53. package/dest/crypto/grumpkin/index.d.ts +47 -0
  54. package/dest/crypto/grumpkin/index.d.ts.map +1 -0
  55. package/dest/crypto/grumpkin/index.js +154 -0
  56. package/dest/crypto/index.d.ts +15 -0
  57. package/dest/crypto/index.d.ts.map +1 -0
  58. package/dest/crypto/index.js +14 -0
  59. package/dest/crypto/keccak/index.d.ts +28 -0
  60. package/dest/crypto/keccak/index.d.ts.map +1 -0
  61. package/dest/crypto/keccak/index.js +248 -0
  62. package/dest/crypto/keys/index.d.ts +5 -0
  63. package/dest/crypto/keys/index.d.ts.map +1 -0
  64. package/dest/crypto/keys/index.js +7 -0
  65. package/dest/crypto/pedersen/index.d.ts +2 -0
  66. package/dest/crypto/pedersen/index.d.ts.map +1 -0
  67. package/dest/crypto/pedersen/index.js +1 -0
  68. package/dest/crypto/pedersen/pedersen.elliptic.d.ts +13 -0
  69. package/dest/crypto/pedersen/pedersen.elliptic.d.ts.map +1 -0
  70. package/dest/crypto/pedersen/pedersen.elliptic.js +582 -0
  71. package/dest/crypto/pedersen/pedersen.noble.d.ts +11 -0
  72. package/dest/crypto/pedersen/pedersen.noble.d.ts.map +1 -0
  73. package/dest/crypto/pedersen/pedersen.noble.js +558 -0
  74. package/dest/crypto/pedersen/pedersen.wasm.d.ts +21 -0
  75. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -0
  76. package/dest/crypto/pedersen/pedersen.wasm.js +41 -0
  77. package/dest/crypto/poseidon/index.d.ts +26 -0
  78. package/dest/crypto/poseidon/index.d.ts.map +1 -0
  79. package/dest/crypto/poseidon/index.js +58 -0
  80. package/dest/crypto/random/index.d.ts +25 -0
  81. package/dest/crypto/random/index.d.ts.map +1 -0
  82. package/dest/crypto/random/index.js +70 -0
  83. package/dest/crypto/random/randomness_singleton.d.ts +25 -0
  84. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -0
  85. package/dest/crypto/random/randomness_singleton.js +55 -0
  86. package/dest/crypto/schnorr/index.d.ts +30 -0
  87. package/dest/crypto/schnorr/index.d.ts.map +1 -0
  88. package/dest/crypto/schnorr/index.js +68 -0
  89. package/dest/crypto/schnorr/signature.d.ts +70 -0
  90. package/dest/crypto/schnorr/signature.d.ts.map +1 -0
  91. package/dest/crypto/schnorr/signature.js +93 -0
  92. package/dest/crypto/secp256k1/index.d.ts +32 -0
  93. package/dest/crypto/secp256k1/index.d.ts.map +1 -0
  94. package/dest/crypto/secp256k1/index.js +116 -0
  95. package/dest/crypto/secp256k1-signer/index.d.ts +3 -0
  96. package/dest/crypto/secp256k1-signer/index.d.ts.map +1 -0
  97. package/dest/crypto/secp256k1-signer/index.js +2 -0
  98. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +24 -0
  99. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -0
  100. package/dest/crypto/secp256k1-signer/secp256k1_signer.js +30 -0
  101. package/dest/crypto/secp256k1-signer/utils.d.ts +40 -0
  102. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -0
  103. package/dest/crypto/secp256k1-signer/utils.js +84 -0
  104. package/dest/crypto/serialize.d.ts +53 -0
  105. package/dest/crypto/serialize.d.ts.map +1 -0
  106. package/dest/crypto/serialize.js +68 -0
  107. package/dest/crypto/sha256/index.d.ts +20 -0
  108. package/dest/crypto/sha256/index.d.ts.map +1 -0
  109. package/dest/crypto/sha256/index.js +166 -0
  110. package/dest/crypto/sha512/index.d.ts +11 -0
  111. package/dest/crypto/sha512/index.d.ts.map +1 -0
  112. package/dest/crypto/sha512/index.js +12 -0
  113. package/dest/crypto/signature/index.d.ts +19 -0
  114. package/dest/crypto/signature/index.d.ts.map +1 -0
  115. package/dest/crypto/signature/index.js +3 -0
  116. package/dest/crypto/sync/index.d.ts +3 -0
  117. package/dest/crypto/sync/index.d.ts.map +1 -0
  118. package/dest/crypto/sync/index.js +4 -0
  119. package/dest/crypto/sync/pedersen/index.d.ts +21 -0
  120. package/dest/crypto/sync/pedersen/index.d.ts.map +1 -0
  121. package/dest/crypto/sync/pedersen/index.js +38 -0
  122. package/dest/crypto/sync/poseidon/index.d.ts +26 -0
  123. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -0
  124. package/dest/crypto/sync/poseidon/index.js +53 -0
  125. package/dest/decorators/index.d.ts +2 -0
  126. package/dest/decorators/index.d.ts.map +1 -0
  127. package/dest/decorators/index.js +1 -0
  128. package/dest/decorators/memoize.d.ts +2 -0
  129. package/dest/decorators/memoize.d.ts.map +1 -0
  130. package/dest/decorators/memoize.js +11 -0
  131. package/dest/error/index.d.ts +21 -0
  132. package/dest/error/index.d.ts.map +1 -0
  133. package/dest/error/index.js +17 -0
  134. package/dest/eth-address/index.d.ts +134 -0
  135. package/dest/eth-address/index.d.ts.map +1 -0
  136. package/dest/eth-address/index.js +198 -0
  137. package/dest/eth-signature/eth_signature.d.ts +62 -0
  138. package/dest/eth-signature/eth_signature.d.ts.map +1 -0
  139. package/dest/eth-signature/eth_signature.js +91 -0
  140. package/dest/eth-signature/index.d.ts +2 -0
  141. package/dest/eth-signature/index.d.ts.map +1 -0
  142. package/dest/eth-signature/index.js +1 -0
  143. package/dest/fields/coordinate.d.ts +68 -0
  144. package/dest/fields/coordinate.d.ts.map +1 -0
  145. package/dest/fields/coordinate.js +96 -0
  146. package/dest/fields/fields.d.ts +176 -0
  147. package/dest/fields/fields.d.ts.map +1 -0
  148. package/dest/fields/fields.js +383 -0
  149. package/dest/fields/index.d.ts +4 -0
  150. package/dest/fields/index.d.ts.map +1 -0
  151. package/dest/fields/index.js +3 -0
  152. package/dest/fields/point.d.ts +175 -0
  153. package/dest/fields/point.d.ts.map +1 -0
  154. package/dest/fields/point.js +260 -0
  155. package/dest/fs/index.d.ts +2 -0
  156. package/dest/fs/index.d.ts.map +1 -0
  157. package/dest/fs/index.js +1 -0
  158. package/dest/fs/run_in_dir.d.ts +2 -0
  159. package/dest/fs/run_in_dir.d.ts.map +1 -0
  160. package/dest/fs/run_in_dir.js +31 -0
  161. package/dest/index.d.ts +31 -0
  162. package/dest/index.d.ts.map +1 -0
  163. package/dest/index.js +31 -0
  164. package/dest/iterable/all.d.ts +9 -0
  165. package/dest/iterable/all.d.ts.map +1 -0
  166. package/dest/iterable/all.js +18 -0
  167. package/dest/iterable/filter.d.ts +10 -0
  168. package/dest/iterable/filter.d.ts.map +1 -0
  169. package/dest/iterable/filter.js +48 -0
  170. package/dest/iterable/index.d.ts +8 -0
  171. package/dest/iterable/index.d.ts.map +1 -0
  172. package/dest/iterable/index.js +7 -0
  173. package/dest/iterable/isAsyncIt.d.ts +7 -0
  174. package/dest/iterable/isAsyncIt.d.ts.map +1 -0
  175. package/dest/iterable/isAsyncIt.js +7 -0
  176. package/dest/iterable/map.d.ts +12 -0
  177. package/dest/iterable/map.d.ts.map +1 -0
  178. package/dest/iterable/map.js +36 -0
  179. package/dest/iterable/peek.d.ts +19 -0
  180. package/dest/iterable/peek.d.ts.map +1 -0
  181. package/dest/iterable/peek.js +33 -0
  182. package/dest/iterable/sort.d.ts +14 -0
  183. package/dest/iterable/sort.d.ts.map +1 -0
  184. package/dest/iterable/sort.js +15 -0
  185. package/dest/iterable/take.d.ts +10 -0
  186. package/dest/iterable/take.d.ts.map +1 -0
  187. package/dest/iterable/take.js +32 -0
  188. package/dest/iterable/toArray.d.ts +2 -0
  189. package/dest/iterable/toArray.d.ts.map +1 -0
  190. package/dest/iterable/toArray.js +7 -0
  191. package/dest/jest/setup.js +7 -0
  192. package/dest/json-rpc/client/fetch.d.ts +32 -0
  193. package/dest/json-rpc/client/fetch.d.ts.map +1 -0
  194. package/dest/json-rpc/client/fetch.js +77 -0
  195. package/dest/json-rpc/client/index.d.ts +3 -0
  196. package/dest/json-rpc/client/index.d.ts.map +1 -0
  197. package/dest/json-rpc/client/index.js +2 -0
  198. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +26 -0
  199. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -0
  200. package/dest/json-rpc/client/safe_json_rpc_client.js +57 -0
  201. package/dest/json-rpc/client/undici.d.ts +5 -0
  202. package/dest/json-rpc/client/undici.d.ts.map +1 -0
  203. package/dest/json-rpc/client/undici.js +63 -0
  204. package/dest/json-rpc/convert.d.ts +27 -0
  205. package/dest/json-rpc/convert.d.ts.map +1 -0
  206. package/dest/json-rpc/convert.js +48 -0
  207. package/dest/json-rpc/fixtures/class_a.d.ts +11 -0
  208. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -0
  209. package/dest/json-rpc/fixtures/class_a.js +20 -0
  210. package/dest/json-rpc/fixtures/class_b.d.ts +11 -0
  211. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -0
  212. package/dest/json-rpc/fixtures/class_b.js +20 -0
  213. package/dest/json-rpc/fixtures/test_state.d.ts +89 -0
  214. package/dest/json-rpc/fixtures/test_state.d.ts.map +1 -0
  215. package/dest/json-rpc/fixtures/test_state.js +131 -0
  216. package/dest/json-rpc/index.d.ts +2 -0
  217. package/dest/json-rpc/index.d.ts.map +1 -0
  218. package/dest/json-rpc/index.js +1 -0
  219. package/dest/json-rpc/js_utils.d.ts +13 -0
  220. package/dest/json-rpc/js_utils.d.ts.map +1 -0
  221. package/dest/json-rpc/js_utils.js +16 -0
  222. package/dest/json-rpc/server/index.d.ts +2 -0
  223. package/dest/json-rpc/server/index.d.ts.map +1 -0
  224. package/dest/json-rpc/server/index.js +1 -0
  225. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +140 -0
  226. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -0
  227. package/dest/json-rpc/server/safe_json_rpc_server.js +346 -0
  228. package/dest/json-rpc/server/telemetry.d.ts +2 -0
  229. package/dest/json-rpc/server/telemetry.d.ts.map +1 -0
  230. package/dest/json-rpc/server/telemetry.js +0 -0
  231. package/dest/json-rpc/test/index.d.ts +2 -0
  232. package/dest/json-rpc/test/index.d.ts.map +1 -0
  233. package/dest/json-rpc/test/index.js +1 -0
  234. package/dest/json-rpc/test/integration.d.ts +15 -0
  235. package/dest/json-rpc/test/integration.d.ts.map +1 -0
  236. package/dest/json-rpc/test/integration.js +21 -0
  237. package/dest/log/console.d.ts +11 -0
  238. package/dest/log/console.d.ts.map +1 -0
  239. package/dest/log/console.js +36 -0
  240. package/dest/log/debug.d.ts +56 -0
  241. package/dest/log/debug.d.ts.map +1 -0
  242. package/dest/log/debug.js +75 -0
  243. package/dest/log/gcloud-logger-config.d.ts +14 -0
  244. package/dest/log/gcloud-logger-config.d.ts.map +1 -0
  245. package/dest/log/gcloud-logger-config.js +66 -0
  246. package/dest/log/index.d.ts +7 -0
  247. package/dest/log/index.d.ts.map +1 -0
  248. package/dest/log/index.js +6 -0
  249. package/dest/log/libp2p_logger.d.ts +7 -0
  250. package/dest/log/libp2p_logger.d.ts.map +1 -0
  251. package/dest/log/libp2p_logger.js +55 -0
  252. package/dest/log/log-filters.d.ts +7 -0
  253. package/dest/log/log-filters.d.ts.map +1 -0
  254. package/dest/log/log-filters.js +59 -0
  255. package/dest/log/log-levels.d.ts +3 -0
  256. package/dest/log/log-levels.d.ts.map +1 -0
  257. package/dest/log/log-levels.js +10 -0
  258. package/dest/log/log_fn.d.ts +7 -0
  259. package/dest/log/log_fn.d.ts.map +1 -0
  260. package/dest/log/log_fn.js +1 -0
  261. package/dest/log/log_history.d.ts +31 -0
  262. package/dest/log/log_history.d.ts.map +1 -0
  263. package/dest/log/log_history.js +38 -0
  264. package/dest/log/pino-logger.d.ts +57 -0
  265. package/dest/log/pino-logger.d.ts.map +1 -0
  266. package/dest/log/pino-logger.js +207 -0
  267. package/dest/message/index.d.ts +32 -0
  268. package/dest/message/index.d.ts.map +1 -0
  269. package/dest/message/index.js +27 -0
  270. package/dest/mutex/index.d.ts +53 -0
  271. package/dest/mutex/index.d.ts.map +1 -0
  272. package/dest/mutex/index.js +78 -0
  273. package/dest/mutex/mutex_database.d.ts +10 -0
  274. package/dest/mutex/mutex_database.d.ts.map +1 -0
  275. package/dest/mutex/mutex_database.js +4 -0
  276. package/dest/noir/index.d.ts +2 -0
  277. package/dest/noir/index.d.ts.map +1 -0
  278. package/dest/noir/index.js +1 -0
  279. package/dest/noir/noir_package_config.d.ts +129 -0
  280. package/dest/noir/noir_package_config.d.ts.map +1 -0
  281. package/dest/noir/noir_package_config.js +36 -0
  282. package/dest/promise/index.d.ts +3 -0
  283. package/dest/promise/index.d.ts.map +1 -0
  284. package/dest/promise/index.js +2 -0
  285. package/dest/promise/running-promise.d.ts +47 -0
  286. package/dest/promise/running-promise.d.ts.map +1 -0
  287. package/dest/promise/running-promise.js +110 -0
  288. package/dest/promise/utils.d.ts +12 -0
  289. package/dest/promise/utils.d.ts.map +1 -0
  290. package/dest/promise/utils.js +20 -0
  291. package/dest/queue/base_memory_queue.d.ts +65 -0
  292. package/dest/queue/base_memory_queue.d.ts.map +1 -0
  293. package/dest/queue/base_memory_queue.js +116 -0
  294. package/dest/queue/batch_queue.d.ts +47 -0
  295. package/dest/queue/batch_queue.d.ts.map +1 -0
  296. package/dest/queue/batch_queue.js +105 -0
  297. package/dest/queue/bounded_serial_queue.d.ts +56 -0
  298. package/dest/queue/bounded_serial_queue.d.ts.map +1 -0
  299. package/dest/queue/bounded_serial_queue.js +84 -0
  300. package/dest/queue/fifo_memory_queue.d.ts +21 -0
  301. package/dest/queue/fifo_memory_queue.d.ts.map +1 -0
  302. package/dest/queue/fifo_memory_queue.js +29 -0
  303. package/dest/queue/index.d.ts +7 -0
  304. package/dest/queue/index.d.ts.map +1 -0
  305. package/dest/queue/index.js +6 -0
  306. package/dest/queue/priority_memory_queue.d.ts +13 -0
  307. package/dest/queue/priority_memory_queue.d.ts.map +1 -0
  308. package/dest/queue/priority_memory_queue.js +16 -0
  309. package/dest/queue/priority_queue.d.ts +14 -0
  310. package/dest/queue/priority_queue.d.ts.map +1 -0
  311. package/dest/queue/priority_queue.js +29 -0
  312. package/dest/queue/semaphore.d.ts +23 -0
  313. package/dest/queue/semaphore.d.ts.map +1 -0
  314. package/dest/queue/semaphore.js +26 -0
  315. package/dest/queue/serial_queue.d.ts +49 -0
  316. package/dest/queue/serial_queue.d.ts.map +1 -0
  317. package/dest/queue/serial_queue.js +72 -0
  318. package/dest/retry/index.d.ts +44 -0
  319. package/dest/retry/index.d.ts.map +1 -0
  320. package/dest/retry/index.js +93 -0
  321. package/dest/running-promise/index.d.ts +2 -0
  322. package/dest/running-promise/index.d.ts.map +1 -0
  323. package/dest/running-promise/index.js +1 -0
  324. package/dest/schemas/api.d.ts +21 -0
  325. package/dest/schemas/api.d.ts.map +1 -0
  326. package/dest/schemas/api.js +3 -0
  327. package/dest/schemas/index.d.ts +6 -0
  328. package/dest/schemas/index.d.ts.map +1 -0
  329. package/dest/schemas/index.js +5 -0
  330. package/dest/schemas/parse.d.ts +9 -0
  331. package/dest/schemas/parse.d.ts.map +1 -0
  332. package/dest/schemas/parse.js +22 -0
  333. package/dest/schemas/schemas.d.ts +45 -0
  334. package/dest/schemas/schemas.d.ts.map +1 -0
  335. package/dest/schemas/schemas.js +38 -0
  336. package/dest/schemas/types.d.ts +3 -0
  337. package/dest/schemas/types.d.ts.map +1 -0
  338. package/dest/schemas/types.js +1 -0
  339. package/dest/schemas/utils.d.ts +53 -0
  340. package/dest/schemas/utils.d.ts.map +1 -0
  341. package/dest/schemas/utils.js +60 -0
  342. package/dest/serialize/buffer_reader.d.ts +239 -0
  343. package/dest/serialize/buffer_reader.d.ts.map +1 -0
  344. package/dest/serialize/buffer_reader.js +290 -0
  345. package/dest/serialize/field_reader.d.ts +112 -0
  346. package/dest/serialize/field_reader.d.ts.map +1 -0
  347. package/dest/serialize/field_reader.js +147 -0
  348. package/dest/serialize/free_funcs.d.ts +105 -0
  349. package/dest/serialize/free_funcs.d.ts.map +1 -0
  350. package/dest/serialize/free_funcs.js +189 -0
  351. package/dest/serialize/index.d.ts +7 -0
  352. package/dest/serialize/index.d.ts.map +1 -0
  353. package/dest/serialize/index.js +6 -0
  354. package/dest/serialize/serialize.d.ts +182 -0
  355. package/dest/serialize/serialize.d.ts.map +1 -0
  356. package/dest/serialize/serialize.js +248 -0
  357. package/dest/serialize/type_registry.d.ts +23 -0
  358. package/dest/serialize/type_registry.d.ts.map +1 -0
  359. package/dest/serialize/type_registry.js +61 -0
  360. package/dest/serialize/types.d.ts +33 -0
  361. package/dest/serialize/types.d.ts.map +1 -0
  362. package/dest/serialize/types.js +21 -0
  363. package/dest/sleep/index.d.ts +51 -0
  364. package/dest/sleep/index.d.ts.map +1 -0
  365. package/dest/sleep/index.js +67 -0
  366. package/dest/string/index.d.ts +11 -0
  367. package/dest/string/index.d.ts.map +1 -0
  368. package/dest/string/index.js +24 -0
  369. package/dest/testing/files/index.d.ts +20 -0
  370. package/dest/testing/files/index.d.ts.map +1 -0
  371. package/dest/testing/files/index.js +58 -0
  372. package/dest/testing/index.d.ts +4 -0
  373. package/dest/testing/index.d.ts.map +1 -0
  374. package/dest/testing/index.js +3 -0
  375. package/dest/testing/port_allocator.d.ts +10 -0
  376. package/dest/testing/port_allocator.d.ts.map +1 -0
  377. package/dest/testing/port_allocator.js +29 -0
  378. package/dest/testing/snapshot_serializer.d.ts +5 -0
  379. package/dest/testing/snapshot_serializer.d.ts.map +1 -0
  380. package/dest/testing/snapshot_serializer.js +32 -0
  381. package/dest/testing/test_data.d.ts +7 -0
  382. package/dest/testing/test_data.d.ts.map +1 -0
  383. package/dest/testing/test_data.js +29 -0
  384. package/dest/timer/date.d.ts +13 -0
  385. package/dest/timer/date.d.ts.map +1 -0
  386. package/dest/timer/date.js +24 -0
  387. package/dest/timer/elapsed.d.ts +13 -0
  388. package/dest/timer/elapsed.d.ts.map +1 -0
  389. package/dest/timer/elapsed.js +25 -0
  390. package/dest/timer/index.d.ts +5 -0
  391. package/dest/timer/index.d.ts.map +1 -0
  392. package/dest/timer/index.js +4 -0
  393. package/dest/timer/timeout.d.ts +41 -0
  394. package/dest/timer/timeout.d.ts.map +1 -0
  395. package/dest/timer/timeout.js +66 -0
  396. package/dest/timer/timer.d.ts +37 -0
  397. package/dest/timer/timer.d.ts.map +1 -0
  398. package/dest/timer/timer.js +40 -0
  399. package/dest/transport/browser/index.d.ts +5 -0
  400. package/dest/transport/browser/index.d.ts.map +1 -0
  401. package/dest/transport/browser/index.js +4 -0
  402. package/dest/transport/browser/message_port_socket.d.ts +37 -0
  403. package/dest/transport/browser/message_port_socket.d.ts.map +1 -0
  404. package/dest/transport/browser/message_port_socket.js +42 -0
  405. package/dest/transport/browser/shared_worker_connector.d.ts +19 -0
  406. package/dest/transport/browser/shared_worker_connector.d.ts.map +1 -0
  407. package/dest/transport/browser/shared_worker_connector.js +19 -0
  408. package/dest/transport/browser/shared_worker_listener.d.ts +38 -0
  409. package/dest/transport/browser/shared_worker_listener.d.ts.map +1 -0
  410. package/dest/transport/browser/shared_worker_listener.js +33 -0
  411. package/dest/transport/browser/worker_connector.d.ts +26 -0
  412. package/dest/transport/browser/worker_connector.d.ts.map +1 -0
  413. package/dest/transport/browser/worker_connector.js +30 -0
  414. package/dest/transport/browser/worker_listener.d.ts +39 -0
  415. package/dest/transport/browser/worker_listener.d.ts.map +1 -0
  416. package/dest/transport/browser/worker_listener.js +35 -0
  417. package/dest/transport/dispatch/create_dispatch_fn.d.ts +25 -0
  418. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -0
  419. package/dest/transport/dispatch/create_dispatch_fn.js +17 -0
  420. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +102 -0
  421. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -0
  422. package/dest/transport/dispatch/create_dispatch_proxy.js +59 -0
  423. package/dest/transport/dispatch/messages.d.ts +52 -0
  424. package/dest/transport/dispatch/messages.d.ts.map +1 -0
  425. package/dest/transport/dispatch/messages.js +13 -0
  426. package/dest/transport/index.d.ts +12 -0
  427. package/dest/transport/index.d.ts.map +1 -0
  428. package/dest/transport/index.js +11 -0
  429. package/dest/transport/interface/connector.d.ts +8 -0
  430. package/dest/transport/interface/connector.d.ts.map +1 -0
  431. package/dest/transport/interface/connector.js +3 -0
  432. package/dest/transport/interface/listener.d.ts +13 -0
  433. package/dest/transport/interface/listener.d.ts.map +1 -0
  434. package/dest/transport/interface/listener.js +4 -0
  435. package/dest/transport/interface/socket.d.ts +13 -0
  436. package/dest/transport/interface/socket.d.ts.map +1 -0
  437. package/dest/transport/interface/socket.js +7 -0
  438. package/dest/transport/interface/transferable.d.ts +68 -0
  439. package/dest/transport/interface/transferable.d.ts.map +1 -0
  440. package/dest/transport/interface/transferable.js +63 -0
  441. package/dest/transport/node/index.d.ts +3 -0
  442. package/dest/transport/node/index.d.ts.map +1 -0
  443. package/dest/transport/node/index.js +2 -0
  444. package/dest/transport/node/node_connector.d.ts +28 -0
  445. package/dest/transport/node/node_connector.d.ts.map +1 -0
  446. package/dest/transport/node/node_connector.js +26 -0
  447. package/dest/transport/node/node_connector_socket.d.ts +42 -0
  448. package/dest/transport/node/node_connector_socket.d.ts.map +1 -0
  449. package/dest/transport/node/node_connector_socket.js +44 -0
  450. package/dest/transport/node/node_listener.d.ts +26 -0
  451. package/dest/transport/node/node_listener.d.ts.map +1 -0
  452. package/dest/transport/node/node_listener.js +26 -0
  453. package/dest/transport/node/node_listener_socket.d.ts +37 -0
  454. package/dest/transport/node/node_listener_socket.d.ts.map +1 -0
  455. package/dest/transport/node/node_listener_socket.js +40 -0
  456. package/dest/transport/transport_client.d.ts +61 -0
  457. package/dest/transport/transport_client.d.ts.map +1 -0
  458. package/dest/transport/transport_client.js +96 -0
  459. package/dest/transport/transport_server.d.ts +56 -0
  460. package/dest/transport/transport_server.d.ts.map +1 -0
  461. package/dest/transport/transport_server.js +114 -0
  462. package/dest/trees/hasher.d.ts +39 -0
  463. package/dest/trees/hasher.d.ts.map +1 -0
  464. package/dest/trees/hasher.js +5 -0
  465. package/dest/trees/index.d.ts +11 -0
  466. package/dest/trees/index.d.ts.map +1 -0
  467. package/dest/trees/index.js +10 -0
  468. package/dest/trees/indexed_merkle_tree.d.ts +13 -0
  469. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -0
  470. package/dest/trees/indexed_merkle_tree.js +27 -0
  471. package/dest/trees/indexed_merkle_tree_calculator.d.ts +23 -0
  472. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -0
  473. package/dest/trees/indexed_merkle_tree_calculator.js +83 -0
  474. package/dest/trees/indexed_tree_leaf.d.ts +57 -0
  475. package/dest/trees/indexed_tree_leaf.d.ts.map +1 -0
  476. package/dest/trees/indexed_tree_leaf.js +5 -0
  477. package/dest/trees/membership_witness.d.ts +62 -0
  478. package/dest/trees/membership_witness.d.ts.map +1 -0
  479. package/dest/trees/membership_witness.js +70 -0
  480. package/dest/trees/merkle_tree.d.ts +18 -0
  481. package/dest/trees/merkle_tree.d.ts.map +1 -0
  482. package/dest/trees/merkle_tree.js +58 -0
  483. package/dest/trees/merkle_tree_calculator.d.ts +16 -0
  484. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -0
  485. package/dest/trees/merkle_tree_calculator.js +61 -0
  486. package/dest/trees/sibling_path.d.ts +132 -0
  487. package/dest/trees/sibling_path.d.ts.map +1 -0
  488. package/dest/trees/sibling_path.js +144 -0
  489. package/dest/trees/unbalanced_merkle_tree.d.ts +17 -0
  490. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -0
  491. package/dest/trees/unbalanced_merkle_tree.js +100 -0
  492. package/dest/trees/unbalanced_tree_store.d.ts +19 -0
  493. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -0
  494. package/dest/trees/unbalanced_tree_store.js +94 -0
  495. package/dest/types/index.d.ts +19 -0
  496. package/dest/types/index.d.ts.map +1 -0
  497. package/dest/types/index.js +3 -0
  498. package/dest/url/index.d.ts +9 -0
  499. package/dest/url/index.d.ts.map +1 -0
  500. package/dest/url/index.js +62 -0
  501. package/dest/validation/index.d.ts +9 -0
  502. package/dest/validation/index.d.ts.map +1 -0
  503. package/dest/validation/index.js +15 -0
  504. package/dest/wasm/empty_wasi_sdk.d.ts +130 -0
  505. package/dest/wasm/empty_wasi_sdk.d.ts.map +1 -0
  506. package/dest/wasm/empty_wasi_sdk.js +148 -0
  507. package/dest/wasm/index.d.ts +2 -0
  508. package/dest/wasm/index.d.ts.map +1 -0
  509. package/dest/wasm/index.js +1 -0
  510. package/dest/wasm/wasm_module.d.ts +136 -0
  511. package/dest/wasm/wasm_module.d.ts.map +1 -0
  512. package/dest/wasm/wasm_module.js +196 -0
  513. package/dest/worker/browser/index.d.ts +3 -0
  514. package/dest/worker/browser/index.d.ts.map +1 -0
  515. package/dest/worker/browser/index.js +2 -0
  516. package/dest/worker/browser/start_web_module.d.ts +7 -0
  517. package/dest/worker/browser/start_web_module.d.ts.map +1 -0
  518. package/dest/worker/browser/start_web_module.js +27 -0
  519. package/dest/worker/browser/web_data_store.d.ts +24 -0
  520. package/dest/worker/browser/web_data_store.d.ts.map +1 -0
  521. package/dest/worker/browser/web_data_store.js +29 -0
  522. package/dest/worker/browser/web_worker.d.ts +10 -0
  523. package/dest/worker/browser/web_worker.d.ts.map +1 -0
  524. package/dest/worker/browser/web_worker.js +25 -0
  525. package/dest/worker/data_store.d.ts +21 -0
  526. package/dest/worker/data_store.d.ts.map +1 -0
  527. package/dest/worker/data_store.js +3 -0
  528. package/dest/worker/index.d.ts +3 -0
  529. package/dest/worker/index.d.ts.map +1 -0
  530. package/dest/worker/index.js +1 -0
  531. package/dest/worker/node/index.d.ts +3 -0
  532. package/dest/worker/node/index.d.ts.map +1 -0
  533. package/dest/worker/node/index.js +2 -0
  534. package/dest/worker/node/node_data_store.d.ts +13 -0
  535. package/dest/worker/node/node_data_store.d.ts.map +1 -0
  536. package/dest/worker/node/node_data_store.js +20 -0
  537. package/dest/worker/node/node_worker.d.ts +6 -0
  538. package/dest/worker/node/node_worker.d.ts.map +1 -0
  539. package/dest/worker/node/node_worker.js +22 -0
  540. package/dest/worker/node/start_node_module.d.ts +7 -0
  541. package/dest/worker/node/start_node_module.d.ts.map +1 -0
  542. package/dest/worker/node/start_node_module.js +31 -0
  543. package/dest/worker/wasm_worker.d.ts +9 -0
  544. package/dest/worker/wasm_worker.d.ts.map +1 -0
  545. package/dest/worker/wasm_worker.js +3 -0
  546. package/dest/worker/worker_pool.d.ts +40 -0
  547. package/dest/worker/worker_pool.d.ts.map +1 -0
  548. package/dest/worker/worker_pool.js +51 -0
  549. package/package.json +176 -0
  550. package/src/array/array.ts +150 -0
  551. package/src/array/index.ts +1 -0
  552. package/src/async-map/index.ts +18 -0
  553. package/src/async-pool/index.ts +50 -0
  554. package/src/bigint-buffer/index.ts +87 -0
  555. package/src/buffer/buffer32.ts +144 -0
  556. package/src/buffer/index.ts +1 -0
  557. package/src/collection/array.ts +203 -0
  558. package/src/collection/index.ts +2 -0
  559. package/src/collection/object.ts +52 -0
  560. package/src/committable/committable.ts +46 -0
  561. package/src/committable/index.ts +1 -0
  562. package/src/config/env_var.ts +207 -0
  563. package/src/config/index.ts +167 -0
  564. package/src/crypto/aes128/index.ts +59 -0
  565. package/src/crypto/ecdsa/index.ts +70 -0
  566. package/src/crypto/ecdsa/signature.ts +100 -0
  567. package/src/crypto/grumpkin/index.ts +97 -0
  568. package/src/crypto/index.ts +14 -0
  569. package/src/crypto/keccak/index.ts +283 -0
  570. package/src/crypto/keys/index.ts +10 -0
  571. package/src/crypto/pedersen/index.ts +1 -0
  572. package/src/crypto/pedersen/pedersen.elliptic.ts +584 -0
  573. package/src/crypto/pedersen/pedersen.noble.ts +573 -0
  574. package/src/crypto/pedersen/pedersen.wasm.ts +48 -0
  575. package/src/crypto/poseidon/index.ts +77 -0
  576. package/src/crypto/random/index.ts +85 -0
  577. package/src/crypto/random/randomness_singleton.ts +62 -0
  578. package/src/crypto/schnorr/index.ts +55 -0
  579. package/src/crypto/schnorr/signature.ts +116 -0
  580. package/src/crypto/secp256k1/index.ts +57 -0
  581. package/src/crypto/secp256k1-signer/index.ts +2 -0
  582. package/src/crypto/secp256k1-signer/secp256k1_signer.ts +38 -0
  583. package/src/crypto/secp256k1-signer/utils.ts +99 -0
  584. package/src/crypto/serialize.ts +85 -0
  585. package/src/crypto/sha256/index.ts +147 -0
  586. package/src/crypto/sha512/index.ts +16 -0
  587. package/src/crypto/signature/index.ts +17 -0
  588. package/src/crypto/sync/index.ts +6 -0
  589. package/src/crypto/sync/pedersen/index.ts +45 -0
  590. package/src/crypto/sync/poseidon/index.ts +76 -0
  591. package/src/decorators/index.ts +1 -0
  592. package/src/decorators/memoize.ts +11 -0
  593. package/src/error/index.ts +22 -0
  594. package/src/eth-address/index.ts +241 -0
  595. package/src/eth-signature/eth_signature.ts +128 -0
  596. package/src/eth-signature/index.ts +1 -0
  597. package/src/fields/coordinate.ts +104 -0
  598. package/src/fields/fields.ts +505 -0
  599. package/src/fields/index.ts +3 -0
  600. package/src/fields/point.ts +300 -0
  601. package/src/fs/index.ts +1 -0
  602. package/src/fs/run_in_dir.ts +33 -0
  603. package/src/index.ts +31 -0
  604. package/src/iterable/all.ts +32 -0
  605. package/src/iterable/filter.ts +77 -0
  606. package/src/iterable/index.ts +7 -0
  607. package/src/iterable/isAsyncIt.ts +8 -0
  608. package/src/iterable/map.ts +66 -0
  609. package/src/iterable/peek.ts +58 -0
  610. package/src/iterable/sort.ts +39 -0
  611. package/src/iterable/take.ts +54 -0
  612. package/src/iterable/toArray.ts +9 -0
  613. package/src/jest/setup.mjs +9 -0
  614. package/src/json-rpc/README.md +55 -0
  615. package/src/json-rpc/client/fetch.ts +103 -0
  616. package/src/json-rpc/client/index.ts +2 -0
  617. package/src/json-rpc/client/safe_json_rpc_client.ts +67 -0
  618. package/src/json-rpc/client/undici.ts +75 -0
  619. package/src/json-rpc/convert.ts +61 -0
  620. package/src/json-rpc/fixtures/class_a.ts +15 -0
  621. package/src/json-rpc/fixtures/class_b.ts +15 -0
  622. package/src/json-rpc/fixtures/test_state.ts +143 -0
  623. package/src/json-rpc/index.ts +1 -0
  624. package/src/json-rpc/js_utils.ts +21 -0
  625. package/src/json-rpc/server/index.ts +1 -0
  626. package/src/json-rpc/server/safe_json_rpc_server.ts +376 -0
  627. package/src/json-rpc/server/telemetry.ts +0 -0
  628. package/src/json-rpc/test/index.ts +1 -0
  629. package/src/json-rpc/test/integration.ts +35 -0
  630. package/src/log/console.ts +39 -0
  631. package/src/log/debug.ts +104 -0
  632. package/src/log/gcloud-logger-config.ts +71 -0
  633. package/src/log/index.ts +6 -0
  634. package/src/log/libp2p_logger.ts +67 -0
  635. package/src/log/log-filters.ts +63 -0
  636. package/src/log/log-levels.ts +3 -0
  637. package/src/log/log_fn.ts +5 -0
  638. package/src/log/log_history.ts +44 -0
  639. package/src/log/pino-logger.ts +243 -0
  640. package/src/message/index.ts +43 -0
  641. package/src/mutex/index.ts +84 -0
  642. package/src/mutex/mutex_database.ts +12 -0
  643. package/src/noir/index.ts +1 -0
  644. package/src/noir/noir_package_config.ts +54 -0
  645. package/src/promise/index.ts +2 -0
  646. package/src/promise/running-promise.ts +125 -0
  647. package/src/promise/utils.ts +29 -0
  648. package/src/queue/base_memory_queue.ts +138 -0
  649. package/src/queue/batch_queue.ts +120 -0
  650. package/src/queue/bounded_serial_queue.ts +100 -0
  651. package/src/queue/fifo_memory_queue.ts +39 -0
  652. package/src/queue/index.ts +6 -0
  653. package/src/queue/priority_memory_queue.ts +20 -0
  654. package/src/queue/priority_queue.ts +34 -0
  655. package/src/queue/semaphore.ts +33 -0
  656. package/src/queue/serial_queue.ts +86 -0
  657. package/src/retry/index.ts +100 -0
  658. package/src/running-promise/index.ts +1 -0
  659. package/src/schemas/api.ts +47 -0
  660. package/src/schemas/index.ts +5 -0
  661. package/src/schemas/parse.ts +29 -0
  662. package/src/schemas/schemas.ts +64 -0
  663. package/src/schemas/types.ts +3 -0
  664. package/src/schemas/utils.ts +112 -0
  665. package/src/serialize/buffer_reader.ts +383 -0
  666. package/src/serialize/field_reader.ts +184 -0
  667. package/src/serialize/free_funcs.ts +204 -0
  668. package/src/serialize/index.ts +6 -0
  669. package/src/serialize/serialize.ts +336 -0
  670. package/src/serialize/type_registry.ts +75 -0
  671. package/src/serialize/types.ts +40 -0
  672. package/src/sleep/index.ts +75 -0
  673. package/src/string/index.ts +31 -0
  674. package/src/testing/files/index.ts +69 -0
  675. package/src/testing/index.ts +3 -0
  676. package/src/testing/port_allocator.ts +31 -0
  677. package/src/testing/snapshot_serializer.ts +33 -0
  678. package/src/testing/test_data.ts +36 -0
  679. package/src/timer/date.ts +24 -0
  680. package/src/timer/elapsed.ts +23 -0
  681. package/src/timer/index.ts +4 -0
  682. package/src/timer/timeout.ts +70 -0
  683. package/src/timer/timer.ts +48 -0
  684. package/src/transport/browser/index.ts +4 -0
  685. package/src/transport/browser/message_port_socket.ts +48 -0
  686. package/src/transport/browser/shared_worker_connector.ts +21 -0
  687. package/src/transport/browser/shared_worker_listener.ts +53 -0
  688. package/src/transport/browser/worker_connector.ts +30 -0
  689. package/src/transport/browser/worker_listener.ts +54 -0
  690. package/src/transport/dispatch/create_dispatch_fn.ts +35 -0
  691. package/src/transport/dispatch/create_dispatch_proxy.ts +141 -0
  692. package/src/transport/dispatch/messages.ts +58 -0
  693. package/src/transport/index.ts +11 -0
  694. package/src/transport/interface/connector.ts +9 -0
  695. package/src/transport/interface/listener.ts +16 -0
  696. package/src/transport/interface/socket.ts +15 -0
  697. package/src/transport/interface/transferable.ts +125 -0
  698. package/src/transport/node/index.ts +2 -0
  699. package/src/transport/node/node_connector.ts +30 -0
  700. package/src/transport/node/node_connector_socket.ts +52 -0
  701. package/src/transport/node/node_listener.ts +34 -0
  702. package/src/transport/node/node_listener_socket.ts +48 -0
  703. package/src/transport/transport_client.ts +131 -0
  704. package/src/transport/transport_server.ts +108 -0
  705. package/src/trees/hasher.ts +39 -0
  706. package/src/trees/index.ts +10 -0
  707. package/src/trees/indexed_merkle_tree.ts +36 -0
  708. package/src/trees/indexed_merkle_tree_calculator.ts +94 -0
  709. package/src/trees/indexed_tree_leaf.ts +56 -0
  710. package/src/trees/membership_witness.ts +99 -0
  711. package/src/trees/merkle_tree.ts +72 -0
  712. package/src/trees/merkle_tree_calculator.ts +67 -0
  713. package/src/trees/sibling_path.ts +183 -0
  714. package/src/trees/unbalanced_merkle_tree.ts +103 -0
  715. package/src/trees/unbalanced_tree_store.ts +102 -0
  716. package/src/types/index.ts +25 -0
  717. package/src/url/index.ts +73 -0
  718. package/src/validation/index.ts +18 -0
  719. package/src/wasm/README.md +6 -0
  720. package/src/wasm/empty_wasi_sdk.ts +166 -0
  721. package/src/wasm/fixtures/gcd.wasm +0 -0
  722. package/src/wasm/fixtures/gcd.wat +27 -0
  723. package/src/wasm/index.ts +1 -0
  724. package/src/wasm/wasm_module.ts +260 -0
  725. package/src/worker/browser/index.ts +2 -0
  726. package/src/worker/browser/start_web_module.ts +24 -0
  727. package/src/worker/browser/web_data_store.ts +38 -0
  728. package/src/worker/browser/web_worker.ts +25 -0
  729. package/src/worker/data_store.ts +19 -0
  730. package/src/worker/index.ts +2 -0
  731. package/src/worker/node/index.ts +2 -0
  732. package/src/worker/node/node_data_store.ts +27 -0
  733. package/src/worker/node/node_worker.ts +23 -0
  734. package/src/worker/node/start_node_module.ts +30 -0
  735. package/src/worker/wasm_worker.ts +7 -0
  736. package/src/worker/worker_pool.ts +73 -0
@@ -0,0 +1,300 @@
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';
8
+
9
+ /**
10
+ * Represents a Point on an elliptic curve with x and y coordinates.
11
+ * The Point class provides methods for creating instances from different input types,
12
+ * converting instances to various output formats, and checking the equality of points.
13
+ * TODO(#7386): Clean up this class.
14
+ */
15
+ export class Point {
16
+ static ZERO = new Point(Fr.ZERO, Fr.ZERO, false);
17
+ static SIZE_IN_BYTES = Fr.SIZE_IN_BYTES * 2;
18
+ static COMPRESSED_SIZE_IN_BYTES = Fr.SIZE_IN_BYTES;
19
+
20
+ /** Used to differentiate this class from AztecAddress */
21
+ public readonly kind = 'point';
22
+
23
+ constructor(
24
+ /**
25
+ * The point's x coordinate
26
+ */
27
+ public readonly x: Fr,
28
+ /**
29
+ * The point's y coordinate
30
+ */
31
+ public readonly y: Fr,
32
+ /**
33
+ * Whether the point is at infinity
34
+ */
35
+ public readonly isInfinite: boolean,
36
+ ) {
37
+ // TODO(#7386): check if on curve
38
+ }
39
+
40
+ toJSON() {
41
+ return this.toString();
42
+ }
43
+
44
+ static get schema() {
45
+ return hexSchemaFor(Point);
46
+ }
47
+
48
+ /**
49
+ * Generate a random Point instance.
50
+ *
51
+ * @returns A randomly generated Point instance.
52
+ */
53
+ static async random() {
54
+ while (true) {
55
+ try {
56
+ return await Point.fromXAndSign(Fr.random(), randomBoolean());
57
+ } catch (e: any) {
58
+ if (!(e instanceof NotOnCurveError)) {
59
+ throw e;
60
+ }
61
+ // The random point is not on the curve - we try again
62
+ continue;
63
+ }
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Create a Point instance from a given buffer or BufferReader.
69
+ * The input 'buffer' should have exactly 64 bytes representing the x and y coordinates.
70
+ *
71
+ * @param buffer - The buffer or BufferReader containing the x and y coordinates of the point.
72
+ * @returns A Point instance.
73
+ */
74
+ static fromBuffer(buffer: Buffer | BufferReader) {
75
+ const reader = BufferReader.asReader(buffer);
76
+ return new this(Fr.fromBuffer(reader), Fr.fromBuffer(reader), false);
77
+ }
78
+
79
+ /**
80
+ * Create a Point instance from a compressed buffer.
81
+ * The input 'buffer' should have exactly 33 bytes representing the x coordinate and the sign of the y coordinate.
82
+ *
83
+ * @param buffer - The buffer containing the x coordinate and the sign of the y coordinate.
84
+ * @returns A Point instance.
85
+ */
86
+ static fromCompressedBuffer(buffer: Buffer | BufferReader): Promise<Point> {
87
+ const reader = BufferReader.asReader(buffer);
88
+ const value = toBigIntBE(reader.readBytes(Point.COMPRESSED_SIZE_IN_BYTES));
89
+
90
+ const x = new Fr(value & ((1n << 255n) - 1n));
91
+ const sign = (value & (1n << 255n)) !== 0n;
92
+
93
+ return this.fromXAndSign(x, sign);
94
+ }
95
+
96
+ /**
97
+ * Create a Point instance from a hex-encoded string.
98
+ * The input should be prefixed with '0x' or not, and have exactly 128 hex characters representing the x and y coordinates.
99
+ * Throws an error if the input length is invalid or coordinate values are out of range.
100
+ *
101
+ * @param str - The hex-encoded string representing the Point coordinates.
102
+ * @returns A Point instance.
103
+ */
104
+ static fromString(str: string) {
105
+ return this.fromBuffer(hexToBuffer(str));
106
+ }
107
+
108
+ /**
109
+ * Returns the contents of the point as an array of 2 fields.
110
+ * @returns The point as an array of 2 fields
111
+ */
112
+ toFields() {
113
+ return [this.x, this.y, new Fr(this.isInfinite)];
114
+ }
115
+
116
+ static fromFields(fields: Fr[] | FieldReader) {
117
+ const reader = FieldReader.asReader(fields);
118
+ return new this(reader.readField(), reader.readField(), reader.readBoolean());
119
+ }
120
+
121
+ /**
122
+ * Uses the x coordinate and isPositive flag (+/-) to reconstruct the point.
123
+ * @dev The y coordinate can be derived from the x coordinate and the "sign" flag by solving the grumpkin curve
124
+ * equation for y.
125
+ * @param x - The x coordinate of the point
126
+ * @param sign - The "sign" of the y coordinate - note that this is not a sign as is known in integer arithmetic.
127
+ * Instead it is a boolean flag that determines whether the y coordinate is <= (Fr.MODULUS - 1) / 2
128
+ * @returns The point as an array of 2 fields
129
+ */
130
+ static async fromXAndSign(x: Fr, sign: boolean) {
131
+ const y = await Point.YFromX(x);
132
+ if (y == null) {
133
+ throw new NotOnCurveError(x);
134
+ }
135
+
136
+ const yPositiveBigInt = y.toBigInt() <= (Fr.MODULUS - 1n) / 2n ? y.toBigInt() : Fr.MODULUS - y.toBigInt();
137
+ const yNegativeBigInt = Fr.MODULUS - yPositiveBigInt;
138
+
139
+ // Choose the positive or negative root based on isPositive
140
+ const finalY = sign ? new Fr(yPositiveBigInt) : new Fr(yNegativeBigInt);
141
+
142
+ // Create and return the new Point
143
+ return new this(x, finalY, false);
144
+ }
145
+
146
+ /**
147
+ * @returns
148
+ */
149
+ static YFromX(x: Fr): Promise<Fr | null> {
150
+ // Calculate y^2 = x^3 - 17 (i.e. the Grumpkin curve equation)
151
+ const ySquared = x.square().mul(x).sub(new Fr(17));
152
+
153
+ // y is then simply the square root. Note however that not all square roots exist in the field: if sqrt returns null
154
+ // then there is no point in the curve with this x coordinate.
155
+ return ySquared.sqrt();
156
+ }
157
+
158
+ /**
159
+ * Returns the x coordinate and the sign of the y coordinate.
160
+ * @dev The y sign can be determined by checking if the y coordinate is greater than half of the modulus.
161
+ * @returns The x coordinate and the sign of the y coordinate.
162
+ */
163
+ toXAndSign(): [Fr, boolean] {
164
+ return [this.x, this.y.toBigInt() <= (Fr.MODULUS - 1n) / 2n];
165
+ }
166
+
167
+ /**
168
+ * Returns the contents of the point as BigInts.
169
+ * @returns The point as BigInts
170
+ */
171
+ toBigInts() {
172
+ return {
173
+ x: this.x.toBigInt(),
174
+ y: this.y.toBigInt(),
175
+ isInfinite: this.isInfinite ? 1n : 0n,
176
+ };
177
+ }
178
+
179
+ /**
180
+ * Converts the Point instance to a Buffer representation of the coordinates.
181
+ * @returns A Buffer representation of the Point instance.
182
+ * @dev Note that toBuffer does not include the isInfinite flag and other serialization methods do (e.g. toFields).
183
+ * This is because currently when we work with point as bytes we don't want to populate the extra bytes for
184
+ * isInfinite flag because:
185
+ * 1. Our Grumpkin BB API currently does not handle point at infinity,
186
+ * 2. we use toBuffer when serializing notes and events and there we only work with public keys and point at infinity
187
+ * is not considered a valid public key and the extra byte would raise DA cost.
188
+ */
189
+ toBuffer() {
190
+ if (this.isInfinite) {
191
+ throw new Error('Cannot serialize infinite point without isInfinite flag');
192
+ }
193
+ const buf = serializeToBuffer([this.x, this.y]);
194
+ if (buf.length !== Point.SIZE_IN_BYTES) {
195
+ throw new Error(`Invalid buffer length for Point: ${buf.length}`);
196
+ }
197
+ return buf;
198
+ }
199
+
200
+ /**
201
+ * Converts the Point instance to a compressed Buffer representation of the coordinates.
202
+ * @returns A Buffer representation of the Point instance
203
+ */
204
+ toCompressedBuffer() {
205
+ const [x, sign] = this.toXAndSign();
206
+ // Here we leverage that Fr fits into 254 bits (log2(Fr.MODULUS) < 254) and given that we serialize Fr to 32 bytes
207
+ // and we use big-endian the 2 most significant bits are never populated. Hence we can use one of the bits as
208
+ // a sign bit.
209
+ const compressedValue = x.toBigInt() + (sign ? 2n ** 255n : 0n);
210
+ const buf = serializeToBuffer(compressedValue);
211
+ if (buf.length !== Point.COMPRESSED_SIZE_IN_BYTES) {
212
+ throw new Error(`Invalid buffer length for compressed Point: ${buf.length}`);
213
+ }
214
+ return buf;
215
+ }
216
+
217
+ /**
218
+ * Convert the Point instance to a hexadecimal string representation.
219
+ * The output string is prefixed with '0x' and consists of exactly 128 hex characters,
220
+ * representing the concatenated x and y coordinates of the point.
221
+ *
222
+ * @returns A hex-encoded string representing the Point instance.
223
+ */
224
+ toString() {
225
+ return bufferToHex(this.toBuffer());
226
+ }
227
+
228
+ /**
229
+ * Generate a short string representation of the Point instance.
230
+ * The returned string includes the first 10 and last 4 characters of the full string representation,
231
+ * with '...' in between to indicate truncation. This is useful for displaying or logging purposes
232
+ * when the full string representation may be too long.
233
+ *
234
+ * @returns A truncated string representation of the Point instance.
235
+ */
236
+ toShortString() {
237
+ const str = this.toString();
238
+ return `${str.slice(0, 10)}...${str.slice(-4)}`;
239
+ }
240
+
241
+ toNoirStruct() {
242
+ /* eslint-disable camelcase */
243
+ return { x: this.x, y: this.y, is_infinite: this.isInfinite };
244
+ /* eslint-enable camelcase */
245
+ }
246
+
247
+ // Used for IvpkM, OvpkM, NpkM and TpkM. TODO(#8124): Consider removing this method.
248
+ toWrappedNoirStruct() {
249
+ /* eslint-disable camelcase */
250
+ return { inner: this.toNoirStruct() };
251
+ /* eslint-enable camelcase */
252
+ }
253
+
254
+ /**
255
+ * Check if two Point instances are equal by comparing their buffer values.
256
+ * Returns true if the buffer values are the same, and false otherwise.
257
+ *
258
+ * @param rhs - The Point instance to compare with the current instance.
259
+ * @returns A boolean indicating whether the two Point instances are equal.
260
+ */
261
+ equals(rhs: Point) {
262
+ return this.x.equals(rhs.x) && this.y.equals(rhs.y);
263
+ }
264
+
265
+ isZero() {
266
+ return this.x.isZero() && this.y.isZero();
267
+ }
268
+
269
+ hash() {
270
+ return poseidon2Hash(this.toFields());
271
+ }
272
+
273
+ /**
274
+ * Check if this is point at infinity.
275
+ * Check this is consistent with how bb is encoding the point at infinity
276
+ */
277
+ public get inf() {
278
+ return this.isInfinite;
279
+ }
280
+
281
+ isOnGrumpkin() {
282
+ // TODO: Check this against how bb handles curve check and infinity point check
283
+ if (this.inf) {
284
+ return true;
285
+ }
286
+
287
+ // The Grumpkin equation is y^2 = x^3 - 17. We could use `YFromX` and then compare to `this.y`, but this would
288
+ // involve computing the square root of y, of which there are two possible valid values. This method is also faster.
289
+ const lhs = this.y.square();
290
+ const rhs = this.x.mul(this.x).mul(this.x).sub(new Fr(17));
291
+ return lhs.equals(rhs);
292
+ }
293
+ }
294
+
295
+ export class NotOnCurveError extends Error {
296
+ constructor(x: Fr) {
297
+ super('The given x-coordinate is not on the Grumpkin curve: ' + x.toString());
298
+ this.name = 'NotOnCurveError';
299
+ }
300
+ }
@@ -0,0 +1 @@
1
+ export * from './run_in_dir.js';
@@ -0,0 +1,33 @@
1
+ import { promises as fs } from 'fs';
2
+ import * as path from 'path';
3
+
4
+ import { createLogger } from '../log/pino-logger.js';
5
+
6
+ // Create a random directory underneath a 'base' directory
7
+ // Calls a provided method, ensures the random directory is cleaned up afterwards unless the operation fails
8
+ export async function runInDirectory<T>(
9
+ workingDirBase: string,
10
+ fn: (dir: string) => Promise<T>,
11
+ skipCleanup: boolean | undefined,
12
+ logger = createLogger('foundation:run-in-directory'),
13
+ ): Promise<T> {
14
+ // Create random directory to be used for temp files
15
+ const workingDirectory = await fs.mkdtemp(path.join(workingDirBase, 'tmp-'));
16
+
17
+ await fs.access(workingDirectory);
18
+
19
+ try {
20
+ return await fn(workingDirectory);
21
+ } catch (err) {
22
+ skipCleanup = true;
23
+ throw err;
24
+ } finally {
25
+ if (!skipCleanup) {
26
+ try {
27
+ await fs.rm(workingDirectory, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
28
+ } catch (err) {
29
+ logger.warn(`Failed to cleanup temporary directory ${workingDirectory}: ${err}`, { err });
30
+ }
31
+ }
32
+ }
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1,31 @@
1
+ // Reexport all folders at the root for packages targeting CommonJS
2
+ export * as asyncMap from './async-map/index.js';
3
+ export * as bigintBuffer from './bigint-buffer/index.js';
4
+ export * as collection from './collection/index.js';
5
+ export * as committable from './committable/index.js';
6
+ export * as crypto from './crypto/index.js';
7
+ export * as errors from './error/index.js';
8
+ export * as ethAddress from './eth-address/index.js';
9
+ export * as fields from './fields/index.js';
10
+ export * as fifo from './queue/index.js';
11
+ export * as fs from './fs/index.js';
12
+ export * as jsonRpc from './json-rpc/index.js';
13
+ export * as jsonRpcClient from './json-rpc/client/index.js';
14
+ export * as jsonRpcServer from './json-rpc/server/index.js';
15
+ export * as log from './log/index.js';
16
+ export * as mutex from './mutex/index.js';
17
+ export * as retry from './retry/index.js';
18
+ export * as runningPromise from './running-promise/index.js';
19
+ export * as serialize from './serialize/index.js';
20
+ export * as sleep from './sleep/index.js';
21
+ export * as timer from './timer/index.js';
22
+ export * as transport from './transport/index.js';
23
+ export * as trees from './trees/index.js';
24
+ export * as types from './types/index.js';
25
+ export * as url from './url/index.js';
26
+ export * as wasm from './wasm/index.js';
27
+ export * as worker from './worker/index.js';
28
+ export * as testing from './testing/index.js';
29
+ export * as config from './config/index.js';
30
+ export * as buffer from './buffer/index.js';
31
+ export * as ethSignature from './eth-signature/index.js';
@@ -0,0 +1,32 @@
1
+ import { isAsyncIterable } from './isAsyncIt.js';
2
+
3
+ /**
4
+ * Collects all values from an (async) iterable and returns them as an array
5
+ * @param source - Iterable to collect all values from
6
+ * @returns All of the iterable's values as an array.
7
+ */
8
+ function all<T>(source: Iterable<T>): T[];
9
+ function all<T>(source: Iterable<T> | AsyncIterable<T>): Promise<T[]>;
10
+ function all<T>(source: Iterable<T> | AsyncIterable<T>): Promise<T[]> | T[] {
11
+ if (isAsyncIterable(source)) {
12
+ return (async () => {
13
+ const arr = [];
14
+
15
+ for await (const entry of source) {
16
+ arr.push(entry);
17
+ }
18
+
19
+ return arr;
20
+ })();
21
+ }
22
+
23
+ const arr = [];
24
+
25
+ for (const entry of source) {
26
+ arr.push(entry);
27
+ }
28
+
29
+ return arr;
30
+ }
31
+
32
+ export { all };
@@ -0,0 +1,77 @@
1
+ import { peek } from './peek.js';
2
+
3
+ function isAsyncIterable<T>(thing: any): thing is AsyncIterable<T> {
4
+ return thing[Symbol.asyncIterator] != null;
5
+ }
6
+
7
+ /**
8
+ * Filters the passed (async) iterable by using the filter function.
9
+ * @param source - An iterable to filter.
10
+ * @returns A generator of the filtered values.
11
+ */
12
+ function filter<T>(
13
+ source: Iterable<T>,
14
+ fn: (val: T, index: number) => Promise<boolean>,
15
+ ): AsyncGenerator<T, void, undefined>;
16
+ function filter<T>(source: Iterable<T>, fn: (val: T, index: number) => boolean): Generator<T, void, undefined>;
17
+ function filter<T>(
18
+ source: Iterable<T> | AsyncIterable<T>,
19
+ fn: (val: T, index: number) => boolean | Promise<boolean>,
20
+ ): AsyncGenerator<T, void, undefined>;
21
+ function filter<T>(
22
+ source: Iterable<T> | AsyncIterable<T>,
23
+ fn: (val: T, index: number) => boolean | Promise<boolean>,
24
+ ): Generator<T, void, undefined> | AsyncGenerator<T, void, undefined> {
25
+ let index = 0;
26
+
27
+ if (isAsyncIterable(source)) {
28
+ return (async function* () {
29
+ for await (const entry of source) {
30
+ if (await fn(entry, index++)) {
31
+ yield entry;
32
+ }
33
+ }
34
+ })();
35
+ }
36
+
37
+ // if mapping function returns a promise we have to return an async generator
38
+ const peekable = peek(source);
39
+ const { value, done } = peekable.next();
40
+
41
+ if (done === true) {
42
+ return (function* () {})();
43
+ }
44
+
45
+ const res = fn(value, index++);
46
+
47
+ // @ts-expect-error .then is not present on O
48
+ if (typeof res.then === 'function') {
49
+ return (async function* () {
50
+ if (await res) {
51
+ yield value;
52
+ }
53
+
54
+ for await (const entry of peekable) {
55
+ if (await fn(entry, index++)) {
56
+ yield entry;
57
+ }
58
+ }
59
+ })();
60
+ }
61
+
62
+ const func = fn as (val: T, index: number) => boolean;
63
+
64
+ return (function* () {
65
+ if (res === true) {
66
+ yield value;
67
+ }
68
+
69
+ for (const entry of peekable) {
70
+ if (func(entry, index++)) {
71
+ yield entry;
72
+ }
73
+ }
74
+ })();
75
+ }
76
+
77
+ export { filter };
@@ -0,0 +1,7 @@
1
+ export * from './map.js';
2
+ export * from './filter.js';
3
+ export * from './sort.js';
4
+ export * from './take.js';
5
+ export * from './all.js';
6
+ export * from './peek.js';
7
+ export * from './toArray.js';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Utility function to type check an AsyncIterable
3
+ * @param thing - Input to type check
4
+ * @returns Type-checked input
5
+ */
6
+ export function isAsyncIterable<T>(thing: any): thing is AsyncIterable<T> {
7
+ return thing[Symbol.asyncIterator] != null;
8
+ }
@@ -0,0 +1,66 @@
1
+ import { isAsyncIterable } from './isAsyncIt.js';
2
+ import { peek } from './peek.js';
3
+
4
+ /**
5
+ * Takes an (async) iterable and returns one with each item mapped by the passed
6
+ * function.
7
+ * @param source - The iterable to run the map function on.
8
+ * @param func - The function to run over the iterable's items.
9
+ * @returns A generator of the mapped items.
10
+ */
11
+ function map<I, O>(
12
+ source: Iterable<I>,
13
+ func: (val: I, index: number) => Promise<O>,
14
+ ): AsyncGenerator<O, void, undefined>;
15
+ function map<I, O>(source: Iterable<I>, func: (val: I, index: number) => O): Generator<O, void, undefined>;
16
+ function map<I, O>(
17
+ source: AsyncIterable<I> | Iterable<I>,
18
+ func: (val: I, index: number) => O | Promise<O>,
19
+ ): AsyncGenerator<O, void, undefined>;
20
+ function map<I, O>(
21
+ source: AsyncIterable<I> | Iterable<I>,
22
+ func: (val: I, index: number) => O | Promise<O>,
23
+ ): AsyncGenerator<O, void, undefined> | Generator<O, void, undefined> {
24
+ let index = 0;
25
+
26
+ if (isAsyncIterable(source)) {
27
+ return (async function* () {
28
+ for await (const val of source) {
29
+ yield func(val, index++);
30
+ }
31
+ })();
32
+ }
33
+
34
+ // if mapping function returns a promise we have to return an async generator
35
+ const peekable = peek(source);
36
+ const { value, done } = peekable.next();
37
+
38
+ if (done === true) {
39
+ return (function* () {})();
40
+ }
41
+
42
+ const res = func(value, index++);
43
+
44
+ // @ts-expect-error .then is not present on O
45
+ if (typeof res.then === 'function') {
46
+ return (async function* () {
47
+ yield await res;
48
+
49
+ for await (const val of peekable) {
50
+ yield func(val, index++);
51
+ }
52
+ })();
53
+ }
54
+
55
+ const fn = func as (val: I, index: number) => O;
56
+
57
+ return (function* () {
58
+ yield res as O;
59
+
60
+ for (const val of peekable) {
61
+ yield fn(val, index++);
62
+ }
63
+ })();
64
+ }
65
+
66
+ export { map };
@@ -0,0 +1,58 @@
1
+ export interface Peek<T> {
2
+ peek(): IteratorResult<T, undefined>;
3
+ }
4
+
5
+ export interface AsyncPeek<T> {
6
+ peek(): Promise<IteratorResult<T, undefined>>;
7
+ }
8
+
9
+ export interface Push<T> {
10
+ push(value: T): void;
11
+ }
12
+
13
+ export type Peekable<T> = Iterable<T> & Peek<T> & Push<T> & Iterator<T>;
14
+
15
+ export type AsyncPeekable<T> = AsyncIterable<T> & AsyncPeek<T> & Push<T> & AsyncIterator<T>;
16
+
17
+ /**
18
+ * Utility function that allows peeking into the contents of an async iterator.
19
+ * @param iterable - The async iterator to peek the values of.
20
+ */
21
+ function peekable<T>(iterable: Iterable<T>): Peekable<T>;
22
+ function peekable<T>(iterable: AsyncIterable<T>): AsyncPeekable<T>;
23
+ function peekable<T>(iterable: Iterable<T> | AsyncIterable<T>): Peekable<T> | AsyncPeekable<T> {
24
+ const [iterator, symbol] =
25
+ // @ts-expect-error can't use Symbol.asyncIterator to index iterable since it might be Iterable
26
+ iterable[Symbol.asyncIterator] != null
27
+ ? // @ts-expect-error can't use Symbol.asyncIterator to index iterable since it might be Iterable
28
+ [iterable[Symbol.asyncIterator](), Symbol.asyncIterator]
29
+ : // @ts-expect-error can't use Symbol.iterator to index iterable since it might be AsyncIterable
30
+ [iterable[Symbol.iterator](), Symbol.iterator];
31
+
32
+ const queue: any[] = [];
33
+
34
+ // @ts-expect-error can't use symbol to index peekable
35
+ return {
36
+ peek: () => {
37
+ return iterator.next();
38
+ },
39
+ push: (value: any) => {
40
+ queue.push(value);
41
+ },
42
+ next: () => {
43
+ if (queue.length > 0) {
44
+ return {
45
+ done: false,
46
+ value: queue.shift(),
47
+ };
48
+ }
49
+
50
+ return iterator.next();
51
+ },
52
+ [symbol]() {
53
+ return this;
54
+ },
55
+ };
56
+ }
57
+
58
+ export { peekable as peek };
@@ -0,0 +1,39 @@
1
+ import { all } from './all.js';
2
+ import { isAsyncIterable } from './isAsyncIt.js';
3
+
4
+ export interface CompareFunction<T> {
5
+ (a: T, b: T): number;
6
+ }
7
+
8
+ /**
9
+ * Collects all values from an async iterator, sorts them
10
+ * using the passed function and yields them.
11
+ * @param source - Iterable to sort.
12
+ * @param sorter - Sorting function.
13
+ * @returns A generator of the sorted values.
14
+ */
15
+ function sort<T>(source: Iterable<T>, sorter: CompareFunction<T>): Generator<T, void, undefined>;
16
+ function sort<T>(
17
+ source: Iterable<T> | AsyncIterable<T>,
18
+ sorter: CompareFunction<T>,
19
+ ): AsyncGenerator<T, void, undefined>;
20
+ function sort<T>(
21
+ source: Iterable<T> | AsyncIterable<T>,
22
+ sorter: CompareFunction<T>,
23
+ ): AsyncGenerator<T, void, undefined> | Generator<T, void, undefined> {
24
+ if (isAsyncIterable(source)) {
25
+ return (async function* () {
26
+ const arr = await all(source);
27
+
28
+ yield* arr.sort(sorter);
29
+ })();
30
+ }
31
+
32
+ return (function* () {
33
+ const arr = all(source);
34
+
35
+ yield* arr.sort(sorter);
36
+ })();
37
+ }
38
+
39
+ export { sort };