@aztec/foundation 0.76.4 → 0.77.0-testnet-ignition.21

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 (459) hide show
  1. package/dest/array/array.d.ts +1 -1
  2. package/dest/array/array.d.ts.map +1 -1
  3. package/dest/array/array.js +19 -26
  4. package/dest/array/index.js +0 -1
  5. package/dest/async-map/index.js +2 -4
  6. package/dest/async-pool/index.js +6 -9
  7. package/dest/bigint-buffer/index.js +6 -13
  8. package/dest/buffer/buffer32.d.ts +1 -1
  9. package/dest/buffer/buffer32.d.ts.map +1 -1
  10. package/dest/buffer/buffer32.js +53 -66
  11. package/dest/buffer/index.js +0 -1
  12. package/dest/collection/array.d.ts +1 -1
  13. package/dest/collection/array.d.ts.map +1 -1
  14. package/dest/collection/array.js +47 -59
  15. package/dest/collection/index.js +0 -1
  16. package/dest/collection/object.js +9 -9
  17. package/dest/committable/committable.js +15 -20
  18. package/dest/committable/index.js +0 -1
  19. package/dest/config/env_var.d.ts +1 -1
  20. package/dest/config/env_var.d.ts.map +1 -1
  21. package/dest/config/env_var.js +1 -2
  22. package/dest/config/index.d.ts +1 -1
  23. package/dest/config/index.d.ts.map +1 -1
  24. package/dest/config/index.js +31 -36
  25. package/dest/crypto/aes128/index.d.ts +34 -0
  26. package/dest/crypto/aes128/index.d.ts.map +1 -0
  27. package/dest/crypto/aes128/index.js +49 -0
  28. package/dest/crypto/ecdsa/index.d.ts +39 -0
  29. package/dest/crypto/ecdsa/index.d.ts.map +1 -0
  30. package/dest/crypto/ecdsa/index.js +88 -0
  31. package/dest/crypto/ecdsa/signature.d.ts +71 -0
  32. package/dest/crypto/ecdsa/signature.d.ts.map +1 -0
  33. package/dest/crypto/ecdsa/signature.js +92 -0
  34. package/dest/crypto/grumpkin/index.d.ts +47 -0
  35. package/dest/crypto/grumpkin/index.d.ts.map +1 -0
  36. package/dest/crypto/grumpkin/index.js +154 -0
  37. package/dest/crypto/index.d.ts +6 -0
  38. package/dest/crypto/index.d.ts.map +1 -1
  39. package/dest/crypto/index.js +6 -1
  40. package/dest/crypto/keccak/index.js +60 -69
  41. package/dest/crypto/keys/index.js +2 -3
  42. package/dest/crypto/pedersen/index.js +0 -1
  43. package/dest/crypto/pedersen/pedersen.elliptic.js +153 -146
  44. package/dest/crypto/pedersen/pedersen.noble.js +140 -142
  45. package/dest/crypto/pedersen/pedersen.wasm.js +17 -16
  46. package/dest/crypto/poseidon/index.js +15 -19
  47. package/dest/crypto/random/index.js +7 -12
  48. package/dest/crypto/random/randomness_singleton.js +12 -12
  49. package/dest/crypto/schnorr/index.d.ts +30 -0
  50. package/dest/crypto/schnorr/index.d.ts.map +1 -0
  51. package/dest/crypto/schnorr/index.js +68 -0
  52. package/dest/crypto/schnorr/signature.d.ts +70 -0
  53. package/dest/crypto/schnorr/signature.d.ts.map +1 -0
  54. package/dest/crypto/schnorr/signature.js +93 -0
  55. package/dest/crypto/secp256k1/index.d.ts +32 -0
  56. package/dest/crypto/secp256k1/index.d.ts.map +1 -0
  57. package/dest/crypto/secp256k1/index.js +116 -0
  58. package/dest/crypto/secp256k1-signer/index.js +0 -1
  59. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +2 -2
  60. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -1
  61. package/dest/crypto/secp256k1-signer/secp256k1_signer.js +8 -9
  62. package/dest/crypto/secp256k1-signer/utils.js +11 -16
  63. package/dest/crypto/serialize.d.ts +53 -0
  64. package/dest/crypto/serialize.d.ts.map +1 -0
  65. package/dest/crypto/serialize.js +68 -0
  66. package/dest/crypto/sha256/index.js +80 -30
  67. package/dest/crypto/sha512/index.js +2 -4
  68. package/dest/crypto/signature/index.d.ts +19 -0
  69. package/dest/crypto/signature/index.d.ts.map +1 -0
  70. package/dest/crypto/signature/index.js +3 -0
  71. package/dest/crypto/sync/index.js +1 -2
  72. package/dest/crypto/sync/pedersen/index.js +14 -13
  73. package/dest/crypto/sync/poseidon/index.js +10 -14
  74. package/dest/decorators/index.js +0 -1
  75. package/dest/decorators/memoize.js +1 -2
  76. package/dest/error/index.js +6 -19
  77. package/dest/eth-address/index.js +92 -113
  78. package/dest/eth-signature/eth_signature.js +21 -27
  79. package/dest/eth-signature/index.js +0 -1
  80. package/dest/fields/coordinate.d.ts +1 -1
  81. package/dest/fields/coordinate.d.ts.map +1 -1
  82. package/dest/fields/coordinate.js +47 -46
  83. package/dest/fields/fields.d.ts.map +1 -1
  84. package/dest/fields/fields.js +112 -126
  85. package/dest/fields/index.js +0 -1
  86. package/dest/fields/point.js +119 -129
  87. package/dest/fs/index.js +0 -1
  88. package/dest/fs/run_in_dir.d.ts +1 -1
  89. package/dest/fs/run_in_dir.d.ts.map +1 -1
  90. package/dest/fs/run_in_dir.js +16 -7
  91. package/dest/index.d.ts +0 -2
  92. package/dest/index.d.ts.map +1 -1
  93. package/dest/index.js +0 -3
  94. package/dest/iterable/all.js +3 -4
  95. package/dest/iterable/filter.js +10 -11
  96. package/dest/iterable/index.js +0 -1
  97. package/dest/iterable/isAsyncIt.js +1 -3
  98. package/dest/iterable/map.js +10 -11
  99. package/dest/iterable/peek.js +14 -14
  100. package/dest/iterable/sort.js +4 -5
  101. package/dest/iterable/take.js +6 -7
  102. package/dest/iterable/toArray.js +1 -2
  103. package/dest/jest/setup.js +7 -0
  104. package/dest/json-rpc/client/fetch.js +25 -20
  105. package/dest/json-rpc/client/index.js +0 -1
  106. package/dest/json-rpc/client/safe_json_rpc_client.js +20 -9
  107. package/dest/json-rpc/client/undici.d.ts +1 -1
  108. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  109. package/dest/json-rpc/client/undici.js +16 -17
  110. package/dest/json-rpc/convert.d.ts +1 -1
  111. package/dest/json-rpc/convert.d.ts.map +1 -1
  112. package/dest/json-rpc/convert.js +10 -20
  113. package/dest/json-rpc/fixtures/class_a.js +8 -5
  114. package/dest/json-rpc/fixtures/class_b.js +8 -5
  115. package/dest/json-rpc/fixtures/test_state.js +53 -40
  116. package/dest/json-rpc/index.js +0 -1
  117. package/dest/json-rpc/js_utils.js +2 -5
  118. package/dest/json-rpc/server/index.js +0 -1
  119. package/dest/json-rpc/server/safe_json_rpc_server.js +145 -101
  120. package/dest/json-rpc/server/telemetry.js +0 -2
  121. package/dest/json-rpc/test/index.js +0 -1
  122. package/dest/json-rpc/test/integration.d.ts +1 -1
  123. package/dest/json-rpc/test/integration.d.ts.map +1 -1
  124. package/dest/json-rpc/test/integration.js +11 -5
  125. package/dest/log/console.d.ts +1 -1
  126. package/dest/log/console.d.ts.map +1 -1
  127. package/dest/log/console.js +14 -16
  128. package/dest/log/debug.d.ts +1 -1
  129. package/dest/log/debug.d.ts.map +1 -1
  130. package/dest/log/debug.js +9 -18
  131. package/dest/log/gcloud-logger-config.js +17 -15
  132. package/dest/log/index.d.ts +1 -0
  133. package/dest/log/index.d.ts.map +1 -1
  134. package/dest/log/index.js +1 -1
  135. package/dest/log/libp2p_logger.d.ts +7 -0
  136. package/dest/log/libp2p_logger.d.ts.map +1 -0
  137. package/dest/log/libp2p_logger.js +55 -0
  138. package/dest/log/log-filters.js +14 -13
  139. package/dest/log/log-levels.js +10 -2
  140. package/dest/log/log_fn.js +1 -2
  141. package/dest/log/log_history.js +21 -25
  142. package/dest/log/pino-logger.d.ts +8 -4
  143. package/dest/log/pino-logger.d.ts.map +1 -1
  144. package/dest/log/pino-logger.js +92 -74
  145. package/dest/message/index.js +7 -3
  146. package/dest/mutex/index.d.ts +1 -1
  147. package/dest/mutex/index.d.ts.map +1 -1
  148. package/dest/mutex/index.js +34 -32
  149. package/dest/mutex/mutex_database.js +4 -2
  150. package/dest/noir/index.js +0 -1
  151. package/dest/noir/noir_package_config.js +13 -8
  152. package/dest/promise/index.js +0 -1
  153. package/dest/promise/running-promise.d.ts +8 -2
  154. package/dest/promise/running-promise.d.ts.map +1 -1
  155. package/dest/promise/running-promise.js +44 -31
  156. package/dest/promise/utils.js +3 -5
  157. package/dest/queue/base_memory_queue.js +51 -59
  158. package/dest/queue/batch_queue.js +34 -27
  159. package/dest/queue/bounded_serial_queue.js +41 -51
  160. package/dest/queue/fifo_memory_queue.d.ts +1 -1
  161. package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
  162. package/dest/queue/fifo_memory_queue.js +4 -8
  163. package/dest/queue/index.js +0 -1
  164. package/dest/queue/priority_memory_queue.js +3 -4
  165. package/dest/queue/priority_queue.js +5 -5
  166. package/dest/queue/semaphore.js +15 -19
  167. package/dest/queue/serial_queue.js +37 -47
  168. package/dest/retry/index.js +21 -18
  169. package/dest/running-promise/index.js +0 -1
  170. package/dest/schemas/api.d.ts +2 -2
  171. package/dest/schemas/api.d.ts.map +1 -1
  172. package/dest/schemas/api.js +2 -7
  173. package/dest/schemas/index.d.ts +1 -1
  174. package/dest/schemas/index.d.ts.map +1 -1
  175. package/dest/schemas/index.js +1 -2
  176. package/dest/schemas/parse.js +4 -8
  177. package/dest/schemas/schemas.d.ts +1 -16
  178. package/dest/schemas/schemas.d.ts.map +1 -1
  179. package/dest/schemas/schemas.js +28 -56
  180. package/dest/schemas/types.d.ts +1 -1
  181. package/dest/schemas/types.d.ts.map +1 -1
  182. package/dest/schemas/types.js +1 -2
  183. package/dest/schemas/utils.d.ts +1 -1
  184. package/dest/schemas/utils.d.ts.map +1 -1
  185. package/dest/schemas/utils.js +18 -31
  186. package/dest/serialize/buffer_reader.d.ts +1 -1
  187. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  188. package/dest/serialize/buffer_reader.js +164 -188
  189. package/dest/serialize/field_reader.d.ts +1 -1
  190. package/dest/serialize/field_reader.d.ts.map +1 -1
  191. package/dest/serialize/field_reader.js +70 -79
  192. package/dest/serialize/free_funcs.d.ts +1 -1
  193. package/dest/serialize/free_funcs.d.ts.map +1 -1
  194. package/dest/serialize/free_funcs.js +40 -37
  195. package/dest/serialize/index.js +0 -1
  196. package/dest/serialize/serialize.js +72 -83
  197. package/dest/serialize/type_registry.js +10 -14
  198. package/dest/serialize/types.js +4 -5
  199. package/dest/sleep/index.js +25 -29
  200. package/dest/string/index.js +0 -1
  201. package/dest/testing/files/index.js +3 -7
  202. package/dest/testing/index.js +0 -1
  203. package/dest/testing/port_allocator.js +7 -10
  204. package/dest/testing/snapshot_serializer.d.ts +1 -1
  205. package/dest/testing/snapshot_serializer.d.ts.map +1 -1
  206. package/dest/testing/snapshot_serializer.js +14 -9
  207. package/dest/testing/test_data.js +7 -8
  208. package/dest/timer/date.js +9 -7
  209. package/dest/timer/elapsed.js +10 -7
  210. package/dest/timer/index.js +0 -1
  211. package/dest/timer/timeout.js +34 -34
  212. package/dest/timer/timer.js +17 -21
  213. package/dest/transport/browser/index.js +0 -1
  214. package/dest/transport/browser/message_port_socket.d.ts +1 -1
  215. package/dest/transport/browser/message_port_socket.d.ts.map +1 -1
  216. package/dest/transport/browser/message_port_socket.js +26 -30
  217. package/dest/transport/browser/shared_worker_connector.d.ts +1 -1
  218. package/dest/transport/browser/shared_worker_connector.d.ts.map +1 -1
  219. package/dest/transport/browser/shared_worker_connector.js +8 -10
  220. package/dest/transport/browser/shared_worker_listener.d.ts +1 -1
  221. package/dest/transport/browser/shared_worker_listener.d.ts.map +1 -1
  222. package/dest/transport/browser/shared_worker_listener.js +13 -17
  223. package/dest/transport/browser/worker_connector.d.ts +1 -1
  224. package/dest/transport/browser/worker_connector.d.ts.map +1 -1
  225. package/dest/transport/browser/worker_connector.js +12 -12
  226. package/dest/transport/browser/worker_listener.d.ts +1 -1
  227. package/dest/transport/browser/worker_listener.d.ts.map +1 -1
  228. package/dest/transport/browser/worker_listener.js +13 -17
  229. package/dest/transport/dispatch/create_dispatch_fn.js +2 -4
  230. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +2 -2
  231. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
  232. package/dest/transport/dispatch/create_dispatch_proxy.js +16 -13
  233. package/dest/transport/dispatch/messages.js +4 -3
  234. package/dest/transport/index.js +0 -1
  235. package/dest/transport/interface/connector.d.ts +1 -1
  236. package/dest/transport/interface/connector.d.ts.map +1 -1
  237. package/dest/transport/interface/connector.js +3 -2
  238. package/dest/transport/interface/listener.d.ts +1 -1
  239. package/dest/transport/interface/listener.d.ts.map +1 -1
  240. package/dest/transport/interface/listener.js +4 -2
  241. package/dest/transport/interface/socket.js +7 -2
  242. package/dest/transport/interface/transferable.js +7 -9
  243. package/dest/transport/node/index.js +0 -1
  244. package/dest/transport/node/node_connector.d.ts +2 -2
  245. package/dest/transport/node/node_connector.d.ts.map +1 -1
  246. package/dest/transport/node/node_connector.js +9 -11
  247. package/dest/transport/node/node_connector_socket.d.ts +2 -2
  248. package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
  249. package/dest/transport/node/node_connector_socket.js +21 -25
  250. package/dest/transport/node/node_listener.d.ts +1 -1
  251. package/dest/transport/node/node_listener.d.ts.map +1 -1
  252. package/dest/transport/node/node_listener.js +11 -15
  253. package/dest/transport/node/node_listener_socket.d.ts +2 -2
  254. package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
  255. package/dest/transport/node/node_listener_socket.js +23 -27
  256. package/dest/transport/transport_client.d.ts +1 -1
  257. package/dest/transport/transport_client.d.ts.map +1 -1
  258. package/dest/transport/transport_client.js +47 -46
  259. package/dest/transport/transport_server.d.ts +1 -1
  260. package/dest/transport/transport_server.d.ts.map +1 -1
  261. package/dest/transport/transport_server.js +68 -55
  262. package/dest/trees/hasher.d.ts +39 -0
  263. package/dest/trees/hasher.d.ts.map +1 -0
  264. package/dest/trees/hasher.js +5 -0
  265. package/dest/trees/index.d.ts +8 -56
  266. package/dest/trees/index.d.ts.map +1 -1
  267. package/dest/trees/index.js +8 -1
  268. package/dest/trees/indexed_merkle_tree.d.ts +13 -0
  269. package/dest/trees/indexed_merkle_tree.d.ts.map +1 -0
  270. package/dest/trees/indexed_merkle_tree.js +27 -0
  271. package/dest/trees/indexed_merkle_tree_calculator.d.ts +23 -0
  272. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -0
  273. package/dest/trees/indexed_merkle_tree_calculator.js +83 -0
  274. package/dest/trees/indexed_tree_leaf.d.ts +57 -0
  275. package/dest/trees/indexed_tree_leaf.d.ts.map +1 -0
  276. package/dest/trees/indexed_tree_leaf.js +5 -0
  277. package/dest/trees/membership_witness.d.ts +62 -0
  278. package/dest/trees/membership_witness.d.ts.map +1 -0
  279. package/dest/trees/membership_witness.js +70 -0
  280. package/dest/trees/merkle_tree.d.ts +18 -0
  281. package/dest/trees/merkle_tree.d.ts.map +1 -0
  282. package/dest/trees/merkle_tree.js +58 -0
  283. package/dest/trees/merkle_tree_calculator.d.ts +16 -0
  284. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -0
  285. package/dest/trees/merkle_tree_calculator.js +61 -0
  286. package/dest/trees/sibling_path.d.ts +132 -0
  287. package/dest/trees/sibling_path.d.ts.map +1 -0
  288. package/dest/trees/sibling_path.js +144 -0
  289. package/dest/trees/unbalanced_merkle_tree.d.ts +1 -1
  290. package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
  291. package/dest/trees/unbalanced_merkle_tree.js +28 -18
  292. package/dest/trees/unbalanced_tree_store.js +43 -29
  293. package/dest/types/index.js +1 -3
  294. package/dest/url/index.js +4 -8
  295. package/dest/validation/index.js +2 -5
  296. package/dest/wasm/empty_wasi_sdk.js +142 -160
  297. package/dest/wasm/index.d.ts +1 -1
  298. package/dest/wasm/index.d.ts.map +1 -1
  299. package/dest/wasm/index.js +0 -1
  300. package/dest/wasm/wasm_module.js +80 -90
  301. package/dest/worker/browser/index.js +0 -1
  302. package/dest/worker/browser/start_web_module.d.ts +1 -1
  303. package/dest/worker/browser/start_web_module.d.ts.map +1 -1
  304. package/dest/worker/browser/start_web_module.js +9 -5
  305. package/dest/worker/browser/web_data_store.d.ts +1 -1
  306. package/dest/worker/browser/web_data_store.d.ts.map +1 -1
  307. package/dest/worker/browser/web_data_store.js +12 -15
  308. package/dest/worker/browser/web_worker.d.ts +1 -1
  309. package/dest/worker/browser/web_worker.d.ts.map +1 -1
  310. package/dest/worker/browser/web_worker.js +6 -5
  311. package/dest/worker/data_store.js +3 -2
  312. package/dest/worker/index.d.ts +1 -1
  313. package/dest/worker/index.d.ts.map +1 -1
  314. package/dest/worker/index.js +0 -1
  315. package/dest/worker/node/index.js +0 -1
  316. package/dest/worker/node/node_data_store.d.ts +1 -1
  317. package/dest/worker/node/node_data_store.d.ts.map +1 -1
  318. package/dest/worker/node/node_data_store.js +4 -5
  319. package/dest/worker/node/node_worker.d.ts +1 -1
  320. package/dest/worker/node/node_worker.d.ts.map +1 -1
  321. package/dest/worker/node/node_worker.js +6 -5
  322. package/dest/worker/node/start_node_module.d.ts +1 -1
  323. package/dest/worker/node/start_node_module.d.ts.map +1 -1
  324. package/dest/worker/node/start_node_module.js +9 -5
  325. package/dest/worker/wasm_worker.d.ts +2 -2
  326. package/dest/worker/wasm_worker.d.ts.map +1 -1
  327. package/dest/worker/wasm_worker.js +3 -2
  328. package/dest/worker/worker_pool.d.ts +1 -1
  329. package/dest/worker/worker_pool.d.ts.map +1 -1
  330. package/dest/worker/worker_pool.js +32 -43
  331. package/package.json +5 -5
  332. package/src/array/array.ts +1 -1
  333. package/src/buffer/buffer32.ts +1 -1
  334. package/src/collection/array.ts +1 -1
  335. package/src/config/env_var.ts +7 -5
  336. package/src/config/index.ts +1 -1
  337. package/src/crypto/aes128/index.ts +59 -0
  338. package/src/crypto/ecdsa/index.ts +70 -0
  339. package/src/crypto/ecdsa/signature.ts +100 -0
  340. package/src/crypto/grumpkin/index.ts +97 -0
  341. package/src/crypto/index.ts +6 -0
  342. package/src/crypto/keys/index.ts +1 -1
  343. package/src/crypto/pedersen/pedersen.wasm.ts +3 -3
  344. package/src/crypto/poseidon/index.ts +5 -5
  345. package/src/crypto/schnorr/index.ts +55 -0
  346. package/src/crypto/schnorr/signature.ts +116 -0
  347. package/src/crypto/secp256k1/index.ts +57 -0
  348. package/src/crypto/secp256k1-signer/secp256k1_signer.ts +2 -2
  349. package/src/crypto/serialize.ts +85 -0
  350. package/src/crypto/signature/index.ts +17 -0
  351. package/src/crypto/sync/index.ts +1 -1
  352. package/src/fields/coordinate.ts +1 -1
  353. package/src/fields/fields.ts +2 -1
  354. package/src/fs/run_in_dir.ts +8 -1
  355. package/src/index.ts +0 -2
  356. package/src/json-rpc/client/undici.ts +1 -1
  357. package/src/json-rpc/convert.ts +1 -1
  358. package/src/json-rpc/server/safe_json_rpc_server.ts +1 -1
  359. package/src/json-rpc/test/integration.ts +1 -1
  360. package/src/log/console.ts +1 -1
  361. package/src/log/debug.ts +1 -1
  362. package/src/log/gcloud-logger-config.ts +1 -1
  363. package/src/log/index.ts +1 -0
  364. package/src/log/libp2p_logger.ts +67 -0
  365. package/src/log/pino-logger.ts +16 -16
  366. package/src/mutex/index.ts +1 -1
  367. package/src/promise/running-promise.ts +24 -5
  368. package/src/queue/fifo_memory_queue.ts +1 -1
  369. package/src/schemas/api.ts +2 -2
  370. package/src/schemas/index.ts +1 -1
  371. package/src/schemas/schemas.ts +2 -26
  372. package/src/schemas/types.ts +1 -1
  373. package/src/schemas/utils.ts +1 -1
  374. package/src/serialize/buffer_reader.ts +1 -1
  375. package/src/serialize/field_reader.ts +1 -1
  376. package/src/serialize/free_funcs.ts +1 -1
  377. package/src/testing/snapshot_serializer.ts +1 -1
  378. package/src/transport/browser/message_port_socket.ts +1 -1
  379. package/src/transport/browser/shared_worker_connector.ts +1 -1
  380. package/src/transport/browser/shared_worker_listener.ts +1 -1
  381. package/src/transport/browser/worker_connector.ts +1 -1
  382. package/src/transport/browser/worker_listener.ts +1 -1
  383. package/src/transport/dispatch/create_dispatch_proxy.ts +2 -2
  384. package/src/transport/interface/connector.ts +1 -1
  385. package/src/transport/interface/listener.ts +1 -1
  386. package/src/transport/node/node_connector.ts +2 -2
  387. package/src/transport/node/node_connector_socket.ts +2 -2
  388. package/src/transport/node/node_listener.ts +1 -1
  389. package/src/transport/node/node_listener_socket.ts +2 -2
  390. package/src/transport/transport_client.ts +2 -2
  391. package/src/transport/transport_server.ts +3 -3
  392. package/src/trees/hasher.ts +39 -0
  393. package/src/trees/index.ts +8 -57
  394. package/src/trees/indexed_merkle_tree.ts +36 -0
  395. package/src/trees/indexed_merkle_tree_calculator.ts +94 -0
  396. package/src/trees/indexed_tree_leaf.ts +56 -0
  397. package/src/trees/membership_witness.ts +99 -0
  398. package/src/trees/merkle_tree.ts +72 -0
  399. package/src/trees/merkle_tree_calculator.ts +67 -0
  400. package/src/trees/sibling_path.ts +183 -0
  401. package/src/trees/unbalanced_merkle_tree.ts +2 -2
  402. package/src/wasm/index.ts +1 -1
  403. package/src/worker/browser/start_web_module.ts +1 -1
  404. package/src/worker/browser/web_data_store.ts +1 -1
  405. package/src/worker/browser/web_worker.ts +1 -1
  406. package/src/worker/index.ts +1 -1
  407. package/src/worker/node/node_data_store.ts +1 -1
  408. package/src/worker/node/node_worker.ts +1 -1
  409. package/src/worker/node/start_node_module.ts +1 -1
  410. package/src/worker/wasm_worker.ts +2 -2
  411. package/src/worker/worker_pool.ts +1 -1
  412. package/dest/abi/abi.d.ts +0 -853
  413. package/dest/abi/abi.d.ts.map +0 -1
  414. package/dest/abi/abi.js +0 -214
  415. package/dest/abi/buffer.d.ts +0 -18
  416. package/dest/abi/buffer.d.ts.map +0 -1
  417. package/dest/abi/buffer.js +0 -34
  418. package/dest/abi/decoder.d.ts +0 -58
  419. package/dest/abi/decoder.d.ts.map +0 -1
  420. package/dest/abi/decoder.js +0 -180
  421. package/dest/abi/encoder.d.ts +0 -16
  422. package/dest/abi/encoder.d.ts.map +0 -1
  423. package/dest/abi/encoder.js +0 -174
  424. package/dest/abi/event_selector.d.ts +0 -52
  425. package/dest/abi/event_selector.d.ts.map +0 -1
  426. package/dest/abi/event_selector.js +0 -76
  427. package/dest/abi/function_selector.d.ts +0 -65
  428. package/dest/abi/function_selector.d.ts.map +0 -1
  429. package/dest/abi/function_selector.js +0 -92
  430. package/dest/abi/index.d.ts +0 -10
  431. package/dest/abi/index.d.ts.map +0 -1
  432. package/dest/abi/index.js +0 -10
  433. package/dest/abi/note_selector.d.ts +0 -42
  434. package/dest/abi/note_selector.d.ts.map +0 -1
  435. package/dest/abi/note_selector.js +0 -63
  436. package/dest/abi/selector.d.ts +0 -42
  437. package/dest/abi/selector.d.ts.map +0 -1
  438. package/dest/abi/selector.js +0 -57
  439. package/dest/abi/u128.d.ts +0 -13
  440. package/dest/abi/u128.d.ts.map +0 -1
  441. package/dest/abi/u128.js +0 -58
  442. package/dest/abi/utils.d.ts +0 -44
  443. package/dest/abi/utils.d.ts.map +0 -1
  444. package/dest/abi/utils.js +0 -72
  445. package/dest/aztec-address/index.d.ts +0 -57
  446. package/dest/aztec-address/index.d.ts.map +0 -1
  447. package/dest/aztec-address/index.js +0 -114
  448. package/src/abi/abi.ts +0 -504
  449. package/src/abi/buffer.ts +0 -36
  450. package/src/abi/decoder.ts +0 -195
  451. package/src/abi/encoder.ts +0 -170
  452. package/src/abi/event_selector.ts +0 -92
  453. package/src/abi/function_selector.ts +0 -124
  454. package/src/abi/index.ts +0 -9
  455. package/src/abi/note_selector.ts +0 -78
  456. package/src/abi/selector.ts +0 -64
  457. package/src/abi/u128.ts +0 -71
  458. package/src/abi/utils.ts +0 -86
  459. package/src/aztec-address/index.ts +0 -146
