@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
@@ -0,0 +1,359 @@
1
+ /* eslint-disable camelcase */ import { bls12_381 } from '@noble/curves/bls12-381';
2
+ import { inspect } from 'util';
3
+ import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
4
+ import { randomBytes } from '../crypto/random/index.js';
5
+ import { hexSchemaFor } from '../schemas/utils.js';
6
+ import { BufferReader } from '../serialize/buffer_reader.js';
7
+ import { TypeRegistry } from '../serialize/type_registry.js';
8
+ import { Fr } from './fields.js';
9
+ /**
10
+ * Base BLS12field class.
11
+ */ export class BLS12Field {
12
+ asBuffer;
13
+ asBigInt;
14
+ constructor(value){
15
+ if (Buffer.isBuffer(value)) {
16
+ if (value.length > this.size()) {
17
+ throw new Error(`Value length ${value.length} exceeds ${this.size()}`);
18
+ }
19
+ this.asBuffer = value.length === this.size() ? value : Buffer.concat([
20
+ Buffer.alloc(this.size() - value.length),
21
+ value
22
+ ]);
23
+ this.toBigInt();
24
+ } else if (typeof value === 'bigint' || typeof value === 'number') {
25
+ this.asBigInt = BigInt(value);
26
+ if (this.asBigInt >= this.modulus()) {
27
+ throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
28
+ }
29
+ this.toBuffer();
30
+ } else {
31
+ throw new Error(`Type '${typeof value}' with value '${value}' passed to BLS12Field constructor.`);
32
+ }
33
+ }
34
+ /**
35
+ * We return a copy of the Buffer to ensure this remains immutable.
36
+ */ toBuffer() {
37
+ if (!this.asBuffer) {
38
+ this.asBuffer = toBufferBE(this.asBigInt, this.size());
39
+ }
40
+ return Buffer.from(this.asBuffer);
41
+ }
42
+ toString() {
43
+ return `0x${this.toBuffer().toString('hex')}`;
44
+ }
45
+ toBigInt() {
46
+ if (this.asBigInt === undefined) {
47
+ this.asBigInt = toBigIntBE(this.asBuffer);
48
+ if (this.asBigInt >= this.modulus()) {
49
+ throw new Error(`Value 0x${this.asBigInt.toString(16)} is greater or equal to field modulus.`);
50
+ }
51
+ }
52
+ return this.asBigInt;
53
+ }
54
+ toNoirBigNum() {
55
+ const buffer = this.toBuffer();
56
+ const limbs = [];
57
+ // Split into 120 bit (=15 byte) limbs
58
+ for(let i = 0; i < Math.ceil(this.size() / 15); i++){
59
+ limbs.push(buffer.subarray(-(i + 1) * 15, this.size() - i * 15));
60
+ }
61
+ return {
62
+ limbs: limbs.map((l)=>`0x${l.toString('hex')}`)
63
+ };
64
+ }
65
+ equals(rhs) {
66
+ return this.toBuffer().equals(rhs.toBuffer());
67
+ }
68
+ lt(rhs) {
69
+ return this.toBigInt() < rhs.toBigInt();
70
+ }
71
+ isZero() {
72
+ return this.toBigInt() === 0n;
73
+ }
74
+ isEmpty() {
75
+ return this.isZero();
76
+ }
77
+ isNegative() {
78
+ // Returns whether the field element is above the halfway point of (p-1)/2
79
+ // Generally referred to as 'negative' but also referred to as 'greater' (e.g. in point compression)
80
+ return this.toBigInt() > (this.modulus() - 1n) / 2n;
81
+ }
82
+ toFriendlyJSON() {
83
+ return this.toString();
84
+ }
85
+ toField() {
86
+ return this;
87
+ }
88
+ }
89
+ /**
90
+ * Constructs a field from a Buffer of BufferReader.
91
+ * It maybe not read the full SIZE_IN_BYTES bytes if the Buffer is shorter, but it will padded in BLS12Field constructor.
92
+ */ function fromBuffer(buffer, f) {
93
+ const reader = BufferReader.asReader(buffer);
94
+ return new f(reader.readBytes(f.SIZE_IN_BYTES));
95
+ }
96
+ /**
97
+ * Returns a random field element.
98
+ */ function random(f) {
99
+ return new f(toBigIntBE(randomBytes(f.SIZE_IN_BYTES * 2)) % f.MODULUS);
100
+ }
101
+ /**
102
+ * Constructs a field from a 0x prefixed hex string.
103
+ */ function fromHexString(str, f) {
104
+ return new f(bufferFromHexString(str));
105
+ }
106
+ /**
107
+ * Constructs a field from noir BigNum type.
108
+ */ function fromNoirBigNum(bignum, f) {
109
+ // We have 120 bit (=15 byte) limbs
110
+ let bigint = 0n;
111
+ for(let i = 0; i < bignum.limbs.length; i++){
112
+ bigint += BigInt(bignum.limbs[i]) << BigInt(120 * i);
113
+ }
114
+ return new f(bigint);
115
+ }
116
+ /**
117
+ * Constructs a buffer from a hex string.
118
+ * Differs from bigint-buffer's fromHex() by allowing odd number of characters.
119
+ */ function bufferFromHexString(str) {
120
+ const withoutPrefix = str.replace(/^0x/i, '');
121
+ const checked = withoutPrefix.match(/^[0-9A-F]+$/i)?.[0];
122
+ if (checked === undefined) {
123
+ throw new Error(`Invalid hex-encoded string: "${str}"`);
124
+ }
125
+ return Buffer.from(checked.length % 2 === 1 ? '0' + checked : checked, 'hex');
126
+ }
127
+ /**
128
+ * Fr field class.
129
+ * @dev This class is used to represent elements of BLS12-381 scalar field.
130
+ */ export class BLS12Fr extends BLS12Field {
131
+ static SIZE_IN_BYTES = bls12_381.fields.Fr.BYTES;
132
+ static MODULUS = bls12_381.fields.Fr.ORDER;
133
+ static ZERO = new BLS12Fr(0n);
134
+ static ONE = new BLS12Fr(1n);
135
+ static MAX_FIELD_VALUE = new BLS12Fr(this.MODULUS - 1n);
136
+ constructor(value){
137
+ super(value);
138
+ }
139
+ [inspect.custom]() {
140
+ return `BLS12Fr<${this.toString()}>`;
141
+ }
142
+ modulus() {
143
+ return BLS12Fr.MODULUS;
144
+ }
145
+ size() {
146
+ return BLS12Fr.SIZE_IN_BYTES;
147
+ }
148
+ static random() {
149
+ return random(BLS12Fr);
150
+ }
151
+ static zero() {
152
+ return BLS12Fr.ZERO;
153
+ }
154
+ static isZero(value) {
155
+ return value.isZero();
156
+ }
157
+ static fromBuffer(buffer) {
158
+ return fromBuffer(buffer, BLS12Fr);
159
+ }
160
+ /**
161
+ * Creates a BLS12Fr instance from a string.
162
+ * @param buf - the string to create a BLS12Fr from.
163
+ * @returns the BLS12Fr instance
164
+ * @remarks if the string only consists of numbers, we assume we are parsing a bigint,
165
+ * otherwise we require the hex string to be prepended with "0x", to ensure there is no misunderstanding
166
+ * as to what is being parsed.
167
+ */ static fromString(buf) {
168
+ if (buf.match(/^\d+$/) !== null) {
169
+ return new BLS12Fr(toBufferBE(BigInt(buf), BLS12Fr.SIZE_IN_BYTES));
170
+ }
171
+ if (buf.match(/^0x/i) !== null) {
172
+ return fromHexString(buf, BLS12Fr);
173
+ }
174
+ throw new Error(`Tried to create a BLS12Fr from an invalid string: ${buf}`);
175
+ }
176
+ /**
177
+ * Creates a BLS12Fr instance from a hex string.
178
+ * @param buf - a hex encoded string.
179
+ * @returns the BLS12Fr instance
180
+ */ static fromHexString(buf) {
181
+ return fromHexString(buf, BLS12Fr);
182
+ }
183
+ /**
184
+ * Constructs a field from noir BigNum type.
185
+ */ static fromNoirBigNum(bignum) {
186
+ return fromNoirBigNum(bignum, BLS12Fr);
187
+ }
188
+ /**
189
+ * Creates a BLS12Fr instance from a BN254 Fr instance.
190
+ * @dev The BN254 field size < BLS12_381, so we cannot overflow here.
191
+ * Useful for blob related calculations.
192
+ * @param field - a BN254 Fr instance.
193
+ * @returns the BLS12Fr instance
194
+ */ static fromBN254Fr(field) {
195
+ return BLS12Fr.fromBuffer(field.toBuffer());
196
+ }
197
+ /**
198
+ * Creates a BN254 Fr instance from a BLS12Fr instance.
199
+ * @dev The BN254 field size < BLS12_381, so we must check the size here
200
+ * Useful for blob related calculations.
201
+ * @param field - a BLS12Fr instance.
202
+ * @returns the BN254 Fr instance
203
+ */ toBN254Fr() {
204
+ if (this.toBigInt() >= Fr.MODULUS) {
205
+ throw new Error(`BLS12-381 Fr field ${this} too large to be converted into a BN254 Fr field`);
206
+ }
207
+ return Fr.fromBuffer(this.toBuffer());
208
+ }
209
+ /** Arithmetic - wrapper around noble curves */ add(rhs) {
210
+ return new BLS12Fr(bls12_381.fields.Fr.add(this.toBigInt(), rhs.toBigInt()));
211
+ }
212
+ square() {
213
+ return new BLS12Fr(bls12_381.fields.Fr.sqr(this.toBigInt()));
214
+ }
215
+ negate() {
216
+ return new BLS12Fr(bls12_381.fields.Fr.neg(this.toBigInt()));
217
+ }
218
+ sub(rhs) {
219
+ return new BLS12Fr(bls12_381.fields.Fr.sub(this.toBigInt(), rhs.toBigInt()));
220
+ }
221
+ mul(rhs) {
222
+ return new BLS12Fr(bls12_381.fields.Fr.mul(this.toBigInt(), rhs.toBigInt()));
223
+ }
224
+ div(rhs) {
225
+ return new BLS12Fr(bls12_381.fields.Fr.div(this.toBigInt(), rhs.toBigInt()));
226
+ }
227
+ sqrt() {
228
+ // The noble library throws when the field does not have a sqrt.
229
+ // We would rather have it return null to avoid throwing when (e.g.) checking candidates.
230
+ let res;
231
+ try {
232
+ res = bls12_381.fields.Fr.sqrt(this.toBigInt());
233
+ } catch (error) {
234
+ if (error.message.includes('Cannot find square root')) {
235
+ return null;
236
+ } else {
237
+ throw error;
238
+ }
239
+ }
240
+ return new BLS12Fr(res);
241
+ }
242
+ pow(rhs) {
243
+ return new BLS12Fr(bls12_381.fields.Fr.pow(this.toBigInt(), rhs));
244
+ }
245
+ toJSON() {
246
+ return this.toString();
247
+ }
248
+ static get schema() {
249
+ return hexSchemaFor(BLS12Fr);
250
+ }
251
+ }
252
+ // For deserializing JSON.
253
+ TypeRegistry.register('BLS12Fr', BLS12Fr);
254
+ /**
255
+ * Fq field class.
256
+ * @dev This class is used to represent elements of BLS12-381 base field.
257
+ */ export class BLS12Fq extends BLS12Field {
258
+ static SIZE_IN_BYTES = bls12_381.fields.Fp.BYTES;
259
+ static MODULUS = bls12_381.fields.Fp.ORDER;
260
+ static ZERO = new BLS12Fq(0n);
261
+ static ONE = new BLS12Fq(1n);
262
+ static MAX_FIELD_VALUE = new BLS12Fq(this.MODULUS - 1n);
263
+ constructor(value){
264
+ super(value);
265
+ }
266
+ [inspect.custom]() {
267
+ return `BLS12Fq<${this.toString()}>`;
268
+ }
269
+ modulus() {
270
+ return BLS12Fq.MODULUS;
271
+ }
272
+ size() {
273
+ return BLS12Fq.SIZE_IN_BYTES;
274
+ }
275
+ static random() {
276
+ return random(BLS12Fq);
277
+ }
278
+ static zero() {
279
+ return BLS12Fq.ZERO;
280
+ }
281
+ static isZero(value) {
282
+ return value.isZero();
283
+ }
284
+ static fromBuffer(buffer) {
285
+ return fromBuffer(buffer, BLS12Fq);
286
+ }
287
+ /**
288
+ * Creates a BLS12Fq instance from a string.
289
+ * @param buf - the string to create a BLS12Fq from.
290
+ * @returns the BLS12Fq instance
291
+ * @remarks if the string only consists of numbers, we assume we are parsing a bigint,
292
+ * otherwise we require the hex string to be prepended with "0x", to ensure there is no misunderstanding
293
+ * as to what is being parsed.
294
+ */ static fromString(buf) {
295
+ if (buf.match(/^\d+$/) !== null) {
296
+ return new BLS12Fq(toBufferBE(BigInt(buf), BLS12Fq.SIZE_IN_BYTES));
297
+ }
298
+ if (buf.match(/^0x/i) !== null) {
299
+ return fromHexString(buf, BLS12Fq);
300
+ }
301
+ throw new Error(`Tried to create a BLS12Fq from an invalid string: ${buf}`);
302
+ }
303
+ /**
304
+ * Creates a BLS12Fq instance from a hex string.
305
+ * @param buf - a hex encoded string.
306
+ * @returns the BLS12Fq instance
307
+ */ static fromHexString(buf) {
308
+ return fromHexString(buf, BLS12Fq);
309
+ }
310
+ /**
311
+ * Constructs a field from noir BigNum type.
312
+ */ static fromNoirBigNum(bignum) {
313
+ return fromNoirBigNum(bignum, BLS12Fq);
314
+ }
315
+ /** Arithmetic - wrapper around noble curves */ add(rhs) {
316
+ return new BLS12Fq(bls12_381.fields.Fp.add(this.toBigInt(), rhs.toBigInt()));
317
+ }
318
+ square() {
319
+ return new BLS12Fq(bls12_381.fields.Fp.sqr(this.toBigInt()));
320
+ }
321
+ negate() {
322
+ return new BLS12Fq(bls12_381.fields.Fp.neg(this.toBigInt()));
323
+ }
324
+ sub(rhs) {
325
+ return new BLS12Fq(bls12_381.fields.Fp.sub(this.toBigInt(), rhs.toBigInt()));
326
+ }
327
+ mul(rhs) {
328
+ return new BLS12Fq(bls12_381.fields.Fp.mul(this.toBigInt(), rhs.toBigInt()));
329
+ }
330
+ div(rhs) {
331
+ return new BLS12Fq(bls12_381.fields.Fp.div(this.toBigInt(), rhs.toBigInt()));
332
+ }
333
+ sqrt() {
334
+ // The noble library throws when the field does not have a sqrt.
335
+ // We would rather have it return null to avoid throwing when (e.g.) checking candidates.
336
+ let res;
337
+ try {
338
+ res = bls12_381.fields.Fp.sqrt(this.toBigInt());
339
+ } catch (error) {
340
+ if (error.message.includes('Cannot find square root')) {
341
+ return null;
342
+ } else {
343
+ throw error;
344
+ }
345
+ }
346
+ return new BLS12Fq(res);
347
+ }
348
+ pow(rhs) {
349
+ return new BLS12Fq(bls12_381.fields.Fp.pow(this.toBigInt(), rhs));
350
+ }
351
+ toJSON() {
352
+ return this.toString();
353
+ }
354
+ static get schema() {
355
+ return hexSchemaFor(BLS12Fq);
356
+ }
357
+ }
358
+ // For deserializing JSON.
359
+ TypeRegistry.register('BLS12Fq', BLS12Fq);
@@ -0,0 +1,229 @@
1
+ import type { ProjPointType } from '@noble/curves/abstract/weierstrass';
2
+ import { inspect } from 'util';
3
+ import { BufferReader } from '../serialize/index.js';
4
+ import { BLS12Fq, BLS12Fr } from './bls12_fields.js';
5
+ import { Fr } from './fields.js';
6
+ /**
7
+ * Represents a Point on an elliptic curve with x and y coordinates.
8
+ * The Point class provides methods for creating instances from different input types,
9
+ * converting instances to various output formats, and checking the equality of points.
10
+ * TODO(#7386): Clean up this class.
11
+ */
12
+ export declare class BLS12Point {
13
+ /**
14
+ * The point's x coordinate
15
+ */
16
+ readonly x: BLS12Fq;
17
+ /**
18
+ * The point's y coordinate
19
+ */
20
+ readonly y: BLS12Fq;
21
+ /**
22
+ * Whether the point is at infinity
23
+ */
24
+ readonly isInfinite: boolean;
25
+ static ZERO: BLS12Point;
26
+ static ONE: BLS12Point;
27
+ static SIZE_IN_BYTES: number;
28
+ static COMPRESSED_SIZE_IN_BYTES: number;
29
+ static COMPRESSED_ZERO: Buffer<ArrayBufferLike>;
30
+ constructor(
31
+ /**
32
+ * The point's x coordinate
33
+ */
34
+ x: BLS12Fq,
35
+ /**
36
+ * The point's y coordinate
37
+ */
38
+ y: BLS12Fq,
39
+ /**
40
+ * Whether the point is at infinity
41
+ */
42
+ isInfinite: boolean);
43
+ toJSON(): `0x${string}`;
44
+ [inspect.custom](): string;
45
+ static get schema(): import("zod").ZodType<BLS12Point, any, string>;
46
+ /**
47
+ * Generate a random Point instance.
48
+ *
49
+ * @returns A randomly generated Point instance.
50
+ */
51
+ static random(): BLS12Point;
52
+ /**
53
+ * Create a Point instance from a given buffer or BufferReader.
54
+ * The input 'buffer' should have exactly 96 bytes representing the x and y coordinates.
55
+ *
56
+ * @param buffer - The buffer or BufferReader containing the x and y coordinates of the point.
57
+ * @returns A Point instance.
58
+ */
59
+ static fromBuffer(buffer: Buffer | BufferReader): BLS12Point;
60
+ /**
61
+ * Create a Point instance from a hex-encoded string.
62
+ * The input should be prefixed with '0x' or not, and have exactly 128 hex characters representing the x and y coordinates.
63
+ * Throws an error if the input length is invalid or coordinate values are out of range.
64
+ *
65
+ * @param str - The hex-encoded string representing the Point coordinates.
66
+ * @returns A Point instance.
67
+ */
68
+ static fromString(str: string): BLS12Point;
69
+ /**
70
+ * Create a compressed buffer instance from a point.
71
+ * @dev NOTE: The compression standard for BLS12-381 differs from BN curves. Instead of
72
+ * one is_positive flag, we have three flags to prepend:
73
+ * - is_compressed: indicator that the point is compressed
74
+ * - is_infinity: whether the point the point at infinity
75
+ * - is_greater: only set if is_compressed && !is_infinity && y > (p - 1)/2
76
+ * See https://github.com/arkworks-rs/algebra/blob/master/curves/bls12_381/src/curves/g1.rs -> serialize_with_mode() -> encoding
77
+ * and noble-curves/src/bls12-381.ts -> setMask()
78
+ * @dev Most of the logic below is taken from noble-curves/src/bls12-381.ts -> toBytes()
79
+ * @param point A BLS12Point instance.
80
+ * @returns The buffer containing the x coordinate and the flags of the y coordinate.
81
+ */
82
+ compress(): Buffer;
83
+ /**
84
+ * Create a Point instance from a compressed buffer.
85
+ * @dev See compress() above for compression encoding for BLS12-381.
86
+ * @dev Most of the logic below is taken from noble-curves/src/bls12-381.ts -> fromBytes()
87
+ * @param buffer - The buffer containing the x coordinate and the flags of the y coordinate.
88
+ * @returns A BLS12Point instance.
89
+ */
90
+ static decompress(buffer: Buffer): BLS12Point;
91
+ /**
92
+ * Converts a Point to two BN254 Fr elements by storing its compressed form (48 bytes) as:
93
+ * +-------------------+------------------------+
94
+ * | 31 bytes | 17 bytes |
95
+ * +-------------------+------------------------+
96
+ * | Field Element 1 | Field Element 2 |
97
+ * | [0][bytes 0-30] | [0...0][bytes 31-47] |
98
+ * +-------------------+------------------------+
99
+ * Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
100
+ * @param point - A BLS12Point instance.
101
+ * @returns The point fields.
102
+ */
103
+ toBN254Fields(): Fr[];
104
+ /**
105
+ * Creates a Point instance from 2 BN254 Fr fields as encoded in toBNFields() above.
106
+ * Used in the rollup circuits to store blob commitments in the native field type. See blob.ts.
107
+ * @param fields - The encoded BN254 fields.
108
+ * @returns The point fields.
109
+ */
110
+ static fromBN254Fields(fields: [Fr, Fr]): BLS12Point;
111
+ /**
112
+ * Creates a point from an array of 2 fields.
113
+ * @returns The point
114
+ */
115
+ static fromBLS12FqFields(fields: BLS12Fq[]): BLS12Point;
116
+ /**
117
+ * Creates a point from @noble/curves projective point definition.
118
+ * @returns The point
119
+ */
120
+ static fromNobleProjectivePoint(point: ProjPointType<bigint>): BLS12Point;
121
+ /**
122
+ * Uses the x coordinate and isPositive flag (+/-) to reconstruct the point.
123
+ * @param x - The x coordinate of the point
124
+ * @param sign - The "sign" of the y coordinate - note that this is not a sign as is known in integer arithmetic.
125
+ * Instead it is a boolean flag that determines whether the y coordinate is <= (Fr.MODULUS - 1) / 2
126
+ * @returns The point as an array of 2 fields
127
+ */
128
+ static fromXAndSign(x: BLS12Fq, sign: boolean): BLS12Point;
129
+ /**
130
+ * @param x - The x coordinate of the point
131
+ * @returns y^2 such that y^2 = x^3 + 4
132
+ */
133
+ static YSquaredFromX(x: BLS12Fq): BLS12Fq;
134
+ /**
135
+ * @param x - The x coordinate of the point
136
+ * @returns The y coordinate of the point, if it exists on BLS12-381
137
+ */
138
+ static YFromX(x: BLS12Fq): BLS12Fq | null;
139
+ /**
140
+ * @param x - The x coordinate of the point
141
+ * @param y - The y coordinate of the point
142
+ * @returns Whether the point exists on BLS12-381
143
+ */
144
+ static isOnCurve(x: BLS12Fq, y: BLS12Fq): boolean;
145
+ /**
146
+ * Returns the contents of the point as an array of 2 fields.
147
+ * @returns The point as an array of 2 fields
148
+ */
149
+ toBLS12FqFields(): BLS12Fq[];
150
+ /**
151
+ * Returns the x coordinate and the sign of the y coordinate.
152
+ * @dev The y sign can be determined by checking if the y coordinate is greater than half of the modulus.
153
+ * @returns The x coordinate and the sign of the y coordinate.
154
+ */
155
+ toXAndSign(): [BLS12Fq, boolean];
156
+ /**
157
+ * Returns the contents of the point as BigInts.
158
+ * @returns The point as BigInts
159
+ */
160
+ toBigInts(): {
161
+ x: bigint;
162
+ y: bigint;
163
+ isInfinite: bigint;
164
+ };
165
+ /**
166
+ * Converts the Point instance to a Buffer representation of the coordinates.
167
+ * @returns A Buffer representation of the Point instance.
168
+ * @dev Note that toBuffer does not include the isInfinite flag and other serialization methods do (e.g. toBigInts).
169
+ */
170
+ toBuffer(): Buffer<ArrayBufferLike>;
171
+ /**
172
+ * Convert the Point instance to a hexadecimal string representation.
173
+ * The output string is prefixed with '0x' and consists of exactly 128 hex characters,
174
+ * representing the concatenated x and y coordinates of the point.
175
+ *
176
+ * @returns A hex-encoded string representing the Point instance.
177
+ */
178
+ toString(): `0x${string}`;
179
+ /**
180
+ * Check if two Point instances are equal by comparing their buffer values.
181
+ * Returns true if the buffer values are the same, and false otherwise.
182
+ *
183
+ * @param rhs - The Point instance to compare with the current instance.
184
+ * @returns A boolean indicating whether the two Point instances are equal.
185
+ */
186
+ equals(rhs: BLS12Point): boolean;
187
+ /**
188
+ * Check whether the point is zero.
189
+ */
190
+ isZero(): boolean;
191
+ /**
192
+ * Check if this is point at infinity.
193
+ * Check this is consistent with how bb is encoding the point at infinity
194
+ */
195
+ get inf(): boolean;
196
+ /** Arithmetic - wrapper around noble curves */
197
+ toNobleProjectivePoint(): ProjPointType<bigint>;
198
+ add(rhs: BLS12Point): BLS12Point;
199
+ negate(): BLS12Point;
200
+ sub(rhs: BLS12Point): BLS12Point;
201
+ /**
202
+ * @dev From noble curves package:
203
+ * Constant time multiplication. Uses wNAF method. Windowed method may be 10% faster,
204
+ * but takes 2x longer to generate and consumes 2x memory.
205
+ * Uses precomputes when available, uses endomorphism for Koblitz curves.
206
+ * @param scalar by which the point would be multiplied
207
+ * @returns New point
208
+ */
209
+ mul(rhs: BLS12Fr): BLS12Point;
210
+ /**
211
+ * @dev From noble curves package:
212
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
213
+ * It's faster, but should only be used when you don't care about an exposed private key e.g. sig verification, which works over *public* keys.
214
+ * @param scalar by which the point would be multiplied
215
+ * @returns New point
216
+ */
217
+ mulUnsafe(rhs: BLS12Fr): BLS12Point;
218
+ /**
219
+ * @dev From noble curves package:
220
+ * Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
221
+ * Not using Strauss-Shamir trick: precomputation tables are faster. The trick could be useful if both P and Q are not G (not in our case).
222
+ * @returns affine point
223
+ */
224
+ mulAndAddUnsafe(a: BLS12Fr, b: BLS12Fr, Q: BLS12Point): BLS12Point;
225
+ }
226
+ export declare class BLSPointNotOnCurveError extends Error {
227
+ constructor(x: BLS12Fq, y?: BLS12Fq);
228
+ }
229
+ //# sourceMappingURL=bls12_point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bls12_point.d.ts","sourceRoot":"","sources":["../../src/fields/bls12_point.ts"],"names":[],"mappings":"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"}