@aztec/cli 0.0.1-commit.b6e433891 → 0.0.1-commit.b8a057fa
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 +10 -6
- 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/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 +0 -1
- package/dest/cmds/validator_keys/eth_json_v3_worker.d.ts +2 -0
- package/dest/cmds/validator_keys/eth_json_v3_worker.d.ts.map +1 -0
- package/dest/cmds/validator_keys/eth_json_v3_worker.js +27 -0
- package/dest/cmds/validator_keys/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/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 +14 -1
- package/dest/config/generated/networks.d.ts +61 -43
- package/dest/config/generated/networks.d.ts.map +1 -1
- package/dest/config/generated/networks.js +60 -42
- 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 +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 +9 -5
- 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/update_l1_validators.ts +0 -1
- 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/chain_l2_config.ts +14 -1
- package/src/config/generated/networks.ts +60 -42
- package/src/utils/aztec.ts +12 -18
- package/src/utils/commands.ts +24 -11
- package/src/utils/inspect.ts +7 -8
|
@@ -1,22 +1,47 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
-
import type { LogFilter, LogId } from '@aztec/aztec.js/log';
|
|
3
2
|
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
4
3
|
import type { TxHash } from '@aztec/aztec.js/tx';
|
|
5
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
6
5
|
import type { LogFn } from '@aztec/foundation/log';
|
|
7
6
|
import { sleep } from '@aztec/foundation/sleep';
|
|
7
|
+
import {
|
|
8
|
+
LogCursor,
|
|
9
|
+
type PublicLogsQuery,
|
|
10
|
+
type Tag,
|
|
11
|
+
logResultToHumanReadable,
|
|
12
|
+
queryAllPublicLogsByTags,
|
|
13
|
+
} from '@aztec/stdlib/logs';
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
/** Options for the `get-logs` CLI command. */
|
|
16
|
+
export type GetLogsOptions = {
|
|
17
|
+
/** Contract address that emitted the logs (required). */
|
|
18
|
+
contractAddress: AztecAddress;
|
|
19
|
+
/** Tag to filter logs by (required). */
|
|
20
|
+
tag: Tag;
|
|
21
|
+
/** Restrict the search to this tx hash. Mutually exclusive with `fromBlock`/`toBlock`. */
|
|
22
|
+
txHash?: TxHash;
|
|
23
|
+
/** Lower block bound, inclusive. */
|
|
24
|
+
fromBlock?: BlockNumber;
|
|
25
|
+
/** Upper block bound, exclusive. */
|
|
26
|
+
toBlock?: BlockNumber;
|
|
27
|
+
/** Log cursor to resume pagination strictly after a previously-seen log. */
|
|
28
|
+
afterLog?: LogCursor;
|
|
29
|
+
/** Node RPC URL. */
|
|
30
|
+
nodeUrl: string;
|
|
31
|
+
/** When set, polls indefinitely for new logs. Incompatible with `txHash` and `toBlock`. */
|
|
32
|
+
follow: boolean;
|
|
33
|
+
/** Log function. */
|
|
34
|
+
log: LogFn;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Fetches public logs for a (contract, tag) pair, draining all pages via the stdlib pagination helper.
|
|
39
|
+
* In `--follow` mode, polls indefinitely: each round drains all currently-available logs, then sleeps
|
|
40
|
+
* until the next poll if nothing new was found.
|
|
41
|
+
*/
|
|
42
|
+
export async function getLogs(options: GetLogsOptions): Promise<void> {
|
|
43
|
+
const { txHash, fromBlock, toBlock, contractAddress, tag, nodeUrl, follow, log } = options;
|
|
44
|
+
let afterLog = options.afterLog;
|
|
20
45
|
|
|
21
46
|
if (follow) {
|
|
22
47
|
if (txHash) {
|
|
@@ -26,43 +51,50 @@ export async function getLogs(
|
|
|
26
51
|
throw Error('Cannot use --follow with --to-block');
|
|
27
52
|
}
|
|
28
53
|
}
|
|
54
|
+
if (txHash !== undefined && (fromBlock !== undefined || toBlock !== undefined)) {
|
|
55
|
+
throw Error('Cannot combine --tx-hash with --from-block / --to-block');
|
|
56
|
+
}
|
|
29
57
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const fetchLogs = async () => {
|
|
33
|
-
const response = await node.getPublicLogs(filter);
|
|
34
|
-
const logs = response.logs;
|
|
58
|
+
const node = createAztecNodeClient(nodeUrl);
|
|
35
59
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
logs.forEach(publicLog => log(publicLog.toHumanReadable()));
|
|
49
|
-
// Set the continuation parameter for the following requests
|
|
50
|
-
filter.afterLog = logs[logs.length - 1].id;
|
|
60
|
+
const drainLogs = async () => {
|
|
61
|
+
const query: PublicLogsQuery = {
|
|
62
|
+
contractAddress,
|
|
63
|
+
tags: [afterLog !== undefined ? { tag, afterLog } : tag],
|
|
64
|
+
fromBlock,
|
|
65
|
+
toBlock,
|
|
66
|
+
txHash,
|
|
67
|
+
};
|
|
68
|
+
const [logsForTag] = await queryAllPublicLogsByTags(node, query);
|
|
69
|
+
if (logsForTag.length > 0) {
|
|
70
|
+
afterLog = LogCursor.fromLog(logsForTag[logsForTag.length - 1]);
|
|
51
71
|
}
|
|
52
|
-
return
|
|
72
|
+
return logsForTag;
|
|
53
73
|
};
|
|
54
74
|
|
|
55
75
|
if (follow) {
|
|
56
76
|
log('Fetching logs...');
|
|
57
77
|
while (true) {
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
78
|
+
const results = await drainLogs();
|
|
79
|
+
if (results.length === 0) {
|
|
60
80
|
await sleep(1000);
|
|
81
|
+
} else {
|
|
82
|
+
results.forEach(r => log(logResultToHumanReadable(r)));
|
|
61
83
|
}
|
|
62
84
|
}
|
|
63
85
|
} else {
|
|
64
|
-
|
|
65
|
-
|
|
86
|
+
const results = await drainLogs();
|
|
87
|
+
if (results.length === 0) {
|
|
88
|
+
log(
|
|
89
|
+
`No logs found for {contractAddress: ${contractAddress.toString()}, tag: ${tag.toString()}` +
|
|
90
|
+
`${txHash ? `, txHash: ${txHash.toString()}` : ''}` +
|
|
91
|
+
`${fromBlock !== undefined ? `, fromBlock: ${fromBlock}` : ''}` +
|
|
92
|
+
`${toBlock !== undefined ? `, toBlock: ${toBlock}` : ''}` +
|
|
93
|
+
`${afterLog ? `, afterLog: ${afterLog.toString()}` : ''}}`,
|
|
94
|
+
);
|
|
95
|
+
} else {
|
|
96
|
+
log('Logs found: \n');
|
|
97
|
+
results.forEach(r => log(logResultToHumanReadable(r)));
|
|
66
98
|
}
|
|
67
99
|
}
|
|
68
100
|
}
|
|
@@ -23,7 +23,6 @@ export async function getNodeInfo(nodeUrl: string, json: boolean, log: LogFn, lo
|
|
|
23
23
|
rewardDistributor: info.l1ContractAddresses.rewardDistributorAddress.toString(),
|
|
24
24
|
governanceProposer: info.l1ContractAddresses.governanceProposerAddress.toString(),
|
|
25
25
|
governance: info.l1ContractAddresses.governanceAddress.toString(),
|
|
26
|
-
slashFactory: info.l1ContractAddresses.slashFactoryAddress?.toString(),
|
|
27
26
|
feeAssetHandler: info.l1ContractAddresses.feeAssetHandlerAddress?.toString(),
|
|
28
27
|
stakingAssetHandler: info.l1ContractAddresses.stakingAssetHandlerAddress?.toString(),
|
|
29
28
|
},
|
|
@@ -51,7 +50,6 @@ export async function getNodeInfo(nodeUrl: string, json: boolean, log: LogFn, lo
|
|
|
51
50
|
log(` RewardDistributor Address: ${info.l1ContractAddresses.rewardDistributorAddress.toString()}`);
|
|
52
51
|
log(` GovernanceProposer Address: ${info.l1ContractAddresses.governanceProposerAddress.toString()}`);
|
|
53
52
|
log(` Governance Address: ${info.l1ContractAddresses.governanceAddress.toString()}`);
|
|
54
|
-
log(` SlashFactory Address: ${info.l1ContractAddresses.slashFactoryAddress?.toString()}`);
|
|
55
53
|
log(` FeeAssetHandler Address: ${info.l1ContractAddresses.feeAssetHandlerAddress?.toString()}`);
|
|
56
54
|
log(` StakingAssetHandler Address: ${info.l1ContractAddresses.stakingAssetHandlerAddress?.toString()}`);
|
|
57
55
|
log(`L2 Contract Addresses:`);
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
nodeOption,
|
|
8
8
|
parseAztecAddress,
|
|
9
9
|
parseField,
|
|
10
|
-
parseOptionalAztecAddress,
|
|
11
10
|
parseOptionalInteger,
|
|
12
|
-
|
|
11
|
+
parseOptionalLogCursor,
|
|
13
12
|
parseOptionalTxHash,
|
|
13
|
+
parseTag,
|
|
14
14
|
} from '../../utils/commands.js';
|
|
15
15
|
|
|
16
16
|
export function injectCommands(program: Command, log: LogFn, debugLogger: Logger) {
|
|
@@ -47,21 +47,26 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger
|
|
|
47
47
|
|
|
48
48
|
program
|
|
49
49
|
.command('get-logs')
|
|
50
|
-
.description('Gets
|
|
51
|
-
.
|
|
50
|
+
.description('Gets public logs for a contract and tag, optionally restricted by block range or tx hash.')
|
|
51
|
+
.requiredOption('-ca, --contract-address <address>', 'Contract address that emitted the logs.', parseAztecAddress)
|
|
52
|
+
.requiredOption('--tag <tag>', 'Tag (Fr value) to filter logs by.', parseTag)
|
|
53
|
+
.option('-tx, --tx-hash <txHash>', 'A transaction hash to restrict the search to.', parseOptionalTxHash)
|
|
52
54
|
.option(
|
|
53
55
|
'-fb, --from-block <blockNum>',
|
|
54
56
|
'Initial block number for getting logs (defaults to 1).',
|
|
55
57
|
parseOptionalInteger,
|
|
56
58
|
)
|
|
57
59
|
.option('-tb, --to-block <blockNum>', 'Up to which block to fetch logs (defaults to latest).', parseOptionalInteger)
|
|
58
|
-
.option(
|
|
59
|
-
|
|
60
|
+
.option(
|
|
61
|
+
'-al --after-log <cursor>',
|
|
62
|
+
'Log cursor of the form <blockNumber>-<txIndexWithinBlock>-<logIndexWithinTx> to resume pagination after.',
|
|
63
|
+
parseOptionalLogCursor,
|
|
64
|
+
)
|
|
60
65
|
.addOption(nodeOption)
|
|
61
66
|
.option('--follow', 'If set, will keep polling for new logs until interrupted.')
|
|
62
|
-
.action(async ({ txHash, fromBlock, toBlock, afterLog, contractAddress,
|
|
67
|
+
.action(async ({ txHash, fromBlock, toBlock, afterLog, contractAddress, tag, nodeUrl, follow }) => {
|
|
63
68
|
const { getLogs } = await import('./get_logs.js');
|
|
64
|
-
await getLogs(txHash, fromBlock, toBlock, afterLog, contractAddress, nodeUrl, follow, log);
|
|
69
|
+
await getLogs({ txHash, fromBlock, toBlock, afterLog, contractAddress, tag, nodeUrl, follow, log });
|
|
65
70
|
});
|
|
66
71
|
|
|
67
72
|
program
|
|
@@ -2,33 +2,37 @@ import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
|
2
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
10
|
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
10
|
-
import {
|
|
11
|
+
import { createFundedInitializerlessAccounts } from '@aztec/wallets/testing';
|
|
11
12
|
|
|
12
13
|
export async function setupL2Contracts(nodeUrl: string, testAccounts: boolean, json: boolean, log: LogFn) {
|
|
13
14
|
const waitOpts: WaitOpts = {
|
|
14
15
|
timeout: 180,
|
|
15
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,
|
|
16
20
|
};
|
|
17
21
|
log('setupL2Contracts: Wait options' + jsonStringify(waitOpts));
|
|
18
22
|
log('setupL2Contracts: Creating PXE client...');
|
|
19
23
|
const node = createAztecNodeClient(nodeUrl);
|
|
20
24
|
const wallet = await EmbeddedWallet.create(node);
|
|
21
25
|
|
|
22
|
-
let
|
|
26
|
+
let accountManagers: AccountManager[] = [];
|
|
23
27
|
if (testAccounts) {
|
|
24
|
-
log('setupL2Contracts:
|
|
28
|
+
log('setupL2Contracts: Creating test accounts...');
|
|
25
29
|
const initialAccountsData = await getInitialTestAccountsData();
|
|
26
|
-
|
|
30
|
+
accountManagers = await createFundedInitializerlessAccounts(wallet, initialAccountsData);
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
if (json) {
|
|
30
34
|
const toPrint: Record<string, AztecAddress> = { ...ProtocolContractAddress };
|
|
31
|
-
|
|
35
|
+
accountManagers.forEach((a, i) => {
|
|
32
36
|
toPrint[`testAccount${i}`] = a.address;
|
|
33
37
|
});
|
|
34
38
|
log(JSON.stringify(toPrint, null, 2));
|
|
@@ -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
|
}
|
|
@@ -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) {
|