@aztec/cli 0.0.0-test.1 → 0.0.1-commit.24de95ac

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 (242) hide show
  1. package/README.md +1 -427
  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 +9 -0
  8. package/dest/cmds/aztec_node/get_current_base_fee.d.ts +3 -0
  9. package/dest/cmds/aztec_node/get_current_base_fee.d.ts.map +1 -0
  10. package/dest/cmds/aztec_node/get_current_base_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 +6 -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.map +1 -0
  21. package/dest/cmds/aztec_node/index.js +28 -0
  22. package/dest/cmds/contracts/inspect_contract.d.ts.map +1 -1
  23. package/dest/cmds/contracts/inspect_contract.js +9 -5
  24. package/dest/cmds/infrastructure/index.d.ts +2 -2
  25. package/dest/cmds/infrastructure/index.d.ts.map +1 -1
  26. package/dest/cmds/infrastructure/index.js +8 -9
  27. package/dest/cmds/infrastructure/sequencers.d.ts +4 -4
  28. package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -1
  29. package/dest/cmds/infrastructure/sequencers.js +29 -16
  30. package/dest/cmds/infrastructure/setup_l2_contract.d.ts +1 -1
  31. package/dest/cmds/infrastructure/setup_l2_contract.d.ts.map +1 -1
  32. package/dest/cmds/infrastructure/setup_l2_contract.js +11 -24
  33. package/dest/cmds/l1/advance_epoch.d.ts +1 -1
  34. package/dest/cmds/l1/advance_epoch.d.ts.map +1 -1
  35. package/dest/cmds/l1/advance_epoch.js +8 -6
  36. package/dest/cmds/l1/assume_proven_through.d.ts +1 -1
  37. package/dest/cmds/l1/assume_proven_through.d.ts.map +1 -1
  38. package/dest/cmds/l1/assume_proven_through.js +9 -8
  39. package/dest/cmds/l1/bridge_erc20.d.ts +2 -2
  40. package/dest/cmds/l1/bridge_erc20.d.ts.map +1 -1
  41. package/dest/cmds/l1/bridge_erc20.js +5 -5
  42. package/dest/cmds/l1/deploy_l1_contracts.d.ts +2 -2
  43. package/dest/cmds/l1/deploy_l1_contracts.d.ts.map +1 -1
  44. package/dest/cmds/l1/deploy_l1_contracts.js +23 -6
  45. package/dest/cmds/l1/deploy_new_rollup.d.ts +2 -1
  46. package/dest/cmds/l1/deploy_new_rollup.d.ts.map +1 -1
  47. package/dest/cmds/l1/deploy_new_rollup.js +17 -8
  48. package/dest/cmds/l1/get_l1_addresses.d.ts +1 -1
  49. package/dest/cmds/l1/get_l1_addresses.d.ts.map +1 -1
  50. package/dest/cmds/l1/governance_utils.d.ts.map +1 -1
  51. package/dest/cmds/l1/governance_utils.js +17 -17
  52. package/dest/cmds/l1/index.d.ts +1 -0
  53. package/dest/cmds/l1/index.d.ts.map +1 -1
  54. package/dest/cmds/l1/index.js +33 -43
  55. package/dest/cmds/l1/trigger_seed_snapshot.d.ts +6 -0
  56. package/dest/cmds/l1/trigger_seed_snapshot.d.ts.map +1 -0
  57. package/dest/cmds/l1/trigger_seed_snapshot.js +19 -0
  58. package/dest/cmds/l1/update_l1_validators.d.ts +17 -2
  59. package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
  60. package/dest/cmds/l1/update_l1_validators.js +159 -103
  61. package/dest/cmds/misc/generate_bootnode_enr.d.ts +1 -1
  62. package/dest/cmds/misc/generate_bootnode_enr.d.ts.map +1 -1
  63. package/dest/cmds/misc/generate_bootnode_enr.js +2 -2
  64. package/dest/cmds/misc/generate_secret_and_hash.d.ts +1 -1
  65. package/dest/cmds/misc/generate_secret_and_hash.d.ts.map +1 -1
  66. package/dest/cmds/misc/generate_secret_and_hash.js +3 -3
  67. package/dest/cmds/misc/generate_secret_key.d.ts +1 -1
  68. package/dest/cmds/misc/generate_secret_key.d.ts.map +1 -1
  69. package/dest/cmds/misc/generate_secret_key.js +1 -1
  70. package/dest/cmds/misc/get_canonical_sponsored_fpc_address.d.ts +3 -0
  71. package/dest/cmds/misc/get_canonical_sponsored_fpc_address.d.ts.map +1 -0
  72. package/dest/cmds/misc/get_canonical_sponsored_fpc_address.js +4 -0
  73. package/dest/cmds/misc/index.d.ts.map +1 -1
  74. package/dest/cmds/misc/index.js +7 -3
  75. package/dest/cmds/misc/update/github.d.ts +0 -1
  76. package/dest/cmds/misc/update/github.d.ts.map +1 -1
  77. package/dest/cmds/misc/update/github.js +0 -1
  78. package/dest/cmds/misc/update.d.ts.map +1 -1
  79. package/dest/cmds/misc/update.js +2 -3
  80. package/dest/cmds/validator_keys/add.d.ts +5 -0
  81. package/dest/cmds/validator_keys/add.d.ts.map +1 -0
  82. package/dest/cmds/validator_keys/add.js +70 -0
  83. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts +12 -0
  84. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts.map +1 -0
  85. package/dest/cmds/validator_keys/generate_bls_keypair.js +26 -0
  86. package/dest/cmds/validator_keys/index.d.ts +4 -0
  87. package/dest/cmds/validator_keys/index.d.ts.map +1 -0
  88. package/dest/cmds/validator_keys/index.js +20 -0
  89. package/dest/cmds/validator_keys/new.d.ts +26 -0
  90. package/dest/cmds/validator_keys/new.d.ts.map +1 -0
  91. package/dest/cmds/validator_keys/new.js +60 -0
  92. package/dest/cmds/validator_keys/shared.d.ts +68 -0
  93. package/dest/cmds/validator_keys/shared.d.ts.map +1 -0
  94. package/dest/cmds/validator_keys/shared.js +271 -0
  95. package/dest/config/cached_fetch.d.ts +18 -0
  96. package/dest/config/cached_fetch.d.ts.map +1 -0
  97. package/dest/config/cached_fetch.js +54 -0
  98. package/dest/config/chain_l2_config.d.ts +39 -0
  99. package/dest/config/chain_l2_config.d.ts.map +1 -0
  100. package/dest/config/chain_l2_config.js +475 -0
  101. package/dest/config/enrich_env.d.ts +4 -0
  102. package/dest/config/enrich_env.d.ts.map +1 -0
  103. package/dest/config/enrich_env.js +12 -0
  104. package/dest/config/get_l1_config.d.ts +8 -0
  105. package/dest/config/get_l1_config.d.ts.map +1 -0
  106. package/dest/config/get_l1_config.js +22 -0
  107. package/dest/config/index.d.ts +5 -0
  108. package/dest/config/index.d.ts.map +1 -0
  109. package/dest/config/index.js +4 -0
  110. package/dest/config/network_config.d.ts +19 -0
  111. package/dest/config/network_config.d.ts.map +1 -0
  112. package/dest/config/network_config.js +79 -0
  113. package/dest/utils/aztec.d.ts +12 -17
  114. package/dest/utils/aztec.d.ts.map +1 -1
  115. package/dest/utils/aztec.js +54 -49
  116. package/dest/utils/commands.d.ts +17 -9
  117. package/dest/utils/commands.d.ts.map +1 -1
  118. package/dest/utils/commands.js +40 -14
  119. package/dest/utils/encoding.js +1 -1
  120. package/dest/utils/github.d.ts +0 -1
  121. package/dest/utils/github.d.ts.map +1 -1
  122. package/dest/utils/github.js +0 -1
  123. package/dest/utils/index.d.ts +1 -0
  124. package/dest/utils/index.d.ts.map +1 -1
  125. package/dest/utils/index.js +1 -0
  126. package/dest/utils/inspect.d.ts +3 -10
  127. package/dest/utils/inspect.d.ts.map +1 -1
  128. package/dest/utils/inspect.js +19 -109
  129. package/dest/utils/setup_contracts.d.ts +3 -0
  130. package/dest/utils/setup_contracts.d.ts.map +1 -0
  131. package/dest/utils/setup_contracts.js +16 -0
  132. package/package.json +44 -33
  133. package/src/cmds/aztec_node/block_number.ts +9 -0
  134. package/src/cmds/aztec_node/get_block.ts +10 -0
  135. package/src/cmds/aztec_node/get_current_base_fee.ts +9 -0
  136. package/src/cmds/aztec_node/get_l1_to_l2_message_witness.ts +27 -0
  137. package/src/cmds/{pxe → aztec_node}/get_logs.ts +8 -7
  138. package/src/cmds/{pxe → aztec_node}/get_node_info.ts +15 -23
  139. package/src/cmds/aztec_node/index.ts +87 -0
  140. package/src/cmds/contracts/inspect_contract.ts +16 -6
  141. package/src/cmds/infrastructure/index.ts +8 -10
  142. package/src/cmds/infrastructure/sequencers.ts +36 -19
  143. package/src/cmds/infrastructure/setup_l2_contract.ts +13 -25
  144. package/src/cmds/l1/advance_epoch.ts +7 -5
  145. package/src/cmds/l1/assume_proven_through.ts +8 -7
  146. package/src/cmds/l1/bridge_erc20.ts +7 -4
  147. package/src/cmds/l1/deploy_l1_contracts.ts +32 -7
  148. package/src/cmds/l1/deploy_new_rollup.ts +23 -9
  149. package/src/cmds/l1/get_l1_addresses.ts +1 -1
  150. package/src/cmds/l1/governance_utils.ts +18 -17
  151. package/src/cmds/l1/index.ts +74 -101
  152. package/src/cmds/l1/trigger_seed_snapshot.ts +31 -0
  153. package/src/cmds/l1/update_l1_validators.ts +194 -94
  154. package/src/cmds/misc/generate_bootnode_enr.ts +3 -2
  155. package/src/cmds/misc/generate_secret_and_hash.ts +3 -3
  156. package/src/cmds/misc/generate_secret_key.ts +1 -1
  157. package/src/cmds/misc/get_canonical_sponsored_fpc_address.ts +7 -0
  158. package/src/cmds/misc/index.ts +13 -4
  159. package/src/cmds/misc/update/github.ts +0 -1
  160. package/src/cmds/misc/update.ts +1 -7
  161. package/src/cmds/validator_keys/add.ts +113 -0
  162. package/src/cmds/validator_keys/generate_bls_keypair.ts +33 -0
  163. package/src/cmds/validator_keys/index.ts +96 -0
  164. package/src/cmds/validator_keys/new.ts +120 -0
  165. package/src/cmds/validator_keys/shared.ts +321 -0
  166. package/src/config/cached_fetch.ts +67 -0
  167. package/src/config/chain_l2_config.ts +627 -0
  168. package/src/config/enrich_env.ts +15 -0
  169. package/src/config/get_l1_config.ts +28 -0
  170. package/src/config/index.ts +4 -0
  171. package/src/config/network_config.ts +102 -0
  172. package/src/utils/aztec.ts +78 -65
  173. package/src/utils/commands.ts +54 -18
  174. package/src/utils/encoding.ts +1 -1
  175. package/src/utils/github.ts +0 -1
  176. package/src/utils/index.ts +1 -0
  177. package/src/utils/inspect.ts +23 -123
  178. package/src/utils/setup_contracts.ts +19 -0
  179. package/dest/cmds/devnet/bootstrap_network.d.ts +0 -3
  180. package/dest/cmds/devnet/bootstrap_network.d.ts.map +0 -1
  181. package/dest/cmds/devnet/bootstrap_network.js +0 -196
  182. package/dest/cmds/devnet/faucet.d.ts +0 -4
  183. package/dest/cmds/devnet/faucet.d.ts.map +0 -1
  184. package/dest/cmds/devnet/faucet.js +0 -26
  185. package/dest/cmds/devnet/index.d.ts.map +0 -1
  186. package/dest/cmds/devnet/index.js +0 -14
  187. package/dest/cmds/l1/deploy_l1_verifier.d.ts +0 -5
  188. package/dest/cmds/l1/deploy_l1_verifier.d.ts.map +0 -1
  189. package/dest/cmds/l1/deploy_l1_verifier.js +0 -54
  190. package/dest/cmds/misc/setup_contracts.d.ts +0 -7
  191. package/dest/cmds/misc/setup_contracts.d.ts.map +0 -1
  192. package/dest/cmds/misc/setup_contracts.js +0 -27
  193. package/dest/cmds/pxe/add_contract.d.ts +0 -5
  194. package/dest/cmds/pxe/add_contract.d.ts.map +0 -1
  195. package/dest/cmds/pxe/add_contract.js +0 -29
  196. package/dest/cmds/pxe/block_number.d.ts +0 -3
  197. package/dest/cmds/pxe/block_number.d.ts.map +0 -1
  198. package/dest/cmds/pxe/block_number.js +0 -10
  199. package/dest/cmds/pxe/get_account.d.ts +0 -4
  200. package/dest/cmds/pxe/get_account.d.ts.map +0 -1
  201. package/dest/cmds/pxe/get_account.js +0 -10
  202. package/dest/cmds/pxe/get_accounts.d.ts +0 -3
  203. package/dest/cmds/pxe/get_accounts.d.ts.map +0 -1
  204. package/dest/cmds/pxe/get_accounts.js +0 -25
  205. package/dest/cmds/pxe/get_block.d.ts +0 -3
  206. package/dest/cmds/pxe/get_block.d.ts.map +0 -1
  207. package/dest/cmds/pxe/get_block.js +0 -9
  208. package/dest/cmds/pxe/get_contract_data.d.ts +0 -4
  209. package/dest/cmds/pxe/get_contract_data.d.ts.map +0 -1
  210. package/dest/cmds/pxe/get_contract_data.js +0 -31
  211. package/dest/cmds/pxe/get_current_base_fee.d.ts +0 -3
  212. package/dest/cmds/pxe/get_current_base_fee.d.ts.map +0 -1
  213. package/dest/cmds/pxe/get_current_base_fee.js +0 -7
  214. package/dest/cmds/pxe/get_l1_to_l2_message_witness.d.ts +0 -4
  215. package/dest/cmds/pxe/get_l1_to_l2_message_witness.d.ts.map +0 -1
  216. package/dest/cmds/pxe/get_l1_to_l2_message_witness.js +0 -11
  217. package/dest/cmds/pxe/get_logs.d.ts +0 -4
  218. package/dest/cmds/pxe/get_logs.d.ts.map +0 -1
  219. package/dest/cmds/pxe/get_node_info.d.ts +0 -3
  220. package/dest/cmds/pxe/get_node_info.d.ts.map +0 -1
  221. package/dest/cmds/pxe/get_pxe_info.d.ts +0 -3
  222. package/dest/cmds/pxe/get_pxe_info.d.ts.map +0 -1
  223. package/dest/cmds/pxe/get_pxe_info.js +0 -11
  224. package/dest/cmds/pxe/index.d.ts +0 -4
  225. package/dest/cmds/pxe/index.d.ts.map +0 -1
  226. package/dest/cmds/pxe/index.js +0 -55
  227. package/src/cmds/devnet/bootstrap_network.ts +0 -318
  228. package/src/cmds/devnet/faucet.ts +0 -33
  229. package/src/cmds/devnet/index.ts +0 -60
  230. package/src/cmds/l1/deploy_l1_verifier.ts +0 -105
  231. package/src/cmds/misc/setup_contracts.ts +0 -40
  232. package/src/cmds/pxe/add_contract.ts +0 -41
  233. package/src/cmds/pxe/block_number.ts +0 -9
  234. package/src/cmds/pxe/get_account.ts +0 -16
  235. package/src/cmds/pxe/get_accounts.ts +0 -35
  236. package/src/cmds/pxe/get_block.ts +0 -10
  237. package/src/cmds/pxe/get_contract_data.ts +0 -51
  238. package/src/cmds/pxe/get_current_base_fee.ts +0 -9
  239. package/src/cmds/pxe/get_l1_to_l2_message_witness.ts +0 -25
  240. package/src/cmds/pxe/get_pxe_info.ts +0 -13
  241. package/src/cmds/pxe/index.ts +0 -170
  242. /package/dest/cmds/{devnet → aztec_node}/index.d.ts +0 -0
