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

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 (120) 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_block.d.ts.map +1 -1
  5. package/dest/cmds/aztec_node/get_block.js +2 -1
  6. package/dest/cmds/aztec_node/get_current_base_fee.d.ts +1 -1
  7. package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts +1 -1
  8. package/dest/cmds/aztec_node/get_logs.d.ts +3 -2
  9. package/dest/cmds/aztec_node/get_logs.d.ts.map +1 -1
  10. package/dest/cmds/aztec_node/get_node_info.d.ts +1 -1
  11. package/dest/cmds/aztec_node/index.d.ts +1 -1
  12. package/dest/cmds/contracts/index.d.ts +1 -1
  13. package/dest/cmds/contracts/inspect_contract.d.ts +1 -1
  14. package/dest/cmds/contracts/inspect_contract.d.ts.map +1 -1
  15. package/dest/cmds/contracts/inspect_contract.js +3 -9
  16. package/dest/cmds/contracts/parse_parameter_struct.d.ts +1 -1
  17. package/dest/cmds/infrastructure/index.d.ts +1 -1
  18. package/dest/cmds/infrastructure/index.d.ts.map +1 -1
  19. package/dest/cmds/infrastructure/index.js +0 -1
  20. package/dest/cmds/infrastructure/sequencers.d.ts +1 -2
  21. package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -1
  22. package/dest/cmds/infrastructure/setup_l2_contract.d.ts +1 -1
  23. package/dest/cmds/l1/advance_epoch.d.ts +1 -1
  24. package/dest/cmds/l1/assume_proven_through.d.ts +1 -1
  25. package/dest/cmds/l1/assume_proven_through.d.ts.map +1 -1
  26. package/dest/cmds/l1/assume_proven_through.js +2 -1
  27. package/dest/cmds/l1/bridge_erc20.d.ts +1 -1
  28. package/dest/cmds/l1/create_l1_account.d.ts +1 -1
  29. package/dest/cmds/l1/deploy_l1_contracts.d.ts +1 -1
  30. package/dest/cmds/l1/deploy_new_rollup.d.ts +1 -1
  31. package/dest/cmds/l1/get_l1_addresses.d.ts +1 -1
  32. package/dest/cmds/l1/get_l1_balance.d.ts +1 -1
  33. package/dest/cmds/l1/governance_utils.d.ts +5 -5
  34. package/dest/cmds/l1/governance_utils.d.ts.map +1 -1
  35. package/dest/cmds/l1/index.d.ts +1 -1
  36. package/dest/cmds/l1/prover_stats.d.ts +1 -1
  37. package/dest/cmds/l1/prover_stats.d.ts.map +1 -1
  38. package/dest/cmds/l1/prover_stats.js +28 -28
  39. package/dest/cmds/l1/trigger_seed_snapshot.d.ts +2 -2
  40. package/dest/cmds/l1/trigger_seed_snapshot.d.ts.map +1 -1
  41. package/dest/cmds/l1/update_l1_validators.d.ts +6 -6
  42. package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
  43. package/dest/cmds/l1/update_l1_validators.js +2 -2
  44. package/dest/cmds/misc/compute_selector.d.ts +1 -1
  45. package/dest/cmds/misc/example_contracts.d.ts +1 -1
  46. package/dest/cmds/misc/generate_bootnode_enr.d.ts +1 -1
  47. package/dest/cmds/misc/generate_p2p_private_key.d.ts +1 -1
  48. package/dest/cmds/misc/generate_secret_and_hash.d.ts +1 -1
  49. package/dest/cmds/misc/generate_secret_key.d.ts +1 -1
  50. package/dest/cmds/misc/get_canonical_sponsored_fpc_address.d.ts +1 -1
  51. package/dest/cmds/misc/index.d.ts +1 -1
  52. package/dest/cmds/misc/update/common.d.ts +1 -1
  53. package/dest/cmds/misc/update/github.d.ts +1 -1
  54. package/dest/cmds/misc/update/noir.d.ts +1 -1
  55. package/dest/cmds/misc/update/npm.d.ts +1 -1
  56. package/dest/cmds/misc/update/npm.js +1 -1
  57. package/dest/cmds/misc/update/utils.d.ts +1 -1
  58. package/dest/cmds/misc/update.d.ts +1 -1
  59. package/dest/cmds/validator_keys/add.d.ts +1 -1
  60. package/dest/cmds/validator_keys/add.d.ts.map +1 -1
  61. package/dest/cmds/validator_keys/add.js +20 -7
  62. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts +1 -1
  63. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts.map +1 -1
  64. package/dest/cmds/validator_keys/generate_bls_keypair.js +2 -1
  65. package/dest/cmds/validator_keys/index.d.ts +1 -1
  66. package/dest/cmds/validator_keys/index.d.ts.map +1 -1
  67. package/dest/cmds/validator_keys/index.js +16 -4
  68. package/dest/cmds/validator_keys/new.d.ts +7 -4
  69. package/dest/cmds/validator_keys/new.d.ts.map +1 -1
  70. package/dest/cmds/validator_keys/new.js +87 -16
  71. package/dest/cmds/validator_keys/shared.d.ts +4 -4
  72. package/dest/cmds/validator_keys/shared.d.ts.map +1 -1
  73. package/dest/cmds/validator_keys/shared.js +29 -27
  74. package/dest/cmds/validator_keys/staker.d.ts +38 -0
  75. package/dest/cmds/validator_keys/staker.d.ts.map +1 -0
  76. package/dest/cmds/validator_keys/staker.js +207 -0
  77. package/dest/cmds/validator_keys/utils.d.ts +25 -0
  78. package/dest/cmds/validator_keys/utils.d.ts.map +1 -0
  79. package/dest/cmds/validator_keys/utils.js +52 -0
  80. package/dest/config/cached_fetch.d.ts +1 -1
  81. package/dest/config/chain_l2_config.d.ts +11 -10
  82. package/dest/config/chain_l2_config.d.ts.map +1 -1
  83. package/dest/config/chain_l2_config.js +64 -34
  84. package/dest/config/enrich_env.d.ts +1 -1
  85. package/dest/config/get_l1_config.d.ts +1 -1
  86. package/dest/config/index.d.ts +1 -1
  87. package/dest/config/network_config.d.ts +6 -3
  88. package/dest/config/network_config.d.ts.map +1 -1
  89. package/dest/config/network_config.js +58 -28
  90. package/dest/utils/aztec.d.ts +1 -1
  91. package/dest/utils/aztec.d.ts.map +1 -1
  92. package/dest/utils/commands.d.ts +2 -2
  93. package/dest/utils/commands.d.ts.map +1 -1
  94. package/dest/utils/encoding.d.ts +1 -1
  95. package/dest/utils/github.d.ts +1 -1
  96. package/dest/utils/index.d.ts +1 -1
  97. package/dest/utils/inspect.d.ts +3 -2
  98. package/dest/utils/inspect.d.ts.map +1 -1
  99. package/dest/utils/setup_contracts.d.ts +1 -1
  100. package/package.json +34 -29
  101. package/public_include_metric_prefixes.json +1 -0
  102. package/src/cmds/aztec_node/get_block.ts +2 -1
  103. package/src/cmds/aztec_node/get_logs.ts +3 -2
  104. package/src/cmds/contracts/inspect_contract.ts +3 -10
  105. package/src/cmds/infrastructure/index.ts +0 -1
  106. package/src/cmds/infrastructure/sequencers.ts +0 -1
  107. package/src/cmds/l1/assume_proven_through.ts +4 -1
  108. package/src/cmds/l1/prover_stats.ts +36 -29
  109. package/src/cmds/l1/update_l1_validators.ts +2 -2
  110. package/src/cmds/misc/update/npm.ts +1 -1
  111. package/src/cmds/validator_keys/add.ts +20 -10
  112. package/src/cmds/validator_keys/generate_bls_keypair.ts +2 -1
  113. package/src/cmds/validator_keys/index.ts +67 -21
  114. package/src/cmds/validator_keys/new.ts +109 -23
  115. package/src/cmds/validator_keys/shared.ts +30 -26
  116. package/src/cmds/validator_keys/staker.ts +300 -0
  117. package/src/cmds/validator_keys/utils.ts +80 -0
  118. package/src/config/chain_l2_config.ts +86 -45
  119. package/src/config/network_config.ts +67 -29
  120. package/src/utils/inspect.ts +2 -1
