@aztec/cli 0.0.1-commit.2ed92850 → 0.0.1-commit.2f68f620
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_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 +13 -3
- 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 +8 -3
- 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 +1 -1
- package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts.map +1 -1
- package/dest/cmds/l1/deploy_l1_contracts_cmd.js +0 -1
- package/dest/cmds/l1/deploy_new_rollup.d.ts +1 -1
- package/dest/cmds/l1/deploy_new_rollup.d.ts.map +1 -1
- package/dest/cmds/l1/deploy_new_rollup.js +2 -4
- package/dest/cmds/l1/index.d.ts +1 -1
- package/dest/cmds/l1/index.d.ts.map +1 -1
- package/dest/cmds/l1/index.js +4 -0
- package/dest/cmds/l1/update_l1_validators.d.ts +1 -1
- package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
- package/dest/cmds/l1/update_l1_validators.js +5 -6
- 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/index.d.ts +1 -1
- package/dest/cmds/validator_keys/index.d.ts.map +1 -1
- package/dest/cmds/validator_keys/index.js +2 -1
- package/dest/cmds/validator_keys/new.d.ts +6 -1
- package/dest/cmds/validator_keys/new.d.ts.map +1 -1
- package/dest/cmds/validator_keys/new.js +78 -8
- package/dest/cmds/validator_keys/shared.d.ts +1 -1
- package/dest/cmds/validator_keys/shared.d.ts.map +1 -1
- package/dest/cmds/validator_keys/shared.js +66 -23
- 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 +1 -1
- package/dest/config/chain_l2_config.d.ts.map +1 -1
- package/dest/config/chain_l2_config.js +3 -1
- package/dest/config/generated/networks.d.ts +68 -52
- package/dest/config/generated/networks.d.ts.map +1 -1
- package/dest/config/generated/networks.js +69 -53
- package/dest/config/network_config.d.ts +1 -1
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +6 -2
- package/dest/utils/aztec.d.ts +1 -2
- package/dest/utils/aztec.d.ts.map +1 -1
- package/dest/utils/aztec.js +2 -3
- package/dest/utils/commands.d.ts +14 -6
- package/dest/utils/commands.d.ts.map +1 -1
- package/dest/utils/commands.js +19 -9
- package/dest/utils/inspect.d.ts +1 -1
- package/dest/utils/inspect.d.ts.map +1 -1
- package/dest/utils/inspect.js +11 -11
- package/package.json +30 -30
- package/src/cmds/aztec_node/block_number.ts +1 -1
- 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 +13 -8
- package/src/cmds/infrastructure/setup_l2_contract.ts +8 -3
- package/src/cmds/l1/compute_genesis_values.ts +29 -0
- package/src/cmds/l1/deploy_l1_contracts_cmd.ts +0 -1
- package/src/cmds/l1/deploy_new_rollup.ts +1 -3
- package/src/cmds/l1/index.ts +18 -0
- package/src/cmds/l1/update_l1_validators.ts +5 -6
- package/src/cmds/validator_keys/eth_json_v3_worker.ts +30 -0
- package/src/cmds/validator_keys/index.ts +18 -4
- package/src/cmds/validator_keys/new.ts +107 -8
- package/src/cmds/validator_keys/shared.ts +86 -34
- package/src/config/cached_fetch.ts +119 -31
- package/src/config/chain_l2_config.ts +3 -1
- package/src/config/generated/networks.ts +67 -51
- package/src/config/network_config.ts +6 -2
- package/src/utils/aztec.ts +12 -18
- package/src/utils/commands.ts +22 -9
- package/src/utils/inspect.ts +7 -8
|
@@ -2,13 +2,74 @@ import { prettyPrintJSON } from '@aztec/cli/utils';
|
|
|
2
2
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
3
|
import { GSEContract } from '@aztec/ethereum/contracts';
|
|
4
4
|
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
5
|
-
import { writeFile } from 'fs/promises';
|
|
5
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
6
6
|
import { basename, dirname, join } from 'path';
|
|
7
7
|
import { createPublicClient, fallback, http } from 'viem';
|
|
8
8
|
import { generateMnemonic, mnemonicToAccount } from 'viem/accounts';
|
|
9
9
|
import { buildValidatorEntries, logValidatorSummaries, maybePrintJson, resolveKeystoreOutputPath, writeBlsBn254ToFile, writeEthJsonV3ToFile, writeKeystoreFile } from './shared.js';
|
|
10
10
|
import { processAttesterAccounts } from './staker.js';
|
|
11
11
|
import { validateBlsPathOptions, validatePublisherOptions, validateRemoteSignerOptions, validateStakerOutputOptions } from './utils.js';
|
|
12
|
+
function validatePassword(password, source) {
|
|
13
|
+
if (password.length === 0) {
|
|
14
|
+
throw new Error(`${source} cannot be empty`);
|
|
15
|
+
}
|
|
16
|
+
return password;
|
|
17
|
+
}
|
|
18
|
+
function stripOneTrailingNewline(password) {
|
|
19
|
+
if (password.endsWith('\n')) {
|
|
20
|
+
password = password.slice(0, -1);
|
|
21
|
+
}
|
|
22
|
+
if (password.endsWith('\r')) {
|
|
23
|
+
password = password.slice(0, -1);
|
|
24
|
+
}
|
|
25
|
+
return password;
|
|
26
|
+
}
|
|
27
|
+
async function resolvePasswordSource(source) {
|
|
28
|
+
if (source.password !== undefined && source.passwordFile !== undefined) {
|
|
29
|
+
throw new Error(`${source.passwordOption} and ${source.passwordFileOption} cannot be used together`);
|
|
30
|
+
}
|
|
31
|
+
if (source.password !== undefined) {
|
|
32
|
+
return validatePassword(source.password, source.passwordOption);
|
|
33
|
+
}
|
|
34
|
+
if (source.passwordFile !== undefined) {
|
|
35
|
+
if (source.passwordFile.length === 0) {
|
|
36
|
+
throw new Error(`${source.passwordFileOption} cannot be empty`);
|
|
37
|
+
}
|
|
38
|
+
const password = stripOneTrailingNewline(await readFile(source.passwordFile, 'utf-8'));
|
|
39
|
+
return validatePassword(password, source.passwordFileOption);
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
async function resolvePasswords(options) {
|
|
44
|
+
const sharedPassword = await resolvePasswordSource({
|
|
45
|
+
password: options.password,
|
|
46
|
+
passwordFile: options.passwordFile,
|
|
47
|
+
passwordOption: '--password',
|
|
48
|
+
passwordFileOption: '--password-file'
|
|
49
|
+
});
|
|
50
|
+
const ethPassword = await resolvePasswordSource({
|
|
51
|
+
password: options.ethPassword,
|
|
52
|
+
passwordFile: options.ethPasswordFile,
|
|
53
|
+
passwordOption: '--eth-password',
|
|
54
|
+
passwordFileOption: '--eth-password-file'
|
|
55
|
+
}) ?? sharedPassword;
|
|
56
|
+
const blsPassword = await resolvePasswordSource({
|
|
57
|
+
password: options.blsPassword,
|
|
58
|
+
passwordFile: options.blsPasswordFile,
|
|
59
|
+
passwordOption: '--bls-password',
|
|
60
|
+
passwordFileOption: '--bls-password-file'
|
|
61
|
+
}) ?? sharedPassword;
|
|
62
|
+
if (ethPassword === undefined && blsPassword === undefined) {
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
if (ethPassword === undefined || blsPassword === undefined) {
|
|
66
|
+
throw new Error('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.');
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
ethPassword,
|
|
70
|
+
blsPassword
|
|
71
|
+
};
|
|
72
|
+
}
|
|
12
73
|
export async function newValidatorKeystore(options, log) {
|
|
13
74
|
// validate bls-path inputs before proceeding with key generation
|
|
14
75
|
validateBlsPathOptions(options);
|
|
@@ -18,9 +79,18 @@ export async function newValidatorKeystore(options, log) {
|
|
|
18
79
|
validatePublisherOptions(options);
|
|
19
80
|
// validate remote signer options
|
|
20
81
|
validateRemoteSignerOptions(options);
|
|
21
|
-
const { dataDir, file, count, publisherCount = 0, publishers, json, coinbase, accountIndex = 0, addressIndex = 0, feeRecipient, remoteSigner, blsPath, ikm, mnemonic: _mnemonic, password, encryptedKeystoreDir, stakerOutput, gseAddress, l1RpcUrls, l1ChainId } = options;
|
|
82
|
+
const { dataDir, file, count, publisherCount = 0, publishers, json, coinbase, accountIndex = 0, addressIndex = 0, feeRecipient, remoteSigner, blsPath, ikm, mnemonic: _mnemonic, password: passwordOption, passwordFile, ethPassword: ethPasswordOption, ethPasswordFile, blsPassword: blsPasswordOption, blsPasswordFile, encryptedKeystoreDir, stakerOutput, gseAddress, l1RpcUrls, l1ChainId } = options;
|
|
83
|
+
const { ethPassword, blsPassword } = await resolvePasswords({
|
|
84
|
+
password: passwordOption,
|
|
85
|
+
passwordFile,
|
|
86
|
+
ethPassword: ethPasswordOption,
|
|
87
|
+
ethPasswordFile,
|
|
88
|
+
blsPassword: blsPasswordOption,
|
|
89
|
+
blsPasswordFile
|
|
90
|
+
});
|
|
91
|
+
const shouldEncryptKeystores = ethPassword !== undefined && blsPassword !== undefined;
|
|
22
92
|
const mnemonic = _mnemonic ?? generateMnemonic(wordlist);
|
|
23
|
-
if (!_mnemonic && !json) {
|
|
93
|
+
if (!_mnemonic && !json && !shouldEncryptKeystores) {
|
|
24
94
|
log('No mnemonic provided, generating new one...');
|
|
25
95
|
log(`Using new mnemonic:`);
|
|
26
96
|
log('');
|
|
@@ -44,15 +114,15 @@ export async function newValidatorKeystore(options, log) {
|
|
|
44
114
|
remoteSigner
|
|
45
115
|
});
|
|
46
116
|
// If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
|
|
47
|
-
if (
|
|
117
|
+
if (shouldEncryptKeystores) {
|
|
48
118
|
const encryptedKeystoreOutDir = encryptedKeystoreDir && encryptedKeystoreDir.length > 0 ? encryptedKeystoreDir : keystoreOutDir;
|
|
49
119
|
await writeEthJsonV3ToFile(validators, {
|
|
50
120
|
outDir: encryptedKeystoreOutDir,
|
|
51
|
-
password
|
|
121
|
+
password: ethPassword
|
|
52
122
|
});
|
|
53
123
|
await writeBlsBn254ToFile(validators, {
|
|
54
124
|
outDir: encryptedKeystoreOutDir,
|
|
55
|
-
password
|
|
125
|
+
password: blsPassword
|
|
56
126
|
});
|
|
57
127
|
}
|
|
58
128
|
const keystore = {
|
|
@@ -76,7 +146,7 @@ export async function newValidatorKeystore(options, log) {
|
|
|
76
146
|
// Process each validator
|
|
77
147
|
for(let i = 0; i < validators.length; i++){
|
|
78
148
|
const validator = validators[i];
|
|
79
|
-
const outputs = await processAttesterAccounts(validator.attester, gse
|
|
149
|
+
const outputs = await processAttesterAccounts(validator.attester, gse);
|
|
80
150
|
// Collect all staker outputs
|
|
81
151
|
for(let j = 0; j < outputs.length; j++){
|
|
82
152
|
allStakerOutputs.push(outputs[j]);
|
|
@@ -88,7 +158,7 @@ export async function newValidatorKeystore(options, log) {
|
|
|
88
158
|
await writeFile(stakerOutputPath, prettyPrintJSON(allStakerOutputs), 'utf-8');
|
|
89
159
|
}
|
|
90
160
|
}
|
|
91
|
-
const outputData = !_mnemonic ? {
|
|
161
|
+
const outputData = !_mnemonic && !shouldEncryptKeystores ? {
|
|
92
162
|
...keystore,
|
|
93
163
|
generatedMnemonic: mnemonic
|
|
94
164
|
} : keystore;
|
|
@@ -65,4 +65,4 @@ export declare function writeEthJsonV3ToFile(validators: ValidatorKeyStore[], op
|
|
|
65
65
|
outDir: string;
|
|
66
66
|
password: string;
|
|
67
67
|
}): Promise<void>;
|
|
68
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
68
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2hhcmVkLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY21kcy92YWxpZGF0b3Jfa2V5cy9zaGFyZWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBS0EsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDaEUsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLGFBQWEsRUFBRSxpQkFBaUIsRUFBRSxNQUFNLDRCQUE0QixDQUFDO0FBQy9GLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBMkRoRSxNQUFNLE1BQU0sZ0JBQWdCLEdBQUc7SUFBRSxXQUFXLENBQUMsRUFBRSxNQUFNLENBQUM7SUFBQyxXQUFXLENBQUMsRUFBRSxNQUFNLENBQUM7SUFBQyxZQUFZLENBQUMsRUFBRSxNQUFNLEVBQUUsQ0FBQTtDQUFFLENBQUM7QUFFdkcsTUFBTSxNQUFNLG9CQUFvQixHQUFHO0lBQ2pDLGNBQWMsRUFBRSxNQUFNLENBQUM7SUFDdkIsY0FBYyxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ3hCLFVBQVUsQ0FBQyxFQUFFLE1BQU0sRUFBRSxDQUFDO0lBQ3RCLFlBQVksRUFBRSxNQUFNLENBQUM7SUFDckIsZ0JB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FPLENBQUMsSUFBSSxDQUFDLENBeUNmIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/shared.ts"],"names":[],"mappings":"AAKA,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;AA2DhE,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,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,GAAE,MAAU,EAAE,YAAY,GAAE,MAAU,UAqBlG;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,CAAC,aAAa,E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,OAAO,CAAC,MAAM,CAAC,CAOjB;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,CAyCf"}
|
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
import { prettyPrintJSON } from '@aztec/cli/utils';
|
|
2
|
+
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
2
3
|
import { deriveBlsPrivateKey } from '@aztec/foundation/crypto/bls';
|
|
3
4
|
import { createBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
|
|
4
5
|
import { computeBn254G1PublicKeyCompressed } from '@aztec/foundation/crypto/bn254';
|
|
5
6
|
import { Wallet } from '@ethersproject/wallet';
|
|
6
7
|
import { constants as fsConstants, mkdirSync } from 'fs';
|
|
7
8
|
import { access, writeFile } from 'fs/promises';
|
|
8
|
-
import { homedir } from 'os';
|
|
9
|
+
import { availableParallelism, homedir } from 'os';
|
|
9
10
|
import { dirname, isAbsolute, join } from 'path';
|
|
10
11
|
import { mnemonicToAccount } from 'viem/accounts';
|
|
12
|
+
import { Worker } from 'worker_threads';
|
|
11
13
|
import { defaultBlsPath } from './utils.js';
|
|
14
|
+
// ethers' default scrypt parameters use substantial memory, so keep worker fan-out bounded.
|
|
15
|
+
const maxEthKeystoreWorkers = Math.max(1, Math.min(4, availableParallelism()));
|
|
16
|
+
function deserializeWorkerError(error) {
|
|
17
|
+
const result = new Error(error.message);
|
|
18
|
+
result.name = error.name ?? result.name;
|
|
19
|
+
result.stack = error.stack;
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
function encryptEthJsonV3InWorker(privateKeyHex, password) {
|
|
23
|
+
return new Promise((resolve, reject)=>{
|
|
24
|
+
const worker = new Worker(new URL('./eth_json_v3_worker.js', import.meta.url), {
|
|
25
|
+
workerData: {
|
|
26
|
+
privateKeyHex,
|
|
27
|
+
password
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
let settled = false;
|
|
31
|
+
worker.once('message', (result)=>{
|
|
32
|
+
settled = true;
|
|
33
|
+
if ('json' in result) {
|
|
34
|
+
resolve(result.json);
|
|
35
|
+
} else {
|
|
36
|
+
reject(deserializeWorkerError(result.error));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
worker.once('error', (error)=>{
|
|
40
|
+
settled = true;
|
|
41
|
+
reject(error);
|
|
42
|
+
});
|
|
43
|
+
worker.once('exit', (code)=>{
|
|
44
|
+
if (!settled) {
|
|
45
|
+
reject(new Error(`ETH JSON V3 worker stopped with exit code ${code}`));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async function encryptEthJsonV3(privateKeyHex, password) {
|
|
51
|
+
if (process.env.JEST_WORKER_ID !== undefined) {
|
|
52
|
+
return await new Wallet(privateKeyHex).encrypt(password);
|
|
53
|
+
}
|
|
54
|
+
return await encryptEthJsonV3InWorker(privateKeyHex, password);
|
|
55
|
+
}
|
|
12
56
|
export function withValidatorIndex(path, accountIndex = 0, addressIndex = 0) {
|
|
13
57
|
// NOTE: The legacy BLS CLI is to allow users who generated keys in 2.1.4 to be able to use the same command
|
|
14
58
|
// to re-generate their keys. In 2.1.5 we switched how we append addresses to the path so this is to maintain backwards compatibility.
|
|
@@ -188,7 +232,7 @@ export function maybePrintJson(log, jsonFlag, obj) {
|
|
|
188
232
|
mkdirSync(outDir, {
|
|
189
233
|
recursive: true
|
|
190
234
|
});
|
|
191
|
-
const keystore = createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath);
|
|
235
|
+
const keystore = await createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath);
|
|
192
236
|
const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
193
237
|
const outPath = join(outDir, `keystore-${safeBase}.json`);
|
|
194
238
|
await writeFile(outPath, JSON.stringify(keystore, null, 2), {
|
|
@@ -197,16 +241,15 @@ export function maybePrintJson(log, jsonFlag, obj) {
|
|
|
197
241
|
return outPath;
|
|
198
242
|
}
|
|
199
243
|
/** Replace plaintext BLS keys in validators with { path, password } pointing to BN254 keystore files. */ export async function writeBlsBn254ToFile(validators, options) {
|
|
200
|
-
|
|
201
|
-
const v = validators[i];
|
|
244
|
+
await Promise.all(validators.map(async (v, i)=>{
|
|
202
245
|
if (!v || typeof v !== 'object' || !('attester' in v)) {
|
|
203
|
-
|
|
246
|
+
return;
|
|
204
247
|
}
|
|
205
248
|
const att = v.attester;
|
|
206
249
|
// Shapes: { bls: <hex> } or { eth: <ethAccount>, bls?: <hex> } or plain EthAccount
|
|
207
250
|
const blsKey = typeof att === 'object' && 'bls' in att ? att.bls : undefined;
|
|
208
251
|
if (!blsKey || typeof blsKey !== 'string') {
|
|
209
|
-
|
|
252
|
+
return;
|
|
210
253
|
}
|
|
211
254
|
const pub = await computeBlsPublicKeyCompressed(blsKey);
|
|
212
255
|
const path = options.blsPath ?? defaultBlsPath;
|
|
@@ -218,15 +261,14 @@ export function maybePrintJson(log, jsonFlag, obj) {
|
|
|
218
261
|
password: options.password
|
|
219
262
|
};
|
|
220
263
|
}
|
|
221
|
-
}
|
|
264
|
+
}));
|
|
222
265
|
}
|
|
223
266
|
/** Writes an Ethereum JSON V3 keystore using ethers, returns absolute path */ export async function writeEthJsonV3Keystore(outDir, fileNameBase, password, privateKeyHex) {
|
|
224
267
|
const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
225
268
|
mkdirSync(outDir, {
|
|
226
269
|
recursive: true
|
|
227
270
|
});
|
|
228
|
-
const
|
|
229
|
-
const json = await wallet.encrypt(password);
|
|
271
|
+
const json = await encryptEthJsonV3(privateKeyHex, password);
|
|
230
272
|
const outPath = join(outDir, `keystore-eth-${safeBase}.json`);
|
|
231
273
|
await writeFile(outPath, json, {
|
|
232
274
|
encoding: 'utf-8'
|
|
@@ -234,16 +276,18 @@ export function maybePrintJson(log, jsonFlag, obj) {
|
|
|
234
276
|
return outPath;
|
|
235
277
|
}
|
|
236
278
|
/** Replace plaintext ETH keys in validators with { path, password } pointing to JSON V3 files. */ export async function writeEthJsonV3ToFile(validators, options) {
|
|
237
|
-
const
|
|
279
|
+
const tasks = [];
|
|
280
|
+
const maybeQueueEncryptEth = (account, label, setEncryptedAccount)=>{
|
|
238
281
|
if (typeof account === 'string' && account.startsWith('0x') && account.length === 66) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
282
|
+
tasks.push(async ()=>{
|
|
283
|
+
const fileBase = `${label}_${account.slice(2, 10)}`;
|
|
284
|
+
const path = await writeEthJsonV3Keystore(options.outDir, fileBase, options.password, account);
|
|
285
|
+
setEncryptedAccount({
|
|
286
|
+
path,
|
|
287
|
+
password: options.password
|
|
288
|
+
});
|
|
289
|
+
});
|
|
245
290
|
}
|
|
246
|
-
return account;
|
|
247
291
|
};
|
|
248
292
|
for(let i = 0; i < validators.length; i++){
|
|
249
293
|
const v = validators[i];
|
|
@@ -253,22 +297,21 @@ export function maybePrintJson(log, jsonFlag, obj) {
|
|
|
253
297
|
// attester may be string (eth), object with eth, or remote signer
|
|
254
298
|
const att = v.attester;
|
|
255
299
|
if (typeof att === 'string') {
|
|
256
|
-
|
|
300
|
+
maybeQueueEncryptEth(att, `attester_${i + 1}`, (account)=>v.attester = account);
|
|
257
301
|
} else if (att && typeof att === 'object' && 'eth' in att) {
|
|
258
|
-
|
|
302
|
+
maybeQueueEncryptEth(att.eth, `attester_${i + 1}`, (account)=>att.eth = account);
|
|
259
303
|
}
|
|
260
304
|
// publisher can be single or array
|
|
261
305
|
if ('publisher' in v) {
|
|
262
306
|
const pub = v.publisher;
|
|
263
307
|
if (Array.isArray(pub)) {
|
|
264
|
-
const out = [];
|
|
265
308
|
for(let j = 0; j < pub.length; j++){
|
|
266
|
-
|
|
309
|
+
maybeQueueEncryptEth(pub[j], `publisher_${i + 1}_${j + 1}`, (account)=>pub[j] = account);
|
|
267
310
|
}
|
|
268
|
-
v.publisher = out;
|
|
269
311
|
} else if (pub !== undefined) {
|
|
270
|
-
|
|
312
|
+
maybeQueueEncryptEth(pub, `publisher_${i + 1}`, (account)=>v.publisher = account);
|
|
271
313
|
}
|
|
272
314
|
}
|
|
273
315
|
}
|
|
316
|
+
await asyncPool(maxEthKeystoreWorkers, tasks, (task)=>task());
|
|
274
317
|
}
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
export interface CachedFetchOptions {
|
|
2
|
-
/**
|
|
3
|
-
cacheDurationMs: number;
|
|
4
|
-
/** The cache file */
|
|
2
|
+
/** The cache file path for storing data. If not provided, no caching is performed. */
|
|
5
3
|
cacheFile?: string;
|
|
4
|
+
/** Fallback max-age in milliseconds when server sends no Cache-Control header. Defaults to 5 minutes. */
|
|
5
|
+
defaultMaxAgeMs?: number;
|
|
6
6
|
}
|
|
7
|
+
/** Extracts max-age value in milliseconds from a Response's Cache-Control header. Returns undefined if not present. */
|
|
8
|
+
export declare function parseMaxAge(response: {
|
|
9
|
+
headers: {
|
|
10
|
+
get(name: string): string | null;
|
|
11
|
+
};
|
|
12
|
+
}): number | undefined;
|
|
7
13
|
/**
|
|
8
|
-
* Fetches data from a URL with file-based caching
|
|
9
|
-
*
|
|
14
|
+
* Fetches data from a URL with file-based HTTP conditional caching.
|
|
15
|
+
*
|
|
16
|
+
* Data is stored as raw JSON in the cache file (same format as the server returns).
|
|
17
|
+
* Caching metadata (ETag, expiry) is stored in a separate sidecar `.meta` file.
|
|
18
|
+
* This keeps the data file human-readable and backward-compatible with older code.
|
|
10
19
|
*
|
|
11
20
|
* @param url - The URL to fetch from
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @returns The fetched and parsed JSON data, or undefined if fetch fails
|
|
21
|
+
* @param options - Caching options
|
|
22
|
+
* @param fetch - Fetch implementation (defaults to globalThis.fetch)
|
|
23
|
+
* @param log - Logger instance
|
|
24
|
+
* @returns The fetched and parsed JSON data, or undefined if fetch fails
|
|
16
25
|
*/
|
|
17
26
|
export declare function cachedFetch<T = any>(url: string, options: CachedFetchOptions, fetch?: typeof globalThis.fetch, log?: import("@aztec/aztec.js/log").Logger): Promise<T | undefined>;
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FjaGVkX2ZldGNoLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uZmlnL2NhY2hlZF9mZXRjaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFLQSxNQUFNLFdBQVcsa0JBQWtCO0lBQ2pDLHNGQUFzRjtJQUN0RixTQUFTLENBQUMsRUFBRSxNQUFNLENBQUM7SUFDbkIseUdBQXlHO0lBQ3pHLGVBQWUsQ0FBQyxFQUFFLE1BQU0sQ0FBQztDQUMxQjtBQVVELHVIQUF1SDtBQUN2SCx3QkFBZ0IsV0FBVyxDQUFDLFFBQVEsRUFBRTtJQUFFLE9BQU8sRUFBRTtRQUFFLEdBQUcsQ0FBQyxJQUFJLEVBQUUsTUFBTSxHQUFHLE1BQU0sR0FBRyxJQUFJLENBQUE7S0FBRSxDQUFBO0NBQUUsR0FBRyxNQUFNLEdBQUcsU0FBUyxDQVUzRztBQUVEOzs7Ozs7Ozs7Ozs7R0FZRztBQUNILHdCQUFzQixXQUFXLENBQUMsQ0FBQyxHQUFHLEdBQUcsRUFDdkMsR0FBRyxFQUFFLE1BQU0sRUFDWCxPQUFPLEVBQUUsa0JBQWtCLEVBQzNCLEtBQUssMEJBQW1CLEVBQ3hCLEdBQUcsdUNBQStCLEdBQ2pDLE9BQU8sQ0FBQyxDQUFDLEdBQUcsU0FBUyxDQUFDLENBb0V4QiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached_fetch.d.ts","sourceRoot":"","sources":["../../src/config/cached_fetch.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,kBAAkB;IACjC,
|
|
1
|
+
{"version":3,"file":"cached_fetch.d.ts","sourceRoot":"","sources":["../../src/config/cached_fetch.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yGAAyG;IACzG,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAUD,uHAAuH;AACvH,wBAAgB,WAAW,CAAC,QAAQ,EAAE;IAAE,OAAO,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,GAAG,MAAM,GAAG,SAAS,CAU3G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAAC,CAAC,GAAG,GAAG,EACvC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,kBAAkB,EAC3B,KAAK,0BAAmB,EACxB,GAAG,uCAA+B,GACjC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAoExB"}
|
|
@@ -1,50 +1,105 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
-
import { mkdir, readFile,
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'fs/promises';
|
|
3
3
|
import { dirname } from 'path';
|
|
4
|
+
const DEFAULT_MAX_AGE_MS = 5 * 60 * 1000; // 5 minutes
|
|
5
|
+
/** Extracts max-age value in milliseconds from a Response's Cache-Control header. Returns undefined if not present. */ export function parseMaxAge(response) {
|
|
6
|
+
const cacheControl = response.headers.get('cache-control');
|
|
7
|
+
if (!cacheControl) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const match = cacheControl.match(/max-age=(\d+)/);
|
|
11
|
+
if (!match) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return parseInt(match[1], 10) * 1000;
|
|
15
|
+
}
|
|
4
16
|
/**
|
|
5
|
-
* Fetches data from a URL with file-based caching
|
|
6
|
-
*
|
|
17
|
+
* Fetches data from a URL with file-based HTTP conditional caching.
|
|
18
|
+
*
|
|
19
|
+
* Data is stored as raw JSON in the cache file (same format as the server returns).
|
|
20
|
+
* Caching metadata (ETag, expiry) is stored in a separate sidecar `.meta` file.
|
|
21
|
+
* This keeps the data file human-readable and backward-compatible with older code.
|
|
7
22
|
*
|
|
8
23
|
* @param url - The URL to fetch from
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @returns The fetched and parsed JSON data, or undefined if fetch fails
|
|
24
|
+
* @param options - Caching options
|
|
25
|
+
* @param fetch - Fetch implementation (defaults to globalThis.fetch)
|
|
26
|
+
* @param log - Logger instance
|
|
27
|
+
* @returns The fetched and parsed JSON data, or undefined if fetch fails
|
|
13
28
|
*/ export async function cachedFetch(url, options, fetch = globalThis.fetch, log = createLogger('cached_fetch')) {
|
|
14
|
-
const {
|
|
15
|
-
//
|
|
29
|
+
const { cacheFile, defaultMaxAgeMs = DEFAULT_MAX_AGE_MS } = options;
|
|
30
|
+
// If no cacheFile, just fetch normally without caching
|
|
31
|
+
if (!cacheFile) {
|
|
32
|
+
return fetchAndParse(url, fetch, log);
|
|
33
|
+
}
|
|
34
|
+
const metaFile = cacheFile + '.meta';
|
|
35
|
+
// Try to read metadata
|
|
36
|
+
let meta;
|
|
16
37
|
try {
|
|
17
|
-
|
|
18
|
-
const info = await stat(cacheFile);
|
|
19
|
-
if (info.mtimeMs + cacheDurationMs > Date.now()) {
|
|
20
|
-
const cachedData = JSON.parse(await readFile(cacheFile, 'utf-8'));
|
|
21
|
-
return cachedData;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
38
|
+
meta = JSON.parse(await readFile(metaFile, 'utf-8'));
|
|
24
39
|
} catch {
|
|
25
|
-
log.trace('
|
|
40
|
+
log.trace('No usable cache metadata found');
|
|
26
41
|
}
|
|
42
|
+
// Try to read cached data
|
|
43
|
+
let cachedData;
|
|
27
44
|
try {
|
|
28
|
-
|
|
45
|
+
cachedData = JSON.parse(await readFile(cacheFile, 'utf-8'));
|
|
46
|
+
} catch {
|
|
47
|
+
log.trace('No usable cached data found');
|
|
48
|
+
}
|
|
49
|
+
// If metadata and data exist and cache is fresh, return directly
|
|
50
|
+
if (meta && cachedData !== undefined && meta.expiresAt > Date.now()) {
|
|
51
|
+
return cachedData;
|
|
52
|
+
}
|
|
53
|
+
// Cache is stale or missing — make a (possibly conditional) request
|
|
54
|
+
try {
|
|
55
|
+
const headers = {};
|
|
56
|
+
if (meta?.etag && cachedData !== undefined) {
|
|
57
|
+
headers['If-None-Match'] = meta.etag;
|
|
58
|
+
}
|
|
59
|
+
const response = await fetch(url, {
|
|
60
|
+
headers
|
|
61
|
+
});
|
|
62
|
+
if (response.status === 304 && cachedData !== undefined) {
|
|
63
|
+
// Not modified — recompute expiry from new response headers and return cached data
|
|
64
|
+
const maxAgeMs = parseMaxAge(response) ?? defaultMaxAgeMs;
|
|
65
|
+
await writeMetaFile(metaFile, {
|
|
66
|
+
etag: meta?.etag,
|
|
67
|
+
expiresAt: Date.now() + maxAgeMs
|
|
68
|
+
}, log);
|
|
69
|
+
return cachedData;
|
|
70
|
+
}
|
|
29
71
|
if (!response.ok) {
|
|
30
72
|
log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
|
|
31
|
-
return
|
|
73
|
+
return cachedData;
|
|
32
74
|
}
|
|
75
|
+
// 200 — parse new data and cache it
|
|
33
76
|
const data = await response.json();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
err
|
|
45
|
-
});
|
|
46
|
-
}
|
|
77
|
+
const maxAgeMs = parseMaxAge(response) ?? defaultMaxAgeMs;
|
|
78
|
+
const etag = response.headers.get('etag') ?? undefined;
|
|
79
|
+
await ensureDir(cacheFile, log);
|
|
80
|
+
await Promise.all([
|
|
81
|
+
writeFile(cacheFile, JSON.stringify(data), 'utf-8'),
|
|
82
|
+
writeFile(metaFile, JSON.stringify({
|
|
83
|
+
etag,
|
|
84
|
+
expiresAt: Date.now() + maxAgeMs
|
|
85
|
+
}), 'utf-8')
|
|
86
|
+
]);
|
|
47
87
|
return data;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
log.warn(`Failed to fetch from ${url}`, {
|
|
90
|
+
err
|
|
91
|
+
});
|
|
92
|
+
return cachedData;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function fetchAndParse(url, fetch, log) {
|
|
96
|
+
try {
|
|
97
|
+
const response = await fetch(url);
|
|
98
|
+
if (!response.ok) {
|
|
99
|
+
log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
return await response.json();
|
|
48
103
|
} catch (err) {
|
|
49
104
|
log.warn(`Failed to fetch from ${url}`, {
|
|
50
105
|
err
|
|
@@ -52,3 +107,26 @@ import { dirname } from 'path';
|
|
|
52
107
|
return undefined;
|
|
53
108
|
}
|
|
54
109
|
}
|
|
110
|
+
async function ensureDir(filePath, log) {
|
|
111
|
+
try {
|
|
112
|
+
await mkdir(dirname(filePath), {
|
|
113
|
+
recursive: true
|
|
114
|
+
});
|
|
115
|
+
} catch (err) {
|
|
116
|
+
log.warn('Failed to create cache directory for: ' + filePath, {
|
|
117
|
+
err
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function writeMetaFile(metaFile, meta, log) {
|
|
122
|
+
try {
|
|
123
|
+
await mkdir(dirname(metaFile), {
|
|
124
|
+
recursive: true
|
|
125
|
+
});
|
|
126
|
+
await writeFile(metaFile, JSON.stringify(meta), 'utf-8');
|
|
127
|
+
} catch (err) {
|
|
128
|
+
log.warn('Failed to write cache metadata: ' + metaFile, {
|
|
129
|
+
err
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -11,4 +11,4 @@ import type { NetworkNames } from '@aztec/foundation/config';
|
|
|
11
11
|
* @param networkName - The network name
|
|
12
12
|
*/
|
|
13
13
|
export declare function enrichEnvironmentWithChainName(networkName: NetworkNames): void;
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhaW5fbDJfY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uZmlnL2NoYWluX2wyX2NvbmZpZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQTBCN0Q7Ozs7Ozs7Ozs7R0FVRztBQUNILHdCQUFnQiw4QkFBOEIsQ0FBQyxXQUFXLEVBQUUsWUFBWSxRQXFCdkUifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain_l2_config.d.ts","sourceRoot":"","sources":["../../src/config/chain_l2_config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AA0B7D;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"chain_l2_config.d.ts","sourceRoot":"","sources":["../../src/config/chain_l2_config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AA0B7D;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,YAAY,QAqBvE"}
|
|
@@ -34,7 +34,9 @@ function getDefaultDataDir(networkName) {
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
// Apply generated network config from defaults.yml
|
|
37
|
-
|
|
37
|
+
// For devnet iterations (v4-devnet-1, etc.), use the base devnet config
|
|
38
|
+
const configKey = /^v\d+-devnet-\d+$/.test(networkName) ? 'devnet' : networkName;
|
|
39
|
+
const generatedConfig = NetworkConfigs[configKey];
|
|
38
40
|
if (generatedConfig) {
|
|
39
41
|
enrichEnvironmentWithNetworkConfig(generatedConfig);
|
|
40
42
|
}
|