@aztec/cli 0.0.0-test.0 → 0.0.1-commit.0208eb9

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 (289) hide show
  1. package/README.md +2 -428
  2. package/dest/cmds/aztec_node/block_number.d.ts +3 -0
  3. package/dest/cmds/aztec_node/block_number.d.ts.map +1 -0
  4. package/dest/cmds/aztec_node/block_number.js +10 -0
  5. package/dest/cmds/aztec_node/get_block.d.ts +3 -0
  6. package/dest/cmds/aztec_node/get_block.d.ts.map +1 -0
  7. package/dest/cmds/aztec_node/get_block.js +10 -0
  8. package/dest/cmds/aztec_node/get_current_min_fee.d.ts +3 -0
  9. package/dest/cmds/aztec_node/get_current_min_fee.d.ts.map +1 -0
  10. package/dest/cmds/aztec_node/get_current_min_fee.js +7 -0
  11. package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts +5 -0
  12. package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts.map +1 -0
  13. package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.js +12 -0
  14. package/dest/cmds/aztec_node/get_logs.d.ts +7 -0
  15. package/dest/cmds/aztec_node/get_logs.d.ts.map +1 -0
  16. package/dest/cmds/{pxe → aztec_node}/get_logs.js +4 -4
  17. package/dest/cmds/aztec_node/get_node_info.d.ts +3 -0
  18. package/dest/cmds/aztec_node/get_node_info.d.ts.map +1 -0
  19. package/dest/cmds/{pxe → aztec_node}/get_node_info.js +14 -15
  20. package/dest/cmds/aztec_node/index.d.ts +4 -0
  21. package/dest/cmds/aztec_node/index.d.ts.map +1 -0
  22. package/dest/cmds/aztec_node/index.js +28 -0
  23. package/dest/cmds/contracts/index.d.ts +1 -1
  24. package/dest/cmds/contracts/inspect_contract.d.ts +1 -1
  25. package/dest/cmds/contracts/inspect_contract.d.ts.map +1 -1
  26. package/dest/cmds/contracts/inspect_contract.js +13 -15
  27. package/dest/cmds/contracts/parse_parameter_struct.d.ts +1 -1
  28. package/dest/cmds/infrastructure/index.d.ts +3 -3
  29. package/dest/cmds/infrastructure/index.d.ts.map +1 -1
  30. package/dest/cmds/infrastructure/index.js +8 -10
  31. package/dest/cmds/infrastructure/sequencers.d.ts +5 -6
  32. package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -1
  33. package/dest/cmds/infrastructure/sequencers.js +38 -18
  34. package/dest/cmds/infrastructure/setup_l2_contract.d.ts +2 -2
  35. package/dest/cmds/infrastructure/setup_l2_contract.d.ts.map +1 -1
  36. package/dest/cmds/infrastructure/setup_l2_contract.js +11 -24
  37. package/dest/cmds/l1/advance_epoch.d.ts +2 -2
  38. package/dest/cmds/l1/advance_epoch.d.ts.map +1 -1
  39. package/dest/cmds/l1/advance_epoch.js +8 -6
  40. package/dest/cmds/l1/assume_proven_through.d.ts +3 -2
  41. package/dest/cmds/l1/assume_proven_through.d.ts.map +1 -1
  42. package/dest/cmds/l1/assume_proven_through.js +10 -10
  43. package/dest/cmds/l1/bridge_erc20.d.ts +3 -3
  44. package/dest/cmds/l1/bridge_erc20.d.ts.map +1 -1
  45. package/dest/cmds/l1/bridge_erc20.js +6 -5
  46. package/dest/cmds/l1/compute_genesis_values.d.ts +4 -0
  47. package/dest/cmds/l1/compute_genesis_values.d.ts.map +1 -0
  48. package/dest/cmds/l1/compute_genesis_values.js +17 -0
  49. package/dest/cmds/l1/create_l1_account.d.ts +1 -1
  50. package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts +4 -0
  51. package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts.map +1 -0
  52. package/dest/cmds/l1/deploy_l1_contracts_cmd.js +81 -0
  53. package/dest/cmds/l1/deploy_new_rollup.d.ts +4 -3
  54. package/dest/cmds/l1/deploy_new_rollup.d.ts.map +1 -1
  55. package/dest/cmds/l1/deploy_new_rollup.js +18 -9
  56. package/dest/cmds/l1/get_l1_addresses.d.ts +2 -2
  57. package/dest/cmds/l1/get_l1_addresses.d.ts.map +1 -1
  58. package/dest/cmds/l1/get_l1_addresses.js +5 -2
  59. package/dest/cmds/l1/get_l1_balance.d.ts +1 -1
  60. package/dest/cmds/l1/get_l1_balance.js +4 -2
  61. package/dest/cmds/l1/governance_utils.d.ts +5 -5
  62. package/dest/cmds/l1/governance_utils.d.ts.map +1 -1
  63. package/dest/cmds/l1/governance_utils.js +19 -17
  64. package/dest/cmds/l1/index.d.ts +1 -1
  65. package/dest/cmds/l1/index.d.ts.map +1 -1
  66. package/dest/cmds/l1/index.js +41 -44
  67. package/dest/cmds/l1/prover_stats.d.ts +1 -1
  68. package/dest/cmds/l1/prover_stats.d.ts.map +1 -1
  69. package/dest/cmds/l1/prover_stats.js +32 -30
  70. package/dest/cmds/l1/trigger_seed_snapshot.d.ts +6 -0
  71. package/dest/cmds/l1/trigger_seed_snapshot.d.ts.map +1 -0
  72. package/dest/cmds/l1/trigger_seed_snapshot.js +20 -0
  73. package/dest/cmds/l1/update_l1_validators.d.ts +21 -6
  74. package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
  75. package/dest/cmds/l1/update_l1_validators.js +198 -103
  76. package/dest/cmds/misc/compute_selector.d.ts +1 -1
  77. package/dest/cmds/misc/example_contracts.d.ts +1 -1
  78. package/dest/cmds/misc/generate_bootnode_enr.d.ts +2 -2
  79. package/dest/cmds/misc/generate_bootnode_enr.d.ts.map +1 -1
  80. package/dest/cmds/misc/generate_bootnode_enr.js +2 -2
  81. package/dest/cmds/misc/generate_p2p_private_key.d.ts +1 -1
  82. package/dest/cmds/misc/generate_secret_and_hash.d.ts +2 -2
  83. package/dest/cmds/misc/generate_secret_and_hash.d.ts.map +1 -1
  84. package/dest/cmds/misc/generate_secret_and_hash.js +4 -4
  85. package/dest/cmds/misc/generate_secret_key.d.ts +2 -2
  86. package/dest/cmds/misc/generate_secret_key.d.ts.map +1 -1
  87. package/dest/cmds/misc/generate_secret_key.js +1 -1
  88. package/dest/cmds/misc/get_canonical_sponsored_fpc_address.d.ts +3 -0
  89. package/dest/cmds/misc/get_canonical_sponsored_fpc_address.d.ts.map +1 -0
  90. package/dest/cmds/misc/get_canonical_sponsored_fpc_address.js +4 -0
  91. package/dest/cmds/misc/index.d.ts +1 -1
  92. package/dest/cmds/misc/index.d.ts.map +1 -1
  93. package/dest/cmds/misc/index.js +8 -4
  94. package/dest/cmds/misc/update/common.d.ts +1 -1
  95. package/dest/cmds/misc/update/github.d.ts +1 -2
  96. package/dest/cmds/misc/update/github.d.ts.map +1 -1
  97. package/dest/cmds/misc/update/github.js +0 -1
  98. package/dest/cmds/misc/update/noir.d.ts +1 -1
  99. package/dest/cmds/misc/update/npm.d.ts +1 -1
  100. package/dest/cmds/misc/update/npm.js +1 -1
  101. package/dest/cmds/misc/update/utils.d.ts +1 -1
  102. package/dest/cmds/misc/update.d.ts +1 -1
  103. package/dest/cmds/misc/update.d.ts.map +1 -1
  104. package/dest/cmds/misc/update.js +2 -3
  105. package/dest/cmds/validator_keys/add.d.ts +5 -0
  106. package/dest/cmds/validator_keys/add.d.ts.map +1 -0
  107. package/dest/cmds/validator_keys/add.js +83 -0
  108. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts +12 -0
  109. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts.map +1 -0
  110. package/dest/cmds/validator_keys/generate_bls_keypair.js +27 -0
  111. package/dest/cmds/validator_keys/index.d.ts +4 -0
  112. package/dest/cmds/validator_keys/index.d.ts.map +1 -0
  113. package/dest/cmds/validator_keys/index.js +32 -0
  114. package/dest/cmds/validator_keys/new.d.ts +29 -0
  115. package/dest/cmds/validator_keys/new.d.ts.map +1 -0
  116. package/dest/cmds/validator_keys/new.js +134 -0
  117. package/dest/cmds/validator_keys/shared.d.ts +68 -0
  118. package/dest/cmds/validator_keys/shared.d.ts.map +1 -0
  119. package/dest/cmds/validator_keys/shared.js +274 -0
  120. package/dest/cmds/validator_keys/staker.d.ts +38 -0
  121. package/dest/cmds/validator_keys/staker.d.ts.map +1 -0
  122. package/dest/cmds/validator_keys/staker.js +210 -0
  123. package/dest/cmds/validator_keys/utils.d.ts +25 -0
  124. package/dest/cmds/validator_keys/utils.d.ts.map +1 -0
  125. package/dest/cmds/validator_keys/utils.js +52 -0
  126. package/dest/config/cached_fetch.d.ts +18 -0
  127. package/dest/config/cached_fetch.d.ts.map +1 -0
  128. package/dest/config/cached_fetch.js +54 -0
  129. package/dest/config/chain_l2_config.d.ts +14 -0
  130. package/dest/config/chain_l2_config.d.ts.map +1 -0
  131. package/dest/config/chain_l2_config.js +45 -0
  132. package/dest/config/enrich_env.d.ts +4 -0
  133. package/dest/config/enrich_env.d.ts.map +1 -0
  134. package/dest/config/enrich_env.js +12 -0
  135. package/dest/config/generated/networks.d.ts +205 -0
  136. package/dest/config/generated/networks.d.ts.map +1 -0
  137. package/dest/config/generated/networks.js +206 -0
  138. package/dest/config/get_l1_config.d.ts +9 -0
  139. package/dest/config/get_l1_config.d.ts.map +1 -0
  140. package/dest/config/get_l1_config.js +24 -0
  141. package/dest/config/index.d.ts +5 -0
  142. package/dest/config/index.d.ts.map +1 -0
  143. package/dest/config/index.js +4 -0
  144. package/dest/config/network_config.d.ts +22 -0
  145. package/dest/config/network_config.d.ts.map +1 -0
  146. package/dest/config/network_config.js +115 -0
  147. package/dest/utils/aztec.d.ts +15 -26
  148. package/dest/utils/aztec.d.ts.map +1 -1
  149. package/dest/utils/aztec.js +56 -72
  150. package/dest/utils/commands.d.ts +22 -13
  151. package/dest/utils/commands.d.ts.map +1 -1
  152. package/dest/utils/commands.js +43 -16
  153. package/dest/utils/encoding.d.ts +1 -1
  154. package/dest/utils/encoding.js +2 -2
  155. package/dest/utils/github.d.ts +1 -2
  156. package/dest/utils/github.d.ts.map +1 -1
  157. package/dest/utils/github.js +0 -1
  158. package/dest/utils/index.d.ts +2 -1
  159. package/dest/utils/index.d.ts.map +1 -1
  160. package/dest/utils/index.js +1 -0
  161. package/dest/utils/inspect.d.ts +5 -11
  162. package/dest/utils/inspect.d.ts.map +1 -1
  163. package/dest/utils/inspect.js +23 -110
  164. package/dest/utils/setup_contracts.d.ts +3 -0
  165. package/dest/utils/setup_contracts.d.ts.map +1 -0
  166. package/dest/utils/setup_contracts.js +16 -0
  167. package/package.json +61 -37
  168. package/public_include_metric_prefixes.json +1 -0
  169. package/src/cmds/aztec_node/block_number.ts +9 -0
  170. package/src/cmds/aztec_node/get_block.ts +11 -0
  171. package/src/cmds/aztec_node/get_current_min_fee.ts +9 -0
  172. package/src/cmds/aztec_node/get_l1_to_l2_message_witness.ts +27 -0
  173. package/src/cmds/{pxe → aztec_node}/get_logs.ts +11 -9
  174. package/src/cmds/{pxe → aztec_node}/get_node_info.ts +15 -23
  175. package/src/cmds/aztec_node/index.ts +87 -0
  176. package/src/cmds/contracts/inspect_contract.ts +20 -17
  177. package/src/cmds/infrastructure/index.ts +8 -11
  178. package/src/cmds/infrastructure/sequencers.ts +41 -22
  179. package/src/cmds/infrastructure/setup_l2_contract.ts +13 -25
  180. package/src/cmds/l1/advance_epoch.ts +7 -5
  181. package/src/cmds/l1/assume_proven_through.ts +11 -10
  182. package/src/cmds/l1/bridge_erc20.ts +8 -4
  183. package/src/cmds/l1/compute_genesis_values.ts +29 -0
  184. package/src/cmds/l1/deploy_l1_contracts_cmd.ts +107 -0
  185. package/src/cmds/l1/deploy_new_rollup.ts +24 -15
  186. package/src/cmds/l1/get_l1_addresses.ts +5 -3
  187. package/src/cmds/l1/get_l1_balance.ts +2 -2
  188. package/src/cmds/l1/governance_utils.ts +20 -24
  189. package/src/cmds/l1/index.ts +87 -113
  190. package/src/cmds/l1/prover_stats.ts +42 -31
  191. package/src/cmds/l1/trigger_seed_snapshot.ts +32 -0
  192. package/src/cmds/l1/update_l1_validators.ts +218 -97
  193. package/src/cmds/misc/generate_bootnode_enr.ts +3 -2
  194. package/src/cmds/misc/generate_secret_and_hash.ts +4 -4
  195. package/src/cmds/misc/generate_secret_key.ts +1 -1
  196. package/src/cmds/misc/get_canonical_sponsored_fpc_address.ts +7 -0
  197. package/src/cmds/misc/index.ts +14 -5
  198. package/src/cmds/misc/update/github.ts +0 -1
  199. package/src/cmds/misc/update/npm.ts +1 -1
  200. package/src/cmds/misc/update.ts +1 -7
  201. package/src/cmds/validator_keys/add.ts +123 -0
  202. package/src/cmds/validator_keys/generate_bls_keypair.ts +34 -0
  203. package/src/cmds/validator_keys/index.ts +142 -0
  204. package/src/cmds/validator_keys/new.ts +207 -0
  205. package/src/cmds/validator_keys/shared.ts +326 -0
  206. package/src/cmds/validator_keys/staker.ts +301 -0
  207. package/src/cmds/validator_keys/utils.ts +81 -0
  208. package/src/config/cached_fetch.ts +67 -0
  209. package/src/config/chain_l2_config.ts +57 -0
  210. package/src/config/enrich_env.ts +15 -0
  211. package/src/config/generated/networks.ts +210 -0
  212. package/src/config/get_l1_config.ts +31 -0
  213. package/src/config/index.ts +4 -0
  214. package/src/config/network_config.ts +147 -0
  215. package/src/utils/aztec.ts +74 -120
  216. package/src/utils/commands.ts +57 -20
  217. package/src/utils/encoding.ts +2 -2
  218. package/src/utils/github.ts +0 -1
  219. package/src/utils/index.ts +1 -0
  220. package/src/utils/inspect.ts +28 -124
  221. package/src/utils/setup_contracts.ts +19 -0
  222. package/dest/cmds/devnet/bootstrap_network.d.ts +0 -3
  223. package/dest/cmds/devnet/bootstrap_network.d.ts.map +0 -1
  224. package/dest/cmds/devnet/bootstrap_network.js +0 -196
  225. package/dest/cmds/devnet/faucet.d.ts +0 -4
  226. package/dest/cmds/devnet/faucet.d.ts.map +0 -1
  227. package/dest/cmds/devnet/faucet.js +0 -26
  228. package/dest/cmds/devnet/index.d.ts +0 -4
  229. package/dest/cmds/devnet/index.d.ts.map +0 -1
  230. package/dest/cmds/devnet/index.js +0 -14
  231. package/dest/cmds/l1/deploy_l1_contracts.d.ts +0 -4
  232. package/dest/cmds/l1/deploy_l1_contracts.d.ts.map +0 -1
  233. package/dest/cmds/l1/deploy_l1_contracts.js +0 -29
  234. package/dest/cmds/l1/deploy_l1_verifier.d.ts +0 -5
  235. package/dest/cmds/l1/deploy_l1_verifier.d.ts.map +0 -1
  236. package/dest/cmds/l1/deploy_l1_verifier.js +0 -54
  237. package/dest/cmds/misc/setup_contracts.d.ts +0 -7
  238. package/dest/cmds/misc/setup_contracts.d.ts.map +0 -1
  239. package/dest/cmds/misc/setup_contracts.js +0 -27
  240. package/dest/cmds/pxe/add_contract.d.ts +0 -5
  241. package/dest/cmds/pxe/add_contract.d.ts.map +0 -1
  242. package/dest/cmds/pxe/add_contract.js +0 -29
  243. package/dest/cmds/pxe/block_number.d.ts +0 -3
  244. package/dest/cmds/pxe/block_number.d.ts.map +0 -1
  245. package/dest/cmds/pxe/block_number.js +0 -10
  246. package/dest/cmds/pxe/get_account.d.ts +0 -4
  247. package/dest/cmds/pxe/get_account.d.ts.map +0 -1
  248. package/dest/cmds/pxe/get_account.js +0 -10
  249. package/dest/cmds/pxe/get_accounts.d.ts +0 -3
  250. package/dest/cmds/pxe/get_accounts.d.ts.map +0 -1
  251. package/dest/cmds/pxe/get_accounts.js +0 -25
  252. package/dest/cmds/pxe/get_block.d.ts +0 -3
  253. package/dest/cmds/pxe/get_block.d.ts.map +0 -1
  254. package/dest/cmds/pxe/get_block.js +0 -9
  255. package/dest/cmds/pxe/get_contract_data.d.ts +0 -4
  256. package/dest/cmds/pxe/get_contract_data.d.ts.map +0 -1
  257. package/dest/cmds/pxe/get_contract_data.js +0 -31
  258. package/dest/cmds/pxe/get_current_base_fee.d.ts +0 -3
  259. package/dest/cmds/pxe/get_current_base_fee.d.ts.map +0 -1
  260. package/dest/cmds/pxe/get_current_base_fee.js +0 -7
  261. package/dest/cmds/pxe/get_l1_to_l2_message_witness.d.ts +0 -4
  262. package/dest/cmds/pxe/get_l1_to_l2_message_witness.d.ts.map +0 -1
  263. package/dest/cmds/pxe/get_l1_to_l2_message_witness.js +0 -11
  264. package/dest/cmds/pxe/get_logs.d.ts +0 -4
  265. package/dest/cmds/pxe/get_logs.d.ts.map +0 -1
  266. package/dest/cmds/pxe/get_node_info.d.ts +0 -3
  267. package/dest/cmds/pxe/get_node_info.d.ts.map +0 -1
  268. package/dest/cmds/pxe/get_pxe_info.d.ts +0 -3
  269. package/dest/cmds/pxe/get_pxe_info.d.ts.map +0 -1
  270. package/dest/cmds/pxe/get_pxe_info.js +0 -11
  271. package/dest/cmds/pxe/index.d.ts +0 -4
  272. package/dest/cmds/pxe/index.d.ts.map +0 -1
  273. package/dest/cmds/pxe/index.js +0 -55
  274. package/src/cmds/devnet/bootstrap_network.ts +0 -318
  275. package/src/cmds/devnet/faucet.ts +0 -33
  276. package/src/cmds/devnet/index.ts +0 -60
  277. package/src/cmds/l1/deploy_l1_contracts.ts +0 -65
  278. package/src/cmds/l1/deploy_l1_verifier.ts +0 -105
  279. package/src/cmds/misc/setup_contracts.ts +0 -40
  280. package/src/cmds/pxe/add_contract.ts +0 -41
  281. package/src/cmds/pxe/block_number.ts +0 -9
  282. package/src/cmds/pxe/get_account.ts +0 -16
  283. package/src/cmds/pxe/get_accounts.ts +0 -35
  284. package/src/cmds/pxe/get_block.ts +0 -10
  285. package/src/cmds/pxe/get_contract_data.ts +0 -51
  286. package/src/cmds/pxe/get_current_base_fee.ts +0 -9
  287. package/src/cmds/pxe/get_l1_to_l2_message_witness.ts +0 -25
  288. package/src/cmds/pxe/get_pxe_info.ts +0 -13
  289. package/src/cmds/pxe/index.ts +0 -170