@@ -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
  }
@@ -13,27 +13,42 @@ import { homedir } from 'os';
13
13
  import { dirname, isAbsolute, join } from 'path';
14
14
  import { mnemonicToAccount } from 'viem/accounts';
15
15
 
16
+ import { defaultBlsPath } from './utils.js';
17
+
16
18
  export type ValidatorSummary = { attesterEth?: string; attesterBls?: string; publisherEth?: string[] };
17
19
 
18
20
  export type BuildValidatorsInput = {
19
21
  validatorCount: number;
20
22
  publisherCount?: number;
23
+ publishers?: string[];
21
24
  accountIndex: number;
22
25
  baseAddressIndex: number;
23
26
  mnemonic: string;
24
27
  ikm?: string;
25
28
  blsPath?: string;
26
- blsOnly?: boolean;
27
29
  feeRecipient: AztecAddress;
28
30
  coinbase?: EthAddress;
29
31
  remoteSigner?: string;
30
- fundingAccount?: EthAddress;
31
32
  };
32
33
 
33
- export function withValidatorIndex(path: string, index: number) {
34
+ export function withValidatorIndex(path: string, accountIndex: number = 0, addressIndex: number = 0) {
35
+ // NOTE: The legacy BLS CLI is to allow users who generated keys in 2.1.4 to be able to use the same command
36
+ // 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.
37
+ const useLegacyBlsCli = ['true', '1', 'yes', 'y'].includes(process.env.LEGACY_BLS_CLI ?? '');
38
+
39
+ const defaultBlsPathParts = defaultBlsPath.split('/');
40
+
34
41
  const parts = path.split('/');
35
- if (parts.length >= 4 && parts[0] === 'm' && parts[1] === '12381' && parts[2] === '3600') {
36
- parts[3] = String(index);
42
+ if (parts.length == defaultBlsPathParts.length && parts.every((part, index) => part === defaultBlsPathParts[index])) {
43
+ if (useLegacyBlsCli) {
44
+ // In 2.1.4, we were using address-index in parts[3] and did NOT use account-index, check lines 32 & 84
45
+ // https://github.com/AztecProtocol/aztec-packages/blob/v2.1.4/yarn-project/cli/src/cmds/validator_keys/shared.ts
46
+
47
+ parts[3] = String(addressIndex);
48
+ } else {
49
+ parts[3] = String(accountIndex);
50
+ parts[5] = String(addressIndex);
51
+ }
37
52
  return parts.join('/');
38
53
  }
39
54
  return path;
@@ -64,42 +79,37 @@ export async function buildValidatorEntries(input: BuildValidatorsInput) {
64
79
  const {
65
80
  validatorCount,
66
81
  publisherCount = 0,
82
+ publishers,
67
83
  accountIndex,
68
84
  baseAddressIndex,
69
85
  mnemonic,
70
86
  ikm,
71
87
  blsPath,
72
- blsOnly,
73
88
  feeRecipient,
74
89
  coinbase,
75
90
  remoteSigner,
76
- fundingAccount,
77
91
  } = input;
78
92
 
79
- const defaultBlsPath = 'm/12381/3600/0/0/0';
80
93
  const summaries: ValidatorSummary[] = [];
81
94
 
82
95
  const validators = await Promise.all(
83
96
  Array.from({ length: validatorCount }, async (_unused, i) => {
84
97
  const addressIndex = baseAddressIndex + i;
85
98
  const basePath = blsPath ?? defaultBlsPath;
86
- const perValidatorPath = withValidatorIndex(basePath, addressIndex);
99
+ const perValidatorPath = withValidatorIndex(basePath, accountIndex, addressIndex);
87
100
 
88
- const blsPrivKey = blsOnly || ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
101
+ const blsPrivKey = ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
89
102
  const blsPubCompressed = blsPrivKey ? await computeBlsPublicKeyCompressed(blsPrivKey) : undefined;
90
103
 
91
- if (blsOnly) {
92
- const attester = { bls: blsPrivKey! };
93
- summaries.push({ attesterBls: blsPubCompressed });
94
- return { attester, feeRecipient } as ValidatorKeyStore;
95
- }
96
-
97
104
  const ethAttester = deriveEthAttester(mnemonic, accountIndex, addressIndex, remoteSigner);
98
105
  const attester = blsPrivKey ? { eth: ethAttester, bls: blsPrivKey } : ethAttester;
99
106
 
100
107
  let publisherField: EthAccount | EthPrivateKey | (EthAccount | EthPrivateKey)[] | undefined;
101
108
  const publisherAddresses: string[] = [];
102
- if (publisherCount > 0) {
109
+ if (publishers && publishers.length > 0) {
110
+ publisherAddresses.push(...publishers);
111
+ publisherField = publishers.length === 1 ? (publishers[0] as EthPrivateKey) : (publishers as EthPrivateKey[]);
112
+ } else if (publisherCount > 0) {
103
113
  const publishersBaseIndex = baseAddressIndex + validatorCount + i * publisherCount;
104
114
  const publisherAccounts = Array.from({ length: publisherCount }, (_unused2, j) => {
105
115
  const publisherAddressIndex = publishersBaseIndex + j;
@@ -130,8 +140,7 @@ export async function buildValidatorEntries(input: BuildValidatorsInput) {
130
140
  attester,
131
141
  ...(publisherField !== undefined ? { publisher: publisherField } : {}),
132
142
  feeRecipient,
133
- coinbase,
134
- fundingAccount,
143
+ coinbase: coinbase ?? attesterEthAddress,
135
144
  } as ValidatorKeyStore;
136
145
  }),
137
146
  );
@@ -229,7 +238,7 @@ export async function writeBn254BlsKeystore(
229
238
  /** Replace plaintext BLS keys in validators with { path, password } pointing to BN254 keystore files. */
230
239
  export async function writeBlsBn254ToFile(
231
240
  validators: ValidatorKeyStore[],
232
- options: { outDir: string; password: string },
241
+ options: { outDir: string; password: string; blsPath?: string },
233
242
  ): Promise<void> {
234
243
  for (let i = 0; i < validators.length; i++) {
235
244
  const v = validators[i];
@@ -245,7 +254,7 @@ export async function writeBlsBn254ToFile(
245
254
  }
246
255
 
247
256
  const pub = await computeBlsPublicKeyCompressed(blsKey);
248
- const path = 'm/12381/3600/0/0/0';
257
+ const path = options.blsPath ?? defaultBlsPath;
249
258
  const fileBase = `${String(i + 1)}_${pub.slice(2, 18)}`;
250
259
  const keystorePath = await writeBn254BlsKeystore(options.outDir, fileBase, options.password, blsKey, pub, path);
251
260
 
@@ -312,10 +321,5 @@ export async function writeEthJsonV3ToFile(
312
321
  (v as any).publisher = await maybeEncryptEth(pub, `publisher_${i + 1}`);
313
322
  }
314
323
  }
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
324
  }
321
325
  }
@@ -0,0 +1,300 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/utils';
2
+ import { GSEContract, createEthereumChain } from '@aztec/ethereum';
3
+ import { computeBn254G1PublicKey, computeBn254G2PublicKey } from '@aztec/foundation/crypto';
4
+ import { decryptBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
5
+ import type { EthAddress } from '@aztec/foundation/eth-address';
6
+ import { Fr } from '@aztec/foundation/fields';
7
+ import type { LogFn } from '@aztec/foundation/log';
8
+ import { loadKeystoreFile } from '@aztec/node-keystore/loader';
9
+ import type {
10
+ AttesterAccount,
11
+ AttesterAccounts,
12
+ BLSAccount,
13
+ EncryptedKeyFileConfig,
14
+ EthAccount,
15
+ MnemonicConfig,
16
+ } from '@aztec/node-keystore/types';
17
+
18
+ import { Wallet } from '@ethersproject/wallet';
19
+ import { readFileSync, writeFileSync } from 'fs';
20
+ import { basename, dirname, join } from 'path';
21
+ import { createPublicClient, fallback, http } from 'viem';
22
+ import { privateKeyToAddress } from 'viem/accounts';
23
+
24
+ export type StakerOptions = {
25
+ from: string;
26
+ password?: string;
27
+ output?: string;
28
+ gseAddress: EthAddress;
29
+ l1RpcUrls: string[];
30
+ l1ChainId: number;
31
+ };
32
+
33
+ export type StakerOutput = {
34
+ attester: string;
35
+ publicKeyG1: {
36
+ x: string;
37
+ y: string;
38
+ };
39
+ publicKeyG2: {
40
+ x0: string;
41
+ x1: string;
42
+ y0: string;
43
+ y1: string;
44
+ };
45
+ proofOfPossession: {
46
+ x: string;
47
+ y: string;
48
+ };
49
+ };
50
+
51
+ /**
52
+ * Check if an object is a MnemonicConfig
53
+ */
54
+ function isMnemonicConfig(obj: unknown): obj is MnemonicConfig {
55
+ return typeof obj === 'object' && obj !== null && 'mnemonic' in obj;
56
+ }
57
+
58
+ /**
59
+ * Check if a value is an encrypted keystore file config
60
+ */
61
+ function isEncryptedKeyFileConfig(value: unknown): value is EncryptedKeyFileConfig {
62
+ return typeof value === 'object' && value !== null && 'path' in value;
63
+ }
64
+
65
+ /**
66
+ * Check if a BLSAccount is a private key string (not an encrypted keystore file)
67
+ */
68
+ function isBlsPrivateKey(bls: unknown): bls is string {
69
+ return typeof bls === 'string' && bls.startsWith('0x');
70
+ }
71
+
72
+ /**
73
+ * Check if an EthAccount is a private key string (66 chars: 0x + 64 hex)
74
+ */
75
+ function isEthPrivateKey(eth: unknown): eth is string {
76
+ return typeof eth === 'string' && eth.startsWith('0x') && eth.length === 66;
77
+ }
78
+
79
+ /**
80
+ * Check if a string is an Ethereum address (42 chars: 0x + 40 hex)
81
+ */
82
+ function isEthAddress(value: unknown): value is string {
83
+ return typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value);
84
+ }
85
+
86
+ /**
87
+ * Decrypt a BLS private key from an encrypted keystore file
88
+ */
89
+ function decryptBlsKey(bls: BLSAccount, password?: string): string | undefined {
90
+ if (isBlsPrivateKey(bls)) {
91
+ return bls;
92
+ }
93
+
94
+ if (isEncryptedKeyFileConfig(bls)) {
95
+ if (!password && !bls.password) {
96
+ return undefined; // Can't decrypt without password
97
+ }
98
+ const pwd = password ?? bls.password!;
99
+ return decryptBn254Keystore(bls.path, pwd);
100
+ }
101
+
102
+ return undefined;
103
+ }
104
+
105
+ /**
106
+ * Decrypt an Ethereum private key from an encrypted keystore file
107
+ */
108
+ async function decryptEthKey(eth: EthAccount, password?: string): Promise<string | undefined> {
109
+ if (isEthPrivateKey(eth)) {
110
+ return eth;
111
+ }
112
+
113
+ if (isEncryptedKeyFileConfig(eth)) {
114
+ if (!password && !eth.password) {
115
+ return undefined; // Can't decrypt without password
116
+ }
117
+ const pwd = password ?? eth.password!;
118
+ const json = readFileSync(eth.path, 'utf-8');
119
+ const wallet = await Wallet.fromEncryptedJson(json, pwd);
120
+ return wallet.privateKey as string;
121
+ }
122
+
123
+ return undefined;
124
+ }
125
+
126
+ /**
127
+ * Extract Ethereum address from an EthAccount (or private key)
128
+ */
129
+ async function getEthAddress(eth: EthAccount | string, password?: string): Promise<EthAddress | undefined> {
130
+ // Case 1: It's a private key string - derive the address
131
+ if (isEthPrivateKey(eth)) {
132
+ return privateKeyToAddress(eth as `0x${string}`) as unknown as EthAddress;
133
+ }
134
+
135
+ // Case 2: It's just an address string directly (EthRemoteSignerAccount can be just EthAddress)
136
+ if (isEthAddress(eth)) {
137
+ return eth as unknown as EthAddress;
138
+ }
139
+
140
+ // Case 3: It's an object with an address property (remote signer config)
141
+ if (typeof eth === 'object' && eth !== null && 'address' in eth) {
142
+ return (eth as any).address as EthAddress;
143
+ }
144
+
145
+ // Case 4: It's an encrypted keystore file - decrypt and derive address
146
+ if (isEncryptedKeyFileConfig(eth)) {
147
+ const privateKey = await decryptEthKey(eth, password);
148
+ if (privateKey) {
149
+ return privateKeyToAddress(privateKey as `0x${string}`) as unknown as EthAddress;
150
+ }
151
+ return undefined;
152
+ }
153
+
154
+ return undefined;
155
+ }
156
+
157
+ /**
158
+ * Extract BLS private key and Ethereum address from an AttesterAccount
159
+ */
160
+ async function extractAttesterInfo(
161
+ attester: AttesterAccount,
162
+ password?: string,
163
+ ): Promise<{ blsPrivateKey?: string; ethAddress?: EthAddress }> {
164
+ // Case 1: attester is { eth: EthAccount, bls?: BLSAccount }
165
+ if (typeof attester === 'object' && attester !== null && 'eth' in attester) {
166
+ const ethAddress = await getEthAddress(attester.eth, password);
167
+ const blsPrivateKey = attester.bls ? decryptBlsKey(attester.bls, password) : undefined;
168
+ return { blsPrivateKey, ethAddress };
169
+ }
170
+
171
+ // Case 2: attester is just an EthAccount directly (no BLS key)
172
+ return {
173
+ blsPrivateKey: undefined,
174
+ ethAddress: await getEthAddress(attester as EthAccount, password),
175
+ };
176
+ }
177
+
178
+ /**
179
+ * Process a single attester entry and output staking JSON
180
+ */
181
+ async function processAttester(
182
+ attester: AttesterAccount,
183
+ gse: GSEContract,
184
+ password?: string,
185
+ ): Promise<StakerOutput | undefined> {
186
+ const { blsPrivateKey, ethAddress } = await extractAttesterInfo(attester, password);
187
+
188
+ // Skip if no BLS private key or no Ethereum address
189
+ if (!blsPrivateKey || !ethAddress) {
190
+ return undefined;
191
+ }
192
+
193
+ // Derive G1 and G2 public keys
194
+ const g1PublicKey = await computeBn254G1PublicKey(blsPrivateKey);
195
+ const g2PublicKey = await computeBn254G2PublicKey(blsPrivateKey);
196
+
197
+ // Generate proof of possession
198
+ const bn254SecretKeyFieldElement = Fr.fromString(blsPrivateKey);
199
+ const registrationTuple = await gse.makeRegistrationTuple(bn254SecretKeyFieldElement.toBigInt());
200
+
201
+ return {
202
+ attester: String(ethAddress),
203
+ publicKeyG1: {
204
+ x: '0x' + g1PublicKey.x.toString(16).padStart(64, '0'),
205
+ y: '0x' + g1PublicKey.y.toString(16).padStart(64, '0'),
206
+ },
207
+ publicKeyG2: {
208
+ x0: '0x' + g2PublicKey.x.c0.toString(16).padStart(64, '0'),
209
+ x1: '0x' + g2PublicKey.x.c1.toString(16).padStart(64, '0'),
210
+ y0: '0x' + g2PublicKey.y.c0.toString(16).padStart(64, '0'),
211
+ y1: '0x' + g2PublicKey.y.c1.toString(16).padStart(64, '0'),
212
+ },
213
+ proofOfPossession: {
214
+ x: '0x' + registrationTuple.proofOfPossession.x.toString(16),
215
+ y: '0x' + registrationTuple.proofOfPossession.y.toString(16),
216
+ },
217
+ };
218
+ }
219
+
220
+ /**
221
+ * Process AttesterAccounts (which can be a single attester, array, or mnemonic)
222
+ */
223
+ export async function processAttesterAccounts(
224
+ attesterAccounts: AttesterAccounts,
225
+ gse: GSEContract,
226
+ password?: string,
227
+ ): Promise<StakerOutput[]> {
228
+ // Skip mnemonic configs
229
+ if (isMnemonicConfig(attesterAccounts)) {
230
+ return [];
231
+ }
232
+
233
+ // Handle array of attesters
234
+ if (Array.isArray(attesterAccounts)) {
235
+ const results: StakerOutput[] = [];
236
+ for (const attester of attesterAccounts) {
237
+ const result = await processAttester(attester, gse, password);
238
+ if (result) {
239
+ results.push(result);
240
+ }
241
+ }
242
+ return results;
243
+ }
244
+
245
+ // Handle single attester
246
+ const result = await processAttester(attesterAccounts, gse, password);
247
+ return result ? [result] : [];
248
+ }
249
+
250
+ /**
251
+ * Main staker command function
252
+ */
253
+ export async function generateStakerJson(options: StakerOptions, log: LogFn): Promise<void> {
254
+ const { from, password, gseAddress, l1RpcUrls, l1ChainId, output } = options;
255
+
256
+ // Load the keystore file
257
+ const keystore = loadKeystoreFile(from);
258
+
259
+ if (!gseAddress) {
260
+ throw new Error('GSE contract address is required');
261
+ }
262
+ log(`Calling GSE contract ${gseAddress} on chain ${l1ChainId}, using ${l1RpcUrls.join(', ')} to get staker outputs`);
263
+
264
+ if (!keystore.validators || keystore.validators.length === 0) {
265
+ log('No validators found in keystore');
266
+ return;
267
+ }
268
+
269
+ const allOutputs: StakerOutput[] = [];
270
+
271
+ // L1 client for proof of possession
272
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
273
+ const publicClient = createPublicClient({
274
+ chain: chain.chainInfo,
275
+ transport: fallback(l1RpcUrls.map(url => http(url))),
276
+ });
277
+ const gse = new GSEContract(publicClient, gseAddress);
278
+
279
+ const keystoreBaseName = basename(from, '.json');
280
+ const outputDir = output ? output : dirname(from);
281
+
282
+ for (let i = 0; i < keystore.validators.length; i++) {
283
+ const validator = keystore.validators[i];
284
+ const outputs = await processAttesterAccounts(validator.attester, gse, password);
285
+
286
+ for (let j = 0; j < outputs.length; j++) {
287
+ allOutputs.push(outputs[j]);
288
+ }
289
+ }
290
+
291
+ if (allOutputs.length === 0) {
292
+ log('No attesters with BLS keys found (skipping mnemonics and encrypted keystores without password)');
293
+ return;
294
+ }
295
+
296
+ // Write a single JSON file with all staker outputs
297
+ const stakerOutputPath = join(outputDir, `${keystoreBaseName}_staker_output.json`);
298
+ writeFileSync(stakerOutputPath, prettyPrintJSON(allOutputs), 'utf-8');
299
+ log(`Wrote staker output for ${allOutputs.length} validator(s) to ${stakerOutputPath}`);
300
+ }