@aztec/cli 2.1.2-rc.3 → 2.1.2-rc.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/add.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAQnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAU5D,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAElE,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,GAAG,EAAE,KAAK,iBA2FpG"}
1
+ {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/add.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAQnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAU5D,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAElE,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,GAAG,EAAE,KAAK,iBAyFpG"}
@@ -4,7 +4,7 @@ import { dirname, isAbsolute, join } from 'path';
4
4
  import { generateMnemonic } from 'viem/accounts';
5
5
  import { buildValidatorEntries, logValidatorSummaries, maybePrintJson, writeBlsBn254ToFile, writeEthJsonV3ToFile, writeKeystoreFile } from './shared.js';
6
6
  export async function addValidatorKeys(existing, options, log) {
7
- const { dataDir, file, count, publisherCount = 0, mnemonic, accountIndex = 0, addressIndex, ikm, blsPath, blsOnly, json, feeRecipient: feeRecipientOpt, coinbase: coinbaseOpt, fundingAccount: fundingAccountOpt, remoteSigner: remoteSignerOpt, password, outDir } = options;
7
+ const { dataDir, file, count, publisherCount = 0, mnemonic, accountIndex = 0, addressIndex, ikm, blsPath, json, feeRecipient: feeRecipientOpt, coinbase: coinbaseOpt, fundingAccount: fundingAccountOpt, remoteSigner: remoteSignerOpt, password, outDir } = options;
8
8
  const validatorCount = typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
9
9
  const baseAddressIndex = addressIndex ?? 0;
10
10
  const keystore = loadKeystoreFile(existing);
@@ -32,7 +32,6 @@ export async function addValidatorKeys(existing, options, log) {
32
32
  mnemonic: mnemonicToUse,
33
33
  ikm,
34
34
  blsPath,
35
- blsOnly,
36
35
  feeRecipient,
37
36
  coinbase,
38
37
  remoteSigner,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,WAyF1D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,WAqH1D"}
@@ -1,16 +1,23 @@
1
1
  import { parseAztecAddress, parseEthereumAddress, parseHex, parseOptionalInteger } from '../../utils/commands.js';
2
2
  export function injectCommands(program, log) {
3
3
  const group = program.command('validator-keys').aliases([
4
- 'valKeys'
4
+ 'valKeys',
5
+ 'valkeys'
5
6
  ]).description('Manage validator keystores for node operators');
6
- group.command('new').summary('Generate a new validator keystore JSON').description('Generates a new validator keystore with ETH secp256k1 accounts and optional BLS accounts').option('--data-dir <path>', 'Directory to store keystore(s). Defaults to ~/.aztec/keystore').option('--file <name>', 'Keystore file name. Defaults to key1.json (or keyN.json if key1.json exists)').option('--count <N>', 'Number of validators to generate', parseOptionalInteger).option('--publisher-count <N>', 'Number of publisher accounts per validator (default 1)', (value)=>parseOptionalInteger(value, 0)).option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation').option('--passphrase <str>', 'Optional passphrase for mnemonic').option('--account-index <N>', 'Base account index for ETH derivation', parseOptionalInteger).option('--address-index <N>', 'Base address index for ETH derivation', parseOptionalInteger).option('--coinbase <address>', 'Coinbase ETH address to use when proposing', parseEthereumAddress).option('--funding-account <address>', 'ETH account to fund publishers', parseEthereumAddress).option('--remote-signer <url>', 'Default remote signer URL for accounts in this file').option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', (value)=>parseHex(value, 32)).option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)').option('--bls-only', 'Generate only BLS keys').option('--password <str>', 'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed').option('--out-dir <dir>', 'Output directory for generated keystore file(s)').option('--json', 'Echo resulting JSON to stdout').requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress).action(async (options)=>{
7
+ group.command('new').summary('Generate a new validator keystore JSON').description('Generates a new validator keystore with ETH secp256k1 accounts and optional BLS accounts').option('--data-dir <path>', 'Directory to store keystore(s). Defaults to ~/.aztec/keystore').option('--file <name>', 'Keystore file name. Defaults to key1.json (or keyN.json if key1.json exists)').option('--count <N>', 'Number of validators to generate', parseOptionalInteger).option('--publisher-count <N>', 'Number of publisher accounts per validator (default 1)', (value)=>parseOptionalInteger(value, 0)).option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation').option('--passphrase <str>', 'Optional passphrase for mnemonic').option('--account-index <N>', 'Base account index for ETH derivation', parseOptionalInteger).option('--address-index <N>', 'Base address index for ETH derivation', parseOptionalInteger).option('--coinbase <address>', 'Coinbase ETH address to use when proposing', parseEthereumAddress).option('--funding-account <address>', 'ETH account to fund publishers', parseEthereumAddress).option('--remote-signer <url>', 'Default remote signer URL for accounts in this file').option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', (value)=>parseHex(value, 32)).option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)').option('--password <str>', 'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed').option('--out-dir <dir>', 'Output directory for generated keystore file(s)').option('--json', 'Echo resulting JSON to stdout').option('--staker-output', 'Generate staker output JSON files for each attester').option('--gse-address <address>', 'GSE contract address (required with --staker-output)', parseEthereumAddress).option('--l1-rpc-urls <urls>', 'L1 RPC URLs (comma-separated, required with --staker-output)', (value)=>value.split(',')).option('-c, --l1-chain-id <number>', 'L1 chain ID (required with --staker-output)', (value)=>parseInt(value), 31337).requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress).action(async (options)=>{
7
8
  const { newValidatorKeystore } = await import('./new.js');
8
9
  await newValidatorKeystore(options, log);
9
10
  });
10
- group.command('add').summary('Augment an existing validator keystore JSON').description('Adds attester/publisher/BLS entries to an existing keystore using the same flags as new').argument('<existing>', 'Path to existing keystore JSON').option('--data-dir <path>', 'Directory where keystore(s) live').option('--file <name>', 'Override output file name').option('--count <N>', 'Number of validators to add', parseOptionalInteger).option('--publisher-count <N>', 'Number of publisher accounts per validator (default 1)', (value)=>parseOptionalInteger(value, 0)).option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation').option('--passphrase <str>', 'Optional passphrase for mnemonic').option('--account-index <N>', 'Base account index for ETH derivation', parseOptionalInteger).option('--address-index <N>', 'Base address index for ETH derivation', parseOptionalInteger).option('--coinbase <address>', 'Coinbase ETH address to use when proposing', parseEthereumAddress).option('--funding-account <address>', 'ETH account to fund publishers', parseEthereumAddress).option('--remote-signer <url>', 'Default remote signer URL for accounts in this file').option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', (value)=>parseHex(value, 32)).option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)').option('--bls-only', 'Generate only BLS keys').option('--empty', 'Generate an empty skeleton without keys').option('--password <str>', 'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed').option('--out-dir <dir>', 'Output directory for generated keystore file(s)').option('--json', 'Echo resulting JSON to stdout').requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress).action(async (existing, options)=>{
11
+ group.command('add').summary('Augment an existing validator keystore JSON').description('Adds attester/publisher/BLS entries to an existing keystore using the same flags as new').argument('<existing>', 'Path to existing keystore JSON').option('--data-dir <path>', 'Directory where keystore(s) live').option('--file <name>', 'Override output file name').option('--count <N>', 'Number of validators to add', parseOptionalInteger).option('--publisher-count <N>', 'Number of publisher accounts per validator (default 1)', (value)=>parseOptionalInteger(value, 0)).option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation').option('--passphrase <str>', 'Optional passphrase for mnemonic').option('--account-index <N>', 'Base account index for ETH derivation', parseOptionalInteger).option('--address-index <N>', 'Base address index for ETH derivation', parseOptionalInteger).option('--coinbase <address>', 'Coinbase ETH address to use when proposing', parseEthereumAddress).option('--funding-account <address>', 'ETH account to fund publishers', parseEthereumAddress).option('--remote-signer <url>', 'Default remote signer URL for accounts in this file').option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', (value)=>parseHex(value, 32)).option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)').option('--empty', 'Generate an empty skeleton without keys').option('--password <str>', 'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed').option('--out-dir <dir>', 'Output directory for generated keystore file(s)').option('--json', 'Echo resulting JSON to stdout').requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress).action(async (existing, options)=>{
11
12
  const { addValidatorKeys } = await import('./add.js');
