@aztec/cli 0.0.1-commit.b655e406 → 0.0.1-commit.fce3e4f

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 (105) hide show
  1. package/README.md +1 -1
  2. package/dest/cmds/aztec_node/block_number.d.ts +1 -1
  3. package/dest/cmds/aztec_node/get_block.d.ts +1 -1
  4. package/dest/cmds/aztec_node/get_current_base_fee.d.ts +1 -1
  5. package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts +1 -1
  6. package/dest/cmds/aztec_node/get_logs.d.ts +1 -1
  7. package/dest/cmds/aztec_node/get_node_info.d.ts +1 -1
  8. package/dest/cmds/aztec_node/index.d.ts +1 -1
  9. package/dest/cmds/contracts/index.d.ts +1 -1
  10. package/dest/cmds/contracts/inspect_contract.d.ts +1 -1
  11. package/dest/cmds/contracts/inspect_contract.d.ts.map +1 -1
  12. package/dest/cmds/contracts/inspect_contract.js +3 -9
  13. package/dest/cmds/contracts/parse_parameter_struct.d.ts +1 -1
  14. package/dest/cmds/infrastructure/index.d.ts +1 -1
  15. package/dest/cmds/infrastructure/sequencers.d.ts +1 -1
  16. package/dest/cmds/infrastructure/setup_l2_contract.d.ts +1 -1
  17. package/dest/cmds/l1/advance_epoch.d.ts +1 -1
  18. package/dest/cmds/l1/assume_proven_through.d.ts +1 -1
  19. package/dest/cmds/l1/bridge_erc20.d.ts +1 -1
  20. package/dest/cmds/l1/create_l1_account.d.ts +1 -1
  21. package/dest/cmds/l1/deploy_l1_contracts.d.ts +1 -1
  22. package/dest/cmds/l1/deploy_new_rollup.d.ts +1 -1
  23. package/dest/cmds/l1/get_l1_addresses.d.ts +1 -1
  24. package/dest/cmds/l1/get_l1_balance.d.ts +1 -1
  25. package/dest/cmds/l1/governance_utils.d.ts +5 -5
  26. package/dest/cmds/l1/governance_utils.d.ts.map +1 -1
  27. package/dest/cmds/l1/index.d.ts +1 -1
  28. package/dest/cmds/l1/prover_stats.d.ts +1 -1
  29. package/dest/cmds/l1/prover_stats.d.ts.map +1 -1
  30. package/dest/cmds/l1/prover_stats.js +28 -28
  31. package/dest/cmds/l1/trigger_seed_snapshot.d.ts +2 -2
  32. package/dest/cmds/l1/trigger_seed_snapshot.d.ts.map +1 -1
  33. package/dest/cmds/l1/update_l1_validators.d.ts +6 -6
  34. package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
  35. package/dest/cmds/l1/update_l1_validators.js +2 -2
  36. package/dest/cmds/misc/compute_selector.d.ts +1 -1
  37. package/dest/cmds/misc/example_contracts.d.ts +1 -1
  38. package/dest/cmds/misc/generate_bootnode_enr.d.ts +1 -1
  39. package/dest/cmds/misc/generate_p2p_private_key.d.ts +1 -1
  40. package/dest/cmds/misc/generate_secret_and_hash.d.ts +1 -1
  41. package/dest/cmds/misc/generate_secret_key.d.ts +1 -1
  42. package/dest/cmds/misc/get_canonical_sponsored_fpc_address.d.ts +1 -1
  43. package/dest/cmds/misc/index.d.ts +1 -1
  44. package/dest/cmds/misc/update/common.d.ts +1 -1
  45. package/dest/cmds/misc/update/github.d.ts +1 -1
  46. package/dest/cmds/misc/update/noir.d.ts +1 -1
  47. package/dest/cmds/misc/update/npm.d.ts +1 -1
  48. package/dest/cmds/misc/update/npm.js +1 -1
  49. package/dest/cmds/misc/update/utils.d.ts +1 -1
  50. package/dest/cmds/misc/update.d.ts +1 -1
  51. package/dest/cmds/validator_keys/add.d.ts +1 -1
  52. package/dest/cmds/validator_keys/add.d.ts.map +1 -1
  53. package/dest/cmds/validator_keys/add.js +20 -7
  54. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts +1 -1
  55. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts.map +1 -1
  56. package/dest/cmds/validator_keys/generate_bls_keypair.js +2 -1
  57. package/dest/cmds/validator_keys/index.d.ts +1 -1
  58. package/dest/cmds/validator_keys/index.d.ts.map +1 -1
  59. package/dest/cmds/validator_keys/index.js +16 -4
  60. package/dest/cmds/validator_keys/new.d.ts +7 -4
  61. package/dest/cmds/validator_keys/new.d.ts.map +1 -1
  62. package/dest/cmds/validator_keys/new.js +87 -16
  63. package/dest/cmds/validator_keys/shared.d.ts +4 -4
  64. package/dest/cmds/validator_keys/shared.d.ts.map +1 -1
  65. package/dest/cmds/validator_keys/shared.js +29 -27
  66. package/dest/cmds/validator_keys/staker.d.ts +38 -0
  67. package/dest/cmds/validator_keys/staker.d.ts.map +1 -0
  68. package/dest/cmds/validator_keys/staker.js +207 -0
  69. package/dest/cmds/validator_keys/utils.d.ts +25 -0
  70. package/dest/cmds/validator_keys/utils.d.ts.map +1 -0
  71. package/dest/cmds/validator_keys/utils.js +52 -0
  72. package/dest/config/cached_fetch.d.ts +1 -1
  73. package/dest/config/chain_l2_config.d.ts +11 -10
  74. package/dest/config/chain_l2_config.d.ts.map +1 -1
  75. package/dest/config/chain_l2_config.js +64 -34
  76. package/dest/config/enrich_env.d.ts +1 -1
  77. package/dest/config/get_l1_config.d.ts +1 -1
  78. package/dest/config/index.d.ts +1 -1
  79. package/dest/config/network_config.d.ts +2 -2
  80. package/dest/config/network_config.d.ts.map +1 -1
  81. package/dest/config/network_config.js +19 -5
  82. package/dest/utils/aztec.d.ts +1 -1
  83. package/dest/utils/aztec.d.ts.map +1 -1
  84. package/dest/utils/commands.d.ts +2 -2
  85. package/dest/utils/commands.d.ts.map +1 -1
  86. package/dest/utils/encoding.d.ts +1 -1
  87. package/dest/utils/github.d.ts +1 -1
  88. package/dest/utils/index.d.ts +1 -1
  89. package/dest/utils/inspect.d.ts +1 -1
  90. package/dest/utils/setup_contracts.d.ts +1 -1
  91. package/package.json +34 -29
  92. package/public_include_metric_prefixes.json +1 -0
  93. package/src/cmds/contracts/inspect_contract.ts +3 -10
  94. package/src/cmds/l1/prover_stats.ts +36 -29
  95. package/src/cmds/l1/update_l1_validators.ts +2 -2
  96. package/src/cmds/misc/update/npm.ts +1 -1
  97. package/src/cmds/validator_keys/add.ts +20 -10
  98. package/src/cmds/validator_keys/generate_bls_keypair.ts +2 -1
  99. package/src/cmds/validator_keys/index.ts +67 -21
  100. package/src/cmds/validator_keys/new.ts +109 -23
  101. package/src/cmds/validator_keys/shared.ts +30 -26
  102. package/src/cmds/validator_keys/staker.ts +300 -0
  103. package/src/cmds/validator_keys/utils.ts +80 -0
  104. package/src/config/chain_l2_config.ts +86 -45
  105. package/src/config/network_config.ts +26 -5
