@aztec/cli 3.0.0-nightly.20251110 → 3.0.0-nightly.20251112
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.
- package/README.md +1 -1
- package/dest/cmds/misc/update/npm.js +1 -1
- package/dest/cmds/validator_keys/add.d.ts.map +1 -1
- package/dest/cmds/validator_keys/add.js +1 -2
- package/dest/cmds/validator_keys/index.d.ts.map +1 -1
- package/dest/cmds/validator_keys/index.js +10 -3
- package/dest/cmds/validator_keys/new.d.ts +4 -1
- package/dest/cmds/validator_keys/new.d.ts.map +1 -1
- package/dest/cmds/validator_keys/new.js +82 -8
- package/dest/cmds/validator_keys/shared.d.ts +0 -1
- package/dest/cmds/validator_keys/shared.d.ts.map +1 -1
- package/dest/cmds/validator_keys/shared.js +2 -14
- package/dest/cmds/validator_keys/staker.d.ts +38 -0
- package/dest/cmds/validator_keys/staker.d.ts.map +1 -0
- package/dest/cmds/validator_keys/staker.js +206 -0
- package/dest/config/chain_l2_config.d.ts +1 -0
- package/dest/config/chain_l2_config.d.ts.map +1 -1
- package/dest/config/chain_l2_config.js +11 -3
- package/package.json +25 -25
- package/src/cmds/misc/update/npm.ts +1 -1
- package/src/cmds/validator_keys/add.ts +0 -2
- package/src/cmds/validator_keys/index.ts +31 -3
- package/src/cmds/validator_keys/new.ts +97 -9
- package/src/cmds/validator_keys/shared.ts +1 -9
- package/src/cmds/validator_keys/staker.ts +298 -0
- package/src/config/chain_l2_config.ts +14 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/cli",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20251112",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./contracts": "./dest/cmds/contracts/index.js",
|
|
@@ -71,21 +71,21 @@
|
|
|
71
71
|
]
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@aztec/accounts": "3.0.0-nightly.
|
|
75
|
-
"@aztec/archiver": "3.0.0-nightly.
|
|
76
|
-
"@aztec/aztec.js": "3.0.0-nightly.
|
|
77
|
-
"@aztec/constants": "3.0.0-nightly.
|
|
78
|
-
"@aztec/entrypoints": "3.0.0-nightly.
|
|
79
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
80
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
81
|
-
"@aztec/l1-artifacts": "3.0.0-nightly.
|
|
82
|
-
"@aztec/node-keystore": "3.0.0-nightly.
|
|
83
|
-
"@aztec/node-lib": "3.0.0-nightly.
|
|
84
|
-
"@aztec/p2p": "3.0.0-nightly.
|
|
85
|
-
"@aztec/protocol-contracts": "3.0.0-nightly.
|
|
86
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
87
|
-
"@aztec/test-wallet": "3.0.0-nightly.
|
|
88
|
-
"@aztec/world-state": "3.0.0-nightly.
|
|
74
|
+
"@aztec/accounts": "3.0.0-nightly.20251112",
|
|
75
|
+
"@aztec/archiver": "3.0.0-nightly.20251112",
|
|
76
|
+
"@aztec/aztec.js": "3.0.0-nightly.20251112",
|
|
77
|
+
"@aztec/constants": "3.0.0-nightly.20251112",
|
|
78
|
+
"@aztec/entrypoints": "3.0.0-nightly.20251112",
|
|
79
|
+
"@aztec/ethereum": "3.0.0-nightly.20251112",
|
|
80
|
+
"@aztec/foundation": "3.0.0-nightly.20251112",
|
|
81
|
+
"@aztec/l1-artifacts": "3.0.0-nightly.20251112",
|
|
82
|
+
"@aztec/node-keystore": "3.0.0-nightly.20251112",
|
|
83
|
+
"@aztec/node-lib": "3.0.0-nightly.20251112",
|
|
84
|
+
"@aztec/p2p": "3.0.0-nightly.20251112",
|
|
85
|
+
"@aztec/protocol-contracts": "3.0.0-nightly.20251112",
|
|
86
|
+
"@aztec/stdlib": "3.0.0-nightly.20251112",
|
|
87
|
+
"@aztec/test-wallet": "3.0.0-nightly.20251112",
|
|
88
|
+
"@aztec/world-state": "3.0.0-nightly.20251112",
|
|
89
89
|
"@ethersproject/wallet": "^5.8.0",
|
|
90
90
|
"@iarna/toml": "^2.2.5",
|
|
91
91
|
"@libp2p/peer-id-factory": "^3.0.4",
|
|
@@ -114,15 +114,15 @@
|
|
|
114
114
|
"typescript": "^5.3.3"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
|
-
"@aztec/accounts": "3.0.0-nightly.
|
|
118
|
-
"@aztec/bb-prover": "3.0.0-nightly.
|
|
119
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
120
|
-
"@aztec/l1-artifacts": "3.0.0-nightly.
|
|
121
|
-
"@aztec/noir-contracts.js": "3.0.0-nightly.
|
|
122
|
-
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.
|
|
123
|
-
"@aztec/noir-test-contracts.js": "3.0.0-nightly.
|
|
124
|
-
"@aztec/protocol-contracts": "3.0.0-nightly.
|
|
125
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
117
|
+
"@aztec/accounts": "3.0.0-nightly.20251112",
|
|
118
|
+
"@aztec/bb-prover": "3.0.0-nightly.20251112",
|
|
119
|
+
"@aztec/ethereum": "3.0.0-nightly.20251112",
|
|
120
|
+
"@aztec/l1-artifacts": "3.0.0-nightly.20251112",
|
|
121
|
+
"@aztec/noir-contracts.js": "3.0.0-nightly.20251112",
|
|
122
|
+
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.20251112",
|
|
123
|
+
"@aztec/noir-test-contracts.js": "3.0.0-nightly.20251112",
|
|
124
|
+
"@aztec/protocol-contracts": "3.0.0-nightly.20251112",
|
|
125
|
+
"@aztec/stdlib": "3.0.0-nightly.20251112"
|
|
126
126
|
},
|
|
127
127
|
"files": [
|
|
128
128
|
"dest",
|
|
@@ -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-
|
|
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)
|
|
@@ -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 {
|
|
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.',
|
|
@@ -67,6 +91,14 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
67
91
|
|
|
68
92
|
const mnemonic = _mnemonic ?? generateMnemonic(wordlist);
|
|
69
93
|
|
|
94
|
+
if (!_mnemonic && !json) {
|
|
95
|
+
log('No mnemonic provided, generating new one...');
|
|
96
|
+
log(`Using new mnemonic:`);
|
|
97
|
+
log('');
|
|
98
|
+
log(mnemonic);
|
|
99
|
+
log('');
|
|
100
|
+
}
|
|
101
|
+
|
|
70
102
|
const validatorCount = typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
|
|
71
103
|
const { outputPath } = await resolveKeystoreOutputPath(dataDir, file);
|
|
72
104
|
|
|
@@ -78,7 +110,6 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
78
110
|
mnemonic,
|
|
79
111
|
ikm,
|
|
80
112
|
blsPath,
|
|
81
|
-
blsOnly,
|
|
82
113
|
feeRecipient,
|
|
83
114
|
coinbase,
|
|
84
115
|
remoteSigner,
|
|
@@ -99,15 +130,66 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
99
130
|
|
|
100
131
|
await writeKeystoreFile(outputPath, keystore);
|
|
101
132
|
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
|
|
165
|
+
const outputData = !_mnemonic ? { ...keystore, generatedMnemonic: mnemonic } : keystore;
|
|
166
|
+
|
|
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 {
|
|
104
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
|
+
}
|
|
105
185
|
}
|
|
106
186
|
|
|
107
|
-
//
|
|
108
|
-
|
|
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
|
+
}
|
|
109
191
|
|
|
110
|
-
if (
|
|
192
|
+
if (mnemonic && remoteSigner && !json) {
|
|
111
193
|
for (let i = 0; i < validatorCount; i++) {
|
|
112
194
|
const addrIdx = addressIndex + i;
|
|
113
195
|
const acct = mnemonicToAccount(mnemonic, {
|
|
@@ -117,4 +199,10 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
117
199
|
log(`attester address: ${acct.address} remoteSignerUrl: ${remoteSigner}`);
|
|
118
200
|
}
|
|
119
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
|
+
}
|
|
120
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 =
|
|
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
|
+
}
|