@aztec/cli 0.17.0 → 0.77.0-testnet-ignition.17

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 (325) hide show
  1. package/README.md +10 -16
  2. package/dest/cmds/contracts/index.d.ts +4 -0
  3. package/dest/cmds/contracts/index.d.ts.map +1 -0
  4. package/dest/cmds/contracts/index.js +12 -0
  5. package/dest/cmds/contracts/inspect_contract.d.ts +3 -0
  6. package/dest/cmds/contracts/inspect_contract.d.ts.map +1 -0
  7. package/dest/cmds/contracts/inspect_contract.js +37 -0
  8. package/dest/cmds/{parse_parameter_struct.d.ts → contracts/parse_parameter_struct.d.ts} +1 -4
  9. package/dest/cmds/contracts/parse_parameter_struct.d.ts.map +1 -0
  10. package/dest/cmds/contracts/parse_parameter_struct.js +13 -0
  11. package/dest/cmds/devnet/bootstrap_network.d.ts +3 -0
  12. package/dest/cmds/devnet/bootstrap_network.d.ts.map +1 -0
  13. package/dest/cmds/devnet/bootstrap_network.js +196 -0
  14. package/dest/cmds/devnet/faucet.d.ts +4 -0
  15. package/dest/cmds/devnet/faucet.d.ts.map +1 -0
  16. package/dest/cmds/devnet/faucet.js +26 -0
  17. package/dest/cmds/devnet/index.d.ts +4 -0
  18. package/dest/cmds/devnet/index.d.ts.map +1 -0
  19. package/dest/cmds/devnet/index.js +14 -0
  20. package/dest/cmds/infrastructure/index.d.ts +4 -0
  21. package/dest/cmds/infrastructure/index.d.ts.map +1 -0
  22. package/dest/cmds/infrastructure/index.js +24 -0
  23. package/dest/cmds/infrastructure/sequencers.d.ts +13 -0
  24. package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -0
  25. package/dest/cmds/infrastructure/sequencers.js +93 -0
  26. package/dest/cmds/infrastructure/setup_l2_contract.d.ts +3 -0
  27. package/dest/cmds/infrastructure/setup_l2_contract.d.ts.map +1 -0
  28. package/dest/cmds/infrastructure/setup_l2_contract.js +43 -0
  29. package/dest/cmds/l1/advance_epoch.d.ts +3 -0
  30. package/dest/cmds/l1/advance_epoch.d.ts.map +1 -0
  31. package/dest/cmds/l1/advance_epoch.js +10 -0
  32. package/dest/cmds/l1/assume_proven_through.d.ts +3 -0
  33. package/dest/cmds/l1/assume_proven_through.d.ts.map +1 -0
  34. package/dest/cmds/l1/assume_proven_through.js +12 -0
  35. package/dest/cmds/l1/bridge_erc20.d.ts +4 -0
  36. package/dest/cmds/l1/bridge_erc20.d.ts.map +1 -0
  37. package/dest/cmds/l1/bridge_erc20.js +31 -0
  38. package/dest/cmds/l1/create_l1_account.d.ts +3 -0
  39. package/dest/cmds/l1/create_l1_account.d.ts.map +1 -0
  40. package/dest/cmds/l1/create_l1_account.js +15 -0
  41. package/dest/cmds/l1/deploy_l1_contracts.d.ts +4 -0
  42. package/dest/cmds/l1/deploy_l1_contracts.d.ts.map +1 -0
  43. package/dest/cmds/l1/deploy_l1_contracts.js +29 -0
  44. package/dest/cmds/l1/deploy_l1_verifier.d.ts +5 -0
  45. package/dest/cmds/l1/deploy_l1_verifier.d.ts.map +1 -0
  46. package/dest/cmds/l1/deploy_l1_verifier.js +54 -0
  47. package/dest/cmds/l1/deploy_new_rollup.d.ts +4 -0
  48. package/dest/cmds/l1/deploy_new_rollup.d.ts.map +1 -0
  49. package/dest/cmds/l1/deploy_new_rollup.js +19 -0
  50. package/dest/cmds/l1/get_l1_addresses.d.ts +4 -0
  51. package/dest/cmds/l1/get_l1_addresses.d.ts.map +1 -0
  52. package/dest/cmds/l1/get_l1_addresses.js +18 -0
  53. package/dest/cmds/l1/get_l1_balance.d.ts +4 -0
  54. package/dest/cmds/l1/get_l1_balance.d.ts.map +1 -0
  55. package/dest/cmds/l1/get_l1_balance.js +33 -0
  56. package/dest/cmds/l1/governance_utils.d.ts +50 -0
  57. package/dest/cmds/l1/governance_utils.d.ts.map +1 -0
  58. package/dest/cmds/l1/governance_utils.js +85 -0
  59. package/dest/cmds/l1/index.d.ts +4 -0
  60. package/dest/cmds/l1/index.d.ts.map +1 -0
  61. package/dest/cmds/l1/index.js +208 -0
  62. package/dest/cmds/l1/prover_stats.d.ts +14 -0
  63. package/dest/cmds/l1/prover_stats.d.ts.map +1 -0
  64. package/dest/cmds/l1/prover_stats.js +145 -0
  65. package/dest/cmds/l1/update_l1_validators.d.ts +30 -0
  66. package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -0
  67. package/dest/cmds/l1/update_l1_validators.js +186 -0
  68. package/dest/cmds/misc/compute_selector.d.ts +3 -0
  69. package/dest/cmds/misc/compute_selector.d.ts.map +1 -0
  70. package/dest/cmds/misc/compute_selector.js +5 -0
  71. package/dest/cmds/misc/example_contracts.d.ts +3 -0
  72. package/dest/cmds/misc/example_contracts.d.ts.map +1 -0
  73. package/dest/cmds/misc/example_contracts.js +6 -0
  74. package/dest/cmds/misc/generate_bootnode_enr.d.ts +3 -0
  75. package/dest/cmds/misc/generate_bootnode_enr.d.ts.map +1 -0
  76. package/dest/cmds/misc/generate_bootnode_enr.js +5 -0
  77. package/dest/cmds/misc/generate_p2p_private_key.d.ts +3 -0
  78. package/dest/cmds/misc/generate_p2p_private_key.d.ts.map +1 -0
  79. package/dest/cmds/misc/generate_p2p_private_key.js +7 -0
  80. package/dest/cmds/misc/generate_secret_and_hash.d.ts +3 -0
  81. package/dest/cmds/misc/generate_secret_and_hash.d.ts.map +1 -0
  82. package/dest/cmds/misc/generate_secret_and_hash.js +11 -0
  83. package/dest/cmds/misc/generate_secret_key.d.ts +5 -0
  84. package/dest/cmds/misc/generate_secret_key.d.ts.map +1 -0
  85. package/dest/cmds/misc/generate_secret_key.js +6 -0
  86. package/dest/cmds/misc/index.d.ts +4 -0
  87. package/dest/cmds/misc/index.d.ts.map +1 -0
  88. package/dest/cmds/misc/index.js +44 -0
  89. package/dest/cmds/misc/setup_contracts.d.ts +7 -0
  90. package/dest/cmds/misc/setup_contracts.d.ts.map +1 -0
  91. package/dest/cmds/misc/setup_contracts.js +27 -0
  92. package/dest/cmds/misc/update/common.d.ts.map +1 -0
  93. package/dest/cmds/misc/update/common.js +3 -0
  94. package/dest/cmds/misc/update/github.d.ts.map +1 -0
  95. package/dest/cmds/misc/update/github.js +3 -0
  96. package/dest/{update → cmds/misc/update}/noir.d.ts +2 -2
  97. package/dest/cmds/misc/update/noir.d.ts.map +1 -0
  98. package/dest/cmds/misc/update/noir.js +45 -0
  99. package/dest/{update → cmds/misc/update}/npm.d.ts +3 -3
  100. package/dest/cmds/misc/update/npm.d.ts.map +1 -0
  101. package/dest/cmds/misc/update/npm.js +127 -0
  102. package/dest/cmds/misc/update/utils.d.ts +14 -0
  103. package/dest/cmds/misc/update/utils.d.ts.map +1 -0
  104. package/dest/cmds/misc/update/utils.js +38 -0
  105. package/dest/cmds/misc/update.d.ts +3 -0
  106. package/dest/cmds/misc/update.d.ts.map +1 -0
  107. package/dest/cmds/misc/update.js +52 -0
  108. package/dest/cmds/pxe/add_contract.d.ts +5 -0
  109. package/dest/cmds/pxe/add_contract.d.ts.map +1 -0
  110. package/dest/cmds/pxe/add_contract.js +29 -0
  111. package/dest/cmds/pxe/block_number.d.ts +3 -0
  112. package/dest/cmds/pxe/block_number.d.ts.map +1 -0
  113. package/dest/cmds/pxe/block_number.js +10 -0
  114. package/dest/cmds/pxe/get_account.d.ts +4 -0
  115. package/dest/cmds/pxe/get_account.d.ts.map +1 -0
  116. package/dest/cmds/pxe/get_account.js +10 -0
  117. package/dest/cmds/pxe/get_accounts.d.ts +3 -0
  118. package/dest/cmds/pxe/get_accounts.d.ts.map +1 -0
  119. package/dest/cmds/pxe/get_accounts.js +25 -0
  120. package/dest/cmds/pxe/get_block.d.ts +3 -0
  121. package/dest/cmds/pxe/get_block.d.ts.map +1 -0
  122. package/dest/cmds/pxe/get_block.js +9 -0
  123. package/dest/cmds/pxe/get_contract_data.d.ts +4 -0
  124. package/dest/cmds/pxe/get_contract_data.d.ts.map +1 -0
  125. package/dest/cmds/pxe/get_contract_data.js +31 -0
  126. package/dest/cmds/pxe/get_current_base_fee.d.ts +3 -0
  127. package/dest/cmds/pxe/get_current_base_fee.d.ts.map +1 -0
  128. package/dest/cmds/pxe/get_current_base_fee.js +7 -0
  129. package/dest/cmds/pxe/get_l1_to_l2_message_witness.d.ts +4 -0
  130. package/dest/cmds/pxe/get_l1_to_l2_message_witness.d.ts.map +1 -0
  131. package/dest/cmds/pxe/get_l1_to_l2_message_witness.js +11 -0
  132. package/dest/cmds/pxe/get_logs.d.ts +4 -0
  133. package/dest/cmds/pxe/get_logs.d.ts.map +1 -0
  134. package/dest/cmds/pxe/get_logs.js +51 -0
  135. package/dest/cmds/pxe/get_node_info.d.ts +3 -0
  136. package/dest/cmds/pxe/get_node_info.d.ts.map +1 -0
  137. package/dest/cmds/pxe/get_node_info.js +61 -0
  138. package/dest/cmds/pxe/get_pxe_info.d.ts +3 -0
  139. package/dest/cmds/pxe/get_pxe_info.d.ts.map +1 -0
  140. package/dest/cmds/pxe/get_pxe_info.js +11 -0
  141. package/dest/cmds/pxe/index.d.ts +4 -0
  142. package/dest/cmds/pxe/index.d.ts.map +1 -0
  143. package/dest/cmds/pxe/index.js +55 -0
  144. package/dest/utils/aztec.d.ts +68 -0
  145. package/dest/utils/aztec.d.ts.map +1 -0
  146. package/dest/utils/aztec.js +173 -0
  147. package/dest/{parse_args.d.ts → utils/commands.d.ts} +50 -12
  148. package/dest/utils/commands.d.ts.map +1 -0
  149. package/dest/utils/commands.js +303 -0
  150. package/dest/{encoding.d.ts → utils/encoding.d.ts} +1 -1
  151. package/dest/utils/encoding.d.ts.map +1 -0
  152. package/dest/utils/encoding.js +103 -0
  153. package/dest/utils/github.d.ts +4 -0
  154. package/dest/utils/github.d.ts.map +1 -0
  155. package/dest/utils/github.js +3 -0
  156. package/dest/utils/index.d.ts +5 -0
  157. package/dest/utils/index.d.ts.map +1 -0
  158. package/dest/utils/index.js +4 -0
  159. package/dest/utils/inspect.d.ts +17 -0
  160. package/dest/utils/inspect.d.ts.map +1 -0
  161. package/dest/utils/inspect.js +177 -0
  162. package/package.json +68 -22
  163. package/src/cmds/contracts/index.ts +34 -0
  164. package/src/cmds/contracts/inspect_contract.ts +51 -0
  165. package/src/cmds/contracts/parse_parameter_struct.ts +27 -0
  166. package/src/cmds/devnet/bootstrap_network.ts +318 -0
  167. package/src/cmds/devnet/faucet.ts +33 -0
  168. package/src/cmds/devnet/index.ts +60 -0
  169. package/src/cmds/infrastructure/index.ts +55 -0
  170. package/src/cmds/infrastructure/sequencers.ts +103 -0
  171. package/src/cmds/infrastructure/setup_l2_contract.ts +47 -0
  172. package/src/cmds/l1/advance_epoch.ts +12 -0
  173. package/src/cmds/l1/assume_proven_through.ts +19 -0
  174. package/src/cmds/l1/bridge_erc20.ts +52 -0
  175. package/src/cmds/l1/create_l1_account.ts +17 -0
  176. package/src/cmds/l1/deploy_l1_contracts.ts +63 -0
  177. package/src/cmds/l1/deploy_l1_verifier.ts +105 -0
  178. package/src/cmds/l1/deploy_new_rollup.ts +58 -0
  179. package/src/cmds/l1/get_l1_addresses.ts +30 -0
  180. package/src/cmds/l1/get_l1_balance.ts +44 -0
  181. package/src/cmds/l1/governance_utils.ts +187 -0
  182. package/src/cmds/l1/index.ts +556 -0
  183. package/src/cmds/l1/prover_stats.ts +202 -0
  184. package/src/cmds/l1/update_l1_validators.ts +238 -0
  185. package/src/cmds/misc/compute_selector.ts +7 -0
  186. package/src/cmds/misc/example_contracts.ts +12 -0
  187. package/src/cmds/misc/generate_bootnode_enr.ts +12 -0
  188. package/src/cmds/misc/generate_p2p_private_key.ts +10 -0
  189. package/src/cmds/misc/generate_secret_and_hash.ts +15 -0
  190. package/src/cmds/misc/generate_secret_key.ts +5 -0
  191. package/src/cmds/misc/index.ts +92 -0
  192. package/src/cmds/misc/setup_contracts.ts +40 -0
  193. package/src/cmds/misc/update/common.ts +16 -0
  194. package/src/cmds/misc/update/github.ts +3 -0
  195. package/src/cmds/misc/update/noir.ts +57 -0
  196. package/src/cmds/misc/update/npm.ts +154 -0
  197. package/src/cmds/misc/update/utils.ts +50 -0
  198. package/src/cmds/misc/update.ts +78 -0
  199. package/src/cmds/pxe/add_contract.ts +41 -0
  200. package/src/cmds/pxe/block_number.ts +9 -0
  201. package/src/cmds/pxe/get_account.ts +16 -0
  202. package/src/cmds/pxe/get_accounts.ts +35 -0
  203. package/src/cmds/pxe/get_block.ts +10 -0
  204. package/src/cmds/pxe/get_contract_data.ts +51 -0
  205. package/src/cmds/pxe/get_current_base_fee.ts +9 -0
  206. package/src/cmds/pxe/get_l1_to_l2_message_witness.ts +25 -0
  207. package/src/cmds/pxe/get_logs.ts +66 -0
  208. package/src/cmds/pxe/get_node_info.ts +71 -0
  209. package/src/cmds/pxe/get_pxe_info.ts +13 -0
  210. package/src/cmds/pxe/index.ts +170 -0
  211. package/src/utils/aztec.ts +248 -0
  212. package/src/utils/commands.ts +384 -0
  213. package/src/utils/encoding.ts +117 -0
  214. package/src/utils/github.ts +3 -0
  215. package/src/utils/index.ts +4 -0
  216. package/src/utils/inspect.ts +208 -0
  217. package/dest/bin/index.d.ts +0 -3
  218. package/dest/bin/index.d.ts.map +0 -1
  219. package/dest/bin/index.js +0 -19
  220. package/dest/client.d.ts +0 -17
  221. package/dest/client.d.ts.map +0 -1
  222. package/dest/client.js +0 -60
  223. package/dest/cmds/add_contract.d.ts +0 -7
  224. package/dest/cmds/add_contract.d.ts.map +0 -1
  225. package/dest/cmds/add_contract.js +0 -15
  226. package/dest/cmds/add_note.d.ts +0 -8
  227. package/dest/cmds/add_note.d.ts.map +0 -1
  228. package/dest/cmds/add_note.js +0 -13
  229. package/dest/cmds/block_number.d.ts +0 -6
  230. package/dest/cmds/block_number.d.ts.map +0 -1
  231. package/dest/cmds/block_number.js +0 -10
  232. package/dest/cmds/call.d.ts +0 -7
  233. package/dest/cmds/call.d.ts.map +0 -1
  234. package/dest/cmds/call.js +0 -18
  235. package/dest/cmds/check_deploy.d.ts +0 -7
  236. package/dest/cmds/check_deploy.d.ts.map +0 -1
  237. package/dest/cmds/check_deploy.js +0 -16
  238. package/dest/cmds/compute_selector.d.ts +0 -6
  239. package/dest/cmds/compute_selector.d.ts.map +0 -1
  240. package/dest/cmds/compute_selector.js +0 -9
  241. package/dest/cmds/create_account.d.ts +0 -7
  242. package/dest/cmds/create_account.d.ts.map +0 -1
  243. package/dest/cmds/create_account.js +0 -31
  244. package/dest/cmds/deploy.d.ts +0 -7
  245. package/dest/cmds/deploy.d.ts.map +0 -1
  246. package/dest/cmds/deploy.js +0 -58
  247. package/dest/cmds/deploy_l1_contracts.d.ts +0 -6
  248. package/dest/cmds/deploy_l1_contracts.d.ts.map +0 -1
  249. package/dest/cmds/deploy_l1_contracts.js +0 -15
  250. package/dest/cmds/example_contracts.d.ts +0 -6
  251. package/dest/cmds/example_contracts.d.ts.map +0 -1
  252. package/dest/cmds/example_contracts.js +0 -10
  253. package/dest/cmds/generate_p2p_private_key.d.ts +0 -6
  254. package/dest/cmds/generate_p2p_private_key.d.ts.map +0 -1
  255. package/dest/cmds/generate_p2p_private_key.js +0 -11
  256. package/dest/cmds/generate_private_key.d.ts +0 -6
  257. package/dest/cmds/generate_private_key.d.ts.map +0 -1
  258. package/dest/cmds/generate_private_key.js +0 -22
  259. package/dest/cmds/get_account.d.ts +0 -7
  260. package/dest/cmds/get_account.d.ts.map +0 -1
  261. package/dest/cmds/get_account.js +0 -15
  262. package/dest/cmds/get_accounts.d.ts +0 -6
  263. package/dest/cmds/get_accounts.d.ts.map +0 -1
  264. package/dest/cmds/get_accounts.js +0 -18
  265. package/dest/cmds/get_contract_data.d.ts +0 -7
  266. package/dest/cmds/get_contract_data.d.ts.map +0 -1
  267. package/dest/cmds/get_contract_data.js +0 -28
  268. package/dest/cmds/get_logs.d.ts +0 -7
  269. package/dest/cmds/get_logs.d.ts.map +0 -1
  270. package/dest/cmds/get_logs.js +0 -54
  271. package/dest/cmds/get_node_info.d.ts +0 -6
  272. package/dest/cmds/get_node_info.d.ts.map +0 -1
  273. package/dest/cmds/get_node_info.js +0 -15
  274. package/dest/cmds/get_recipient.d.ts +0 -7
  275. package/dest/cmds/get_recipient.d.ts.map +0 -1
  276. package/dest/cmds/get_recipient.js +0 -15
  277. package/dest/cmds/get_recipients.d.ts +0 -6
  278. package/dest/cmds/get_recipients.d.ts.map +0 -1
  279. package/dest/cmds/get_recipients.js +0 -18
  280. package/dest/cmds/get_tx_receipt.d.ts +0 -7
  281. package/dest/cmds/get_tx_receipt.d.ts.map +0 -1
  282. package/dest/cmds/get_tx_receipt.js +0 -16
  283. package/dest/cmds/inspect_contract.d.ts +0 -6
  284. package/dest/cmds/inspect_contract.d.ts.map +0 -1
  285. package/dest/cmds/inspect_contract.js +0 -19
  286. package/dest/cmds/parse_parameter_struct.d.ts.map +0 -1
  287. package/dest/cmds/parse_parameter_struct.js +0 -20
  288. package/dest/cmds/register_account.d.ts +0 -7
  289. package/dest/cmds/register_account.d.ts.map +0 -1
  290. package/dest/cmds/register_account.js +0 -13
  291. package/dest/cmds/register_recipient.d.ts +0 -7
  292. package/dest/cmds/register_recipient.d.ts.map +0 -1
  293. package/dest/cmds/register_recipient.js +0 -11
  294. package/dest/cmds/send.d.ts +0 -7
  295. package/dest/cmds/send.d.ts.map +0 -1
  296. package/dest/cmds/send.js +0 -27
  297. package/dest/cmds/unbox.d.ts +0 -7
  298. package/dest/cmds/unbox.d.ts.map +0 -1
  299. package/dest/cmds/unbox.js +0 -133
  300. package/dest/encoding.d.ts.map +0 -1
  301. package/dest/encoding.js +0 -114
  302. package/dest/github.d.ts.map +0 -1
  303. package/dest/github.js +0 -4
  304. package/dest/index.d.ts +0 -10
  305. package/dest/index.d.ts.map +0 -1
  306. package/dest/index.js +0 -321
  307. package/dest/parse_args.d.ts.map +0 -1
  308. package/dest/parse_args.js +0 -233
  309. package/dest/test/mocks.d.ts +0 -3
  310. package/dest/test/mocks.d.ts.map +0 -1
  311. package/dest/test/mocks.js +0 -65
  312. package/dest/update/common.d.ts.map +0 -1
  313. package/dest/update/common.js +0 -2
  314. package/dest/update/noir.d.ts.map +0 -1
  315. package/dest/update/noir.js +0 -63
  316. package/dest/update/npm.d.ts.map +0 -1
  317. package/dest/update/npm.js +0 -125
  318. package/dest/update/update.d.ts +0 -3
  319. package/dest/update/update.d.ts.map +0 -1
  320. package/dest/update/update.js +0 -58
  321. package/dest/utils.d.ts +0 -70
  322. package/dest/utils.d.ts.map +0 -1
  323. package/dest/utils.js +0 -168
  324. /package/dest/{update → cmds/misc/update}/common.d.ts +0 -0
  325. /package/dest/{github.d.ts → cmds/misc/update/github.d.ts} +0 -0