@@ -55,33 +55,40 @@ export async function proverStats(opts: {
55
55
 
56
56
  // If we only care for raw logs, output them
57
57
  if (rawLogs && !provingTimeout) {
58
- log(`l1_block_number, l2_block_number, prover_id, tx_hash`);
58
+ log(`l1_block_number, checkpoint_number, prover_id, tx_hash`);
59
59
  for (const event of events) {
60
- const { l1BlockNumber, l2BlockNumber, proverId, txHash } = event;
61
- log(`${l1BlockNumber}, ${l2BlockNumber}, ${proverId}, ${txHash}`);
60
+ const { l1BlockNumber, checkpointNumber, proverId, txHash } = event;
61
+ log(`${l1BlockNumber}, ${checkpointNumber}, ${proverId}, ${txHash}`);
62
62
  }
63
63
  return;
64
64
  }
65
65
 
66
- // If we don't have a proving timeout, we can just count the number of unique blocks per prover
66
+ // If we don't have a proving timeout, we can just count the number of unique checkpoints per prover
67
67
  if (!provingTimeout) {
68
68
  const stats = groupBy(events, 'proverId');
69
- log(`prover_id, total_blocks_proven`);
69
+ log(`prover_id, total_checkpoints_proven`);
70
70
  for (const proverId in stats) {
71
- const uniqueBlocks = new Set(stats[proverId].map(e => e.l2BlockNumber));
72
- log(`${proverId}, ${uniqueBlocks.size}`);
71
+ const uniqueCheckpoints = new Set(stats[proverId].map(e => e.checkpointNumber));
72
+ log(`${proverId}, ${uniqueCheckpoints.size}`);
73
73
  }
74
74
  return;
75
75
  }
76
76
 
77
- // But if we do, fetch the events for each block submitted, so we can look up their timestamp
78
- const blockEvents = await getL2BlockEvents(startBlock, lastBlockNum, batchSize, debugLog, publicClient, rollup);
77
+ // But if we do, fetch the events for each checkpoint submitted, so we can look up their timestamp
78
+ const checkpointEvents = await getCheckpointProposedEvents(
79
+ startBlock,
80
+ lastBlockNum,
81
+ batchSize,
82
+ debugLog,
83
+ publicClient,
84
+ rollup,
85
+ );
79
86
  debugLog.verbose(
80
- `First L2 block within range is ${blockEvents[0]?.args.blockNumber} at L1 block ${blockEvents[0]?.blockNumber}`,
87
+ `First checkpoint within range is ${checkpointEvents[0]?.args.checkpointNumber} at L1 block ${checkpointEvents[0]?.blockNumber}`,
81
88
  );
82
89
 
83
90
  // Get the timestamps for every block on every log, both for proof and block submissions
84
- const l1BlockNumbers = unique([...events.map(e => e.l1BlockNumber), ...blockEvents.map(e => e.blockNumber)]);
91
+ const l1BlockNumbers = unique([...events.map(e => e.l1BlockNumber), ...checkpointEvents.map(e => e.blockNumber)]);
85
92
  const l1BlockTimestamps: Record<string, bigint> = {};
86
93
  for (const l1Batch of chunk(l1BlockNumbers, Number(batchSize))) {
87
94
  const blocks = await Promise.all(
@@ -93,44 +100,44 @@ export async function proverStats(opts: {
93
100
  }
94
101
  }
95
102
 
96
- // Map from l2 block number to the l1 block in which it was submitted
97
- const l2BlockSubmissions: Record<string, bigint> = {};
98
- for (const blockEvent of blockEvents) {
99
- l2BlockSubmissions[blockEvent.args.blockNumber!.toString()] = blockEvent.blockNumber;
103
+ // Map from checkpoint number to the l1 block in which it was submitted
104
+ const checkpointSubmissions: Record<string, bigint> = {};
105
+ for (const checkpointEvent of checkpointEvents) {
106
+ checkpointSubmissions[checkpointEvent.args.checkpointNumber!.toString()] = checkpointEvent.blockNumber;
100
107
  }
101
108
 
102
109
  // If we want raw logs, output them
103
110
  if (rawLogs) {
104
- log(`l1_block_number, l2_block_number, l2_block_submission_timestamp, proof_timestamp, prover_id, tx_hash`);
111
+ log(`l1_block_number, checkpoint_number, checkpoint_submission_timestamp, proof_timestamp, prover_id, tx_hash`);
105
112
  for (const event of events) {
106
- const { l1BlockNumber, l2BlockNumber, proverId, txHash } = event;
107
- const uploadedBlockNumber = l2BlockSubmissions[l2BlockNumber.toString()];
113
+ const { l1BlockNumber, checkpointNumber, proverId, txHash } = event;
114
+ const uploadedBlockNumber = checkpointSubmissions[checkpointNumber.toString()];
108
115
  if (!uploadedBlockNumber) {
109
116
  continue;
110
117
  }
111
118
  const uploadedTimestamp = l1BlockTimestamps[uploadedBlockNumber.toString()];
112
119
  const provenTimestamp = l1BlockTimestamps[l1BlockNumber.toString()];
113
- log(`${l1BlockNumber}, ${l2BlockNumber}, ${uploadedTimestamp}, ${provenTimestamp}, ${proverId}, ${txHash}`);
120
+ log(`${l1BlockNumber}, ${checkpointNumber}, ${uploadedTimestamp}, ${provenTimestamp}, ${proverId}, ${txHash}`);
114
121
  }
115
122
  return;
116
123
  }
117
124
 
118
125
  // Or calculate stats per prover
119
- const stats = mapValues(groupBy(events, 'proverId'), (blocks, proverId) =>
126
+ const stats = mapValues(groupBy(events, 'proverId'), (checkpoints, proverId) =>
120
127
  compactArray(
121
- blocks.map(e => {
128
+ checkpoints.map(e => {
122
129
  const provenTimestamp = l1BlockTimestamps[e.l1BlockNumber.toString()];
123
- const uploadedBlockNumber = l2BlockSubmissions[e.l2BlockNumber.toString()];
130
+ const uploadedBlockNumber = checkpointSubmissions[e.checkpointNumber.toString()];
124
131
  if (!uploadedBlockNumber) {
125
132
  debugLog.verbose(
126
- `Skipping ${proverId}'s proof for L2 block ${e.l2BlockNumber} as it was before the start block`,
133
+ `Skipping ${proverId}'s proof for checkpoint ${e.checkpointNumber} as it was before the start block`,
127
134
  );
128
135
  return undefined;
129
136
  }
130
137
  const uploadedTimestamp = l1BlockTimestamps[uploadedBlockNumber.toString()];
131
138
  const provingTime = provenTimestamp - uploadedTimestamp;
132
139
  debugLog.debug(
133
- `prover=${e.proverId} blockNumber=${e.l2BlockNumber} uploaded=${uploadedTimestamp} proven=${provenTimestamp} time=${provingTime}`,
140
+ `prover=${e.proverId} checkpointNumber=${e.checkpointNumber} uploaded=${uploadedTimestamp} proven=${provenTimestamp} time=${provingTime}`,
134
141
  );
135
142
  return { provenTimestamp, uploadedTimestamp, provingTime, ...e };
136
143
  }),
@@ -141,8 +148,8 @@ export async function proverStats(opts: {
141
148
  for (const proverId in stats) {
142
149
  const blocks = stats[proverId];
143
150
  const withinTimeout = blocks.filter(b => b.provingTime <= provingTimeout);
144
- const uniqueBlocksWithinTimeout = new Set(withinTimeout.map(e => e.l2BlockNumber));
145
- const uniqueBlocks = new Set(blocks.map(e => e.l2BlockNumber));
151
+ const uniqueBlocksWithinTimeout = new Set(withinTimeout.map(e => e.checkpointNumber));
152
+ const uniqueBlocks = new Set(blocks.map(e => e.checkpointNumber));
146
153
  const avgProvingTime =
147
154
  blocks.length === 0 ? 0 : Math.ceil(Number(blocks.reduce((acc, b) => acc + b.provingTime, 0n)) / blocks.length);
148
155
 
@@ -171,7 +178,7 @@ async function getL2ProofVerifiedEvents(
171
178
  return events;
172
179
  }
173
180
 
174
- async function getL2BlockEvents(
181
+ async function getCheckpointProposedEvents(
175
182
  startBlock: bigint,
176
183
  lastBlockNum: bigint,
177
184
  batchSize: bigint,
@@ -188,14 +195,14 @@ async function getL2BlockEvents(
188
195
  address: getAddress(rollup.toString()),
189
196
  event: getAbiItem({
190
197
  abi: RollupAbi,
191
- name: 'L2BlockProposed',
198
+ name: 'CheckpointProposed',
192
199
  }),
193
200
  fromBlock: blockNum,
194
201
  toBlock: end,
195
202
  });
196
203
 
197
204
  events.push(...newEvents);
198
- debugLog.verbose(`Got ${newEvents.length} events querying l2 block submitted from block ${blockNum} to ${end}`);
205
+ debugLog.verbose(`Got ${newEvents.length} events querying checkpoints submitted from block ${blockNum} to ${end}`);
199
206
  blockNum += batchSize;
200
207
  }
201
208
  return events;
@@ -299,9 +299,9 @@ export async function debugRollup({ rpcUrls, chainId, rollupAddress, log }: Roll
299
299
  const publicClient = getPublicClient({ l1RpcUrls: rpcUrls, l1ChainId: chainId });
300
300
  const rollup = new RollupContract(publicClient, rollupAddress);
301
301
 
302
- const pendingNum = await rollup.getBlockNumber();
302
+ const pendingNum = await rollup.getCheckpointNumber();
303
303
  log(`Pending block num: ${pendingNum}`);
304
- const provenNum = await rollup.getProvenBlockNumber();
304
+ const provenNum = await rollup.getProvenCheckpointNumber();
305
305
  log(`Proven block num: ${provenNum}`);
306
306
  const validators = await rollup.getAttesters();
307
307
  log(`Validators: ${validators.map(v => v.toString()).join(', ')}`);
@@ -9,7 +9,7 @@ import { type SemVer, parse } from 'semver';
9
9
  import type { DependencyChanges } from './common.js';
10
10
  import { atomicUpdateFile } from './utils.js';
11
11
 
12
- const deprecatedNpmPackages = new Set<string>(['@aztec/cli', '@aztec/aztec-sandbox']);
12
+ const deprecatedNpmPackages = new Set<string>(['@aztec/cli', '@aztec/aztec-local-network']);
13
13
  const npmDeprecationMessage = `
14
14
  The following packages have been deprecated and will no longer be updated on the npm registry:
15
15
  ${Array.from(deprecatedNpmPackages)
@@ -16,28 +16,35 @@ import {
16
16
  writeEthJsonV3ToFile,
17
17
  writeKeystoreFile,
18
18
  } from './shared.js';
19
+ import { validateBlsPathOptions, validatePublisherOptions, validateRemoteSignerOptions } from './utils.js';
19
20
 
20
21
  export type AddValidatorKeysOptions = NewValidatorKeystoreOptions;
21
22
 
22
23
  export async function addValidatorKeys(existing: string, options: AddValidatorKeysOptions, log: LogFn) {
24
+ // validate bls-path inputs before proceeding with key generation
25
+ validateBlsPathOptions(options);
26
+ // validate publisher options
27
+ validatePublisherOptions(options);
28
+ // validate remote signer options
29
+ validateRemoteSignerOptions(options);
30
+
23
31
  const {
24
32
  dataDir,
25
33
  file,
26
34
  count,
27
35
  publisherCount = 0,
36
+ publishers,
28
37
  mnemonic,
29
38
  accountIndex = 0,
30
39
  addressIndex,
31
40
  ikm,
32
41
  blsPath,
33
- blsOnly,
34
42
  json,
35
43
  feeRecipient: feeRecipientOpt,
36
44
  coinbase: coinbaseOpt,
37
- fundingAccount: fundingAccountOpt,
38
45
  remoteSigner: remoteSignerOpt,
39
46
  password,
40
- outDir,
47
+ encryptedKeystoreDir,
41
48
  } = options;
42
49
 
43
50
  const validatorCount = typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
@@ -55,8 +62,6 @@ export async function addValidatorKeys(existing: string, options: AddValidatorKe
55
62
  throw new Error('feeRecipient is required (either present in existing file or via --fee-recipient)');
56
63
  }
57
64
  const coinbase = (coinbaseOpt as EthAddress | undefined) ?? (first.coinbase as EthAddress | undefined);
58
- const fundingAccount =
59
- (fundingAccountOpt as EthAddress | undefined) ?? (first.fundingAccount as EthAddress | undefined);
60
65
  const derivedRemoteSigner = (first.attester as any)?.remoteSignerUrl || (first.attester as any)?.eth?.remoteSignerUrl;
61
66
  const remoteSigner = remoteSignerOpt ?? derivedRemoteSigner;
62
67
 
@@ -70,26 +75,31 @@ export async function addValidatorKeys(existing: string, options: AddValidatorKe
70
75
  const { validators, summaries } = await buildValidatorEntries({
71
76
  validatorCount,
72
77
  publisherCount,
78
+ publishers,
73
79
  accountIndex,
74
80
  baseAddressIndex: effectiveBaseAddressIndex,
75
81
  mnemonic: mnemonicToUse,
76
82
  ikm,
77
83
  blsPath,
78
- blsOnly,
79
84
  feeRecipient,
80
85
  coinbase,
81
86
  remoteSigner,
82
- fundingAccount,
83
87
  });
84
88
 
85
89
  keystore.validators.push(...validators);
86
90
 
87
91
  // If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
88
92
  if (password !== undefined) {
89
- const targetDir =
90
- outDir && outDir.length > 0 ? outDir : dataDir && dataDir.length > 0 ? dataDir : dirname(existing);
93
+ let targetDir: string;
94
+ if (encryptedKeystoreDir && encryptedKeystoreDir.length > 0) {
95
+ targetDir = encryptedKeystoreDir;
96
+ } else if (dataDir && dataDir.length > 0) {
97
+ targetDir = dataDir;
98
+ } else {
99
+ targetDir = dirname(existing);
100
+ }
91
101
  await writeEthJsonV3ToFile(keystore.validators, { outDir: targetDir, password });
92
- await writeBlsBn254ToFile(keystore.validators, { outDir: targetDir, password });
102
+ await writeBlsBn254ToFile(keystore.validators, { outDir: targetDir, password, blsPath });
93
103
  }
94
104
 
95
105
  let outputPath = existing;
@@ -4,6 +4,7 @@ import type { LogFn } from '@aztec/foundation/log';
4
4
  import { writeFile } from 'fs/promises';
5
5
 
6
6
  import { computeBlsPublicKeyCompressed, withValidatorIndex } from './shared.js';
7
+ import { defaultBlsPath } from './utils.js';
7
8
 
8
9
  export type GenerateBlsKeypairOptions = {
9
10
  mnemonic?: string;
@@ -17,7 +18,7 @@ export type GenerateBlsKeypairOptions = {
17
18
 
18
19
  export async function generateBlsKeypair(options: GenerateBlsKeypairOptions, log: LogFn) {
19
20
  const { mnemonic, ikm, blsPath, compressed = true, json, out } = options;
20
- const path = withValidatorIndex(blsPath ?? 'm/12381/3600/0/0/0', 0);
21
+ const path = withValidatorIndex(blsPath ?? defaultBlsPath, 0);
21
22
  const priv = deriveBlsPrivateKey(mnemonic, ikm, path);
22
23
  const pub = await computeBlsPublicKeyCompressed(priv);
23
24
  const result = { path, privateKey: priv, publicKey: pub, format: compressed ? 'compressed' : 'uncompressed' };
@@ -3,11 +3,12 @@ import type { LogFn } from '@aztec/foundation/log';
3
3
  import { Command } from 'commander';
4
4
 
5
5
  import { parseAztecAddress, parseEthereumAddress, parseHex, parseOptionalInteger } from '../../utils/commands.js';
6
+ import { defaultBlsPath } from './utils.js';
6
7
 
7
8
  export function injectCommands(program: Command, log: LogFn) {
8
9
  const group = program
9
10
  .command('validator-keys')
10
- .aliases(['valKeys'])
11
+ .aliases(['valKeys', 'valkeys'])
11
12
  .description('Manage validator keystores for node operators');
12
13
 
13
14
  group
@@ -17,28 +18,47 @@ export function injectCommands(program: Command, log: LogFn) {
17
18
  .option('--data-dir <path>', 'Directory to store keystore(s). Defaults to ~/.aztec/keystore')
18
19
  .option('--file <name>', 'Keystore file name. Defaults to key1.json (or keyN.json if key1.json exists)')
19
20
  .option('--count <N>', 'Number of validators to generate', parseOptionalInteger)
20
- .option('--publisher-count <N>', 'Number of publisher accounts per validator (default 1)', value =>
21
+ .option('--publisher-count <N>', 'Number of publisher accounts per validator (default 0)', value =>
21
22
  parseOptionalInteger(value, 0),
22
23
  )
24
+ .option('--publishers <privateKeys>', 'Comma-separated list of publisher private keys for all validators.', value =>
25
+ value.split(',').map((key: string) => key.trim()),
26
+ )
23
27
  .option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation')
24
28
  .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('--account-index <N>', 'Base account index for ETH/BLS derivation', parseOptionalInteger)
30
+ .option('--address-index <N>', 'Base address index for ETH/BLS derivation', parseOptionalInteger)
31
+ .option(
32
+ '--coinbase <address>',
33
+ 'Coinbase ETH address to use when proposing. Defaults to attester address.',
34
+ parseEthereumAddress,
35
+ )
36
+ // TODO: add funding account back in when implemented
37
+ // .option('--funding-account <privateKey|address>', 'ETH private key (or address for remote signer setup) to fund publishers')
29
38
  .option('--remote-signer <url>', 'Default remote signer URL for accounts in this file')
30
39
  .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')
40
+ .option('--bls-path <path>', `EIP-2334 path (default ${defaultBlsPath})`)
33
41
  .option(
34
42
  '--password <str>',
35
43
  'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed',
36
44
  )
37
- .option('--out-dir <dir>', 'Output directory for generated keystore file(s)')
45
+ .option('--encrypted-keystore-dir <dir>', 'Output directory for encrypted keystore file(s)')
38
46
  .option('--json', 'Echo resulting JSON to stdout')
47
+ .option('--staker-output', 'Generate a single staker output JSON file with an array of validator entries')
48
+ .option('--gse-address <address>', 'GSE contract address (required with --staker-output)', parseEthereumAddress)
49
+ .option('--l1-rpc-urls <urls>', 'L1 RPC URLs (comma-separated, required with --staker-output)', value =>
50
+ value.split(','),
51
+ )
52
+ .option(
53
+ '-c, --l1-chain-id <number>',
54
+ 'L1 chain ID (required with --staker-output)',
55
+ value => parseInt(value),
56
+ 31337,
57
+ )
39
58
  .requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress)
40
59
  .action(async options => {
41
60
  const { newValidatorKeystore } = await import('./new.js');
61
+
42
62
  await newValidatorKeystore(options, log);
43
63
  });
44
64
 
@@ -47,28 +67,35 @@ export function injectCommands(program: Command, log: LogFn) {
47
67
  .summary('Augment an existing validator keystore JSON')
48
68
  .description('Adds attester/publisher/BLS entries to an existing keystore using the same flags as new')
49
69
  .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 =>
70
+ .option('--data-dir <path>', 'Directory where keystore(s) live. (default: ~/.aztec/keystore)')
71
+ .option('--file <name>', 'Override output file name. (default: key<N>.json)')
72
+ .option('--count <N>', 'Number of validators to add. (default: 1)', parseOptionalInteger)
73
+ .option('--publisher-count <N>', 'Number of publisher accounts per validator (default 0)', value =>
54
74
  parseOptionalInteger(value, 0),
55
75
  )
76
+ .option('--publishers <privateKeys>', 'Comma-separated list of publisher private keys for all validators.', value =>
77
+ value.split(',').map((key: string) => key.trim()),
78
+ )
56
79
  .option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation')
57
80
  .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)
81
+ .option('--account-index <N>', 'Base account index for ETH/BLS derivation', parseOptionalInteger)
82
+ .option('--address-index <N>', 'Base address index for ETH/BLS derivation', parseOptionalInteger)
83
+ .option(
84
+ '--coinbase <address>',
85
+ 'Coinbase ETH address to use when proposing. Defaults to attester address.',
86
+ parseEthereumAddress,
87
+ )
88
+ // TODO: add funding account back in when implemented
89
+ // .option('--funding-account <privateKey|address>', 'ETH private key (or address for remote signer setup) to fund publishers')
62
90
  .option('--remote-signer <url>', 'Default remote signer URL for accounts in this file')
63
91
  .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')
92
+ .option('--bls-path <path>', `EIP-2334 path (default ${defaultBlsPath})`)
66
93
  .option('--empty', 'Generate an empty skeleton without keys')
67
94
  .option(
68
95
  '--password <str>',
69
96
  'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed',
70
97
  )
71
- .option('--out-dir <dir>', 'Output directory for generated keystore file(s)')
98
+ .option('--encrypted-keystore-dir <dir>', 'Output directory for encrypted keystore file(s)')
72
99
  .option('--json', 'Echo resulting JSON to stdout')
73
100
  .requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress)
74
101
  .action(async (existing: string, options) => {
@@ -76,13 +103,32 @@ export function injectCommands(program: Command, log: LogFn) {
76
103
  await addValidatorKeys(existing, options, log);
77
104
  });
78
105
 
106
+ group
107
+ .command('staker')
108
+ .summary('Generate staking JSON from keystore')
109
+ .description(
110
+ 'Reads a validator keystore and outputs staking data with BLS public keys for each attester (skips mnemonics)',
111
+ )
112
+ .requiredOption('--from <keystore>', 'Path to keystore JSON file')
113
+ .option('--password <password>', 'Password for decrypting encrypted keystores (if not specified in keystore file)')
114
+ .requiredOption('--gse-address <address>', 'GSE contract address', parseEthereumAddress)
115
+ .option('--l1-rpc-urls <urls>', 'L1 RPC URLs (comma-separated)', value => value.split(','), [
116
+ 'http://localhost:8545',
117
+ ])
118
+ .option('-c, --l1-chain-id <number>', 'L1 chain ID', value => parseInt(value), 31337)
119
+ .option('--output <file>', 'Output file path (if not specified, JSON is written to stdout)')
120
+ .action(async options => {
121
+ const { generateStakerJson } = await import('./staker.js');
122
+ await generateStakerJson(options, log);
123
+ });
124
+
79
125
  // top-level convenience: aztec generate-bls-keypair
80
126
  program
81
127
  .command('generate-bls-keypair')
82
128
  .description('Generate a BLS keypair with convenience flags')
83
129
  .option('--mnemonic <mnemonic>', 'Mnemonic for BLS derivation')
84
130
  .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)')
131
+ .option('--bls-path <path>', `EIP-2334 path (default ${defaultBlsPath})`)
86
132
  .option('--g2', 'Derive on G2 subgroup')
87
133
  .option('--compressed', 'Output compressed public key')
88
134
  .option('--json', 'Print JSON output to stdout')
@@ -1,9 +1,13 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/utils';
2
+ import { GSEContract, createEthereumChain } from '@aztec/ethereum';
1
3
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
4
  import type { LogFn } from '@aztec/foundation/log';
3
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
6
 
5
7
  import { wordlist } from '@scure/bip39/wordlists/english.js';
6
- import { dirname } from 'path';
8
+ import { writeFile } from 'fs/promises';
9
+ import { basename, dirname, join } from 'path';
10
+ import { createPublicClient, fallback, http } from 'viem';
7
11
  import { generateMnemonic, mnemonicToAccount } from 'viem/accounts';
8
12
 
9
13
  import {
@@ -15,12 +19,20 @@ import {
15
19
  writeEthJsonV3ToFile,
16
20
  writeKeystoreFile,
17
21
  } from './shared.js';
22
+ import { processAttesterAccounts } from './staker.js';
23
+ import {
24
+ validateBlsPathOptions,
25
+ validatePublisherOptions,
26
+ validateRemoteSignerOptions,
27
+ validateStakerOutputOptions,
28
+ } from './utils.js';
18
29
 
19
30
  export type NewValidatorKeystoreOptions = {
20
31
  dataDir?: string;
21
32
  file?: string;
22
33
  count?: number;
23
34
  publisherCount?: number;
35
+ publishers?: string[];
24
36
  mnemonic?: string;
25
37
  passphrase?: string;
26
38
  accountIndex?: number;
@@ -28,68 +40,85 @@ export type NewValidatorKeystoreOptions = {
28
40
  separatePublisher?: boolean;
29
41
  ikm?: string;
30
42
  blsPath?: string;
31
- blsOnly?: boolean;
32
43
  password?: string;
33
- outDir?: string;
44
+ encryptedKeystoreDir?: string;
34
45
  json?: boolean;
35
46
  feeRecipient: AztecAddress;
36
47
  coinbase?: EthAddress;
37
48
  remoteSigner?: string;
38
- fundingAccount?: EthAddress;
49
+ stakerOutput?: boolean;
50
+ gseAddress?: EthAddress;
51
+ l1RpcUrls?: string[];
52
+ l1ChainId?: number;
39
53
  };
40
54
 
41
55
  export async function newValidatorKeystore(options: NewValidatorKeystoreOptions, log: LogFn) {
56
+ // validate bls-path inputs before proceeding with key generation
57
+ validateBlsPathOptions(options);
58
+ // validate staker output options before proceeding with key generation
59
+ validateStakerOutputOptions(options);
60
+ // validate publisher options
61
+ validatePublisherOptions(options);
62
+ // validate remote signer options
63
+ validateRemoteSignerOptions(options);
64
+
42
65
  const {
43
66
  dataDir,
44
67
  file,
45
68
  count,
46
69
  publisherCount = 0,
70
+ publishers,
47
71
  json,
48
72
  coinbase,
49
73
  accountIndex = 0,
50
74
  addressIndex = 0,
51
75
  feeRecipient,
52
76
  remoteSigner,
53
- fundingAccount,
54
- blsOnly,
55
77
  blsPath,
56
78
  ikm,
57
79
  mnemonic: _mnemonic,
58
80
  password,
59
- outDir,
81
+ encryptedKeystoreDir,
82
+ stakerOutput,
83
+ gseAddress,
84
+ l1RpcUrls,
85
+ l1ChainId,
60
86
  } = options;
61
87
 
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
88
  const mnemonic = _mnemonic ?? generateMnemonic(wordlist);
69
89
 
90
+ if (!_mnemonic && !json) {
91
+ log('No mnemonic provided, generating new one...');
92
+ log(`Using new mnemonic:`);
93
+ log('');
94
+ log(mnemonic);
95
+ log('');
96
+ }
97
+
70
98
  const validatorCount = typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
71
99
  const { outputPath } = await resolveKeystoreOutputPath(dataDir, file);
100
+ const keystoreOutDir = dirname(outputPath);
72
101
 
73
102
  const { validators, summaries } = await buildValidatorEntries({
74
103
  validatorCount,
75
104
  publisherCount,
105
+ publishers,
76
106
  accountIndex,
77
107
  baseAddressIndex: addressIndex,
78
108
  mnemonic,
79
109
  ikm,
80
110
  blsPath,
81
- blsOnly,
82
111
  feeRecipient,
83
112
  coinbase,
84
113
  remoteSigner,
85
- fundingAccount,
86
114
  });
87
115
 
88
116
  // If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
89
117
  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 });
118
+ const encryptedKeystoreOutDir =
119
+ encryptedKeystoreDir && encryptedKeystoreDir.length > 0 ? encryptedKeystoreDir : keystoreOutDir;
120
+ await writeEthJsonV3ToFile(validators, { outDir: encryptedKeystoreOutDir, password });
121
+ await writeBlsBn254ToFile(validators, { outDir: encryptedKeystoreOutDir, password });
93
122
  }
94
123
 
95
124
  const keystore = {
@@ -99,15 +128,66 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
99
128
 
100
129
  await writeKeystoreFile(outputPath, keystore);
101
130
 
102
- maybePrintJson(log, json, keystore as unknown as Record<string, any>);
103
- if (!json) {
131
+ // Generate staker outputs if requested
132
+ const allStakerOutputs: any[] = [];
133
+ if (stakerOutput && gseAddress && l1RpcUrls && l1ChainId !== undefined) {
134
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
135
+ const publicClient = createPublicClient({
136
+ chain: chain.chainInfo,
137
+ transport: fallback(l1RpcUrls.map(url => http(url))),
138
+ });
139
+ const gse = new GSEContract(publicClient, gseAddress);
140
+
141
+ // Extract keystore base name without extension for unique staker output filenames
142
+ const keystoreBaseName = basename(outputPath, '.json');
143
+
144
+ // Process each validator
145
+ for (let i = 0; i < validators.length; i++) {
146
+ const validator = validators[i];
147
+ const outputs = await processAttesterAccounts(validator.attester, gse, password);
148
+
149
+ // Collect all staker outputs
150
+ for (let j = 0; j < outputs.length; j++) {
151
+ allStakerOutputs.push(outputs[j]);
152
+ }
153
+ }
154
+
155
+ // Write a single JSON file with all staker outputs
156
+ if (allStakerOutputs.length > 0) {
157
+ const stakerOutputPath = join(keystoreOutDir, `${keystoreBaseName}_staker_output.json`);
158
+ await writeFile(stakerOutputPath, prettyPrintJSON(allStakerOutputs), 'utf-8');
159
+ }
160
+ }
161
+
162
+ const outputData = !_mnemonic ? { ...keystore, generatedMnemonic: mnemonic } : keystore;
163
+
164
+ // Handle JSON output
165
+ if (json) {
166
+ if (stakerOutput && allStakerOutputs.length > 0) {
167
+ const combinedOutput = {
168
+ keystore: outputData,
169
+ staker: allStakerOutputs,
170
+ };
171
+ maybePrintJson(log, json, combinedOutput as unknown as Record<string, any>);
172
+ } else {
173
+ maybePrintJson(log, json, outputData as unknown as Record<string, any>);
174
+ }
175
+ } else {
104
176
  log(`Wrote validator keystore to ${outputPath}`);
177
+ if (stakerOutput && allStakerOutputs.length > 0) {
178
+ const keystoreBaseName = basename(outputPath, '.json');
179
+ const stakerOutputPath = join(keystoreOutDir, `${keystoreBaseName}_staker_output.json`);
180
+ log(`Wrote staker output for ${allStakerOutputs.length} validator(s) to ${stakerOutputPath}`);
181
+ log('');
182
+ }
105
183
  }
106
184
 
107
- // Always print a concise summary of public keys (addresses and BLS pubkeys)
108
- logValidatorSummaries(log, summaries);
185
+ // print a concise summary of public keys (addresses and BLS pubkeys) if no --json options was selected
186
+ if (!json) {
187
+ logValidatorSummaries(log, summaries);
188
+ }
109
189
 
110
- if (!blsOnly && mnemonic && remoteSigner) {
190
+ if (mnemonic && remoteSigner && !json) {
111
191
  for (let i = 0; i < validatorCount; i++) {
112
192
  const addrIdx = addressIndex + i;
113
193
  const acct = mnemonicToAccount(mnemonic, {
@@ -117,4 +197,10 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
117
197
  log(`attester address: ${acct.address} remoteSignerUrl: ${remoteSigner}`);
118
198
  }
119
199
  }
200
+
201
+ // Log staker outputs if not in JSON mode
202
+ if (!json && stakerOutput && allStakerOutputs.length > 0) {
203
+ log('\nStaker outputs:');
204
+ log(prettyPrintJSON(allStakerOutputs));
205
+ }
120
206
  }