@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,26 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import { Fr } from '../../../fields/fields.js';
4
+ import { type Fieldable } from '../../../serialize/serialize.js';
5
+ /**
6
+ * Create a poseidon hash (field) from an array of input fields.
7
+ * @param input - The input fields to hash.
8
+ * @returns The poseidon hash.
9
+ */
10
+ export declare function poseidon2Hash(input: Fieldable[]): Fr;
11
+ /**
12
+ * Create a poseidon hash (field) from an array of input fields and a domain separator.
13
+ * @param input - The input fields to hash.
14
+ * @param separator - The domain separator.
15
+ * @returns The poseidon hash.
16
+ */
17
+ export declare function poseidon2HashWithSeparator(input: Fieldable[], separator: number): Fr;
18
+ export declare function poseidon2HashAccumulate(input: Fieldable[]): Fr;
19
+ /**
20
+ * Runs a Poseidon2 permutation.
21
+ * @param input the input state. Expected to be of size 4.
22
+ * @returns the output state, size 4.
23
+ */
24
+ export declare function poseidon2Permutation(input: Fieldable[]): Fr[];
25
+ export declare function poseidon2HashBytes(input: Buffer): Fr;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/crypto/sync/poseidon/index.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,KAAK,SAAS,EAAqB,MAAM,iCAAiC,CAAC;AAEpF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAMpD;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,EAAE,CAQpF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAM9D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,CAU7D;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,EAAE,CAgBpD"}
@@ -0,0 +1,53 @@
1
+ import { BarretenbergSync, Fr as FrBarretenberg } from '@aztec/bb.js';
2
+ import { Fr } from '../../../fields/fields.js';
3
+ import { serializeToFields } from '../../../serialize/serialize.js';
4
+ /**
5
+ * Create a poseidon hash (field) from an array of input fields.
6
+ * @param input - The input fields to hash.
7
+ * @returns The poseidon hash.
8
+ */ export function poseidon2Hash(input) {
9
+ const inputFields = serializeToFields(input);
10
+ const hash = BarretenbergSync.getSingleton().poseidon2Hash(inputFields.map((i)=>new FrBarretenberg(i.toBuffer())));
11
+ return Fr.fromBuffer(Buffer.from(hash.toBuffer()));
12
+ }
13
+ /**
14
+ * Create a poseidon hash (field) from an array of input fields and a domain separator.
15
+ * @param input - The input fields to hash.
16
+ * @param separator - The domain separator.
17
+ * @returns The poseidon hash.
18
+ */ export function poseidon2HashWithSeparator(input, separator) {
19
+ const inputFields = serializeToFields(input);
20
+ inputFields.unshift(new Fr(separator));
21
+ const hash = BarretenbergSync.getSingleton().poseidon2Hash(inputFields.map((i)=>new FrBarretenberg(i.toBuffer())));
22
+ return Fr.fromBuffer(Buffer.from(hash.toBuffer()));
23
+ }
24
+ export function poseidon2HashAccumulate(input) {
25
+ const inputFields = serializeToFields(input);
26
+ const result = BarretenbergSync.getSingleton().poseidon2HashAccumulate(inputFields.map((i)=>new FrBarretenberg(i.toBuffer())));
27
+ return Fr.fromBuffer(Buffer.from(result.toBuffer()));
28
+ }
29
+ /**
30
+ * Runs a Poseidon2 permutation.
31
+ * @param input the input state. Expected to be of size 4.
32
+ * @returns the output state, size 4.
33
+ */ export function poseidon2Permutation(input) {
34
+ const inputFields = serializeToFields(input);
35
+ // We'd like this assertion but it's not possible to use it in the browser.
36
+ // assert(input.length === 4, 'Input state must be of size 4');
37
+ const res = BarretenbergSync.getSingleton().poseidon2Permutation(inputFields.map((i)=>new FrBarretenberg(i.toBuffer())));
38
+ // We'd like this assertion but it's not possible to use it in the browser.
39
+ // assert(res.length === 4, 'Output state must be of size 4');
40
+ return res.map((o)=>Fr.fromBuffer(Buffer.from(o.toBuffer())));
41
+ }
42
+ export function poseidon2HashBytes(input) {
43
+ const inputFields = [];
44
+ for(let i = 0; i < input.length; i += 31){
45
+ const fieldBytes = Buffer.alloc(32, 0);
46
+ input.slice(i, i + 31).copy(fieldBytes);
47
+ // Noir builds the bytes as little-endian, so we need to reverse them.
48
+ fieldBytes.reverse();
49
+ inputFields.push(Fr.fromBuffer(fieldBytes));
50
+ }
51
+ const res = BarretenbergSync.getSingleton().poseidon2Hash(inputFields.map((i)=>new FrBarretenberg(i.toBuffer())));
52
+ return Fr.fromBuffer(Buffer.from(res.toBuffer()));
53
+ }
@@ -0,0 +1,2 @@
1
+ export * from './memoize.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './memoize.js';
@@ -0,0 +1,2 @@
1
+ export declare function memoize<This extends object, Result>(fn: () => Result, context: ClassMethodDecoratorContext): (this: This) => Result;
2
+ //# sourceMappingURL=memoize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/decorators/memoize.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,IAAI,SAAS,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,MAAM,EAAE,OAAO,EAAE,2BAA2B,UAClF,IAAI,YAS5B"}
@@ -0,0 +1,11 @@
1
+ export function memoize(fn, context) {
2
+ return function() {
3
+ const key = `__${String(context.name)}_value`;
4
+ const thisWithKey = this;
5
+ if (!(key in this)) {
6
+ const result = fn.call(this);
7
+ thisWithKey[key] = result;
8
+ }
9
+ return thisWithKey[key];
10
+ };
11
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Represents an error thrown when an operation is interrupted unexpectedly.
3
+ * This custom error class extends the built-in Error class in JavaScript and
4
+ * can be used to handle cases where a process or task is terminated before completion.
5
+ */
6
+ export declare class InterruptError extends Error {
7
+ readonly name = "InterruptError";
8
+ }
9
+ /**
10
+ * An error thrown when an action times out.
11
+ */
12
+ export declare class TimeoutError extends Error {
13
+ readonly name = "TimeoutError";
14
+ }
15
+ /**
16
+ * Represents an error thrown when an operation is aborted.
17
+ */
18
+ export declare class AbortError extends Error {
19
+ readonly name = "AbortError";
20
+ }
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAyB,IAAI,oBAAoB;CAClD;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAyB,IAAI,kBAAkB;CAChD;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAyB,IAAI,gBAAgB;CAC9C"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Represents an error thrown when an operation is interrupted unexpectedly.
3
+ * This custom error class extends the built-in Error class in JavaScript and
4
+ * can be used to handle cases where a process or task is terminated before completion.
5
+ */ export class InterruptError extends Error {
6
+ name = 'InterruptError';
7
+ }
8
+ /**
9
+ * An error thrown when an action times out.
10
+ */ export class TimeoutError extends Error {
11
+ name = 'TimeoutError';
12
+ }
13
+ /**
14
+ * Represents an error thrown when an operation is aborted.
15
+ */ export class AbortError extends Error {
16
+ name = 'AbortError';
17
+ }
@@ -0,0 +1,134 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ /// <reference types="node" resolution-mode="require"/>
4
+ import { inspect } from 'util';
5
+ import { Fr } from '../fields/index.js';
6
+ import { BufferReader, FieldReader } from '../serialize/index.js';
7
+ /**
8
+ * Represents an Ethereum address as a 20-byte buffer and provides various utility methods
9
+ * for converting between different representations, generating random addresses, validating
10
+ * checksums, and comparing addresses. EthAddress can be instantiated using a buffer or string,
11
+ * and can be serialized/deserialized from a buffer or BufferReader.
12
+ */
13
+ export declare class EthAddress {
14
+ private buffer;
15
+ /** The size of an Ethereum address in bytes. */
16
+ static SIZE_IN_BYTES: number;
17
+ /** Represents a zero Ethereum address with 20 bytes filled with zeros. */
18
+ static ZERO: EthAddress;
19
+ constructor(buffer: Buffer);
20
+ /**
21
+ * Creates an EthAddress instance from a valid Ethereum address string.
22
+ * The input 'address' can be either in checksum format or lowercase, and it can be prefixed with '0x'.
23
+ * Throws an error if the input is not a valid Ethereum address.
24
+ *
25
+ * @param address - The string representing the Ethereum address.
26
+ * @returns An EthAddress instance.
27
+ */
28
+ static fromString(address: string): EthAddress;
29
+ /**
30
+ * Create a random EthAddress instance with 20 random bytes.
31
+ * This method generates a new Ethereum address with a randomly generated set of 20 bytes.
32
+ * It is useful for generating test addresses or unique identifiers.
33
+ *
34
+ * @returns A randomly generated EthAddress instance.
35
+ */
36
+ static random(): EthAddress;
37
+ /**
38
+ * Determines if the given string represents a valid Ethereum address.
39
+ * A valid address should meet the following criteria:
40
+ * 1. Contains exactly 40 hex characters (excluding an optional '0x' prefix).
41
+ * 2. Is either all lowercase, all uppercase, or has a valid checksum based on EIP-55.
42
+ *
43
+ * @param address - The string to be checked for validity as an Ethereum address.
44
+ * @returns True if the input string represents a valid Ethereum address, false otherwise.
45
+ */
46
+ static isAddress(address: string): boolean;
47
+ /**
48
+ * Checks if the EthAddress instance represents a zero address.
49
+ * A zero address consists of 20 bytes filled with zeros and is considered an invalid address.
50
+ *
51
+ * @returns A boolean indicating whether the EthAddress instance is a zero address or not.
52
+ */
53
+ isZero(): boolean;
54
+ /**
55
+ * Checks if the given Ethereum address has a valid checksum.
56
+ * The input 'address' should be prefixed with '0x' or not, and have exactly 40 hex characters.
57
+ * Returns true if the address has a valid checksum, false otherwise.
58
+ *
59
+ * @param address - The hex-encoded string representing the Ethereum address.
60
+ * @returns A boolean value indicating whether the address has a valid checksum.
61
+ */
62
+ static checkAddressChecksum(address: string): boolean;
63
+ /**
64
+ * Converts an Ethereum address to its checksum format.
65
+ * The input 'address' should be prefixed with '0x' or not, and have exactly 40 hex characters.
66
+ * The checksum format is created by capitalizing certain characters in the hex string
67
+ * based on the hash of the lowercase address.
68
+ * Throws an error if the input address is invalid.
69
+ *
70
+ * @param address - The Ethereum address as a hex-encoded string.
71
+ * @returns The Ethereum address in its checksum format.
72
+ */
73
+ static toChecksumAddress(address: string): string;
74
+ /**
75
+ * Checks whether the given EthAddress instance is equal to the current instance.
76
+ * Equality is determined by comparing the underlying byte buffers of both instances.
77
+ *
78
+ * @param rhs - The EthAddress instance to compare with the current instance.
79
+ * @returns A boolean value indicating whether the two instances are equal (true) or not (false).
80
+ */
81
+ equals(rhs: EthAddress): boolean;
82
+ /**
83
+ * Converts the Ethereum address to a hex-encoded string.
84
+ * The resulting string is prefixed with '0x' and has exactly 40 hex characters.
85
+ * This method can be used to represent the EthAddress instance in the widely used hexadecimal format.
86
+ *
87
+ * @returns A hex-encoded string representation of the Ethereum address.
88
+ */
89
+ toString(): `0x${string}`;
90
+ [inspect.custom](): string;
91
+ /**
92
+ * Returns the Ethereum address as a checksummed string.
93
+ * The output string will have characters in the correct upper or lowercase form, according to EIP-55.
94
+ * This provides a way to verify if an address is typed correctly, by checking the character casing.
95
+ *
96
+ * @returns A checksummed Ethereum address string.
97
+ */
98
+ toChecksumString(): string;
99
+ /**
100
+ * Returns a 20-byte buffer representation of the Ethereum address.
101
+ * @returns A 20-byte Buffer containing the Ethereum address.
102
+ */
103
+ toBuffer(): Buffer;
104
+ /**
105
+ * Returns a 32-byte buffer representation of the Ethereum address, with the original 20-byte address
106
+ * occupying the last 20 bytes and the first 12 bytes being zero-filled.
107
+ * This format is commonly used in smart contracts when handling addresses as 32-byte values.
108
+ *
109
+ * @returns A 32-byte Buffer containing the padded Ethereum address.
110
+ */
111
+ toBuffer32(): Buffer;
112
+ /**
113
+ * Returns a new field with the same contents as this EthAddress.
114
+ *
115
+ * @returns An Fr instance.
116
+ */
117
+ toField(): Fr;
118
+ /**
119
+ * Converts a field to a eth address.
120
+ * @param fr - The field to convert.
121
+ * @returns The eth address.
122
+ */
123
+ static fromField(fr: Fr): EthAddress;
124
+ static fromFields(fields: Fr[] | FieldReader): EthAddress;
125
+ /**
126
+ * Deserializes from a buffer or reader, corresponding to a write in cpp.
127
+ * @param buffer - Buffer to read from.
128
+ * @returns The EthAddress.
129
+ */
130
+ static fromBuffer(buffer: Buffer | BufferReader): EthAddress;
131
+ toJSON(): `0x${string}`;
132
+ static get schema(): import("zod").ZodType<EthAddress, any, string>;
133
+ }
134
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/eth-address/index.ts"],"names":[],"mappings":";;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAI/B,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIlE;;;;;GAKG;AACH,qBAAa,UAAU;IAMT,OAAO,CAAC,MAAM;IAL1B,gDAAgD;IAChD,OAAc,aAAa,SAAM;IACjC,0EAA0E;IAC1E,OAAc,IAAI,aAA0D;gBAExD,MAAM,EAAE,MAAM;IAMlC;;;;;;;OAOG;WACW,UAAU,CAAC,OAAO,EAAE,MAAM;IAOxC;;;;;;OAMG;WACW,MAAM;IAIpB;;;;;;;;OAQG;WACW,SAAS,CAAC,OAAO,EAAE,MAAM;IAYvC;;;;;OAKG;IACI,MAAM;IAIb;;;;;;;OAOG;WACW,oBAAoB,CAAC,OAAO,EAAE,MAAM;IAgBlD;;;;;;;;;OASG;WACW,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAoB/C;;;;;;OAMG;IACI,MAAM,CAAC,GAAG,EAAE,UAAU;IAI7B;;;;;;OAMG;IACI,QAAQ;IAIf,CAAC,OAAO,CAAC,MAAM,CAAC;IAIhB;;;;;;OAMG;IACI,gBAAgB;IAIvB;;;OAGG;IACI,QAAQ;IAIf;;;;;;OAMG;IACI,UAAU;IAMjB;;;;OAIG;IACI,OAAO;IAId;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,UAAU;IAIpC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW;IAK5C;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,UAAU;IAK5D,MAAM;IAIN,MAAM,KAAK,MAAM,mDAEhB;CACF"}
@@ -0,0 +1,198 @@
1
+ import { inspect } from 'util';
2
+ import { keccak256String } from '../crypto/keccak/index.js';
3
+ import { randomBytes } from '../crypto/random/index.js';
4
+ import { Fr } from '../fields/index.js';
5
+ import { hexSchemaFor } from '../schemas/utils.js';
6
+ import { BufferReader, FieldReader } from '../serialize/index.js';
7
+ import { TypeRegistry } from '../serialize/type_registry.js';
8
+ import { bufferToHex } from '../string/index.js';
9
+ /**
10
+ * Represents an Ethereum address as a 20-byte buffer and provides various utility methods
11
+ * for converting between different representations, generating random addresses, validating
12
+ * checksums, and comparing addresses. EthAddress can be instantiated using a buffer or string,
13
+ * and can be serialized/deserialized from a buffer or BufferReader.
14
+ */ export class EthAddress {
15
+ buffer;
16
+ /** The size of an Ethereum address in bytes. */ static SIZE_IN_BYTES = 20;
17
+ /** Represents a zero Ethereum address with 20 bytes filled with zeros. */ static ZERO = new EthAddress(Buffer.alloc(EthAddress.SIZE_IN_BYTES));
18
+ constructor(buffer){
19
+ this.buffer = buffer;
20
+ if (buffer.length !== EthAddress.SIZE_IN_BYTES) {
21
+ throw new Error(`Expect buffer size to be ${EthAddress.SIZE_IN_BYTES}. Got ${buffer.length}.`);
22
+ }
23
+ }
24
+ /**
25
+ * Creates an EthAddress instance from a valid Ethereum address string.
26
+ * The input 'address' can be either in checksum format or lowercase, and it can be prefixed with '0x'.
27
+ * Throws an error if the input is not a valid Ethereum address.
28
+ *
29
+ * @param address - The string representing the Ethereum address.
30
+ * @returns An EthAddress instance.
31
+ */ static fromString(address) {
32
+ if (!EthAddress.isAddress(address)) {
33
+ throw new Error(`Invalid address string: ${address}`);
34
+ }
35
+ return new EthAddress(Buffer.from(address.replace(/^0x/i, ''), 'hex'));
36
+ }
37
+ /**
38
+ * Create a random EthAddress instance with 20 random bytes.
39
+ * This method generates a new Ethereum address with a randomly generated set of 20 bytes.
40
+ * It is useful for generating test addresses or unique identifiers.
41
+ *
42
+ * @returns A randomly generated EthAddress instance.
43
+ */ static random() {
44
+ return new EthAddress(randomBytes(20));
45
+ }
46
+ /**
47
+ * Determines if the given string represents a valid Ethereum address.
48
+ * A valid address should meet the following criteria:
49
+ * 1. Contains exactly 40 hex characters (excluding an optional '0x' prefix).
50
+ * 2. Is either all lowercase, all uppercase, or has a valid checksum based on EIP-55.
51
+ *
52
+ * @param address - The string to be checked for validity as an Ethereum address.
53
+ * @returns True if the input string represents a valid Ethereum address, false otherwise.
54
+ */ static isAddress(address) {
55
+ if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
56
+ // Does not have the basic requirements of an address.
57
+ return false;
58
+ } else if (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address)) {
59
+ // It's ALL lowercase or ALL uppercase.
60
+ return true;
61
+ } else {
62
+ return EthAddress.checkAddressChecksum(address);
63
+ }
64
+ }
65
+ /**
66
+ * Checks if the EthAddress instance represents a zero address.
67
+ * A zero address consists of 20 bytes filled with zeros and is considered an invalid address.
68
+ *
69
+ * @returns A boolean indicating whether the EthAddress instance is a zero address or not.
70
+ */ isZero() {
71
+ return this.equals(EthAddress.ZERO);
72
+ }
73
+ /**
74
+ * Checks if the given Ethereum address has a valid checksum.
75
+ * The input 'address' should be prefixed with '0x' or not, and have exactly 40 hex characters.
76
+ * Returns true if the address has a valid checksum, false otherwise.
77
+ *
78
+ * @param address - The hex-encoded string representing the Ethereum address.
79
+ * @returns A boolean value indicating whether the address has a valid checksum.
80
+ */ static checkAddressChecksum(address) {
81
+ address = address.replace(/^0x/i, '');
82
+ const addressHash = keccak256String(address.toLowerCase());
83
+ for(let i = 0; i < 40; i++){
84
+ // The nth letter should be uppercase if the nth digit of casemap is 1.
85
+ if (parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i] || parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i]) {
86
+ return false;
87
+ }
88
+ }
89
+ return true;
90
+ }
91
+ /**
92
+ * Converts an Ethereum address to its checksum format.
93
+ * The input 'address' should be prefixed with '0x' or not, and have exactly 40 hex characters.
94
+ * The checksum format is created by capitalizing certain characters in the hex string
95
+ * based on the hash of the lowercase address.
96
+ * Throws an error if the input address is invalid.
97
+ *
98
+ * @param address - The Ethereum address as a hex-encoded string.
99
+ * @returns The Ethereum address in its checksum format.
100
+ */ static toChecksumAddress(address) {
101
+ if (!EthAddress.isAddress(address)) {
102
+ throw new Error('Invalid address string.');
103
+ }
104
+ address = address.toLowerCase().replace(/^0x/i, '');
105
+ const addressHash = keccak256String(address);
106
+ let checksumAddress = '0x';
107
+ for(let i = 0; i < address.length; i++){
108
+ // If ith character is 9 to f then make it uppercase.
109
+ if (parseInt(addressHash[i], 16) > 7) {
110
+ checksumAddress += address[i].toUpperCase();
111
+ } else {
112
+ checksumAddress += address[i];
113
+ }
114
+ }
115
+ return checksumAddress;
116
+ }
117
+ /**
118
+ * Checks whether the given EthAddress instance is equal to the current instance.
119
+ * Equality is determined by comparing the underlying byte buffers of both instances.
120
+ *
121
+ * @param rhs - The EthAddress instance to compare with the current instance.
122
+ * @returns A boolean value indicating whether the two instances are equal (true) or not (false).
123
+ */ equals(rhs) {
124
+ return this.buffer.equals(rhs.buffer);
125
+ }
126
+ /**
127
+ * Converts the Ethereum address to a hex-encoded string.
128
+ * The resulting string is prefixed with '0x' and has exactly 40 hex characters.
129
+ * This method can be used to represent the EthAddress instance in the widely used hexadecimal format.
130
+ *
131
+ * @returns A hex-encoded string representation of the Ethereum address.
132
+ */ toString() {
133
+ return bufferToHex(this.buffer);
134
+ }
135
+ [inspect.custom]() {
136
+ return `EthAddress<${this.toString()}>`;
137
+ }
138
+ /**
139
+ * Returns the Ethereum address as a checksummed string.
140
+ * The output string will have characters in the correct upper or lowercase form, according to EIP-55.
141
+ * This provides a way to verify if an address is typed correctly, by checking the character casing.
142
+ *
143
+ * @returns A checksummed Ethereum address string.
144
+ */ toChecksumString() {
145
+ return EthAddress.toChecksumAddress(this.buffer.toString('hex'));
146
+ }
147
+ /**
148
+ * Returns a 20-byte buffer representation of the Ethereum address.
149
+ * @returns A 20-byte Buffer containing the Ethereum address.
150
+ */ toBuffer() {
151
+ return this.buffer;
152
+ }
153
+ /**
154
+ * Returns a 32-byte buffer representation of the Ethereum address, with the original 20-byte address
155
+ * occupying the last 20 bytes and the first 12 bytes being zero-filled.
156
+ * This format is commonly used in smart contracts when handling addresses as 32-byte values.
157
+ *
158
+ * @returns A 32-byte Buffer containing the padded Ethereum address.
159
+ */ toBuffer32() {
160
+ const buffer = Buffer.alloc(32);
161
+ this.buffer.copy(buffer, 12);
162
+ return buffer;
163
+ }
164
+ /**
165
+ * Returns a new field with the same contents as this EthAddress.
166
+ *
167
+ * @returns An Fr instance.
168
+ */ toField() {
169
+ return Fr.fromBuffer(this.toBuffer32());
170
+ }
171
+ /**
172
+ * Converts a field to a eth address.
173
+ * @param fr - The field to convert.
174
+ * @returns The eth address.
175
+ */ static fromField(fr) {
176
+ return new EthAddress(fr.toBuffer().slice(-EthAddress.SIZE_IN_BYTES));
177
+ }
178
+ static fromFields(fields) {
179
+ const reader = FieldReader.asReader(fields);
180
+ return EthAddress.fromField(reader.readField());
181
+ }
182
+ /**
183
+ * Deserializes from a buffer or reader, corresponding to a write in cpp.
184
+ * @param buffer - Buffer to read from.
185
+ * @returns The EthAddress.
186
+ */ static fromBuffer(buffer) {
187
+ const reader = BufferReader.asReader(buffer);
188
+ return new EthAddress(reader.readBytes(EthAddress.SIZE_IN_BYTES));
189
+ }
190
+ toJSON() {
191
+ return this.toString();
192
+ }
193
+ static get schema() {
194
+ return hexSchemaFor(EthAddress, EthAddress.isAddress);
195
+ }
196
+ }
197
+ // For deserializing JSON.
198
+ TypeRegistry.register('EthAddress', EthAddress);
@@ -0,0 +1,62 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import { Buffer32 } from '@aztec/foundation/buffer';
4
+ import { BufferReader } from '@aztec/foundation/serialize';
5
+ import { z } from 'zod';
6
+ /**Viem Signature
7
+ *
8
+ * A version of the Signature class that uses `0x${string}` values for r and s rather than
9
+ * Buffer32s
10
+ */
11
+ export type ViemSignature = {
12
+ r: `0x${string}`;
13
+ s: `0x${string}`;
14
+ v: number;
15
+ isEmpty: boolean;
16
+ };
17
+ /**
18
+ * Signature
19
+ *
20
+ * Contains a signature split into it's primary components (r,s,v)
21
+ */
22
+ export declare class Signature {
23
+ /** The r value of the signature */
24
+ readonly r: Buffer32;
25
+ /** The s value of the signature */
26
+ readonly s: Buffer32;
27
+ /** The v value of the signature */
28
+ readonly v: number;
29
+ /** Does this struct store an empty signature */
30
+ readonly isEmpty: boolean;
31
+ private size;
32
+ constructor(
33
+ /** The r value of the signature */
34
+ r: Buffer32,
35
+ /** The s value of the signature */
36
+ s: Buffer32,
37
+ /** The v value of the signature */
38
+ v: number,
39
+ /** Does this struct store an empty signature */
40
+ isEmpty?: boolean);
41
+ static fromBuffer(buf: Buffer | BufferReader): Signature;
42
+ static isValidString(sig: `0x${string}`): boolean;
43
+ /**
44
+ * A seperate method exists for this as when signing locally with viem, as when
45
+ * parsing from viem, we can expect the v value to be a u8, rather than our
46
+ * default serialization of u32
47
+ */
48
+ static fromString(sig: `0x${string}`): Signature;
49
+ static random(): Signature;
50
+ static empty(): Signature;
51
+ equals(other: Signature): boolean;
52
+ toBuffer(): Buffer;
53
+ getSize(): number;
54
+ toString(): `0x${string}`;
55
+ /**
56
+ * Return the signature with `0x${string}` encodings for r and s
57
+ */
58
+ toViemSignature(): ViemSignature;
59
+ toJSON(): `0x${string}`;
60
+ static get schema(): z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>, Signature, string>;
61
+ }
62
+ //# sourceMappingURL=eth_signature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eth_signature.d.ts","sourceRoot":"","sources":["../../src/eth-signature/eth_signature.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IACjB,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,SAAS;IAKlB,mCAAmC;aACnB,CAAC,EAAE,QAAQ;IAC3B,mCAAmC;aACnB,CAAC,EAAE,QAAQ;IAC3B,mCAAmC;aACnB,CAAC,EAAE,MAAM;IACzB,gDAAgD;aAChC,OAAO,EAAE,OAAO;IAVlC,OAAO,CAAC,IAAI,CAAqB;;IAG/B,mCAAmC;IACnB,CAAC,EAAE,QAAQ;IAC3B,mCAAmC;IACnB,CAAC,EAAE,QAAQ;IAC3B,mCAAmC;IACnB,CAAC,EAAE,MAAM;IACzB,gDAAgD;IAChC,OAAO,GAAE,OAAe;IAG1C,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAYxD,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO;IAIjD;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,SAAS;IAYhD,MAAM,CAAC,MAAM,IAAI,SAAS;IAI1B,MAAM,CAAC,KAAK,IAAI,SAAS;IAIzB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IAIjC,QAAQ,IAAI,MAAM;IAMlB,OAAO,IAAI,MAAM;IAUjB,QAAQ,IAAI,KAAK,MAAM,EAAE;IAIzB;;OAEG;IACH,eAAe,IAAI,aAAa;IAShC,MAAM;IAIN,MAAM,KAAK,MAAM,2HAMhB;CACF"}
@@ -0,0 +1,91 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
+ import { z } from 'zod';
4
+ import { hasHexPrefix, hexToBuffer } from '../string/index.js';
5
+ /**
6
+ * Signature
7
+ *
8
+ * Contains a signature split into it's primary components (r,s,v)
9
+ */ export class Signature {
10
+ r;
11
+ s;
12
+ v;
13
+ isEmpty;
14
+ // Cached values
15
+ size;
16
+ constructor(/** The r value of the signature */ r, /** The s value of the signature */ s, /** The v value of the signature */ v, /** Does this struct store an empty signature */ isEmpty = false){
17
+ this.r = r;
18
+ this.s = s;
19
+ this.v = v;
20
+ this.isEmpty = isEmpty;
21
+ }
22
+ static fromBuffer(buf) {
23
+ const reader = BufferReader.asReader(buf);
24
+ const r = reader.readObject(Buffer32);
25
+ const s = reader.readObject(Buffer32);
26
+ const v = reader.readNumber();
27
+ const isEmpty = r.isZero() && s.isZero();
28
+ return new Signature(r, s, v, isEmpty);
29
+ }
30
+ static isValidString(sig) {
31
+ return /^0x[0-9a-f]{129,}$/i.test(sig);
32
+ }
33
+ /**
34
+ * A seperate method exists for this as when signing locally with viem, as when
35
+ * parsing from viem, we can expect the v value to be a u8, rather than our
36
+ * default serialization of u32
37
+ */ static fromString(sig) {
38
+ const buf = hexToBuffer(sig);
39
+ const reader = BufferReader.asReader(buf);
40
+ const r = reader.readObject(Buffer32);
41
+ const s = reader.readObject(Buffer32);
42
+ const v = parseInt(sig.slice(2 + 64 * 2), 16);
43
+ const isEmpty = r.isZero() && s.isZero();
44
+ return new Signature(r, s, v, isEmpty);
45
+ }
46
+ static random() {
47
+ return new Signature(Buffer32.random(), Buffer32.random(), Math.floor(Math.random() * 2), false);
48
+ }
49
+ static empty() {
50
+ return new Signature(Buffer32.ZERO, Buffer32.ZERO, 0, true);
51
+ }
52
+ equals(other) {
53
+ return this.r.equals(other.r) && this.s.equals(other.s) && this.v === other.v && this.isEmpty === other.isEmpty;
54
+ }
55
+ toBuffer() {
56
+ const buffer = serializeToBuffer([
57
+ this.r,
58
+ this.s,
59
+ this.v
60
+ ]);
61
+ this.size = buffer.length;
62
+ return buffer;
63
+ }
64
+ getSize() {
65
+ // We cache size to avoid recalculating it
66
+ if (this.size) {
67
+ return this.size;
68
+ }
69
+ this.size = this.toBuffer().length;
70
+ return this.size;
71
+ }
72
+ toString() {
73
+ return `0x${this.r.buffer.toString('hex')}${this.s.buffer.toString('hex')}${this.v.toString(16)}`;
74
+ }
75
+ /**
76
+ * Return the signature with `0x${string}` encodings for r and s
77
+ */ toViemSignature() {
78
+ return {
79
+ r: this.r.toString(),
80
+ s: this.s.toString(),
81
+ v: this.v,
82
+ isEmpty: this.isEmpty
83
+ };
84
+ }
85
+ toJSON() {
86
+ return this.toString();
87
+ }
88
+ static get schema() {
89
+ return z.string().refine(hasHexPrefix, 'No hex prefix').refine(Signature.isValidString, 'Not a valid Ethereum signature').transform(Signature.fromString);
90
+ }
91
+ }
@@ -0,0 +1,2 @@
1
+ export * from './eth_signature.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/eth-signature/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './eth_signature.js';