@@ -0,0 +1,326 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/utils';
2
+ import { deriveBlsPrivateKey } from '@aztec/foundation/crypto/bls';
3
+ import { createBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
4
+ import { computeBn254G1PublicKeyCompressed } from '@aztec/foundation/crypto/bn254';
5
+ import type { EthAddress } from '@aztec/foundation/eth-address';
6
+ import type { LogFn } from '@aztec/foundation/log';
7
+ import type { EthAccount, EthPrivateKey, ValidatorKeyStore } from '@aztec/node-keystore/types';
8
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
9
+
10
+ import { Wallet } from '@ethersproject/wallet';
11
+ import { constants as fsConstants, mkdirSync } from 'fs';
12
+ import { access, writeFile } from 'fs/promises';
13
+ import { homedir } from 'os';
14
+ import { dirname, isAbsolute, join } from 'path';
15
+ import { mnemonicToAccount } from 'viem/accounts';
16
+
17
+ import { defaultBlsPath } from './utils.js';
18
+
19
+ export type ValidatorSummary = { attesterEth?: string; attesterBls?: string; publisherEth?: string[] };
20
+
21
+ export type BuildValidatorsInput = {
22
+ validatorCount: number;
23
+ publisherCount?: number;
24
+ publishers?: string[];
25
+ accountIndex: number;
26
+ baseAddressIndex: number;
27
+ mnemonic: string;
28
+ ikm?: string;
29
+ blsPath?: string;
30
+ feeRecipient: AztecAddress;
31
+ coinbase?: EthAddress;
32
+ remoteSigner?: string;
33
+ };
34
+
35
+ export function withValidatorIndex(path: string, accountIndex: number = 0, addressIndex: number = 0) {
36
+ // NOTE: The legacy BLS CLI is to allow users who generated keys in 2.1.4 to be able to use the same command
37
+ // to re-generate their keys. In 2.1.5 we switched how we append addresses to the path so this is to maintain backwards compatibility.
38
+ const useLegacyBlsCli = ['true', '1', 'yes', 'y'].includes(process.env.LEGACY_BLS_CLI ?? '');
39
+
40
+ const defaultBlsPathParts = defaultBlsPath.split('/');
41
+
42
+ const parts = path.split('/');
43
+ if (parts.length == defaultBlsPathParts.length && parts.every((part, index) => part === defaultBlsPathParts[index])) {
44
+ if (useLegacyBlsCli) {
45
+ // In 2.1.4, we were using address-index in parts[3] and did NOT use account-index, check lines 32 & 84
46
+ // https://github.com/AztecProtocol/aztec-packages/blob/v2.1.4/yarn-project/cli/src/cmds/validator_keys/shared.ts
47
+
48
+ parts[3] = String(addressIndex);
49
+ } else {
50
+ parts[3] = String(accountIndex);
51
+ parts[5] = String(addressIndex);
52
+ }
53
+ return parts.join('/');
54
+ }
55
+ return path;
56
+ }
57
+
58
+ /**
59
+ * Compute a compressed BN254 G1 public key from a private key.
60
+ * @param privateKeyHex - Private key as 0x-prefixed hex string
61
+ * @returns Compressed G1 point (32 bytes with sign bit in MSB)
62
+ */
63
+ export async function computeBlsPublicKeyCompressed(privateKeyHex: string): Promise<string> {
64
+ return await computeBn254G1PublicKeyCompressed(privateKeyHex);
65
+ }
66
+
67
+ export function deriveEthAttester(
68
+ mnemonic: string,
69
+ baseAccountIndex: number,
70
+ addressIndex: number,
71
+ remoteSigner?: string,
72
+ ): EthAccount | EthPrivateKey {
73
+ const acct = mnemonicToAccount(mnemonic, { accountIndex: baseAccountIndex, addressIndex });
74
+ return remoteSigner
75
+ ? ({ address: acct.address as unknown as EthAddress, remoteSignerUrl: remoteSigner } as EthAccount)
76
+ : (('0x' + Buffer.from(acct.getHdKey().privateKey!).toString('hex')) as EthPrivateKey);
77
+ }
78
+
79
+ export async function buildValidatorEntries(input: BuildValidatorsInput) {
80
+ const {
81
+ validatorCount,
82
+ publisherCount = 0,
83
+ publishers,
84
+ accountIndex,
85
+ baseAddressIndex,
86
+ mnemonic,
87
+ ikm,
88
+ blsPath,
89
+ feeRecipient,
90
+ coinbase,
91
+ remoteSigner,
92
+ } = input;
93
+
94
+ const summaries: ValidatorSummary[] = [];
95
+
96
+ const validators = await Promise.all(
97
+ Array.from({ length: validatorCount }, async (_unused, i) => {
98
+ const addressIndex = baseAddressIndex + i;
99
+ const basePath = blsPath ?? defaultBlsPath;
100
+ const perValidatorPath = withValidatorIndex(basePath, accountIndex, addressIndex);
101
+
102
+ const blsPrivKey = ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
103
+ const blsPubCompressed = blsPrivKey ? await computeBlsPublicKeyCompressed(blsPrivKey) : undefined;
104
+
105
+ const ethAttester = deriveEthAttester(mnemonic, accountIndex, addressIndex, remoteSigner);
106
+ const attester = blsPrivKey ? { eth: ethAttester, bls: blsPrivKey } : ethAttester;
107
+
108
+ let publisherField: EthAccount | EthPrivateKey | (EthAccount | EthPrivateKey)[] | undefined;
109
+ const publisherAddresses: string[] = [];
110
+ if (publishers && publishers.length > 0) {
111
+ publisherAddresses.push(...publishers);
112
+ publisherField = publishers.length === 1 ? (publishers[0] as EthPrivateKey) : (publishers as EthPrivateKey[]);
113
+ } else if (publisherCount > 0) {
114
+ const publishersBaseIndex = baseAddressIndex + validatorCount + i * publisherCount;
115
+ const publisherAccounts = Array.from({ length: publisherCount }, (_unused2, j) => {
116
+ const publisherAddressIndex = publishersBaseIndex + j;
117
+ const pubAcct = mnemonicToAccount(mnemonic, {
118
+ accountIndex,
119
+ addressIndex: publisherAddressIndex,
120
+ });
121
+ publisherAddresses.push(pubAcct.address as unknown as string);
122
+ return remoteSigner
123
+ ? ({ address: pubAcct.address as unknown as EthAddress, remoteSignerUrl: remoteSigner } as EthAccount)
124
+ : (('0x' + Buffer.from(pubAcct.getHdKey().privateKey!).toString('hex')) as EthPrivateKey);
125
+ });
126
+ publisherField = publisherCount === 1 ? publisherAccounts[0] : publisherAccounts;
127
+ }
128
+
129
+ const acct = mnemonicToAccount(mnemonic, {
130
+ accountIndex,
131
+ addressIndex,
132
+ });
133
+ const attesterEthAddress = acct.address as unknown as string;
134
+ summaries.push({
135
+ attesterEth: attesterEthAddress,
136
+ attesterBls: blsPubCompressed,
137
+ publisherEth: publisherAddresses.length > 0 ? publisherAddresses : undefined,
138
+ });
139
+
140
+ return {
141
+ attester,
142
+ ...(publisherField !== undefined ? { publisher: publisherField } : {}),
143
+ feeRecipient,
144
+ coinbase: coinbase ?? attesterEthAddress,
145
+ } as ValidatorKeyStore;
146
+ }),
147
+ );
148
+
149
+ return { validators, summaries };
150
+ }
151
+
152
+ export async function resolveKeystoreOutputPath(dataDir?: string, file?: string) {
153
+ const defaultDataDir = join(homedir(), '.aztec', 'keystore');
154
+ const resolvedDir = dataDir && dataDir.length > 0 ? dataDir : defaultDataDir;
155
+ let outputPath: string;
156
+ if (file && file.length > 0) {
157
+ outputPath = isAbsolute(file) ? file : join(resolvedDir, file);
158
+ } else {
159
+ let index = 1;
160
+ while (true) {
161
+ const candidate = join(resolvedDir, `key${index}.json`);
162
+ try {
163
+ await access(candidate, fsConstants.F_OK);
164
+ index += 1;
165
+ } catch {
166
+ outputPath = candidate;
167
+ break;
168
+ }
169
+ }
170
+ }
171
+ return { resolvedDir, outputPath: outputPath! };
172
+ }
173
+
174
+ export async function writeKeystoreFile(path: string, keystore: unknown) {
175
+ mkdirSync(dirname(path), { recursive: true });
176
+ await writeFile(path, JSON.stringify(keystore, null, 2), { encoding: 'utf-8' });
177
+ }
178
+
179
+ export function logValidatorSummaries(log: LogFn, summaries: ValidatorSummary[]) {
180
+ const lines: string[] = [];
181
+ for (let i = 0; i < summaries.length; i++) {
182
+ const v = summaries[i];
183
+ lines.push(`acc${i + 1}:`);
184
+ lines.push(` attester:`);
185
+ if (v.attesterEth) {
186
+ lines.push(` eth: ${v.attesterEth}`);
187
+ }
188
+ if (v.attesterBls) {
189
+ lines.push(` bls: ${v.attesterBls}`);
190
+ }
191
+ if (v.publisherEth && v.publisherEth.length > 0) {
192
+ lines.push(` publisher:`);
193
+ for (const addr of v.publisherEth) {
194
+ lines.push(` - ${addr}`);
195
+ }
196
+ }
197
+ }
198
+ if (lines.length > 0) {
199
+ log(lines.join('\n'));
200
+ }
201
+ }
202
+
203
+ export function maybePrintJson(log: LogFn, jsonFlag: boolean | undefined, obj: unknown) {
204
+ if (jsonFlag) {
205
+ log(prettyPrintJSON(obj as Record<string, any>));
206
+ }
207
+ }
208
+
209
+ /**
210
+ * Writes a BN254 keystore file for a BN254 BLS private key.
211
+ * Returns the absolute path to the written file.
212
+ *
213
+ * @param outDir - Directory to write the keystore file to
214
+ * @param fileNameBase - Base name for the keystore file (will be sanitized)
215
+ * @param password - Password for encrypting the private key
216
+ * @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
217
+ * @param pubkeyHex - Public key as hex string
218
+ * @param derivationPath - BIP-44 style derivation path
219
+ * @returns Absolute path to the written keystore file
220
+ */
221
+ export async function writeBn254BlsKeystore(
222
+ outDir: string,
223
+ fileNameBase: string,
224
+ password: string,
225
+ privateKeyHex: string,
226
+ pubkeyHex: string,
227
+ derivationPath: string,
228
+ ): Promise<string> {
229
+ mkdirSync(outDir, { recursive: true });
230
+
231
+ const keystore = createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath);
232
+
233
+ const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
234
+ const outPath = join(outDir, `keystore-${safeBase}.json`);
235
+ await writeFile(outPath, JSON.stringify(keystore, null, 2), { encoding: 'utf-8' });
236
+ return outPath;
237
+ }
238
+
239
+ /** Replace plaintext BLS keys in validators with { path, password } pointing to BN254 keystore files. */
240
+ export async function writeBlsBn254ToFile(
241
+ validators: ValidatorKeyStore[],
242
+ options: { outDir: string; password: string; blsPath?: string },
243
+ ): Promise<void> {
244
+ for (let i = 0; i < validators.length; i++) {
245
+ const v = validators[i];
246
+ if (!v || typeof v !== 'object' || !('attester' in v)) {
247
+ continue;
248
+ }
249
+ const att = (v as any).attester;
250
+
251
+ // Shapes: { bls: <hex> } or { eth: <ethAccount>, bls?: <hex> } or plain EthAccount
252
+ const blsKey: string | undefined = typeof att === 'object' && 'bls' in att ? (att as any).bls : undefined;
253
+ if (!blsKey || typeof blsKey !== 'string') {
254
+ continue;
255
+ }
256
+
257
+ const pub = await computeBlsPublicKeyCompressed(blsKey);
258
+ const path = options.blsPath ?? defaultBlsPath;
259
+ const fileBase = `${String(i + 1)}_${pub.slice(2, 18)}`;
260
+ const keystorePath = await writeBn254BlsKeystore(options.outDir, fileBase, options.password, blsKey, pub, path);
261
+
262
+ if (typeof att === 'object') {
263
+ (att as any).bls = { path: keystorePath, password: options.password };
264
+ }
265
+ }
266
+ }
267
+
268
+ /** Writes an Ethereum JSON V3 keystore using ethers, returns absolute path */
269
+ export async function writeEthJsonV3Keystore(
270
+ outDir: string,
271
+ fileNameBase: string,
272
+ password: string,
273
+ privateKeyHex: string,
274
+ ): Promise<string> {
275
+ const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
276
+ mkdirSync(outDir, { recursive: true });
277
+ const wallet = new Wallet(privateKeyHex);
278
+ const json = await wallet.encrypt(password);
279
+ const outPath = join(outDir, `keystore-eth-${safeBase}.json`);
280
+ await writeFile(outPath, json, { encoding: 'utf-8' });
281
+ return outPath;
282
+ }
283
+
284
+ /** Replace plaintext ETH keys in validators with { path, password } pointing to JSON V3 files. */
285
+ export async function writeEthJsonV3ToFile(
286
+ validators: ValidatorKeyStore[],
287
+ options: { outDir: string; password: string },
288
+ ): Promise<void> {
289
+ const maybeEncryptEth = async (account: any, label: string) => {
290
+ if (typeof account === 'string' && account.startsWith('0x') && account.length === 66) {
291
+ const fileBase = `${label}_${account.slice(2, 10)}`;
292
+ const p = await writeEthJsonV3Keystore(options.outDir, fileBase, options.password, account);
293
+ return { path: p, password: options.password };
294
+ }
295
+ return account;
296
+ };
297
+
298
+ for (let i = 0; i < validators.length; i++) {
299
+ const v = validators[i];
300
+ if (!v || typeof v !== 'object') {
301
+ continue;
302
+ }
303
+
304
+ // attester may be string (eth), object with eth, or remote signer
305
+ const att = (v as any).attester;
306
+ if (typeof att === 'string') {
307
+ (v as any).attester = await maybeEncryptEth(att, `attester_${i + 1}`);
308
+ } else if (att && typeof att === 'object' && 'eth' in att) {
309
+ (att as any).eth = await maybeEncryptEth((att as any).eth, `attester_${i + 1}`);
310
+ }
311
+
312
+ // publisher can be single or array
313
+ if ('publisher' in v) {
314
+ const pub = (v as any).publisher;
315
+ if (Array.isArray(pub)) {
316
+ const out: any[] = [];
317
+ for (let j = 0; j < pub.length; j++) {
318
+ out.push(await maybeEncryptEth(pub[j], `publisher_${i + 1}_${j + 1}`));
319
+ }
320
+ (v as any).publisher = out;
321
+ } else if (pub !== undefined) {
322
+ (v as any).publisher = await maybeEncryptEth(pub, `publisher_${i + 1}`);
323
+ }
324
+ }
325
+ }
326
+ }
@@ -0,0 +1,301 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/utils';
2
+ import { createEthereumChain } from '@aztec/ethereum/chain';
3
+ import { GSEContract } from '@aztec/ethereum/contracts';
4
+ import { decryptBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
5
+ import { computeBn254G1PublicKey, computeBn254G2PublicKey } from '@aztec/foundation/crypto/bn254';
6
+ import { Fr } from '@aztec/foundation/curves/bn254';
7
+ import type { EthAddress } from '@aztec/foundation/eth-address';
8
+ import type { LogFn } from '@aztec/foundation/log';
9
+ import { loadKeystoreFile } from '@aztec/node-keystore/loader';
10
+ import type {
11
+ AttesterAccount,
12
+ AttesterAccounts,
13
+ BLSAccount,
14
+ EncryptedKeyFileConfig,
15
+ EthAccount,
16
+ MnemonicConfig,
17
+ } from '@aztec/node-keystore/types';
18
+
19
+ import { Wallet } from '@ethersproject/wallet';
20
+ import { readFileSync, writeFileSync } from 'fs';
21
+ import { basename, dirname, join } from 'path';
22
+ import { createPublicClient, fallback, http } from 'viem';
23
+ import { privateKeyToAddress } from 'viem/accounts';
24
+
25
+ export type StakerOptions = {
26
+ from: string;
27
+ password?: string;
28
+ output?: string;
29
+ gseAddress: EthAddress;
30
+ l1RpcUrls: string[];
31
+ l1ChainId: number;
32
+ };
33
+
34
+ export type StakerOutput = {
35
+ attester: string;
36
+ publicKeyG1: {
37
+ x: string;
38
+ y: string;
39
+ };
40
+ publicKeyG2: {
41
+ x0: string;
42
+ x1: string;
43
+ y0: string;
44
+ y1: string;
45
+ };
46
+ proofOfPossession: {
47
+ x: string;
48
+ y: string;
49
+ };
50
+ };
51
+
52
+ /**
53
+ * Check if an object is a MnemonicConfig
54
+ */
55
+ function isMnemonicConfig(obj: unknown): obj is MnemonicConfig {
56
+ return typeof obj === 'object' && obj !== null && 'mnemonic' in obj;
57
+ }
58
+
59
+ /**
60
+ * Check if a value is an encrypted keystore file config
61
+ */
62
+ function isEncryptedKeyFileConfig(value: unknown): value is EncryptedKeyFileConfig {
63
+ return typeof value === 'object' && value !== null && 'path' in value;
64
+ }
65
+
66
+ /**
67
+ * Check if a BLSAccount is a private key string (not an encrypted keystore file)
68
+ */
69
+ function isBlsPrivateKey(bls: unknown): bls is string {
70
+ return typeof bls === 'string' && bls.startsWith('0x');
71
+ }
72
+
73
+ /**
74
+ * Check if an EthAccount is a private key string (66 chars: 0x + 64 hex)
75
+ */
76
+ function isEthPrivateKey(eth: unknown): eth is string {
77
+ return typeof eth === 'string' && eth.startsWith('0x') && eth.length === 66;
78
+ }
79
+
80
+ /**
81
+ * Check if a string is an Ethereum address (42 chars: 0x + 40 hex)
82
+ */
83
+ function isEthAddress(value: unknown): value is string {
84
+ return typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value);
85
+ }
86
+
87
+ /**
88
+ * Decrypt a BLS private key from an encrypted keystore file
89
+ */
90
+ function decryptBlsKey(bls: BLSAccount, password?: string): string | undefined {
91
+ if (isBlsPrivateKey(bls)) {
92
+ return bls;
93
+ }
94
+
95
+ if (isEncryptedKeyFileConfig(bls)) {
96
+ if (!password && !bls.password) {
97
+ return undefined; // Can't decrypt without password
98
+ }
99
+ const pwd = password ?? bls.password!;
100
+ return decryptBn254Keystore(bls.path, pwd);
101
+ }
102
+
103
+ return undefined;
104
+ }
105
+
106
+ /**
107
+ * Decrypt an Ethereum private key from an encrypted keystore file
108
+ */
109
+ async function decryptEthKey(eth: EthAccount, password?: string): Promise<string | undefined> {
110
+ if (isEthPrivateKey(eth)) {
111
+ return eth;
112
+ }
113
+
114
+ if (isEncryptedKeyFileConfig(eth)) {
115
+ if (!password && !eth.password) {
116
+ return undefined; // Can't decrypt without password
117
+ }
118
+ const pwd = password ?? eth.password!;
119
+ const json = readFileSync(eth.path, 'utf-8');
120
+ const wallet = await Wallet.fromEncryptedJson(json, pwd);
121
+ return wallet.privateKey as string;
122
+ }
123
+
124
+ return undefined;
125
+ }
126
+
127
+ /**
128
+ * Extract Ethereum address from an EthAccount (or private key)
129
+ */
130
+ async function getEthAddress(eth: EthAccount | string, password?: string): Promise<EthAddress | undefined> {
131
+ // Case 1: It's a private key string - derive the address
132
+ if (isEthPrivateKey(eth)) {
133
+ return privateKeyToAddress(eth as `0x${string}`) as unknown as EthAddress;
134
+ }
135
+
136
+ // Case 2: It's just an address string directly (EthRemoteSignerAccount can be just EthAddress)
137
+ if (isEthAddress(eth)) {
138
+ return eth as unknown as EthAddress;
139
+ }
140
+
141
+ // Case 3: It's an object with an address property (remote signer config)
142
+ if (typeof eth === 'object' && eth !== null && 'address' in eth) {
143
+ return (eth as any).address as EthAddress;
144
+ }
145
+
146
+ // Case 4: It's an encrypted keystore file - decrypt and derive address
147
+ if (isEncryptedKeyFileConfig(eth)) {
148
+ const privateKey = await decryptEthKey(eth, password);
149
+ if (privateKey) {
150
+ return privateKeyToAddress(privateKey as `0x${string}`) as unknown as EthAddress;
151
+ }
152
+ return undefined;
153
+ }
154
+
155
+ return undefined;
156
+ }
157
+
158
+ /**
159
+ * Extract BLS private key and Ethereum address from an AttesterAccount
160
+ */
161
+ async function extractAttesterInfo(
162
+ attester: AttesterAccount,
163
+ password?: string,
164
+ ): Promise<{ blsPrivateKey?: string; ethAddress?: EthAddress }> {
165
+ // Case 1: attester is { eth: EthAccount, bls?: BLSAccount }
166
+ if (typeof attester === 'object' && attester !== null && 'eth' in attester) {
167
+ const ethAddress = await getEthAddress(attester.eth, password);
168
+ const blsPrivateKey = attester.bls ? decryptBlsKey(attester.bls, password) : undefined;
169
+ return { blsPrivateKey, ethAddress };
170
+ }
171
+
172
+ // Case 2: attester is just an EthAccount directly (no BLS key)
173
+ return {
174
+ blsPrivateKey: undefined,
175
+ ethAddress: await getEthAddress(attester as EthAccount, password),
176
+ };
177
+ }
178
+
179
+ /**
180
+ * Process a single attester entry and output staking JSON
181
+ */
182
+ async function processAttester(
183
+ attester: AttesterAccount,
184
+ gse: GSEContract,
185
+ password?: string,
186
+ ): Promise<StakerOutput | undefined> {
187
+ const { blsPrivateKey, ethAddress } = await extractAttesterInfo(attester, password);
188
+
189
+ // Skip if no BLS private key or no Ethereum address
190
+ if (!blsPrivateKey || !ethAddress) {
191
+ return undefined;
192
+ }
193
+
194
+ // Derive G1 and G2 public keys
195
+ const g1PublicKey = await computeBn254G1PublicKey(blsPrivateKey);
196
+ const g2PublicKey = await computeBn254G2PublicKey(blsPrivateKey);
197
+
198
+ // Generate proof of possession
199
+ const bn254SecretKeyFieldElement = Fr.fromString(blsPrivateKey);
200
+ const registrationTuple = await gse.makeRegistrationTuple(bn254SecretKeyFieldElement.toBigInt());
201
+
202
+ return {
203
+ attester: String(ethAddress),
204
+ publicKeyG1: {
205
+ x: '0x' + g1PublicKey.x.toString(16).padStart(64, '0'),
206
+ y: '0x' + g1PublicKey.y.toString(16).padStart(64, '0'),
207
+ },
208
+ publicKeyG2: {
209
+ x0: '0x' + g2PublicKey.x.c0.toString(16).padStart(64, '0'),
210
+ x1: '0x' + g2PublicKey.x.c1.toString(16).padStart(64, '0'),
211
+ y0: '0x' + g2PublicKey.y.c0.toString(16).padStart(64, '0'),
212
+ y1: '0x' + g2PublicKey.y.c1.toString(16).padStart(64, '0'),
213
+ },
214
+ proofOfPossession: {
215
+ x: '0x' + registrationTuple.proofOfPossession.x.toString(16),
216
+ y: '0x' + registrationTuple.proofOfPossession.y.toString(16),
217
+ },
218
+ };
219
+ }
220
+
221
+ /**
222
+ * Process AttesterAccounts (which can be a single attester, array, or mnemonic)
223
+ */
224
+ export async function processAttesterAccounts(
225
+ attesterAccounts: AttesterAccounts,
226
+ gse: GSEContract,
227
+ password?: string,
228
+ ): Promise<StakerOutput[]> {
229
+ // Skip mnemonic configs
230
+ if (isMnemonicConfig(attesterAccounts)) {
231
+ return [];
232
+ }
233
+
234
+ // Handle array of attesters
235
+ if (Array.isArray(attesterAccounts)) {
236
+ const results: StakerOutput[] = [];
237
+ for (const attester of attesterAccounts) {
238
+ const result = await processAttester(attester, gse, password);
239
+ if (result) {
240
+ results.push(result);
241
+ }
242
+ }
243
+ return results;
244
+ }
245
+
246
+ // Handle single attester
247
+ const result = await processAttester(attesterAccounts, gse, password);
248
+ return result ? [result] : [];
249
+ }
250
+
251
+ /**
252
+ * Main staker command function
253
+ */
254
+ export async function generateStakerJson(options: StakerOptions, log: LogFn): Promise<void> {
255
+ const { from, password, gseAddress, l1RpcUrls, l1ChainId, output } = options;
256
+
257
+ // Load the keystore file
258
+ const keystore = loadKeystoreFile(from);
259
+
260
+ if (!gseAddress) {
261
+ throw new Error('GSE contract address is required');
262
+ }
263
+ log(`Calling GSE contract ${gseAddress} on chain ${l1ChainId}, using ${l1RpcUrls.join(', ')} to get staker outputs`);
264
+
265
+ if (!keystore.validators || keystore.validators.length === 0) {
266
+ log('No validators found in keystore');
267
+ return;
268
+ }
269
+
270
+ const allOutputs: StakerOutput[] = [];
271
+
272
+ // L1 client for proof of possession
273
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
274
+ const publicClient = createPublicClient({
275
+ chain: chain.chainInfo,
276
+ transport: fallback(l1RpcUrls.map(url => http(url, { batch: false }))),
277
+ });
278
+ const gse = new GSEContract(publicClient, gseAddress);
279
+
280
+ const keystoreBaseName = basename(from, '.json');
281
+ const outputDir = output ? output : dirname(from);
282
+
283
+ for (let i = 0; i < keystore.validators.length; i++) {
284
+ const validator = keystore.validators[i];
285
+ const outputs = await processAttesterAccounts(validator.attester, gse, password);
286
+
287
+ for (let j = 0; j < outputs.length; j++) {
288
+ allOutputs.push(outputs[j]);
289
+ }
290
+ }
291
+
292
+ if (allOutputs.length === 0) {
293
+ log('No attesters with BLS keys found (skipping mnemonics and encrypted keystores without password)');
294
+ return;
295
+ }
296
+
297
+ // Write a single JSON file with all staker outputs
298
+ const stakerOutputPath = join(outputDir, `${keystoreBaseName}_staker_output.json`);
299
+ writeFileSync(stakerOutputPath, prettyPrintJSON(allOutputs), 'utf-8');
300
+ log(`Wrote staker output for ${allOutputs.length} validator(s) to ${stakerOutputPath}`);
301
+ }
@@ -0,0 +1,81 @@
1
+ import type { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { ethPrivateKeySchema } from '@aztec/node-keystore/schemas';
3
+ import type { EthPrivateKey } from '@aztec/node-keystore/types';
4
+
5
+ export const defaultBlsPath = 'm/12381/3600/0/0/0';
6
+
7
+ export function validateBlsPathOptions(options: {
8
+ count?: number;
9
+ publisherCount?: number;
10
+ accountIndex?: number;
11
+ addressIndex?: number;
12
+ blsPath?: string;
13
+ ikm?: string;
14
+ }) {
15
+ if (options.blsPath && options.blsPath !== defaultBlsPath) {
16
+ if (
17
+ (options.count && options.count !== 1) ||
18
+ (options.publisherCount && options.publisherCount > 0) ||
19
+ (options.accountIndex && options.accountIndex !== 0) ||
20
+ (options.addressIndex && options.addressIndex !== 0)
21
+ ) {
22
+ throw new Error('--bls-path cannot be used with --count, --publisher-count, --account-index, or --address-index');
23
+ }
24
+ }
25
+ }
26
+
27
+ export function validateStakerOutputOptions(options: {
28
+ stakerOutput?: boolean;
29
+ gseAddress?: EthAddress;
30
+ l1RpcUrls?: string[];
31
+ l1ChainId?: number;
32
+ }) {
33
+ if (!options.stakerOutput) {
34
+ return;
35
+ }
36
+ // Required options for staker output
37
+ if (!options.gseAddress) {
38
+ throw new Error('--gse-address is required when using --staker-output');
39
+ }
40
+ if (!options.l1RpcUrls || options.l1RpcUrls.length === 0) {
41
+ throw new Error('--l1-rpc-urls is required when using --staker-output');
42
+ }
43
+
44
+ if (options.l1ChainId === undefined) {
45
+ throw new Error('--l1-chain-id is required when using --staker-output');
46
+ }
47
+ }
48
+
49
+ export function validateRemoteSignerOptions(options: { remoteSigner?: string; mnemonic?: string }) {
50
+ if (options.remoteSigner && !options.mnemonic) {
51
+ throw new Error(
52
+ 'Using --remote-signer requires a deterministic key source. Provide --mnemonic to derive keys, or omit --remote-signer to write new private keys to keystore.',
53
+ );
54
+ }
55
+ }
56
+
57
+ export function validatePublisherOptions(options: { publishers?: string[]; publisherCount?: number }) {
58
+ if (options.publisherCount && options.publisherCount > 0 && options.publishers && options.publishers.length > 0) {
59
+ throw new Error('--publishers and --publisher-count cannot be used together');
60
+ }
61
+
62
+ if (options.publishers && options.publishers.length > 0) {
63
+ // Normalize each private key by adding 0x prefix if missing
64
+ const normalizedKeys: string[] = [];
65
+ for (const key of options.publishers) {
66
+ let privateKey = key.trim();
67
+ if (!privateKey.startsWith('0x')) {
68
+ privateKey = '0x' + privateKey;
69
+ }
70
+
71
+ try {
72
+ ethPrivateKeySchema.parse(privateKey);
73
+ normalizedKeys.push(privateKey);
74
+ } catch (error) {
75
+ throw new Error(`Invalid publisher private key: ${error instanceof Error ? error.message : String(error)}`);
76
+ }
77
+ }
78
+ // Update the options with the normalized keys
79
+ options.publishers = normalizedKeys as EthPrivateKey[];
80
+ }
81
+ }