@aztec/cli 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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/dest/cmds/aztec_node/block_number.js +1 -1
- package/dest/cmds/aztec_node/get_current_min_fee.d.ts +3 -0
- package/dest/cmds/aztec_node/get_current_min_fee.d.ts.map +1 -0
- package/dest/cmds/aztec_node/{get_current_base_fee.js → get_current_min_fee.js} +2 -2
- package/dest/cmds/aztec_node/get_logs.d.ts +30 -4
- package/dest/cmds/aztec_node/get_logs.d.ts.map +1 -1
- package/dest/cmds/aztec_node/get_logs.js +39 -29
- package/dest/cmds/aztec_node/get_node_info.d.ts +1 -1
- package/dest/cmds/aztec_node/get_node_info.d.ts.map +1 -1
- package/dest/cmds/aztec_node/get_node_info.js +0 -2
- package/dest/cmds/aztec_node/index.d.ts +1 -1
- package/dest/cmds/aztec_node/index.d.ts.map +1 -1
- package/dest/cmds/aztec_node/index.js +16 -6
- package/dest/cmds/contracts/inspect_contract.js +1 -1
- package/dest/cmds/infrastructure/sequencers.d.ts +1 -1
- package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -1
- package/dest/cmds/infrastructure/sequencers.js +11 -4
- package/dest/cmds/infrastructure/setup_l2_contract.d.ts +1 -1
- package/dest/cmds/infrastructure/setup_l2_contract.d.ts.map +1 -1
- package/dest/cmds/infrastructure/setup_l2_contract.js +12 -7
- package/dest/cmds/l1/assume_proven_through.d.ts +3 -2
- package/dest/cmds/l1/assume_proven_through.d.ts.map +1 -1
- package/dest/cmds/l1/assume_proven_through.js +3 -5
- package/dest/cmds/l1/bridge_erc20.d.ts +1 -1
- package/dest/cmds/l1/bridge_erc20.d.ts.map +1 -1
- package/dest/cmds/l1/bridge_erc20.js +2 -1
- package/dest/cmds/l1/compute_genesis_values.d.ts +4 -0
- package/dest/cmds/l1/compute_genesis_values.d.ts.map +1 -0
- package/dest/cmds/l1/compute_genesis_values.js +17 -0
- package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts +4 -0
- package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts.map +1 -0
- package/dest/cmds/l1/{deploy_l1_contracts.js → deploy_l1_contracts_cmd.js} +39 -5
- package/dest/cmds/l1/deploy_new_rollup.d.ts +4 -4
- package/dest/cmds/l1/deploy_new_rollup.d.ts.map +1 -1
- package/dest/cmds/l1/deploy_new_rollup.js +4 -6
- package/dest/cmds/l1/get_l1_addresses.d.ts +1 -1
- package/dest/cmds/l1/get_l1_addresses.d.ts.map +1 -1
- package/dest/cmds/l1/get_l1_addresses.js +5 -2
- package/dest/cmds/l1/get_l1_balance.js +4 -2
- package/dest/cmds/l1/governance_utils.d.ts +1 -1
- package/dest/cmds/l1/governance_utils.d.ts.map +1 -1
- package/dest/cmds/l1/governance_utils.js +3 -1
- package/dest/cmds/l1/index.d.ts +1 -2
- package/dest/cmds/l1/index.d.ts.map +1 -1
- package/dest/cmds/l1/index.js +17 -10
- package/dest/cmds/l1/prover_stats.d.ts +1 -1
- package/dest/cmds/l1/prover_stats.d.ts.map +1 -1
- package/dest/cmds/l1/prover_stats.js +4 -2
- package/dest/cmds/l1/trigger_seed_snapshot.d.ts +1 -1
- package/dest/cmds/l1/trigger_seed_snapshot.d.ts.map +1 -1
- package/dest/cmds/l1/trigger_seed_snapshot.js +2 -1
- package/dest/cmds/l1/update_l1_validators.d.ts +3 -3
- package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
- package/dest/cmds/l1/update_l1_validators.js +56 -18
- package/dest/cmds/misc/generate_secret_and_hash.js +1 -1
- package/dest/cmds/misc/index.d.ts +1 -1
- package/dest/cmds/misc/index.d.ts.map +1 -1
- package/dest/cmds/misc/index.js +1 -1
- package/dest/cmds/validator_keys/eth_json_v3_worker.d.ts +2 -0
- package/dest/cmds/validator_keys/eth_json_v3_worker.d.ts.map +1 -0
- package/dest/cmds/validator_keys/eth_json_v3_worker.js +27 -0
- package/dest/cmds/validator_keys/generate_bls_keypair.js +1 -1
- package/dest/cmds/validator_keys/index.d.ts +1 -1
- package/dest/cmds/validator_keys/index.d.ts.map +1 -1
- package/dest/cmds/validator_keys/index.js +7 -6
- package/dest/cmds/validator_keys/new.d.ts +7 -1
- package/dest/cmds/validator_keys/new.d.ts.map +1 -1
- package/dest/cmds/validator_keys/new.js +103 -14
- package/dest/cmds/validator_keys/set_funding_account.d.ts +14 -0
- package/dest/cmds/validator_keys/set_funding_account.d.ts.map +1 -0
- package/dest/cmds/validator_keys/set_funding_account.js +37 -0
- package/dest/cmds/validator_keys/shared.d.ts +15 -2
- package/dest/cmds/validator_keys/shared.d.ts.map +1 -1
- package/dest/cmds/validator_keys/shared.js +102 -24
- package/dest/cmds/validator_keys/staker.d.ts +2 -2
- package/dest/cmds/validator_keys/staker.d.ts.map +1 -1
- package/dest/cmds/validator_keys/staker.js +7 -4
- package/dest/cmds/validator_keys/utils.d.ts +12 -2
- package/dest/cmds/validator_keys/utils.d.ts.map +1 -1
- package/dest/cmds/validator_keys/utils.js +35 -1
- package/dest/config/cached_fetch.d.ts +19 -10
- package/dest/config/cached_fetch.d.ts.map +1 -1
- package/dest/config/cached_fetch.js +110 -32
- package/dest/config/chain_l2_config.d.ts +17 -38
- package/dest/config/chain_l2_config.d.ts.map +1 -1
- package/dest/config/chain_l2_config.js +48 -493
- package/dest/config/generated/networks.d.ts +239 -0
- package/dest/config/generated/networks.d.ts.map +1 -0
- package/dest/config/generated/networks.js +240 -0
- package/dest/config/get_l1_config.d.ts +3 -2
- package/dest/config/get_l1_config.d.ts.map +1 -1
- package/dest/config/get_l1_config.js +3 -1
- package/dest/config/network_config.d.ts +2 -2
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +13 -3
- package/dest/utils/aztec.d.ts +7 -14
- package/dest/utils/aztec.d.ts.map +1 -1
- package/dest/utils/aztec.js +19 -41
- package/dest/utils/commands.d.ts +25 -15
- package/dest/utils/commands.d.ts.map +1 -1
- package/dest/utils/commands.js +34 -22
- package/dest/utils/encoding.js +1 -1
- package/dest/utils/inspect.d.ts +1 -1
- package/dest/utils/inspect.d.ts.map +1 -1
- package/dest/utils/inspect.js +15 -12
- package/package.json +39 -31
- package/src/cmds/aztec_node/block_number.ts +1 -1
- package/src/cmds/aztec_node/{get_current_base_fee.ts → get_current_min_fee.ts} +2 -2
- package/src/cmds/aztec_node/get_logs.ts +70 -38
- package/src/cmds/aztec_node/get_node_info.ts +0 -2
- package/src/cmds/aztec_node/index.ts +16 -11
- package/src/cmds/contracts/inspect_contract.ts +1 -1
- package/src/cmds/infrastructure/sequencers.ts +7 -4
- package/src/cmds/infrastructure/setup_l2_contract.ts +12 -7
- package/src/cmds/l1/assume_proven_through.ts +4 -7
- package/src/cmds/l1/bridge_erc20.ts +2 -1
- package/src/cmds/l1/compute_genesis_values.ts +29 -0
- package/src/cmds/l1/{deploy_l1_contracts.ts → deploy_l1_contracts_cmd.ts} +39 -23
- package/src/cmds/l1/deploy_new_rollup.ts +5 -12
- package/src/cmds/l1/get_l1_addresses.ts +4 -2
- package/src/cmds/l1/get_l1_balance.ts +2 -2
- package/src/cmds/l1/governance_utils.ts +3 -8
- package/src/cmds/l1/index.ts +30 -21
- package/src/cmds/l1/prover_stats.ts +6 -2
- package/src/cmds/l1/trigger_seed_snapshot.ts +2 -1
- package/src/cmds/l1/update_l1_validators.ts +50 -30
- package/src/cmds/misc/generate_secret_and_hash.ts +1 -1
- package/src/cmds/misc/index.ts +1 -1
- package/src/cmds/validator_keys/eth_json_v3_worker.ts +30 -0
- package/src/cmds/validator_keys/generate_bls_keypair.ts +1 -1
- package/src/cmds/validator_keys/index.ts +48 -8
- package/src/cmds/validator_keys/new.ts +132 -11
- package/src/cmds/validator_keys/set_funding_account.ts +55 -0
- package/src/cmds/validator_keys/shared.ts +125 -36
- package/src/cmds/validator_keys/staker.ts +5 -4
- package/src/cmds/validator_keys/utils.ts +46 -2
- package/src/config/cached_fetch.ts +119 -31
- package/src/config/chain_l2_config.ts +46 -642
- package/src/config/generated/networks.ts +244 -0
- package/src/config/get_l1_config.ts +4 -1
- package/src/config/network_config.ts +14 -3
- package/src/utils/aztec.ts +30 -95
- package/src/utils/commands.ts +41 -26
- package/src/utils/encoding.ts +1 -1
- package/src/utils/inspect.ts +11 -9
- package/dest/cmds/aztec_node/get_current_base_fee.d.ts +0 -3
- package/dest/cmds/aztec_node/get_current_base_fee.d.ts.map +0 -1
- package/dest/cmds/l1/deploy_l1_contracts.d.ts +0 -4
- package/dest/cmds/l1/deploy_l1_contracts.d.ts.map +0 -1
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { prettyPrintJSON } from '@aztec/cli/utils';
|
|
2
|
-
import {
|
|
2
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
|
+
import { GSEContract } from '@aztec/ethereum/contracts';
|
|
3
4
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
5
|
import type { LogFn } from '@aztec/foundation/log';
|
|
5
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
7
|
|
|
7
8
|
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
8
|
-
import { writeFile } from 'fs/promises';
|
|
9
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
9
10
|
import { basename, dirname, join } from 'path';
|
|
10
11
|
import { createPublicClient, fallback, http } from 'viem';
|
|
11
|
-
import { generateMnemonic, mnemonicToAccount } from 'viem/accounts';
|
|
12
|
+
import { generateMnemonic, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
12
13
|
|
|
13
14
|
import {
|
|
14
15
|
buildValidatorEntries,
|
|
16
|
+
encryptFundingAccountToFile,
|
|
15
17
|
logValidatorSummaries,
|
|
16
18
|
maybePrintJson,
|
|
19
|
+
resolveFundingAccount,
|
|
17
20
|
resolveKeystoreOutputPath,
|
|
18
21
|
writeBlsBn254ToFile,
|
|
19
22
|
writeEthJsonV3ToFile,
|
|
@@ -22,6 +25,7 @@ import {
|
|
|
22
25
|
import { processAttesterAccounts } from './staker.js';
|
|
23
26
|
import {
|
|
24
27
|
validateBlsPathOptions,
|
|
28
|
+
validateFundingAccountOptions,
|
|
25
29
|
validatePublisherOptions,
|
|
26
30
|
validateRemoteSignerOptions,
|
|
27
31
|
validateStakerOutputOptions,
|
|
@@ -41,10 +45,16 @@ export type NewValidatorKeystoreOptions = {
|
|
|
41
45
|
ikm?: string;
|
|
42
46
|
blsPath?: string;
|
|
43
47
|
password?: string;
|
|
48
|
+
passwordFile?: string;
|
|
49
|
+
ethPassword?: string;
|
|
50
|
+
ethPasswordFile?: string;
|
|
51
|
+
blsPassword?: string;
|
|
52
|
+
blsPasswordFile?: string;
|
|
44
53
|
encryptedKeystoreDir?: string;
|
|
45
54
|
json?: boolean;
|
|
46
55
|
feeRecipient: AztecAddress;
|
|
47
56
|
coinbase?: EthAddress;
|
|
57
|
+
fundingAccount?: string;
|
|
48
58
|
remoteSigner?: string;
|
|
49
59
|
stakerOutput?: boolean;
|
|
50
60
|
gseAddress?: EthAddress;
|
|
@@ -52,6 +62,86 @@ export type NewValidatorKeystoreOptions = {
|
|
|
52
62
|
l1ChainId?: number;
|
|
53
63
|
};
|
|
54
64
|
|
|
65
|
+
type PasswordSourceOptions = Pick<
|
|
66
|
+
NewValidatorKeystoreOptions,
|
|
67
|
+
'password' | 'passwordFile' | 'ethPassword' | 'ethPasswordFile' | 'blsPassword' | 'blsPasswordFile'
|
|
68
|
+
>;
|
|
69
|
+
|
|
70
|
+
type PasswordSource = {
|
|
71
|
+
password?: string;
|
|
72
|
+
passwordFile?: string;
|
|
73
|
+
passwordOption: string;
|
|
74
|
+
passwordFileOption: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
function validatePassword(password: string, source: string): string {
|
|
78
|
+
if (password.length === 0) {
|
|
79
|
+
throw new Error(`${source} cannot be empty`);
|
|
80
|
+
}
|
|
81
|
+
return password;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function stripOneTrailingNewline(password: string): string {
|
|
85
|
+
if (password.endsWith('\n')) {
|
|
86
|
+
password = password.slice(0, -1);
|
|
87
|
+
}
|
|
88
|
+
if (password.endsWith('\r')) {
|
|
89
|
+
password = password.slice(0, -1);
|
|
90
|
+
}
|
|
91
|
+
return password;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function resolvePasswordSource(source: PasswordSource): Promise<string | undefined> {
|
|
95
|
+
if (source.password !== undefined && source.passwordFile !== undefined) {
|
|
96
|
+
throw new Error(`${source.passwordOption} and ${source.passwordFileOption} cannot be used together`);
|
|
97
|
+
}
|
|
98
|
+
if (source.password !== undefined) {
|
|
99
|
+
return validatePassword(source.password, source.passwordOption);
|
|
100
|
+
}
|
|
101
|
+
if (source.passwordFile !== undefined) {
|
|
102
|
+
if (source.passwordFile.length === 0) {
|
|
103
|
+
throw new Error(`${source.passwordFileOption} cannot be empty`);
|
|
104
|
+
}
|
|
105
|
+
const password = stripOneTrailingNewline(await readFile(source.passwordFile, 'utf-8'));
|
|
106
|
+
return validatePassword(password, source.passwordFileOption);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function resolvePasswords(options: PasswordSourceOptions) {
|
|
113
|
+
const sharedPassword = await resolvePasswordSource({
|
|
114
|
+
password: options.password,
|
|
115
|
+
passwordFile: options.passwordFile,
|
|
116
|
+
passwordOption: '--password',
|
|
117
|
+
passwordFileOption: '--password-file',
|
|
118
|
+
});
|
|
119
|
+
const ethPassword =
|
|
120
|
+
(await resolvePasswordSource({
|
|
121
|
+
password: options.ethPassword,
|
|
122
|
+
passwordFile: options.ethPasswordFile,
|
|
123
|
+
passwordOption: '--eth-password',
|
|
124
|
+
passwordFileOption: '--eth-password-file',
|
|
125
|
+
})) ?? sharedPassword;
|
|
126
|
+
const blsPassword =
|
|
127
|
+
(await resolvePasswordSource({
|
|
128
|
+
password: options.blsPassword,
|
|
129
|
+
passwordFile: options.blsPasswordFile,
|
|
130
|
+
passwordOption: '--bls-password',
|
|
131
|
+
passwordFileOption: '--bls-password-file',
|
|
132
|
+
})) ?? sharedPassword;
|
|
133
|
+
|
|
134
|
+
if (ethPassword === undefined && blsPassword === undefined) {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
if (ethPassword === undefined || blsPassword === undefined) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
'Both ETH and BLS passwords are required when writing encrypted keystores. Provide --password to use one password for both, or provide both --eth-password and --bls-password.',
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return { ethPassword, blsPassword };
|
|
143
|
+
}
|
|
144
|
+
|
|
55
145
|
export async function newValidatorKeystore(options: NewValidatorKeystoreOptions, log: LogFn) {
|
|
56
146
|
// validate bls-path inputs before proceeding with key generation
|
|
57
147
|
validateBlsPathOptions(options);
|
|
@@ -61,6 +151,8 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
61
151
|
validatePublisherOptions(options);
|
|
62
152
|
// validate remote signer options
|
|
63
153
|
validateRemoteSignerOptions(options);
|
|
154
|
+
// validate funding account option
|
|
155
|
+
validateFundingAccountOptions(options);
|
|
64
156
|
|
|
65
157
|
const {
|
|
66
158
|
dataDir,
|
|
@@ -70,6 +162,7 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
70
162
|
publishers,
|
|
71
163
|
json,
|
|
72
164
|
coinbase,
|
|
165
|
+
fundingAccount,
|
|
73
166
|
accountIndex = 0,
|
|
74
167
|
addressIndex = 0,
|
|
75
168
|
feeRecipient,
|
|
@@ -77,7 +170,12 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
77
170
|
blsPath,
|
|
78
171
|
ikm,
|
|
79
172
|
mnemonic: _mnemonic,
|
|
80
|
-
password,
|
|
173
|
+
password: passwordOption,
|
|
174
|
+
passwordFile,
|
|
175
|
+
ethPassword: ethPasswordOption,
|
|
176
|
+
ethPasswordFile,
|
|
177
|
+
blsPassword: blsPasswordOption,
|
|
178
|
+
blsPasswordFile,
|
|
81
179
|
encryptedKeystoreDir,
|
|
82
180
|
stakerOutput,
|
|
83
181
|
gseAddress,
|
|
@@ -85,9 +183,18 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
85
183
|
l1ChainId,
|
|
86
184
|
} = options;
|
|
87
185
|
|
|
186
|
+
const { ethPassword, blsPassword } = await resolvePasswords({
|
|
187
|
+
password: passwordOption,
|
|
188
|
+
passwordFile,
|
|
189
|
+
ethPassword: ethPasswordOption,
|
|
190
|
+
ethPasswordFile,
|
|
191
|
+
blsPassword: blsPasswordOption,
|
|
192
|
+
blsPasswordFile,
|
|
193
|
+
});
|
|
194
|
+
const shouldEncryptKeystores = ethPassword !== undefined && blsPassword !== undefined;
|
|
88
195
|
const mnemonic = _mnemonic ?? generateMnemonic(wordlist);
|
|
89
196
|
|
|
90
|
-
if (!_mnemonic && !json) {
|
|
197
|
+
if (!_mnemonic && !json && !shouldEncryptKeystores) {
|
|
91
198
|
log('No mnemonic provided, generating new one...');
|
|
92
199
|
log(`Using new mnemonic:`);
|
|
93
200
|
log('');
|
|
@@ -113,17 +220,26 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
113
220
|
remoteSigner,
|
|
114
221
|
});
|
|
115
222
|
|
|
223
|
+
let resolvedFundingAccount = fundingAccount ? resolveFundingAccount(fundingAccount, remoteSigner) : undefined;
|
|
224
|
+
|
|
116
225
|
// If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
|
|
117
|
-
if (
|
|
226
|
+
if (shouldEncryptKeystores) {
|
|
118
227
|
const encryptedKeystoreOutDir =
|
|
119
228
|
encryptedKeystoreDir && encryptedKeystoreDir.length > 0 ? encryptedKeystoreDir : keystoreOutDir;
|
|
120
|
-
await writeEthJsonV3ToFile(validators, { outDir: encryptedKeystoreOutDir, password });
|
|
121
|
-
await writeBlsBn254ToFile(validators, { outDir: encryptedKeystoreOutDir, password });
|
|
229
|
+
await writeEthJsonV3ToFile(validators, { outDir: encryptedKeystoreOutDir, password: ethPassword });
|
|
230
|
+
await writeBlsBn254ToFile(validators, { outDir: encryptedKeystoreOutDir, password: blsPassword });
|
|
231
|
+
if (resolvedFundingAccount) {
|
|
232
|
+
resolvedFundingAccount = await encryptFundingAccountToFile(resolvedFundingAccount, {
|
|
233
|
+
outDir: encryptedKeystoreOutDir,
|
|
234
|
+
password: ethPassword,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
122
237
|
}
|
|
123
238
|
|
|
124
239
|
const keystore = {
|
|
125
240
|
schemaVersion: 1,
|
|
126
241
|
validators,
|
|
242
|
+
...(resolvedFundingAccount ? { fundingAccount: resolvedFundingAccount } : {}),
|
|
127
243
|
};
|
|
128
244
|
|
|
129
245
|
await writeKeystoreFile(outputPath, keystore);
|
|
@@ -134,7 +250,7 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
134
250
|
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
135
251
|
const publicClient = createPublicClient({
|
|
136
252
|
chain: chain.chainInfo,
|
|
137
|
-
transport: fallback(l1RpcUrls.map(url => http(url))),
|
|
253
|
+
transport: fallback(l1RpcUrls.map(url => http(url, { batch: false }))),
|
|
138
254
|
});
|
|
139
255
|
const gse = new GSEContract(publicClient, gseAddress);
|
|
140
256
|
|
|
@@ -144,7 +260,7 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
144
260
|
// Process each validator
|
|
145
261
|
for (let i = 0; i < validators.length; i++) {
|
|
146
262
|
const validator = validators[i];
|
|
147
|
-
const outputs = await processAttesterAccounts(validator.attester, gse
|
|
263
|
+
const outputs = await processAttesterAccounts(validator.attester, gse);
|
|
148
264
|
|
|
149
265
|
// Collect all staker outputs
|
|
150
266
|
for (let j = 0; j < outputs.length; j++) {
|
|
@@ -159,7 +275,7 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
159
275
|
}
|
|
160
276
|
}
|
|
161
277
|
|
|
162
|
-
const outputData = !_mnemonic ? { ...keystore, generatedMnemonic: mnemonic } : keystore;
|
|
278
|
+
const outputData = !_mnemonic && !shouldEncryptKeystores ? { ...keystore, generatedMnemonic: mnemonic } : keystore;
|
|
163
279
|
|
|
164
280
|
// Handle JSON output
|
|
165
281
|
if (json) {
|
|
@@ -185,6 +301,11 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
185
301
|
// print a concise summary of public keys (addresses and BLS pubkeys) if no --json options was selected
|
|
186
302
|
if (!json) {
|
|
187
303
|
logValidatorSummaries(log, summaries);
|
|
304
|
+
if (fundingAccount) {
|
|
305
|
+
const funderAddress =
|
|
306
|
+
fundingAccount.length === 66 ? privateKeyToAccount(fundingAccount as `0x${string}`).address : fundingAccount;
|
|
307
|
+
log(`funding account: ${funderAddress}`);
|
|
308
|
+
}
|
|
188
309
|
}
|
|
189
310
|
|
|
190
311
|
if (mnemonic && remoteSigner && !json) {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
+
import { loadKeystoreFile } from '@aztec/node-keystore/loader';
|
|
3
|
+
import type { KeyStore } from '@aztec/node-keystore/types';
|
|
4
|
+
|
|
5
|
+
import { dirname } from 'path';
|
|
6
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
7
|
+
|
|
8
|
+
import { encryptFundingAccountToFile, maybePrintJson, resolveFundingAccount, writeKeystoreFile } from './shared.js';
|
|
9
|
+
import { validateFundingAccountOptions } from './utils.js';
|
|
10
|
+
|
|
11
|
+
export type SetFundingAccountOptions = {
|
|
12
|
+
remoteSigner?: string;
|
|
13
|
+
password?: string;
|
|
14
|
+
encryptedKeystoreDir?: string;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sets the top-level funding account of an existing keystore, replacing any previous one. The
|
|
20
|
+
* account may be a private key, or an address paired with a remote signer URL. With a password,
|
|
21
|
+
* a plaintext key is encrypted to an ETH JSON V3 file and stored as a { path, password } reference.
|
|
22
|
+
*/
|
|
23
|
+
export async function setFundingAccount(
|
|
24
|
+
existing: string,
|
|
25
|
+
fundingAccount: string,
|
|
26
|
+
options: SetFundingAccountOptions,
|
|
27
|
+
log: LogFn,
|
|
28
|
+
) {
|
|
29
|
+
const { remoteSigner, password, encryptedKeystoreDir, json } = options;
|
|
30
|
+
|
|
31
|
+
const keystore: KeyStore = loadKeystoreFile(existing);
|
|
32
|
+
|
|
33
|
+
const validated = { fundingAccount, remoteSigner };
|
|
34
|
+
validateFundingAccountOptions(validated, !!keystore.remoteSigner);
|
|
35
|
+
|
|
36
|
+
let resolved = resolveFundingAccount(validated.fundingAccount!, remoteSigner);
|
|
37
|
+
if (password !== undefined) {
|
|
38
|
+
const outDir = encryptedKeystoreDir && encryptedKeystoreDir.length > 0 ? encryptedKeystoreDir : dirname(existing);
|
|
39
|
+
resolved = await encryptFundingAccountToFile(resolved, { outDir, password });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (keystore.fundingAccount) {
|
|
43
|
+
log('Replacing existing funding account in keystore');
|
|
44
|
+
}
|
|
45
|
+
keystore.fundingAccount = resolved;
|
|
46
|
+
|
|
47
|
+
await writeKeystoreFile(existing, keystore);
|
|
48
|
+
|
|
49
|
+
if (!json) {
|
|
50
|
+
const value = validated.fundingAccount!;
|
|
51
|
+
const funderAddress = value.length === 66 ? privateKeyToAccount(value as `0x${string}`).address : value;
|
|
52
|
+
log(`Set funding account ${funderAddress} in ${existing}`);
|
|
53
|
+
}
|
|
54
|
+
maybePrintJson(log, !!json, keystore as unknown as Record<string, any>);
|
|
55
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { prettyPrintJSON } from '@aztec/cli/utils';
|
|
2
|
-
import {
|
|
2
|
+
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
3
|
+
import { deriveBlsPrivateKey } from '@aztec/foundation/crypto/bls';
|
|
3
4
|
import { createBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
|
|
4
|
-
import
|
|
5
|
+
import { computeBn254G1PublicKeyCompressed } from '@aztec/foundation/crypto/bn254';
|
|
6
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
7
|
import type { LogFn } from '@aztec/foundation/log';
|
|
6
8
|
import type { EthAccount, EthPrivateKey, ValidatorKeyStore } from '@aztec/node-keystore/types';
|
|
7
9
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -9,12 +11,60 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
9
11
|
import { Wallet } from '@ethersproject/wallet';
|
|
10
12
|
import { constants as fsConstants, mkdirSync } from 'fs';
|
|
11
13
|
import { access, writeFile } from 'fs/promises';
|
|
12
|
-
import { homedir } from 'os';
|
|
14
|
+
import { availableParallelism, homedir } from 'os';
|
|
13
15
|
import { dirname, isAbsolute, join } from 'path';
|
|
14
16
|
import { mnemonicToAccount } from 'viem/accounts';
|
|
17
|
+
import { Worker } from 'worker_threads';
|
|
15
18
|
|
|
16
19
|
import { defaultBlsPath } from './utils.js';
|
|
17
20
|
|
|
21
|
+
type EthJsonV3WorkerResult = { json: string } | { error: { message: string; name?: string; stack?: string } };
|
|
22
|
+
|
|
23
|
+
// ethers' default scrypt parameters use substantial memory, so keep worker fan-out bounded.
|
|
24
|
+
const maxEthKeystoreWorkers = Math.max(1, Math.min(4, availableParallelism()));
|
|
25
|
+
|
|
26
|
+
function deserializeWorkerError(error: { message: string; name?: string; stack?: string }) {
|
|
27
|
+
const result = new Error(error.message);
|
|
28
|
+
result.name = error.name ?? result.name;
|
|
29
|
+
result.stack = error.stack;
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function encryptEthJsonV3InWorker(privateKeyHex: string, password: string): Promise<string> {
|
|
34
|
+
return new Promise<string>((resolve, reject) => {
|
|
35
|
+
const worker = new Worker(new URL('./eth_json_v3_worker.js', import.meta.url), {
|
|
36
|
+
workerData: { privateKeyHex, password },
|
|
37
|
+
});
|
|
38
|
+
let settled = false;
|
|
39
|
+
|
|
40
|
+
worker.once('message', (result: EthJsonV3WorkerResult) => {
|
|
41
|
+
settled = true;
|
|
42
|
+
|
|
43
|
+
if ('json' in result) {
|
|
44
|
+
resolve(result.json);
|
|
45
|
+
} else {
|
|
46
|
+
reject(deserializeWorkerError(result.error));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
worker.once('error', error => {
|
|
50
|
+
settled = true;
|
|
51
|
+
reject(error);
|
|
52
|
+
});
|
|
53
|
+
worker.once('exit', code => {
|
|
54
|
+
if (!settled) {
|
|
55
|
+
reject(new Error(`ETH JSON V3 worker stopped with exit code ${code}`));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function encryptEthJsonV3(privateKeyHex: string, password: string): Promise<string> {
|
|
62
|
+
if (process.env.JEST_WORKER_ID !== undefined) {
|
|
63
|
+
return await new Wallet(privateKeyHex).encrypt(password);
|
|
64
|
+
}
|
|
65
|
+
return await encryptEthJsonV3InWorker(privateKeyHex, password);
|
|
66
|
+
}
|
|
67
|
+
|
|
18
68
|
export type ValidatorSummary = { attesterEth?: string; attesterBls?: string; publisherEth?: string[] };
|
|
19
69
|
|
|
20
70
|
export type BuildValidatorsInput = {
|
|
@@ -75,6 +125,21 @@ export function deriveEthAttester(
|
|
|
75
125
|
: (('0x' + Buffer.from(acct.getHdKey().privateKey!).toString('hex')) as EthPrivateKey);
|
|
76
126
|
}
|
|
77
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Resolve a `--funding-account` value into a keystore `EthAccount`. A 66-char value is a private key
|
|
130
|
+
* (used verbatim). A 42-char value is an address: with an explicit `remoteSigner` URL it becomes an
|
|
131
|
+
* `{ address, remoteSignerUrl }` pair; without one it is stored as a bare address that falls back to
|
|
132
|
+
* the keystore-level remote signer at runtime. Callers must validate the value first (see
|
|
133
|
+
* `validateFundingAccountOptions`).
|
|
134
|
+
*/
|
|
135
|
+
export function resolveFundingAccount(fundingAccount: string, remoteSigner?: string): EthAccount {
|
|
136
|
+
if (fundingAccount.length === 66) {
|
|
137
|
+
return fundingAccount as EthPrivateKey;
|
|
138
|
+
}
|
|
139
|
+
const address = EthAddress.fromString(fundingAccount);
|
|
140
|
+
return remoteSigner ? ({ address, remoteSignerUrl: remoteSigner } as EthAccount) : address;
|
|
141
|
+
}
|
|
142
|
+
|
|
78
143
|
export async function buildValidatorEntries(input: BuildValidatorsInput) {
|
|
79
144
|
const {
|
|
80
145
|
validatorCount,
|
|
@@ -227,7 +292,7 @@ export async function writeBn254BlsKeystore(
|
|
|
227
292
|
): Promise<string> {
|
|
228
293
|
mkdirSync(outDir, { recursive: true });
|
|
229
294
|
|
|
230
|
-
const keystore = createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath);
|
|
295
|
+
const keystore = await createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath);
|
|
231
296
|
|
|
232
297
|
const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
233
298
|
const outPath = join(outDir, `keystore-${safeBase}.json`);
|
|
@@ -240,28 +305,29 @@ export async function writeBlsBn254ToFile(
|
|
|
240
305
|
validators: ValidatorKeyStore[],
|
|
241
306
|
options: { outDir: string; password: string; blsPath?: string },
|
|
242
307
|
): Promise<void> {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
308
|
+
await Promise.all(
|
|
309
|
+
validators.map(async (v, i) => {
|
|
310
|
+
if (!v || typeof v !== 'object' || !('attester' in v)) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const att = (v as any).attester;
|
|
249
314
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
315
|
+
// Shapes: { bls: <hex> } or { eth: <ethAccount>, bls?: <hex> } or plain EthAccount
|
|
316
|
+
const blsKey: string | undefined = typeof att === 'object' && 'bls' in att ? (att as any).bls : undefined;
|
|
317
|
+
if (!blsKey || typeof blsKey !== 'string') {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
255
320
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
321
|
+
const pub = await computeBlsPublicKeyCompressed(blsKey);
|
|
322
|
+
const path = options.blsPath ?? defaultBlsPath;
|
|
323
|
+
const fileBase = `${String(i + 1)}_${pub.slice(2, 18)}`;
|
|
324
|
+
const keystorePath = await writeBn254BlsKeystore(options.outDir, fileBase, options.password, blsKey, pub, path);
|
|
260
325
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
326
|
+
if (typeof att === 'object') {
|
|
327
|
+
(att as any).bls = { path: keystorePath, password: options.password };
|
|
328
|
+
}
|
|
329
|
+
}),
|
|
330
|
+
);
|
|
265
331
|
}
|
|
266
332
|
|
|
267
333
|
/** Writes an Ethereum JSON V3 keystore using ethers, returns absolute path */
|
|
@@ -273,25 +339,48 @@ export async function writeEthJsonV3Keystore(
|
|
|
273
339
|
): Promise<string> {
|
|
274
340
|
const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
275
341
|
mkdirSync(outDir, { recursive: true });
|
|
276
|
-
const
|
|
277
|
-
const json = await wallet.encrypt(password);
|
|
342
|
+
const json = await encryptEthJsonV3(privateKeyHex, password);
|
|
278
343
|
const outPath = join(outDir, `keystore-eth-${safeBase}.json`);
|
|
279
344
|
await writeFile(outPath, json, { encoding: 'utf-8' });
|
|
280
345
|
return outPath;
|
|
281
346
|
}
|
|
282
347
|
|
|
348
|
+
/**
|
|
349
|
+
* If `account` is a plaintext ETH private key, encrypt it to a JSON V3 file and return a
|
|
350
|
+
* { path, password } reference; otherwise return it unchanged.
|
|
351
|
+
*/
|
|
352
|
+
async function maybeEncryptEthAccount(account: any, label: string, options: { outDir: string; password: string }) {
|
|
353
|
+
if (typeof account === 'string' && account.startsWith('0x') && account.length === 66) {
|
|
354
|
+
const fileBase = `${label}_${account.slice(2, 10)}`;
|
|
355
|
+
const p = await writeEthJsonV3Keystore(options.outDir, fileBase, options.password, account);
|
|
356
|
+
return { path: p, password: options.password };
|
|
357
|
+
}
|
|
358
|
+
return account;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** Encrypt a plaintext funding-account key to a JSON V3 file, replacing it with a { path, password } reference. */
|
|
362
|
+
export async function encryptFundingAccountToFile(
|
|
363
|
+
account: EthAccount,
|
|
364
|
+
options: { outDir: string; password: string },
|
|
365
|
+
): Promise<EthAccount> {
|
|
366
|
+
return (await maybeEncryptEthAccount(account, 'funding', options)) as EthAccount;
|
|
367
|
+
}
|
|
368
|
+
|
|
283
369
|
/** Replace plaintext ETH keys in validators with { path, password } pointing to JSON V3 files. */
|
|
284
370
|
export async function writeEthJsonV3ToFile(
|
|
285
371
|
validators: ValidatorKeyStore[],
|
|
286
372
|
options: { outDir: string; password: string },
|
|
287
373
|
): Promise<void> {
|
|
288
|
-
const
|
|
374
|
+
const tasks: (() => Promise<void>)[] = [];
|
|
375
|
+
|
|
376
|
+
const maybeQueueEncryptEth = (account: any, label: string, setEncryptedAccount: (account: any) => void) => {
|
|
289
377
|
if (typeof account === 'string' && account.startsWith('0x') && account.length === 66) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
378
|
+
tasks.push(async () => {
|
|
379
|
+
const fileBase = `${label}_${account.slice(2, 10)}`;
|
|
380
|
+
const path = await writeEthJsonV3Keystore(options.outDir, fileBase, options.password, account);
|
|
381
|
+
setEncryptedAccount({ path, password: options.password });
|
|
382
|
+
});
|
|
293
383
|
}
|
|
294
|
-
return account;
|
|
295
384
|
};
|
|
296
385
|
|
|
297
386
|
for (let i = 0; i < validators.length; i++) {
|
|
@@ -303,23 +392,23 @@ export async function writeEthJsonV3ToFile(
|
|
|
303
392
|
// attester may be string (eth), object with eth, or remote signer
|
|
304
393
|
const att = (v as any).attester;
|
|
305
394
|
if (typeof att === 'string') {
|
|
306
|
-
(
|
|
395
|
+
maybeQueueEncryptEth(att, `attester_${i + 1}`, account => ((v as any).attester = account));
|
|
307
396
|
} else if (att && typeof att === 'object' && 'eth' in att) {
|
|
308
|
-
(att as any).eth
|
|
397
|
+
maybeQueueEncryptEth((att as any).eth, `attester_${i + 1}`, account => ((att as any).eth = account));
|
|
309
398
|
}
|
|
310
399
|
|
|
311
400
|
// publisher can be single or array
|
|
312
401
|
if ('publisher' in v) {
|
|
313
402
|
const pub = (v as any).publisher;
|
|
314
403
|
if (Array.isArray(pub)) {
|
|
315
|
-
const out: any[] = [];
|
|
316
404
|
for (let j = 0; j < pub.length; j++) {
|
|
317
|
-
|
|
405
|
+
maybeQueueEncryptEth(pub[j], `publisher_${i + 1}_${j + 1}`, account => (pub[j] = account));
|
|
318
406
|
}
|
|
319
|
-
(v as any).publisher = out;
|
|
320
407
|
} else if (pub !== undefined) {
|
|
321
|
-
(
|
|
408
|
+
maybeQueueEncryptEth(pub, `publisher_${i + 1}`, account => ((v as any).publisher = account));
|
|
322
409
|
}
|
|
323
410
|
}
|
|
324
411
|
}
|
|
412
|
+
|
|
413
|
+
await asyncPool(maxEthKeystoreWorkers, tasks, task => task());
|
|
325
414
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { prettyPrintJSON } from '@aztec/cli/utils';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
|
+
import { GSEContract } from '@aztec/ethereum/contracts';
|
|
4
4
|
import { decryptBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
|
|
5
|
+
import { computeBn254G1PublicKey, computeBn254G2PublicKey } from '@aztec/foundation/crypto/bn254';
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
7
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
7
8
|
import type { LogFn } from '@aztec/foundation/log';
|
|
8
9
|
import { loadKeystoreFile } from '@aztec/node-keystore/loader';
|
|
9
10
|
import type {
|
|
@@ -272,7 +273,7 @@ export async function generateStakerJson(options: StakerOptions, log: LogFn): Pr
|
|
|
272
273
|
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
273
274
|
const publicClient = createPublicClient({
|
|
274
275
|
chain: chain.chainInfo,
|
|
275
|
-
transport: fallback(l1RpcUrls.map(url => http(url))),
|
|
276
|
+
transport: fallback(l1RpcUrls.map(url => http(url, { batch: false }))),
|
|
276
277
|
});
|
|
277
278
|
const gse = new GSEContract(publicClient, gseAddress);
|
|
278
279
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { ethPrivateKeySchema } from '@aztec/node-keystore/schemas';
|
|
3
|
+
import type { EthPrivateKey } from '@aztec/node-keystore/types';
|
|
3
4
|
|
|
4
5
|
export const defaultBlsPath = 'm/12381/3600/0/0/0';
|
|
5
6
|
|
|
@@ -78,3 +79,46 @@ export function validatePublisherOptions(options: { publishers?: string[]; publi
|
|
|
78
79
|
options.publishers = normalizedKeys as EthPrivateKey[];
|
|
79
80
|
}
|
|
80
81
|
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Validates and normalizes the `--funding-account` option in place. The value may be a private key
|
|
85
|
+
* (used as a local signer) or an ETH address. An address needs a remote signer to sign funding txs:
|
|
86
|
+
* either `--remote-signer`, or a keystore that already defines one (pass `hasKeystoreRemoteSigner`),
|
|
87
|
+
* which a bare address inherits at runtime.
|
|
88
|
+
*/
|
|
89
|
+
export function validateFundingAccountOptions(
|
|
90
|
+
options: { fundingAccount?: string; remoteSigner?: string },
|
|
91
|
+
hasKeystoreRemoteSigner = false,
|
|
92
|
+
) {
|
|
93
|
+
if (!options.fundingAccount) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let value = options.fundingAccount.trim();
|
|
98
|
+
if (!value.startsWith('0x')) {
|
|
99
|
+
value = '0x' + value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (value.length === 66) {
|
|
103
|
+
try {
|
|
104
|
+
ethPrivateKeySchema.parse(value);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
throw new Error(`Invalid funding account private key: ${error instanceof Error ? error.message : String(error)}`);
|
|
107
|
+
}
|
|
108
|
+
} else if (value.length === 42) {
|
|
109
|
+
try {
|
|
110
|
+
EthAddress.fromString(value);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
throw new Error(`Invalid funding account address: ${error instanceof Error ? error.message : String(error)}`);
|
|
113
|
+
}
|
|
114
|
+
if (!options.remoteSigner && !hasKeystoreRemoteSigner) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
'--funding-account as an address requires --remote-signer, or a keystore that already defines a remote signer',
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
throw new Error('Invalid funding account: expected a 32-byte private key or a 20-byte address');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
options.fundingAccount = value;
|
|
124
|
+
}
|