package/src/abi/abi.ts DELETED
@@ -1,504 +0,0 @@
1
- /* eslint-disable camelcase */
2
- import { inflate } from 'pako';
3
- import { z } from 'zod';
4
-
5
- import { type Fr } from '../fields/fields.js';
6
- import { createLogger } from '../log/index.js';
7
- import { schemas } from '../schemas/schemas.js';
8
- import { type ZodFor } from '../schemas/types.js';
9
- import { FunctionSelector } from './function_selector.js';
10
- import { type NoteSelector } from './note_selector.js';
11
-
12
- /** A basic value. */
13
- export interface BasicValue<T extends string, V> {
14
- /** The kind of the value. */
15
- kind: T;
16
- value: V;
17
- }
18
-
19
- const logger = createLogger('aztec:foundation:abi');
20
-
21
- /** An exported value. */
22
- export type AbiValue =
23
- | BasicValue<'boolean', boolean>
24
- | BasicValue<'string', string>
25
- | BasicValue<'array', AbiValue[]>
26
- | TupleValue
27
- | IntegerValue
28
- | StructValue;
29
-
30
- export const AbiValueSchema: z.ZodType<AbiValue> = z.discriminatedUnion('kind', [
31
- z.object({ kind: z.literal('boolean'), value: z.boolean() }),
32
- z.object({ kind: z.literal('string'), value: z.string() }),
33
- z.object({ kind: z.literal('array'), value: z.array(z.lazy(() => AbiValueSchema)) }),
34
- z.object({ kind: z.literal('tuple'), fields: z.array(z.lazy(() => AbiValueSchema)) }),
35
- z.object({ kind: z.literal('integer'), value: z.string(), sign: z.boolean() }),
36
- z.object({
37
- kind: z.literal('struct'),
38
- fields: z.array(z.object({ name: z.string(), value: z.lazy(() => AbiValueSchema) })),
39
- }),
40
- ]);
41
-
42
- export type TypedStructFieldValue<T> = { name: string; value: T };
43
-
44
- export interface StructValue {
45
- kind: 'struct';
46
- fields: TypedStructFieldValue<AbiValue>[];
47
- }
48
-
49
- export interface TupleValue {
50
- kind: 'tuple';
51
- fields: AbiValue[];
52
- }
53
-
54
- export interface IntegerValue extends BasicValue<'integer', string> {
55
- sign: boolean;
56
- }
57
-
58
- /** Indicates whether a parameter is public or secret/private. */
59
- export const ABIParameterVisibility = ['public', 'private', 'databus'] as const;
60
-
61
- /** Indicates whether a parameter is public or secret/private. */
62
- export type ABIParameterVisibility = (typeof ABIParameterVisibility)[number];
63
-
64
- /** A basic type. */
65
- export interface BasicType<T extends string> {
66
- /** The kind of the type. */
67
- kind: T;
68
- }
69
-
70
- /** Sign for numeric types. */
71
- const Sign = ['unsigned', 'signed'] as const;
72
- type Sign = (typeof Sign)[number];
73
-
74
- /** A variable type. */
75
- export type AbiType =
76
- | BasicType<'field'>
77
- | BasicType<'boolean'>
78
- | IntegerType
79
- | ArrayType
80
- | StringType
81
- | StructType
82
- | TupleType;
83
-
84
- export const AbiTypeSchema: z.ZodType<AbiType> = z.discriminatedUnion('kind', [
85
- z.object({ kind: z.literal('field') }),
86
- z.object({ kind: z.literal('boolean') }),
87
- z.object({ kind: z.literal('integer'), sign: z.enum(Sign), width: z.number() }),
88
- z.object({ kind: z.literal('array'), length: z.number(), type: z.lazy(() => AbiTypeSchema) }),
89
- z.object({ kind: z.literal('string'), length: z.number() }),
90
- z.object({ kind: z.literal('struct'), fields: z.array(z.lazy(() => ABIVariableSchema)), path: z.string() }),
91
- z.object({ kind: z.literal('tuple'), fields: z.array(z.lazy(() => AbiTypeSchema)) }),
92
- ]);
93
-
94
- /** A named type. */
95
- export const ABIVariableSchema = z.object({
96
- /** The name of the variable. */
97
- name: z.string(),
98
- /** The type of the variable. */
99
- type: AbiTypeSchema,
100
- });
101
-
102
- /** A named type. */
103
- export type ABIVariable = z.infer<typeof ABIVariableSchema>;
104
-
105
- /** A function parameter. */
106
- export const ABIParameterSchema = ABIVariableSchema.and(
107
- z.object({
108
- /** Visibility of the parameter in the function. */
109
- visibility: z.enum(ABIParameterVisibility),
110
- }),
111
- );
112
-
113
- /** A function parameter. */
114
- export type ABIParameter = z.infer<typeof ABIParameterSchema>;
115
-
116
- /** An integer type. */
117
- export interface IntegerType extends BasicType<'integer'> {
118
- /** The sign of the integer. */
119
- sign: Sign;
120
- /** The width of the integer in bits. */
121
- width: number;
122
- }
123
-
124
- /** An array type. */
125
- export interface ArrayType extends BasicType<'array'> {
126
- /** The length of the array. */
127
- length: number;
128
- /** The type of the array elements. */
129
- type: AbiType;
130
- }
131
-
132
- /** A tuple type. */
133
- export interface TupleType extends BasicType<'tuple'> {
134
- /** The types of the tuple elements. */
135
- fields: AbiType[];
136
- }
137
-
138
- /** A string type. */
139
- export interface StringType extends BasicType<'string'> {
140
- /** The length of the string. */
141
- length: number;
142
- }
143
-
144
- /** A struct type. */
145
- export interface StructType extends BasicType<'struct'> {
146
- /** The fields of the struct. */
147
- fields: ABIVariable[];
148
- /** Fully qualified name of the struct. */
149
- path: string;
150
- }
151
-
152
- /** An error could be a custom error of any regular type or a string error. */
153
- export type AbiErrorType =
154
- | { error_kind: 'string'; string: string }
155
- | { error_kind: 'fmtstring'; length: number; item_types: AbiType[] }
156
- | ({ error_kind: 'custom' } & AbiType);
157
-
158
- const AbiErrorTypeSchema = z.union([
159
- z.object({ error_kind: z.literal('string'), string: z.string() }),
160
- z.object({ error_kind: z.literal('fmtstring'), length: z.number(), item_types: z.array(AbiTypeSchema) }),
161
- z.object({ error_kind: z.literal('custom') }).and(AbiTypeSchema),
162
- ]) satisfies ZodFor<AbiErrorType>;
163
-
164
- /** Aztec.nr function types. */
165
- export enum FunctionType {
166
- PRIVATE = 'private',
167
- PUBLIC = 'public',
168
- UNCONSTRAINED = 'unconstrained',
169
- }
170
-
171
- /** The abi entry of a function. */
172
- export interface FunctionAbi {
173
- /** The name of the function. */
174
- name: string;
175
- /** Whether the function is secret. */
176
- functionType: FunctionType;
177
- /** Whether the function is internal. */
178
- isInternal: boolean;
179
- /** Whether the function can alter state or not */
180
- isStatic: boolean;
181
- /** Function parameters. */
182
- parameters: ABIParameter[];
183
- /** The types of the return values. */
184
- returnTypes: AbiType[];
185
- /** The types of the errors that the function can throw. */
186
- errorTypes: Partial<Record<string, AbiErrorType>>;
187
- /** Whether the function is flagged as an initializer. */
188
- isInitializer: boolean;
189
- }
190
-
191
- export const FunctionAbiSchema = z.object({
192
- name: z.string(),
193
- functionType: z.nativeEnum(FunctionType),
194
- isInternal: z.boolean(),
195
- isStatic: z.boolean(),
196
- isInitializer: z.boolean(),
197
- parameters: z.array(z.object({ name: z.string(), type: AbiTypeSchema, visibility: z.enum(ABIParameterVisibility) })),
198
- returnTypes: z.array(AbiTypeSchema),
199
- errorTypes: z.record(AbiErrorTypeSchema),
200
- }) satisfies z.ZodType<FunctionAbi>;
201
-
202
- /** Debug metadata for a function. */
203
- export interface FunctionDebugMetadata {
204
- /** Maps opcodes to source code pointers */
205
- debugSymbols: DebugInfo;
206
- /** Maps the file IDs to the file contents to resolve pointers */
207
- files: DebugFileMap;
208
- }
209
-
210
- export const FunctionDebugMetadataSchema = z.object({
211
- debugSymbols: z.object({
212
- locations: z.record(
213
- z.array(z.object({ span: z.object({ start: z.number(), end: z.number() }), file: z.number() })),
214
- ),
215
- brillig_locations: z.record(
216
- z.record(z.array(z.object({ span: z.object({ start: z.number(), end: z.number() }), file: z.number() }))),
217
- ),
218
- }),
219
- files: z.record(z.object({ source: z.string(), path: z.string() })),
220
- }) satisfies z.ZodType<FunctionDebugMetadata>;
221
-
222
- /** The artifact entry of a function. */
223
- export interface FunctionArtifact extends FunctionAbi {
224
- /** The ACIR bytecode of the function. */
225
- bytecode: Buffer;
226
- /** The verification key of the function, base64 encoded, if it's a private fn. */
227
- verificationKey?: string;
228
- /** Maps opcodes to source code pointers */
229
- debugSymbols: string;
230
- /** Debug metadata for the function. */
231
- debug?: FunctionDebugMetadata;
232
- }
233
-
234
- export const FunctionArtifactSchema = FunctionAbiSchema.and(
235
- z.object({
236
- bytecode: schemas.Buffer,
237
- verificationKey: z.string().optional(),
238
- debugSymbols: z.string(),
239
- debug: FunctionDebugMetadataSchema.optional(),
240
- }),
241
- ) satisfies ZodFor<FunctionArtifact>;
242
-
243
- /** A file ID. It's assigned during compilation. */
244
- export type FileId = number;
245
-
246
- /** A pointer to a specific section of the source code. */
247
- export interface SourceCodeLocation {
248
- /** The section of the source code. */
249
- span: {
250
- /** The byte where the section starts. */
251
- start: number;
252
- /** The byte where the section ends. */
253
- end: number;
254
- };
255
- /** The source code file pointed to. */
256
- file: FileId;
257
- }
258
-
259
- /**
260
- * The location of an opcode in the bytecode.
261
- * It's a string of the form `{acirIndex}` or `{acirIndex}:{brilligIndex}`.
262
- */
263
- export type OpcodeLocation = string;
264
-
265
- export type BrilligFunctionId = number;
266
-
267
- export type OpcodeToLocationsMap = Record<OpcodeLocation, SourceCodeLocation[]>;
268
-
269
- /** The debug information for a given function. */
270
- export interface DebugInfo {
271
- /** A map of the opcode location to the source code location. */
272
- locations: OpcodeToLocationsMap;
273
- /** For each Brillig function, we have a map of the opcode location to the source code location. */
274
- brillig_locations: Record<BrilligFunctionId, OpcodeToLocationsMap>;
275
- }
276
-
277
- /** The debug information for a given program (a collection of functions) */
278
- export interface ProgramDebugInfo {
279
- /** A list of debug information that matches with each function in a program */
280
- debug_infos: Array<DebugInfo>;
281
- }
282
-
283
- /** Maps a file ID to its metadata for debugging purposes. */
284
- export type DebugFileMap = Record<
285
- FileId,
286
- {
287
- /** The source code of the file. */
288
- source: string;
289
- /** The path of the file. */
290
- path: string;
291
- }
292
- >;
293
-
294
- /** Type representing a field of a note (e.g. `amount` in `TokenNote`). */
295
- export type NoteField = {
296
- /** Name of the field (e.g. `amount`). */
297
- name: string;
298
- /** Index where the note field starts in the serialized note array. */
299
- index: number;
300
- /** Whether the field can be unset when creating the note (in the partial notes flow). */
301
- nullable: boolean;
302
- };
303
-
304
- export const NoteFieldSchema = z.object({
305
- name: z.string(),
306
- index: z.number(),
307
- nullable: z.boolean(),
308
- }) satisfies z.ZodType<NoteField>;
309
-
310
- /** Type representing a note in use in the contract. */
311
- export type ContractNote = {
312
- /** Note identifier */
313
- id: NoteSelector;
314
- /** Type of the note (e.g., 'TransparentNote') */
315
- typ: string;
316
- /** Fields of the note. */
317
- fields: NoteField[];
318
- };
319
-
320
- export const ContractNoteSchema = z.object({
321
- id: schemas.NoteSelector,
322
- typ: z.string(),
323
- fields: z.array(NoteFieldSchema),
324
- }) satisfies ZodFor<ContractNote>;
325
-
326
- /** Type representing a field layout in the storage of a contract. */
327
- export type FieldLayout = {
328
- /** Slot in which the field is stored. */
329
- slot: Fr;
330
- };
331
-
332
- /** Defines artifact of a contract. */
333
- export interface ContractArtifact {
334
- /** The name of the contract. */
335
- name: string;
336
-
337
- /** The version of compiler used to create this artifact */
338
- aztecNrVersion?: string;
339
-
340
- /** The functions of the contract. */
341
- functions: FunctionArtifact[];
342
-
343
- /** The outputs of the contract. */
344
- outputs: {
345
- structs: Record<string, AbiType[]>;
346
- globals: Record<string, AbiValue[]>;
347
- };
348
-
349
- /** Storage layout */
350
- storageLayout: Record<string, FieldLayout>;
351
-
352
- /** The notes used in the contract. */
353
- notes: Record<string, ContractNote>;
354
-
355
- /** The map of file ID to the source code and path of the file. */
356
- fileMap: DebugFileMap;
357
- }
358
-
359
- export const ContractArtifactSchema: ZodFor<ContractArtifact> = z.object({
360
- name: z.string(),
361
- aztecNrVersion: z.string().optional(),
362
- functions: z.array(FunctionArtifactSchema),
363
- outputs: z.object({
364
- structs: z.record(z.array(AbiTypeSchema)).transform(structs => {
365
- for (const [key, value] of Object.entries(structs)) {
366
- // We are manually ordering events and functions in the abi by path.
367
- // The path ordering is arbitrary, and only needed to ensure deterministic order.
368
- // These are the only arrays in the artifact with arbitrary order, and hence the only ones
369
- // we need to sort.
370
- if (key === 'events' || key === 'functions') {
371
- structs[key] = (value as StructType[]).sort((a, b) => (a.path > b.path ? -1 : 1));
372
- }
373
- }
374
- return structs;
375
- }),
376
- globals: z.record(z.array(AbiValueSchema)),
377
- }),
378
- storageLayout: z.record(z.object({ slot: schemas.Fr })),
379
- notes: z.record(ContractNoteSchema),
380
- fileMap: z.record(z.coerce.number(), z.object({ source: z.string(), path: z.string() })),
381
- });
382
-
383
- export function getFunctionArtifactByName(artifact: ContractArtifact, functionName: string): FunctionArtifact {
384
- const functionArtifact = artifact.functions.find(f => f.name === functionName);
385
-
386
- if (!functionArtifact) {
387
- throw new Error(`Unknown function ${functionName}`);
388
- }
389
-
390
- const debugMetadata = getFunctionDebugMetadata(artifact, functionArtifact);
391
- return { ...functionArtifact, debug: debugMetadata };
392
- }
393
-
394
- /** Gets a function artifact including debug metadata given its name or selector. */
395
- export async function getFunctionArtifact(
396
- artifact: ContractArtifact,
397
- functionNameOrSelector: string | FunctionSelector,
398
- ): Promise<FunctionArtifact> {
399
- let functionArtifact;
400
- if (typeof functionNameOrSelector === 'string') {
401
- functionArtifact = artifact.functions.find(f => f.name === functionNameOrSelector);
402
- } else {
403
- const functionsAndSelectors = await Promise.all(
404
- artifact.functions.map(async fn => ({
405
- fn,
406
- selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
407
- })),
408
- );
409
- functionArtifact = functionsAndSelectors.find(fnAndSelector =>
410
- functionNameOrSelector.equals(fnAndSelector.selector),
411
- )?.fn;
412
- }
413
- if (!functionArtifact) {
414
- throw new Error(`Unknown function ${functionNameOrSelector}`);
415
- }
416
-
417
- const debugMetadata = getFunctionDebugMetadata(artifact, functionArtifact);
418
-
419
- return { ...functionArtifact, debug: debugMetadata };
420
- }
421
-
422
- /**
423
- * Gets the debug metadata of a given function from the contract artifact
424
- * @param artifact - The contract build artifact
425
- * @param functionName - The name of the function
426
- * @returns The debug metadata of the function
427
- */
428
- export function getFunctionDebugMetadata(
429
- contractArtifact: ContractArtifact,
430
- functionArtifact: FunctionArtifact,
431
- ): FunctionDebugMetadata | undefined {
432
- try {
433
- if (functionArtifact.debugSymbols && contractArtifact.fileMap) {
434
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/10546) investigate why debugMetadata is so big for some tests.
435
- const programDebugSymbols = JSON.parse(
436
- inflate(Buffer.from(functionArtifact.debugSymbols, 'base64'), { to: 'string', raw: true }),
437
- );
438
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/5813)
439
- // We only support handling debug info for the contract function entry point.
440
- // So for now we simply index into the first debug info.
441
- return {
442
- debugSymbols: programDebugSymbols.debug_infos[0],
443
- files: contractArtifact.fileMap,
444
- };
445
- }
446
- } catch (err: any) {
447
- if (err instanceof RangeError && err.message.includes('Invalid string length')) {
448
- logger.warn(
449
- `Caught RangeError: Invalid string length. This suggests the debug_symbols field of the contract ${contractArtifact.name} and function ${functionArtifact.name} is huge; too big to parse. We'll skip returning this info until this issue is resolved. Here's the error:\n${err.message}`,
450
- );
451
- // We'll return undefined.
452
- } else {
453
- // Rethrow unexpected errors
454
- throw err;
455
- }
456
- }
457
-
458
- return undefined;
459
- }
460
-
461
- /**
462
- * Returns an initializer from the contract, assuming there is at least one. If there are multiple initializers,
463
- * it returns the one named "constructor" or "initializer"; if there is none with that name, it returns the first
464
- * initializer it finds, prioritizing initializers with no arguments and then private ones.
465
- * @param contractArtifact - The contract artifact.
466
- * @returns An initializer function, or none if there are no functions flagged as initializers in the contract.
467
- */
468
- export function getDefaultInitializer(contractArtifact: ContractArtifact): FunctionArtifact | undefined {
469
- const initializers = contractArtifact.functions.filter(f => f.isInitializer);
470
- return initializers.length > 1
471
- ? initializers.find(f => f.name === 'constructor') ??
472
- initializers.find(f => f.name === 'initializer') ??
473
- initializers.find(f => f.parameters?.length === 0) ??
474
- initializers.find(f => f.functionType === FunctionType.PRIVATE) ??
475
- initializers[0]
476
- : initializers[0];
477
- }
478
-
479
- /**
480
- * Returns an initializer from the contract.
481
- * @param initializerNameOrArtifact - The name of the constructor, or the artifact of the constructor, or undefined
482
- * to pick the default initializer.
483
- */
484
- export function getInitializer(
485
- contract: ContractArtifact,
486
- initializerNameOrArtifact: string | undefined | FunctionArtifact,
487
- ): FunctionArtifact | undefined {
488
- if (typeof initializerNameOrArtifact === 'string') {
489
- const found = contract.functions.find(f => f.name === initializerNameOrArtifact);
490
- if (!found) {
491
- throw new Error(`Constructor method ${initializerNameOrArtifact} not found in contract artifact`);
492
- } else if (!found.isInitializer) {
493
- throw new Error(`Method ${initializerNameOrArtifact} is not an initializer`);
494
- }
495
- return found;
496
- } else if (initializerNameOrArtifact === undefined) {
497
- return getDefaultInitializer(contract);
498
- } else {
499
- if (!initializerNameOrArtifact.isInitializer) {
500
- throw new Error(`Method ${initializerNameOrArtifact.name} is not an initializer`);
501
- }
502
- return initializerNameOrArtifact;
503
- }
504
- }
package/src/abi/buffer.ts DELETED
@@ -1,36 +0,0 @@
1
- import chunk from 'lodash.chunk';
2
-
3
- import { Fr } from '../fields/fields.js';
4
-
5
- /**
6
- * Formats a buffer as an array of fields. Splits the input into 31-byte chunks, and stores each
7
- * of them into a field, omitting the field's first byte, then adds zero-fields at the end until the max length.
8
- * @param input - Input to format.
9
- * @param targetLength - Length of the target array in number of fields.
10
- * @returns A field with the total length in bytes, followed by an array of fields such that their concatenation is equal to the input buffer, followed by enough zeroes to reach targetLength.
11
- */
12
- export function bufferAsFields(input: Buffer, targetLength: number): Fr[] {
13
- const encoded = [
14
- new Fr(input.length),
15
- ...chunk(input, Fr.SIZE_IN_BYTES - 1).map(c => {
16
- const fieldBytes = Buffer.alloc(Fr.SIZE_IN_BYTES);
17
- Buffer.from(c).copy(fieldBytes, 1);
18
- return Fr.fromBuffer(fieldBytes);
19
- }),
20
- ];
21
- if (encoded.length > targetLength) {
22
- throw new Error(`Input buffer exceeds maximum size: got ${encoded.length} but max is ${targetLength}`);
23
- }
24
- // Fun fact: we cannot use padArrayEnd here since typescript cannot deal with a Tuple this big
25
- return [...encoded, ...Array(targetLength - encoded.length).fill(Fr.ZERO)];
26
- }
27
-
28
- /**
29
- * Recovers a buffer from an array of fields.
30
- * @param fields - An output from bufferAsFields.
31
- * @returns The recovered buffer.
32
- */
33
- export function bufferFromFields(fields: Fr[]): Buffer {
34
- const [length, ...payload] = fields;
35
- return Buffer.concat(payload.map(f => f.toBuffer().subarray(1))).subarray(0, length.toNumber());
36
- }