@aztec/cli 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107
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/README.md +2 -428
- package/dest/cmds/aztec_node/block_number.d.ts +3 -0
- package/dest/cmds/aztec_node/block_number.d.ts.map +1 -0
- package/dest/cmds/aztec_node/block_number.js +10 -0
- package/dest/cmds/aztec_node/get_block.d.ts +3 -0
- package/dest/cmds/aztec_node/get_block.d.ts.map +1 -0
- package/dest/cmds/aztec_node/get_block.js +10 -0
- package/dest/cmds/aztec_node/get_current_base_fee.d.ts +3 -0
- package/dest/cmds/aztec_node/get_current_base_fee.d.ts.map +1 -0
- package/dest/cmds/aztec_node/get_current_base_fee.js +7 -0
- package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts +5 -0
- package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts.map +1 -0
- package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.js +12 -0
- package/dest/cmds/aztec_node/get_logs.d.ts +7 -0
- package/dest/cmds/aztec_node/get_logs.d.ts.map +1 -0
- package/dest/cmds/{pxe → aztec_node}/get_logs.js +4 -4
- package/dest/cmds/aztec_node/get_node_info.d.ts +3 -0
- package/dest/cmds/aztec_node/get_node_info.d.ts.map +1 -0
- package/dest/cmds/{pxe → aztec_node}/get_node_info.js +3 -8
- package/dest/cmds/aztec_node/index.d.ts +4 -0
- package/dest/cmds/aztec_node/index.d.ts.map +1 -0
- package/dest/cmds/aztec_node/index.js +28 -0
- package/dest/cmds/contracts/index.d.ts +1 -1
- package/dest/cmds/contracts/inspect_contract.d.ts +1 -1
- package/dest/cmds/contracts/inspect_contract.d.ts.map +1 -1
- package/dest/cmds/contracts/inspect_contract.js +4 -10
- package/dest/cmds/contracts/parse_parameter_struct.d.ts +1 -1
- package/dest/cmds/infrastructure/index.d.ts +3 -3
- package/dest/cmds/infrastructure/index.d.ts.map +1 -1
- package/dest/cmds/infrastructure/index.js +7 -9
- package/dest/cmds/infrastructure/sequencers.d.ts +3 -5
- package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -1
- package/dest/cmds/infrastructure/sequencers.js +15 -7
- package/dest/cmds/infrastructure/setup_l2_contract.d.ts +2 -2
- package/dest/cmds/infrastructure/setup_l2_contract.d.ts.map +1 -1
- package/dest/cmds/infrastructure/setup_l2_contract.js +10 -25
- package/dest/cmds/l1/advance_epoch.d.ts +2 -2
- package/dest/cmds/l1/advance_epoch.d.ts.map +1 -1
- package/dest/cmds/l1/advance_epoch.js +6 -5
- package/dest/cmds/l1/assume_proven_through.d.ts +2 -2
- package/dest/cmds/l1/assume_proven_through.d.ts.map +1 -1
- package/dest/cmds/l1/assume_proven_through.js +8 -6
- package/dest/cmds/l1/bridge_erc20.d.ts +2 -2
- package/dest/cmds/l1/bridge_erc20.d.ts.map +1 -1
- package/dest/cmds/l1/bridge_erc20.js +3 -2
- package/dest/cmds/l1/create_l1_account.d.ts +1 -1
- package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts +4 -0
- package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts.map +1 -0
- package/dest/cmds/l1/{deploy_l1_contracts.js → deploy_l1_contracts_cmd.js} +42 -7
- package/dest/cmds/l1/deploy_new_rollup.d.ts +4 -4
- package/dest/cmds/l1/deploy_new_rollup.d.ts.map +1 -1
- package/dest/cmds/l1/deploy_new_rollup.js +5 -5
- package/dest/cmds/l1/get_l1_addresses.d.ts +2 -2
- package/dest/cmds/l1/get_l1_addresses.d.ts.map +1 -1
- package/dest/cmds/l1/get_l1_addresses.js +5 -2
- package/dest/cmds/l1/get_l1_balance.d.ts +1 -1
- package/dest/cmds/l1/get_l1_balance.js +4 -2
- package/dest/cmds/l1/governance_utils.d.ts +5 -5
- package/dest/cmds/l1/governance_utils.d.ts.map +1 -1
- package/dest/cmds/l1/governance_utils.js +3 -1
- package/dest/cmds/l1/index.d.ts +1 -2
- package/dest/cmds/l1/index.d.ts.map +1 -1
- package/dest/cmds/l1/index.js +22 -36
- package/dest/cmds/l1/prover_stats.d.ts +1 -1
- package/dest/cmds/l1/prover_stats.d.ts.map +1 -1
- package/dest/cmds/l1/prover_stats.js +32 -30
- package/dest/cmds/l1/trigger_seed_snapshot.d.ts +2 -2
- package/dest/cmds/l1/trigger_seed_snapshot.d.ts.map +1 -1
- package/dest/cmds/l1/trigger_seed_snapshot.js +2 -1
- package/dest/cmds/l1/update_l1_validators.d.ts +10 -5
- package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
- package/dest/cmds/l1/update_l1_validators.js +74 -9
- package/dest/cmds/misc/compute_selector.d.ts +1 -1
- package/dest/cmds/misc/example_contracts.d.ts +1 -1
- package/dest/cmds/misc/generate_bootnode_enr.d.ts +1 -1
- package/dest/cmds/misc/generate_p2p_private_key.d.ts +1 -1
- package/dest/cmds/misc/generate_secret_and_hash.d.ts +1 -1
- package/dest/cmds/misc/generate_secret_and_hash.js +2 -2
- package/dest/cmds/misc/generate_secret_key.d.ts +2 -2
- package/dest/cmds/misc/generate_secret_key.d.ts.map +1 -1
- package/dest/cmds/misc/generate_secret_key.js +1 -1
- package/dest/cmds/misc/get_canonical_sponsored_fpc_address.d.ts +1 -1
- package/dest/cmds/misc/index.d.ts +1 -1
- package/dest/cmds/misc/index.d.ts.map +1 -1
- package/dest/cmds/misc/index.js +1 -1
- package/dest/cmds/misc/update/common.d.ts +1 -1
- package/dest/cmds/misc/update/github.d.ts +1 -1
- package/dest/cmds/misc/update/noir.d.ts +1 -1
- package/dest/cmds/misc/update/npm.d.ts +1 -1
- package/dest/cmds/misc/update/npm.js +1 -1
- package/dest/cmds/misc/update/utils.d.ts +1 -1
- package/dest/cmds/misc/update.d.ts +1 -1
- package/dest/cmds/validator_keys/add.d.ts +5 -0
- package/dest/cmds/validator_keys/add.d.ts.map +1 -0
- package/dest/cmds/validator_keys/add.js +83 -0
- package/dest/cmds/validator_keys/generate_bls_keypair.d.ts +12 -0
- package/dest/cmds/validator_keys/generate_bls_keypair.d.ts.map +1 -0
- package/dest/cmds/validator_keys/generate_bls_keypair.js +27 -0
- package/dest/cmds/validator_keys/index.d.ts +4 -0
- package/dest/cmds/validator_keys/index.d.ts.map +1 -0
- package/dest/cmds/validator_keys/index.js +32 -0
- package/dest/cmds/validator_keys/new.d.ts +29 -0
- package/dest/cmds/validator_keys/new.d.ts.map +1 -0
- package/dest/cmds/validator_keys/new.js +134 -0
- package/dest/cmds/validator_keys/shared.d.ts +68 -0
- package/dest/cmds/validator_keys/shared.d.ts.map +1 -0
- package/dest/cmds/validator_keys/shared.js +274 -0
- package/dest/cmds/validator_keys/staker.d.ts +38 -0
- package/dest/cmds/validator_keys/staker.d.ts.map +1 -0
- package/dest/cmds/validator_keys/staker.js +210 -0
- package/dest/cmds/validator_keys/utils.d.ts +25 -0
- package/dest/cmds/validator_keys/utils.d.ts.map +1 -0
- package/dest/cmds/validator_keys/utils.js +52 -0
- package/dest/config/cached_fetch.d.ts +18 -0
- package/dest/config/cached_fetch.d.ts.map +1 -0
- package/dest/config/cached_fetch.js +54 -0
- package/dest/config/chain_l2_config.d.ts +41 -0
- package/dest/config/chain_l2_config.d.ts.map +1 -0
- package/dest/config/chain_l2_config.js +524 -0
- package/dest/config/enrich_env.d.ts +4 -0
- package/dest/config/enrich_env.d.ts.map +1 -0
- package/dest/config/enrich_env.js +12 -0
- package/dest/config/get_l1_config.d.ts +9 -0
- package/dest/config/get_l1_config.d.ts.map +1 -0
- package/dest/config/get_l1_config.js +24 -0
- package/dest/config/index.d.ts +5 -0
- package/dest/config/index.d.ts.map +1 -0
- package/dest/config/index.js +4 -0
- package/dest/config/network_config.d.ts +22 -0
- package/dest/config/network_config.d.ts.map +1 -0
- package/dest/config/network_config.js +115 -0
- package/dest/utils/aztec.d.ts +8 -20
- package/dest/utils/aztec.d.ts.map +1 -1
- package/dest/utils/aztec.js +22 -67
- package/dest/utils/commands.d.ts +21 -12
- package/dest/utils/commands.d.ts.map +1 -1
- package/dest/utils/commands.js +38 -11
- package/dest/utils/encoding.d.ts +1 -1
- package/dest/utils/encoding.js +1 -1
- package/dest/utils/github.d.ts +1 -1
- package/dest/utils/index.d.ts +1 -1
- package/dest/utils/inspect.d.ts +5 -11
- package/dest/utils/inspect.d.ts.map +1 -1
- package/dest/utils/inspect.js +13 -95
- package/dest/utils/setup_contracts.d.ts +2 -4
- package/dest/utils/setup_contracts.d.ts.map +1 -1
- package/dest/utils/setup_contracts.js +2 -22
- package/package.json +43 -28
- package/public_include_metric_prefixes.json +1 -0
- package/src/cmds/aztec_node/block_number.ts +9 -0
- package/src/cmds/aztec_node/get_block.ts +11 -0
- package/src/cmds/aztec_node/get_current_base_fee.ts +9 -0
- package/src/cmds/aztec_node/get_l1_to_l2_message_witness.ts +27 -0
- package/src/cmds/{pxe → aztec_node}/get_logs.ts +11 -9
- package/src/cmds/{pxe → aztec_node}/get_node_info.ts +5 -16
- package/src/cmds/aztec_node/index.ts +87 -0
- package/src/cmds/contracts/inspect_contract.ts +4 -11
- package/src/cmds/infrastructure/index.ts +7 -18
- package/src/cmds/infrastructure/sequencers.ts +13 -11
- package/src/cmds/infrastructure/setup_l2_contract.ts +13 -30
- package/src/cmds/l1/advance_epoch.ts +6 -5
- package/src/cmds/l1/assume_proven_through.ts +10 -6
- package/src/cmds/l1/bridge_erc20.ts +5 -2
- package/src/cmds/l1/{deploy_l1_contracts.ts → deploy_l1_contracts_cmd.ts} +44 -24
- package/src/cmds/l1/deploy_new_rollup.ts +6 -9
- package/src/cmds/l1/get_l1_addresses.ts +5 -3
- package/src/cmds/l1/get_l1_balance.ts +2 -2
- package/src/cmds/l1/governance_utils.ts +3 -8
- package/src/cmds/l1/index.ts +28 -66
- package/src/cmds/l1/prover_stats.ts +42 -31
- package/src/cmds/l1/trigger_seed_snapshot.ts +2 -1
- package/src/cmds/l1/update_l1_validators.ts +88 -18
- package/src/cmds/misc/generate_secret_and_hash.ts +2 -2
- package/src/cmds/misc/generate_secret_key.ts +1 -1
- package/src/cmds/misc/index.ts +1 -1
- package/src/cmds/misc/update/npm.ts +1 -1
- package/src/cmds/validator_keys/add.ts +123 -0
- package/src/cmds/validator_keys/generate_bls_keypair.ts +34 -0
- package/src/cmds/validator_keys/index.ts +142 -0
- package/src/cmds/validator_keys/new.ts +207 -0
- package/src/cmds/validator_keys/shared.ts +326 -0
- package/src/cmds/validator_keys/staker.ts +301 -0
- package/src/cmds/validator_keys/utils.ts +81 -0
- package/src/config/cached_fetch.ts +67 -0
- package/src/config/chain_l2_config.ts +694 -0
- package/src/config/enrich_env.ts +15 -0
- package/src/config/get_l1_config.ts +31 -0
- package/src/config/index.ts +4 -0
- package/src/config/network_config.ts +147 -0
- package/src/utils/aztec.ts +27 -118
- package/src/utils/commands.ts +52 -15
- package/src/utils/encoding.ts +1 -1
- package/src/utils/inspect.ts +19 -111
- package/src/utils/setup_contracts.ts +4 -43
- package/dest/cmds/devnet/bootstrap_network.d.ts +0 -3
- package/dest/cmds/devnet/bootstrap_network.d.ts.map +0 -1
- package/dest/cmds/devnet/bootstrap_network.js +0 -216
- package/dest/cmds/devnet/faucet.d.ts +0 -4
- package/dest/cmds/devnet/faucet.d.ts.map +0 -1
- package/dest/cmds/devnet/faucet.js +0 -26
- package/dest/cmds/devnet/index.d.ts +0 -4
- package/dest/cmds/devnet/index.d.ts.map +0 -1
- package/dest/cmds/devnet/index.js +0 -14
- package/dest/cmds/l1/deploy_l1_contracts.d.ts +0 -4
- package/dest/cmds/l1/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/cmds/pxe/add_contract.d.ts +0 -5
- package/dest/cmds/pxe/add_contract.d.ts.map +0 -1
- package/dest/cmds/pxe/add_contract.js +0 -29
- package/dest/cmds/pxe/block_number.d.ts +0 -3
- package/dest/cmds/pxe/block_number.d.ts.map +0 -1
- package/dest/cmds/pxe/block_number.js +0 -10
- package/dest/cmds/pxe/get_account.d.ts +0 -4
- package/dest/cmds/pxe/get_account.d.ts.map +0 -1
- package/dest/cmds/pxe/get_account.js +0 -10
- package/dest/cmds/pxe/get_accounts.d.ts +0 -3
- package/dest/cmds/pxe/get_accounts.d.ts.map +0 -1
- package/dest/cmds/pxe/get_accounts.js +0 -25
- package/dest/cmds/pxe/get_block.d.ts +0 -3
- package/dest/cmds/pxe/get_block.d.ts.map +0 -1
- package/dest/cmds/pxe/get_block.js +0 -9
- package/dest/cmds/pxe/get_contract_data.d.ts +0 -4
- package/dest/cmds/pxe/get_contract_data.d.ts.map +0 -1
- package/dest/cmds/pxe/get_contract_data.js +0 -31
- package/dest/cmds/pxe/get_current_base_fee.d.ts +0 -3
- package/dest/cmds/pxe/get_current_base_fee.d.ts.map +0 -1
- package/dest/cmds/pxe/get_current_base_fee.js +0 -7
- package/dest/cmds/pxe/get_l1_to_l2_message_witness.d.ts +0 -4
- package/dest/cmds/pxe/get_l1_to_l2_message_witness.d.ts.map +0 -1
- package/dest/cmds/pxe/get_l1_to_l2_message_witness.js +0 -11
- package/dest/cmds/pxe/get_logs.d.ts +0 -4
- package/dest/cmds/pxe/get_logs.d.ts.map +0 -1
- package/dest/cmds/pxe/get_node_info.d.ts +0 -3
- package/dest/cmds/pxe/get_node_info.d.ts.map +0 -1
- package/dest/cmds/pxe/get_pxe_info.d.ts +0 -3
- package/dest/cmds/pxe/get_pxe_info.d.ts.map +0 -1
- package/dest/cmds/pxe/get_pxe_info.js +0 -11
- package/dest/cmds/pxe/index.d.ts +0 -4
- package/dest/cmds/pxe/index.d.ts.map +0 -1
- package/dest/cmds/pxe/index.js +0 -55
- package/src/cmds/devnet/bootstrap_network.ts +0 -321
- package/src/cmds/devnet/faucet.ts +0 -33
- package/src/cmds/devnet/index.ts +0 -60
- package/src/cmds/pxe/add_contract.ts +0 -41
- package/src/cmds/pxe/block_number.ts +0 -9
- package/src/cmds/pxe/get_account.ts +0 -16
- package/src/cmds/pxe/get_accounts.ts +0 -35
- package/src/cmds/pxe/get_block.ts +0 -10
- package/src/cmds/pxe/get_contract_data.ts +0 -51
- package/src/cmds/pxe/get_current_base_fee.ts +0 -9
- package/src/cmds/pxe/get_l1_to_l2_message_witness.ts +0 -25
- package/src/cmds/pxe/get_pxe_info.ts +0 -13
- package/src/cmds/pxe/index.ts +0 -170
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { retrieveL2ProofVerifiedEvents } from '@aztec/archiver';
|
|
2
|
-
import {
|
|
2
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
|
+
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
3
4
|
import { compactArray, mapValues, unique } from '@aztec/foundation/collection';
|
|
4
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
6
|
import { type LogFn, type Logger, createLogger } from '@aztec/foundation/log';
|
|
@@ -46,7 +47,10 @@ export async function proverStats(opts: {
|
|
|
46
47
|
.then(a => a.rollupAddress);
|
|
47
48
|
|
|
48
49
|
const chain = createEthereumChain(l1RpcUrls, chainId).chainInfo;
|
|
49
|
-
const publicClient = createPublicClient({
|
|
50
|
+
const publicClient = createPublicClient({
|
|
51
|
+
chain,
|
|
52
|
+
transport: fallback(l1RpcUrls.map(url => http(url, { batch: false }))),
|
|
53
|
+
});
|
|
50
54
|
const lastBlockNum = endBlock ?? (await publicClient.getBlockNumber());
|
|
51
55
|
debugLog.verbose(`Querying events on rollup at ${rollup.toString()} from ${startBlock} up to ${lastBlockNum}`);
|
|
52
56
|
|
|
@@ -55,33 +59,40 @@ export async function proverStats(opts: {
|
|
|
55
59
|
|
|
56
60
|
// If we only care for raw logs, output them
|
|
57
61
|
if (rawLogs && !provingTimeout) {
|
|
58
|
-
log(`l1_block_number,
|
|
62
|
+
log(`l1_block_number, checkpoint_number, prover_id, tx_hash`);
|
|
59
63
|
for (const event of events) {
|
|
60
|
-
const { l1BlockNumber,
|
|
61
|
-
log(`${l1BlockNumber}, ${
|
|
64
|
+
const { l1BlockNumber, checkpointNumber, proverId, txHash } = event;
|
|
65
|
+
log(`${l1BlockNumber}, ${checkpointNumber}, ${proverId}, ${txHash}`);
|
|
62
66
|
}
|
|
63
67
|
return;
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
// If we don't have a proving timeout, we can just count the number of unique
|
|
70
|
+
// If we don't have a proving timeout, we can just count the number of unique checkpoints per prover
|
|
67
71
|
if (!provingTimeout) {
|
|
68
72
|
const stats = groupBy(events, 'proverId');
|
|
69
|
-
log(`prover_id,
|
|
73
|
+
log(`prover_id, total_checkpoints_proven`);
|
|
70
74
|
for (const proverId in stats) {
|
|
71
|
-
const
|
|
72
|
-
log(`${proverId}, ${
|
|
75
|
+
const uniqueCheckpoints = new Set(stats[proverId].map(e => e.checkpointNumber));
|
|
76
|
+
log(`${proverId}, ${uniqueCheckpoints.size}`);
|
|
73
77
|
}
|
|
74
78
|
return;
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
// But if we do, fetch the events for each
|
|
78
|
-
const
|
|
81
|
+
// But if we do, fetch the events for each checkpoint submitted, so we can look up their timestamp
|
|
82
|
+
const checkpointEvents = await getCheckpointProposedEvents(
|
|
83
|
+
startBlock,
|
|
84
|
+
lastBlockNum,
|
|
85
|
+
batchSize,
|
|
86
|
+
debugLog,
|
|
87
|
+
publicClient,
|
|
88
|
+
rollup,
|
|
89
|
+
);
|
|
79
90
|
debugLog.verbose(
|
|
80
|
-
`First
|
|
91
|
+
`First checkpoint within range is ${checkpointEvents[0]?.args.checkpointNumber} at L1 block ${checkpointEvents[0]?.blockNumber}`,
|
|
81
92
|
);
|
|
82
93
|
|
|
83
94
|
// Get the timestamps for every block on every log, both for proof and block submissions
|
|
84
|
-
const l1BlockNumbers = unique([...events.map(e => e.l1BlockNumber), ...
|
|
95
|
+
const l1BlockNumbers = unique([...events.map(e => e.l1BlockNumber), ...checkpointEvents.map(e => e.blockNumber)]);
|
|
85
96
|
const l1BlockTimestamps: Record<string, bigint> = {};
|
|
86
97
|
for (const l1Batch of chunk(l1BlockNumbers, Number(batchSize))) {
|
|
87
98
|
const blocks = await Promise.all(
|
|
@@ -93,44 +104,44 @@ export async function proverStats(opts: {
|
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
106
|
|
|
96
|
-
// Map from
|
|
97
|
-
const
|
|
98
|
-
for (const
|
|
99
|
-
|
|
107
|
+
// Map from checkpoint number to the l1 block in which it was submitted
|
|
108
|
+
const checkpointSubmissions: Record<string, bigint> = {};
|
|
109
|
+
for (const checkpointEvent of checkpointEvents) {
|
|
110
|
+
checkpointSubmissions[checkpointEvent.args.checkpointNumber!.toString()] = checkpointEvent.blockNumber;
|
|
100
111
|
}
|
|
101
112
|
|
|
102
113
|
// If we want raw logs, output them
|
|
103
114
|
if (rawLogs) {
|
|
104
|
-
log(`l1_block_number,
|
|
115
|
+
log(`l1_block_number, checkpoint_number, checkpoint_submission_timestamp, proof_timestamp, prover_id, tx_hash`);
|
|
105
116
|
for (const event of events) {
|
|
106
|
-
const { l1BlockNumber,
|
|
107
|
-
const uploadedBlockNumber =
|
|
117
|
+
const { l1BlockNumber, checkpointNumber, proverId, txHash } = event;
|
|
118
|
+
const uploadedBlockNumber = checkpointSubmissions[checkpointNumber.toString()];
|
|
108
119
|
if (!uploadedBlockNumber) {
|
|
109
120
|
continue;
|
|
110
121
|
}
|
|
111
122
|
const uploadedTimestamp = l1BlockTimestamps[uploadedBlockNumber.toString()];
|
|
112
123
|
const provenTimestamp = l1BlockTimestamps[l1BlockNumber.toString()];
|
|
113
|
-
log(`${l1BlockNumber}, ${
|
|
124
|
+
log(`${l1BlockNumber}, ${checkpointNumber}, ${uploadedTimestamp}, ${provenTimestamp}, ${proverId}, ${txHash}`);
|
|
114
125
|
}
|
|
115
126
|
return;
|
|
116
127
|
}
|
|
117
128
|
|
|
118
129
|
// Or calculate stats per prover
|
|
119
|
-
const stats = mapValues(groupBy(events, 'proverId'), (
|
|
130
|
+
const stats = mapValues(groupBy(events, 'proverId'), (checkpoints, proverId) =>
|
|
120
131
|
compactArray(
|
|
121
|
-
|
|
132
|
+
checkpoints.map(e => {
|
|
122
133
|
const provenTimestamp = l1BlockTimestamps[e.l1BlockNumber.toString()];
|
|
123
|
-
const uploadedBlockNumber =
|
|
134
|
+
const uploadedBlockNumber = checkpointSubmissions[e.checkpointNumber.toString()];
|
|
124
135
|
if (!uploadedBlockNumber) {
|
|
125
136
|
debugLog.verbose(
|
|
126
|
-
`Skipping ${proverId}'s proof for
|
|
137
|
+
`Skipping ${proverId}'s proof for checkpoint ${e.checkpointNumber} as it was before the start block`,
|
|
127
138
|
);
|
|
128
139
|
return undefined;
|
|
129
140
|
}
|
|
130
141
|
const uploadedTimestamp = l1BlockTimestamps[uploadedBlockNumber.toString()];
|
|
131
142
|
const provingTime = provenTimestamp - uploadedTimestamp;
|
|
132
143
|
debugLog.debug(
|
|
133
|
-
`prover=${e.proverId}
|
|
144
|
+
`prover=${e.proverId} checkpointNumber=${e.checkpointNumber} uploaded=${uploadedTimestamp} proven=${provenTimestamp} time=${provingTime}`,
|
|
134
145
|
);
|
|
135
146
|
return { provenTimestamp, uploadedTimestamp, provingTime, ...e };
|
|
136
147
|
}),
|
|
@@ -141,8 +152,8 @@ export async function proverStats(opts: {
|
|
|
141
152
|
for (const proverId in stats) {
|
|
142
153
|
const blocks = stats[proverId];
|
|
143
154
|
const withinTimeout = blocks.filter(b => b.provingTime <= provingTimeout);
|
|
144
|
-
const uniqueBlocksWithinTimeout = new Set(withinTimeout.map(e => e.
|
|
145
|
-
const uniqueBlocks = new Set(blocks.map(e => e.
|
|
155
|
+
const uniqueBlocksWithinTimeout = new Set(withinTimeout.map(e => e.checkpointNumber));
|
|
156
|
+
const uniqueBlocks = new Set(blocks.map(e => e.checkpointNumber));
|
|
146
157
|
const avgProvingTime =
|
|
147
158
|
blocks.length === 0 ? 0 : Math.ceil(Number(blocks.reduce((acc, b) => acc + b.provingTime, 0n)) / blocks.length);
|
|
148
159
|
|
|
@@ -171,7 +182,7 @@ async function getL2ProofVerifiedEvents(
|
|
|
171
182
|
return events;
|
|
172
183
|
}
|
|
173
184
|
|
|
174
|
-
async function
|
|
185
|
+
async function getCheckpointProposedEvents(
|
|
175
186
|
startBlock: bigint,
|
|
176
187
|
lastBlockNum: bigint,
|
|
177
188
|
batchSize: bigint,
|
|
@@ -188,14 +199,14 @@ async function getL2BlockEvents(
|
|
|
188
199
|
address: getAddress(rollup.toString()),
|
|
189
200
|
event: getAbiItem({
|
|
190
201
|
abi: RollupAbi,
|
|
191
|
-
name: '
|
|
202
|
+
name: 'CheckpointProposed',
|
|
192
203
|
}),
|
|
193
204
|
fromBlock: blockNum,
|
|
194
205
|
toBlock: end,
|
|
195
206
|
});
|
|
196
207
|
|
|
197
208
|
events.push(...newEvents);
|
|
198
|
-
debugLog.verbose(`Got ${newEvents.length} events querying
|
|
209
|
+
debugLog.verbose(`Got ${newEvents.length} events querying checkpoints submitted from block ${blockNum} to ${end}`);
|
|
199
210
|
blockNum += batchSize;
|
|
200
211
|
}
|
|
201
212
|
return events;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { createEthereumChain
|
|
1
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
2
|
+
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
2
3
|
import type { LogFn } from '@aztec/foundation/log';
|
|
3
4
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
4
5
|
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
createL1TxUtilsFromViemWallet,
|
|
7
|
-
getL1ContractsConfigEnvVars,
|
|
8
|
-
getPublicClient,
|
|
9
|
-
isAnvilTestChain,
|
|
10
|
-
} from '@aztec/ethereum';
|
|
1
|
+
import { createEthereumChain, isAnvilTestChain } from '@aztec/ethereum/chain';
|
|
2
|
+
import { createExtendedL1Client, getPublicClient } from '@aztec/ethereum/client';
|
|
3
|
+
import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
|
|
4
|
+
import { GSEContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
5
|
+
import { createL1TxUtilsFromViemWallet } from '@aztec/ethereum/l1-tx-utils';
|
|
11
6
|
import { EthCheatCodes } from '@aztec/ethereum/test';
|
|
12
7
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
13
8
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
9
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
14
10
|
import { RollupAbi, StakingAssetHandlerAbi } from '@aztec/l1-artifacts';
|
|
15
11
|
import { ZkPassportProofParams } from '@aztec/stdlib/zkpassport';
|
|
16
12
|
|
|
@@ -96,7 +92,7 @@ export async function addL1Validator({
|
|
|
96
92
|
|
|
97
93
|
const registrationTuple = await gse.makeRegistrationTuple(blsSecretKey);
|
|
98
94
|
|
|
99
|
-
const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, debugLogger);
|
|
95
|
+
const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, { logger: debugLogger });
|
|
100
96
|
const proofParamsObj = ZkPassportProofParams.fromBuffer(proofParams);
|
|
101
97
|
const merkleProofArray = merkleProof.map(proof => addLeadingHex(proof));
|
|
102
98
|
|
|
@@ -120,7 +116,81 @@ export async function addL1Validator({
|
|
|
120
116
|
await l1Client.waitForTransactionReceipt({ hash: receipt.transactionHash });
|
|
121
117
|
if (isAnvilTestChain(chainId)) {
|
|
122
118
|
dualLog(`Funding validator on L1`);
|
|
123
|
-
const cheatCodes = new EthCheatCodes(rpcUrls, debugLogger);
|
|
119
|
+
const cheatCodes = new EthCheatCodes(rpcUrls, new DateProvider(), debugLogger);
|
|
120
|
+
await cheatCodes.setBalance(attesterAddress, 10n ** 20n);
|
|
121
|
+
} else {
|
|
122
|
+
const balance = await l1Client.getBalance({ address: attesterAddress.toString() });
|
|
123
|
+
dualLog(`Validator balance: ${formatEther(balance)} ETH`);
|
|
124
|
+
if (balance === 0n) {
|
|
125
|
+
dualLog(`WARNING: Proposer has no balance. Remember to fund it!`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function addL1ValidatorViaRollup({
|
|
131
|
+
rpcUrls,
|
|
132
|
+
chainId,
|
|
133
|
+
privateKey,
|
|
134
|
+
mnemonic,
|
|
135
|
+
attesterAddress,
|
|
136
|
+
withdrawerAddress,
|
|
137
|
+
blsSecretKey,
|
|
138
|
+
moveWithLatestRollup,
|
|
139
|
+
rollupAddress,
|
|
140
|
+
log,
|
|
141
|
+
debugLogger,
|
|
142
|
+
}: RollupCommandArgs &
|
|
143
|
+
LoggerArgs & {
|
|
144
|
+
blsSecretKey: bigint; // scalar field element of BN254
|
|
145
|
+
attesterAddress: EthAddress;
|
|
146
|
+
moveWithLatestRollup: boolean;
|
|
147
|
+
}) {
|
|
148
|
+
const dualLog = makeDualLog(log, debugLogger);
|
|
149
|
+
const account = getAccount(privateKey, mnemonic);
|
|
150
|
+
const chain = createEthereumChain(rpcUrls, chainId);
|
|
151
|
+
const l1Client = createExtendedL1Client(rpcUrls, account, chain.chainInfo);
|
|
152
|
+
|
|
153
|
+
dualLog(`Adding validator ${attesterAddress} to rollup ${rollupAddress.toString()} via direct deposit`);
|
|
154
|
+
|
|
155
|
+
if (!withdrawerAddress) {
|
|
156
|
+
throw new Error(`Withdrawer address required`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const rollup = getContract({
|
|
160
|
+
address: rollupAddress.toString(),
|
|
161
|
+
abi: RollupAbi,
|
|
162
|
+
client: l1Client,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const gseAddress = await rollup.read.getGSE();
|
|
166
|
+
|
|
167
|
+
const gse = new GSEContract(l1Client, gseAddress);
|
|
168
|
+
|
|
169
|
+
const registrationTuple = await gse.makeRegistrationTuple(blsSecretKey);
|
|
170
|
+
|
|
171
|
+
const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, { logger: debugLogger });
|
|
172
|
+
|
|
173
|
+
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
174
|
+
to: rollupAddress.toString(),
|
|
175
|
+
data: encodeFunctionData({
|
|
176
|
+
abi: RollupAbi,
|
|
177
|
+
functionName: 'deposit',
|
|
178
|
+
args: [
|
|
179
|
+
attesterAddress.toString(),
|
|
180
|
+
withdrawerAddress.toString(),
|
|
181
|
+
registrationTuple.publicKeyInG1,
|
|
182
|
+
registrationTuple.publicKeyInG2,
|
|
183
|
+
registrationTuple.proofOfPossession,
|
|
184
|
+
moveWithLatestRollup,
|
|
185
|
+
],
|
|
186
|
+
}),
|
|
187
|
+
abi: StakingAssetHandlerAbi,
|
|
188
|
+
});
|
|
189
|
+
dualLog(`Transaction hash: ${receipt.transactionHash}`);
|
|
190
|
+
await l1Client.waitForTransactionReceipt({ hash: receipt.transactionHash });
|
|
191
|
+
if (isAnvilTestChain(chainId)) {
|
|
192
|
+
dualLog(`Funding validator on L1`);
|
|
193
|
+
const cheatCodes = new EthCheatCodes(rpcUrls, new DateProvider(), debugLogger);
|
|
124
194
|
await cheatCodes.setBalance(attesterAddress, 10n ** 20n);
|
|
125
195
|
} else {
|
|
126
196
|
const balance = await l1Client.getBalance({ address: attesterAddress.toString() });
|
|
@@ -145,7 +215,7 @@ export async function removeL1Validator({
|
|
|
145
215
|
const account = getAccount(privateKey, mnemonic);
|
|
146
216
|
const chain = createEthereumChain(rpcUrls, chainId);
|
|
147
217
|
const l1Client = createExtendedL1Client(rpcUrls, account, chain.chainInfo);
|
|
148
|
-
const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, debugLogger);
|
|
218
|
+
const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, { logger: debugLogger });
|
|
149
219
|
|
|
150
220
|
dualLog(`Removing validator ${validatorAddress.toString()} from rollup ${rollupAddress.toString()}`);
|
|
151
221
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
@@ -172,7 +242,7 @@ export async function pruneRollup({
|
|
|
172
242
|
const account = getAccount(privateKey, mnemonic);
|
|
173
243
|
const chain = createEthereumChain(rpcUrls, chainId);
|
|
174
244
|
const l1Client = createExtendedL1Client(rpcUrls, account, chain.chainInfo);
|
|
175
|
-
const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, debugLogger);
|
|
245
|
+
const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, { logger: debugLogger });
|
|
176
246
|
|
|
177
247
|
dualLog(`Trying prune`);
|
|
178
248
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
@@ -201,7 +271,7 @@ export async function fastForwardEpochs({
|
|
|
201
271
|
client: publicClient,
|
|
202
272
|
});
|
|
203
273
|
|
|
204
|
-
const cheatCodes = new EthCheatCodes(rpcUrls, debugLogger);
|
|
274
|
+
const cheatCodes = new EthCheatCodes(rpcUrls, new DateProvider(), debugLogger);
|
|
205
275
|
const currentSlot = await rollup.read.getCurrentSlot();
|
|
206
276
|
const l2SlotsInEpoch = await rollup.read.getEpochDuration();
|
|
207
277
|
const timestamp = await rollup.read.getTimestampForSlot([currentSlot + l2SlotsInEpoch * numEpochs]);
|
|
@@ -224,9 +294,9 @@ export async function debugRollup({ rpcUrls, chainId, rollupAddress, log }: Roll
|
|
|
224
294
|
const publicClient = getPublicClient({ l1RpcUrls: rpcUrls, l1ChainId: chainId });
|
|
225
295
|
const rollup = new RollupContract(publicClient, rollupAddress);
|
|
226
296
|
|
|
227
|
-
const pendingNum = await rollup.
|
|
297
|
+
const pendingNum = await rollup.getCheckpointNumber();
|
|
228
298
|
log(`Pending block num: ${pendingNum}`);
|
|
229
|
-
const provenNum = await rollup.
|
|
299
|
+
const provenNum = await rollup.getProvenCheckpointNumber();
|
|
230
300
|
log(`Proven block num: ${provenNum}`);
|
|
231
301
|
const validators = await rollup.getAttesters();
|
|
232
302
|
log(`Validators: ${validators.map(v => v.toString()).join(', ')}`);
|
|
@@ -234,7 +304,7 @@ export async function debugRollup({ rpcUrls, chainId, rollupAddress, log }: Roll
|
|
|
234
304
|
log(`Committee: ${committee?.map(v => v.toString()).join(', ')}`);
|
|
235
305
|
const archive = await rollup.archive();
|
|
236
306
|
log(`Archive: ${archive}`);
|
|
237
|
-
const epochNum = await rollup.
|
|
307
|
+
const epochNum = await rollup.getCurrentEpochNumber();
|
|
238
308
|
log(`Current epoch: ${epochNum}`);
|
|
239
309
|
const slot = await rollup.getSlotNumber();
|
|
240
310
|
log(`Current slot: ${slot}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { computeSecretHash } from '@aztec/aztec.js';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { computeSecretHash } from '@aztec/aztec.js/crypto';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { LogFn } from '@aztec/foundation/log';
|
|
4
4
|
|
|
5
5
|
export async function generateSecretAndHash(log: LogFn) {
|
package/src/cmds/misc/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
-
import { printENR } from '@aztec/p2p/enr';
|
|
3
2
|
|
|
4
3
|
import type { Command } from 'commander';
|
|
5
4
|
|
|
@@ -49,6 +48,7 @@ export function injectCommands(program: Command, log: LogFn) {
|
|
|
49
48
|
.description('Decodes and ENR record')
|
|
50
49
|
.argument('<enr>', 'The encoded ENR string')
|
|
51
50
|
.action(async (enr: string) => {
|
|
51
|
+
const { printENR } = await import('@aztec/p2p/enr');
|
|
52
52
|
await printENR(enr, log);
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -9,7 +9,7 @@ import { type SemVer, parse } from 'semver';
|
|
|
9
9
|
import type { DependencyChanges } from './common.js';
|
|
10
10
|
import { atomicUpdateFile } from './utils.js';
|
|
11
11
|
|
|
12
|
-
const deprecatedNpmPackages = new Set<string>(['@aztec/cli', '@aztec/aztec-
|
|
12
|
+
const deprecatedNpmPackages = new Set<string>(['@aztec/cli', '@aztec/aztec-local-network']);
|
|
13
13
|
const npmDeprecationMessage = `
|
|
14
14
|
The following packages have been deprecated and will no longer be updated on the npm registry:
|
|
15
15
|
${Array.from(deprecatedNpmPackages)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
3
|
+
import { loadKeystoreFile } from '@aztec/node-keystore/loader';
|
|
4
|
+
import type { KeyStore } from '@aztec/node-keystore/types';
|
|
5
|
+
|
|
6
|
+
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
7
|
+
import { dirname, isAbsolute, join } from 'path';
|
|
8
|
+
import { generateMnemonic } from 'viem/accounts';
|
|
9
|
+
|
|
10
|
+
import type { NewValidatorKeystoreOptions } from './new.js';
|
|
11
|
+
import {
|
|
12
|
+
buildValidatorEntries,
|
|
13
|
+
logValidatorSummaries,
|
|
14
|
+
maybePrintJson,
|
|
15
|
+
writeBlsBn254ToFile,
|
|
16
|
+
writeEthJsonV3ToFile,
|
|
17
|
+
writeKeystoreFile,
|
|
18
|
+
} from './shared.js';
|
|
19
|
+
import { validateBlsPathOptions, validatePublisherOptions, validateRemoteSignerOptions } from './utils.js';
|
|
20
|
+
|
|
21
|
+
export type AddValidatorKeysOptions = NewValidatorKeystoreOptions;
|
|
22
|
+
|
|
23
|
+
export async function addValidatorKeys(existing: string, options: AddValidatorKeysOptions, log: LogFn) {
|
|
24
|
+
// validate bls-path inputs before proceeding with key generation
|
|
25
|
+
validateBlsPathOptions(options);
|
|
26
|
+
// validate publisher options
|
|
27
|
+
validatePublisherOptions(options);
|
|
28
|
+
// validate remote signer options
|
|
29
|
+
validateRemoteSignerOptions(options);
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
dataDir,
|
|
33
|
+
file,
|
|
34
|
+
count,
|
|
35
|
+
publisherCount = 0,
|
|
36
|
+
publishers,
|
|
37
|
+
mnemonic,
|
|
38
|
+
accountIndex = 0,
|
|
39
|
+
addressIndex,
|
|
40
|
+
ikm,
|
|
41
|
+
blsPath,
|
|
42
|
+
json,
|
|
43
|
+
feeRecipient: feeRecipientOpt,
|
|
44
|
+
coinbase: coinbaseOpt,
|
|
45
|
+
remoteSigner: remoteSignerOpt,
|
|
46
|
+
password,
|
|
47
|
+
encryptedKeystoreDir,
|
|
48
|
+
} = options;
|
|
49
|
+
|
|
50
|
+
const validatorCount = typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
|
|
51
|
+
const baseAddressIndex = addressIndex ?? 0;
|
|
52
|
+
|
|
53
|
+
const keystore: KeyStore = loadKeystoreFile(existing);
|
|
54
|
+
|
|
55
|
+
if (!keystore.validators || !Array.isArray(keystore.validators)) {
|
|
56
|
+
throw new Error('Invalid keystore: missing validators array');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const first = keystore.validators[0] ?? {};
|
|
60
|
+
const feeRecipient = feeRecipientOpt ?? first.feeRecipient;
|
|
61
|
+
if (!feeRecipient) {
|
|
62
|
+
throw new Error('feeRecipient is required (either present in existing file or via --fee-recipient)');
|
|
63
|
+
}
|
|
64
|
+
const coinbase = (coinbaseOpt as EthAddress | undefined) ?? (first.coinbase as EthAddress | undefined);
|
|
65
|
+
const derivedRemoteSigner = (first.attester as any)?.remoteSignerUrl || (first.attester as any)?.eth?.remoteSignerUrl;
|
|
66
|
+
const remoteSigner = remoteSignerOpt ?? derivedRemoteSigner;
|
|
67
|
+
|
|
68
|
+
// Ensure we always have a mnemonic for key derivation if none was provided
|
|
69
|
+
const mnemonicToUse = mnemonic ?? generateMnemonic(wordlist);
|
|
70
|
+
|
|
71
|
+
// If user explicitly provided --address-index, use it as-is. Otherwise, append after existing validators.
|
|
72
|
+
const effectiveBaseAddressIndex =
|
|
73
|
+
addressIndex === undefined ? baseAddressIndex + keystore.validators.length : baseAddressIndex;
|
|
74
|
+
|
|
75
|
+
const { validators, summaries } = await buildValidatorEntries({
|
|
76
|
+
validatorCount,
|
|
77
|
+
publisherCount,
|
|
78
|
+
publishers,
|
|
79
|
+
accountIndex,
|
|
80
|
+
baseAddressIndex: effectiveBaseAddressIndex,
|
|
81
|
+
mnemonic: mnemonicToUse,
|
|
82
|
+
ikm,
|
|
83
|
+
blsPath,
|
|
84
|
+
feeRecipient,
|
|
85
|
+
coinbase,
|
|
86
|
+
remoteSigner,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
keystore.validators.push(...validators);
|
|
90
|
+
|
|
91
|
+
// If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
|
|
92
|
+
if (password !== undefined) {
|
|
93
|
+
let targetDir: string;
|
|
94
|
+
if (encryptedKeystoreDir && encryptedKeystoreDir.length > 0) {
|
|
95
|
+
targetDir = encryptedKeystoreDir;
|
|
96
|
+
} else if (dataDir && dataDir.length > 0) {
|
|
97
|
+
targetDir = dataDir;
|
|
98
|
+
} else {
|
|
99
|
+
targetDir = dirname(existing);
|
|
100
|
+
}
|
|
101
|
+
await writeEthJsonV3ToFile(keystore.validators, { outDir: targetDir, password });
|
|
102
|
+
await writeBlsBn254ToFile(keystore.validators, { outDir: targetDir, password, blsPath });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let outputPath = existing;
|
|
106
|
+
if (file && file.length > 0) {
|
|
107
|
+
if (isAbsolute(file)) {
|
|
108
|
+
outputPath = file;
|
|
109
|
+
} else if (dataDir && dataDir.length > 0) {
|
|
110
|
+
outputPath = join(dataDir, file);
|
|
111
|
+
} else {
|
|
112
|
+
outputPath = join(dirname(existing), file);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
await writeKeystoreFile(outputPath, keystore);
|
|
117
|
+
|
|
118
|
+
if (!json) {
|
|
119
|
+
log(`Updated keystore ${outputPath} with ${validators.length} new validator(s)`);
|
|
120
|
+
logValidatorSummaries(log, summaries);
|
|
121
|
+
}
|
|
122
|
+
maybePrintJson(log, !!json, keystore as unknown as Record<string, any>);
|
|
123
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { deriveBlsPrivateKey } from '@aztec/foundation/crypto/bls';
|
|
2
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
3
|
+
|
|
4
|
+
import { writeFile } from 'fs/promises';
|
|
5
|
+
|
|
6
|
+
import { computeBlsPublicKeyCompressed, withValidatorIndex } from './shared.js';
|
|
7
|
+
import { defaultBlsPath } from './utils.js';
|
|
8
|
+
|
|
9
|
+
export type GenerateBlsKeypairOptions = {
|
|
10
|
+
mnemonic?: string;
|
|
11
|
+
ikm?: string;
|
|
12
|
+
blsPath?: string;
|
|
13
|
+
g2?: boolean;
|
|
14
|
+
compressed?: boolean;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
out?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export async function generateBlsKeypair(options: GenerateBlsKeypairOptions, log: LogFn) {
|
|
20
|
+
const { mnemonic, ikm, blsPath, compressed = true, json, out } = options;
|
|
21
|
+
const path = withValidatorIndex(blsPath ?? defaultBlsPath, 0);
|
|
22
|
+
const priv = deriveBlsPrivateKey(mnemonic, ikm, path);
|
|
23
|
+
const pub = await computeBlsPublicKeyCompressed(priv);
|
|
24
|
+
const result = { path, privateKey: priv, publicKey: pub, format: compressed ? 'compressed' : 'uncompressed' };
|
|
25
|
+
if (out) {
|
|
26
|
+
await writeFile(out, JSON.stringify(result, null, 2), { encoding: 'utf-8' });
|
|
27
|
+
if (!json) {
|
|
28
|
+
log(`Wrote BLS keypair to ${out}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (json || !out) {
|
|
32
|
+
log(JSON.stringify(result, null, 2));
|
|
33
|
+
}
|
|
34
|
+
}
|