@@ -0,0 +1,96 @@
1
+ import type { LogFn } from '@aztec/foundation/log';
2
+
3
+ import { Command } from 'commander';
4
+
5
+ import { parseAztecAddress, parseEthereumAddress, parseHex, parseOptionalInteger } from '../../utils/commands.js';
6
+
7
+ export function injectCommands(program: Command, log: LogFn) {
8
+ const group = program
9
+ .command('validator-keys')
10
+ .aliases(['valKeys'])
11
+ .description('Manage validator keystores for node operators');
12
+
13
+ group
14
+ .command('new')
15
+ .summary('Generate a new validator keystore JSON')
16
+ .description('Generates a new validator keystore with ETH secp256k1 accounts and optional BLS accounts')
17
+ .option('--data-dir <path>', 'Directory to store keystore(s). Defaults to ~/.aztec/keystore')
18
+ .option('--file <name>', 'Keystore file name. Defaults to key1.json (or keyN.json if key1.json exists)')
19
+ .option('--count <N>', 'Number of validators to generate', parseOptionalInteger)
20
+ .option('--publisher-count <N>', 'Number of publisher accounts per validator (default 1)', value =>
21
+ parseOptionalInteger(value, 0),
22
+ )
23
+ .option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation')
24
+ .option('--passphrase <str>', 'Optional passphrase for mnemonic')
25
+ .option('--account-index <N>', 'Base account index for ETH derivation', parseOptionalInteger)
26
+ .option('--address-index <N>', 'Base address index for ETH derivation', parseOptionalInteger)
27
+ .option('--coinbase <address>', 'Coinbase ETH address to use when proposing', parseEthereumAddress)
28
+ .option('--funding-account <address>', 'ETH account to fund publishers', parseEthereumAddress)
29
+ .option('--remote-signer <url>', 'Default remote signer URL for accounts in this file')
30
+ .option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', value => parseHex(value, 32))
31
+ .option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)')
32
+ .option('--bls-only', 'Generate only BLS keys')
33
+ .option(
34
+ '--password <str>',
35
+ 'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed',
36
+ )
37
+ .option('--out-dir <dir>', 'Output directory for generated keystore file(s)')
38
+ .option('--json', 'Echo resulting JSON to stdout')
39
+ .requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress)
40
+ .action(async options => {
41
+ const { newValidatorKeystore } = await import('./new.js');
42
+ await newValidatorKeystore(options, log);
43
+ });
44
+
45
+ group
46
+ .command('add')
47
+ .summary('Augment an existing validator keystore JSON')
48
+ .description('Adds attester/publisher/BLS entries to an existing keystore using the same flags as new')
49
+ .argument('<existing>', 'Path to existing keystore JSON')
50
+ .option('--data-dir <path>', 'Directory where keystore(s) live')
51
+ .option('--file <name>', 'Override output file name')
52
+ .option('--count <N>', 'Number of validators to add', parseOptionalInteger)
53
+ .option('--publisher-count <N>', 'Number of publisher accounts per validator (default 1)', value =>
54
+ parseOptionalInteger(value, 0),
55
+ )
56
+ .option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation')
57
+ .option('--passphrase <str>', 'Optional passphrase for mnemonic')
58
+ .option('--account-index <N>', 'Base account index for ETH derivation', parseOptionalInteger)
59
+ .option('--address-index <N>', 'Base address index for ETH derivation', parseOptionalInteger)
60
+ .option('--coinbase <address>', 'Coinbase ETH address to use when proposing', parseEthereumAddress)
61
+ .option('--funding-account <address>', 'ETH account to fund publishers', parseEthereumAddress)
62
+ .option('--remote-signer <url>', 'Default remote signer URL for accounts in this file')
63
+ .option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', value => parseHex(value, 32))
64
+ .option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)')
65
+ .option('--bls-only', 'Generate only BLS keys')
66
+ .option('--empty', 'Generate an empty skeleton without keys')
67
+ .option(
68
+ '--password <str>',
69
+ 'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed',
70
+ )
71
+ .option('--out-dir <dir>', 'Output directory for generated keystore file(s)')
72
+ .option('--json', 'Echo resulting JSON to stdout')
73
+ .requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress)
74
+ .action(async (existing: string, options) => {
75
+ const { addValidatorKeys } = await import('./add.js');
76
+ await addValidatorKeys(existing, options, log);
77
+ });
78
+
79
+ // top-level convenience: aztec generate-bls-keypair
80
+ program
81
+ .command('generate-bls-keypair')
82
+ .description('Generate a BLS keypair with convenience flags')
83
+ .option('--mnemonic <mnemonic>', 'Mnemonic for BLS derivation')
84
+ .option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', value => parseHex(value, 32))
85
+ .option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)')
86
+ .option('--g2', 'Derive on G2 subgroup')
87
+ .option('--compressed', 'Output compressed public key')
88
+ .option('--json', 'Print JSON output to stdout')
89
+ .option('--out <file>', 'Write output to file')
90
+ .action(async options => {
91
+ const { generateBlsKeypair } = await import('./generate_bls_keypair.js');
92
+ await generateBlsKeypair(options, log);
93
+ });
94
+
95
+ return program;
96
+ }
@@ -0,0 +1,120 @@
1
+ import type { EthAddress } from '@aztec/foundation/eth-address';
2
+ import type { LogFn } from '@aztec/foundation/log';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+
5
+ import { wordlist } from '@scure/bip39/wordlists/english.js';
6
+ import { dirname } from 'path';
7
+ import { generateMnemonic, mnemonicToAccount } from 'viem/accounts';
8
+
9
+ import {
10
+ buildValidatorEntries,
11
+ logValidatorSummaries,
12
+ maybePrintJson,
13
+ resolveKeystoreOutputPath,
14
+ writeBlsBn254ToFile,
15
+ writeEthJsonV3ToFile,
16
+ writeKeystoreFile,
17
+ } from './shared.js';
18
+
19
+ export type NewValidatorKeystoreOptions = {
20
+ dataDir?: string;
21
+ file?: string;
22
+ count?: number;
23
+ publisherCount?: number;
24
+ mnemonic?: string;
25
+ passphrase?: string;
26
+ accountIndex?: number;
27
+ addressIndex?: number;
28
+ separatePublisher?: boolean;
29
+ ikm?: string;
30
+ blsPath?: string;
31
+ blsOnly?: boolean;
32
+ password?: string;
33
+ outDir?: string;
34
+ json?: boolean;
35
+ feeRecipient: AztecAddress;
36
+ coinbase?: EthAddress;
37
+ remoteSigner?: string;
38
+ fundingAccount?: EthAddress;
39
+ };
40
+
41
+ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions, log: LogFn) {
42
+ const {
43
+ dataDir,
44
+ file,
45
+ count,
46
+ publisherCount = 0,
47
+ json,
48
+ coinbase,
49
+ accountIndex = 0,
50
+ addressIndex = 0,
51
+ feeRecipient,
52
+ remoteSigner,
53
+ fundingAccount,
54
+ blsOnly,
55
+ blsPath,
56
+ ikm,
57
+ mnemonic: _mnemonic,
58
+ password,
59
+ outDir,
60
+ } = options;
61
+
62
+ if (remoteSigner && !_mnemonic) {
63
+ throw new Error(
64
+ 'Using --remote-signer requires a deterministic key source. Provide --mnemonic to derive keys, or omit --remote-signer to write new private keys to keystore.',
65
+ );
66
+ }
67
+
68
+ const mnemonic = _mnemonic ?? generateMnemonic(wordlist);
69
+
70
+ const validatorCount = typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
71
+ const { outputPath } = await resolveKeystoreOutputPath(dataDir, file);
72
+
73
+ const { validators, summaries } = await buildValidatorEntries({
74
+ validatorCount,
75
+ publisherCount,
76
+ accountIndex,
77
+ baseAddressIndex: addressIndex,
78
+ mnemonic,
79
+ ikm,
80
+ blsPath,
81
+ blsOnly,
82
+ feeRecipient,
83
+ coinbase,
84
+ remoteSigner,
85
+ fundingAccount,
86
+ });
87
+
88
+ // If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
89
+ if (password !== undefined) {
90
+ const keystoreOutDir = outDir && outDir.length > 0 ? outDir : dirname(outputPath);
91
+ await writeEthJsonV3ToFile(validators, { outDir: keystoreOutDir, password });
92
+ await writeBlsBn254ToFile(validators, { outDir: keystoreOutDir, password });
93
+ }
94
+
95
+ const keystore = {
96
+ schemaVersion: 1,
97
+ validators,
98
+ };
99
+
100
+ await writeKeystoreFile(outputPath, keystore);
101
+
102
+ maybePrintJson(log, json, keystore as unknown as Record<string, any>);
103
+ if (!json) {
104
+ log(`Wrote validator keystore to ${outputPath}`);
105
+ }
106
+
107
+ // Always print a concise summary of public keys (addresses and BLS pubkeys)
108
+ logValidatorSummaries(log, summaries);
109
+
110
+ if (!blsOnly && mnemonic && remoteSigner) {
111
+ for (let i = 0; i < validatorCount; i++) {
112
+ const addrIdx = addressIndex + i;
113
+ const acct = mnemonicToAccount(mnemonic, {
114
+ accountIndex,
115
+ addressIndex: addrIdx,
116
+ });
117
+ log(`attester address: ${acct.address} remoteSignerUrl: ${remoteSigner}`);
118
+ }
119
+ }
120
+ }
@@ -0,0 +1,321 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/utils';
2
+ import { computeBn254G1PublicKeyCompressed, deriveBlsPrivateKey } from '@aztec/foundation/crypto';
3
+ import { createBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
4
+ import type { EthAddress } from '@aztec/foundation/eth-address';
5
+ import type { LogFn } from '@aztec/foundation/log';
6
+ import type { EthAccount, EthPrivateKey, ValidatorKeyStore } from '@aztec/node-keystore/types';
7
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
+
9
+ import { Wallet } from '@ethersproject/wallet';
10
+ import { constants as fsConstants, mkdirSync } from 'fs';
11
+ import { access, writeFile } from 'fs/promises';
12
+ import { homedir } from 'os';
13
+ import { dirname, isAbsolute, join } from 'path';
14
+ import { mnemonicToAccount } from 'viem/accounts';
15
+
16
+ export type ValidatorSummary = { attesterEth?: string; attesterBls?: string; publisherEth?: string[] };
17
+
18
+ export type BuildValidatorsInput = {
19
+ validatorCount: number;
20
+ publisherCount?: number;
21
+ accountIndex: number;
22
+ baseAddressIndex: number;
23
+ mnemonic: string;
24
+ ikm?: string;
25
+ blsPath?: string;
26
+ blsOnly?: boolean;
27
+ feeRecipient: AztecAddress;
28
+ coinbase?: EthAddress;
29
+ remoteSigner?: string;
30
+ fundingAccount?: EthAddress;
31
+ };
32
+
33
+ export function withValidatorIndex(path: string, index: number) {
34
+ const parts = path.split('/');
35
+ if (parts.length >= 4 && parts[0] === 'm' && parts[1] === '12381' && parts[2] === '3600') {
36
+ parts[3] = String(index);
37
+ return parts.join('/');
38
+ }
39
+ return path;
40
+ }
41
+
42
+ /**
43
+ * Compute a compressed BN254 G1 public key from a private key.
44
+ * @param privateKeyHex - Private key as 0x-prefixed hex string
45
+ * @returns Compressed G1 point (32 bytes with sign bit in MSB)
46
+ */
47
+ export async function computeBlsPublicKeyCompressed(privateKeyHex: string): Promise<string> {
48
+ return await computeBn254G1PublicKeyCompressed(privateKeyHex);
49
+ }
50
+
51
+ export function deriveEthAttester(
52
+ mnemonic: string,
53
+ baseAccountIndex: number,
54
+ addressIndex: number,
55
+ remoteSigner?: string,
56
+ ): EthAccount | EthPrivateKey {
57
+ const acct = mnemonicToAccount(mnemonic, { accountIndex: baseAccountIndex, addressIndex });
58
+ return remoteSigner
59
+ ? ({ address: acct.address as unknown as EthAddress, remoteSignerUrl: remoteSigner } as EthAccount)
60
+ : (('0x' + Buffer.from(acct.getHdKey().privateKey!).toString('hex')) as EthPrivateKey);
61
+ }
62
+
63
+ export async function buildValidatorEntries(input: BuildValidatorsInput) {
64
+ const {
65
+ validatorCount,
66
+ publisherCount = 0,
67
+ accountIndex,
68
+ baseAddressIndex,
69
+ mnemonic,
70
+ ikm,
71
+ blsPath,
72
+ blsOnly,
73
+ feeRecipient,
74
+ coinbase,
75
+ remoteSigner,
76
+ fundingAccount,
77
+ } = input;
78
+
79
+ const defaultBlsPath = 'm/12381/3600/0/0/0';
80
+ const summaries: ValidatorSummary[] = [];
81
+
82
+ const validators = await Promise.all(
83
+ Array.from({ length: validatorCount }, async (_unused, i) => {
84
+ const addressIndex = baseAddressIndex + i;
85
+ const basePath = blsPath ?? defaultBlsPath;
86
+ const perValidatorPath = withValidatorIndex(basePath, addressIndex);
87
+
88
+ const blsPrivKey = blsOnly || ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
89
+ const blsPubCompressed = blsPrivKey ? await computeBlsPublicKeyCompressed(blsPrivKey) : undefined;
90
+
91
+ if (blsOnly) {
92
+ const attester = { bls: blsPrivKey! };
93
+ summaries.push({ attesterBls: blsPubCompressed });
94
+ return { attester, feeRecipient } as ValidatorKeyStore;
95
+ }
96
+
97
+ const ethAttester = deriveEthAttester(mnemonic, accountIndex, addressIndex, remoteSigner);
98
+ const attester = blsPrivKey ? { eth: ethAttester, bls: blsPrivKey } : ethAttester;
99
+
100
+ let publisherField: EthAccount | EthPrivateKey | (EthAccount | EthPrivateKey)[] | undefined;
101
+ const publisherAddresses: string[] = [];
102
+ if (publisherCount > 0) {
103
+ const publishersBaseIndex = baseAddressIndex + validatorCount + i * publisherCount;
104
+ const publisherAccounts = Array.from({ length: publisherCount }, (_unused2, j) => {
105
+ const publisherAddressIndex = publishersBaseIndex + j;
106
+ const pubAcct = mnemonicToAccount(mnemonic, {
107
+ accountIndex,
108
+ addressIndex: publisherAddressIndex,
109
+ });
110
+ publisherAddresses.push(pubAcct.address as unknown as string);
111
+ return remoteSigner
112
+ ? ({ address: pubAcct.address as unknown as EthAddress, remoteSignerUrl: remoteSigner } as EthAccount)
113
+ : (('0x' + Buffer.from(pubAcct.getHdKey().privateKey!).toString('hex')) as EthPrivateKey);
114
+ });
115
+ publisherField = publisherCount === 1 ? publisherAccounts[0] : publisherAccounts;
116
+ }
117
+
118
+ const acct = mnemonicToAccount(mnemonic, {
119
+ accountIndex,
120
+ addressIndex,
121
+ });
122
+ const attesterEthAddress = acct.address as unknown as string;
123
+ summaries.push({
124
+ attesterEth: attesterEthAddress,
125
+ attesterBls: blsPubCompressed,
126
+ publisherEth: publisherAddresses.length > 0 ? publisherAddresses : undefined,
127
+ });
128
+
129
+ return {
130
+ attester,
131
+ ...(publisherField !== undefined ? { publisher: publisherField } : {}),
132
+ feeRecipient,
133
+ coinbase,
134
+ fundingAccount,
135
+ } as ValidatorKeyStore;
136
+ }),
137
+ );
138
+
139
+ return { validators, summaries };
140
+ }
141
+
142
+ export async function resolveKeystoreOutputPath(dataDir?: string, file?: string) {
143
+ const defaultDataDir = join(homedir(), '.aztec', 'keystore');
144
+ const resolvedDir = dataDir && dataDir.length > 0 ? dataDir : defaultDataDir;
145
+ let outputPath: string;
146
+ if (file && file.length > 0) {
147
+ outputPath = isAbsolute(file) ? file : join(resolvedDir, file);
148
+ } else {
149
+ let index = 1;
150
+ while (true) {
151
+ const candidate = join(resolvedDir, `key${index}.json`);
152
+ try {
153
+ await access(candidate, fsConstants.F_OK);
154
+ index += 1;
155
+ } catch {
156
+ outputPath = candidate;
157
+ break;
158
+ }
159
+ }
160
+ }
161
+ return { resolvedDir, outputPath: outputPath! };
162
+ }
163
+
164
+ export async function writeKeystoreFile(path: string, keystore: unknown) {
165
+ mkdirSync(dirname(path), { recursive: true });
166
+ await writeFile(path, JSON.stringify(keystore, null, 2), { encoding: 'utf-8' });
167
+ }
168
+
169
+ export function logValidatorSummaries(log: LogFn, summaries: ValidatorSummary[]) {
170
+ const lines: string[] = [];
171
+ for (let i = 0; i < summaries.length; i++) {
172
+ const v = summaries[i];
173
+ lines.push(`acc${i + 1}:`);
174
+ lines.push(` attester:`);
175
+ if (v.attesterEth) {
176
+ lines.push(` eth: ${v.attesterEth}`);
177
+ }
178
+ if (v.attesterBls) {
179
+ lines.push(` bls: ${v.attesterBls}`);
180
+ }
181
+ if (v.publisherEth && v.publisherEth.length > 0) {
182
+ lines.push(` publisher:`);
183
+ for (const addr of v.publisherEth) {
184
+ lines.push(` - ${addr}`);
185
+ }
186
+ }
187
+ }
188
+ if (lines.length > 0) {
189
+ log(lines.join('\n'));
190
+ }
191
+ }
192
+
193
+ export function maybePrintJson(log: LogFn, jsonFlag: boolean | undefined, obj: unknown) {
194
+ if (jsonFlag) {
195
+ log(prettyPrintJSON(obj as Record<string, any>));
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Writes a BN254 keystore file for a BN254 BLS private key.
201
+ * Returns the absolute path to the written file.
202
+ *
203
+ * @param outDir - Directory to write the keystore file to
204
+ * @param fileNameBase - Base name for the keystore file (will be sanitized)
205
+ * @param password - Password for encrypting the private key
206
+ * @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
207
+ * @param pubkeyHex - Public key as hex string
208
+ * @param derivationPath - BIP-44 style derivation path
209
+ * @returns Absolute path to the written keystore file
210
+ */
211
+ export async function writeBn254BlsKeystore(
212
+ outDir: string,
213
+ fileNameBase: string,
214
+ password: string,
215
+ privateKeyHex: string,
216
+ pubkeyHex: string,
217
+ derivationPath: string,
218
+ ): Promise<string> {
219
+ mkdirSync(outDir, { recursive: true });
220
+
221
+ const keystore = createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath);
222
+
223
+ const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
224
+ const outPath = join(outDir, `keystore-${safeBase}.json`);
225
+ await writeFile(outPath, JSON.stringify(keystore, null, 2), { encoding: 'utf-8' });
226
+ return outPath;
227
+ }
228
+
229
+ /** Replace plaintext BLS keys in validators with { path, password } pointing to BN254 keystore files. */
230
+ export async function writeBlsBn254ToFile(
231
+ validators: ValidatorKeyStore[],
232
+ options: { outDir: string; password: string },
233
+ ): Promise<void> {
234
+ for (let i = 0; i < validators.length; i++) {
235
+ const v = validators[i];
236
+ if (!v || typeof v !== 'object' || !('attester' in v)) {
237
+ continue;
238
+ }
239
+ const att = (v as any).attester;
240
+
241
+ // Shapes: { bls: <hex> } or { eth: <ethAccount>, bls?: <hex> } or plain EthAccount
242
+ const blsKey: string | undefined = typeof att === 'object' && 'bls' in att ? (att as any).bls : undefined;
243
+ if (!blsKey || typeof blsKey !== 'string') {
244
+ continue;
245
+ }
246
+
247
+ const pub = await computeBlsPublicKeyCompressed(blsKey);
248
+ const path = 'm/12381/3600/0/0/0';
249
+ const fileBase = `${String(i + 1)}_${pub.slice(2, 18)}`;
250
+ const keystorePath = await writeBn254BlsKeystore(options.outDir, fileBase, options.password, blsKey, pub, path);
251
+
252
+ if (typeof att === 'object') {
253
+ (att as any).bls = { path: keystorePath, password: options.password };
254
+ }
255
+ }
256
+ }
257
+
258
+ /** Writes an Ethereum JSON V3 keystore using ethers, returns absolute path */
259
+ export async function writeEthJsonV3Keystore(
260
+ outDir: string,
261
+ fileNameBase: string,
262
+ password: string,
263
+ privateKeyHex: string,
264
+ ): Promise<string> {
265
+ const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
266
+ mkdirSync(outDir, { recursive: true });
267
+ const wallet = new Wallet(privateKeyHex);
268
+ const json = await wallet.encrypt(password);
269
+ const outPath = join(outDir, `keystore-eth-${safeBase}.json`);
270
+ await writeFile(outPath, json, { encoding: 'utf-8' });
271
+ return outPath;
272
+ }
273
+
274
+ /** Replace plaintext ETH keys in validators with { path, password } pointing to JSON V3 files. */
275
+ export async function writeEthJsonV3ToFile(
276
+ validators: ValidatorKeyStore[],
277
+ options: { outDir: string; password: string },
278
+ ): Promise<void> {
279
+ const maybeEncryptEth = async (account: any, label: string) => {
280
+ if (typeof account === 'string' && account.startsWith('0x') && account.length === 66) {
281
+ const fileBase = `${label}_${account.slice(2, 10)}`;
282
+ const p = await writeEthJsonV3Keystore(options.outDir, fileBase, options.password, account);
283
+ return { path: p, password: options.password };
284
+ }
285
+ return account;
286
+ };
287
+
288
+ for (let i = 0; i < validators.length; i++) {
289
+ const v = validators[i];
290
+ if (!v || typeof v !== 'object') {
291
+ continue;
292
+ }
293
+
294
+ // attester may be string (eth), object with eth, or remote signer
295
+ const att = (v as any).attester;
296
+ if (typeof att === 'string') {
297
+ (v as any).attester = await maybeEncryptEth(att, `attester_${i + 1}`);
298
+ } else if (att && typeof att === 'object' && 'eth' in att) {
299
+ (att as any).eth = await maybeEncryptEth((att as any).eth, `attester_${i + 1}`);
300
+ }
301
+
302
+ // publisher can be single or array
303
+ if ('publisher' in v) {
304
+ const pub = (v as any).publisher;
305
+ if (Array.isArray(pub)) {
306
+ const out: any[] = [];
307
+ for (let j = 0; j < pub.length; j++) {
308
+ out.push(await maybeEncryptEth(pub[j], `publisher_${i + 1}_${j + 1}`));
309
+ }
310
+ (v as any).publisher = out;
311
+ } else if (pub !== undefined) {
312
+ (v as any).publisher = await maybeEncryptEth(pub, `publisher_${i + 1}`);
313
+ }
314
+ }
315
+
316
+ // Optional fundingAccount within validator
317
+ if ('fundingAccount' in v) {
318
+ (v as any).fundingAccount = await maybeEncryptEth((v as any).fundingAccount, `funding_${i + 1}`);
319
+ }
320
+ }
321
+ }
@@ -0,0 +1,67 @@
1
+ import { createLogger } from '@aztec/aztec.js/log';
2
+
3
+ import { mkdir, readFile, stat, writeFile } from 'fs/promises';
4
+ import { dirname } from 'path';
5
+
6
+ export interface CachedFetchOptions {
7
+ /** Cache duration in milliseconds */
8
+ cacheDurationMs: number;
9
+ /** The cache file */
10
+ cacheFile?: string;
11
+ }
12
+
13
+ /**
14
+ * Fetches data from a URL with file-based caching support.
15
+ * This utility can be used by both remote config and bootnodes fetching.
16
+ *
17
+ * @param url - The URL to fetch from
18
+ * @param networkName - Network name for cache directory structure
19
+ * @param options - Caching and error handling options
20
+ * @param cacheDir - Optional cache directory (defaults to no caching)
21
+ * @returns The fetched and parsed JSON data, or undefined if fetch fails and throwOnError is false
22
+ */
23
+ export async function cachedFetch<T = any>(
24
+ url: string,
25
+ options: CachedFetchOptions,
26
+ fetch = globalThis.fetch,
27
+ log = createLogger('cached_fetch'),
28
+ ): Promise<T | undefined> {
29
+ const { cacheDurationMs, cacheFile } = options;
30
+
31
+ // Try to read from cache first
32
+ try {
33
+ if (cacheFile) {
34
+ const info = await stat(cacheFile);
35
+ if (info.mtimeMs + cacheDurationMs > Date.now()) {
36
+ const cachedData = JSON.parse(await readFile(cacheFile, 'utf-8'));
37
+ return cachedData;
38
+ }
39
+ }
40
+ } catch {
41
+ log.trace('Failed to read data from cache');
42
+ }
43
+
44
+ try {
45
+ const response = await fetch(url);
46
+ if (!response.ok) {
47
+ log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
48
+ return undefined;
49
+ }
50
+
51
+ const data = await response.json();
52
+
53
+ try {
54
+ if (cacheFile) {
55
+ await mkdir(dirname(cacheFile), { recursive: true });
56
+ await writeFile(cacheFile, JSON.stringify(data), 'utf-8');
57
+ }
58
+ } catch (err) {
59
+ log.warn('Failed to cache data on disk: ' + cacheFile, { cacheFile, err });
60
+ }
61
+
62
+ return data;
63
+ } catch (err) {
64
+ log.warn(`Failed to fetch from ${url}`, { err });
65
+ return undefined;
66
+ }
67
+ }