@aztec-labs/cli 6.0.0-nightly.20260829

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.
Files changed (227) hide show
  1. package/README.md +23 -0
  2. package/dest/cmds/aztec_node/block_number.d.ts +3 -0
  3. package/dest/cmds/aztec_node/block_number.d.ts.map +1 -0
  4. package/dest/cmds/aztec_node/block_number.js +10 -0
  5. package/dest/cmds/aztec_node/get_block.d.ts +3 -0
  6. package/dest/cmds/aztec_node/get_block.d.ts.map +1 -0
  7. package/dest/cmds/aztec_node/get_block.js +10 -0
  8. package/dest/cmds/aztec_node/get_current_min_fee.d.ts +3 -0
  9. package/dest/cmds/aztec_node/get_current_min_fee.d.ts.map +1 -0
  10. package/dest/cmds/aztec_node/get_current_min_fee.js +7 -0
  11. package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts +5 -0
  12. package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts.map +1 -0
  13. package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.js +12 -0
  14. package/dest/cmds/aztec_node/get_logs.d.ts +33 -0
  15. package/dest/cmds/aztec_node/get_logs.d.ts.map +1 -0
  16. package/dest/cmds/aztec_node/get_logs.js +61 -0
  17. package/dest/cmds/aztec_node/get_node_info.d.ts +3 -0
  18. package/dest/cmds/aztec_node/get_node_info.d.ts.map +1 -0
  19. package/dest/cmds/aztec_node/get_node_info.js +58 -0
  20. package/dest/cmds/aztec_node/index.d.ts +4 -0
  21. package/dest/cmds/aztec_node/index.d.ts.map +1 -0
  22. package/dest/cmds/aztec_node/index.js +38 -0
  23. package/dest/cmds/infrastructure/index.d.ts +4 -0
  24. package/dest/cmds/infrastructure/index.d.ts.map +1 -0
  25. package/dest/cmds/infrastructure/index.js +22 -0
  26. package/dest/cmds/infrastructure/sequencers.d.ts +12 -0
  27. package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -0
  28. package/dest/cmds/infrastructure/sequencers.js +113 -0
  29. package/dest/cmds/infrastructure/setup_l2_contract.d.ts +3 -0
  30. package/dest/cmds/infrastructure/setup_l2_contract.d.ts.map +1 -0
  31. package/dest/cmds/infrastructure/setup_l2_contract.js +35 -0
  32. package/dest/cmds/l1/advance_epoch.d.ts +3 -0
  33. package/dest/cmds/l1/advance_epoch.d.ts.map +1 -0
  34. package/dest/cmds/l1/advance_epoch.js +12 -0
  35. package/dest/cmds/l1/assume_proven_through.d.ts +4 -0
  36. package/dest/cmds/l1/assume_proven_through.d.ts.map +1 -0
  37. package/dest/cmds/l1/assume_proven_through.js +12 -0
  38. package/dest/cmds/l1/compute_genesis_values.d.ts +4 -0
  39. package/dest/cmds/l1/compute_genesis_values.d.ts.map +1 -0
  40. package/dest/cmds/l1/compute_genesis_values.js +17 -0
  41. package/dest/cmds/l1/create_l1_account.d.ts +3 -0
  42. package/dest/cmds/l1/create_l1_account.d.ts.map +1 -0
  43. package/dest/cmds/l1/create_l1_account.js +15 -0
  44. package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts +4 -0
  45. package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts.map +1 -0
  46. package/dest/cmds/l1/deploy_l1_contracts_cmd.js +80 -0
  47. package/dest/cmds/l1/deploy_new_rollup.d.ts +5 -0
  48. package/dest/cmds/l1/deploy_new_rollup.d.ts.map +1 -0
  49. package/dest/cmds/l1/deploy_new_rollup.js +26 -0
  50. package/dest/cmds/l1/get_l1_addresses.d.ts +4 -0
  51. package/dest/cmds/l1/get_l1_addresses.d.ts.map +1 -0
  52. package/dest/cmds/l1/get_l1_addresses.js +21 -0
  53. package/dest/cmds/l1/get_l1_balance.d.ts +4 -0
  54. package/dest/cmds/l1/get_l1_balance.d.ts.map +1 -0
  55. package/dest/cmds/l1/get_l1_balance.js +35 -0
  56. package/dest/cmds/l1/governance_utils.d.ts +50 -0
  57. package/dest/cmds/l1/governance_utils.d.ts.map +1 -0
  58. package/dest/cmds/l1/governance_utils.js +87 -0
  59. package/dest/cmds/l1/index.d.ts +4 -0
  60. package/dest/cmds/l1/index.d.ts.map +1 -0
  61. package/dest/cmds/l1/index.js +201 -0
  62. package/dest/cmds/l1/prover_stats.d.ts +14 -0
  63. package/dest/cmds/l1/prover_stats.d.ts.map +1 -0
  64. package/dest/cmds/l1/prover_stats.js +147 -0
  65. package/dest/cmds/l1/trigger_seed_snapshot.d.ts +6 -0
  66. package/dest/cmds/l1/trigger_seed_snapshot.d.ts.map +1 -0
  67. package/dest/cmds/l1/trigger_seed_snapshot.js +20 -0
  68. package/dest/cmds/l1/update_l1_validators.d.ts +45 -0
  69. package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -0
  70. package/dest/cmds/l1/update_l1_validators.js +280 -0
  71. package/dest/cmds/misc/generate_bootnode_enr.d.ts +3 -0
  72. package/dest/cmds/misc/generate_bootnode_enr.d.ts.map +1 -0
  73. package/dest/cmds/misc/generate_bootnode_enr.js +5 -0
  74. package/dest/cmds/misc/generate_p2p_private_key.d.ts +3 -0
  75. package/dest/cmds/misc/generate_p2p_private_key.d.ts.map +1 -0
  76. package/dest/cmds/misc/generate_p2p_private_key.js +7 -0
  77. package/dest/cmds/misc/generate_secret_key.d.ts +5 -0
  78. package/dest/cmds/misc/generate_secret_key.d.ts.map +1 -0
  79. package/dest/cmds/misc/generate_secret_key.js +6 -0
  80. package/dest/cmds/misc/index.d.ts +4 -0
  81. package/dest/cmds/misc/index.d.ts.map +1 -0
  82. package/dest/cmds/misc/index.js +32 -0
  83. package/dest/cmds/misc/update/common.d.ts +17 -0
  84. package/dest/cmds/misc/update/common.d.ts.map +1 -0
  85. package/dest/cmds/misc/update/common.js +3 -0
  86. package/dest/cmds/misc/update/github.d.ts +3 -0
  87. package/dest/cmds/misc/update/github.d.ts.map +1 -0
  88. package/dest/cmds/misc/update/github.js +2 -0
  89. package/dest/cmds/misc/update/noir.d.ts +10 -0
  90. package/dest/cmds/misc/update/noir.d.ts.map +1 -0
  91. package/dest/cmds/misc/update/noir.js +45 -0
  92. package/dest/cmds/misc/update/npm.d.ts +34 -0
  93. package/dest/cmds/misc/update/npm.d.ts.map +1 -0
  94. package/dest/cmds/misc/update/npm.js +123 -0
  95. package/dest/cmds/misc/update/utils.d.ts +14 -0
  96. package/dest/cmds/misc/update/utils.d.ts.map +1 -0
  97. package/dest/cmds/misc/update/utils.js +38 -0
  98. package/dest/cmds/misc/update.d.ts +3 -0
  99. package/dest/cmds/misc/update.d.ts.map +1 -0
  100. package/dest/cmds/misc/update.js +51 -0
  101. package/dest/cmds/validator_keys/add.d.ts +5 -0
  102. package/dest/cmds/validator_keys/add.d.ts.map +1 -0
  103. package/dest/cmds/validator_keys/add.js +83 -0
  104. package/dest/cmds/validator_keys/eth_json_v3_worker.d.ts +2 -0
  105. package/dest/cmds/validator_keys/eth_json_v3_worker.d.ts.map +1 -0
  106. package/dest/cmds/validator_keys/eth_json_v3_worker.js +27 -0
  107. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts +12 -0
  108. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts.map +1 -0
  109. package/dest/cmds/validator_keys/generate_bls_keypair.js +27 -0
  110. package/dest/cmds/validator_keys/index.d.ts +4 -0
  111. package/dest/cmds/validator_keys/index.d.ts.map +1 -0
  112. package/dest/cmds/validator_keys/index.js +33 -0
  113. package/dest/cmds/validator_keys/new.d.ts +35 -0
  114. package/dest/cmds/validator_keys/new.d.ts.map +1 -0
  115. package/dest/cmds/validator_keys/new.js +220 -0
  116. package/dest/cmds/validator_keys/set_funding_account.d.ts +14 -0
  117. package/dest/cmds/validator_keys/set_funding_account.d.ts.map +1 -0
  118. package/dest/cmds/validator_keys/set_funding_account.js +37 -0
  119. package/dest/cmds/validator_keys/shared.d.ts +81 -0
  120. package/dest/cmds/validator_keys/shared.d.ts.map +1 -0
  121. package/dest/cmds/validator_keys/shared.js +352 -0
  122. package/dest/cmds/validator_keys/staker.d.ts +38 -0
  123. package/dest/cmds/validator_keys/staker.d.ts.map +1 -0
  124. package/dest/cmds/validator_keys/staker.js +210 -0
  125. package/dest/cmds/validator_keys/utils.d.ts +35 -0
  126. package/dest/cmds/validator_keys/utils.d.ts.map +1 -0
  127. package/dest/cmds/validator_keys/utils.js +86 -0
  128. package/dest/config/cached_fetch.d.ts +27 -0
  129. package/dest/config/cached_fetch.d.ts.map +1 -0
  130. package/dest/config/cached_fetch.js +132 -0
  131. package/dest/config/chain_l2_config.d.ts +19 -0
  132. package/dest/config/chain_l2_config.d.ts.map +1 -0
  133. package/dest/config/chain_l2_config.js +60 -0
  134. package/dest/config/enrich_env.d.ts +4 -0
  135. package/dest/config/enrich_env.d.ts.map +1 -0
  136. package/dest/config/enrich_env.js +12 -0
  137. package/dest/config/generated/networks.d.ts +236 -0
  138. package/dest/config/generated/networks.d.ts.map +1 -0
  139. package/dest/config/generated/networks.js +237 -0
  140. package/dest/config/get_l1_config.d.ts +9 -0
  141. package/dest/config/get_l1_config.d.ts.map +1 -0
  142. package/dest/config/get_l1_config.js +24 -0
  143. package/dest/config/index.d.ts +5 -0
  144. package/dest/config/index.d.ts.map +1 -0
  145. package/dest/config/index.js +4 -0
  146. package/dest/config/network_config.d.ts +22 -0
  147. package/dest/config/network_config.d.ts.map +1 -0
  148. package/dest/config/network_config.js +119 -0
  149. package/dest/utils/aztec.d.ts +56 -0
  150. package/dest/utils/aztec.d.ts.map +1 -0
  151. package/dest/utils/aztec.js +161 -0
  152. package/dest/utils/commands.d.ts +161 -0
  153. package/dest/utils/commands.d.ts.map +1 -0
  154. package/dest/utils/commands.js +341 -0
  155. package/dest/utils/encoding.d.ts +15 -0
  156. package/dest/utils/encoding.d.ts.map +1 -0
  157. package/dest/utils/encoding.js +103 -0
  158. package/dest/utils/github.d.ts +3 -0
  159. package/dest/utils/github.d.ts.map +1 -0
  160. package/dest/utils/github.js +2 -0
  161. package/dest/utils/index.d.ts +6 -0
  162. package/dest/utils/index.d.ts.map +1 -0
  163. package/dest/utils/index.js +5 -0
  164. package/dest/utils/inspect.d.ts +11 -0
  165. package/dest/utils/inspect.d.ts.map +1 -0
  166. package/dest/utils/inspect.js +90 -0
  167. package/dest/utils/setup_contracts.d.ts +3 -0
  168. package/dest/utils/setup_contracts.d.ts.map +1 -0
  169. package/dest/utils/setup_contracts.js +16 -0
  170. package/package.json +141 -0
  171. package/public_include_metric_prefixes.json +1 -0
  172. package/src/cmds/aztec_node/block_number.ts +9 -0
  173. package/src/cmds/aztec_node/get_block.ts +11 -0
  174. package/src/cmds/aztec_node/get_current_min_fee.ts +9 -0
  175. package/src/cmds/aztec_node/get_l1_to_l2_message_witness.ts +27 -0
  176. package/src/cmds/aztec_node/get_logs.ts +100 -0
  177. package/src/cmds/aztec_node/get_node_info.ts +61 -0
  178. package/src/cmds/aztec_node/index.ts +91 -0
  179. package/src/cmds/infrastructure/index.ts +51 -0
  180. package/src/cmds/infrastructure/sequencers.ts +122 -0
  181. package/src/cmds/infrastructure/setup_l2_contract.ts +40 -0
  182. package/src/cmds/l1/advance_epoch.ts +14 -0
  183. package/src/cmds/l1/assume_proven_through.ts +20 -0
  184. package/src/cmds/l1/compute_genesis_values.ts +29 -0
  185. package/src/cmds/l1/create_l1_account.ts +16 -0
  186. package/src/cmds/l1/deploy_l1_contracts_cmd.ts +105 -0
  187. package/src/cmds/l1/deploy_new_rollup.ts +65 -0
  188. package/src/cmds/l1/get_l1_addresses.ts +31 -0
  189. package/src/cmds/l1/get_l1_balance.ts +44 -0
  190. package/src/cmds/l1/governance_utils.ts +183 -0
  191. package/src/cmds/l1/index.ts +499 -0
  192. package/src/cmds/l1/prover_stats.ts +213 -0
  193. package/src/cmds/l1/trigger_seed_snapshot.ts +32 -0
  194. package/src/cmds/l1/update_l1_validators.ts +358 -0
  195. package/src/cmds/misc/generate_bootnode_enr.ts +13 -0
  196. package/src/cmds/misc/generate_p2p_private_key.ts +9 -0
  197. package/src/cmds/misc/generate_secret_key.ts +5 -0
  198. package/src/cmds/misc/index.ts +67 -0
  199. package/src/cmds/misc/update/common.ts +16 -0
  200. package/src/cmds/misc/update/github.ts +2 -0
  201. package/src/cmds/misc/update/noir.ts +56 -0
  202. package/src/cmds/misc/update/npm.ts +148 -0
  203. package/src/cmds/misc/update/utils.ts +49 -0
  204. package/src/cmds/misc/update.ts +71 -0
  205. package/src/cmds/validator_keys/add.ts +122 -0
  206. package/src/cmds/validator_keys/eth_json_v3_worker.ts +30 -0
  207. package/src/cmds/validator_keys/generate_bls_keypair.ts +33 -0
  208. package/src/cmds/validator_keys/index.ts +181 -0
  209. package/src/cmds/validator_keys/new.ts +326 -0
  210. package/src/cmds/validator_keys/set_funding_account.ts +54 -0
  211. package/src/cmds/validator_keys/shared.ts +414 -0
  212. package/src/cmds/validator_keys/staker.ts +300 -0
  213. package/src/cmds/validator_keys/utils.ts +124 -0
  214. package/src/config/cached_fetch.ts +154 -0
  215. package/src/config/chain_l2_config.ts +71 -0
  216. package/src/config/enrich_env.ts +15 -0
  217. package/src/config/generated/networks.ts +241 -0
  218. package/src/config/get_l1_config.ts +31 -0
  219. package/src/config/index.ts +4 -0
  220. package/src/config/network_config.ts +150 -0
  221. package/src/utils/aztec.ts +203 -0
  222. package/src/utils/commands.ts +434 -0
  223. package/src/utils/encoding.ts +117 -0
  224. package/src/utils/github.ts +2 -0
  225. package/src/utils/index.ts +5 -0
  226. package/src/utils/inspect.ts +111 -0
  227. package/src/utils/setup_contracts.ts +19 -0