12
13
  await addValidatorKeys(existing, options, log);
13
14
  });
15
+ group.command('staker').summary('Generate staking JSON from keystore').description('Reads a validator keystore and outputs staking data with BLS public keys for each attester (skips mnemonics)').requiredOption('--from <keystore>', 'Path to keystore JSON file').option('--password <password>', 'Password for decrypting encrypted keystores (if not specified in keystore file)').requiredOption('--gse-address <address>', 'GSE contract address', parseEthereumAddress).option('--l1-rpc-urls <urls>', 'L1 RPC URLs (comma-separated)', (value)=>value.split(','), [
16
+ 'http://localhost:8545'
17
+ ]).option('-c, --l1-chain-id <number>', 'L1 chain ID', (value)=>parseInt(value), 31337).option('--output <file>', 'Output file path (if not specified, JSON is written to stdout)').action(async (options)=>{
18
+ const { generateStakerJson } = await import('./staker.js');
19
+ await generateStakerJson(options, log);
20
+ });
14
21
  // top-level convenience: aztec generate-bls-keypair
15
22
  program.command('generate-bls-keypair').description('Generate a BLS keypair with convenience flags').option('--mnemonic <mnemonic>', 'Mnemonic for BLS derivation').option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', (value)=>parseHex(value, 32)).option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)').option('--g2', 'Derive on G2 subgroup').option('--compressed', 'Output compressed public key').option('--json', 'Print JSON output to stdout').option('--out <file>', 'Write output to file').action(async (options)=>{
16
23
  const { generateBlsKeypair } = await import('./generate_bls_keypair.js');
@@ -13,7 +13,6 @@ export type NewValidatorKeystoreOptions = {
13
13
  separatePublisher?: boolean;
14
14
  ikm?: string;
15
15
  blsPath?: string;
16
- blsOnly?: boolean;
17
16
  password?: string;
18
17
  outDir?: string;
19
18
  json?: boolean;
@@ -21,6 +20,10 @@ export type NewValidatorKeystoreOptions = {
21
20
  coinbase?: EthAddress;
22
21
  remoteSigner?: string;
23
22
  fundingAccount?: EthAddress;
23
+ stakerOutput?: boolean;
24
+ gseAddress?: EthAddress;
25
+ l1RpcUrls?: string[];
26
+ l1ChainId?: number;
24
27
  };
25
28
  export declare function newValidatorKeystore(options: NewValidatorKeystoreOptions, log: LogFn): Promise<void>;
26
29
  //# sourceMappingURL=new.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/new.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAgBhE,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,UAAU,CAAC;CAC7B,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,2BAA2B,EAAE,GAAG,EAAE,KAAK,iBAyF1F"}
1
+ {"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/new.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAmBhE,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,UAAU,CAAC;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,2BAA2B,EAAE,GAAG,EAAE,KAAK,iBA+J1F"}
@@ -1,9 +1,26 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/utils';
2
+ import { GSEContract, createEthereumChain } from '@aztec/ethereum';
1
3
  import { wordlist } from '@scure/bip39/wordlists/english.js';
2
- import { dirname } from 'path';
4
+ import { writeFile } from 'fs/promises';
5
+ import { basename, dirname, join } from 'path';
6
+ import { createPublicClient, fallback, http } from 'viem';
3
7
  import { generateMnemonic, mnemonicToAccount } from 'viem/accounts';
4
8
  import { buildValidatorEntries, logValidatorSummaries, maybePrintJson, resolveKeystoreOutputPath, writeBlsBn254ToFile, writeEthJsonV3ToFile, writeKeystoreFile } from './shared.js';
9
+ import { processAttesterAccounts } from './staker.js';
5
10
  export async function newValidatorKeystore(options, log) {
6
- const { dataDir, file, count, publisherCount = 0, json, coinbase, accountIndex = 0, addressIndex = 0, feeRecipient, remoteSigner, fundingAccount, blsOnly, blsPath, ikm, mnemonic: _mnemonic, password, outDir } = options;
11
+ const { dataDir, file, count, publisherCount = 0, json, coinbase, accountIndex = 0, addressIndex = 0, feeRecipient, remoteSigner, fundingAccount, blsPath, ikm, mnemonic: _mnemonic, password, outDir, stakerOutput, gseAddress, l1RpcUrls, l1ChainId } = options;
12
+ // Validate staker output requirements
13
+ if (stakerOutput) {
14
+ if (!gseAddress) {
15
+ throw new Error('--gse-address is required when using --staker-output');
16
+ }
17
+ if (!l1RpcUrls || l1RpcUrls.length === 0) {
18
+ throw new Error('--l1-rpc-urls is required when using --staker-output');
19
+ }
20
+ if (l1ChainId === undefined) {
21
+ throw new Error('--l1-chain-id is required when using --staker-output');
22
+ }
23
+ }
7
24
  if (remoteSigner && !_mnemonic) {
8
25
  throw new Error('Using --remote-signer requires a deterministic key source. Provide --mnemonic to derive keys, or omit --remote-signer to write new private keys to keystore.');
9
26
  }
@@ -25,7 +42,6 @@ export async function newValidatorKeystore(options, log) {
25
42
  mnemonic,
26
43
  ikm,
27
44
  blsPath,
28
- blsOnly,
29
45
  feeRecipient,
30
46
  coinbase,
31
47
  remoteSigner,
@@ -48,17 +64,59 @@ export async function newValidatorKeystore(options, log) {
48
64
  validators
49
65
  };
50
66
  await writeKeystoreFile(outputPath, keystore);
67
+ // Generate staker outputs if requested
68
+ const allStakerOutputs = [];
69
+ if (stakerOutput && gseAddress && l1RpcUrls && l1ChainId !== undefined) {
70
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
71
+ const publicClient = createPublicClient({
72
+ chain: chain.chainInfo,
73
+ transport: fallback(l1RpcUrls.map((url)=>http(url)))
74
+ });
75
+ const gse = new GSEContract(publicClient, gseAddress);
76
+ const keystoreOutDir = outDir && outDir.length > 0 ? outDir : dirname(outputPath);
77
+ // Extract keystore base name without extension for unique staker output filenames
78
+ const keystoreBaseName = basename(outputPath, '.json');
79
+ // Process each validator
80
+ for(let i = 0; i < validators.length; i++){
81
+ const validator = validators[i];
82
+ const outputs = await processAttesterAccounts(validator.attester, gse, password);
83
+ // Save each attester's staker output
84
+ for(let j = 0; j < outputs.length; j++){
85
+ const attesterIndex = i + 1;
86
+ const stakerOutputPath = join(keystoreOutDir, `${keystoreBaseName}_attester${attesterIndex}_staker_output.json`);
87
+ await writeFile(stakerOutputPath, prettyPrintJSON(outputs[j]), 'utf-8');
88
+ allStakerOutputs.push(outputs[j]);
89
+ }
90
+ }
91
+ }
51
92
  const outputData = !_mnemonic ? {
52
93
  ...keystore,
53
94
  generatedMnemonic: mnemonic
54
95
  } : keystore;
55
- maybePrintJson(log, json, outputData);
56
- if (!json) {
96
+ // Handle JSON output
97
+ if (json) {
98
+ if (stakerOutput && allStakerOutputs.length > 0) {
99
+ const combinedOutput = {
100
+ keystore: outputData,
101
+ staker: allStakerOutputs
102
+ };
103
+ maybePrintJson(log, json, combinedOutput);
104
+ } else {
105
+ maybePrintJson(log, json, outputData);
106
+ }
107
+ } else {
57
108
  log(`Wrote validator keystore to ${outputPath}`);
109
+ if (stakerOutput && allStakerOutputs.length > 0) {
110
+ const keystoreOutDir = outDir && outDir.length > 0 ? outDir : dirname(outputPath);
111
+ log(`Wrote ${allStakerOutputs.length} staker output file(s) to ${keystoreOutDir}`);
112
+ log('');
113
+ }
58
114
  }
59
- // Always print a concise summary of public keys (addresses and BLS pubkeys)
60
- logValidatorSummaries(log, summaries);
61
- if (!blsOnly && mnemonic && remoteSigner) {
115
+ // print a concise summary of public keys (addresses and BLS pubkeys) if no --json options was selected
116
+ if (!json) {
117
+ logValidatorSummaries(log, summaries);
118
+ }
119
+ if (mnemonic && remoteSigner && !json) {
62
120
  for(let i = 0; i < validatorCount; i++){
63
121
  const addrIdx = addressIndex + i;
64
122
  const acct = mnemonicToAccount(mnemonic, {
@@ -68,4 +126,9 @@ export async function newValidatorKeystore(options, log) {
68
126
  log(`attester address: ${acct.address} remoteSignerUrl: ${remoteSigner}`);
69
127
  }
70
128
  }
129
+ // Log staker outputs if not in JSON mode
130
+ if (!json && stakerOutput && allStakerOutputs.length > 0) {
131
+ log('\nStaker outputs:');
132
+ log(prettyPrintJSON(allStakerOutputs));
133
+ }
71
134
  }
@@ -15,7 +15,6 @@ export type BuildValidatorsInput = {
15
15
  mnemonic: string;
16
16
  ikm?: string;
17
17
  blsPath?: string;
18
- blsOnly?: boolean;
19
18
  feeRecipient: AztecAddress;
20
19
  coinbase?: EthAddress;
21
20
  remoteSigner?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAShE,MAAM,MAAM,gBAAgB,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEvG,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACr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rB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,CAAC,CASjB;AAED,yGAAyG;AACzG,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,iBAAiB,EAAE,EAC/B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED,8EAA8E;AAC9E,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED,kGAAkG;AAClG,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,iBAAiB,EAAE,EAC/B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,IAAI,CAAC,CA2Cf"}
@@ -33,7 +33,7 @@ export function deriveEthAttester(mnemonic, baseAccountIndex, addressIndex, remo
33
33
  } : '0x' + Buffer.from(acct.getHdKey().privateKey).toString('hex');
34
34
  }
35
35
  export async function buildValidatorEntries(input) {
36
- const { validatorCount, publisherCount = 0, accountIndex, baseAddressIndex, mnemonic, ikm, blsPath, blsOnly, feeRecipient, coinbase, remoteSigner, fundingAccount } = input;
36
+ const { validatorCount, publisherCount = 0, accountIndex, baseAddressIndex, mnemonic, ikm, blsPath, feeRecipient, coinbase, remoteSigner, fundingAccount } = input;
37
37
  const defaultBlsPath = 'm/12381/3600/0/0/0';
38
38
  const summaries = [];
39
39
  const validators = await Promise.all(Array.from({
@@ -42,20 +42,8 @@ export async function buildValidatorEntries(input) {
42
42
  const addressIndex = baseAddressIndex + i;
43
43
  const basePath = blsPath ?? defaultBlsPath;
44
44
  const perValidatorPath = withValidatorIndex(basePath, addressIndex);
45
- const blsPrivKey = blsOnly || ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
45
+ const blsPrivKey = ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
46
46
  const blsPubCompressed = blsPrivKey ? await computeBlsPublicKeyCompressed(blsPrivKey) : undefined;
47
- if (blsOnly) {
48
- const attester = {
49
- bls: blsPrivKey
50
- };
51
- summaries.push({
52
- attesterBls: blsPubCompressed
53
- });
54
- return {
55
- attester,
56
- feeRecipient
57
- };
58
- }
59
47
  const ethAttester = deriveEthAttester(mnemonic, accountIndex, addressIndex, remoteSigner);
60
48
  const attester = blsPrivKey ? {
61
49
  eth: ethAttester,
@@ -0,0 +1,38 @@
1
+ import { GSEContract } from '@aztec/ethereum';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { LogFn } from '@aztec/foundation/log';
4
+ import type { AttesterAccounts } from '@aztec/node-keystore/types';
5
+ export type StakerOptions = {
6
+ from: string;
7
+ password?: string;
8
+ output?: string;
9
+ gseAddress: EthAddress;
10
+ l1RpcUrls: string[];
11
+ l1ChainId: number;
12
+ };
13
+ export type StakerOutput = {
14
+ attester: string;
15
+ publicKeyG1: {
16
+ x: string;
17
+ y: string;
18
+ };
19
+ publicKeyG2: {
20
+ x0: string;
21
+ x1: string;
22
+ y0: string;
23
+ y1: string;
24
+ };
25
+ proofOfPossession: {
26
+ x: string;
27
+ y: string;
28
+ };
29
+ };
30
+ /**
31
+ * Process AttesterAccounts (which can be a single attester, array, or mnemonic)
32
+ */
33
+ export declare function processAttesterAccounts(attesterAccounts: AttesterAccounts, gse: GSEContract, password?: string): Promise<StakerOutput[]>;
34
+ /**
35
+ * Main staker command function
36
+ */
37
+ export declare function generateStakerJson(options: StakerOptions, log: LogFn): Promise<void>;
38
+ //# sourceMappingURL=staker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staker.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/staker.ts"],"names":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EthereumChain } from '@aztec/ethereum';
3
+ import { computeBn254G1PublicKey, computeBn254G2PublicKey } from '@aztec/foundation/crypto';
4
+ import { decryptBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
5
+ import { Fr } from '@aztec/foundation/fields';
6
+ import { loadKeystoreFile } from '@aztec/node-keystore/loader';
7
+ import { Wallet } from '@ethersproject/wallet';
8
+ import { readFileSync, writeFileSync } from 'fs';
9
+ import { createPublicClient, fallback, http } from 'viem';
10
+ import { privateKeyToAddress } from 'viem/accounts';
11
+ /**
12
+ * Check if an object is a MnemonicConfig
13
+ */ function isMnemonicConfig(obj) {
14
+ return typeof obj === 'object' && obj !== null && 'mnemonic' in obj;
15
+ }
16
+ /**
17
+ * Check if a value is an encrypted keystore file config
18
+ */ function isEncryptedKeyFileConfig(value) {
19
+ return typeof value === 'object' && value !== null && 'path' in value;
20
+ }
21
+ /**
22
+ * Check if a BLSAccount is a private key string (not an encrypted keystore file)
23
+ */ function isBlsPrivateKey(bls) {
24
+ return typeof bls === 'string' && bls.startsWith('0x');
25
+ }
26
+ /**
27
+ * Check if an EthAccount is a private key string (66 chars: 0x + 64 hex)
28
+ */ function isEthPrivateKey(eth) {
29
+ return typeof eth === 'string' && eth.startsWith('0x') && eth.length === 66;
30
+ }
31
+ /**
32
+ * Check if a string is an Ethereum address (42 chars: 0x + 40 hex)
33
+ */ function isEthAddress(value) {
34
+ return typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value);
35
+ }
36
+ /**
37
+ * Decrypt a BLS private key from an encrypted keystore file
38
+ */ function decryptBlsKey(bls, password) {
39
+ if (isBlsPrivateKey(bls)) {
40
+ return bls;
41
+ }
42
+ if (isEncryptedKeyFileConfig(bls)) {
43
+ if (!password && !bls.password) {
44
+ return undefined; // Can't decrypt without password
45
+ }
46
+ const pwd = password ?? bls.password;
47
+ return decryptBn254Keystore(bls.path, pwd);
48
+ }
49
+ return undefined;
50
+ }
51
+ /**
52
+ * Decrypt an Ethereum private key from an encrypted keystore file
53
+ */ async function decryptEthKey(eth, password) {
54
+ if (isEthPrivateKey(eth)) {
55
+ return eth;
56
+ }
57
+ if (isEncryptedKeyFileConfig(eth)) {
58
+ if (!password && !eth.password) {
59
+ return undefined; // Can't decrypt without password
60
+ }
61
+ const pwd = password ?? eth.password;
62
+ const json = readFileSync(eth.path, 'utf-8');
63
+ const wallet = await Wallet.fromEncryptedJson(json, pwd);
64
+ return wallet.privateKey;
65
+ }
66
+ return undefined;
67
+ }
68
+ /**
69
+ * Extract Ethereum address from an EthAccount (or private key)
70
+ */ async function getEthAddress(eth, password) {
71
+ // Case 1: It's a private key string - derive the address
72
+ if (isEthPrivateKey(eth)) {
73
+ return privateKeyToAddress(eth);
74
+ }
75
+ // Case 2: It's just an address string directly (EthRemoteSignerAccount can be just EthAddress)
76
+ if (isEthAddress(eth)) {
77
+ return eth;
78
+ }
79
+ // Case 3: It's an object with an address property (remote signer config)
80
+ if (typeof eth === 'object' && eth !== null && 'address' in eth) {
81
+ return eth.address;
82
+ }
83
+ // Case 4: It's an encrypted keystore file - decrypt and derive address
84
+ if (isEncryptedKeyFileConfig(eth)) {
85
+ const privateKey = await decryptEthKey(eth, password);
86
+ if (privateKey) {
87
+ return privateKeyToAddress(privateKey);
88
+ }
89
+ return undefined;
90
+ }
91
+ return undefined;
92
+ }
93
+ /**
94
+ * Extract BLS private key and Ethereum address from an AttesterAccount
95
+ */ async function extractAttesterInfo(attester, password) {
96
+ // Case 1: attester is { eth: EthAccount, bls?: BLSAccount }
97
+ if (typeof attester === 'object' && attester !== null && 'eth' in attester) {
98
+ const ethAddress = await getEthAddress(attester.eth, password);
99
+ const blsPrivateKey = attester.bls ? decryptBlsKey(attester.bls, password) : undefined;
100
+ return {
101
+ blsPrivateKey,
102
+ ethAddress
103
+ };
104
+ }
105
+ // Case 2: attester is just an EthAccount directly (no BLS key)
106
+ return {
107
+ blsPrivateKey: undefined,
108
+ ethAddress: await getEthAddress(attester, password)
109
+ };
110
+ }
111
+ /**
112
+ * Process a single attester entry and output staking JSON
113
+ */ async function processAttester(attester, gse, password) {
114
+ const { blsPrivateKey, ethAddress } = await extractAttesterInfo(attester, password);
115
+ // Skip if no BLS private key or no Ethereum address
116
+ if (!blsPrivateKey || !ethAddress) {
117
+ return undefined;
118
+ }
119
+ // Derive G1 and G2 public keys
120
+ const g1PublicKey = await computeBn254G1PublicKey(blsPrivateKey);
121
+ const g2PublicKey = await computeBn254G2PublicKey(blsPrivateKey);
122
+ // Generate proof of possession
123
+ const bn254SecretKeyFieldElement = Fr.fromString(blsPrivateKey);
124
+ const registrationTuple = await gse.makeRegistrationTuple(bn254SecretKeyFieldElement.toBigInt());
125
+ return {
126
+ attester: String(ethAddress),
127
+ publicKeyG1: {
128
+ x: '0x' + g1PublicKey.x.toString(16).padStart(64, '0'),
129
+ y: '0x' + g1PublicKey.y.toString(16).padStart(64, '0')
130
+ },
131
+ publicKeyG2: {
132
+ x0: '0x' + g2PublicKey.x.c0.toString(16).padStart(64, '0'),
133
+ x1: '0x' + g2PublicKey.x.c1.toString(16).padStart(64, '0'),
134
+ y0: '0x' + g2PublicKey.y.c0.toString(16).padStart(64, '0'),
135
+ y1: '0x' + g2PublicKey.y.c1.toString(16).padStart(64, '0')
136
+ },
137
+ proofOfPossession: {
138
+ x: '0x' + registrationTuple.proofOfPossession.x.toString(16),
139
+ y: '0x' + registrationTuple.proofOfPossession.y.toString(16)
140
+ }
141
+ };
142
+ }
143
+ /**
144
+ * Process AttesterAccounts (which can be a single attester, array, or mnemonic)
145
+ */ export async function processAttesterAccounts(attesterAccounts, gse, password) {
146
+ // Skip mnemonic configs
147
+ if (isMnemonicConfig(attesterAccounts)) {
148
+ return [];
149
+ }
150
+ // Handle array of attesters
151
+ if (Array.isArray(attesterAccounts)) {
152
+ const results = [];
153
+ for (const attester of attesterAccounts){
154
+ const result = await processAttester(attester, gse, password);
155
+ if (result) {
156
+ results.push(result);
157
+ }
158
+ }
159
+ return results;
160
+ }
161
+ // Handle single attester
162
+ const result = await processAttester(attesterAccounts, gse, password);
163
+ return result ? [
164
+ result
165
+ ] : [];
166
+ }
167
+ /**
168
+ * Main staker command function
169
+ */ export async function generateStakerJson(options, log) {
170
+ const { from, password, gseAddress, l1RpcUrls, l1ChainId, output } = options;
171
+ // Load the keystore file
172
+ const keystore = loadKeystoreFile(from);
173
+ if (!gseAddress) {
174
+ throw new Error('GSE contract address is required');
175
+ }
176
+ log(`Calling GSE contract ${gseAddress} on chain ${l1ChainId}, using ${l1RpcUrls.join(', ')} to get staker outputs`);
177
+ if (!keystore.validators || keystore.validators.length === 0) {
178
+ log('No validators found in keystore');
179
+ return;
180
+ }
181
+ const allOutputs = [];
182
+ // L1 client for proof of possession
183
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
184
+ const publicClient = createPublicClient({
185
+ chain: chain.chainInfo,
186
+ transport: fallback(l1RpcUrls.map((url)=>http(url)))
187
+ });
188
+ const gse = new GSEContract(publicClient, gseAddress);
189
+ // Process each validator
190
+ for (const validator of keystore.validators){
191
+ const outputs = await processAttesterAccounts(validator.attester, gse, password);
192
+ allOutputs.push(...outputs);
193
+ }
194
+ if (allOutputs.length === 0) {
195
+ log('No attesters with BLS keys found (skipping mnemonics and encrypted keystores without password)');
196
+ return;
197
+ }
198
+ const jsonOutput = prettyPrintJSON(allOutputs);
199
+ // Write to file if output is specified, otherwise log to stdout
200
+ if (output) {
201
+ writeFileSync(output, jsonOutput, 'utf-8');
202
+ log(`Wrote staking data to ${output}`);
203
+ } else {
204
+ log(jsonOutput);
205
+ }
206
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/cli",
3
- "version": "2.1.2-rc.3",
3
+ "version": "2.1.2-rc.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./contracts": "./dest/cmds/contracts/index.js",
@@ -71,18 +71,18 @@
71
71
  ]
72
72
  },
73
73
  "dependencies": {
74
- "@aztec/archiver": "2.1.2-rc.3",
75
- "@aztec/aztec.js": "2.1.2-rc.3",
76
- "@aztec/constants": "2.1.2-rc.3",
77
- "@aztec/entrypoints": "2.1.2-rc.3",
78
- "@aztec/ethereum": "2.1.2-rc.3",
79
- "@aztec/foundation": "2.1.2-rc.3",
80
- "@aztec/l1-artifacts": "2.1.2-rc.3",
81
- "@aztec/node-keystore": "2.1.2-rc.3",
82
- "@aztec/node-lib": "2.1.2-rc.3",
83
- "@aztec/p2p": "2.1.2-rc.3",
84
- "@aztec/stdlib": "2.1.2-rc.3",
85
- "@aztec/world-state": "2.1.2-rc.3",
74
+ "@aztec/archiver": "2.1.2-rc.5",
75
+ "@aztec/aztec.js": "2.1.2-rc.5",
76
+ "@aztec/constants": "2.1.2-rc.5",
77
+ "@aztec/entrypoints": "2.1.2-rc.5",
78
+ "@aztec/ethereum": "2.1.2-rc.5",
79
+ "@aztec/foundation": "2.1.2-rc.5",
80
+ "@aztec/l1-artifacts": "2.1.2-rc.5",
81
+ "@aztec/node-keystore": "2.1.2-rc.5",
82
+ "@aztec/node-lib": "2.1.2-rc.5",
83
+ "@aztec/p2p": "2.1.2-rc.5",
84
+ "@aztec/stdlib": "2.1.2-rc.5",
85
+ "@aztec/world-state": "2.1.2-rc.5",
86
86
  "@ethersproject/wallet": "^5.8.0",
87
87
  "@iarna/toml": "^2.2.5",
88
88
  "@libp2p/peer-id-factory": "^3.0.4",
@@ -96,8 +96,8 @@
96
96
  "viem": "npm:@spalladino/viem@2.38.2-eip7594.0"
97
97
  },
98
98
  "devDependencies": {
99
- "@aztec/accounts": "2.1.2-rc.3",
100
- "@aztec/protocol-contracts": "2.1.2-rc.3",
99
+ "@aztec/accounts": "2.1.2-rc.5",
100
+ "@aztec/protocol-contracts": "2.1.2-rc.5",
101
101
  "@jest/globals": "^30.0.0",
102
102
  "@types/jest": "^30.0.0",
103
103
  "@types/lodash.chunk": "^4.2.9",
@@ -113,15 +113,15 @@
113
113
  "typescript": "^5.3.3"
114
114
  },
115
115
  "peerDependencies": {
116
- "@aztec/accounts": "2.1.2-rc.3",
117
- "@aztec/bb-prover": "2.1.2-rc.3",
118
- "@aztec/ethereum": "2.1.2-rc.3",
119
- "@aztec/l1-artifacts": "2.1.2-rc.3",
120
- "@aztec/noir-contracts.js": "2.1.2-rc.3",
121
- "@aztec/noir-protocol-circuits-types": "2.1.2-rc.3",
122
- "@aztec/noir-test-contracts.js": "2.1.2-rc.3",
123
- "@aztec/protocol-contracts": "2.1.2-rc.3",
124
- "@aztec/stdlib": "2.1.2-rc.3"
116
+ "@aztec/accounts": "2.1.2-rc.5",
117
+ "@aztec/bb-prover": "2.1.2-rc.5",
118
+ "@aztec/ethereum": "2.1.2-rc.5",
119
+ "@aztec/l1-artifacts": "2.1.2-rc.5",
120
+ "@aztec/noir-contracts.js": "2.1.2-rc.5",
121
+ "@aztec/noir-protocol-circuits-types": "2.1.2-rc.5",
122
+ "@aztec/noir-test-contracts.js": "2.1.2-rc.5",
123
+ "@aztec/protocol-contracts": "2.1.2-rc.5",
124
+ "@aztec/stdlib": "2.1.2-rc.5"
125
125
  },
126
126
  "files": [
127
127
  "dest",
@@ -30,7 +30,6 @@ export async function addValidatorKeys(existing: string, options: AddValidatorKe
30
30
  addressIndex,
31
31
  ikm,
32
32
  blsPath,
33
- blsOnly,
34
33
  json,
35
34
  feeRecipient: feeRecipientOpt,
36
35
  coinbase: coinbaseOpt,
@@ -75,7 +74,6 @@ export async function addValidatorKeys(existing: string, options: AddValidatorKe
75
74
  mnemonic: mnemonicToUse,
76
75
  ikm,
77
76
  blsPath,
78
- blsOnly,
79
77
  feeRecipient,
80
78
  coinbase,
81
79
  remoteSigner,
@@ -7,7 +7,7 @@ import { parseAztecAddress, parseEthereumAddress, parseHex, parseOptionalInteger
7
7
  export function injectCommands(program: Command, log: LogFn) {
8
8
  const group = program
9
9
  .command('validator-keys')
10
- .aliases(['valKeys'])
10
+ .aliases(['valKeys', 'valkeys'])
11
11
  .description('Manage validator keystores for node operators');
12
12
 
13
13
  group
@@ -29,13 +29,23 @@ export function injectCommands(program: Command, log: LogFn) {
29
29
  .option('--remote-signer <url>', 'Default remote signer URL for accounts in this file')
30
30
  .option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', value => parseHex(value, 32))
31
31
  .option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)')
32
- .option('--bls-only', 'Generate only BLS keys')
33
32
  .option(
34
33
  '--password <str>',
35
34
  'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed',
36
35
  )
37
36
  .option('--out-dir <dir>', 'Output directory for generated keystore file(s)')
38
37
  .option('--json', 'Echo resulting JSON to stdout')
38
+ .option('--staker-output', 'Generate staker output JSON files for each attester')
39
+ .option('--gse-address <address>', 'GSE contract address (required with --staker-output)', parseEthereumAddress)
40
+ .option('--l1-rpc-urls <urls>', 'L1 RPC URLs (comma-separated, required with --staker-output)', value =>
41
+ value.split(','),
42
+ )
43
+ .option(
44
+ '-c, --l1-chain-id <number>',
45
+ 'L1 chain ID (required with --staker-output)',
46
+ value => parseInt(value),
47
+ 31337,
48
+ )
39
49
  .requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress)
40
50
  .action(async options => {
41
51
  const { newValidatorKeystore } = await import('./new.js');
@@ -62,7 +72,6 @@ export function injectCommands(program: Command, log: LogFn) {
62
72
  .option('--remote-signer <url>', 'Default remote signer URL for accounts in this file')
63
73
  .option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', value => parseHex(value, 32))
64
74
  .option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)')
65
- .option('--bls-only', 'Generate only BLS keys')
66
75
  .option('--empty', 'Generate an empty skeleton without keys')
67
76
  .option(
68
77
  '--password <str>',
@@ -76,6 +85,25 @@ export function injectCommands(program: Command, log: LogFn) {
76
85
  await addValidatorKeys(existing, options, log);
77
86
  });
78
87
 
88
+ group
89
+ .command('staker')
90
+ .summary('Generate staking JSON from keystore')
91
+ .description(
92
+ 'Reads a validator keystore and outputs staking data with BLS public keys for each attester (skips mnemonics)',
93
+ )
94
+ .requiredOption('--from <keystore>', 'Path to keystore JSON file')
95
+ .option('--password <password>', 'Password for decrypting encrypted keystores (if not specified in keystore file)')
96
+ .requiredOption('--gse-address <address>', 'GSE contract address', parseEthereumAddress)
97
+ .option('--l1-rpc-urls <urls>', 'L1 RPC URLs (comma-separated)', value => value.split(','), [
98
+ 'http://localhost:8545',
99
+ ])
100
+ .option('-c, --l1-chain-id <number>', 'L1 chain ID', value => parseInt(value), 31337)
101
+ .option('--output <file>', 'Output file path (if not specified, JSON is written to stdout)')
102
+ .action(async options => {
103
+ const { generateStakerJson } = await import('./staker.js');
104
+ await generateStakerJson(options, log);
105
+ });
106
+
79
107
  // top-level convenience: aztec generate-bls-keypair
80
108
  program
81
109
  .command('generate-bls-keypair')
@@ -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,6 +19,7 @@ import {
15
19
  writeEthJsonV3ToFile,
16
20
  writeKeystoreFile,
17
21
  } from './shared.js';
22
+ import { processAttesterAccounts } from './staker.js';
18
23
 
19
24
  export type NewValidatorKeystoreOptions = {
20
25
  dataDir?: string;
@@ -28,7 +33,6 @@ export type NewValidatorKeystoreOptions = {
28
33
  separatePublisher?: boolean;
29
34
  ikm?: string;
30
35
  blsPath?: string;
31
- blsOnly?: boolean;
32
36
  password?: string;
33
37
  outDir?: string;
34
38
  json?: boolean;
@@ -36,6 +40,10 @@ export type NewValidatorKeystoreOptions = {
36
40
  coinbase?: EthAddress;
37
41
  remoteSigner?: string;
38
42
  fundingAccount?: EthAddress;
43
+ stakerOutput?: boolean;
44
+ gseAddress?: EthAddress;
45
+ l1RpcUrls?: string[];
46
+ l1ChainId?: number;
39
47
  };
40
48
 
41
49
  export async function newValidatorKeystore(options: NewValidatorKeystoreOptions, log: LogFn) {
@@ -51,14 +59,30 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
51
59
  feeRecipient,
52
60
  remoteSigner,
53
61
  fundingAccount,
54
- blsOnly,
55
62
  blsPath,
56
63
  ikm,
57
64
  mnemonic: _mnemonic,
58
65
  password,
59
66
  outDir,
67
+ stakerOutput,
68
+ gseAddress,
69
+ l1RpcUrls,
70
+ l1ChainId,
60
71
  } = options;
61
72
 
73
+ // Validate staker output requirements
74
+ if (stakerOutput) {
75
+ if (!gseAddress) {
76
+ throw new Error('--gse-address is required when using --staker-output');
77
+ }
78
+ if (!l1RpcUrls || l1RpcUrls.length === 0) {
79
+ throw new Error('--l1-rpc-urls is required when using --staker-output');
80
+ }
81
+ if (l1ChainId === undefined) {
82
+ throw new Error('--l1-chain-id is required when using --staker-output');
83
+ }
84
+ }
85
+
62
86
  if (remoteSigner && !_mnemonic) {
63
87
  throw new Error(
64
88
  'Using --remote-signer requires a deterministic key source. Provide --mnemonic to derive keys, or omit --remote-signer to write new private keys to keystore.',
@@ -86,7 +110,6 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
86
110
  mnemonic,
87
111
  ikm,
88
112
  blsPath,
89
- blsOnly,
90
113
  feeRecipient,
91
114
  coinbase,
92
115
  remoteSigner,
@@ -107,17 +130,66 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
107
130
 
108
131
  await writeKeystoreFile(outputPath, keystore);
109
132
 
133
+ // Generate staker outputs if requested
134
+ const allStakerOutputs: any[] = [];
135
+ if (stakerOutput && gseAddress && l1RpcUrls && l1ChainId !== undefined) {
136
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
137
+ const publicClient = createPublicClient({
138
+ chain: chain.chainInfo,
139
+ transport: fallback(l1RpcUrls.map(url => http(url))),
140
+ });
141
+ const gse = new GSEContract(publicClient, gseAddress);
142
+
143
+ const keystoreOutDir = outDir && outDir.length > 0 ? outDir : dirname(outputPath);
144
+ // Extract keystore base name without extension for unique staker output filenames
145
+ const keystoreBaseName = basename(outputPath, '.json');
146
+
147
+ // Process each validator
148
+ for (let i = 0; i < validators.length; i++) {
149
+ const validator = validators[i];
150
+ const outputs = await processAttesterAccounts(validator.attester, gse, password);
151
+
152
+ // Save each attester's staker output
153
+ for (let j = 0; j < outputs.length; j++) {
154
+ const attesterIndex = i + 1;
155
+ const stakerOutputPath = join(
156
+ keystoreOutDir,
157
+ `${keystoreBaseName}_attester${attesterIndex}_staker_output.json`,
158
+ );
159
+ await writeFile(stakerOutputPath, prettyPrintJSON(outputs[j]), 'utf-8');
160
+ allStakerOutputs.push(outputs[j]);
161
+ }
162
+ }
163
+ }
164
+
110
165
  const outputData = !_mnemonic ? { ...keystore, generatedMnemonic: mnemonic } : keystore;
111
166
 
112
- maybePrintJson(log, json, outputData as unknown as Record<string, any>);
113
- if (!json) {
167
+ // Handle JSON output
168
+ if (json) {
169
+ if (stakerOutput && allStakerOutputs.length > 0) {
170
+ const combinedOutput = {
171
+ keystore: outputData,
172
+ staker: allStakerOutputs,
173
+ };
174
+ maybePrintJson(log, json, combinedOutput as unknown as Record<string, any>);
175
+ } else {
176
+ maybePrintJson(log, json, outputData as unknown as Record<string, any>);
177
+ }
178
+ } else {
114
179
  log(`Wrote validator keystore to ${outputPath}`);
180
+ if (stakerOutput && allStakerOutputs.length > 0) {
181
+ const keystoreOutDir = outDir && outDir.length > 0 ? outDir : dirname(outputPath);
182
+ log(`Wrote ${allStakerOutputs.length} staker output file(s) to ${keystoreOutDir}`);
183
+ log('');
184
+ }
115
185
  }
116
186
 
117
- // Always print a concise summary of public keys (addresses and BLS pubkeys)
118
- logValidatorSummaries(log, summaries);
187
+ // print a concise summary of public keys (addresses and BLS pubkeys) if no --json options was selected
188
+ if (!json) {
189
+ logValidatorSummaries(log, summaries);
190
+ }
119
191
 
120
- if (!blsOnly && mnemonic && remoteSigner) {
192
+ if (mnemonic && remoteSigner && !json) {
121
193
  for (let i = 0; i < validatorCount; i++) {
122
194
  const addrIdx = addressIndex + i;
123
195
  const acct = mnemonicToAccount(mnemonic, {
@@ -127,4 +199,10 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
127
199
  log(`attester address: ${acct.address} remoteSignerUrl: ${remoteSigner}`);
128
200
  }
129
201
  }
202
+
203
+ // Log staker outputs if not in JSON mode
204
+ if (!json && stakerOutput && allStakerOutputs.length > 0) {
205
+ log('\nStaker outputs:');
206
+ log(prettyPrintJSON(allStakerOutputs));
207
+ }
130
208
  }
@@ -23,7 +23,6 @@ export type BuildValidatorsInput = {
23
23
  mnemonic: string;
24
24
  ikm?: string;
25
25
  blsPath?: string;
26
- blsOnly?: boolean;
27
26
  feeRecipient: AztecAddress;
28
27
  coinbase?: EthAddress;
29
28
  remoteSigner?: string;
@@ -69,7 +68,6 @@ export async function buildValidatorEntries(input: BuildValidatorsInput) {
69
68
  mnemonic,
70
69
  ikm,
71
70
  blsPath,
72
- blsOnly,
73
71
  feeRecipient,
74
72
  coinbase,
75
73
  remoteSigner,
@@ -85,15 +83,9 @@ export async function buildValidatorEntries(input: BuildValidatorsInput) {
85
83
  const basePath = blsPath ?? defaultBlsPath;
86
84
  const perValidatorPath = withValidatorIndex(basePath, addressIndex);
87
85
 
88
- const blsPrivKey = blsOnly || ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
86
+ const blsPrivKey = ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
89
87
  const blsPubCompressed = blsPrivKey ? await computeBlsPublicKeyCompressed(blsPrivKey) : undefined;
90
88
 
91
- if (blsOnly) {
92
- const attester = { bls: blsPrivKey! };
93
- summaries.push({ attesterBls: blsPubCompressed });
94
- return { attester, feeRecipient } as ValidatorKeyStore;
95
- }
96
-
97
89
  const ethAttester = deriveEthAttester(mnemonic, accountIndex, addressIndex, remoteSigner);
98
90
  const attester = blsPrivKey ? { eth: ethAttester, bls: blsPrivKey } : ethAttester;
99
91
 
@@ -0,0 +1,298 @@
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 { createPublicClient, fallback, http } from 'viem';
21
+ import { privateKeyToAddress } from 'viem/accounts';
22
+
23
+ export type StakerOptions = {
24
+ from: string;
25
+ password?: string;
26
+ output?: string;
27
+ gseAddress: EthAddress;
28
+ l1RpcUrls: string[];
29
+ l1ChainId: number;
30
+ };
31
+
32
+ export type StakerOutput = {
33
+ attester: string;
34
+ publicKeyG1: {
35
+ x: string;
36
+ y: string;
37
+ };
38
+ publicKeyG2: {
39
+ x0: string;
40
+ x1: string;
41
+ y0: string;
42
+ y1: string;
43
+ };
44
+ proofOfPossession: {
45
+ x: string;
46
+ y: string;
47
+ };
48
+ };
49
+
50
+ /**
51
+ * Check if an object is a MnemonicConfig
52
+ */
53
+ function isMnemonicConfig(obj: unknown): obj is MnemonicConfig {
54
+ return typeof obj === 'object' && obj !== null && 'mnemonic' in obj;
55
+ }
56
+
57
+ /**
58
+ * Check if a value is an encrypted keystore file config
59
+ */
60
+ function isEncryptedKeyFileConfig(value: unknown): value is EncryptedKeyFileConfig {
61
+ return typeof value === 'object' && value !== null && 'path' in value;
62
+ }
63
+
64
+ /**
65
+ * Check if a BLSAccount is a private key string (not an encrypted keystore file)
66
+ */
67
+ function isBlsPrivateKey(bls: unknown): bls is string {
68
+ return typeof bls === 'string' && bls.startsWith('0x');
69
+ }
70
+
71
+ /**
72
+ * Check if an EthAccount is a private key string (66 chars: 0x + 64 hex)
73
+ */
74
+ function isEthPrivateKey(eth: unknown): eth is string {
75
+ return typeof eth === 'string' && eth.startsWith('0x') && eth.length === 66;
76
+ }
77
+
78
+ /**
79
+ * Check if a string is an Ethereum address (42 chars: 0x + 40 hex)
80
+ */
81
+ function isEthAddress(value: unknown): value is string {
82
+ return typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value);
83
+ }
84
+
85
+ /**
86
+ * Decrypt a BLS private key from an encrypted keystore file
87
+ */
88
+ function decryptBlsKey(bls: BLSAccount, password?: string): string | undefined {
89
+ if (isBlsPrivateKey(bls)) {
90
+ return bls;
91
+ }
92
+
93
+ if (isEncryptedKeyFileConfig(bls)) {
94
+ if (!password && !bls.password) {
95
+ return undefined; // Can't decrypt without password
96
+ }
97
+ const pwd = password ?? bls.password!;
98
+ return decryptBn254Keystore(bls.path, pwd);
99
+ }
100
+
101
+ return undefined;
102
+ }
103
+
104
+ /**
105
+ * Decrypt an Ethereum private key from an encrypted keystore file
106
+ */
107
+ async function decryptEthKey(eth: EthAccount, password?: string): Promise<string | undefined> {
108
+ if (isEthPrivateKey(eth)) {
109
+ return eth;
110
+ }
111
+
112
+ if (isEncryptedKeyFileConfig(eth)) {
113
+ if (!password && !eth.password) {
114
+ return undefined; // Can't decrypt without password
115
+ }
116
+ const pwd = password ?? eth.password!;
117
+ const json = readFileSync(eth.path, 'utf-8');
118
+ const wallet = await Wallet.fromEncryptedJson(json, pwd);
119
+ return wallet.privateKey as string;
120
+ }
121
+
122
+ return undefined;
123
+ }
124
+
125
+ /**
126
+ * Extract Ethereum address from an EthAccount (or private key)
127
+ */
128
+ async function getEthAddress(eth: EthAccount | string, password?: string): Promise<EthAddress | undefined> {
129
+ // Case 1: It's a private key string - derive the address
130
+ if (isEthPrivateKey(eth)) {
131
+ return privateKeyToAddress(eth as `0x${string}`) as unknown as EthAddress;
132
+ }
133
+
134
+ // Case 2: It's just an address string directly (EthRemoteSignerAccount can be just EthAddress)
135
+ if (isEthAddress(eth)) {
136
+ return eth as unknown as EthAddress;
137
+ }
138
+
139
+ // Case 3: It's an object with an address property (remote signer config)
140
+ if (typeof eth === 'object' && eth !== null && 'address' in eth) {
141
+ return (eth as any).address as EthAddress;
142
+ }
143
+
144
+ // Case 4: It's an encrypted keystore file - decrypt and derive address
145
+ if (isEncryptedKeyFileConfig(eth)) {
146
+ const privateKey = await decryptEthKey(eth, password);
147
+ if (privateKey) {
148
+ return privateKeyToAddress(privateKey as `0x${string}`) as unknown as EthAddress;
149
+ }
150
+ return undefined;
151
+ }
152
+
153
+ return undefined;
154
+ }
155
+
156
+ /**
157
+ * Extract BLS private key and Ethereum address from an AttesterAccount
158
+ */
159
+ async function extractAttesterInfo(
160
+ attester: AttesterAccount,
161
+ password?: string,
162
+ ): Promise<{ blsPrivateKey?: string; ethAddress?: EthAddress }> {
163
+ // Case 1: attester is { eth: EthAccount, bls?: BLSAccount }
164
+ if (typeof attester === 'object' && attester !== null && 'eth' in attester) {
165
+ const ethAddress = await getEthAddress(attester.eth, password);
166
+ const blsPrivateKey = attester.bls ? decryptBlsKey(attester.bls, password) : undefined;
167
+ return { blsPrivateKey, ethAddress };
168
+ }
169
+
170
+ // Case 2: attester is just an EthAccount directly (no BLS key)
171
+ return {
172
+ blsPrivateKey: undefined,
173
+ ethAddress: await getEthAddress(attester as EthAccount, password),
174
+ };
175
+ }
176
+
177
+ /**
178
+ * Process a single attester entry and output staking JSON
179
+ */
180
+ async function processAttester(
181
+ attester: AttesterAccount,
182
+ gse: GSEContract,
183
+ password?: string,
184
+ ): Promise<StakerOutput | undefined> {
185
+ const { blsPrivateKey, ethAddress } = await extractAttesterInfo(attester, password);
186
+
187
+ // Skip if no BLS private key or no Ethereum address
188
+ if (!blsPrivateKey || !ethAddress) {
189
+ return undefined;
190
+ }
191
+
192
+ // Derive G1 and G2 public keys
193
+ const g1PublicKey = await computeBn254G1PublicKey(blsPrivateKey);
194
+ const g2PublicKey = await computeBn254G2PublicKey(blsPrivateKey);
195
+
196
+ // Generate proof of possession
197
+ const bn254SecretKeyFieldElement = Fr.fromString(blsPrivateKey);
198
+ const registrationTuple = await gse.makeRegistrationTuple(bn254SecretKeyFieldElement.toBigInt());
199
+
200
+ return {
201
+ attester: String(ethAddress),
202
+ publicKeyG1: {
203
+ x: '0x' + g1PublicKey.x.toString(16).padStart(64, '0'),
204
+ y: '0x' + g1PublicKey.y.toString(16).padStart(64, '0'),
205
+ },
206
+ publicKeyG2: {
207
+ x0: '0x' + g2PublicKey.x.c0.toString(16).padStart(64, '0'),
208
+ x1: '0x' + g2PublicKey.x.c1.toString(16).padStart(64, '0'),
209
+ y0: '0x' + g2PublicKey.y.c0.toString(16).padStart(64, '0'),
210
+ y1: '0x' + g2PublicKey.y.c1.toString(16).padStart(64, '0'),
211
+ },
212
+ proofOfPossession: {
213
+ x: '0x' + registrationTuple.proofOfPossession.x.toString(16),
214
+ y: '0x' + registrationTuple.proofOfPossession.y.toString(16),
215
+ },
216
+ };
217
+ }
218
+
219
+ /**
220
+ * Process AttesterAccounts (which can be a single attester, array, or mnemonic)
221
+ */
222
+ export async function processAttesterAccounts(
223
+ attesterAccounts: AttesterAccounts,
224
+ gse: GSEContract,
225
+ password?: string,
226
+ ): Promise<StakerOutput[]> {
227
+ // Skip mnemonic configs
228
+ if (isMnemonicConfig(attesterAccounts)) {
229
+ return [];
230
+ }
231
+
232
+ // Handle array of attesters
233
+ if (Array.isArray(attesterAccounts)) {
234
+ const results: StakerOutput[] = [];
235
+ for (const attester of attesterAccounts) {
236
+ const result = await processAttester(attester, gse, password);
237
+ if (result) {
238
+ results.push(result);
239
+ }
240
+ }
241
+ return results;
242
+ }
243
+
244
+ // Handle single attester
245
+ const result = await processAttester(attesterAccounts, gse, password);
246
+ return result ? [result] : [];
247
+ }
248
+
249
+ /**
250
+ * Main staker command function
251
+ */
252
+ export async function generateStakerJson(options: StakerOptions, log: LogFn): Promise<void> {
253
+ const { from, password, gseAddress, l1RpcUrls, l1ChainId, output } = options;
254
+
255
+ // Load the keystore file
256
+ const keystore = loadKeystoreFile(from);
257
+
258
+ if (!gseAddress) {
259
+ throw new Error('GSE contract address is required');
260
+ }
261
+ log(`Calling GSE contract ${gseAddress} on chain ${l1ChainId}, using ${l1RpcUrls.join(', ')} to get staker outputs`);
262
+
263
+ if (!keystore.validators || keystore.validators.length === 0) {
264
+ log('No validators found in keystore');
265
+ return;
266
+ }
267
+
268
+ const allOutputs: StakerOutput[] = [];
269
+
270
+ // L1 client for proof of possession
271
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
272
+ const publicClient = createPublicClient({
273
+ chain: chain.chainInfo,
274
+ transport: fallback(l1RpcUrls.map(url => http(url))),
275
+ });
276
+ const gse = new GSEContract(publicClient, gseAddress);
277
+
278
+ // Process each validator
279
+ for (const validator of keystore.validators) {
280
+ const outputs = await processAttesterAccounts(validator.attester, gse, password);
281
+ allOutputs.push(...outputs);
282
+ }
283
+
284
+ if (allOutputs.length === 0) {
285
+ log('No attesters with BLS keys found (skipping mnemonics and encrypted keystores without password)');
286
+ return;
287
+ }
288
+
289
+ const jsonOutput = prettyPrintJSON(allOutputs);
290
+
291
+ // Write to file if output is specified, otherwise log to stdout
292
+ if (output) {
293
+ writeFileSync(output, jsonOutput, 'utf-8');
294
+ log(`Wrote staking data to ${output}`);
295
+ } else {
296
+ log(jsonOutput);
297
+ }
298
+ }