@@ -0,0 +1,384 @@
1
+ import { FunctionSelector } from '@aztec/aztec.js/abi';
2
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
3
+ import { EthAddress } from '@aztec/aztec.js/eth_address';
4
+ import { Fr } from '@aztec/aztec.js/fields';
5
+ import { LogId } from '@aztec/aztec.js/log_id';
6
+ import { TxHash } from '@aztec/aztec.js/tx_hash';
7
+ import type { LogFn } from '@aztec/foundation/log';
8
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
9
+ import { PublicKeys } from '@aztec/stdlib/keys';
10
+
11
+ import { type Command, CommanderError, InvalidArgumentError, Option } from 'commander';
12
+ import { lookup } from 'dns/promises';
13
+ import { rename, writeFile } from 'fs/promises';
14
+
15
+ /**
16
+ * If we can successfully resolve 'host.docker.internal', then we are running in a container, and we should treat
17
+ * localhost as being host.docker.internal.
18
+ */
19
+ export const getLocalhost = () =>
20
+ lookup('host.docker.internal')
21
+ .then(() => 'host.docker.internal')
22
+ .catch(() => 'localhost');
23
+
24
+ export const LOCALHOST = await getLocalhost();
25
+ export const { ETHEREUM_HOSTS = `http://${LOCALHOST}:8545`, PRIVATE_KEY, API_KEY, CLI_VERSION } = process.env;
26
+
27
+ export function addOptions(program: Command, options: Option[]) {
28
+ options.forEach(option => program.addOption(option));
29
+ return program;
30
+ }
31
+
32
+ export const makePxeOption = (mandatory: boolean) =>
33
+ new Option('-u, --rpc-url <string>', 'URL of the PXE')
34
+ .env('PXE_URL')
35
+ .default(`http://${LOCALHOST}:8080`)
36
+ .conflicts('remote-pxe')
37
+ .makeOptionMandatory(mandatory);
38
+
39
+ export const pxeOption = makePxeOption(true);
40
+
41
+ export const l1ChainIdOption = new Option('-c, --l1-chain-id <number>', 'Chain ID of the ethereum host')
42
+ .env('L1_CHAIN_ID')
43
+ .default(31337)
44
+ .argParser(value => {
45
+ const parsedValue = Number(value);
46
+ if (isNaN(parsedValue)) {
47
+ throw new Error('Chain ID must be a number.');
48
+ }
49
+ return parsedValue;
50
+ });
51
+
52
+ export const createSecretKeyOption = (
53
+ description: string,
54
+ mandatory: boolean,
55
+ argsParser?: (value: string, previous: Fr) => Fr,
56
+ ) =>
57
+ new Option('-sk, --secret-key <string>', description)
58
+ .env('SECRET_KEY')
59
+ .argParser(argsParser ?? parseSecretKey)
60
+ .makeOptionMandatory(mandatory);
61
+
62
+ export const logJson = (log: LogFn) => (obj: object) => log(JSON.stringify(obj, null, 2));
63
+
64
+ /**
65
+ * Updates a file in place atomically.
66
+ * @param filePath - Path to file
67
+ * @param contents - New contents to write
68
+ */
69
+ export async function atomicUpdateFile(filePath: string, contents: string) {
70
+ const tmpFilepath = filePath + '.tmp';
71
+ try {
72
+ await writeFile(tmpFilepath, contents, {
73
+ // let's crash if the tmp file already exists
74
+ flag: 'wx',
75
+ });
76
+ await rename(tmpFilepath, filePath);
77
+ } catch (e) {
78
+ if (e instanceof Error && 'code' in e && e.code === 'EEXIST') {
79
+ const commanderError = new CommanderError(
80
+ 1,
81
+ e.code,
82
+ `Temporary file already exists: ${tmpFilepath}. Delete this file and try again.`,
83
+ );
84
+ commanderError.nestedError = e.message;
85
+ throw commanderError;
86
+ } else {
87
+ throw e;
88
+ }
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Utility to select a TX sender either from user input
94
+ * or from the first account that is found in a PXE instance.
95
+ * @param pxe - The PXE instance that will be checked for an account.
96
+ * @param _from - The user input.
97
+ * @returns An Aztec address. Will throw if one can't be found in either options.
98
+ */
99
+ export async function getTxSender(pxe: PXE, _from?: string) {
100
+ let from: AztecAddress;
101
+ if (_from) {
102
+ try {
103
+ from = AztecAddress.fromString(_from);
104
+ } catch {
105
+ throw new InvalidArgumentError(`Invalid option 'from' passed: ${_from}`);
106
+ }
107
+ } else {
108
+ const accounts = await pxe.getRegisteredAccounts();
109
+ if (!accounts.length) {
110
+ throw new Error('No accounts found in PXE instance.');
111
+ }
112
+ from = accounts[0].address;
113
+ }
114
+ return from;
115
+ }
116
+
117
+ /**
118
+ * Removes the leading 0x from a hex string. If no leading 0x is found the string is returned unchanged.
119
+ * @param hex - A hex string
120
+ * @returns A new string with leading 0x removed
121
+ */
122
+ const stripLeadingHex = (hex: string) => {
123
+ if (hex.length > 2 && hex.startsWith('0x')) {
124
+ return hex.substring(2);
125
+ }
126
+ return hex;
127
+ };
128
+
129
+ export function parseBigint(bigint: string): bigint | undefined {
130
+ return bigint ? BigInt(bigint) : undefined;
131
+ }
132
+
133
+ /**
134
+ * Parses a hex encoded string to an Fr integer
135
+ * @param str - Hex encoded string
136
+ * @returns A integer
137
+ */
138
+ export function parseFieldFromHexString(str: string): Fr {
139
+ const hex = stripLeadingHex(str);
140
+
141
+ // ensure it's a hex string
142
+ if (!hex.match(/^[0-9a-f]+$/i)) {
143
+ throw new InvalidArgumentError('Invalid hex string');
144
+ }
145
+
146
+ // pad it so that we may read it as a buffer.
147
+ // Buffer needs _exactly_ two hex characters per byte
148
+ const padded = hex.length % 2 === 1 ? '0' + hex : hex;
149
+ let buf = Buffer.from(padded, 'hex');
150
+ if (buf.length > Fr.SIZE_IN_BYTES) {
151
+ buf = buf.subarray(buf.length - Fr.SIZE_IN_BYTES);
152
+ }
153
+
154
+ const fr = Buffer.alloc(Fr.SIZE_IN_BYTES, 0);
155
+ fr.set(buf, Fr.SIZE_IN_BYTES - buf.length);
156
+
157
+ // finally, turn it into an integer
158
+ return Fr.fromBuffer(fr);
159
+ }
160
+
161
+ /**
162
+ * Parses an AztecAddress from a string.
163
+ * @param address - A serialized Aztec address
164
+ * @returns An Aztec address
165
+ * @throws InvalidArgumentError if the input string is not valid.
166
+ */
167
+ export function parseAztecAddress(address: string): AztecAddress {
168
+ try {
169
+ return AztecAddress.fromString(address);
170
+ } catch {
171
+ throw new InvalidArgumentError(`Invalid address: ${address}`);
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Parses an Ethereum address from a string.
177
+ * @param address - A serialized Ethereum address
178
+ * @returns An Ethereum address
179
+ * @throws InvalidArgumentError if the input string is not valid.
180
+ */
181
+ export function parseEthereumAddress(address: string): EthAddress {
182
+ try {
183
+ return EthAddress.fromString(address);
184
+ } catch {
185
+ throw new InvalidArgumentError(`Invalid address: ${address}`);
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Parses an AztecAddress from a string.
191
+ * @param address - A serialized Aztec address
192
+ * @returns An Aztec address
193
+ * @throws InvalidArgumentError if the input string is not valid.
194
+ */
195
+ export function parseOptionalAztecAddress(address: string): AztecAddress | undefined {
196
+ if (!address) {
197
+ return undefined;
198
+ }
199
+ return parseAztecAddress(address);
200
+ }
201
+
202
+ /**
203
+ * Parses an optional log ID string into a LogId object.
204
+ *
205
+ * @param logId - The log ID string to parse.
206
+ * @returns The parsed LogId object, or undefined if the log ID is missing or empty.
207
+ */
208
+ export function parseOptionalLogId(logId: string): LogId | undefined {
209
+ if (!logId) {
210
+ return undefined;
211
+ }
212
+ return LogId.fromString(logId);
213
+ }
214
+
215
+ /**
216
+ * Parses a selector from a string.
217
+ * @param selector - A serialized selector.
218
+ * @returns A selector.
219
+ * @throws InvalidArgumentError if the input string is not valid.
220
+ */
221
+ export function parseOptionalSelector(selector: string): FunctionSelector | undefined {
222
+ if (!selector) {
223
+ return undefined;
224
+ }
225
+ try {
226
+ return FunctionSelector.fromString(selector);
227
+ } catch {
228
+ throw new InvalidArgumentError(`Invalid selector: ${selector}`);
229
+ }
230
+ }
231
+
232
+ /**
233
+ * Parses a string into an integer or returns undefined if the input is falsy.
234
+ *
235
+ * @param value - The string to parse into an integer.
236
+ * @returns The parsed integer, or undefined if the input string is falsy.
237
+ * @throws If the input is not a valid integer.
238
+ */
239
+ export function parseOptionalInteger(value: string): number | undefined {
240
+ if (!value) {
241
+ return undefined;
242
+ }
243
+ const parsed = Number(value);
244
+ if (!Number.isInteger(parsed)) {
245
+ throw new InvalidArgumentError('Invalid integer.');
246
+ }
247
+ return parsed;
248
+ }
249
+
250
+ /**
251
+ * Parses a TxHash from a string.
252
+ * @param txHash - A transaction hash
253
+ * @returns A TxHash instance
254
+ * @throws InvalidArgumentError if the input string is not valid.
255
+ */
256
+ export function parseTxHash(txHash: string): TxHash {
257
+ try {
258
+ return TxHash.fromString(txHash);
259
+ } catch {
260
+ throw new InvalidArgumentError(`Invalid transaction hash: ${txHash}`);
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Parses an optional TxHash from a string.
266
+ * Calls parseTxHash internally.
267
+ * @param txHash - A transaction hash
268
+ * @returns A TxHash instance, or undefined if the input string is falsy.
269
+ * @throws InvalidArgumentError if the input string is not valid.
270
+ */
271
+ export function parseOptionalTxHash(txHash: string): TxHash | undefined {
272
+ if (!txHash) {
273
+ return undefined;
274
+ }
275
+ return parseTxHash(txHash);
276
+ }
277
+
278
+ /**
279
+ * Parses a public key from a string.
280
+ * @param publicKey - A public keys object serialised as a string
281
+ * @returns A PublicKeys instance
282
+ * @throws InvalidArgumentError if the input string is not valid.
283
+ */
284
+ export function parsePublicKey(publicKey: string): PublicKeys | undefined {
285
+ if (!publicKey) {
286
+ return undefined;
287
+ }
288
+ try {
289
+ return PublicKeys.fromString(publicKey);
290
+ } catch (err) {
291
+ throw new InvalidArgumentError(`Invalid public key: ${publicKey}`);
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Parses a partial address from a string.
297
+ * @param address - A partial address
298
+ * @returns A Fr instance
299
+ * @throws InvalidArgumentError if the input string is not valid.
300
+ */
301
+ export function parsePartialAddress(address: string): Fr {
302
+ try {
303
+ return Fr.fromHexString(address);
304
+ } catch (err) {
305
+ throw new InvalidArgumentError(`Invalid partial address: ${address}`);
306
+ }
307
+ }
308
+
309
+ /**
310
+ * Parses a secret key from a string.
311
+ * @param privateKey - A string
312
+ * @returns A secret key
313
+ * @throws InvalidArgumentError if the input string is not valid.
314
+ */
315
+ export function parseSecretKey(secretKey: string): Fr {
316
+ try {
317
+ return Fr.fromHexString(secretKey);
318
+ } catch (err) {
319
+ throw new InvalidArgumentError(`Invalid encryption secret key: ${secretKey}`);
320
+ }
321
+ }
322
+
323
+ /**
324
+ * Parses a field from a string.
325
+ * @param field - A string representing the field.
326
+ * @returns A field.
327
+ * @throws InvalidArgumentError if the input string is not valid.
328
+ */
329
+ export function parseField(field: string): Fr {
330
+ try {
331
+ const isHex = field.startsWith('0x') || field.match(new RegExp(`^[0-9a-f]{${Fr.SIZE_IN_BYTES * 2}}$`, 'i'));
332
+ if (isHex) {
333
+ return Fr.fromHexString(field);
334
+ }
335
+
336
+ if (['true', 'false'].includes(field)) {
337
+ return new Fr(field === 'true');
338
+ }
339
+
340
+ const isNumber = +field || field === '0';
341
+ if (isNumber) {
342
+ return new Fr(BigInt(field));
343
+ }
344
+
345
+ const isBigInt = field.endsWith('n');
346
+ if (isBigInt) {
347
+ return new Fr(BigInt(field.replace(/n$/, '')));
348
+ }
349
+
350
+ return new Fr(BigInt(field));
351
+ } catch (err) {
352
+ throw new InvalidArgumentError(`Invalid field: ${field}`);
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Parses an array of strings to Frs.
358
+ * @param fields - An array of strings representing the fields.
359
+ * @returns An array of Frs.
360
+ */
361
+ export function parseFields(fields: string[]): Fr[] {
362
+ return fields.map(parseField);
363
+ }
364
+
365
+ /**
366
+ * Pretty prints an object as JSON
367
+ * @param data - The object to stringify
368
+ * @returns A JSON string
369
+ */
370
+ export function prettyPrintJSON(data: Record<string, any>): string {
371
+ return JSON.stringify(
372
+ data,
373
+ (_key, val) => {
374
+ if (typeof val === 'bigint') {
375
+ return String(val);
376
+ } else if (val && typeof val === 'object' && 'toBuffer' in val) {
377
+ return '0x' + val.toBuffer().toString('hex');
378
+ } else {
379
+ return val;
380
+ }
381
+ },
382
+ 2,
383
+ );
384
+ }
@@ -0,0 +1,117 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import type { ABIParameter, AbiType, StructType } from '@aztec/stdlib/abi';
3
+
4
+ /**
5
+ * Parses a hex string into an ABI struct type.
6
+ * @param str - The encoded hex string.
7
+ * @param abiType - The ABI Struct type.
8
+ * @returns An object in the ABI struct type's format.
9
+ */
10
+ export function parseStructString(str: string, abiType: StructType) {
11
+ // Assign string bytes to struct fields.
12
+ const buf = Buffer.from(str.replace(/^0x/i, ''), 'hex');
13
+ const struct: any = {};
14
+ let byteIndex = 0;
15
+ let argIndex = 0;
16
+ while (byteIndex < buf.length) {
17
+ const { name } = abiType.fields[argIndex];
18
+ struct[name] = Fr.fromBuffer(buf.subarray(byteIndex, byteIndex + 32));
19
+ byteIndex += 32;
20
+ argIndex += 1;
21
+ }
22
+
23
+ return struct;
24
+ }
25
+
26
+ /**
27
+ * Helper function to encode CLI string args to an appropriate JS type.
28
+ * @param arg - The CLI argument.
29
+ * @param abiType - The type as described by the contract's ABI.
30
+ * @returns The encoded argument.
31
+ */
32
+ function encodeArg(arg: string, abiType: AbiType, name: string): any {
33
+ const { kind } = abiType;
34
+ if (kind === 'field' || kind === 'integer') {
35
+ let res: bigint;
36
+ try {
37
+ res = BigInt(arg);
38
+ } catch (err) {
39
+ throw new Error(
40
+ `Invalid value passed for ${name}. Could not parse ${arg} as a${kind === 'integer' ? 'n' : ''} ${kind}.`,
41
+ );
42
+ }
43
+ return res;
44
+ } else if (kind === 'boolean') {
45
+ if (arg === 'true') {
46
+ return true;
47
+ }
48
+ if (arg === 'false') {
49
+ return false;
50
+ } else {
51
+ throw Error(`Invalid boolean value passed for ${name}: ${arg}.`);
52
+ }
53
+ } else if (kind === 'string') {
54
+ return arg;
55
+ } else if (kind === 'array') {
56
+ let arr;
57
+ const res = [];
58
+ try {
59
+ arr = JSON.parse(arg);
60
+ } catch {
61
+ throw new Error(`Unable to parse arg ${arg} as array for ${name} parameter`);
62
+ }
63
+ if (!Array.isArray(arr)) {
64
+ throw Error(`Invalid argument ${arg} passed for array parameter ${name}.`);
65
+ }
66
+ if (arr.length !== abiType.length) {
67
+ throw Error(`Invalid array length passed for ${name}. Expected ${abiType.length}, received ${arr.length}.`);
68
+ }
69
+ for (let i = 0; i < abiType.length; i += 1) {
70
+ res.push(encodeArg(arr[i], abiType.type, name));
71
+ }
72
+ return res;
73
+ } else if (kind === 'struct') {
74
+ // check if input is encoded long string
75
+ if (arg.startsWith('0x')) {
76
+ return parseStructString(arg, abiType);
77
+ }
78
+ let obj;
79
+ try {
80
+ obj = JSON.parse(arg);
81
+ } catch {
82
+ throw new Error(`Unable to parse arg ${arg} as struct`);
83
+ }
84
+ if (Array.isArray(obj)) {
85
+ throw Error(`Array passed for arg ${name}. Expected a struct.`);
86
+ }
87
+ const res: any = {};
88
+ for (const field of abiType.fields) {
89
+ // Remove field name from list as it's present
90
+ const arg = obj[field.name];
91
+ if (!arg) {
92
+ throw Error(`Expected field ${field.name} not found in struct ${name}.`);
93
+ }
94
+ res[field.name] = encodeArg(obj[field.name], field.type, field.name);
95
+ }
96
+ return res;
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Tries to encode function args to their equivalent TS type.
102
+ * @param args - An array of function's / constructor's args.
103
+ * @returns The encoded array.
104
+ */
105
+ export function encodeArgs(args: any[], params: ABIParameter[]) {
106
+ if (args.length !== params.length) {
107
+ throw new Error(
108
+ `Invalid args provided.\nExpected args: [${params
109
+ .map(param => param.name + ': ' + param.type.kind)
110
+ .join(', ')}]\nReceived args: ${args.join(', ')}`,
111
+ );
112
+ }
113
+ return args.map((arg: any, index) => {
114
+ const { type, name } = params[index];
115
+ return encodeArg(arg, type, name);
116
+ });
117
+ }
@@ -0,0 +1,3 @@
1
+ export const GITHUB_OWNER = 'AztecProtocol';
2
+ export const GITHUB_REPO = 'aztec-packages';
3
+ export const GITHUB_TAG_PREFIX = 'aztec-packages';
@@ -0,0 +1,4 @@
1
+ export * from './commands.js';
2
+ export * from './aztec.js';
3
+ export * from './encoding.js';
4
+ export * from './github.js';