@@ -0,0 +1,300 @@
1
+ import { prettyPrintJSON } from '@aztec-labs/cli/utils';
2
+ import { createEthereumChain } from '@aztec-labs/ethereum/chain';
3
+ import { GSEContract } from '@aztec-labs/ethereum/contracts';
4
+ import { decryptBn254Keystore } from '@aztec-labs/foundation/crypto/bls/bn254_keystore';
5
+ import { computeBn254G1PublicKey, computeBn254G2PublicKey } from '@aztec-labs/foundation/crypto/bn254';
6
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
7
+ import type { EthAddress } from '@aztec-labs/foundation/eth-address';
8
+ import type { LogFn } from '@aztec-labs/foundation/log';
9
+ import { loadKeystoreFile } from '@aztec-labs/node-keystore/loader';
10
+ import type {
11
+ AttesterAccount,
12
+ AttesterAccounts,
13
+ BLSAccount,
14
+ EncryptedKeyFileConfig,
15
+ EthAccount,
16
+ MnemonicConfig,
17
+ } from '@aztec-labs/node-keystore/types';
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, { batch: false }))),
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,124 @@
1
+ import { EthAddress } from '@aztec-labs/foundation/eth-address';
2
+ import { ethPrivateKeySchema } from '@aztec-labs/node-keystore/schemas';
3
+ import type { EthPrivateKey } from '@aztec-labs/node-keystore/types';
4
+
5
+ export const defaultBlsPath = 'm/12381/3600/0/0/0';
6
+
7
+ export function validateBlsPathOptions(options: {
8
+ count?: number;
9
+ publisherCount?: number;
10
+ accountIndex?: number;
11
+ addressIndex?: number;
12
+ blsPath?: string;
13
+ ikm?: string;
14
+ }) {
15
+ if (options.blsPath && options.blsPath !== defaultBlsPath) {
16
+ if (
17
+ (options.count && options.count !== 1) ||
18
+ (options.publisherCount && options.publisherCount > 0) ||
19
+ (options.accountIndex && options.accountIndex !== 0) ||
20
+ (options.addressIndex && options.addressIndex !== 0)
21
+ ) {
22
+ throw new Error('--bls-path cannot be used with --count, --publisher-count, --account-index, or --address-index');
23
+ }
24
+ }
25
+ }
26
+
27
+ export function validateStakerOutputOptions(options: {
28
+ stakerOutput?: boolean;
29
+ gseAddress?: EthAddress;
30
+ l1RpcUrls?: string[];
31
+ l1ChainId?: number;
32
+ }) {
33
+ if (!options.stakerOutput) {
34
+ return;
35
+ }
36
+ // Required options for staker output
37
+ if (!options.gseAddress) {
38
+ throw new Error('--gse-address is required when using --staker-output');
39
+ }
40
+ if (!options.l1RpcUrls || options.l1RpcUrls.length === 0) {
41
+ throw new Error('--l1-rpc-urls is required when using --staker-output');
42
+ }
43
+
44
+ if (options.l1ChainId === undefined) {
45
+ throw new Error('--l1-chain-id is required when using --staker-output');
46
+ }
47
+ }
48
+
49
+ export function validateRemoteSignerOptions(options: { remoteSigner?: string; mnemonic?: string }) {
50
+ if (options.remoteSigner && !options.mnemonic) {
51
+ throw new Error(
52
+ 'Using --remote-signer requires a deterministic key source. Provide --mnemonic to derive keys, or omit --remote-signer to write new private keys to keystore.',
53
+ );
54
+ }
55
+ }
56
+
57
+ export function validatePublisherOptions(options: { publishers?: string[]; publisherCount?: number }) {
58
+ if (options.publisherCount && options.publisherCount > 0 && options.publishers && options.publishers.length > 0) {
59
+ throw new Error('--publishers and --publisher-count cannot be used together');
60
+ }
61
+
62
+ if (options.publishers && options.publishers.length > 0) {
63
+ // Normalize each private key by adding 0x prefix if missing
64
+ const normalizedKeys: string[] = [];
65
+ for (const key of options.publishers) {
66
+ let privateKey = key.trim();
67
+ if (!privateKey.startsWith('0x')) {
68
+ privateKey = '0x' + privateKey;
69
+ }
70
+
71
+ try {
72
+ ethPrivateKeySchema.parse(privateKey);
73
+ normalizedKeys.push(privateKey);
74
+ } catch (error) {
75
+ throw new Error(`Invalid publisher private key: ${error instanceof Error ? error.message : String(error)}`);
76
+ }
77
+ }
78
+ // Update the options with the normalized keys
79
+ options.publishers = normalizedKeys as EthPrivateKey[];
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Validates and normalizes the `--funding-account` option in place. The value may be a private key
85
+ * (used as a local signer) or an ETH address. An address needs a remote signer to sign funding txs:
86
+ * either `--remote-signer`, or a keystore that already defines one (pass `hasKeystoreRemoteSigner`),
87
+ * which a bare address inherits at runtime.
88
+ */
89
+ export function validateFundingAccountOptions(
90
+ options: { fundingAccount?: string; remoteSigner?: string },
91
+ hasKeystoreRemoteSigner = false,
92
+ ) {
93
+ if (!options.fundingAccount) {
94
+ return;
95
+ }
96
+
97
+ let value = options.fundingAccount.trim();
98
+ if (!value.startsWith('0x')) {
99
+ value = '0x' + value;
100
+ }
101
+
102
+ if (value.length === 66) {
103
+ try {
104
+ ethPrivateKeySchema.parse(value);
105
+ } catch (error) {
106
+ throw new Error(`Invalid funding account private key: ${error instanceof Error ? error.message : String(error)}`);
107
+ }
108
+ } else if (value.length === 42) {
109
+ try {
110
+ EthAddress.fromString(value);
111
+ } catch (error) {
112
+ throw new Error(`Invalid funding account address: ${error instanceof Error ? error.message : String(error)}`);
113
+ }
114
+ if (!options.remoteSigner && !hasKeystoreRemoteSigner) {
115
+ throw new Error(
116
+ '--funding-account as an address requires --remote-signer, or a keystore that already defines a remote signer',
117
+ );
118
+ }
119
+ } else {
120
+ throw new Error('Invalid funding account: expected a 32-byte private key or a 20-byte address');
121
+ }
122
+
123
+ options.fundingAccount = value;
124
+ }
@@ -0,0 +1,154 @@
1
+ import { createLogger } from '@aztec-labs/aztec.js/log';
2
+ import { mkdir, readFile, writeFile } from 'fs/promises';
3
+ import { dirname } from 'path';
4
+
5
+ export interface CachedFetchOptions {
6
+ /** The cache file path for storing data. If not provided, no caching is performed. */
7
+ cacheFile?: string;
8
+ /** Fallback max-age in milliseconds when server sends no Cache-Control header. Defaults to 5 minutes. */
9
+ defaultMaxAgeMs?: number;
10
+ }
11
+
12
+ /** Cache metadata stored in a sidecar .meta file alongside the data file. */
13
+ interface CacheMeta {
14
+ etag?: string;
15
+ expiresAt: number;
16
+ }
17
+
18
+ const DEFAULT_MAX_AGE_MS = 5 * 60 * 1000; // 5 minutes
19
+
20
+ /** Extracts max-age value in milliseconds from a Response's Cache-Control header. Returns undefined if not present. */
21
+ export function parseMaxAge(response: { headers: { get(name: string): string | null } }): number | undefined {
22
+ const cacheControl = response.headers.get('cache-control');
23
+ if (!cacheControl) {
24
+ return undefined;
25
+ }
26
+ const match = cacheControl.match(/max-age=(\d+)/);
27
+ if (!match) {
28
+ return undefined;
29
+ }
30
+ return parseInt(match[1], 10) * 1000;
31
+ }
32
+
33
+ /**
34
+ * Fetches data from a URL with file-based HTTP conditional caching.
35
+ *
36
+ * Data is stored as raw JSON in the cache file (same format as the server returns).
37
+ * Caching metadata (ETag, expiry) is stored in a separate sidecar `.meta` file.
38
+ * This keeps the data file human-readable and backward-compatible with older code.
39
+ *
40
+ * @param url - The URL to fetch from
41
+ * @param options - Caching options
42
+ * @param fetch - Fetch implementation (defaults to globalThis.fetch)
43
+ * @param log - Logger instance
44
+ * @returns The fetched and parsed JSON data, or undefined if fetch fails
45
+ */
46
+ export async function cachedFetch<T = any>(
47
+ url: string,
48
+ options: CachedFetchOptions,
49
+ fetch = globalThis.fetch,
50
+ log = createLogger('cached_fetch'),
51
+ ): Promise<T | undefined> {
52
+ const { cacheFile, defaultMaxAgeMs = DEFAULT_MAX_AGE_MS } = options;
53
+
54
+ // If no cacheFile, just fetch normally without caching
55
+ if (!cacheFile) {
56
+ return fetchAndParse<T>(url, fetch, log);
57
+ }
58
+
59
+ const metaFile = cacheFile + '.meta';
60
+
61
+ // Try to read metadata
62
+ let meta: CacheMeta | undefined;
63
+ try {
64
+ meta = JSON.parse(await readFile(metaFile, 'utf-8'));
65
+ } catch {
66
+ log.trace('No usable cache metadata found');
67
+ }
68
+
69
+ // Try to read cached data
70
+ let cachedData: T | undefined;
71
+ try {
72
+ cachedData = JSON.parse(await readFile(cacheFile, 'utf-8'));
73
+ } catch {
74
+ log.trace('No usable cached data found');
75
+ }
76
+
77
+ // If metadata and data exist and cache is fresh, return directly
78
+ if (meta && cachedData !== undefined && meta.expiresAt > Date.now()) {
79
+ return cachedData;
80
+ }
81
+
82
+ // Cache is stale or missing — make a (possibly conditional) request
83
+ try {
84
+ const headers: Record<string, string> = {};
85
+ if (meta?.etag && cachedData !== undefined) {
86
+ headers['If-None-Match'] = meta.etag;
87
+ }
88
+
89
+ const response = await fetch(url, { headers });
90
+
91
+ if (response.status === 304 && cachedData !== undefined) {
92
+ // Not modified — recompute expiry from new response headers and return cached data
93
+ const maxAgeMs = parseMaxAge(response) ?? defaultMaxAgeMs;
94
+ await writeMetaFile(metaFile, { etag: meta?.etag, expiresAt: Date.now() + maxAgeMs }, log);
95
+ return cachedData;
96
+ }
97
+
98
+ if (!response.ok) {
99
+ log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
100
+ return cachedData;
101
+ }
102
+
103
+ // 200 — parse new data and cache it
104
+ const data = (await response.json()) as T;
105
+ const maxAgeMs = parseMaxAge(response) ?? defaultMaxAgeMs;
106
+ const etag = response.headers.get('etag') ?? undefined;
107
+
108
+ await ensureDir(cacheFile, log);
109
+ await Promise.all([
110
+ writeFile(cacheFile, JSON.stringify(data), 'utf-8'),
111
+ writeFile(metaFile, JSON.stringify({ etag, expiresAt: Date.now() + maxAgeMs }), 'utf-8'),
112
+ ]);
113
+
114
+ return data;
115
+ } catch (err) {
116
+ log.warn(`Failed to fetch from ${url}`, { err });
117
+ return cachedData;
118
+ }
119
+ }
120
+
121
+ async function fetchAndParse<T>(
122
+ url: string,
123
+ fetch: typeof globalThis.fetch,
124
+ log: ReturnType<typeof createLogger>,
125
+ ): Promise<T | undefined> {
126
+ try {
127
+ const response = await fetch(url);
128
+ if (!response.ok) {
129
+ log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
130
+ return undefined;
131
+ }
132
+ return (await response.json()) as T;
133
+ } catch (err) {
134
+ log.warn(`Failed to fetch from ${url}`, { err });
135
+ return undefined;
136
+ }
137
+ }
138
+
139
+ async function ensureDir(filePath: string, log: ReturnType<typeof createLogger>) {
140
+ try {
141
+ await mkdir(dirname(filePath), { recursive: true });
142
+ } catch (err) {
143
+ log.warn('Failed to create cache directory for: ' + filePath, { err });
144
+ }
145
+ }
146
+
147
+ async function writeMetaFile(metaFile: string, meta: CacheMeta, log: ReturnType<typeof createLogger>) {
148
+ try {
149
+ await mkdir(dirname(metaFile), { recursive: true });
150
+ await writeFile(metaFile, JSON.stringify(meta), 'utf-8');
151
+ } catch (err) {
152
+ log.warn('Failed to write cache metadata: ' + metaFile, { err });
153
+ }
154
+ }
@@ -0,0 +1,71 @@
1
+ import type { NetworkNames } from '@aztec-labs/foundation/config';
2
+ import { createLogger } from '@aztec-labs/foundation/log';
3
+ import { type ConsensusEnvVar, checkConsensusEnvOverrides } from '@aztec-labs/stdlib/config';
4
+ import path from 'path';
5
+
6
+ import { devnetConfig, mainnetConfig, testnetConfig } from './generated/networks.js';
7
+
8
+ type NetworkConfigEnv = Record<string, string | number | boolean>;
9
+
10
+ const NetworkConfigs: Partial<Record<NetworkNames, NetworkConfigEnv>> = {
11
+ devnet: devnetConfig,
12
+ testnet: testnetConfig,
13
+ mainnet: mainnetConfig,
14
+ };
15
+
16
+ /** Every generated network config must define every consensus-critical env var. */
17
+ export type ConsensusComplete = Record<ConsensusEnvVar, string | number | boolean>;
18
+ ({ devnetConfig, testnetConfig, mainnetConfig }) satisfies Record<string, ConsensusComplete>;
19
+
20
+ const log = createLogger('cli:chain_l2_config');
21
+
22
+ function enrichEnvironmentWithNetworkConfig(config: NetworkConfigEnv): void {
23
+ for (const [key, value] of Object.entries(config)) {
24
+ if (process.env[key] === undefined && value !== undefined) {
25
+ process.env[key] = String(value);
26
+ }
27
+ }
28
+ }
29
+
30
+ function getDefaultDataDir(networkName: NetworkNames): string {
31
+ return path.join(process.env.HOME || '~', '.aztec', networkName, 'data');
32
+ }
33
+
34
+ /**
35
+ * Sets up environment for the given network.
36
+ *
37
+ * For 'local' network: returns early, using hardcoded defaults from DefaultL1ContractsConfig
38
+ * and DefaultSlasherConfig (which match the 'defaults' section of defaults.yml).
39
+ *
40
+ * For deployed networks: applies network configuration from generated defaults.yml,
41
+ * merging base defaults with network-specific overrides. Before merging, enforces that operators have not
42
+ * overridden any consensus-critical env var with a value diverging from the network config (throwing unless
43
+ * ALLOW_OVERRIDING_NETWORK_CONFIG is set), so all nodes of a network agree on consensus-critical values.
44
+ *
45
+ * @param networkName - The network name
46
+ */
47
+ export function enrichEnvironmentWithChainName(networkName: NetworkNames) {
48
+ // For 'local', we don't inject any env vars - use hardcoded TypeScript/Solidity defaults
49
+ // These defaults are defined in defaults.yml 'defaults' section and match:
50
+ // - DefaultL1ContractsConfig (yarn-project/ethereum/src/config.ts)
51
+ // - Solidity vm.envOr defaults (l1-contracts/script/deploy/RollupConfiguration.sol)
52
+ if (networkName === 'local') {
53
+ return;
54
+ }
55
+
56
+ // Apply generated network config from defaults.yml
57
+ // For devnet iterations (v4-devnet-1, etc.), use the base devnet config
58
+ const configKey = /^v\d+-devnet-\d+$/.test(networkName) ? 'devnet' : networkName;
59
+ const generatedConfig = NetworkConfigs[configKey];
60
+ if (generatedConfig) {
61
+ // The check is pure; this layer owns env mutation, so apply its canonical writes before enriching.
62
+ const canonical = checkConsensusEnvOverrides(generatedConfig, process.env, msg => log.warn(msg));
63
+ Object.assign(process.env, canonical);
64
+ enrichEnvironmentWithNetworkConfig(generatedConfig);
65
+ }
66
+
67
+ // Set DATA_DIRECTORY if not already set
68
+ if (process.env['DATA_DIRECTORY'] === undefined) {
69
+ process.env['DATA_DIRECTORY'] = getDefaultDataDir(networkName);
70
+ }
71
+ }
@@ -0,0 +1,15 @@
1
+ import { EthAddress } from '@aztec-labs/aztec.js/addresses';
2
+ import type { EnvVar } from '@aztec-labs/foundation/config';
3
+
4
+ export function enrichVar(envVar: EnvVar, value: string | undefined) {
5
+ // Don't override
6
+ if (process.env[envVar] || value === undefined) {
7
+ return;
8
+ }
9
+ process.env[envVar] = value;
10
+ }
11
+
12
+ export function enrichEthAddressVar(envVar: EnvVar, value: string) {
13
+ // EthAddress doesn't like being given empty strings
14
+ enrichVar(envVar, value || EthAddress.ZERO.toString());
15
+ }