@aztec/cli 0.0.1-fake-c83136db25 → 0.0.1-private.3d175340d2
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 +1 -1
- package/dest/cmds/aztec_node/block_number.d.ts +1 -1
- package/dest/cmds/aztec_node/block_number.js +1 -1
- package/dest/cmds/aztec_node/get_block.d.ts +1 -1
- package/dest/cmds/aztec_node/get_block.d.ts.map +1 -1
- package/dest/cmds/aztec_node/get_block.js +2 -1
- package/dest/cmds/aztec_node/get_current_min_fee.d.ts +3 -0
- package/dest/cmds/aztec_node/get_current_min_fee.d.ts.map +1 -0
- package/dest/cmds/aztec_node/{get_current_base_fee.js → get_current_min_fee.js} +2 -2
- package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts +1 -1
- package/dest/cmds/aztec_node/get_logs.d.ts +30 -3
- 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 +16 -6
- 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 +1 -1
- package/dest/cmds/infrastructure/index.d.ts.map +1 -1
- package/dest/cmds/infrastructure/index.js +0 -1
- package/dest/cmds/infrastructure/sequencers.d.ts +1 -2
- package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -1
- package/dest/cmds/infrastructure/sequencers.js +11 -4
- 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 +4 -3
- package/dest/cmds/l1/advance_epoch.d.ts +1 -1
- 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 -4
- package/dest/cmds/l1/bridge_erc20.d.ts +1 -1
- package/dest/cmds/l1/bridge_erc20.d.ts.map +1 -1
- package/dest/cmds/l1/bridge_erc20.js +2 -1
- 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/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} +39 -5
- 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 +4 -6
- package/dest/cmds/l1/get_l1_addresses.d.ts +1 -1
- 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 +17 -10
- 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 +7 -7
- package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
- package/dest/cmds/l1/update_l1_validators.js +58 -20
- 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 +1 -1
- package/dest/cmds/misc/generate_secret_key.d.ts +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 +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 +13 -38
- package/dest/config/chain_l2_config.d.ts.map +1 -1
- package/dest/config/chain_l2_config.js +35 -440
- package/dest/config/enrich_env.d.ts +1 -1
- package/dest/config/generated/networks.d.ts +221 -0
- package/dest/config/generated/networks.d.ts.map +1 -0
- package/dest/config/generated/networks.js +222 -0
- package/dest/config/get_l1_config.d.ts +3 -2
- package/dest/config/get_l1_config.d.ts.map +1 -1
- package/dest/config/get_l1_config.js +3 -1
- package/dest/config/index.d.ts +1 -1
- package/dest/config/network_config.d.ts +7 -4
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +70 -30
- package/dest/utils/aztec.d.ts +7 -14
- package/dest/utils/aztec.d.ts.map +1 -1
- package/dest/utils/aztec.js +19 -41
- package/dest/utils/commands.d.ts +30 -12
- package/dest/utils/commands.d.ts.map +1 -1
- package/dest/utils/commands.js +54 -16
- 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 +3 -2
- package/dest/utils/inspect.d.ts.map +1 -1
- package/dest/utils/inspect.js +10 -6
- package/dest/utils/setup_contracts.d.ts +1 -1
- package/package.json +47 -30
- package/public_include_metric_prefixes.json +1 -0
- package/src/cmds/aztec_node/block_number.ts +1 -1
- package/src/cmds/aztec_node/get_block.ts +2 -1
- package/src/cmds/aztec_node/{get_current_base_fee.ts → get_current_min_fee.ts} +2 -2
- package/src/cmds/aztec_node/get_logs.ts +70 -37
- package/src/cmds/aztec_node/get_node_info.ts +0 -2
- package/src/cmds/aztec_node/index.ts +16 -11
- package/src/cmds/contracts/inspect_contract.ts +4 -11
- package/src/cmds/infrastructure/index.ts +0 -1
- package/src/cmds/infrastructure/sequencers.ts +7 -5
- package/src/cmds/infrastructure/setup_l2_contract.ts +5 -4
- package/src/cmds/l1/assume_proven_through.ts +4 -4
- package/src/cmds/l1/bridge_erc20.ts +2 -1
- package/src/cmds/l1/compute_genesis_values.ts +29 -0
- package/src/cmds/l1/{deploy_l1_contracts.ts → deploy_l1_contracts_cmd.ts} +39 -23
- package/src/cmds/l1/deploy_new_rollup.ts +5 -12
- package/src/cmds/l1/get_l1_addresses.ts +4 -2
- 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 +30 -21
- 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 +52 -32
- package/src/cmds/misc/generate_secret_and_hash.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 +119 -31
- package/src/config/chain_l2_config.ts +36 -574
- package/src/config/generated/networks.ts +226 -0
- package/src/config/get_l1_config.ts +4 -1
- package/src/config/network_config.ts +80 -31
- package/src/utils/aztec.ts +30 -95
- package/src/utils/commands.ts +68 -16
- package/src/utils/encoding.ts +1 -1
- package/src/utils/inspect.ts +10 -7
- package/dest/cmds/aztec_node/get_current_base_fee.d.ts +0 -3
- package/dest/cmds/aztec_node/get_current_base_fee.d.ts.map +0 -1
- package/dest/cmds/l1/deploy_l1_contracts.d.ts +0 -4
- package/dest/cmds/l1/deploy_l1_contracts.d.ts.map +0 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { prettyPrintJSON } from '@aztec/cli/utils';
|
|
2
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
|
+
import { GSEContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
5
|
+
import { writeFile } from 'fs/promises';
|
|
6
|
+
import { basename, dirname, join } from 'path';
|
|
7
|
+
import { createPublicClient, fallback, http } from 'viem';
|
|
8
|
+
import { generateMnemonic, mnemonicToAccount } from 'viem/accounts';
|
|
9
|
+
import { buildValidatorEntries, logValidatorSummaries, maybePrintJson, resolveKeystoreOutputPath, writeBlsBn254ToFile, writeEthJsonV3ToFile, writeKeystoreFile } from './shared.js';
|
|
10
|
+
import { processAttesterAccounts } from './staker.js';
|
|
11
|
+
import { validateBlsPathOptions, validatePublisherOptions, validateRemoteSignerOptions, validateStakerOutputOptions } from './utils.js';
|
|
12
|
+
export async function newValidatorKeystore(options, log) {
|
|
13
|
+
// validate bls-path inputs before proceeding with key generation
|
|
14
|
+
validateBlsPathOptions(options);
|
|
15
|
+
// validate staker output options before proceeding with key generation
|
|
16
|
+
validateStakerOutputOptions(options);
|
|
17
|
+
// validate publisher options
|
|
18
|
+
validatePublisherOptions(options);
|
|
19
|
+
// validate remote signer options
|
|
20
|
+
validateRemoteSignerOptions(options);
|
|
21
|
+
const { dataDir, file, count, publisherCount = 0, publishers, json, coinbase, accountIndex = 0, addressIndex = 0, feeRecipient, remoteSigner, blsPath, ikm, mnemonic: _mnemonic, password, encryptedKeystoreDir, stakerOutput, gseAddress, l1RpcUrls, l1ChainId } = options;
|
|
22
|
+
const mnemonic = _mnemonic ?? generateMnemonic(wordlist);
|
|
23
|
+
if (!_mnemonic && !json) {
|
|
24
|
+
log('No mnemonic provided, generating new one...');
|
|
25
|
+
log(`Using new mnemonic:`);
|
|
26
|
+
log('');
|
|
27
|
+
log(mnemonic);
|
|
28
|
+
log('');
|
|
29
|
+
}
|
|
30
|
+
const validatorCount = typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
|
|
31
|
+
const { outputPath } = await resolveKeystoreOutputPath(dataDir, file);
|
|
32
|
+
const keystoreOutDir = dirname(outputPath);
|
|
33
|
+
const { validators, summaries } = await buildValidatorEntries({
|
|
34
|
+
validatorCount,
|
|
35
|
+
publisherCount,
|
|
36
|
+
publishers,
|
|
37
|
+
accountIndex,
|
|
38
|
+
baseAddressIndex: addressIndex,
|
|
39
|
+
mnemonic,
|
|
40
|
+
ikm,
|
|
41
|
+
blsPath,
|
|
42
|
+
feeRecipient,
|
|
43
|
+
coinbase,
|
|
44
|
+
remoteSigner
|
|
45
|
+
});
|
|
46
|
+
// If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
|
|
47
|
+
if (password !== undefined) {
|
|
48
|
+
const encryptedKeystoreOutDir = encryptedKeystoreDir && encryptedKeystoreDir.length > 0 ? encryptedKeystoreDir : keystoreOutDir;
|
|
49
|
+
await writeEthJsonV3ToFile(validators, {
|
|
50
|
+
outDir: encryptedKeystoreOutDir,
|
|
51
|
+
password
|
|
52
|
+
});
|
|
53
|
+
await writeBlsBn254ToFile(validators, {
|
|
54
|
+
outDir: encryptedKeystoreOutDir,
|
|
55
|
+
password
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const keystore = {
|
|
59
|
+
schemaVersion: 1,
|
|
60
|
+
validators
|
|
61
|
+
};
|
|
62
|
+
await writeKeystoreFile(outputPath, keystore);
|
|
63
|
+
// Generate staker outputs if requested
|
|
64
|
+
const allStakerOutputs = [];
|
|
65
|
+
if (stakerOutput && gseAddress && l1RpcUrls && l1ChainId !== undefined) {
|
|
66
|
+
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
67
|
+
const publicClient = createPublicClient({
|
|
68
|
+
chain: chain.chainInfo,
|
|
69
|
+
transport: fallback(l1RpcUrls.map((url)=>http(url, {
|
|
70
|
+
batch: false
|
|
71
|
+
})))
|
|
72
|
+
});
|
|
73
|
+
const gse = new GSEContract(publicClient, gseAddress);
|
|
74
|
+
// Extract keystore base name without extension for unique staker output filenames
|
|
75
|
+
const keystoreBaseName = basename(outputPath, '.json');
|
|
76
|
+
// Process each validator
|
|
77
|
+
for(let i = 0; i < validators.length; i++){
|
|
78
|
+
const validator = validators[i];
|
|
79
|
+
const outputs = await processAttesterAccounts(validator.attester, gse, password);
|
|
80
|
+
// Collect all staker outputs
|
|
81
|
+
for(let j = 0; j < outputs.length; j++){
|
|
82
|
+
allStakerOutputs.push(outputs[j]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Write a single JSON file with all staker outputs
|
|
86
|
+
if (allStakerOutputs.length > 0) {
|
|
87
|
+
const stakerOutputPath = join(keystoreOutDir, `${keystoreBaseName}_staker_output.json`);
|
|
88
|
+
await writeFile(stakerOutputPath, prettyPrintJSON(allStakerOutputs), 'utf-8');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const outputData = !_mnemonic ? {
|
|
92
|
+
...keystore,
|
|
93
|
+
generatedMnemonic: mnemonic
|
|
94
|
+
} : keystore;
|
|
95
|
+
// Handle JSON output
|
|
96
|
+
if (json) {
|
|
97
|
+
if (stakerOutput && allStakerOutputs.length > 0) {
|
|
98
|
+
const combinedOutput = {
|
|
99
|
+
keystore: outputData,
|
|
100
|
+
staker: allStakerOutputs
|
|
101
|
+
};
|
|
102
|
+
maybePrintJson(log, json, combinedOutput);
|
|
103
|
+
} else {
|
|
104
|
+
maybePrintJson(log, json, outputData);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
log(`Wrote validator keystore to ${outputPath}`);
|
|
108
|
+
if (stakerOutput && allStakerOutputs.length > 0) {
|
|
109
|
+
const keystoreBaseName = basename(outputPath, '.json');
|
|
110
|
+
const stakerOutputPath = join(keystoreOutDir, `${keystoreBaseName}_staker_output.json`);
|
|
111
|
+
log(`Wrote staker output for ${allStakerOutputs.length} validator(s) to ${stakerOutputPath}`);
|
|
112
|
+
log('');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// print a concise summary of public keys (addresses and BLS pubkeys) if no --json options was selected
|
|
116
|
+
if (!json) {
|
|
117
|
+
logValidatorSummaries(log, summaries);
|
|
118
|
+
}
|
|
119
|
+
if (mnemonic && remoteSigner && !json) {
|
|
120
|
+
for(let i = 0; i < validatorCount; i++){
|
|
121
|
+
const addrIdx = addressIndex + i;
|
|
122
|
+
const acct = mnemonicToAccount(mnemonic, {
|
|
123
|
+
accountIndex,
|
|
124
|
+
addressIndex: addrIdx
|
|
125
|
+
});
|
|
126
|
+
log(`attester address: ${acct.address} remoteSignerUrl: ${remoteSigner}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Log staker outputs if not in JSON mode
|
|
130
|
+
if (!json && stakerOutput && allStakerOutputs.length > 0) {
|
|
131
|
+
log('\nStaker outputs:');
|
|
132
|
+
log(prettyPrintJSON(allStakerOutputs));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
3
|
+
import type { EthAccount, EthPrivateKey, ValidatorKeyStore } from '@aztec/node-keystore/types';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
export type ValidatorSummary = {
|
|
6
|
+
attesterEth?: string;
|
|
7
|
+
attesterBls?: string;
|
|
8
|
+
publisherEth?: string[];
|
|
9
|
+
};
|
|
10
|
+
export type BuildValidatorsInput = {
|
|
11
|
+
validatorCount: number;
|
|
12
|
+
publisherCount?: number;
|
|
13
|
+
publishers?: string[];
|
|
14
|
+
accountIndex: number;
|
|
15
|
+
baseAddressIndex: number;
|
|
16
|
+
mnemonic: string;
|
|
17
|
+
ikm?: string;
|
|
18
|
+
blsPath?: string;
|
|
19
|
+
feeRecipient: AztecAddress;
|
|
20
|
+
coinbase?: EthAddress;
|
|
21
|
+
remoteSigner?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function withValidatorIndex(path: string, accountIndex?: number, addressIndex?: number): string;
|
|
24
|
+
/**
|
|
25
|
+
* Compute a compressed BN254 G1 public key from a private key.
|
|
26
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
27
|
+
* @returns Compressed G1 point (32 bytes with sign bit in MSB)
|
|
28
|
+
*/
|
|
29
|
+
export declare function computeBlsPublicKeyCompressed(privateKeyHex: string): Promise<string>;
|
|
30
|
+
export declare function deriveEthAttester(mnemonic: string, baseAccountIndex: number, addressIndex: number, remoteSigner?: string): EthAccount | EthPrivateKey;
|
|
31
|
+
export declare function buildValidatorEntries(input: BuildValidatorsInput): Promise<{
|
|
32
|
+
validators: ValidatorKeyStore[];
|
|
33
|
+
summaries: ValidatorSummary[];
|
|
34
|
+
}>;
|
|
35
|
+
export declare function resolveKeystoreOutputPath(dataDir?: string, file?: string): Promise<{
|
|
36
|
+
resolvedDir: string;
|
|
37
|
+
outputPath: string;
|
|
38
|
+
}>;
|
|
39
|
+
export declare function writeKeystoreFile(path: string, keystore: unknown): Promise<void>;
|
|
40
|
+
export declare function logValidatorSummaries(log: LogFn, summaries: ValidatorSummary[]): void;
|
|
41
|
+
export declare function maybePrintJson(log: LogFn, jsonFlag: boolean | undefined, obj: unknown): void;
|
|
42
|
+
/**
|
|
43
|
+
* Writes a BN254 keystore file for a BN254 BLS private key.
|
|
44
|
+
* Returns the absolute path to the written file.
|
|
45
|
+
*
|
|
46
|
+
* @param outDir - Directory to write the keystore file to
|
|
47
|
+
* @param fileNameBase - Base name for the keystore file (will be sanitized)
|
|
48
|
+
* @param password - Password for encrypting the private key
|
|
49
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
|
|
50
|
+
* @param pubkeyHex - Public key as hex string
|
|
51
|
+
* @param derivationPath - BIP-44 style derivation path
|
|
52
|
+
* @returns Absolute path to the written keystore file
|
|
53
|
+
*/
|
|
54
|
+
export declare function writeBn254BlsKeystore(outDir: string, fileNameBase: string, password: string, privateKeyHex: string, pubkeyHex: string, derivationPath: string): Promise<string>;
|
|
55
|
+
/** Replace plaintext BLS keys in validators with { path, password } pointing to BN254 keystore files. */
|
|
56
|
+
export declare function writeBlsBn254ToFile(validators: ValidatorKeyStore[], options: {
|
|
57
|
+
outDir: string;
|
|
58
|
+
password: string;
|
|
59
|
+
blsPath?: string;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
/** Writes an Ethereum JSON V3 keystore using ethers, returns absolute path */
|
|
62
|
+
export declare function writeEthJsonV3Keystore(outDir: string, fileNameBase: string, password: string, privateKeyHex: string): Promise<string>;
|
|
63
|
+
/** Replace plaintext ETH keys in validators with { path, password } pointing to JSON V3 files. */
|
|
64
|
+
export declare function writeEthJsonV3ToFile(validators: ValidatorKeyStore[], options: {
|
|
65
|
+
outDir: string;
|
|
66
|
+
password: string;
|
|
67
|
+
}): Promise<void>;
|
|
68
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2hhcmVkLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY21kcy92YWxpZGF0b3Jfa2V5cy9zaGFyZWQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUEsT0FBTyxLQUFLLE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AE,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,GAAG,EAAE,OAAO,QAIrF;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,CAAC,CASjB;AAED,yGAAyG;AACzG,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,iBAAiB,EAAE,EAC/B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9D,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED,8EAA8E;AAC9E,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,CAQjB;AAED,kGAAkG;AAClG,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,iBAAiB,EAAE,EAC/B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,IAAI,CAAC,CAsCf"}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { prettyPrintJSON } from '@aztec/cli/utils';
|
|
2
|
+
import { deriveBlsPrivateKey } from '@aztec/foundation/crypto/bls';
|
|
3
|
+
import { createBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
|
|
4
|
+
import { computeBn254G1PublicKeyCompressed } from '@aztec/foundation/crypto/bn254';
|
|
5
|
+
import { Wallet } from '@ethersproject/wallet';
|
|
6
|
+
import { constants as fsConstants, mkdirSync } from 'fs';
|
|
7
|
+
import { access, writeFile } from 'fs/promises';
|
|
8
|
+
import { homedir } from 'os';
|
|
9
|
+
import { dirname, isAbsolute, join } from 'path';
|
|
10
|
+
import { mnemonicToAccount } from 'viem/accounts';
|
|
11
|
+
import { defaultBlsPath } from './utils.js';
|
|
12
|
+
export function withValidatorIndex(path, accountIndex = 0, addressIndex = 0) {
|
|
13
|
+
// NOTE: The legacy BLS CLI is to allow users who generated keys in 2.1.4 to be able to use the same command
|
|
14
|
+
// to re-generate their keys. In 2.1.5 we switched how we append addresses to the path so this is to maintain backwards compatibility.
|
|
15
|
+
const useLegacyBlsCli = [
|
|
16
|
+
'true',
|
|
17
|
+
'1',
|
|
18
|
+
'yes',
|
|
19
|
+
'y'
|
|
20
|
+
].includes(process.env.LEGACY_BLS_CLI ?? '');
|
|
21
|
+
const defaultBlsPathParts = defaultBlsPath.split('/');
|
|
22
|
+
const parts = path.split('/');
|
|
23
|
+
if (parts.length == defaultBlsPathParts.length && parts.every((part, index)=>part === defaultBlsPathParts[index])) {
|
|
24
|
+
if (useLegacyBlsCli) {
|
|
25
|
+
// In 2.1.4, we were using address-index in parts[3] and did NOT use account-index, check lines 32 & 84
|
|
26
|
+
// https://github.com/AztecProtocol/aztec-packages/blob/v2.1.4/yarn-project/cli/src/cmds/validator_keys/shared.ts
|
|
27
|
+
parts[3] = String(addressIndex);
|
|
28
|
+
} else {
|
|
29
|
+
parts[3] = String(accountIndex);
|
|
30
|
+
parts[5] = String(addressIndex);
|
|
31
|
+
}
|
|
32
|
+
return parts.join('/');
|
|
33
|
+
}
|
|
34
|
+
return path;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Compute a compressed BN254 G1 public key from a private key.
|
|
38
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
39
|
+
* @returns Compressed G1 point (32 bytes with sign bit in MSB)
|
|
40
|
+
*/ export async function computeBlsPublicKeyCompressed(privateKeyHex) {
|
|
41
|
+
return await computeBn254G1PublicKeyCompressed(privateKeyHex);
|
|
42
|
+
}
|
|
43
|
+
export function deriveEthAttester(mnemonic, baseAccountIndex, addressIndex, remoteSigner) {
|
|
44
|
+
const acct = mnemonicToAccount(mnemonic, {
|
|
45
|
+
accountIndex: baseAccountIndex,
|
|
46
|
+
addressIndex
|
|
47
|
+
});
|
|
48
|
+
return remoteSigner ? {
|
|
49
|
+
address: acct.address,
|
|
50
|
+
remoteSignerUrl: remoteSigner
|
|
51
|
+
} : '0x' + Buffer.from(acct.getHdKey().privateKey).toString('hex');
|
|
52
|
+
}
|
|
53
|
+
export async function buildValidatorEntries(input) {
|
|
54
|
+
const { validatorCount, publisherCount = 0, publishers, accountIndex, baseAddressIndex, mnemonic, ikm, blsPath, feeRecipient, coinbase, remoteSigner } = input;
|
|
55
|
+
const summaries = [];
|
|
56
|
+
const validators = await Promise.all(Array.from({
|
|
57
|
+
length: validatorCount
|
|
58
|
+
}, async (_unused, i)=>{
|
|
59
|
+
const addressIndex = baseAddressIndex + i;
|
|
60
|
+
const basePath = blsPath ?? defaultBlsPath;
|
|
61
|
+
const perValidatorPath = withValidatorIndex(basePath, accountIndex, addressIndex);
|
|
62
|
+
const blsPrivKey = ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
|
|
63
|
+
const blsPubCompressed = blsPrivKey ? await computeBlsPublicKeyCompressed(blsPrivKey) : undefined;
|
|
64
|
+
const ethAttester = deriveEthAttester(mnemonic, accountIndex, addressIndex, remoteSigner);
|
|
65
|
+
const attester = blsPrivKey ? {
|
|
66
|
+
eth: ethAttester,
|
|
67
|
+
bls: blsPrivKey
|
|
68
|
+
} : ethAttester;
|
|
69
|
+
let publisherField;
|
|
70
|
+
const publisherAddresses = [];
|
|
71
|
+
if (publishers && publishers.length > 0) {
|
|
72
|
+
publisherAddresses.push(...publishers);
|
|
73
|
+
publisherField = publishers.length === 1 ? publishers[0] : publishers;
|
|
74
|
+
} else if (publisherCount > 0) {
|
|
75
|
+
const publishersBaseIndex = baseAddressIndex + validatorCount + i * publisherCount;
|
|
76
|
+
const publisherAccounts = Array.from({
|
|
77
|
+
length: publisherCount
|
|
78
|
+
}, (_unused2, j)=>{
|
|
79
|
+
const publisherAddressIndex = publishersBaseIndex + j;
|
|
80
|
+
const pubAcct = mnemonicToAccount(mnemonic, {
|
|
81
|
+
accountIndex,
|
|
82
|
+
addressIndex: publisherAddressIndex
|
|
83
|
+
});
|
|
84
|
+
publisherAddresses.push(pubAcct.address);
|
|
85
|
+
return remoteSigner ? {
|
|
86
|
+
address: pubAcct.address,
|
|
87
|
+
remoteSignerUrl: remoteSigner
|
|
88
|
+
} : '0x' + Buffer.from(pubAcct.getHdKey().privateKey).toString('hex');
|
|
89
|
+
});
|
|
90
|
+
publisherField = publisherCount === 1 ? publisherAccounts[0] : publisherAccounts;
|
|
91
|
+
}
|
|
92
|
+
const acct = mnemonicToAccount(mnemonic, {
|
|
93
|
+
accountIndex,
|
|
94
|
+
addressIndex
|
|
95
|
+
});
|
|
96
|
+
const attesterEthAddress = acct.address;
|
|
97
|
+
summaries.push({
|
|
98
|
+
attesterEth: attesterEthAddress,
|
|
99
|
+
attesterBls: blsPubCompressed,
|
|
100
|
+
publisherEth: publisherAddresses.length > 0 ? publisherAddresses : undefined
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
attester,
|
|
104
|
+
...publisherField !== undefined ? {
|
|
105
|
+
publisher: publisherField
|
|
106
|
+
} : {},
|
|
107
|
+
feeRecipient,
|
|
108
|
+
coinbase: coinbase ?? attesterEthAddress
|
|
109
|
+
};
|
|
110
|
+
}));
|
|
111
|
+
return {
|
|
112
|
+
validators,
|
|
113
|
+
summaries
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export async function resolveKeystoreOutputPath(dataDir, file) {
|
|
117
|
+
const defaultDataDir = join(homedir(), '.aztec', 'keystore');
|
|
118
|
+
const resolvedDir = dataDir && dataDir.length > 0 ? dataDir : defaultDataDir;
|
|
119
|
+
let outputPath;
|
|
120
|
+
if (file && file.length > 0) {
|
|
121
|
+
outputPath = isAbsolute(file) ? file : join(resolvedDir, file);
|
|
122
|
+
} else {
|
|
123
|
+
let index = 1;
|
|
124
|
+
while(true){
|
|
125
|
+
const candidate = join(resolvedDir, `key${index}.json`);
|
|
126
|
+
try {
|
|
127
|
+
await access(candidate, fsConstants.F_OK);
|
|
128
|
+
index += 1;
|
|
129
|
+
} catch {
|
|
130
|
+
outputPath = candidate;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
resolvedDir,
|
|
137
|
+
outputPath: outputPath
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export async function writeKeystoreFile(path, keystore) {
|
|
141
|
+
mkdirSync(dirname(path), {
|
|
142
|
+
recursive: true
|
|
143
|
+
});
|
|
144
|
+
await writeFile(path, JSON.stringify(keystore, null, 2), {
|
|
145
|
+
encoding: 'utf-8'
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
export function logValidatorSummaries(log, summaries) {
|
|
149
|
+
const lines = [];
|
|
150
|
+
for(let i = 0; i < summaries.length; i++){
|
|
151
|
+
const v = summaries[i];
|
|
152
|
+
lines.push(`acc${i + 1}:`);
|
|
153
|
+
lines.push(` attester:`);
|
|
154
|
+
if (v.attesterEth) {
|
|
155
|
+
lines.push(` eth: ${v.attesterEth}`);
|
|
156
|
+
}
|
|
157
|
+
if (v.attesterBls) {
|
|
158
|
+
lines.push(` bls: ${v.attesterBls}`);
|
|
159
|
+
}
|
|
160
|
+
if (v.publisherEth && v.publisherEth.length > 0) {
|
|
161
|
+
lines.push(` publisher:`);
|
|
162
|
+
for (const addr of v.publisherEth){
|
|
163
|
+
lines.push(` - ${addr}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (lines.length > 0) {
|
|
168
|
+
log(lines.join('\n'));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export function maybePrintJson(log, jsonFlag, obj) {
|
|
172
|
+
if (jsonFlag) {
|
|
173
|
+
log(prettyPrintJSON(obj));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Writes a BN254 keystore file for a BN254 BLS private key.
|
|
178
|
+
* Returns the absolute path to the written file.
|
|
179
|
+
*
|
|
180
|
+
* @param outDir - Directory to write the keystore file to
|
|
181
|
+
* @param fileNameBase - Base name for the keystore file (will be sanitized)
|
|
182
|
+
* @param password - Password for encrypting the private key
|
|
183
|
+
* @param privateKeyHex - Private key as 0x-prefixed hex string (32 bytes)
|
|
184
|
+
* @param pubkeyHex - Public key as hex string
|
|
185
|
+
* @param derivationPath - BIP-44 style derivation path
|
|
186
|
+
* @returns Absolute path to the written keystore file
|
|
187
|
+
*/ export async function writeBn254BlsKeystore(outDir, fileNameBase, password, privateKeyHex, pubkeyHex, derivationPath) {
|
|
188
|
+
mkdirSync(outDir, {
|
|
189
|
+
recursive: true
|
|
190
|
+
});
|
|
191
|
+
const keystore = createBn254Keystore(password, privateKeyHex, pubkeyHex, derivationPath);
|
|
192
|
+
const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
193
|
+
const outPath = join(outDir, `keystore-${safeBase}.json`);
|
|
194
|
+
await writeFile(outPath, JSON.stringify(keystore, null, 2), {
|
|
195
|
+
encoding: 'utf-8'
|
|
196
|
+
});
|
|
197
|
+
return outPath;
|
|
198
|
+
}
|
|
199
|
+
/** Replace plaintext BLS keys in validators with { path, password } pointing to BN254 keystore files. */ export async function writeBlsBn254ToFile(validators, options) {
|
|
200
|
+
for(let i = 0; i < validators.length; i++){
|
|
201
|
+
const v = validators[i];
|
|
202
|
+
if (!v || typeof v !== 'object' || !('attester' in v)) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const att = v.attester;
|
|
206
|
+
// Shapes: { bls: <hex> } or { eth: <ethAccount>, bls?: <hex> } or plain EthAccount
|
|
207
|
+
const blsKey = typeof att === 'object' && 'bls' in att ? att.bls : undefined;
|
|
208
|
+
if (!blsKey || typeof blsKey !== 'string') {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const pub = await computeBlsPublicKeyCompressed(blsKey);
|
|
212
|
+
const path = options.blsPath ?? defaultBlsPath;
|
|
213
|
+
const fileBase = `${String(i + 1)}_${pub.slice(2, 18)}`;
|
|
214
|
+
const keystorePath = await writeBn254BlsKeystore(options.outDir, fileBase, options.password, blsKey, pub, path);
|
|
215
|
+
if (typeof att === 'object') {
|
|
216
|
+
att.bls = {
|
|
217
|
+
path: keystorePath,
|
|
218
|
+
password: options.password
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** Writes an Ethereum JSON V3 keystore using ethers, returns absolute path */ export async function writeEthJsonV3Keystore(outDir, fileNameBase, password, privateKeyHex) {
|
|
224
|
+
const safeBase = fileNameBase.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
225
|
+
mkdirSync(outDir, {
|
|
226
|
+
recursive: true
|
|
227
|
+
});
|
|
228
|
+
const wallet = new Wallet(privateKeyHex);
|
|
229
|
+
const json = await wallet.encrypt(password);
|
|
230
|
+
const outPath = join(outDir, `keystore-eth-${safeBase}.json`);
|
|
231
|
+
await writeFile(outPath, json, {
|
|
232
|
+
encoding: 'utf-8'
|
|
233
|
+
});
|
|
234
|
+
return outPath;
|
|
235
|
+
}
|
|
236
|
+
/** Replace plaintext ETH keys in validators with { path, password } pointing to JSON V3 files. */ export async function writeEthJsonV3ToFile(validators, options) {
|
|
237
|
+
const maybeEncryptEth = async (account, label)=>{
|
|
238
|
+
if (typeof account === 'string' && account.startsWith('0x') && account.length === 66) {
|
|
239
|
+
const fileBase = `${label}_${account.slice(2, 10)}`;
|
|
240
|
+
const p = await writeEthJsonV3Keystore(options.outDir, fileBase, options.password, account);
|
|
241
|
+
return {
|
|
242
|
+
path: p,
|
|
243
|
+
password: options.password
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return account;
|
|
247
|
+
};
|
|
248
|
+
for(let i = 0; i < validators.length; i++){
|
|
249
|
+
const v = validators[i];
|
|
250
|
+
if (!v || typeof v !== 'object') {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
// attester may be string (eth), object with eth, or remote signer
|
|
254
|
+
const att = v.attester;
|
|
255
|
+
if (typeof att === 'string') {
|
|
256
|
+
v.attester = await maybeEncryptEth(att, `attester_${i + 1}`);
|
|
257
|
+
} else if (att && typeof att === 'object' && 'eth' in att) {
|
|
258
|
+
att.eth = await maybeEncryptEth(att.eth, `attester_${i + 1}`);
|
|
259
|
+
}
|
|
260
|
+
// publisher can be single or array
|
|
261
|
+
if ('publisher' in v) {
|
|
262
|
+
const pub = v.publisher;
|
|
263
|
+
if (Array.isArray(pub)) {
|
|
264
|
+
const out = [];
|
|
265
|
+
for(let j = 0; j < pub.length; j++){
|
|
266
|
+
out.push(await maybeEncryptEth(pub[j], `publisher_${i + 1}_${j + 1}`));
|
|
267
|
+
}
|
|
268
|
+
v.publisher = out;
|
|
269
|
+
} else if (pub !== undefined) {
|
|
270
|
+
v.publisher = await maybeEncryptEth(pub, `publisher_${i + 1}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { GSEContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
4
|
+
import type { AttesterAccounts } from '@aztec/node-keystore/types';
|
|
5
|
+
export type StakerOptions = {
|
|
6
|
+
from: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
output?: string;
|
|
9
|
+
gseAddress: EthAddress;
|
|
10
|
+
l1RpcUrls: string[];
|
|
11
|
+
l1ChainId: number;
|
|
12
|
+
};
|
|
13
|
+
export type StakerOutput = {
|
|
14
|
+
attester: string;
|
|
15
|
+
publicKeyG1: {
|
|
16
|
+
x: string;
|
|
17
|
+
y: string;
|
|
18
|
+
};
|
|
19
|
+
publicKeyG2: {
|
|
20
|
+
x0: string;
|
|
21
|
+
x1: string;
|
|
22
|
+
y0: string;
|
|
23
|
+
y1: string;
|
|
24
|
+
};
|
|
25
|
+
proofOfPossession: {
|
|
26
|
+
x: string;
|
|
27
|
+
y: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Process AttesterAccounts (which can be a single attester, array, or mnemonic)
|
|
32
|
+
*/
|
|
33
|
+
export declare function processAttesterAccounts(attesterAccounts: AttesterAccounts, gse: GSEContract, password?: string): Promise<StakerOutput[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Main staker command function
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateStakerJson(options: StakerOptions, log: LogFn): Promise<void>;
|
|
38
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Rha2VyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY21kcy92YWxpZGF0b3Jfa2V5cy9zdGFrZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBSXhELE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQ2hFLE9BQU8sS0FBSyxFQUFFLEtBQUssRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRW5ELE9BQU8sS0FBSyxFQUVWLGdCQUFnQixFQUtqQixNQUFNLDRCQUE0QixDQUFDO0FBUXBDLE1BQU0sTUFBTSxhQUFhLEdBQUc7SUFDMUIsSUFBSSxFQUFFLE1BQU0sQ0FBQztJQUNiLFFBQVEsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUNsQixNQUFNLENBQUMsRUF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