@aztec/cli 0.0.1-commit.b655e406 → 0.0.1-commit.fce3e4f
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/get_block.d.ts +1 -1
- package/dest/cmds/aztec_node/get_current_base_fee.d.ts +1 -1
- package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts +1 -1
- package/dest/cmds/aztec_node/get_logs.d.ts +1 -1
- package/dest/cmds/aztec_node/get_node_info.d.ts +1 -1
- package/dest/cmds/aztec_node/index.d.ts +1 -1
- 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 +3 -9
- package/dest/cmds/contracts/parse_parameter_struct.d.ts +1 -1
- package/dest/cmds/infrastructure/index.d.ts +1 -1
- package/dest/cmds/infrastructure/sequencers.d.ts +1 -1
- package/dest/cmds/infrastructure/setup_l2_contract.d.ts +1 -1
- package/dest/cmds/l1/advance_epoch.d.ts +1 -1
- package/dest/cmds/l1/assume_proven_through.d.ts +1 -1
- package/dest/cmds/l1/bridge_erc20.d.ts +1 -1
- package/dest/cmds/l1/create_l1_account.d.ts +1 -1
- package/dest/cmds/l1/deploy_l1_contracts.d.ts +1 -1
- package/dest/cmds/l1/deploy_new_rollup.d.ts +1 -1
- package/dest/cmds/l1/get_l1_addresses.d.ts +1 -1
- package/dest/cmds/l1/get_l1_balance.d.ts +1 -1
- 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/index.d.ts +1 -1
- 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 +28 -28
- 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/update_l1_validators.d.ts +6 -6
- package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
- package/dest/cmds/l1/update_l1_validators.js +2 -2
- 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_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/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 +1 -1
- package/dest/cmds/validator_keys/add.d.ts.map +1 -1
- package/dest/cmds/validator_keys/add.js +20 -7
- package/dest/cmds/validator_keys/generate_bls_keypair.d.ts +1 -1
- package/dest/cmds/validator_keys/generate_bls_keypair.d.ts.map +1 -1
- package/dest/cmds/validator_keys/generate_bls_keypair.js +2 -1
- 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 +16 -4
- package/dest/cmds/validator_keys/new.d.ts +7 -4
- package/dest/cmds/validator_keys/new.d.ts.map +1 -1
- package/dest/cmds/validator_keys/new.js +87 -16
- package/dest/cmds/validator_keys/shared.d.ts +4 -4
- package/dest/cmds/validator_keys/shared.d.ts.map +1 -1
- package/dest/cmds/validator_keys/shared.js +29 -27
- 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 +207 -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 +1 -1
- package/dest/config/chain_l2_config.d.ts +11 -10
- package/dest/config/chain_l2_config.d.ts.map +1 -1
- package/dest/config/chain_l2_config.js +64 -34
- package/dest/config/enrich_env.d.ts +1 -1
- package/dest/config/get_l1_config.d.ts +1 -1
- package/dest/config/index.d.ts +1 -1
- package/dest/config/network_config.d.ts +2 -2
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +19 -5
- package/dest/utils/aztec.d.ts +1 -1
- package/dest/utils/aztec.d.ts.map +1 -1
- package/dest/utils/commands.d.ts +2 -2
- package/dest/utils/commands.d.ts.map +1 -1
- package/dest/utils/encoding.d.ts +1 -1
- package/dest/utils/github.d.ts +1 -1
- package/dest/utils/index.d.ts +1 -1
- package/dest/utils/inspect.d.ts +1 -1
- package/dest/utils/setup_contracts.d.ts +1 -1
- package/package.json +34 -29
- package/public_include_metric_prefixes.json +1 -0
- package/src/cmds/contracts/inspect_contract.ts +3 -10
- package/src/cmds/l1/prover_stats.ts +36 -29
- package/src/cmds/l1/update_l1_validators.ts +2 -2
- package/src/cmds/misc/update/npm.ts +1 -1
- package/src/cmds/validator_keys/add.ts +20 -10
- package/src/cmds/validator_keys/generate_bls_keypair.ts +2 -1
- package/src/cmds/validator_keys/index.ts +67 -21
- package/src/cmds/validator_keys/new.ts +109 -23
- package/src/cmds/validator_keys/shared.ts +30 -26
- package/src/cmds/validator_keys/staker.ts +300 -0
- package/src/cmds/validator_keys/utils.ts +80 -0
- package/src/config/chain_l2_config.ts +86 -45
- package/src/config/network_config.ts +26 -5
|
@@ -13,27 +13,42 @@ import { homedir } from 'os';
|
|
|
13
13
|
import { dirname, isAbsolute, join } from 'path';
|
|
14
14
|
import { mnemonicToAccount } from 'viem/accounts';
|
|
15
15
|
|
|
16
|
+
import { defaultBlsPath } from './utils.js';
|
|
17
|
+
|
|
16
18
|
export type ValidatorSummary = { attesterEth?: string; attesterBls?: string; publisherEth?: string[] };
|
|
17
19
|
|
|
18
20
|
export type BuildValidatorsInput = {
|
|
19
21
|
validatorCount: number;
|
|
20
22
|
publisherCount?: number;
|
|
23
|
+
publishers?: string[];
|
|
21
24
|
accountIndex: number;
|
|
22
25
|
baseAddressIndex: number;
|
|
23
26
|
mnemonic: string;
|
|
24
27
|
ikm?: string;
|
|
25
28
|
blsPath?: string;
|
|
26
|
-
blsOnly?: boolean;
|
|
27
29
|
feeRecipient: AztecAddress;
|
|
28
30
|
coinbase?: EthAddress;
|
|
29
31
|
remoteSigner?: string;
|
|
30
|
-
fundingAccount?: EthAddress;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
export function withValidatorIndex(path: string,
|
|
34
|
+
export function withValidatorIndex(path: string, accountIndex: number = 0, addressIndex: number = 0) {
|
|
35
|
+
// NOTE: The legacy BLS CLI is to allow users who generated keys in 2.1.4 to be able to use the same command
|
|
36
|
+
// 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.
|
|
37
|
+
const useLegacyBlsCli = ['true', '1', 'yes', 'y'].includes(process.env.LEGACY_BLS_CLI ?? '');
|
|
38
|
+
|
|
39
|
+
const defaultBlsPathParts = defaultBlsPath.split('/');
|
|
40
|
+
|
|
34
41
|
const parts = path.split('/');
|
|
35
|
-
if (parts.length
|
|
36
|
-
|
|
42
|
+
if (parts.length == defaultBlsPathParts.length && parts.every((part, index) => part === defaultBlsPathParts[index])) {
|
|
43
|
+
if (useLegacyBlsCli) {
|
|
44
|
+
// In 2.1.4, we were using address-index in parts[3] and did NOT use account-index, check lines 32 & 84
|
|
45
|
+
// https://github.com/AztecProtocol/aztec-packages/blob/v2.1.4/yarn-project/cli/src/cmds/validator_keys/shared.ts
|
|
46
|
+
|
|
47
|
+
parts[3] = String(addressIndex);
|
|
48
|
+
} else {
|
|
49
|
+
parts[3] = String(accountIndex);
|
|
50
|
+
parts[5] = String(addressIndex);
|
|
51
|
+
}
|
|
37
52
|
return parts.join('/');
|
|
38
53
|
}
|
|
39
54
|
return path;
|
|
@@ -64,42 +79,37 @@ export async function buildValidatorEntries(input: BuildValidatorsInput) {
|
|
|
64
79
|
const {
|
|
65
80
|
validatorCount,
|
|
66
81
|
publisherCount = 0,
|
|
82
|
+
publishers,
|
|
67
83
|
accountIndex,
|
|
68
84
|
baseAddressIndex,
|
|
69
85
|
mnemonic,
|
|
70
86
|
ikm,
|
|
71
87
|
blsPath,
|
|
72
|
-
blsOnly,
|
|
73
88
|
feeRecipient,
|
|
74
89
|
coinbase,
|
|
75
90
|
remoteSigner,
|
|
76
|
-
fundingAccount,
|
|
77
91
|
} = input;
|
|
78
92
|
|
|
79
|
-
const defaultBlsPath = 'm/12381/3600/0/0/0';
|
|
80
93
|
const summaries: ValidatorSummary[] = [];
|
|
81
94
|
|
|
82
95
|
const validators = await Promise.all(
|
|
83
96
|
Array.from({ length: validatorCount }, async (_unused, i) => {
|
|
84
97
|
const addressIndex = baseAddressIndex + i;
|
|
85
98
|
const basePath = blsPath ?? defaultBlsPath;
|
|
86
|
-
const perValidatorPath = withValidatorIndex(basePath, addressIndex);
|
|
99
|
+
const perValidatorPath = withValidatorIndex(basePath, accountIndex, addressIndex);
|
|
87
100
|
|
|
88
|
-
const blsPrivKey =
|
|
101
|
+
const blsPrivKey = ikm || mnemonic ? deriveBlsPrivateKey(mnemonic, ikm, perValidatorPath) : undefined;
|
|
89
102
|
const blsPubCompressed = blsPrivKey ? await computeBlsPublicKeyCompressed(blsPrivKey) : undefined;
|
|
90
103
|
|
|
91
|
-
if (blsOnly) {
|
|
92
|
-
const attester = { bls: blsPrivKey! };
|
|
93
|
-
summaries.push({ attesterBls: blsPubCompressed });
|
|
94
|
-
return { attester, feeRecipient } as ValidatorKeyStore;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
104
|
const ethAttester = deriveEthAttester(mnemonic, accountIndex, addressIndex, remoteSigner);
|
|
98
105
|
const attester = blsPrivKey ? { eth: ethAttester, bls: blsPrivKey } : ethAttester;
|
|
99
106
|
|
|
100
107
|
let publisherField: EthAccount | EthPrivateKey | (EthAccount | EthPrivateKey)[] | undefined;
|
|
101
108
|
const publisherAddresses: string[] = [];
|
|
102
|
-
if (
|
|
109
|
+
if (publishers && publishers.length > 0) {
|
|
110
|
+
publisherAddresses.push(...publishers);
|
|
111
|
+
publisherField = publishers.length === 1 ? (publishers[0] as EthPrivateKey) : (publishers as EthPrivateKey[]);
|
|
112
|
+
} else if (publisherCount > 0) {
|
|
103
113
|
const publishersBaseIndex = baseAddressIndex + validatorCount + i * publisherCount;
|
|
104
114
|
const publisherAccounts = Array.from({ length: publisherCount }, (_unused2, j) => {
|
|
105
115
|
const publisherAddressIndex = publishersBaseIndex + j;
|
|
@@ -130,8 +140,7 @@ export async function buildValidatorEntries(input: BuildValidatorsInput) {
|
|
|
130
140
|
attester,
|
|
131
141
|
...(publisherField !== undefined ? { publisher: publisherField } : {}),
|
|
132
142
|
feeRecipient,
|
|
133
|
-
coinbase,
|
|
134
|
-
fundingAccount,
|
|
143
|
+
coinbase: coinbase ?? attesterEthAddress,
|
|
135
144
|
} as ValidatorKeyStore;
|
|
136
145
|
}),
|
|
137
146
|
);
|
|
@@ -229,7 +238,7 @@ export async function writeBn254BlsKeystore(
|
|
|
229
238
|
/** Replace plaintext BLS keys in validators with { path, password } pointing to BN254 keystore files. */
|
|
230
239
|
export async function writeBlsBn254ToFile(
|
|
231
240
|
validators: ValidatorKeyStore[],
|
|
232
|
-
options: { outDir: string; password: string },
|
|
241
|
+
options: { outDir: string; password: string; blsPath?: string },
|
|
233
242
|
): Promise<void> {
|
|
234
243
|
for (let i = 0; i < validators.length; i++) {
|
|
235
244
|
const v = validators[i];
|
|
@@ -245,7 +254,7 @@ export async function writeBlsBn254ToFile(
|
|
|
245
254
|
}
|
|
246
255
|
|
|
247
256
|
const pub = await computeBlsPublicKeyCompressed(blsKey);
|
|
248
|
-
const path =
|
|
257
|
+
const path = options.blsPath ?? defaultBlsPath;
|
|
249
258
|
const fileBase = `${String(i + 1)}_${pub.slice(2, 18)}`;
|
|
250
259
|
const keystorePath = await writeBn254BlsKeystore(options.outDir, fileBase, options.password, blsKey, pub, path);
|
|
251
260
|
|
|
@@ -312,10 +321,5 @@ export async function writeEthJsonV3ToFile(
|
|
|
312
321
|
(v as any).publisher = await maybeEncryptEth(pub, `publisher_${i + 1}`);
|
|
313
322
|
}
|
|
314
323
|
}
|
|
315
|
-
|
|
316
|
-
// Optional fundingAccount within validator
|
|
317
|
-
if ('fundingAccount' in v) {
|
|
318
|
-
(v as any).fundingAccount = await maybeEncryptEth((v as any).fundingAccount, `funding_${i + 1}`);
|
|
319
|
-
}
|
|
320
324
|
}
|
|
321
325
|
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { prettyPrintJSON } from '@aztec/cli/utils';
|
|
2
|
+
import { GSEContract, createEthereumChain } from '@aztec/ethereum';
|
|
3
|
+
import { computeBn254G1PublicKey, computeBn254G2PublicKey } from '@aztec/foundation/crypto';
|
|
4
|
+
import { decryptBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
|
|
5
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
7
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
8
|
+
import { loadKeystoreFile } from '@aztec/node-keystore/loader';
|
|
9
|
+
import type {
|
|
10
|
+
AttesterAccount,
|
|
11
|
+
AttesterAccounts,
|
|
12
|
+
BLSAccount,
|
|
13
|
+
EncryptedKeyFileConfig,
|
|
14
|
+
EthAccount,
|
|
15
|
+
MnemonicConfig,
|
|
16
|
+
} from '@aztec/node-keystore/types';
|
|
17
|
+
|
|
18
|
+
import { Wallet } from '@ethersproject/wallet';
|
|
19
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
20
|
+
import { basename, dirname, join } from 'path';
|
|
21
|
+
import { createPublicClient, fallback, http } from 'viem';
|
|
22
|
+
import { privateKeyToAddress } from 'viem/accounts';
|
|
23
|
+
|
|
24
|
+
export type StakerOptions = {
|
|
25
|
+
from: string;
|
|
26
|
+
password?: string;
|
|
27
|
+
output?: string;
|
|
28
|
+
gseAddress: EthAddress;
|
|
29
|
+
l1RpcUrls: string[];
|
|
30
|
+
l1ChainId: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type StakerOutput = {
|
|
34
|
+
attester: string;
|
|
35
|
+
publicKeyG1: {
|
|
36
|
+
x: string;
|
|
37
|
+
y: string;
|
|
38
|
+
};
|
|
39
|
+
publicKeyG2: {
|
|
40
|
+
x0: string;
|
|
41
|
+
x1: string;
|
|
42
|
+
y0: string;
|
|
43
|
+
y1: string;
|
|
44
|
+
};
|
|
45
|
+
proofOfPossession: {
|
|
46
|
+
x: string;
|
|
47
|
+
y: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Check if an object is a MnemonicConfig
|
|
53
|
+
*/
|
|
54
|
+
function isMnemonicConfig(obj: unknown): obj is MnemonicConfig {
|
|
55
|
+
return typeof obj === 'object' && obj !== null && 'mnemonic' in obj;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Check if a value is an encrypted keystore file config
|
|
60
|
+
*/
|
|
61
|
+
function isEncryptedKeyFileConfig(value: unknown): value is EncryptedKeyFileConfig {
|
|
62
|
+
return typeof value === 'object' && value !== null && 'path' in value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Check if a BLSAccount is a private key string (not an encrypted keystore file)
|
|
67
|
+
*/
|
|
68
|
+
function isBlsPrivateKey(bls: unknown): bls is string {
|
|
69
|
+
return typeof bls === 'string' && bls.startsWith('0x');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Check if an EthAccount is a private key string (66 chars: 0x + 64 hex)
|
|
74
|
+
*/
|
|
75
|
+
function isEthPrivateKey(eth: unknown): eth is string {
|
|
76
|
+
return typeof eth === 'string' && eth.startsWith('0x') && eth.length === 66;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Check if a string is an Ethereum address (42 chars: 0x + 40 hex)
|
|
81
|
+
*/
|
|
82
|
+
function isEthAddress(value: unknown): value is string {
|
|
83
|
+
return typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Decrypt a BLS private key from an encrypted keystore file
|
|
88
|
+
*/
|
|
89
|
+
function decryptBlsKey(bls: BLSAccount, password?: string): string | undefined {
|
|
90
|
+
if (isBlsPrivateKey(bls)) {
|
|
91
|
+
return bls;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (isEncryptedKeyFileConfig(bls)) {
|
|
95
|
+
if (!password && !bls.password) {
|
|
96
|
+
return undefined; // Can't decrypt without password
|
|
97
|
+
}
|
|
98
|
+
const pwd = password ?? bls.password!;
|
|
99
|
+
return decryptBn254Keystore(bls.path, pwd);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Decrypt an Ethereum private key from an encrypted keystore file
|
|
107
|
+
*/
|
|
108
|
+
async function decryptEthKey(eth: EthAccount, password?: string): Promise<string | undefined> {
|
|
109
|
+
if (isEthPrivateKey(eth)) {
|
|
110
|
+
return eth;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (isEncryptedKeyFileConfig(eth)) {
|
|
114
|
+
if (!password && !eth.password) {
|
|
115
|
+
return undefined; // Can't decrypt without password
|
|
116
|
+
}
|
|
117
|
+
const pwd = password ?? eth.password!;
|
|
118
|
+
const json = readFileSync(eth.path, 'utf-8');
|
|
119
|
+
const wallet = await Wallet.fromEncryptedJson(json, pwd);
|
|
120
|
+
return wallet.privateKey as string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Extract Ethereum address from an EthAccount (or private key)
|
|
128
|
+
*/
|
|
129
|
+
async function getEthAddress(eth: EthAccount | string, password?: string): Promise<EthAddress | undefined> {
|
|
130
|
+
// Case 1: It's a private key string - derive the address
|
|
131
|
+
if (isEthPrivateKey(eth)) {
|
|
132
|
+
return privateKeyToAddress(eth as `0x${string}`) as unknown as EthAddress;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Case 2: It's just an address string directly (EthRemoteSignerAccount can be just EthAddress)
|
|
136
|
+
if (isEthAddress(eth)) {
|
|
137
|
+
return eth as unknown as EthAddress;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Case 3: It's an object with an address property (remote signer config)
|
|
141
|
+
if (typeof eth === 'object' && eth !== null && 'address' in eth) {
|
|
142
|
+
return (eth as any).address as EthAddress;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Case 4: It's an encrypted keystore file - decrypt and derive address
|
|
146
|
+
if (isEncryptedKeyFileConfig(eth)) {
|
|
147
|
+
const privateKey = await decryptEthKey(eth, password);
|
|
148
|
+
if (privateKey) {
|
|
149
|
+
return privateKeyToAddress(privateKey as `0x${string}`) as unknown as EthAddress;
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Extract BLS private key and Ethereum address from an AttesterAccount
|
|
159
|
+
*/
|
|
160
|
+
async function extractAttesterInfo(
|
|
161
|
+
attester: AttesterAccount,
|
|
162
|
+
password?: string,
|
|
163
|
+
): Promise<{ blsPrivateKey?: string; ethAddress?: EthAddress }> {
|
|
164
|
+
// Case 1: attester is { eth: EthAccount, bls?: BLSAccount }
|
|
165
|
+
if (typeof attester === 'object' && attester !== null && 'eth' in attester) {
|
|
166
|
+
const ethAddress = await getEthAddress(attester.eth, password);
|
|
167
|
+
const blsPrivateKey = attester.bls ? decryptBlsKey(attester.bls, password) : undefined;
|
|
168
|
+
return { blsPrivateKey, ethAddress };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Case 2: attester is just an EthAccount directly (no BLS key)
|
|
172
|
+
return {
|
|
173
|
+
blsPrivateKey: undefined,
|
|
174
|
+
ethAddress: await getEthAddress(attester as EthAccount, password),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Process a single attester entry and output staking JSON
|
|
180
|
+
*/
|
|
181
|
+
async function processAttester(
|
|
182
|
+
attester: AttesterAccount,
|
|
183
|
+
gse: GSEContract,
|
|
184
|
+
password?: string,
|
|
185
|
+
): Promise<StakerOutput | undefined> {
|
|
186
|
+
const { blsPrivateKey, ethAddress } = await extractAttesterInfo(attester, password);
|
|
187
|
+
|
|
188
|
+
// Skip if no BLS private key or no Ethereum address
|
|
189
|
+
if (!blsPrivateKey || !ethAddress) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Derive G1 and G2 public keys
|
|
194
|
+
const g1PublicKey = await computeBn254G1PublicKey(blsPrivateKey);
|
|
195
|
+
const g2PublicKey = await computeBn254G2PublicKey(blsPrivateKey);
|
|
196
|
+
|
|
197
|
+
// Generate proof of possession
|
|
198
|
+
const bn254SecretKeyFieldElement = Fr.fromString(blsPrivateKey);
|
|
199
|
+
const registrationTuple = await gse.makeRegistrationTuple(bn254SecretKeyFieldElement.toBigInt());
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
attester: String(ethAddress),
|
|
203
|
+
publicKeyG1: {
|
|
204
|
+
x: '0x' + g1PublicKey.x.toString(16).padStart(64, '0'),
|
|
205
|
+
y: '0x' + g1PublicKey.y.toString(16).padStart(64, '0'),
|
|
206
|
+
},
|
|
207
|
+
publicKeyG2: {
|
|
208
|
+
x0: '0x' + g2PublicKey.x.c0.toString(16).padStart(64, '0'),
|
|
209
|
+
x1: '0x' + g2PublicKey.x.c1.toString(16).padStart(64, '0'),
|
|
210
|
+
y0: '0x' + g2PublicKey.y.c0.toString(16).padStart(64, '0'),
|
|
211
|
+
y1: '0x' + g2PublicKey.y.c1.toString(16).padStart(64, '0'),
|
|
212
|
+
},
|
|
213
|
+
proofOfPossession: {
|
|
214
|
+
x: '0x' + registrationTuple.proofOfPossession.x.toString(16),
|
|
215
|
+
y: '0x' + registrationTuple.proofOfPossession.y.toString(16),
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Process AttesterAccounts (which can be a single attester, array, or mnemonic)
|
|
222
|
+
*/
|
|
223
|
+
export async function processAttesterAccounts(
|
|
224
|
+
attesterAccounts: AttesterAccounts,
|
|
225
|
+
gse: GSEContract,
|
|
226
|
+
password?: string,
|
|
227
|
+
): Promise<StakerOutput[]> {
|
|
228
|
+
// Skip mnemonic configs
|
|
229
|
+
if (isMnemonicConfig(attesterAccounts)) {
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Handle array of attesters
|
|
234
|
+
if (Array.isArray(attesterAccounts)) {
|
|
235
|
+
const results: StakerOutput[] = [];
|
|
236
|
+
for (const attester of attesterAccounts) {
|
|
237
|
+
const result = await processAttester(attester, gse, password);
|
|
238
|
+
if (result) {
|
|
239
|
+
results.push(result);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return results;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Handle single attester
|
|
246
|
+
const result = await processAttester(attesterAccounts, gse, password);
|
|
247
|
+
return result ? [result] : [];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Main staker command function
|
|
252
|
+
*/
|
|
253
|
+
export async function generateStakerJson(options: StakerOptions, log: LogFn): Promise<void> {
|
|
254
|
+
const { from, password, gseAddress, l1RpcUrls, l1ChainId, output } = options;
|
|
255
|
+
|
|
256
|
+
// Load the keystore file
|
|
257
|
+
const keystore = loadKeystoreFile(from);
|
|
258
|
+
|
|
259
|
+
if (!gseAddress) {
|
|
260
|
+
throw new Error('GSE contract address is required');
|
|
261
|
+
}
|
|
262
|
+
log(`Calling GSE contract ${gseAddress} on chain ${l1ChainId}, using ${l1RpcUrls.join(', ')} to get staker outputs`);
|
|
263
|
+
|
|
264
|
+
if (!keystore.validators || keystore.validators.length === 0) {
|
|
265
|
+
log('No validators found in keystore');
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const allOutputs: StakerOutput[] = [];
|
|
270
|
+
|
|
271
|
+
// L1 client for proof of possession
|
|
272
|
+
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
273
|
+
const publicClient = createPublicClient({
|
|
274
|
+
chain: chain.chainInfo,
|
|
275
|
+
transport: fallback(l1RpcUrls.map(url => http(url))),
|
|
276
|
+
});
|
|
277
|
+
const gse = new GSEContract(publicClient, gseAddress);
|
|
278
|
+
|
|
279
|
+
const keystoreBaseName = basename(from, '.json');
|
|
280
|
+
const outputDir = output ? output : dirname(from);
|
|
281
|
+
|
|
282
|
+
for (let i = 0; i < keystore.validators.length; i++) {
|
|
283
|
+
const validator = keystore.validators[i];
|
|
284
|
+
const outputs = await processAttesterAccounts(validator.attester, gse, password);
|
|
285
|
+
|
|
286
|
+
for (let j = 0; j < outputs.length; j++) {
|
|
287
|
+
allOutputs.push(outputs[j]);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (allOutputs.length === 0) {
|
|
292
|
+
log('No attesters with BLS keys found (skipping mnemonics and encrypted keystores without password)');
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Write a single JSON file with all staker outputs
|
|
297
|
+
const stakerOutputPath = join(outputDir, `${keystoreBaseName}_staker_output.json`);
|
|
298
|
+
writeFileSync(stakerOutputPath, prettyPrintJSON(allOutputs), 'utf-8');
|
|
299
|
+
log(`Wrote staker output for ${allOutputs.length} validator(s) to ${stakerOutputPath}`);
|
|
300
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { type EthPrivateKey, ethPrivateKeySchema } from '@aztec/node-keystore';
|
|
3
|
+
|
|
4
|
+
export const defaultBlsPath = 'm/12381/3600/0/0/0';
|
|
5
|
+
|
|
6
|
+
export function validateBlsPathOptions(options: {
|
|
7
|
+
count?: number;
|
|
8
|
+
publisherCount?: number;
|
|
9
|
+
accountIndex?: number;
|
|
10
|
+
addressIndex?: number;
|
|
11
|
+
blsPath?: string;
|
|
12
|
+
ikm?: string;
|
|
13
|
+
}) {
|
|
14
|
+
if (options.blsPath && options.blsPath !== defaultBlsPath) {
|
|
15
|
+
if (
|
|
16
|
+
(options.count && options.count !== 1) ||
|
|
17
|
+
(options.publisherCount && options.publisherCount > 0) ||
|
|
18
|
+
(options.accountIndex && options.accountIndex !== 0) ||
|
|
19
|
+
(options.addressIndex && options.addressIndex !== 0)
|
|
20
|
+
) {
|
|
21
|
+
throw new Error('--bls-path cannot be used with --count, --publisher-count, --account-index, or --address-index');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function validateStakerOutputOptions(options: {
|
|
27
|
+
stakerOutput?: boolean;
|
|
28
|
+
gseAddress?: EthAddress;
|
|
29
|
+
l1RpcUrls?: string[];
|
|
30
|
+
l1ChainId?: number;
|
|
31
|
+
}) {
|
|
32
|
+
if (!options.stakerOutput) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// Required options for staker output
|
|
36
|
+
if (!options.gseAddress) {
|
|
37
|
+
throw new Error('--gse-address is required when using --staker-output');
|
|
38
|
+
}
|
|
39
|
+
if (!options.l1RpcUrls || options.l1RpcUrls.length === 0) {
|
|
40
|
+
throw new Error('--l1-rpc-urls is required when using --staker-output');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (options.l1ChainId === undefined) {
|
|
44
|
+
throw new Error('--l1-chain-id is required when using --staker-output');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function validateRemoteSignerOptions(options: { remoteSigner?: string; mnemonic?: string }) {
|
|
49
|
+
if (options.remoteSigner && !options.mnemonic) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
'Using --remote-signer requires a deterministic key source. Provide --mnemonic to derive keys, or omit --remote-signer to write new private keys to keystore.',
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function validatePublisherOptions(options: { publishers?: string[]; publisherCount?: number }) {
|
|
57
|
+
if (options.publisherCount && options.publisherCount > 0 && options.publishers && options.publishers.length > 0) {
|
|
58
|
+
throw new Error('--publishers and --publisher-count cannot be used together');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (options.publishers && options.publishers.length > 0) {
|
|
62
|
+
// Normalize each private key by adding 0x prefix if missing
|
|
63
|
+
const normalizedKeys: string[] = [];
|
|
64
|
+
for (const key of options.publishers) {
|
|
65
|
+
let privateKey = key.trim();
|
|
66
|
+
if (!privateKey.startsWith('0x')) {
|
|
67
|
+
privateKey = '0x' + privateKey;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
ethPrivateKeySchema.parse(privateKey);
|
|
72
|
+
normalizedKeys.push(privateKey);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw new Error(`Invalid publisher private key: ${error instanceof Error ? error.message : String(error)}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Update the options with the normalized keys
|
|
78
|
+
options.publishers = normalizedKeys as EthPrivateKey[];
|
|
79
|
+
}
|
|
80
|
+
}
|