@aztec/cli 0.0.1-commit.3469e52 → 0.0.1-commit.350e0a4d
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 +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/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 +7 -2
- 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 +7 -2
- package/dest/config/chain_l2_config.d.ts.map +1 -1
- package/dest/config/chain_l2_config.js +17 -2
- package/dest/config/generated/networks.d.ts +93 -56
- package/dest/config/generated/networks.d.ts.map +1 -1
- package/dest/config/generated/networks.js +94 -57
- 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 +21 -11
- 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 +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 +12 -7
- package/src/cmds/l1/assume_proven_through.ts +4 -7
- 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 +23 -4
- 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 +17 -2
- package/src/config/generated/networks.ts +92 -55
- package/src/config/network_config.ts +6 -2
- package/src/utils/aztec.ts +12 -18
- package/src/utils/commands.ts +24 -11
- package/src/utils/inspect.ts +11 -9
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
2
|
-
import
|
|
2
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
3
3
|
import type { WaitOpts } from '@aztec/aztec.js/contracts';
|
|
4
4
|
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
5
|
+
import { TxStatus } from '@aztec/aztec.js/tx';
|
|
5
6
|
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
6
7
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
7
8
|
import type { LogFn } from '@aztec/foundation/log';
|
|
8
9
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
9
|
-
import {
|
|
10
|
+
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
11
|
+
import { createFundedInitializerlessAccounts } from '@aztec/wallets/testing';
|
|
10
12
|
|
|
11
13
|
export async function setupL2Contracts(nodeUrl: string, testAccounts: boolean, json: boolean, log: LogFn) {
|
|
12
14
|
const waitOpts: WaitOpts = {
|
|
13
15
|
timeout: 180,
|
|
14
16
|
interval: 1,
|
|
17
|
+
// The embedded wallet defaults to PROPOSED, which can be dropped if its proposed block is pruned
|
|
18
|
+
// before the checkpoint lands. Wait for the checkpoint so serial setup is reliable.
|
|
19
|
+
waitForStatus: TxStatus.CHECKPOINTED,
|
|
15
20
|
};
|
|
16
21
|
log('setupL2Contracts: Wait options' + jsonStringify(waitOpts));
|
|
17
22
|
log('setupL2Contracts: Creating PXE client...');
|
|
18
23
|
const node = createAztecNodeClient(nodeUrl);
|
|
19
|
-
const wallet = await
|
|
24
|
+
const wallet = await EmbeddedWallet.create(node);
|
|
20
25
|
|
|
21
|
-
let
|
|
26
|
+
let accountManagers: AccountManager[] = [];
|
|
22
27
|
if (testAccounts) {
|
|
23
|
-
log('setupL2Contracts:
|
|
28
|
+
log('setupL2Contracts: Creating test accounts...');
|
|
24
29
|
const initialAccountsData = await getInitialTestAccountsData();
|
|
25
|
-
|
|
30
|
+
accountManagers = await createFundedInitializerlessAccounts(wallet, initialAccountsData);
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
if (json) {
|
|
29
34
|
const toPrint: Record<string, AztecAddress> = { ...ProtocolContractAddress };
|
|
30
|
-
|
|
35
|
+
accountManagers.forEach((a, i) => {
|
|
31
36
|
toPrint[`testAccount${i}`] = a.address;
|
|
32
37
|
});
|
|
33
38
|
log(JSON.stringify(toPrint, null, 2));
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
2
2
|
import { RollupCheatCodes } from '@aztec/ethereum/test';
|
|
3
|
-
import {
|
|
3
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import type { LogFn } from '@aztec/foundation/log';
|
|
5
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
6
|
|
|
7
7
|
export async function assumeProvenThrough(
|
|
8
|
-
|
|
8
|
+
checkpointOrLatest: CheckpointNumber | undefined,
|
|
9
9
|
l1RpcUrls: string[],
|
|
10
10
|
nodeUrl: string,
|
|
11
11
|
log: LogFn,
|
|
12
12
|
) {
|
|
13
13
|
const aztecNode = createAztecNodeClient(nodeUrl);
|
|
14
14
|
const rollupAddress = await aztecNode.getNodeInfo().then(i => i.l1ContractAddresses.rollupAddress);
|
|
15
|
-
const blockNumber: BlockNumber = blockNumberOrLatest
|
|
16
|
-
? BlockNumber(blockNumberOrLatest)
|
|
17
|
-
: await aztecNode.getBlockNumber();
|
|
18
15
|
|
|
19
16
|
const rollupCheatCodes = RollupCheatCodes.create(l1RpcUrls, { rollupAddress }, new DateProvider());
|
|
20
17
|
|
|
21
|
-
await rollupCheatCodes.markAsProven(
|
|
22
|
-
log(`Assumed proven through
|
|
18
|
+
await rollupCheatCodes.markAsProven(checkpointOrLatest);
|
|
19
|
+
log(`Assumed proven through checkpoint ${checkpointOrLatest ?? 'latest'}`);
|
|
23
20
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
2
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
3
|
+
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
4
|
+
import { getGenesisValues } from '@aztec/world-state/testing';
|
|
5
|
+
|
|
6
|
+
import { getSponsoredFPCAddress } from '../../utils/setup_contracts.js';
|
|
7
|
+
|
|
8
|
+
/** Computes and prints genesis values needed for L1 contract deployment. */
|
|
9
|
+
export async function computeGenesisValuesCmd(testAccounts: boolean, sponsoredFPC: boolean, log: LogFn) {
|
|
10
|
+
const initialAccounts = testAccounts ? await getInitialTestAccountsData() : [];
|
|
11
|
+
const sponsoredFPCAddresses = sponsoredFPC ? await getSponsoredFPCAddress() : [];
|
|
12
|
+
const initialFundedAccounts = initialAccounts.map(a => a.address).concat(sponsoredFPCAddresses);
|
|
13
|
+
const { genesisArchiveRoot } = await getGenesisValues(initialFundedAccounts);
|
|
14
|
+
|
|
15
|
+
const { getVKTreeRoot } = await import('@aztec/noir-protocol-circuits-types/vk-tree');
|
|
16
|
+
const vkTreeRoot = getVKTreeRoot();
|
|
17
|
+
|
|
18
|
+
log(
|
|
19
|
+
JSON.stringify(
|
|
20
|
+
{
|
|
21
|
+
vkTreeRoot: vkTreeRoot.toString(),
|
|
22
|
+
protocolContractsHash: protocolContractsHash.toString(),
|
|
23
|
+
genesisArchiveRoot: genesisArchiveRoot.toString(),
|
|
24
|
+
},
|
|
25
|
+
null,
|
|
26
|
+
2,
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -96,7 +96,6 @@ export async function deployL1ContractsCmd(
|
|
|
96
96
|
log(`RewardDistributor Address: ${l1ContractAddresses.rewardDistributorAddress.toString()}`);
|
|
97
97
|
log(`GovernanceProposer Address: ${l1ContractAddresses.governanceProposerAddress.toString()}`);
|
|
98
98
|
log(`Governance Address: ${l1ContractAddresses.governanceAddress.toString()}`);
|
|
99
|
-
log(`SlashFactory Address: ${l1ContractAddresses.slashFactoryAddress?.toString()}`);
|
|
100
99
|
log(`FeeAssetHandler Address: ${l1ContractAddresses.feeAssetHandlerAddress?.toString()}`);
|
|
101
100
|
log(`StakingAssetHandler Address: ${l1ContractAddresses.stakingAssetHandlerAddress?.toString()}`);
|
|
102
101
|
log(`ZK Passport Verifier Address: ${l1ContractAddresses.zkPassportVerifierAddress?.toString()}`);
|
|
@@ -29,7 +29,7 @@ export async function deployNewRollup(
|
|
|
29
29
|
const initialFundedAccounts = initialAccounts.map(a => a.address).concat(sponsoredFPCAddress);
|
|
30
30
|
const { genesisArchiveRoot, fundingNeeded } = await getGenesisValues(initialFundedAccounts);
|
|
31
31
|
|
|
32
|
-
const { rollup
|
|
32
|
+
const { rollup } = await deployNewRollupContracts(
|
|
33
33
|
registryAddress,
|
|
34
34
|
rpcUrls,
|
|
35
35
|
privateKey,
|
|
@@ -51,7 +51,6 @@ export async function deployNewRollup(
|
|
|
51
51
|
initialFundedAccounts: initialFundedAccounts.map(a => a.toString()),
|
|
52
52
|
initialValidators: initialValidators.map(a => a.attester.toString()),
|
|
53
53
|
genesisArchiveRoot: genesisArchiveRoot.toString(),
|
|
54
|
-
slashFactoryAddress: slashFactoryAddress.toString(),
|
|
55
54
|
},
|
|
56
55
|
null,
|
|
57
56
|
2,
|
|
@@ -62,6 +61,5 @@ export async function deployNewRollup(
|
|
|
62
61
|
log(`Initial funded accounts: ${initialFundedAccounts.map(a => a.toString()).join(', ')}`);
|
|
63
62
|
log(`Initial validators: ${initialValidators.map(a => a.attester.toString()).join(', ')}`);
|
|
64
63
|
log(`Genesis archive root: ${genesisArchiveRoot.toString()}`);
|
|
65
|
-
log(`Slash Factory Address: ${slashFactoryAddress.toString()}`);
|
|
66
64
|
}
|
|
67
65
|
}
|
package/src/cmds/l1/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
3
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
3
4
|
|
|
@@ -105,6 +106,24 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger
|
|
|
105
106
|
);
|
|
106
107
|
});
|
|
107
108
|
|
|
109
|
+
program
|
|
110
|
+
.command('compute-genesis-values')
|
|
111
|
+
.description('Computes genesis values (VK tree root, protocol contracts hash, genesis archive root).')
|
|
112
|
+
.addOption(
|
|
113
|
+
new Option('--test-accounts <boolean>', 'Include initial test accounts in genesis state')
|
|
114
|
+
.env('TEST_ACCOUNTS')
|
|
115
|
+
.argParser(arg => arg === 'true'),
|
|
116
|
+
)
|
|
117
|
+
.addOption(
|
|
118
|
+
new Option('--sponsored-fpc <boolean>', 'Include sponsored FPC contract in genesis state')
|
|
119
|
+
.env('SPONSORED_FPC')
|
|
120
|
+
.argParser(arg => arg === 'true'),
|
|
121
|
+
)
|
|
122
|
+
.action(async options => {
|
|
123
|
+
const { computeGenesisValuesCmd } = await import('./compute_genesis_values.js');
|
|
124
|
+
await computeGenesisValuesCmd(options.testAccounts, options.sponsoredFpc, log);
|
|
125
|
+
});
|
|
126
|
+
|
|
108
127
|
program
|
|
109
128
|
.command('deposit-governance-tokens')
|
|
110
129
|
.description('Deposits governance tokens to the governance contract.')
|
|
@@ -497,14 +516,14 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger
|
|
|
497
516
|
program
|
|
498
517
|
.command('set-proven-through', { hidden: true })
|
|
499
518
|
.description(
|
|
500
|
-
'Instructs the L1 rollup contract to assume all blocks until the given
|
|
519
|
+
'Instructs the L1 rollup contract to assume all blocks until the given checkpoint are automatically proven.',
|
|
501
520
|
)
|
|
502
|
-
.argument('[
|
|
521
|
+
.argument('[checkpoint]', 'The target checkpoint, defaults to the latest pending checkpoint.', parseBigint)
|
|
503
522
|
.addOption(l1RpcUrlsOption)
|
|
504
523
|
.addOption(nodeOption)
|
|
505
|
-
.action(async (
|
|
524
|
+
.action(async (checkpoint, options) => {
|
|
506
525
|
const { assumeProvenThrough } = await import('./assume_proven_through.js');
|
|
507
|
-
await assumeProvenThrough(
|
|
526
|
+
await assumeProvenThrough(CheckpointNumber.fromBigInt(checkpoint), options.l1RpcUrls, options.nodeUrl, log);
|
|
508
527
|
});
|
|
509
528
|
|
|
510
529
|
program
|
|
@@ -2,7 +2,7 @@ import { createEthereumChain, isAnvilTestChain } from '@aztec/ethereum/chain';
|
|
|
2
2
|
import { createExtendedL1Client, getPublicClient } from '@aztec/ethereum/client';
|
|
3
3
|
import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
|
|
4
4
|
import { GSEContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
5
|
-
import {
|
|
5
|
+
import { createL1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
6
6
|
import { EthCheatCodes } from '@aztec/ethereum/test';
|
|
7
7
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
8
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
@@ -38,7 +38,6 @@ export interface LoggerArgs {
|
|
|
38
38
|
export function generateL1Account() {
|
|
39
39
|
const privateKey = generatePrivateKey();
|
|
40
40
|
const account = privateKeyToAccount(privateKey);
|
|
41
|
-
account.address;
|
|
42
41
|
return {
|
|
43
42
|
privateKey,
|
|
44
43
|
address: account.address,
|
|
@@ -88,7 +87,7 @@ export async function addL1Validator({
|
|
|
88
87
|
const gse = new GSEContract(l1Client, gseAddress);
|
|
89
88
|
const registrationTuple = await gse.makeRegistrationTuple(blsSecretKey);
|
|
90
89
|
|
|
91
|
-
const l1TxUtils =
|
|
90
|
+
const l1TxUtils = createL1TxUtils(l1Client, { logger: debugLogger });
|
|
92
91
|
const proofParamsObj = ZkPassportProofParams.fromBuffer(proofParams);
|
|
93
92
|
|
|
94
93
|
// Step 1: Claim STK tokens from the faucet
|
|
@@ -194,7 +193,7 @@ export async function addL1ValidatorViaRollup({
|
|
|
194
193
|
|
|
195
194
|
const registrationTuple = await gse.makeRegistrationTuple(blsSecretKey);
|
|
196
195
|
|
|
197
|
-
const l1TxUtils =
|
|
196
|
+
const l1TxUtils = createL1TxUtils(l1Client, { logger: debugLogger });
|
|
198
197
|
|
|
199
198
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
200
199
|
to: rollupAddress.toString(),
|
|
@@ -241,7 +240,7 @@ export async function removeL1Validator({
|
|
|
241
240
|
const account = getAccount(privateKey, mnemonic);
|
|
242
241
|
const chain = createEthereumChain(rpcUrls, chainId);
|
|
243
242
|
const l1Client = createExtendedL1Client(rpcUrls, account, chain.chainInfo);
|
|
244
|
-
const l1TxUtils =
|
|
243
|
+
const l1TxUtils = createL1TxUtils(l1Client, { logger: debugLogger });
|
|
245
244
|
|
|
246
245
|
dualLog(`Removing validator ${validatorAddress.toString()} from rollup ${rollupAddress.toString()}`);
|
|
247
246
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
@@ -268,7 +267,7 @@ export async function pruneRollup({
|
|
|
268
267
|
const account = getAccount(privateKey, mnemonic);
|
|
269
268
|
const chain = createEthereumChain(rpcUrls, chainId);
|
|
270
269
|
const l1Client = createExtendedL1Client(rpcUrls, account, chain.chainInfo);
|
|
271
|
-
const l1TxUtils =
|
|
270
|
+
const l1TxUtils = createL1TxUtils(l1Client, { logger: debugLogger });
|
|
272
271
|
|
|
273
272
|
dualLog(`Trying prune`);
|
|
274
273
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Wallet } from '@ethersproject/wallet';
|
|
2
|
+
import { parentPort, workerData } from 'worker_threads';
|
|
3
|
+
|
|
4
|
+
type EthJsonV3WorkerData = {
|
|
5
|
+
privateKeyHex: string;
|
|
6
|
+
password: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type SerializedError = {
|
|
10
|
+
message: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
stack?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function serializeError(error: unknown): SerializedError {
|
|
16
|
+
if (error instanceof Error) {
|
|
17
|
+
return { message: error.message, name: error.name, stack: error.stack };
|
|
18
|
+
}
|
|
19
|
+
return { message: String(error) };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void (async () => {
|
|
23
|
+
try {
|
|
24
|
+
const { privateKeyHex, password } = workerData as EthJsonV3WorkerData;
|
|
25
|
+
const json = await new Wallet(privateKeyHex).encrypt(password);
|
|
26
|
+
parentPort?.postMessage({ json });
|
|
27
|
+
} catch (error) {
|
|
28
|
+
parentPort?.postMessage({ error: serializeError(error) });
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LogFn } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
|
-
import { Command } from 'commander';
|
|
3
|
+
import { Command, Option } from 'commander';
|
|
4
4
|
|
|
5
5
|
import { parseAztecAddress, parseEthereumAddress, parseHex, parseOptionalInteger } from '../../utils/commands.js';
|
|
6
6
|
import { defaultBlsPath } from './utils.js';
|
|
@@ -38,10 +38,24 @@ export function injectCommands(program: Command, log: LogFn) {
|
|
|
38
38
|
.option('--remote-signer <url>', 'Default remote signer URL for accounts in this file')
|
|
39
39
|
.option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', value => parseHex(value, 32))
|
|
40
40
|
.option('--bls-path <path>', `EIP-2334 path (default ${defaultBlsPath})`)
|
|
41
|
-
.
|
|
42
|
-
'--password <str>',
|
|
43
|
-
|
|
41
|
+
.addOption(
|
|
42
|
+
new Option('--password <str>', 'Shared password for writing ETH JSON V3 and BLS EIP-2335 keystore files').env(
|
|
43
|
+
'AZTEC_KEYSTORE_PASSWORD',
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
.option('--password-file <path>', 'File containing the shared password for writing keystore files')
|
|
47
|
+
.addOption(
|
|
48
|
+
new Option('--eth-password <str>', 'Password for writing ETH JSON V3 keystore files').env(
|
|
49
|
+
'AZTEC_ETH_KEYSTORE_PASSWORD',
|
|
50
|
+
),
|
|
51
|
+
)
|
|
52
|
+
.option('--eth-password-file <path>', 'File containing the password for writing ETH JSON V3 keystore files')
|
|
53
|
+
.addOption(
|
|
54
|
+
new Option('--bls-password <str>', 'Password for writing BLS EIP-2335 keystore files').env(
|
|
55
|
+
'AZTEC_BLS_KEYSTORE_PASSWORD',
|
|
56
|
+
),
|
|
44
57
|
)
|
|
58
|
+
.option('--bls-password-file <path>', 'File containing the password for writing BLS EIP-2335 keystore files')
|
|
45
59
|
.option('--encrypted-keystore-dir <dir>', 'Output directory for encrypted keystore file(s)')
|
|
46
60
|
.option('--json', 'Echo resulting JSON to stdout')
|
|
47
61
|
.option('--staker-output', 'Generate a single staker output JSON file with an array of validator entries')
|
|
@@ -6,7 +6,7 @@ import type { LogFn } from '@aztec/foundation/log';
|
|
|
6
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
7
|
|
|
8
8
|
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
9
|
-
import { writeFile } from 'fs/promises';
|
|
9
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
10
10
|
import { basename, dirname, join } from 'path';
|
|
11
11
|
import { createPublicClient, fallback, http } from 'viem';
|
|
12
12
|
import { generateMnemonic, mnemonicToAccount } from 'viem/accounts';
|
|
@@ -42,6 +42,11 @@ export type NewValidatorKeystoreOptions = {
|
|
|
42
42
|
ikm?: string;
|
|
43
43
|
blsPath?: string;
|
|
44
44
|
password?: string;
|
|
45
|
+
passwordFile?: string;
|
|
46
|
+
ethPassword?: string;
|
|
47
|
+
ethPasswordFile?: string;
|
|
48
|
+
blsPassword?: string;
|
|
49
|
+
blsPasswordFile?: string;
|
|
45
50
|
encryptedKeystoreDir?: string;
|
|
46
51
|
json?: boolean;
|
|
47
52
|
feeRecipient: AztecAddress;
|
|
@@ -53,6 +58,86 @@ export type NewValidatorKeystoreOptions = {
|
|
|
53
58
|
l1ChainId?: number;
|
|
54
59
|
};
|
|
55
60
|
|
|
61
|
+
type PasswordSourceOptions = Pick<
|
|
62
|
+
NewValidatorKeystoreOptions,
|
|
63
|
+
'password' | 'passwordFile' | 'ethPassword' | 'ethPasswordFile' | 'blsPassword' | 'blsPasswordFile'
|
|
64
|
+
>;
|
|
65
|
+
|
|
66
|
+
type PasswordSource = {
|
|
67
|
+
password?: string;
|
|
68
|
+
passwordFile?: string;
|
|
69
|
+
passwordOption: string;
|
|
70
|
+
passwordFileOption: string;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function validatePassword(password: string, source: string): string {
|
|
74
|
+
if (password.length === 0) {
|
|
75
|
+
throw new Error(`${source} cannot be empty`);
|
|
76
|
+
}
|
|
77
|
+
return password;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function stripOneTrailingNewline(password: string): string {
|
|
81
|
+
if (password.endsWith('\n')) {
|
|
82
|
+
password = password.slice(0, -1);
|
|
83
|
+
}
|
|
84
|
+
if (password.endsWith('\r')) {
|
|
85
|
+
password = password.slice(0, -1);
|
|
86
|
+
}
|
|
87
|
+
return password;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function resolvePasswordSource(source: PasswordSource): Promise<string | undefined> {
|
|
91
|
+
if (source.password !== undefined && source.passwordFile !== undefined) {
|
|
92
|
+
throw new Error(`${source.passwordOption} and ${source.passwordFileOption} cannot be used together`);
|
|
93
|
+
}
|
|
94
|
+
if (source.password !== undefined) {
|
|
95
|
+
return validatePassword(source.password, source.passwordOption);
|
|
96
|
+
}
|
|
97
|
+
if (source.passwordFile !== undefined) {
|
|
98
|
+
if (source.passwordFile.length === 0) {
|
|
99
|
+
throw new Error(`${source.passwordFileOption} cannot be empty`);
|
|
100
|
+
}
|
|
101
|
+
const password = stripOneTrailingNewline(await readFile(source.passwordFile, 'utf-8'));
|
|
102
|
+
return validatePassword(password, source.passwordFileOption);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function resolvePasswords(options: PasswordSourceOptions) {
|
|
109
|
+
const sharedPassword = await resolvePasswordSource({
|
|
110
|
+
password: options.password,
|
|
111
|
+
passwordFile: options.passwordFile,
|
|
112
|
+
passwordOption: '--password',
|
|
113
|
+
passwordFileOption: '--password-file',
|
|
114
|
+
});
|
|
115
|
+
const ethPassword =
|
|
116
|
+
(await resolvePasswordSource({
|
|
117
|
+
password: options.ethPassword,
|
|
118
|
+
passwordFile: options.ethPasswordFile,
|
|
119
|
+
passwordOption: '--eth-password',
|
|
120
|
+
passwordFileOption: '--eth-password-file',
|
|
121
|
+
})) ?? sharedPassword;
|
|
122
|
+
const blsPassword =
|
|
123
|
+
(await resolvePasswordSource({
|
|
124
|
+
password: options.blsPassword,
|
|
125
|
+
passwordFile: options.blsPasswordFile,
|
|
126
|
+
passwordOption: '--bls-password',
|
|
127
|
+
passwordFileOption: '--bls-password-file',
|
|
128
|
+
})) ?? sharedPassword;
|
|
129
|
+
|
|
130
|
+
if (ethPassword === undefined && blsPassword === undefined) {
|
|
131
|
+
return {};
|
|
132
|
+
}
|
|
133
|
+
if (ethPassword === undefined || blsPassword === undefined) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
'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.',
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return { ethPassword, blsPassword };
|
|
139
|
+
}
|
|
140
|
+
|
|
56
141
|
export async function newValidatorKeystore(options: NewValidatorKeystoreOptions, log: LogFn) {
|
|
57
142
|
// validate bls-path inputs before proceeding with key generation
|
|
58
143
|
validateBlsPathOptions(options);
|
|
@@ -78,7 +163,12 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
78
163
|
blsPath,
|
|
79
164
|
ikm,
|
|
80
165
|
mnemonic: _mnemonic,
|
|
81
|
-
password,
|
|
166
|
+
password: passwordOption,
|
|
167
|
+
passwordFile,
|
|
168
|
+
ethPassword: ethPasswordOption,
|
|
169
|
+
ethPasswordFile,
|
|
170
|
+
blsPassword: blsPasswordOption,
|
|
171
|
+
blsPasswordFile,
|
|
82
172
|
encryptedKeystoreDir,
|
|
83
173
|
stakerOutput,
|
|
84
174
|
gseAddress,
|
|
@@ -86,9 +176,18 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
86
176
|
l1ChainId,
|
|
87
177
|
} = options;
|
|
88
178
|
|
|
179
|
+
const { ethPassword, blsPassword } = await resolvePasswords({
|
|
180
|
+
password: passwordOption,
|
|
181
|
+
passwordFile,
|
|
182
|
+
ethPassword: ethPasswordOption,
|
|
183
|
+
ethPasswordFile,
|
|
184
|
+
blsPassword: blsPasswordOption,
|
|
185
|
+
blsPasswordFile,
|
|
186
|
+
});
|
|
187
|
+
const shouldEncryptKeystores = ethPassword !== undefined && blsPassword !== undefined;
|
|
89
188
|
const mnemonic = _mnemonic ?? generateMnemonic(wordlist);
|
|
90
189
|
|
|
91
|
-
if (!_mnemonic && !json) {
|
|
190
|
+
if (!_mnemonic && !json && !shouldEncryptKeystores) {
|
|
92
191
|
log('No mnemonic provided, generating new one...');
|
|
93
192
|
log(`Using new mnemonic:`);
|
|
94
193
|
log('');
|
|
@@ -115,11 +214,11 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
115
214
|
});
|
|
116
215
|
|
|
117
216
|
// If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
|
|
118
|
-
if (
|
|
217
|
+
if (shouldEncryptKeystores) {
|
|
119
218
|
const encryptedKeystoreOutDir =
|
|
120
219
|
encryptedKeystoreDir && encryptedKeystoreDir.length > 0 ? encryptedKeystoreDir : keystoreOutDir;
|
|
121
|
-
await writeEthJsonV3ToFile(validators, { outDir: encryptedKeystoreOutDir, password });
|
|
122
|
-
await writeBlsBn254ToFile(validators, { outDir: encryptedKeystoreOutDir, password });
|
|
220
|
+
await writeEthJsonV3ToFile(validators, { outDir: encryptedKeystoreOutDir, password: ethPassword });
|
|
221
|
+
await writeBlsBn254ToFile(validators, { outDir: encryptedKeystoreOutDir, password: blsPassword });
|
|
123
222
|
}
|
|
124
223
|
|
|
125
224
|
const keystore = {
|
|
@@ -145,7 +244,7 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
145
244
|
// Process each validator
|
|
146
245
|
for (let i = 0; i < validators.length; i++) {
|
|
147
246
|
const validator = validators[i];
|
|
148
|
-
const outputs = await processAttesterAccounts(validator.attester, gse
|
|
247
|
+
const outputs = await processAttesterAccounts(validator.attester, gse);
|
|
149
248
|
|
|
150
249
|
// Collect all staker outputs
|
|
151
250
|
for (let j = 0; j < outputs.length; j++) {
|
|
@@ -160,7 +259,7 @@ export async function newValidatorKeystore(options: NewValidatorKeystoreOptions,
|
|
|
160
259
|
}
|
|
161
260
|
}
|
|
162
261
|
|
|
163
|
-
const outputData = !_mnemonic ? { ...keystore, generatedMnemonic: mnemonic } : keystore;
|
|
262
|
+
const outputData = !_mnemonic && !shouldEncryptKeystores ? { ...keystore, generatedMnemonic: mnemonic } : keystore;
|
|
164
263
|
|
|
165
264
|
// Handle JSON output
|
|
166
265
|
if (json) {
|