@aztec/cli 3.0.0-nightly.20251030-2 → 3.0.0-nightly.20251031
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/cmds/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 +70 -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 +26 -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 +20 -0
- package/dest/cmds/validator_keys/new.d.ts +26 -0
- package/dest/cmds/validator_keys/new.d.ts.map +1 -0
- package/dest/cmds/validator_keys/new.js +60 -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 +271 -0
- package/dest/utils/commands.d.ts +10 -1
- package/dest/utils/commands.d.ts.map +1 -1
- package/dest/utils/commands.js +30 -3
- package/package.json +28 -24
- package/src/cmds/validator_keys/add.ts +113 -0
- package/src/cmds/validator_keys/generate_bls_keypair.ts +33 -0
- package/src/cmds/validator_keys/index.ts +96 -0
- package/src/cmds/validator_keys/new.ts +120 -0
- package/src/cmds/validator_keys/shared.ts +321 -0
- package/src/utils/commands.ts +41 -3
package/dest/utils/commands.js
CHANGED
|
@@ -73,6 +73,27 @@ export const logJson = (log)=>(obj)=>log(JSON.stringify(obj, null, 2));
|
|
|
73
73
|
}
|
|
74
74
|
return from;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Parses and validates a hex string. Removes leading 0x if present, checks for hex validity,
|
|
78
|
+
* and enforces an optional minimum length.
|
|
79
|
+
* @param hex - The hex string to validate.
|
|
80
|
+
* @param minLen - Optional minimum length (in hex characters, after stripping '0x').
|
|
81
|
+
* @returns The normalized hex string (without leading 0x).
|
|
82
|
+
* @throws InvalidArgumentError if the string is not valid hex or does not meet the minimum length.
|
|
83
|
+
*/ // minLen is now interpreted as the minimum number of bytes (2 hex characters per byte)
|
|
84
|
+
export function parseHex(hex, minLen) {
|
|
85
|
+
const normalized = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
86
|
+
if (!/^[0-9a-fA-F]*$/.test(normalized)) {
|
|
87
|
+
throw new InvalidArgumentError('Invalid hex string');
|
|
88
|
+
}
|
|
89
|
+
if (minLen !== undefined) {
|
|
90
|
+
const minHexLen = minLen * 2;
|
|
91
|
+
if (normalized.length < minHexLen) {
|
|
92
|
+
throw new InvalidArgumentError(`Hex string is too short (length ${normalized.length}), minimum byte length is ${minLen} (hex chars: ${minHexLen})`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return `0x${normalized}`;
|
|
96
|
+
}
|
|
76
97
|
/**
|
|
77
98
|
* Removes the leading 0x from a hex string. If no leading 0x is found the string is returned unchanged.
|
|
78
99
|
* @param hex - A hex string
|
|
@@ -117,7 +138,7 @@ export function parseBigint(bigint) {
|
|
|
117
138
|
try {
|
|
118
139
|
return AztecAddress.fromString(address);
|
|
119
140
|
} catch {
|
|
120
|
-
throw new InvalidArgumentError(`Invalid address: ${address}`);
|
|
141
|
+
throw new InvalidArgumentError(`Invalid Aztec address: ${address}`);
|
|
121
142
|
}
|
|
122
143
|
}
|
|
123
144
|
/**
|
|
@@ -129,7 +150,7 @@ export function parseBigint(bigint) {
|
|
|
129
150
|
try {
|
|
130
151
|
return EthAddress.fromString(address);
|
|
131
152
|
} catch {
|
|
132
|
-
throw new InvalidArgumentError(`Invalid
|
|
153
|
+
throw new InvalidArgumentError(`Invalid Ethereumaddress: ${address}`);
|
|
133
154
|
}
|
|
134
155
|
}
|
|
135
156
|
/**
|
|
@@ -175,7 +196,7 @@ export function parseBigint(bigint) {
|
|
|
175
196
|
* @param value - The string to parse into an integer.
|
|
176
197
|
* @returns The parsed integer, or undefined if the input string is falsy.
|
|
177
198
|
* @throws If the input is not a valid integer.
|
|
178
|
-
*/ export function parseOptionalInteger(value) {
|
|
199
|
+
*/ export function parseOptionalInteger(value, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
|
|
179
200
|
if (!value) {
|
|
180
201
|
return undefined;
|
|
181
202
|
}
|
|
@@ -183,6 +204,12 @@ export function parseBigint(bigint) {
|
|
|
183
204
|
if (!Number.isInteger(parsed)) {
|
|
184
205
|
throw new InvalidArgumentError('Invalid integer.');
|
|
185
206
|
}
|
|
207
|
+
if (parsed < min) {
|
|
208
|
+
throw new InvalidArgumentError(`Value must be greater than ${min}.`);
|
|
209
|
+
}
|
|
210
|
+
if (parsed > max) {
|
|
211
|
+
throw new InvalidArgumentError(`Value must be less than ${max}.`);
|
|
212
|
+
}
|
|
186
213
|
return parsed;
|
|
187
214
|
}
|
|
188
215
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/cli",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20251031",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./contracts": "./dest/cmds/contracts/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"./aztec_node": "./dest/cmds/aztec_node/index.js",
|
|
11
11
|
"./cli-utils": "./dest/utils/index.js",
|
|
12
12
|
"./misc": "./dest/cmds/misc/index.js",
|
|
13
|
+
"./validator_keys": "./dest/cmds/validator_keys/index.js",
|
|
13
14
|
"./setup-contracts": "./dest/cmds/misc/setup_contracts.js",
|
|
14
15
|
"./utils": "./dest/utils/index.js",
|
|
15
16
|
"./inspect": "./dest/utils/inspect.js",
|
|
@@ -70,22 +71,25 @@
|
|
|
70
71
|
]
|
|
71
72
|
},
|
|
72
73
|
"dependencies": {
|
|
73
|
-
"@aztec/accounts": "3.0.0-nightly.
|
|
74
|
-
"@aztec/archiver": "3.0.0-nightly.
|
|
75
|
-
"@aztec/aztec.js": "3.0.0-nightly.
|
|
76
|
-
"@aztec/constants": "3.0.0-nightly.
|
|
77
|
-
"@aztec/entrypoints": "3.0.0-nightly.
|
|
78
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
79
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
80
|
-
"@aztec/l1-artifacts": "3.0.0-nightly.
|
|
81
|
-
"@aztec/node-
|
|
82
|
-
"@aztec/
|
|
83
|
-
"@aztec/
|
|
84
|
-
"@aztec/
|
|
85
|
-
"@aztec/
|
|
86
|
-
"@aztec/
|
|
74
|
+
"@aztec/accounts": "3.0.0-nightly.20251031",
|
|
75
|
+
"@aztec/archiver": "3.0.0-nightly.20251031",
|
|
76
|
+
"@aztec/aztec.js": "3.0.0-nightly.20251031",
|
|
77
|
+
"@aztec/constants": "3.0.0-nightly.20251031",
|
|
78
|
+
"@aztec/entrypoints": "3.0.0-nightly.20251031",
|
|
79
|
+
"@aztec/ethereum": "3.0.0-nightly.20251031",
|
|
80
|
+
"@aztec/foundation": "3.0.0-nightly.20251031",
|
|
81
|
+
"@aztec/l1-artifacts": "3.0.0-nightly.20251031",
|
|
82
|
+
"@aztec/node-keystore": "3.0.0-nightly.20251031",
|
|
83
|
+
"@aztec/node-lib": "3.0.0-nightly.20251031",
|
|
84
|
+
"@aztec/p2p": "3.0.0-nightly.20251031",
|
|
85
|
+
"@aztec/protocol-contracts": "3.0.0-nightly.20251031",
|
|
86
|
+
"@aztec/stdlib": "3.0.0-nightly.20251031",
|
|
87
|
+
"@aztec/test-wallet": "3.0.0-nightly.20251031",
|
|
88
|
+
"@aztec/world-state": "3.0.0-nightly.20251031",
|
|
89
|
+
"@ethersproject/wallet": "^5.8.0",
|
|
87
90
|
"@iarna/toml": "^2.2.5",
|
|
88
91
|
"@libp2p/peer-id-factory": "^3.0.4",
|
|
92
|
+
"@scure/bip39": "^2.0.1",
|
|
89
93
|
"commander": "^12.1.0",
|
|
90
94
|
"lodash.chunk": "^4.2.0",
|
|
91
95
|
"lodash.groupby": "^4.6.0",
|
|
@@ -110,15 +114,15 @@
|
|
|
110
114
|
"typescript": "^5.3.3"
|
|
111
115
|
},
|
|
112
116
|
"peerDependencies": {
|
|
113
|
-
"@aztec/accounts": "3.0.0-nightly.
|
|
114
|
-
"@aztec/bb-prover": "3.0.0-nightly.
|
|
115
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
116
|
-
"@aztec/l1-artifacts": "3.0.0-nightly.
|
|
117
|
-
"@aztec/noir-contracts.js": "3.0.0-nightly.
|
|
118
|
-
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.
|
|
119
|
-
"@aztec/noir-test-contracts.js": "3.0.0-nightly.
|
|
120
|
-
"@aztec/protocol-contracts": "3.0.0-nightly.
|
|
121
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
117
|
+
"@aztec/accounts": "3.0.0-nightly.20251031",
|
|
118
|
+
"@aztec/bb-prover": "3.0.0-nightly.20251031",
|
|
119
|
+
"@aztec/ethereum": "3.0.0-nightly.20251031",
|
|
120
|
+
"@aztec/l1-artifacts": "3.0.0-nightly.20251031",
|
|
121
|
+
"@aztec/noir-contracts.js": "3.0.0-nightly.20251031",
|
|
122
|
+
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.20251031",
|
|
123
|
+
"@aztec/noir-test-contracts.js": "3.0.0-nightly.20251031",
|
|
124
|
+
"@aztec/protocol-contracts": "3.0.0-nightly.20251031",
|
|
125
|
+
"@aztec/stdlib": "3.0.0-nightly.20251031"
|
|
122
126
|
},
|
|
123
127
|
"files": [
|
|
124
128
|
"dest",
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
|
|
20
|
+
export type AddValidatorKeysOptions = NewValidatorKeystoreOptions;
|
|
21
|
+
|
|
22
|
+
export async function addValidatorKeys(existing: string, options: AddValidatorKeysOptions, log: LogFn) {
|
|
23
|
+
const {
|
|
24
|
+
dataDir,
|
|
25
|
+
file,
|
|
26
|
+
count,
|
|
27
|
+
publisherCount = 0,
|
|
28
|
+
mnemonic,
|
|
29
|
+
accountIndex = 0,
|
|
30
|
+
addressIndex,
|
|
31
|
+
ikm,
|
|
32
|
+
blsPath,
|
|
33
|
+
blsOnly,
|
|
34
|
+
json,
|
|
35
|
+
feeRecipient: feeRecipientOpt,
|
|
36
|
+
coinbase: coinbaseOpt,
|
|
37
|
+
fundingAccount: fundingAccountOpt,
|
|
38
|
+
remoteSigner: remoteSignerOpt,
|
|
39
|
+
password,
|
|
40
|
+
outDir,
|
|
41
|
+
} = options;
|
|
42
|
+
|
|
43
|
+
const validatorCount = typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
|
|
44
|
+
const baseAddressIndex = addressIndex ?? 0;
|
|
45
|
+
|
|
46
|
+
const keystore: KeyStore = loadKeystoreFile(existing);
|
|
47
|
+
|
|
48
|
+
if (!keystore.validators || !Array.isArray(keystore.validators)) {
|
|
49
|
+
throw new Error('Invalid keystore: missing validators array');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const first = keystore.validators[0] ?? {};
|
|
53
|
+
const feeRecipient = feeRecipientOpt ?? first.feeRecipient;
|
|
54
|
+
if (!feeRecipient) {
|
|
55
|
+
throw new Error('feeRecipient is required (either present in existing file or via --fee-recipient)');
|
|
56
|
+
}
|
|
57
|
+
const coinbase = (coinbaseOpt as EthAddress | undefined) ?? (first.coinbase as EthAddress | undefined);
|
|
58
|
+
const fundingAccount =
|
|
59
|
+
(fundingAccountOpt as EthAddress | undefined) ?? (first.fundingAccount as EthAddress | undefined);
|
|
60
|
+
const derivedRemoteSigner = (first.attester as any)?.remoteSignerUrl || (first.attester as any)?.eth?.remoteSignerUrl;
|
|
61
|
+
const remoteSigner = remoteSignerOpt ?? derivedRemoteSigner;
|
|
62
|
+
|
|
63
|
+
// Ensure we always have a mnemonic for key derivation if none was provided
|
|
64
|
+
const mnemonicToUse = mnemonic ?? generateMnemonic(wordlist);
|
|
65
|
+
|
|
66
|
+
// If user explicitly provided --address-index, use it as-is. Otherwise, append after existing validators.
|
|
67
|
+
const effectiveBaseAddressIndex =
|
|
68
|
+
addressIndex === undefined ? baseAddressIndex + keystore.validators.length : baseAddressIndex;
|
|
69
|
+
|
|
70
|
+
const { validators, summaries } = await buildValidatorEntries({
|
|
71
|
+
validatorCount,
|
|
72
|
+
publisherCount,
|
|
73
|
+
accountIndex,
|
|
74
|
+
baseAddressIndex: effectiveBaseAddressIndex,
|
|
75
|
+
mnemonic: mnemonicToUse,
|
|
76
|
+
ikm,
|
|
77
|
+
blsPath,
|
|
78
|
+
blsOnly,
|
|
79
|
+
feeRecipient,
|
|
80
|
+
coinbase,
|
|
81
|
+
remoteSigner,
|
|
82
|
+
fundingAccount,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
keystore.validators.push(...validators);
|
|
86
|
+
|
|
87
|
+
// If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
|
|
88
|
+
if (password !== undefined) {
|
|
89
|
+
const targetDir =
|
|
90
|
+
outDir && outDir.length > 0 ? outDir : dataDir && dataDir.length > 0 ? dataDir : dirname(existing);
|
|
91
|
+
await writeEthJsonV3ToFile(keystore.validators, { outDir: targetDir, password });
|
|
92
|
+
await writeBlsBn254ToFile(keystore.validators, { outDir: targetDir, password });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let outputPath = existing;
|
|
96
|
+
if (file && file.length > 0) {
|
|
97
|
+
if (isAbsolute(file)) {
|
|
98
|
+
outputPath = file;
|
|
99
|
+
} else if (dataDir && dataDir.length > 0) {
|
|
100
|
+
outputPath = join(dataDir, file);
|
|
101
|
+
} else {
|
|
102
|
+
outputPath = join(dirname(existing), file);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
await writeKeystoreFile(outputPath, keystore);
|
|
107
|
+
|
|
108
|
+
if (!json) {
|
|
109
|
+
log(`Updated keystore ${outputPath} with ${validators.length} new validator(s)`);
|
|
110
|
+
logValidatorSummaries(log, summaries);
|
|
111
|
+
}
|
|
112
|
+
maybePrintJson(log, !!json, keystore as unknown as Record<string, any>);
|
|
113
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { deriveBlsPrivateKey } from '@aztec/foundation/crypto';
|
|
2
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
3
|
+
|
|
4
|
+
import { writeFile } from 'fs/promises';
|
|
5
|
+
|
|
6
|
+
import { computeBlsPublicKeyCompressed, withValidatorIndex } from './shared.js';
|
|
7
|
+
|
|
8
|
+
export type GenerateBlsKeypairOptions = {
|
|
9
|
+
mnemonic?: string;
|
|
10
|
+
ikm?: string;
|
|
11
|
+
blsPath?: string;
|
|
12
|
+
g2?: boolean;
|
|
13
|
+
compressed?: boolean;
|
|
14
|
+
json?: boolean;
|
|
15
|
+
out?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export async function generateBlsKeypair(options: GenerateBlsKeypairOptions, log: LogFn) {
|
|
19
|
+
const { mnemonic, ikm, blsPath, compressed = true, json, out } = options;
|
|
20
|
+
const path = withValidatorIndex(blsPath ?? 'm/12381/3600/0/0/0', 0);
|
|
21
|
+
const priv = deriveBlsPrivateKey(mnemonic, ikm, path);
|
|
22
|
+
const pub = await computeBlsPublicKeyCompressed(priv);
|
|
23
|
+
const result = { path, privateKey: priv, publicKey: pub, format: compressed ? 'compressed' : 'uncompressed' };
|
|
24
|
+
if (out) {
|
|
25
|
+
await writeFile(out, JSON.stringify(result, null, 2), { encoding: 'utf-8' });
|
|
26
|
+
if (!json) {
|
|
27
|
+
log(`Wrote BLS keypair to ${out}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (json || !out) {
|
|
31
|
+
log(JSON.stringify(result, null, 2));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
|
|
5
|
+
import { parseAztecAddress, parseEthereumAddress, parseHex, parseOptionalInteger } from '../../utils/commands.js';
|
|
6
|
+
|
|
7
|
+
export function injectCommands(program: Command, log: LogFn) {
|
|
8
|
+
const group = program
|
|
9
|
+
.command('validator-keys')
|
|
10
|
+
.aliases(['valKeys'])
|
|
11
|
+
.description('Manage validator keystores for node operators');
|
|
12
|
+
|
|
13
|
+
group
|
|
14
|
+
.command('new')
|
|
15
|
+
.summary('Generate a new validator keystore JSON')
|
|
16
|
+
.description('Generates a new validator keystore with ETH secp256k1 accounts and optional BLS accounts')
|
|
17
|
+
.option('--data-dir <path>', 'Directory to store keystore(s). Defaults to ~/.aztec/keystore')
|
|
18
|
+
.option('--file <name>', 'Keystore file name. Defaults to key1.json (or keyN.json if key1.json exists)')
|
|
19
|
+
.option('--count <N>', 'Number of validators to generate', parseOptionalInteger)
|
|
20
|
+
.option('--publisher-count <N>', 'Number of publisher accounts per validator (default 1)', value =>
|
|
21
|
+
parseOptionalInteger(value, 0),
|
|
22
|
+
)
|
|
23
|
+
.option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation')
|
|
24
|
+
.option('--passphrase <str>', 'Optional passphrase for mnemonic')
|
|
25
|
+
.option('--account-index <N>', 'Base account index for ETH derivation', parseOptionalInteger)
|
|
26
|
+
.option('--address-index <N>', 'Base address index for ETH derivation', parseOptionalInteger)
|
|
27
|
+
.option('--coinbase <address>', 'Coinbase ETH address to use when proposing', parseEthereumAddress)
|
|
28
|
+
.option('--funding-account <address>', 'ETH account to fund publishers', parseEthereumAddress)
|
|
29
|
+
.option('--remote-signer <url>', 'Default remote signer URL for accounts in this file')
|
|
30
|
+
.option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', value => parseHex(value, 32))
|
|
31
|
+
.option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)')
|
|
32
|
+
.option('--bls-only', 'Generate only BLS keys')
|
|
33
|
+
.option(
|
|
34
|
+
'--password <str>',
|
|
35
|
+
'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed',
|
|
36
|
+
)
|
|
37
|
+
.option('--out-dir <dir>', 'Output directory for generated keystore file(s)')
|
|
38
|
+
.option('--json', 'Echo resulting JSON to stdout')
|
|
39
|
+
.requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress)
|
|
40
|
+
.action(async options => {
|
|
41
|
+
const { newValidatorKeystore } = await import('./new.js');
|
|
42
|
+
await newValidatorKeystore(options, log);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
group
|
|
46
|
+
.command('add')
|
|
47
|
+
.summary('Augment an existing validator keystore JSON')
|
|
48
|
+
.description('Adds attester/publisher/BLS entries to an existing keystore using the same flags as new')
|
|
49
|
+
.argument('<existing>', 'Path to existing keystore JSON')
|
|
50
|
+
.option('--data-dir <path>', 'Directory where keystore(s) live')
|
|
51
|
+
.option('--file <name>', 'Override output file name')
|
|
52
|
+
.option('--count <N>', 'Number of validators to add', parseOptionalInteger)
|
|
53
|
+
.option('--publisher-count <N>', 'Number of publisher accounts per validator (default 1)', value =>
|
|
54
|
+
parseOptionalInteger(value, 0),
|
|
55
|
+
)
|
|
56
|
+
.option('--mnemonic <mnemonic>', 'Mnemonic for ETH/BLS derivation')
|
|
57
|
+
.option('--passphrase <str>', 'Optional passphrase for mnemonic')
|
|
58
|
+
.option('--account-index <N>', 'Base account index for ETH derivation', parseOptionalInteger)
|
|
59
|
+
.option('--address-index <N>', 'Base address index for ETH derivation', parseOptionalInteger)
|
|
60
|
+
.option('--coinbase <address>', 'Coinbase ETH address to use when proposing', parseEthereumAddress)
|
|
61
|
+
.option('--funding-account <address>', 'ETH account to fund publishers', parseEthereumAddress)
|
|
62
|
+
.option('--remote-signer <url>', 'Default remote signer URL for accounts in this file')
|
|
63
|
+
.option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', value => parseHex(value, 32))
|
|
64
|
+
.option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)')
|
|
65
|
+
.option('--bls-only', 'Generate only BLS keys')
|
|
66
|
+
.option('--empty', 'Generate an empty skeleton without keys')
|
|
67
|
+
.option(
|
|
68
|
+
'--password <str>',
|
|
69
|
+
'Password for writing keystore files (ETH JSON V3 and BLS EIP-2335). Empty string allowed',
|
|
70
|
+
)
|
|
71
|
+
.option('--out-dir <dir>', 'Output directory for generated keystore file(s)')
|
|
72
|
+
.option('--json', 'Echo resulting JSON to stdout')
|
|
73
|
+
.requiredOption('--fee-recipient <address>', 'Aztec address that will receive fees', parseAztecAddress)
|
|
74
|
+
.action(async (existing: string, options) => {
|
|
75
|
+
const { addValidatorKeys } = await import('./add.js');
|
|
76
|
+
await addValidatorKeys(existing, options, log);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// top-level convenience: aztec generate-bls-keypair
|
|
80
|
+
program
|
|
81
|
+
.command('generate-bls-keypair')
|
|
82
|
+
.description('Generate a BLS keypair with convenience flags')
|
|
83
|
+
.option('--mnemonic <mnemonic>', 'Mnemonic for BLS derivation')
|
|
84
|
+
.option('--ikm <hex>', 'Initial keying material for BLS (alternative to mnemonic)', value => parseHex(value, 32))
|
|
85
|
+
.option('--bls-path <path>', 'EIP-2334 path (default m/12381/3600/0/0/0)')
|
|
86
|
+
.option('--g2', 'Derive on G2 subgroup')
|
|
87
|
+
.option('--compressed', 'Output compressed public key')
|
|
88
|
+
.option('--json', 'Print JSON output to stdout')
|
|
89
|
+
.option('--out <file>', 'Write output to file')
|
|
90
|
+
.action(async options => {
|
|
91
|
+
const { generateBlsKeypair } = await import('./generate_bls_keypair.js');
|
|
92
|
+
await generateBlsKeypair(options, log);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return program;
|
|
96
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
|
|
5
|
+
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
6
|
+
import { dirname } from 'path';
|
|
7
|
+
import { generateMnemonic, mnemonicToAccount } from 'viem/accounts';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
buildValidatorEntries,
|
|
11
|
+
logValidatorSummaries,
|
|
12
|
+
maybePrintJson,
|
|
13
|
+
resolveKeystoreOutputPath,
|
|
14
|
+
writeBlsBn254ToFile,
|
|
15
|
+
writeEthJsonV3ToFile,
|
|
16
|
+
writeKeystoreFile,
|
|
17
|
+
} from './shared.js';
|
|
18
|
+
|
|
19
|
+
export type NewValidatorKeystoreOptions = {
|
|
20
|
+
dataDir?: string;
|
|
21
|
+
file?: string;
|
|
22
|
+
count?: number;
|
|
23
|
+
publisherCount?: number;
|
|
24
|
+
mnemonic?: string;
|
|
25
|
+
passphrase?: string;
|
|
26
|
+
accountIndex?: number;
|
|
27
|
+
addressIndex?: number;
|
|
28
|
+
separatePublisher?: boolean;
|
|
29
|
+
ikm?: string;
|
|
30
|
+
blsPath?: string;
|
|
31
|
+
blsOnly?: boolean;
|
|
32
|
+
password?: string;
|
|
33
|
+
outDir?: string;
|
|
34
|
+
json?: boolean;
|
|
35
|
+
feeRecipient: AztecAddress;
|
|
36
|
+
coinbase?: EthAddress;
|
|
37
|
+
remoteSigner?: string;
|
|
38
|
+
fundingAccount?: EthAddress;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export async function newValidatorKeystore(options: NewValidatorKeystoreOptions, log: LogFn) {
|
|
42
|
+
const {
|
|
43
|
+
dataDir,
|
|
44
|
+
file,
|
|
45
|
+
count,
|
|
46
|
+
publisherCount = 0,
|
|
47
|
+
json,
|
|
48
|
+
coinbase,
|
|
49
|
+
accountIndex = 0,
|
|
50
|
+
addressIndex = 0,
|
|
51
|
+
feeRecipient,
|
|
52
|
+
remoteSigner,
|
|
53
|
+
fundingAccount,
|
|
54
|
+
blsOnly,
|
|
55
|
+
blsPath,
|
|
56
|
+
ikm,
|
|
57
|
+
mnemonic: _mnemonic,
|
|
58
|
+
password,
|
|
59
|
+
outDir,
|
|
60
|
+
} = options;
|
|
61
|
+
|
|
62
|
+
if (remoteSigner && !_mnemonic) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'Using --remote-signer requires a deterministic key source. Provide --mnemonic to derive keys, or omit --remote-signer to write new private keys to keystore.',
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const mnemonic = _mnemonic ?? generateMnemonic(wordlist);
|
|
69
|
+
|
|
70
|
+
const validatorCount = typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
|
|
71
|
+
const { outputPath } = await resolveKeystoreOutputPath(dataDir, file);
|
|
72
|
+
|
|
73
|
+
const { validators, summaries } = await buildValidatorEntries({
|
|
74
|
+
validatorCount,
|
|
75
|
+
publisherCount,
|
|
76
|
+
accountIndex,
|
|
77
|
+
baseAddressIndex: addressIndex,
|
|
78
|
+
mnemonic,
|
|
79
|
+
ikm,
|
|
80
|
+
blsPath,
|
|
81
|
+
blsOnly,
|
|
82
|
+
feeRecipient,
|
|
83
|
+
coinbase,
|
|
84
|
+
remoteSigner,
|
|
85
|
+
fundingAccount,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// If password provided, write ETH JSON V3 and BLS BN254 keystores and replace plaintext
|
|
89
|
+
if (password !== undefined) {
|
|
90
|
+
const keystoreOutDir = outDir && outDir.length > 0 ? outDir : dirname(outputPath);
|
|
91
|
+
await writeEthJsonV3ToFile(validators, { outDir: keystoreOutDir, password });
|
|
92
|
+
await writeBlsBn254ToFile(validators, { outDir: keystoreOutDir, password });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const keystore = {
|
|
96
|
+
schemaVersion: 1,
|
|
97
|
+
validators,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
await writeKeystoreFile(outputPath, keystore);
|
|
101
|
+
|
|
102
|
+
maybePrintJson(log, json, keystore as unknown as Record<string, any>);
|
|
103
|
+
if (!json) {
|
|
104
|
+
log(`Wrote validator keystore to ${outputPath}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Always print a concise summary of public keys (addresses and BLS pubkeys)
|
|
108
|
+
logValidatorSummaries(log, summaries);
|
|
109
|
+
|
|
110
|
+
if (!blsOnly && mnemonic && remoteSigner) {
|
|
111
|
+
for (let i = 0; i < validatorCount; i++) {
|
|
112
|
+
const addrIdx = addressIndex + i;
|
|
113
|
+
const acct = mnemonicToAccount(mnemonic, {
|
|
114
|
+
accountIndex,
|
|
115
|
+
addressIndex: addrIdx,
|
|
116
|
+
});
|
|
117
|
+
log(`attester address: ${acct.address} remoteSignerUrl: ${remoteSigner}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|