@aztec/cli 2.1.0-rc.24 → 2.1.0-rc.27
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 +27 -23
- 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
|
@@ -74,6 +74,27 @@ export const logJson = (log)=>(obj)=>log(JSON.stringify(obj, null, 2));
|
|
|
74
74
|
}
|
|
75
75
|
return from;
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Parses and validates a hex string. Removes leading 0x if present, checks for hex validity,
|
|
79
|
+
* and enforces an optional minimum length.
|
|
80
|
+
* @param hex - The hex string to validate.
|
|
81
|
+
* @param minLen - Optional minimum length (in hex characters, after stripping '0x').
|
|
82
|
+
* @returns The normalized hex string (without leading 0x).
|
|
83
|
+
* @throws InvalidArgumentError if the string is not valid hex or does not meet the minimum length.
|
|
84
|
+
*/ // minLen is now interpreted as the minimum number of bytes (2 hex characters per byte)
|
|
85
|
+
export function parseHex(hex, minLen) {
|
|
86
|
+
const normalized = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
87
|
+
if (!/^[0-9a-fA-F]*$/.test(normalized)) {
|
|
88
|
+
throw new InvalidArgumentError('Invalid hex string');
|
|
89
|
+
}
|
|
90
|
+
if (minLen !== undefined) {
|
|
91
|
+
const minHexLen = minLen * 2;
|
|
92
|
+
if (normalized.length < minHexLen) {
|
|
93
|
+
throw new InvalidArgumentError(`Hex string is too short (length ${normalized.length}), minimum byte length is ${minLen} (hex chars: ${minHexLen})`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return `0x${normalized}`;
|
|
97
|
+
}
|
|
77
98
|
/**
|
|
78
99
|
* Removes the leading 0x from a hex string. If no leading 0x is found the string is returned unchanged.
|
|
79
100
|
* @param hex - A hex string
|
|
@@ -118,7 +139,7 @@ export function parseBigint(bigint) {
|
|
|
118
139
|
try {
|
|
119
140
|
return AztecAddress.fromString(address);
|
|
120
141
|
} catch {
|
|
121
|
-
throw new InvalidArgumentError(`Invalid address: ${address}`);
|
|
142
|
+
throw new InvalidArgumentError(`Invalid Aztec address: ${address}`);
|
|
122
143
|
}
|
|
123
144
|
}
|
|
124
145
|
/**
|
|
@@ -130,7 +151,7 @@ export function parseBigint(bigint) {
|
|
|
130
151
|
try {
|
|
131
152
|
return EthAddress.fromString(address);
|
|
132
153
|
} catch {
|
|
133
|
-
throw new InvalidArgumentError(`Invalid
|
|
154
|
+
throw new InvalidArgumentError(`Invalid Ethereumaddress: ${address}`);
|
|
134
155
|
}
|
|
135
156
|
}
|
|
136
157
|
/**
|
|
@@ -176,7 +197,7 @@ export function parseBigint(bigint) {
|
|
|
176
197
|
* @param value - The string to parse into an integer.
|
|
177
198
|
* @returns The parsed integer, or undefined if the input string is falsy.
|
|
178
199
|
* @throws If the input is not a valid integer.
|
|
179
|
-
*/ export function parseOptionalInteger(value) {
|
|
200
|
+
*/ export function parseOptionalInteger(value, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
|
|
180
201
|
if (!value) {
|
|
181
202
|
return undefined;
|
|
182
203
|
}
|
|
@@ -184,6 +205,12 @@ export function parseBigint(bigint) {
|
|
|
184
205
|
if (!Number.isInteger(parsed)) {
|
|
185
206
|
throw new InvalidArgumentError('Invalid integer.');
|
|
186
207
|
}
|
|
208
|
+
if (parsed < min) {
|
|
209
|
+
throw new InvalidArgumentError(`Value must be greater than ${min}.`);
|
|
210
|
+
}
|
|
211
|
+
if (parsed > max) {
|
|
212
|
+
throw new InvalidArgumentError(`Value must be less than ${max}.`);
|
|
213
|
+
}
|
|
187
214
|
return parsed;
|
|
188
215
|
}
|
|
189
216
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/cli",
|
|
3
|
-
"version": "2.1.0-rc.
|
|
3
|
+
"version": "2.1.0-rc.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./contracts": "./dest/cmds/contracts/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"./pxe": "./dest/cmds/pxe/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,19 +71,22 @@
|
|
|
70
71
|
]
|
|
71
72
|
},
|
|
72
73
|
"dependencies": {
|
|
73
|
-
"@aztec/archiver": "2.1.0-rc.
|
|
74
|
-
"@aztec/aztec.js": "2.1.0-rc.
|
|
75
|
-
"@aztec/constants": "2.1.0-rc.
|
|
76
|
-
"@aztec/entrypoints": "2.1.0-rc.
|
|
77
|
-
"@aztec/ethereum": "2.1.0-rc.
|
|
78
|
-
"@aztec/foundation": "2.1.0-rc.
|
|
79
|
-
"@aztec/l1-artifacts": "2.1.0-rc.
|
|
80
|
-
"@aztec/node-
|
|
81
|
-
"@aztec/
|
|
82
|
-
"@aztec/
|
|
83
|
-
"@aztec/
|
|
74
|
+
"@aztec/archiver": "2.1.0-rc.27",
|
|
75
|
+
"@aztec/aztec.js": "2.1.0-rc.27",
|
|
76
|
+
"@aztec/constants": "2.1.0-rc.27",
|
|
77
|
+
"@aztec/entrypoints": "2.1.0-rc.27",
|
|
78
|
+
"@aztec/ethereum": "2.1.0-rc.27",
|
|
79
|
+
"@aztec/foundation": "2.1.0-rc.27",
|
|
80
|
+
"@aztec/l1-artifacts": "2.1.0-rc.27",
|
|
81
|
+
"@aztec/node-keystore": "2.1.0-rc.27",
|
|
82
|
+
"@aztec/node-lib": "2.1.0-rc.27",
|
|
83
|
+
"@aztec/p2p": "2.1.0-rc.27",
|
|
84
|
+
"@aztec/stdlib": "2.1.0-rc.27",
|
|
85
|
+
"@aztec/world-state": "2.1.0-rc.27",
|
|
86
|
+
"@ethersproject/wallet": "^5.8.0",
|
|
84
87
|
"@iarna/toml": "^2.2.5",
|
|
85
88
|
"@libp2p/peer-id-factory": "^3.0.4",
|
|
89
|
+
"@scure/bip39": "^2.0.1",
|
|
86
90
|
"commander": "^12.1.0",
|
|
87
91
|
"lodash.chunk": "^4.2.0",
|
|
88
92
|
"lodash.groupby": "^4.6.0",
|
|
@@ -92,8 +96,8 @@
|
|
|
92
96
|
"viem": "npm:@spalladino/viem@2.38.2-eip7594.0"
|
|
93
97
|
},
|
|
94
98
|
"devDependencies": {
|
|
95
|
-
"@aztec/accounts": "2.1.0-rc.
|
|
96
|
-
"@aztec/protocol-contracts": "2.1.0-rc.
|
|
99
|
+
"@aztec/accounts": "2.1.0-rc.27",
|
|
100
|
+
"@aztec/protocol-contracts": "2.1.0-rc.27",
|
|
97
101
|
"@jest/globals": "^30.0.0",
|
|
98
102
|
"@types/jest": "^30.0.0",
|
|
99
103
|
"@types/lodash.chunk": "^4.2.9",
|
|
@@ -109,15 +113,15 @@
|
|
|
109
113
|
"typescript": "^5.3.3"
|
|
110
114
|
},
|
|
111
115
|
"peerDependencies": {
|
|
112
|
-
"@aztec/accounts": "2.1.0-rc.
|
|
113
|
-
"@aztec/bb-prover": "2.1.0-rc.
|
|
114
|
-
"@aztec/ethereum": "2.1.0-rc.
|
|
115
|
-
"@aztec/l1-artifacts": "2.1.0-rc.
|
|
116
|
-
"@aztec/noir-contracts.js": "2.1.0-rc.
|
|
117
|
-
"@aztec/noir-protocol-circuits-types": "2.1.0-rc.
|
|
118
|
-
"@aztec/noir-test-contracts.js": "2.1.0-rc.
|
|
119
|
-
"@aztec/protocol-contracts": "2.1.0-rc.
|
|
120
|
-
"@aztec/stdlib": "2.1.0-rc.
|
|
116
|
+
"@aztec/accounts": "2.1.0-rc.27",
|
|
117
|
+
"@aztec/bb-prover": "2.1.0-rc.27",
|
|
118
|
+
"@aztec/ethereum": "2.1.0-rc.27",
|
|
119
|
+
"@aztec/l1-artifacts": "2.1.0-rc.27",
|
|
120
|
+
"@aztec/noir-contracts.js": "2.1.0-rc.27",
|
|
121
|
+
"@aztec/noir-protocol-circuits-types": "2.1.0-rc.27",
|
|
122
|
+
"@aztec/noir-test-contracts.js": "2.1.0-rc.27",
|
|
123
|
+
"@aztec/protocol-contracts": "2.1.0-rc.27",
|
|
124
|
+
"@aztec/stdlib": "2.1.0-rc.27"
|
|
121
125
|
},
|
|
122
126
|
"files": [
|
|
123
127
|
"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
|
+
}
|