@aztec/cli 5.0.0-rc.2 → 5.0.1
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/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 +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 +98 -12
- 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 +100 -23
- 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 +34 -0
- package/dest/utils/commands.d.ts +7 -6
- package/dest/utils/commands.d.ts.map +1 -1
- package/dest/utils/commands.js +8 -7
- package/package.json +30 -30
- package/src/cmds/validator_keys/eth_json_v3_worker.ts +30 -0
- package/src/cmds/validator_keys/index.ts +48 -8
- package/src/cmds/validator_keys/new.ts +129 -9
- package/src/cmds/validator_keys/set_funding_account.ts +55 -0
- package/src/cmds/validator_keys/shared.ts +123 -35
- package/src/cmds/validator_keys/utils.ts +44 -1
- package/src/utils/commands.ts +12 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth_json_v3_worker.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/eth_json_v3_worker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Wallet } from '@ethersproject/wallet';
|
|
2
|
+
import { parentPort, workerData } from 'worker_threads';
|
|
3
|
+
function serializeError(error) {
|
|
4
|
+
if (error instanceof Error) {
|
|
5
|
+
return {
|
|
6
|
+
message: error.message,
|
|
7
|
+
name: error.name,
|
|
8
|
+
stack: error.stack
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
message: String(error)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
void (async ()=>{
|
|
16
|
+
try {
|
|
17
|
+
const { privateKeyHex, password } = workerData;
|
|
18
|
+
const json = await new Wallet(privateKeyHex).encrypt(password);
|
|
19
|
+
parentPort?.postMessage({
|
|
20
|
+
json
|
|
21
|
+
});
|
|
22
|
+
} catch (error) {
|
|
23
|
+
parentPort?.postMessage({
|
|
24
|
+
error: serializeError(error)
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { LogFn } from '@aztec/foundation/log';
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
export declare function injectCommands(program: Command, log: LogFn): Command;
|
|
4
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jbWRzL3ZhbGlkYXRvcl9rZXlzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLEtBQUssRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRW5ELE9BQU8sRUFBRSxPQUFPLEVBQVUsTUFBTSxXQUFXLENBQUM7QUFLNUMsd0JBQWdCLGNBQWMsQ0FBQyxPQUFPLEVBQUUsT0FBTyxFQUFFLEdBQUcsRUFBRSxLQUFLLFdBOEsxRCJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAK5C,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,WA8K1D"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Option } from 'commander';
|
|
1
2
|
import { parseAztecAddress, parseEthereumAddress, parseHex, parseOptionalInteger } from '../../utils/commands.js';
|
|
2
3
|
import { defaultBlsPath } from './utils.js';
|
|
3
4
|
export function injectCommands(program, log) {
|
|
@@ -5,18 +6,18 @@ export function injectCommands(program, log) {
|
|
|
5
6
|
'valKeys',
|
|
6
7
|
'valkeys'
|
|
7
8
|
]).description('Manage validator keystores for node operators');
|
|
8
|
-
group.command('new').summary('Generate a new validator keystore JSON').description('Generates a new validator keystore with ETH secp256k1 accounts and optional BLS accounts').option('--data-dir <path>', 'Directory to store keystore(s). Defaults to ~/.aztec/keystore').option('--file <name>', 'Keystore file name. Defaults to key1.json (or keyN.json if key1.json exists)').option('--count <N>', 'Number of validators to generate', parseOptionalInteger).option('--publisher-count <N>', 'Number of publisher accounts per validator (default 0)', (value)=>parseOptionalInteger(value, 0)).option('--publishers <privateKeys>', 'Comma-separated list of publisher private keys for all validators.', (value)=>value.split(',').map((key)=>key.trim())).option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation').option('--passphrase <str>', 'Optional passphrase for mnemonic').option('--account-index <N>', 'Base account index for ETH/BLS derivation', parseOptionalInteger).option('--address-index <N>', 'Base address index for ETH/BLS derivation', parseOptionalInteger).option('--coinbase <address>', 'Coinbase ETH address to use when proposing. Defaults to attester address.', parseEthereumAddress)
|
|
9
|
-
// .option('--funding-account <privateKey|address>', 'ETH private key (or address for remote signer setup) to fund publishers')
|
|
10
|
-
.option('--remote-signer <url>', 'Default remote signer URL for accounts in this file').option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', (value)=>parseHex(value, 32)).option('--bls-path <path>', `EIP-2334 path (default ${defaultBlsPath})`).option('--password <str>', 'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed').option('--encrypted-keystore-dir <dir>', 'Output directory for encrypted keystore file(s)').option('--json', 'Echo resulting JSON to stdout').option('--staker-output', 'Generate a single staker output JSON file with an array of validator entries').option('--gse-address <address>', 'GSE contract address (required with --staker-output)', parseEthereumAddress).option('--l1-rpc-urls <urls>', 'L1 RPC URLs (comma-separated, required with --staker-output)', (value)=>value.split(',')).option('-c, --l1-chain-id <number>', 'L1 chain ID (required with --staker-output)', (value)=>parseInt(value), 31337).requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress).action(async (options)=>{
|
|
9
|
+
group.command('new').summary('Generate a new validator keystore JSON').description('Generates a new validator keystore with ETH secp256k1 accounts and optional BLS accounts').option('--data-dir <path>', 'Directory to store keystore(s). Defaults to ~/.aztec/keystore').option('--file <name>', 'Keystore file name. Defaults to key1.json (or keyN.json if key1.json exists)').option('--count <N>', 'Number of validators to generate', parseOptionalInteger).option('--publisher-count <N>', 'Number of publisher accounts per validator (default 0)', (value)=>parseOptionalInteger(value, 0)).option('--publishers <privateKeys>', 'Comma-separated list of publisher private keys for all validators.', (value)=>value.split(',').map((key)=>key.trim())).option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation').option('--passphrase <str>', 'Optional passphrase for mnemonic').option('--account-index <N>', 'Base account index for ETH/BLS derivation', parseOptionalInteger).option('--address-index <N>', 'Base address index for ETH/BLS derivation', parseOptionalInteger).option('--coinbase <address>', 'Coinbase ETH address to use when proposing. Defaults to attester address.', parseEthereumAddress).option('--funding-account <privateKey|address>', 'ETH funding account used to top up publisher EOAs. Provide a private key, or an address together with --remote-signer.').option('--remote-signer <url>', 'Default remote signer URL for accounts in this file').option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', (value)=>parseHex(value, 32)).option('--bls-path <path>', `EIP-2334 path (default ${defaultBlsPath})`).addOption(new Option('--password <str>', 'Shared password for writing ETH JSON V3 and BLS EIP-2335 keystore files').env('AZTEC_KEYSTORE_PASSWORD')).option('--password-file <path>', 'File containing the shared password for writing keystore files').addOption(new Option('--eth-password <str>', 'Password for writing ETH JSON V3 keystore files').env('AZTEC_ETH_KEYSTORE_PASSWORD')).option('--eth-password-file <path>', 'File containing the password for writing ETH JSON V3 keystore files').addOption(new Option('--bls-password <str>', 'Password for writing BLS EIP-2335 keystore files').env('AZTEC_BLS_KEYSTORE_PASSWORD')).option('--bls-password-file <path>', 'File containing the password for writing BLS EIP-2335 keystore files').option('--encrypted-keystore-dir <dir>', 'Output directory for encrypted keystore file(s)').option('--json', 'Echo resulting JSON to stdout').option('--staker-output', 'Generate a single staker output JSON file with an array of validator entries').option('--gse-address <address>', 'GSE contract address (required with --staker-output)', parseEthereumAddress).option('--l1-rpc-urls <urls>', 'L1 RPC URLs (comma-separated, required with --staker-output)', (value)=>value.split(',')).option('-c, --l1-chain-id <number>', 'L1 chain ID (required with --staker-output)', (value)=>parseInt(value), 31337).requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress).action(async (options)=>{
|
|
11
10
|
const { newValidatorKeystore } = await import('./new.js');
|
|
12
11
|
await newValidatorKeystore(options, log);
|
|
13
12
|
});
|
|
14
|
-
group.command('add').summary('Augment an existing validator keystore JSON').description('Adds attester/publisher/BLS entries to an existing keystore using the same flags as new').argument('<existing>', 'Path to existing keystore JSON').option('--data-dir <path>', 'Directory where keystore(s) live. (default: ~/.aztec/keystore)').option('--file <name>', 'Override output file name. (default: key<N>.json)').option('--count <N>', 'Number of validators to add. (default: 1)', parseOptionalInteger).option('--publisher-count <N>', 'Number of publisher accounts per validator (default 0)', (value)=>parseOptionalInteger(value, 0)).option('--publishers <privateKeys>', 'Comma-separated list of publisher private keys for all validators.', (value)=>value.split(',').map((key)=>key.trim())).option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation').option('--passphrase <str>', 'Optional passphrase for mnemonic').option('--account-index <N>', 'Base account index for ETH/BLS derivation', parseOptionalInteger).option('--address-index <N>', 'Base address index for ETH/BLS derivation', parseOptionalInteger).option('--coinbase <address>', 'Coinbase ETH address to use when proposing. Defaults to attester address.', parseEthereumAddress)
|
|
15
|
-
// .option('--funding-account <privateKey|address>', 'ETH private key (or address for remote signer setup) to fund publishers')
|
|
16
|
-
.option('--remote-signer <url>', 'Default remote signer URL for accounts in this file').option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', (value)=>parseHex(value, 32)).option('--bls-path <path>', `EIP-2334 path (default ${defaultBlsPath})`).option('--empty', 'Generate an empty skeleton without keys').option('--password <str>', 'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed').option('--encrypted-keystore-dir <dir>', 'Output directory for encrypted keystore file(s)').option('--json', 'Echo resulting JSON to stdout').requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress).action(async (existing, options)=>{
|
|
13
|
+
group.command('add').summary('Augment an existing validator keystore JSON').description('Adds attester/publisher/BLS entries to an existing keystore using the same flags as new').argument('<existing>', 'Path to existing keystore JSON').option('--data-dir <path>', 'Directory where keystore(s) live. (default: ~/.aztec/keystore)').option('--file <name>', 'Override output file name. (default: key<N>.json)').option('--count <N>', 'Number of validators to add. (default: 1)', parseOptionalInteger).option('--publisher-count <N>', 'Number of publisher accounts per validator (default 0)', (value)=>parseOptionalInteger(value, 0)).option('--publishers <privateKeys>', 'Comma-separated list of publisher private keys for all validators.', (value)=>value.split(',').map((key)=>key.trim())).option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation').option('--passphrase <str>', 'Optional passphrase for mnemonic').option('--account-index <N>', 'Base account index for ETH/BLS derivation', parseOptionalInteger).option('--address-index <N>', 'Base address index for ETH/BLS derivation', parseOptionalInteger).option('--coinbase <address>', 'Coinbase ETH address to use when proposing. Defaults to attester address.', parseEthereumAddress).option('--remote-signer <url>', 'Default remote signer URL for accounts in this file').option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', (value)=>parseHex(value, 32)).option('--bls-path <path>', `EIP-2334 path (default ${defaultBlsPath})`).option('--empty', 'Generate an empty skeleton without keys').option('--password <str>', 'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed').option('--encrypted-keystore-dir <dir>', 'Output directory for encrypted keystore file(s)').option('--json', 'Echo resulting JSON to stdout').requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress).action(async (existing, options)=>{
|
|
17
14
|
const { addValidatorKeys } = await import('./add.js');
|
|
18
15
|
await addValidatorKeys(existing, options, log);
|
|
19
16
|
});
|
|
17
|
+
group.command('set-funding-account').summary('Set the funding account of an existing keystore').description('Sets the keystore-level ETH funding account used to top up publisher EOAs, replacing any existing one').argument('<existing>', 'Path to existing keystore JSON').argument('<privateKey|address>', 'Funding account: a private key, or an address (needs --remote-signer unless the keystore already defines one)').option('--remote-signer <url>', 'Remote signer URL for the funding account (required with an address unless the keystore already defines one)').option('--password <str>', 'Password for writing the funding key as an encrypted ETH JSON V3 file. Empty string allowed').option('--encrypted-keystore-dir <dir>', 'Output directory for the encrypted funding key file').option('--json', 'Echo resulting JSON to stdout').action(async (existing, fundingAccount, options)=>{
|
|
18
|
+
const { setFundingAccount } = await import('./set_funding_account.js');
|
|
19
|
+
await setFundingAccount(existing, fundingAccount, options, log);
|
|
20
|
+
});
|
|
20
21
|
group.command('staker').summary('Generate staking JSON from keystore').description('Reads a validator keystore and outputs staking data with BLS public keys for each attester (skips mnemonics)').requiredOption('--from <keystore>', 'Path to keystore JSON file').option('--password <password>', 'Password for decrypting encrypted keystores (if not specified in keystore file)').requiredOption('--gse-address <address>', 'GSE contract address', parseEthereumAddress).option('--l1-rpc-urls <urls>', 'L1 RPC URLs (comma-separated)', (value)=>value.split(','), [
|
|
21
22
|
'http://localhost:8545'
|
|
22
23
|
]).option('-c, --l1-chain-id <number>', 'L1 chain ID', (value)=>parseInt(value), 31337).option('--output <file>', 'Output file path (if not specified, JSON is written to stdout)').action(async (options)=>{
|
|
@@ -15,10 +15,16 @@ export type NewValidatorKeystoreOptions = {
|
|
|
15
15
|
ikm?: string;
|
|
16
16
|
blsPath?: string;
|
|
17
17
|
password?: string;
|
|
18
|
+
passwordFile?: string;
|
|
19
|
+
ethPassword?: string;
|
|
20
|
+
ethPasswordFile?: string;
|
|
21
|
+
blsPassword?: string;
|
|
22
|
+
blsPasswordFile?: string;
|
|
18
23
|
encryptedKeystoreDir?: string;
|
|
19
24
|
json?: boolean;
|
|
20
25
|
feeRecipient: AztecAddress;
|
|
21
26
|
coinbase?: EthAddress;
|
|
27
|
+
fundingAccount?: string;
|
|
22
28
|
remoteSigner?: string;
|
|
23
29
|
stakerOutput?: boolean;
|
|
24
30
|
gseAddress?: EthAddress;
|
|
@@ -26,4 +32,4 @@ export type NewValidatorKeystoreOptions = {
|
|
|
26
32
|
l1ChainId?: number;
|
|
27
33
|
};
|
|
28
34
|
export declare function newValidatorKeystore(options: NewValidatorKeystoreOptions, log: LogFn): Promise<void>;
|
|
29
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
35
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmV3LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY21kcy92YWxpZGF0b3Jfa2V5cy9uZXcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0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QUUsT0FBTyxDQUFDO0lBQ2YsWUFBWSxFQUFFLFlBQVksQ0FBQztJQUMzQixRQUFRLENBQUMsRUFBRSxVQUFVLENBQUM7SUFDdEIsY0FBYyxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ3hCLFlBQVksQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUN0QixZQUFZLENBQUMsRUFBRSxPQUFPLENBQUM7SUFDdkIsVUFBVSxDQUFDLEVBQUUsVUFBVSxDQUFDO0lBQ3hCLFNBQVMsQ0FBQyxFQUFFLE1BQU0sRUFBRSxDQUFDO0lBQ3JCLFNBQVMsQ0FBQyxFQUFFLE1BQU0sQ0FBQztDQUNwQixDQUFDO0FBa0ZGLHdCQUFzQixvQkFBb0IsQ0FBQyxPQUFPLEVBQUUsMkJBQTJCLEVBQUUsR0FBRyxFQUFFLEtBQUssaUJBc0wxRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/new.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/new.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AA4BhE,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAkFF,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,2BAA2B,EAAE,GAAG,EAAE,KAAK,iBAsL1F"}
|
|
@@ -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
|
-
import { generateMnemonic, mnemonicToAccount } from 'viem/accounts';
|
|
9
|
-
import { buildValidatorEntries, logValidatorSummaries, maybePrintJson, resolveKeystoreOutputPath, writeBlsBn254ToFile, writeEthJsonV3ToFile, writeKeystoreFile } from './shared.js';
|
|
8
|
+
import { generateMnemonic, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
9
|
+
import { buildValidatorEntries, encryptFundingAccountToFile, logValidatorSummaries, maybePrintJson, resolveFundingAccount, resolveKeystoreOutputPath, writeBlsBn254ToFile, writeEthJsonV3ToFile, writeKeystoreFile } from './shared.js';
|
|
10
10
|
import { processAttesterAccounts } from './staker.js';
|
|
11
|
-
import { validateBlsPathOptions, validatePublisherOptions, validateRemoteSignerOptions, validateStakerOutputOptions } from './utils.js';
|
|
11
|
+
import { validateBlsPathOptions, validateFundingAccountOptions, 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,20 @@ export async function newValidatorKeystore(options, log) {
|
|
|
18
79
|
validatePublisherOptions(options);
|
|
19
80
|
// validate remote signer options
|
|
20
81
|
validateRemoteSignerOptions(options);
|
|
21
|
-
|
|
82
|
+
// validate funding account option
|
|
83
|
+
validateFundingAccountOptions(options);
|
|
84
|
+
const { dataDir, file, count, publisherCount = 0, publishers, json, coinbase, fundingAccount, 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;
|
|
85
|
+
const { ethPassword, blsPassword } = await resolvePasswords({
|
|
86
|
+
password: passwordOption,
|
|
87
|
+
passwordFile,
|
|
88
|
+
ethPassword: ethPasswordOption,
|
|
89
|
+
ethPasswordFile,
|
|
90
|
+
blsPassword: blsPasswordOption,
|
|
91
|
+
blsPasswordFile
|
|
92
|
+
});
|
|
93
|
+
const shouldEncryptKeystores = ethPassword !== undefined && blsPassword !== undefined;
|
|
22
94
|
const mnemonic = _mnemonic ?? generateMnemonic(wordlist);
|
|
23
|
-
if (!_mnemonic && !json) {
|
|
95
|
+
if (!_mnemonic && !json && !shouldEncryptKeystores) {
|
|
24
96
|
log('No mnemonic provided, generating new one...');
|
|
25
97
|
log(`Using new mnemonic:`);
|
|
26
98
|
log('');
|
|
@@ -43,21 +115,31 @@ export async function newValidatorKeystore(options, log) {
|
|
|
43
115
|
coinbase,
|
|
44
116
|
remoteSigner
|
|
45
117
|
});
|
|
118
|
+
let resolvedFundingAccount = fundingAccount ? resolveFundingAccount(fundingAccount, remoteSigner) : undefined;
|
|
46
119
|
// If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
|
|
47
|
-
if (
|
|
120
|
+
if (shouldEncryptKeystores) {
|
|
48
121
|
const encryptedKeystoreOutDir = encryptedKeystoreDir && encryptedKeystoreDir.length > 0 ? encryptedKeystoreDir : keystoreOutDir;
|
|
49
122
|
await writeEthJsonV3ToFile(validators, {
|
|
50
123
|
outDir: encryptedKeystoreOutDir,
|
|
51
|
-
password
|
|
124
|
+
password: ethPassword
|
|
52
125
|
});
|
|
53
126
|
await writeBlsBn254ToFile(validators, {
|
|
54
127
|
outDir: encryptedKeystoreOutDir,
|
|
55
|
-
password
|
|
128
|
+
password: blsPassword
|
|
56
129
|
});
|
|
130
|
+
if (resolvedFundingAccount) {
|
|
131
|
+
resolvedFundingAccount = await encryptFundingAccountToFile(resolvedFundingAccount, {
|
|
132
|
+
outDir: encryptedKeystoreOutDir,
|
|
133
|
+
password: ethPassword
|
|
134
|
+
});
|
|
135
|
+
}
|
|
57
136
|
}
|
|
58
137
|
const keystore = {
|
|
59
138
|
schemaVersion: 1,
|
|
60
|
-
validators
|
|
139
|
+
validators,
|
|
140
|
+
...resolvedFundingAccount ? {
|
|
141
|
+
fundingAccount: resolvedFundingAccount
|
|
142
|
+
} : {}
|
|
61
143
|
};
|
|
62
144
|
await writeKeystoreFile(outputPath, keystore);
|
|
63
145
|
// Generate staker outputs if requested
|
|
@@ -76,7 +158,7 @@ export async function newValidatorKeystore(options, log) {
|
|
|
76
158
|
// Process each validator
|
|
77
159
|
for(let i = 0; i < validators.length; i++){
|
|
78
160
|
const validator = validators[i];
|
|
79
|
-
const outputs = await processAttesterAccounts(validator.attester, gse
|
|
161
|
+
const outputs = await processAttesterAccounts(validator.attester, gse);
|
|
80
162
|
// Collect all staker outputs
|
|
81
163
|
for(let j = 0; j < outputs.length; j++){
|
|
82
164
|
allStakerOutputs.push(outputs[j]);
|
|
@@ -88,7 +170,7 @@ export async function newValidatorKeystore(options, log) {
|
|
|
88
170
|
await writeFile(stakerOutputPath, prettyPrintJSON(allStakerOutputs), 'utf-8');
|
|
89
171
|
}
|
|
90
172
|
}
|
|
91
|
-
const outputData = !_mnemonic ? {
|
|
173
|
+
const outputData = !_mnemonic && !shouldEncryptKeystores ? {
|
|
92
174
|
...keystore,
|
|
93
175
|
generatedMnemonic: mnemonic
|
|
94
176
|
} : keystore;
|
|
@@ -115,6 +197,10 @@ export async function newValidatorKeystore(options, log) {
|
|
|
115
197
|
// print a concise summary of public keys (addresses and BLS pubkeys) if no --json options was selected
|
|
116
198
|
if (!json) {
|
|
117
199
|
logValidatorSummaries(log, summaries);
|
|
200
|
+
if (fundingAccount) {
|
|
201
|
+
const funderAddress = fundingAccount.length === 66 ? privateKeyToAccount(fundingAccount).address : fundingAccount;
|
|
202
|
+
log(`funding account: ${funderAddress}`);
|
|
203
|
+
}
|
|
118
204
|
}
|
|
119
205
|
if (mnemonic && remoteSigner && !json) {
|
|
120
206
|
for(let i = 0; i < validatorCount; i++){
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
+
export type SetFundingAccountOptions = {
|
|
3
|
+
remoteSigner?: string;
|
|
4
|
+
password?: string;
|
|
5
|
+
encryptedKeystoreDir?: string;
|
|
6
|
+
json?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Sets the top-level funding account of an existing keystore, replacing any previous one. The
|
|
10
|
+
* account may be a private key, or an address paired with a remote signer URL. With a password,
|
|
11
|
+
* a plaintext key is encrypted to an ETH JSON V3 file and stored as a { path, password } reference.
|
|
12
|
+
*/
|
|
13
|
+
export declare function setFundingAccount(existing: string, fundingAccount: string, options: SetFundingAccountOptions, log: LogFn): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0X2Z1bmRpbmdfYWNjb3VudC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NtZHMvdmFsaWRhdG9yX2tleXMvc2V0X2Z1bmRpbmdfYWNjb3VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxLQUFLLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQVVuRCxNQUFNLE1BQU0sd0JBQXdCLEdBQUc7SUFDckMsWUFBWSxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ3RCLFFBQVEsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUNsQixvQkFBb0IsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUM5QixJQUFJLENBQUMsRUFBRSxPQUFPLENBQUM7Q0FDaEIsQ0FBQztBQUVGOzs7O0dBSUc7QUFDSCx3QkFBc0IsaUJBQWlCLENBQ3JDLFFBQVEsRUFBRSxNQUFNLEVBQ2hCLGNBQWMsRUFBRSxNQUFNLEVBQ3RCLE9BQU8sRUFBRSx3QkFBd0IsRUFDakMsR0FBRyxFQUFFLEtBQUssaUJBNEJYIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set_funding_account.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/set_funding_account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAUnD,MAAM,MAAM,wBAAwB,GAAG;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,wBAAwB,EACjC,GAAG,EAAE,KAAK,iBA4BX"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { loadKeystoreFile } from '@aztec/node-keystore/loader';
|
|
2
|
+
import { dirname } from 'path';
|
|
3
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
4
|
+
import { encryptFundingAccountToFile, maybePrintJson, resolveFundingAccount, writeKeystoreFile } from './shared.js';
|
|
5
|
+
import { validateFundingAccountOptions } from './utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Sets the top-level funding account of an existing keystore, replacing any previous one. The
|
|
8
|
+
* account may be a private key, or an address paired with a remote signer URL. With a password,
|
|
9
|
+
* a plaintext key is encrypted to an ETH JSON V3 file and stored as a { path, password } reference.
|
|
10
|
+
*/ export async function setFundingAccount(existing, fundingAccount, options, log) {
|
|
11
|
+
const { remoteSigner, password, encryptedKeystoreDir, json } = options;
|
|
12
|
+
const keystore = loadKeystoreFile(existing);
|
|
13
|
+
const validated = {
|
|
14
|
+
fundingAccount,
|
|
15
|
+
remoteSigner
|
|
16
|
+
};
|
|
17
|
+
validateFundingAccountOptions(validated, !!keystore.remoteSigner);
|
|
18
|
+
let resolved = resolveFundingAccount(validated.fundingAccount, remoteSigner);
|
|
19
|
+
if (password !== undefined) {
|
|
20
|
+
const outDir = encryptedKeystoreDir && encryptedKeystoreDir.length > 0 ? encryptedKeystoreDir : dirname(existing);
|
|
21
|
+
resolved = await encryptFundingAccountToFile(resolved, {
|
|
22
|
+
outDir,
|
|
23
|
+
password
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (keystore.fundingAccount) {
|
|
27
|
+
log('Replacing existing funding account in keystore');
|
|
28
|
+
}
|
|
29
|
+
keystore.fundingAccount = resolved;
|
|
30
|
+
await writeKeystoreFile(existing, keystore);
|
|
31
|
+
if (!json) {
|
|
32
|
+
const value = validated.fundingAccount;
|
|
33
|
+
const funderAddress = value.length === 66 ? privateKeyToAccount(value).address : value;
|
|
34
|
+
log(`Set funding account ${funderAddress} in ${existing}`);
|
|
35
|
+
}
|
|
36
|
+
maybePrintJson(log, !!json, keystore);
|
|
37
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import type { LogFn } from '@aztec/foundation/log';
|
|
3
3
|
import type { EthAccount, EthPrivateKey, ValidatorKeyStore } from '@aztec/node-keystore/types';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -28,6 +28,14 @@ export declare function withValidatorIndex(path: string, accountIndex?: number,
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function computeBlsPublicKeyCompressed(privateKeyHex: string): Promise<string>;
|
|
30
30
|
export declare function deriveEthAttester(mnemonic: string, baseAccountIndex: number, addressIndex: number, remoteSigner?: string): EthAccount | EthPrivateKey;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve a `--funding-account` value into a keystore `EthAccount`. A 66-char value is a private key
|
|
33
|
+
* (used verbatim). A 42-char value is an address: with an explicit `remoteSigner` URL it becomes an
|
|
34
|
+
* `{ address, remoteSignerUrl }` pair; without one it is stored as a bare address that falls back to
|
|
35
|
+
* the keystore-level remote signer at runtime. Callers must validate the value first (see
|
|
36
|
+
* `validateFundingAccountOptions`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveFundingAccount(fundingAccount: string, remoteSigner?: string): EthAccount;
|
|
31
39
|
export declare function buildValidatorEntries(input: BuildValidatorsInput): Promise<{
|
|
32
40
|
validators: ValidatorKeyStore[];
|
|
33
41
|
summaries: ValidatorSummary[];
|
|
@@ -60,9 +68,14 @@ export declare function writeBlsBn254ToFile(validators: ValidatorKeyStore[], opt
|
|
|
60
68
|
}): Promise<void>;
|
|
61
69
|
/** Writes an Ethereum JSON V3 keystore using ethers, returns absolute path */
|
|
62
70
|
export declare function writeEthJsonV3Keystore(outDir: string, fileNameBase: string, password: string, privateKeyHex: string): Promise<string>;
|
|
71
|
+
/** Encrypt a plaintext funding-account key to a JSON V3 file, replacing it with a { path, password } reference. */
|
|
72
|
+
export declare function encryptFundingAccountToFile(account: EthAccount, options: {
|
|
73
|
+
outDir: string;
|
|
74
|
+
password: string;
|
|
75
|
+
}): Promise<EthAccount>;
|
|
63
76
|
/** Replace plaintext ETH keys in validators with { path, password } pointing to JSON V3 files. */
|
|
64
77
|
export declare function writeEthJsonV3ToFile(validators: ValidatorKeyStore[], options: {
|
|
65
78
|
outDir: string;
|
|
66
79
|
password: string;
|
|
67
80
|
}): Promise<void>;
|
|
68
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
81
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2hhcmVkLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY21kcy92YWxpZGF0b3Jfa2V5cy9zaGFyZWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBS0EsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQzNELE9BQU8sS0FBSyxFQUFFLEtBQUssRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQ25ELE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxhQUFhLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSw0QkFBNEIsQ0FBQztBQUMvRixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQTJEaEUsTUFBTSxNQUFNLGdCQUFnQixHQUFHO0lBQUUsV0FBVyxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQUMsV0FBVyxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQUMsWUFBWSxDQUFDLEVBQUUsTUFBTSxFQUFFLENBQUE7Q0FBRSxDQUFDO0FBRXZHLE1BQU0sTUFBTSxvQkFBb0IsR0FBRztJQUNqQyxjQUFjLEVBQUUsTUFBTSxDQUFDO0lBQ3ZCLGNBQWMsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUN4QixVQUFVLENBQUMsRUFBRSxNQUFNLEVBQUUsQ0FBQztJQUN0QixZQUFZLEVBQUUsTUFBTSxDQUFDO0lBQ3JCLGdCQUFnQixFQUFFLE1BQU0sQ0FBQztJQUN6QixR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UU7SUFBRSxNQUFNLEVBQUUsTUFBTSxDQUFDO0lBQUMsUUFBUSxFQUFFLE1BQU0sQ0FBQTtDQUFFLEdBQzVDLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FFckI7QUFFRCxrR0FBa0c7QUFDbEcsd0JBQXNCLG9CQUFvQixDQUN4QyxVQUFVLEVBQUUsaUJBQWlCLEVBQUUsRUFDL0IsT0FBTyxFQUFFO0lBQUUsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUFDLFFBQVEsRUFBRSxNQUFNLENBQUE7Q0FBRSxHQUM1QyxPQUFPLENBQUMsSUFBSSxDQUFDLENBeUNmIn0=
|
|
@@ -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,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,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,QAA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B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,CAAC,CASjB;AAED,yGAAyG;AACzG,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,iBAAiB,EAAE,EAC/B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9D,OAAO,CAAC,IAAI,CAAC,CAwBf;AAED,8EAA8E;AAC9E,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,CAOjB;AAeD,mHAAmH;AACnH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,UAAU,CAAC,CAErB;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,59 @@
|
|
|
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';
|
|
6
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
7
|
import { Wallet } from '@ethersproject/wallet';
|
|
6
8
|
import { constants as fsConstants, mkdirSync } from 'fs';
|
|
7
9
|
import { access, writeFile } from 'fs/promises';
|
|
8
|
-
import { homedir } from 'os';
|
|
10
|
+
import { availableParallelism, homedir } from 'os';
|
|
9
11
|
import { dirname, isAbsolute, join } from 'path';
|
|
10
12
|
import { mnemonicToAccount } from 'viem/accounts';
|
|
13
|
+
import { Worker } from 'worker_threads';
|
|
11
14
|
import { defaultBlsPath } from './utils.js';
|
|
15
|
+
// ethers' default scrypt parameters use substantial memory, so keep worker fan-out bounded.
|
|
16
|
+
const maxEthKeystoreWorkers = Math.max(1, Math.min(4, availableParallelism()));
|
|
17
|
+
function deserializeWorkerError(error) {
|
|
18
|
+
const result = new Error(error.message);
|
|
19
|
+
result.name = error.name ?? result.name;
|
|
20
|
+
result.stack = error.stack;
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function encryptEthJsonV3InWorker(privateKeyHex, password) {
|
|
24
|
+
return new Promise((resolve, reject)=>{
|
|
25
|
+
const worker = new Worker(new URL('./eth_json_v3_worker.js', import.meta.url), {
|
|
26
|
+
workerData: {
|
|
27
|
+
privateKeyHex,
|
|
28
|
+
password
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
let settled = false;
|
|
32
|
+
worker.once('message', (result)=>{
|
|
33
|
+
settled = true;
|
|
34
|
+
if ('json' in result) {
|
|
35
|
+
resolve(result.json);
|
|
36
|
+
} else {
|
|
37
|
+
reject(deserializeWorkerError(result.error));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
worker.once('error', (error)=>{
|
|
41
|
+
settled = true;
|
|
42
|
+
reject(error);
|
|
43
|
+
});
|
|
44
|
+
worker.once('exit', (code)=>{
|
|
45
|
+
if (!settled) {
|
|
46
|
+
reject(new Error(`ETH JSON V3 worker stopped with exit code ${code}`));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async function encryptEthJsonV3(privateKeyHex, password) {
|
|
52
|
+
if (process.env.JEST_WORKER_ID !== undefined) {
|
|
53
|
+
return await new Wallet(privateKeyHex).encrypt(password);
|
|
54
|
+
}
|
|
55
|
+
return await encryptEthJsonV3InWorker(privateKeyHex, password);
|
|
56
|
+
}
|
|
12
57
|
export function withValidatorIndex(path, accountIndex = 0, addressIndex = 0) {
|
|
13
58
|
// 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
59
|
// 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.
|
|
@@ -50,6 +95,22 @@ export function deriveEthAttester(mnemonic, baseAccountIndex, addressIndex, remo
|
|
|
50
95
|
remoteSignerUrl: remoteSigner
|
|
51
96
|
} : '0x' + Buffer.from(acct.getHdKey().privateKey).toString('hex');
|
|
52
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Resolve a `--funding-account` value into a keystore `EthAccount`. A 66-char value is a private key
|
|
100
|
+
* (used verbatim). A 42-char value is an address: with an explicit `remoteSigner` URL it becomes an
|
|
101
|
+
* `{ address, remoteSignerUrl }` pair; without one it is stored as a bare address that falls back to
|
|
102
|
+
* the keystore-level remote signer at runtime. Callers must validate the value first (see
|
|
103
|
+
* `validateFundingAccountOptions`).
|
|
104
|
+
*/ export function resolveFundingAccount(fundingAccount, remoteSigner) {
|
|
105
|
+
if (fundingAccount.length === 66) {
|
|
106
|
+
return fundingAccount;
|
|
107
|
+
}
|
|
108
|
+
const address = EthAddress.fromString(fundingAccount);
|
|
109
|
+
return remoteSigner ? {
|
|
110
|
+
address,
|
|
111
|
+
remoteSignerUrl: remoteSigner
|
|
112
|
+
} : address;
|
|
113
|
+
}
|
|
53
114
|
export async function buildValidatorEntries(input) {
|
|
54
115
|
const { validatorCount, publisherCount = 0, publishers, accountIndex, baseAddressIndex, mnemonic, ikm, blsPath, feeRecipient, coinbase, remoteSigner } = input;
|
|
55
116
|
const summaries = [];
|
|
@@ -188,7 +249,7 @@ export function maybePrintJson(log, jsonFlag, obj) {
|
|
|
188
249
|
mkdirSync(outDir, {
|
|
189
250
|
recursive: true
|
|
190
251
|
});
|
|
191
|
-
const keystore = createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath);
|
|
252
|
+
const keystore = await createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath);
|
|
192
253
|
const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
193
254
|
const outPath = join(outDir, `keystore-${safeBase}.json`);
|
|
194
255
|
await writeFile(outPath, JSON.stringify(keystore, null, 2), {
|
|
@@ -197,16 +258,15 @@ export function maybePrintJson(log, jsonFlag, obj) {
|
|
|
197
258
|
return outPath;
|
|
198
259
|
}
|
|
199
260
|
/** 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];
|
|
261
|
+
await Promise.all(validators.map(async (v, i)=>{
|
|
202
262
|
if (!v || typeof v !== 'object' || !('attester' in v)) {
|
|
203
|
-
|
|
263
|
+
return;
|
|
204
264
|
}
|
|
205
265
|
const att = v.attester;
|
|
206
266
|
// Shapes: { bls: <hex> } or { eth: <ethAccount>, bls?: <hex> } or plain EthAccount
|
|
207
267
|
const blsKey = typeof att === 'object' && 'bls' in att ? att.bls : undefined;
|
|
208
268
|
if (!blsKey || typeof blsKey !== 'string') {
|
|
209
|
-
|
|
269
|
+
return;
|
|
210
270
|
}
|
|
211
271
|
const pub = await computeBlsPublicKeyCompressed(blsKey);
|
|
212
272
|
const path = options.blsPath ?? defaultBlsPath;
|
|
@@ -218,32 +278,50 @@ export function maybePrintJson(log, jsonFlag, obj) {
|
|
|
218
278
|
password: options.password
|
|
219
279
|
};
|
|
220
280
|
}
|
|
221
|
-
}
|
|
281
|
+
}));
|
|
222
282
|
}
|
|
223
283
|
/** Writes an Ethereum JSON V3 keystore using ethers, returns absolute path */ export async function writeEthJsonV3Keystore(outDir, fileNameBase, password, privateKeyHex) {
|
|
224
284
|
const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
225
285
|
mkdirSync(outDir, {
|
|
226
286
|
recursive: true
|
|
227
287
|
});
|
|
228
|
-
const
|
|
229
|
-
const json = await wallet.encrypt(password);
|
|
288
|
+
const json = await encryptEthJsonV3(privateKeyHex, password);
|
|
230
289
|
const outPath = join(outDir, `keystore-eth-${safeBase}.json`);
|
|
231
290
|
await writeFile(outPath, json, {
|
|
232
291
|
encoding: 'utf-8'
|
|
233
292
|
});
|
|
234
293
|
return outPath;
|
|
235
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* If `account` is a plaintext ETH private key, encrypt it to a JSON V3 file and return a
|
|
297
|
+
* { path, password } reference; otherwise return it unchanged.
|
|
298
|
+
*/ async function maybeEncryptEthAccount(account, label, options) {
|
|
299
|
+
if (typeof account === 'string' && account.startsWith('0x') && account.length === 66) {
|
|
300
|
+
const fileBase = `${label}_${account.slice(2, 10)}`;
|
|
301
|
+
const p = await writeEthJsonV3Keystore(options.outDir, fileBase, options.password, account);
|
|
302
|
+
return {
|
|
303
|
+
path: p,
|
|
304
|
+
password: options.password
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
return account;
|
|
308
|
+
}
|
|
309
|
+
/** Encrypt a plaintext funding-account key to a JSON V3 file, replacing it with a { path, password } reference. */ export async function encryptFundingAccountToFile(account, options) {
|
|
310
|
+
return await maybeEncryptEthAccount(account, 'funding', options);
|
|
311
|
+
}
|
|
236
312
|
/** Replace plaintext ETH keys in validators with { path, password } pointing to JSON V3 files. */ export async function writeEthJsonV3ToFile(validators, options) {
|
|
237
|
-
const
|
|
313
|
+
const tasks = [];
|
|
314
|
+
const maybeQueueEncryptEth = (account, label, setEncryptedAccount)=>{
|
|
238
315
|
if (typeof account === 'string' && account.startsWith('0x') && account.length === 66) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
316
|
+
tasks.push(async ()=>{
|
|
317
|
+
const fileBase = `${label}_${account.slice(2, 10)}`;
|
|
318
|
+
const path = await writeEthJsonV3Keystore(options.outDir, fileBase, options.password, account);
|
|
319
|
+
setEncryptedAccount({
|
|
320
|
+
path,
|
|
321
|
+
password: options.password
|
|
322
|
+
});
|
|
323
|
+
});
|
|
245
324
|
}
|
|
246
|
-
return account;
|
|
247
325
|
};
|
|
248
326
|
for(let i = 0; i < validators.length; i++){
|
|
249
327
|
const v = validators[i];
|
|
@@ -253,22 +331,21 @@ export function maybePrintJson(log, jsonFlag, obj) {
|
|
|
253
331
|
// attester may be string (eth), object with eth, or remote signer
|
|
254
332
|
const att = v.attester;
|
|
255
333
|
if (typeof att === 'string') {
|
|
256
|
-
|
|
334
|
+
maybeQueueEncryptEth(att, `attester_${i + 1}`, (account)=>v.attester = account);
|
|
257
335
|
} else if (att && typeof att === 'object' && 'eth' in att) {
|
|
258
|
-
|
|
336
|
+
maybeQueueEncryptEth(att.eth, `attester_${i + 1}`, (account)=>att.eth = account);
|
|
259
337
|
}
|
|
260
338
|
// publisher can be single or array
|
|
261
339
|
if ('publisher' in v) {
|
|
262
340
|
const pub = v.publisher;
|
|
263
341
|
if (Array.isArray(pub)) {
|
|
264
|
-
const out = [];
|
|
265
342
|
for(let j = 0; j < pub.length; j++){
|
|
266
|
-
|
|
343
|
+
maybeQueueEncryptEth(pub[j], `publisher_${i + 1}_${j + 1}`, (account)=>pub[j] = account);
|
|
267
344
|
}
|
|
268
|
-
v.publisher = out;
|
|
269
345
|
} else if (pub !== undefined) {
|
|
270
|
-
|
|
346
|
+
maybeQueueEncryptEth(pub, `publisher_${i + 1}`, (account)=>v.publisher = account);
|
|
271
347
|
}
|
|
272
348
|
}
|
|
273
349
|
}
|
|
350
|
+
await asyncPool(maxEthKeystoreWorkers, tasks, (task)=>task());
|
|
274
351
|
}
|