@aztec/cli 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891

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 (180) hide show
  1. package/README.md +1 -1
  2. package/dest/cmds/aztec_node/block_number.d.ts +1 -1
  3. package/dest/cmds/aztec_node/get_block.d.ts +1 -1
  4. package/dest/cmds/aztec_node/get_block.d.ts.map +1 -1
  5. package/dest/cmds/aztec_node/get_block.js +2 -1
  6. package/dest/cmds/aztec_node/get_current_min_fee.d.ts +3 -0
  7. package/dest/cmds/aztec_node/get_current_min_fee.d.ts.map +1 -0
  8. package/dest/cmds/aztec_node/{get_current_base_fee.js → get_current_min_fee.js} +2 -2
  9. package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts +1 -1
  10. package/dest/cmds/aztec_node/get_logs.d.ts +3 -2
  11. package/dest/cmds/aztec_node/get_logs.d.ts.map +1 -1
  12. package/dest/cmds/aztec_node/get_node_info.d.ts +1 -1
  13. package/dest/cmds/aztec_node/index.d.ts +1 -1
  14. package/dest/cmds/aztec_node/index.js +3 -3
  15. package/dest/cmds/contracts/index.d.ts +1 -1
  16. package/dest/cmds/contracts/inspect_contract.d.ts +1 -1
  17. package/dest/cmds/contracts/inspect_contract.d.ts.map +1 -1
  18. package/dest/cmds/contracts/inspect_contract.js +4 -10
  19. package/dest/cmds/contracts/parse_parameter_struct.d.ts +1 -1
  20. package/dest/cmds/infrastructure/index.d.ts +1 -1
  21. package/dest/cmds/infrastructure/index.d.ts.map +1 -1
  22. package/dest/cmds/infrastructure/index.js +0 -1
  23. package/dest/cmds/infrastructure/sequencers.d.ts +1 -2
  24. package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -1
  25. package/dest/cmds/infrastructure/sequencers.js +11 -4
  26. package/dest/cmds/infrastructure/setup_l2_contract.d.ts +1 -1
  27. package/dest/cmds/infrastructure/setup_l2_contract.d.ts.map +1 -1
  28. package/dest/cmds/infrastructure/setup_l2_contract.js +4 -3
  29. package/dest/cmds/l1/advance_epoch.d.ts +1 -1
  30. package/dest/cmds/l1/assume_proven_through.d.ts +3 -2
  31. package/dest/cmds/l1/assume_proven_through.d.ts.map +1 -1
  32. package/dest/cmds/l1/assume_proven_through.js +3 -4
  33. package/dest/cmds/l1/bridge_erc20.d.ts +1 -1
  34. package/dest/cmds/l1/bridge_erc20.d.ts.map +1 -1
  35. package/dest/cmds/l1/bridge_erc20.js +2 -1
  36. package/dest/cmds/l1/compute_genesis_values.d.ts +4 -0
  37. package/dest/cmds/l1/compute_genesis_values.d.ts.map +1 -0
  38. package/dest/cmds/l1/compute_genesis_values.js +17 -0
  39. package/dest/cmds/l1/create_l1_account.d.ts +1 -1
  40. package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts +4 -0
  41. package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts.map +1 -0
  42. package/dest/cmds/l1/{deploy_l1_contracts.js → deploy_l1_contracts_cmd.js} +39 -4
  43. package/dest/cmds/l1/deploy_new_rollup.d.ts +4 -4
  44. package/dest/cmds/l1/deploy_new_rollup.d.ts.map +1 -1
  45. package/dest/cmds/l1/deploy_new_rollup.js +3 -3
  46. package/dest/cmds/l1/get_l1_addresses.d.ts +1 -1
  47. package/dest/cmds/l1/get_l1_addresses.d.ts.map +1 -1
  48. package/dest/cmds/l1/get_l1_addresses.js +5 -2
  49. package/dest/cmds/l1/get_l1_balance.d.ts +1 -1
  50. package/dest/cmds/l1/get_l1_balance.js +4 -2
  51. package/dest/cmds/l1/governance_utils.d.ts +5 -5
  52. package/dest/cmds/l1/governance_utils.d.ts.map +1 -1
  53. package/dest/cmds/l1/governance_utils.js +3 -1
  54. package/dest/cmds/l1/index.d.ts +1 -2
  55. package/dest/cmds/l1/index.d.ts.map +1 -1
  56. package/dest/cmds/l1/index.js +17 -10
  57. package/dest/cmds/l1/prover_stats.d.ts +1 -1
  58. package/dest/cmds/l1/prover_stats.d.ts.map +1 -1
  59. package/dest/cmds/l1/prover_stats.js +32 -30
  60. package/dest/cmds/l1/trigger_seed_snapshot.d.ts +2 -2
  61. package/dest/cmds/l1/trigger_seed_snapshot.d.ts.map +1 -1
  62. package/dest/cmds/l1/trigger_seed_snapshot.js +2 -1
  63. package/dest/cmds/l1/update_l1_validators.d.ts +7 -7
  64. package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -1
  65. package/dest/cmds/l1/update_l1_validators.js +58 -19
  66. package/dest/cmds/misc/compute_selector.d.ts +1 -1
  67. package/dest/cmds/misc/example_contracts.d.ts +1 -1
  68. package/dest/cmds/misc/generate_bootnode_enr.d.ts +1 -1
  69. package/dest/cmds/misc/generate_p2p_private_key.d.ts +1 -1
  70. package/dest/cmds/misc/generate_secret_and_hash.d.ts +1 -1
  71. package/dest/cmds/misc/generate_secret_and_hash.js +1 -1
  72. package/dest/cmds/misc/generate_secret_key.d.ts +1 -1
  73. package/dest/cmds/misc/get_canonical_sponsored_fpc_address.d.ts +1 -1
  74. package/dest/cmds/misc/index.d.ts +1 -1
  75. package/dest/cmds/misc/index.d.ts.map +1 -1
  76. package/dest/cmds/misc/index.js +1 -1
  77. package/dest/cmds/misc/update/common.d.ts +1 -1
  78. package/dest/cmds/misc/update/github.d.ts +1 -1
  79. package/dest/cmds/misc/update/noir.d.ts +1 -1
  80. package/dest/cmds/misc/update/npm.d.ts +1 -1
  81. package/dest/cmds/misc/update/npm.js +1 -1
  82. package/dest/cmds/misc/update/utils.d.ts +1 -1
  83. package/dest/cmds/misc/update.d.ts +1 -1
  84. package/dest/cmds/validator_keys/add.d.ts +1 -1
  85. package/dest/cmds/validator_keys/add.d.ts.map +1 -1
  86. package/dest/cmds/validator_keys/add.js +20 -7
  87. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts +1 -1
  88. package/dest/cmds/validator_keys/generate_bls_keypair.d.ts.map +1 -1
  89. package/dest/cmds/validator_keys/generate_bls_keypair.js +3 -2
  90. package/dest/cmds/validator_keys/index.d.ts +1 -1
  91. package/dest/cmds/validator_keys/index.d.ts.map +1 -1
  92. package/dest/cmds/validator_keys/index.js +16 -4
  93. package/dest/cmds/validator_keys/new.d.ts +7 -4
  94. package/dest/cmds/validator_keys/new.d.ts.map +1 -1
  95. package/dest/cmds/validator_keys/new.js +90 -16
  96. package/dest/cmds/validator_keys/shared.d.ts +4 -4
  97. package/dest/cmds/validator_keys/shared.d.ts.map +1 -1
  98. package/dest/cmds/validator_keys/shared.js +31 -28
  99. package/dest/cmds/validator_keys/staker.d.ts +38 -0
  100. package/dest/cmds/validator_keys/staker.d.ts.map +1 -0
  101. package/dest/cmds/validator_keys/staker.js +210 -0
  102. package/dest/cmds/validator_keys/utils.d.ts +25 -0
  103. package/dest/cmds/validator_keys/utils.d.ts.map +1 -0
  104. package/dest/cmds/validator_keys/utils.js +52 -0
  105. package/dest/config/cached_fetch.d.ts +19 -10
  106. package/dest/config/cached_fetch.d.ts.map +1 -1
  107. package/dest/config/cached_fetch.js +110 -32
  108. package/dest/config/chain_l2_config.d.ts +13 -38
  109. package/dest/config/chain_l2_config.d.ts.map +1 -1
  110. package/dest/config/chain_l2_config.js +35 -463
  111. package/dest/config/enrich_env.d.ts +1 -1
  112. package/dest/config/generated/networks.d.ts +221 -0
  113. package/dest/config/generated/networks.d.ts.map +1 -0
  114. package/dest/config/generated/networks.js +222 -0
  115. package/dest/config/get_l1_config.d.ts +3 -2
  116. package/dest/config/get_l1_config.d.ts.map +1 -1
  117. package/dest/config/get_l1_config.js +3 -1
  118. package/dest/config/index.d.ts +1 -1
  119. package/dest/config/network_config.d.ts +7 -4
  120. package/dest/config/network_config.d.ts.map +1 -1
  121. package/dest/config/network_config.js +70 -30
  122. package/dest/utils/aztec.d.ts +7 -13
  123. package/dest/utils/aztec.d.ts.map +1 -1
  124. package/dest/utils/aztec.js +19 -40
  125. package/dest/utils/commands.d.ts +8 -7
  126. package/dest/utils/commands.d.ts.map +1 -1
  127. package/dest/utils/commands.js +6 -5
  128. package/dest/utils/encoding.d.ts +1 -1
  129. package/dest/utils/encoding.js +1 -1
  130. package/dest/utils/github.d.ts +1 -1
  131. package/dest/utils/index.d.ts +1 -1
  132. package/dest/utils/inspect.d.ts +3 -2
  133. package/dest/utils/inspect.d.ts.map +1 -1
  134. package/dest/utils/inspect.js +4 -1
  135. package/dest/utils/setup_contracts.d.ts +1 -1
  136. package/package.json +44 -31
  137. package/public_include_metric_prefixes.json +1 -0
  138. package/src/cmds/aztec_node/get_block.ts +2 -1
  139. package/src/cmds/aztec_node/{get_current_base_fee.ts → get_current_min_fee.ts} +2 -2
  140. package/src/cmds/aztec_node/get_logs.ts +3 -2
  141. package/src/cmds/aztec_node/index.ts +3 -3
  142. package/src/cmds/contracts/inspect_contract.ts +4 -11
  143. package/src/cmds/infrastructure/index.ts +0 -1
  144. package/src/cmds/infrastructure/sequencers.ts +7 -5
  145. package/src/cmds/infrastructure/setup_l2_contract.ts +5 -4
  146. package/src/cmds/l1/assume_proven_through.ts +4 -4
  147. package/src/cmds/l1/bridge_erc20.ts +2 -1
  148. package/src/cmds/l1/compute_genesis_values.ts +29 -0
  149. package/src/cmds/l1/{deploy_l1_contracts.ts → deploy_l1_contracts_cmd.ts} +39 -22
  150. package/src/cmds/l1/deploy_new_rollup.ts +4 -9
  151. package/src/cmds/l1/get_l1_addresses.ts +4 -2
  152. package/src/cmds/l1/get_l1_balance.ts +2 -2
  153. package/src/cmds/l1/governance_utils.ts +3 -8
  154. package/src/cmds/l1/index.ts +30 -21
  155. package/src/cmds/l1/prover_stats.ts +42 -31
  156. package/src/cmds/l1/trigger_seed_snapshot.ts +2 -1
  157. package/src/cmds/l1/update_l1_validators.ts +52 -31
  158. package/src/cmds/misc/generate_secret_and_hash.ts +1 -1
  159. package/src/cmds/misc/index.ts +1 -1
  160. package/src/cmds/misc/update/npm.ts +1 -1
  161. package/src/cmds/validator_keys/add.ts +20 -10
  162. package/src/cmds/validator_keys/generate_bls_keypair.ts +3 -2
  163. package/src/cmds/validator_keys/index.ts +67 -21
  164. package/src/cmds/validator_keys/new.ts +110 -23
  165. package/src/cmds/validator_keys/shared.ts +32 -27
  166. package/src/cmds/validator_keys/staker.ts +301 -0
  167. package/src/cmds/validator_keys/utils.ts +81 -0
  168. package/src/config/cached_fetch.ts +119 -31
  169. package/src/config/chain_l2_config.ts +36 -604
  170. package/src/config/generated/networks.ts +226 -0
  171. package/src/config/get_l1_config.ts +4 -1
  172. package/src/config/network_config.ts +80 -31
  173. package/src/utils/aztec.ts +24 -83
  174. package/src/utils/commands.ts +6 -5
  175. package/src/utils/encoding.ts +1 -1
  176. package/src/utils/inspect.ts +6 -2
  177. package/dest/cmds/aztec_node/get_current_base_fee.d.ts +0 -3
  178. package/dest/cmds/aztec_node/get_current_base_fee.d.ts.map +0 -1
  179. package/dest/cmds/l1/deploy_l1_contracts.d.ts +0 -4
  180. package/dest/cmds/l1/deploy_l1_contracts.d.ts.map +0 -1
@@ -0,0 +1,38 @@
1
+ import { GSEContract } from '@aztec/ethereum/contracts';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { LogFn } from '@aztec/foundation/log';
4
+ import type { AttesterAccounts } from '@aztec/node-keystore/types';
5
+ export type StakerOptions = {
6
+ from: string;
7
+ password?: string;
8
+ output?: string;
9
+ gseAddress: EthAddress;
10
+ l1RpcUrls: string[];
11
+ l1ChainId: number;
12
+ };
13
+ export type StakerOutput = {
14
+ attester: string;
15
+ publicKeyG1: {
16
+ x: string;
17
+ y: string;
18
+ };
19
+ publicKeyG2: {
20
+ x0: string;
21
+ x1: string;
22
+ y0: string;
23
+ y1: string;
24
+ };
25
+ proofOfPossession: {
26
+ x: string;
27
+ y: string;
28
+ };
29
+ };
30
+ /**
31
+ * Process AttesterAccounts (which can be a single attester, array, or mnemonic)
32
+ */
33
+ export declare function processAttesterAccounts(attesterAccounts: AttesterAccounts, gse: GSEContract, password?: string): Promise<StakerOutput[]>;
34
+ /**
35
+ * Main staker command function
36
+ */
37
+ export declare function generateStakerJson(options: StakerOptions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CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IACF,WAAW,EAAE;QACX,EAAE,EAAE,MAAM,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;KACZ,CAAC;IACF,iBAAiB,EAAE;QACjB,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;CACH,CAAC;AA2KF;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,gBAAgB,EAAE,gBAAgB,EAClC,GAAG,EAAE,WAAW,EAChB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,EAAE,CAAC,CAqBzB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CA+C1F"}
@@ -0,0 +1,210 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/utils';
2
+ import { createEthereumChain } from '@aztec/ethereum/chain';
3
+ import { GSEContract } from '@aztec/ethereum/contracts';
4
+ import { decryptBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
5
+ import { computeBn254G1PublicKey, computeBn254G2PublicKey } from '@aztec/foundation/crypto/bn254';
6
+ import { Fr } from '@aztec/foundation/curves/bn254';
7
+ import { loadKeystoreFile } from '@aztec/node-keystore/loader';
8
+ import { Wallet } from '@ethersproject/wallet';
9
+ import { readFileSync, writeFileSync } from 'fs';
10
+ import { basename, dirname, join } from 'path';
11
+ import { createPublicClient, fallback, http } from 'viem';
12
+ import { privateKeyToAddress } from 'viem/accounts';
13
+ /**
14
+ * Check if an object is a MnemonicConfig
15
+ */ function isMnemonicConfig(obj) {
16
+ return typeof obj === 'object' && obj !== null && 'mnemonic' in obj;
17
+ }
18
+ /**
19
+ * Check if a value is an encrypted keystore file config
20
+ */ function isEncryptedKeyFileConfig(value) {
21
+ return typeof value === 'object' && value !== null && 'path' in value;
22
+ }
23
+ /**
24
+ * Check if a BLSAccount is a private key string (not an encrypted keystore file)
25
+ */ function isBlsPrivateKey(bls) {
26
+ return typeof bls === 'string' && bls.startsWith('0x');
27
+ }
28
+ /**
29
+ * Check if an EthAccount is a private key string (66 chars: 0x + 64 hex)
30
+ */ function isEthPrivateKey(eth) {
31
+ return typeof eth === 'string' && eth.startsWith('0x') && eth.length === 66;
32
+ }
33
+ /**
34
+ * Check if a string is an Ethereum address (42 chars: 0x + 40 hex)
35
+ */ function isEthAddress(value) {
36
+ return typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value);
37
+ }
38
+ /**
39
+ * Decrypt a BLS private key from an encrypted keystore file
40
+ */ function decryptBlsKey(bls, password) {
41
+ if (isBlsPrivateKey(bls)) {
42
+ return bls;
43
+ }
44
+ if (isEncryptedKeyFileConfig(bls)) {
45
+ if (!password && !bls.password) {
46
+ return undefined; // Can't decrypt without password
47
+ }
48
+ const pwd = password ?? bls.password;
49
+ return decryptBn254Keystore(bls.path, pwd);
50
+ }
51
+ return undefined;
52
+ }
53
+ /**
54
+ * Decrypt an Ethereum private key from an encrypted keystore file
55
+ */ async function decryptEthKey(eth, password) {
56
+ if (isEthPrivateKey(eth)) {
57
+ return eth;
58
+ }
59
+ if (isEncryptedKeyFileConfig(eth)) {
60
+ if (!password && !eth.password) {
61
+ return undefined; // Can't decrypt without password
62
+ }
63
+ const pwd = password ?? eth.password;
64
+ const json = readFileSync(eth.path, 'utf-8');
65
+ const wallet = await Wallet.fromEncryptedJson(json, pwd);
66
+ return wallet.privateKey;
67
+ }
68
+ return undefined;
69
+ }
70
+ /**
71
+ * Extract Ethereum address from an EthAccount (or private key)
72
+ */ async function getEthAddress(eth, password) {
73
+ // Case 1: It's a private key string - derive the address
74
+ if (isEthPrivateKey(eth)) {
75
+ return privateKeyToAddress(eth);
76
+ }
77
+ // Case 2: It's just an address string directly (EthRemoteSignerAccount can be just EthAddress)
78
+ if (isEthAddress(eth)) {
79
+ return eth;
80
+ }
81
+ // Case 3: It's an object with an address property (remote signer config)
82
+ if (typeof eth === 'object' && eth !== null && 'address' in eth) {
83
+ return eth.address;
84
+ }
85
+ // Case 4: It's an encrypted keystore file - decrypt and derive address
86
+ if (isEncryptedKeyFileConfig(eth)) {
87
+ const privateKey = await decryptEthKey(eth, password);
88
+ if (privateKey) {
89
+ return privateKeyToAddress(privateKey);
90
+ }
91
+ return undefined;
92
+ }
93
+ return undefined;
94
+ }
95
+ /**
96
+ * Extract BLS private key and Ethereum address from an AttesterAccount
97
+ */ async function extractAttesterInfo(attester, password) {
98
+ // Case 1: attester is { eth: EthAccount, bls?: BLSAccount }
99
+ if (typeof attester === 'object' && attester !== null && 'eth' in attester) {
100
+ const ethAddress = await getEthAddress(attester.eth, password);
101
+ const blsPrivateKey = attester.bls ? decryptBlsKey(attester.bls, password) : undefined;
102
+ return {
103
+ blsPrivateKey,
104
+ ethAddress
105
+ };
106
+ }
107
+ // Case 2: attester is just an EthAccount directly (no BLS key)
108
+ return {
109
+ blsPrivateKey: undefined,
110
+ ethAddress: await getEthAddress(attester, password)
111
+ };
112
+ }
113
+ /**
114
+ * Process a single attester entry and output staking JSON
115
+ */ async function processAttester(attester, gse, password) {
116
+ const { blsPrivateKey, ethAddress } = await extractAttesterInfo(attester, password);
117
+ // Skip if no BLS private key or no Ethereum address
118
+ if (!blsPrivateKey || !ethAddress) {
119
+ return undefined;
120
+ }
121
+ // Derive G1 and G2 public keys
122
+ const g1PublicKey = await computeBn254G1PublicKey(blsPrivateKey);
123
+ const g2PublicKey = await computeBn254G2PublicKey(blsPrivateKey);
124
+ // Generate proof of possession
125
+ const bn254SecretKeyFieldElement = Fr.fromString(blsPrivateKey);
126
+ const registrationTuple = await gse.makeRegistrationTuple(bn254SecretKeyFieldElement.toBigInt());
127
+ return {
128
+ attester: String(ethAddress),
129
+ publicKeyG1: {
130
+ x: '0x' + g1PublicKey.x.toString(16).padStart(64, '0'),
131
+ y: '0x' + g1PublicKey.y.toString(16).padStart(64, '0')
132
+ },
133
+ publicKeyG2: {
134
+ x0: '0x' + g2PublicKey.x.c0.toString(16).padStart(64, '0'),
135
+ x1: '0x' + g2PublicKey.x.c1.toString(16).padStart(64, '0'),
136
+ y0: '0x' + g2PublicKey.y.c0.toString(16).padStart(64, '0'),
137
+ y1: '0x' + g2PublicKey.y.c1.toString(16).padStart(64, '0')
138
+ },
139
+ proofOfPossession: {
140
+ x: '0x' + registrationTuple.proofOfPossession.x.toString(16),
141
+ y: '0x' + registrationTuple.proofOfPossession.y.toString(16)
142
+ }
143
+ };
144
+ }
145
+ /**
146
+ * Process AttesterAccounts (which can be a single attester, array, or mnemonic)
147
+ */ export async function processAttesterAccounts(attesterAccounts, gse, password) {
148
+ // Skip mnemonic configs
149
+ if (isMnemonicConfig(attesterAccounts)) {
150
+ return [];
151
+ }
152
+ // Handle array of attesters
153
+ if (Array.isArray(attesterAccounts)) {
154
+ const results = [];
155
+ for (const attester of attesterAccounts){
156
+ const result = await processAttester(attester, gse, password);
157
+ if (result) {
158
+ results.push(result);
159
+ }
160
+ }
161
+ return results;
162
+ }
163
+ // Handle single attester
164
+ const result = await processAttester(attesterAccounts, gse, password);
165
+ return result ? [
166
+ result
167
+ ] : [];
168
+ }
169
+ /**
170
+ * Main staker command function
171
+ */ export async function generateStakerJson(options, log) {
172
+ const { from, password, gseAddress, l1RpcUrls, l1ChainId, output } = options;
173
+ // Load the keystore file
174
+ const keystore = loadKeystoreFile(from);
175
+ if (!gseAddress) {
176
+ throw new Error('GSE contract address is required');
177
+ }
178
+ log(`Calling GSE contract ${gseAddress} on chain ${l1ChainId}, using ${l1RpcUrls.join(', ')} to get staker outputs`);
179
+ if (!keystore.validators || keystore.validators.length === 0) {
180
+ log('No validators found in keystore');
181
+ return;
182
+ }
183
+ const allOutputs = [];
184
+ // L1 client for proof of possession
185
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
186
+ const publicClient = createPublicClient({
187
+ chain: chain.chainInfo,
188
+ transport: fallback(l1RpcUrls.map((url)=>http(url, {
189
+ batch: false
190
+ })))
191
+ });
192
+ const gse = new GSEContract(publicClient, gseAddress);
193
+ const keystoreBaseName = basename(from, '.json');
194
+ const outputDir = output ? output : dirname(from);
195
+ for(let i = 0; i < keystore.validators.length; i++){
196
+ const validator = keystore.validators[i];
197
+ const outputs = await processAttesterAccounts(validator.attester, gse, password);
198
+ for(let j = 0; j < outputs.length; j++){
199
+ allOutputs.push(outputs[j]);
200
+ }
201
+ }
202
+ if (allOutputs.length === 0) {
203
+ log('No attesters with BLS keys found (skipping mnemonics and encrypted keystores without password)');
204
+ return;
205
+ }
206
+ // Write a single JSON file with all staker outputs
207
+ const stakerOutputPath = join(outputDir, `${keystoreBaseName}_staker_output.json`);
208
+ writeFileSync(stakerOutputPath, prettyPrintJSON(allOutputs), 'utf-8');
209
+ log(`Wrote staker output for ${allOutputs.length} validator(s) to ${stakerOutputPath}`);
210
+ }
@@ -0,0 +1,25 @@
1
+ import type { EthAddress } from '@aztec/foundation/eth-address';
2
+ export declare const defaultBlsPath = "m/12381/3600/0/0/0";
3
+ export declare function validateBlsPathOptions(options: {
4
+ count?: number;
5
+ publisherCount?: number;
6
+ accountIndex?: number;
7
+ addressIndex?: number;
8
+ blsPath?: string;
9
+ ikm?: string;
10
+ }): void;
11
+ export declare function validateStakerOutputOptions(options: {
12
+ stakerOutput?: boolean;
13
+ gseAddress?: EthAddress;
14
+ l1RpcUrls?: string[];
15
+ l1ChainId?: number;
16
+ }): void;
17
+ export declare function validateRemoteSignerOptions(options: {
18
+ remoteSigner?: string;
19
+ mnemonic?: string;
20
+ }): void;
21
+ export declare function validatePublisherOptions(options: {
22
+ publishers?: string[];
23
+ publisherCount?: number;
24
+ }): void;
25
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Ny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version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/cmds/validator_keys/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAIhE,eAAO,MAAM,cAAc,uBAAuB,CAAC;AAEnD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,QAWA;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE;IACnD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,QAeA;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,QAMhG;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,QAwBnG"}
@@ -0,0 +1,52 @@
1
+ import { ethPrivateKeySchema } from '@aztec/node-keystore/schemas';
2
+ export const defaultBlsPath = 'm/12381/3600/0/0/0';
3
+ export function validateBlsPathOptions(options) {
4
+ if (options.blsPath && options.blsPath !== defaultBlsPath) {
5
+ if (options.count && options.count !== 1 || options.publisherCount && options.publisherCount > 0 || options.accountIndex && options.accountIndex !== 0 || options.addressIndex && options.addressIndex !== 0) {
6
+ throw new Error('--bls-path cannot be used with --count, --publisher-count, --account-index, or --address-index');
7
+ }
8
+ }
9
+ }
10
+ export function validateStakerOutputOptions(options) {
11
+ if (!options.stakerOutput) {
12
+ return;
13
+ }
14
+ // Required options for staker output
15
+ if (!options.gseAddress) {
16
+ throw new Error('--gse-address is required when using --staker-output');
17
+ }
18
+ if (!options.l1RpcUrls || options.l1RpcUrls.length === 0) {
19
+ throw new Error('--l1-rpc-urls is required when using --staker-output');
20
+ }
21
+ if (options.l1ChainId === undefined) {
22
+ throw new Error('--l1-chain-id is required when using --staker-output');
23
+ }
24
+ }
25
+ export function validateRemoteSignerOptions(options) {
26
+ if (options.remoteSigner && !options.mnemonic) {
27
+ throw new Error('Using --remote-signer requires a deterministic key source. Provide --mnemonic to derive keys, or omit --remote-signer to write new private keys to keystore.');
28
+ }
29
+ }
30
+ export function validatePublisherOptions(options) {
31
+ if (options.publisherCount && options.publisherCount > 0 && options.publishers && options.publishers.length > 0) {
32
+ throw new Error('--publishers and --publisher-count cannot be used together');
33
+ }
34
+ if (options.publishers && options.publishers.length > 0) {
35
+ // Normalize each private key by adding 0x prefix if missing
36
+ const normalizedKeys = [];
37
+ for (const key of options.publishers){
38
+ let privateKey = key.trim();
39
+ if (!privateKey.startsWith('0x')) {
40
+ privateKey = '0x' + privateKey;
41
+ }
42
+ try {
43
+ ethPrivateKeySchema.parse(privateKey);
44
+ normalizedKeys.push(privateKey);
45
+ } catch (error) {
46
+ throw new Error(`Invalid publisher private key: ${error instanceof Error ? error.message : String(error)}`);
47
+ }
48
+ }
49
+ // Update the options with the normalized keys
50
+ options.publishers = normalizedKeys;
51
+ }
52
+ }
@@ -1,18 +1,27 @@
1
1
  export interface CachedFetchOptions {
2
- /** Cache duration in milliseconds */
3
- cacheDurationMs: number;
4
- /** The cache file */
2
+ /** The cache file path for storing data. If not provided, no caching is performed. */
5
3
  cacheFile?: string;
4
+ /** Fallback max-age in milliseconds when server sends no Cache-Control header. Defaults to 5 minutes. */
5
+ defaultMaxAgeMs?: number;
6
6
  }
7
+ /** Extracts max-age value in milliseconds from a Response's Cache-Control header. Returns undefined if not present. */
8
+ export declare function parseMaxAge(response: {
9
+ headers: {
10
+ get(name: string): string | null;
11
+ };
12
+ }): number | undefined;
7
13
  /**
8
- * Fetches data from a URL with file-based caching support.
9
- * This utility can be used by both remote config and bootnodes fetching.
14
+ * Fetches data from a URL with file-based HTTP conditional caching.
15
+ *
16
+ * Data is stored as raw JSON in the cache file (same format as the server returns).
17
+ * Caching metadata (ETag, expiry) is stored in a separate sidecar `.meta` file.
18
+ * This keeps the data file human-readable and backward-compatible with older code.
10
19
  *
11
20
  * @param url - The URL to fetch from
12
- * @param networkName - Network name for cache directory structure
13
- * @param options - Caching and error handling options
14
- * @param cacheDir - Optional cache directory (defaults to no caching)
15
- * @returns The fetched and parsed JSON data, or undefined if fetch fails and throwOnError is false
21
+ * @param options - Caching options
22
+ * @param fetch - Fetch implementation (defaults to globalThis.fetch)
23
+ * @param log - Logger instance
24
+ * @returns The fetched and parsed JSON data, or undefined if fetch fails
16
25
  */
17
26
  export declare function cachedFetch<T = any>(url: string, options: CachedFetchOptions, fetch?: typeof globalThis.fetch, log?: import("@aztec/aztec.js/log").Logger): Promise<T | undefined>;
18
- //# sourceMappingURL=cached_fetch.d.ts.map
27
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FjaGVkX2ZldGNoLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uZmlnL2NhY2hlZF9mZXRjaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFLQSxNQUFNLFdBQVcsa0JBQWtCO0lBQ2pDLHNGQUFzRjtJQUN0RixTQUFTLENBQUMsRUFBRSxNQUFNLENBQUM7SUFDbkIseUdBQXlHO0lBQ3pHLGVBQWUsQ0FBQyxFQUFFLE1BQU0sQ0FBQztDQUMxQjtBQVVELHVIQUF1SDtBQUN2SCx3QkFBZ0IsV0FBVyxDQUFDLFFBQVEsRUFBRTtJQUFFLE9BQU8sRUFBRTtRQUFFLEdBQUcsQ0FBQyxJQUFJLEVBQUUsTUFBTSxHQUFHLE1BQU0sR0FBRyxJQUFJLENBQUE7S0FBRSxDQUFBO0NBQUUsR0FBRyxNQUFNLEdBQUcsU0FBUyxDQVUzRztBQUVEOzs7Ozs7Ozs7Ozs7R0FZRztBQUNILHdCQUFzQixXQUFXLENBQUMsQ0FBQyxHQUFHLEdBQUcsRUFDdkMsR0FBRyxFQUFFLE1BQU0sRUFDWCxPQUFPLEVBQUUsa0JBQWtCLEVBQzNCLEtBQUssMEJBQW1CLEVBQ3hCLEdBQUcsdUNBQStCLEdBQ2pDLE9BQU8sQ0FBQyxDQUFDLEdBQUcsU0FBUyxDQUFDLENBb0V4QiJ9
@@ -1 +1 @@
1
- {"version":3,"file":"cached_fetch.d.ts","sourceRoot":"","sources":["../../src/config/cached_fetch.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,CAAC,GAAG,GAAG,EACvC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,kBAAkB,EAC3B,KAAK,0BAAmB,EACxB,GAAG,uCAA+B,GACjC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAuCxB"}
1
+ {"version":3,"file":"cached_fetch.d.ts","sourceRoot":"","sources":["../../src/config/cached_fetch.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yGAAyG;IACzG,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAUD,uHAAuH;AACvH,wBAAgB,WAAW,CAAC,QAAQ,EAAE;IAAE,OAAO,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,GAAG,MAAM,GAAG,SAAS,CAU3G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAAC,CAAC,GAAG,GAAG,EACvC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,kBAAkB,EAC3B,KAAK,0BAAmB,EACxB,GAAG,uCAA+B,GACjC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAoExB"}
@@ -1,50 +1,105 @@
1
1
  import { createLogger } from '@aztec/aztec.js/log';
2
- import { mkdir, readFile, stat, writeFile } from 'fs/promises';
2
+ import { mkdir, readFile, writeFile } from 'fs/promises';
3
3
  import { dirname } from 'path';
4
+ const DEFAULT_MAX_AGE_MS = 5 * 60 * 1000; // 5 minutes
5
+ /** Extracts max-age value in milliseconds from a Response's Cache-Control header. Returns undefined if not present. */ export function parseMaxAge(response) {
6
+ const cacheControl = response.headers.get('cache-control');
7
+ if (!cacheControl) {
8
+ return undefined;
9
+ }
10
+ const match = cacheControl.match(/max-age=(\d+)/);
11
+ if (!match) {
12
+ return undefined;
13
+ }
14
+ return parseInt(match[1], 10) * 1000;
15
+ }
4
16
  /**
5
- * Fetches data from a URL with file-based caching support.
6
- * This utility can be used by both remote config and bootnodes fetching.
17
+ * Fetches data from a URL with file-based HTTP conditional caching.
18
+ *
19
+ * Data is stored as raw JSON in the cache file (same format as the server returns).
20
+ * Caching metadata (ETag, expiry) is stored in a separate sidecar `.meta` file.
21
+ * This keeps the data file human-readable and backward-compatible with older code.
7
22
  *
8
23
  * @param url - The URL to fetch from
9
- * @param networkName - Network name for cache directory structure
10
- * @param options - Caching and error handling options
11
- * @param cacheDir - Optional cache directory (defaults to no caching)
12
- * @returns The fetched and parsed JSON data, or undefined if fetch fails and throwOnError is false
24
+ * @param options - Caching options
25
+ * @param fetch - Fetch implementation (defaults to globalThis.fetch)
26
+ * @param log - Logger instance
27
+ * @returns The fetched and parsed JSON data, or undefined if fetch fails
13
28
  */ export async function cachedFetch(url, options, fetch = globalThis.fetch, log = createLogger('cached_fetch')) {
14
- const { cacheDurationMs, cacheFile } = options;
15
- // Try to read from cache first
29
+ const { cacheFile, defaultMaxAgeMs = DEFAULT_MAX_AGE_MS } = options;
30
+ // If no cacheFile, just fetch normally without caching
31
+ if (!cacheFile) {
32
+ return fetchAndParse(url, fetch, log);
33
+ }
34
+ const metaFile = cacheFile + '.meta';
35
+ // Try to read metadata
36
+ let meta;
16
37
  try {
17
- if (cacheFile) {
18
- const info = await stat(cacheFile);
19
- if (info.mtimeMs + cacheDurationMs > Date.now()) {
20
- const cachedData = JSON.parse(await readFile(cacheFile, 'utf-8'));
21
- return cachedData;
22
- }
23
- }
38
+ meta = JSON.parse(await readFile(metaFile, 'utf-8'));
24
39
  } catch {
25
- log.trace('Failed to read data from cache');
40
+ log.trace('No usable cache metadata found');
26
41
  }
42
+ // Try to read cached data
43
+ let cachedData;
27
44
  try {
28
- const response = await fetch(url);
45
+ cachedData = JSON.parse(await readFile(cacheFile, 'utf-8'));
46
+ } catch {
47
+ log.trace('No usable cached data found');
48
+ }
49
+ // If metadata and data exist and cache is fresh, return directly
50
+ if (meta && cachedData !== undefined && meta.expiresAt > Date.now()) {
51
+ return cachedData;
52
+ }
53
+ // Cache is stale or missing — make a (possibly conditional) request
54
+ try {
55
+ const headers = {};
56
+ if (meta?.etag && cachedData !== undefined) {
57
+ headers['If-None-Match'] = meta.etag;
58
+ }
59
+ const response = await fetch(url, {
60
+ headers
61
+ });
62
+ if (response.status === 304 && cachedData !== undefined) {
63
+ // Not modified — recompute expiry from new response headers and return cached data
64
+ const maxAgeMs = parseMaxAge(response) ?? defaultMaxAgeMs;
65
+ await writeMetaFile(metaFile, {
66
+ etag: meta?.etag,
67
+ expiresAt: Date.now() + maxAgeMs
68
+ }, log);
69
+ return cachedData;
70
+ }
29
71
  if (!response.ok) {
30
72
  log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
31
- return undefined;
73
+ return cachedData;
32
74
  }
75
+ // 200 — parse new data and cache it
33
76
  const data = await response.json();
34
- try {
35
- if (cacheFile) {
36
- await mkdir(dirname(cacheFile), {
37
- recursive: true
38
- });
39
- await writeFile(cacheFile, JSON.stringify(data), 'utf-8');
40
- }
41
- } catch (err) {
42
- log.warn('Failed to cache data on disk: ' + cacheFile, {
43
- cacheFile,
44
- err
45
- });
46
- }
77
+ const maxAgeMs = parseMaxAge(response) ?? defaultMaxAgeMs;
78
+ const etag = response.headers.get('etag') ?? undefined;
79
+ await ensureDir(cacheFile, log);
80
+ await Promise.all([
81
+ writeFile(cacheFile, JSON.stringify(data), 'utf-8'),
82
+ writeFile(metaFile, JSON.stringify({
83
+ etag,
84
+ expiresAt: Date.now() + maxAgeMs
85
+ }), 'utf-8')
86
+ ]);
47
87
  return data;
88
+ } catch (err) {
89
+ log.warn(`Failed to fetch from ${url}`, {
90
+ err
91
+ });
92
+ return cachedData;
93
+ }
94
+ }
95
+ async function fetchAndParse(url, fetch, log) {
96
+ try {
97
+ const response = await fetch(url);
98
+ if (!response.ok) {
99
+ log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
100
+ return undefined;
101
+ }
102
+ return await response.json();
48
103
  } catch (err) {
49
104
  log.warn(`Failed to fetch from ${url}`, {
50
105
  err
@@ -52,3 +107,26 @@ import { dirname } from 'path';
52
107
  return undefined;
53
108
  }
54
109
  }
110
+ async function ensureDir(filePath, log) {
111
+ try {
112
+ await mkdir(dirname(filePath), {
113
+ recursive: true
114
+ });
115
+ } catch (err) {
116
+ log.warn('Failed to create cache directory for: ' + filePath, {
117
+ err
118
+ });
119
+ }
120
+ }
121
+ async function writeMetaFile(metaFile, meta, log) {
122
+ try {
123
+ await mkdir(dirname(metaFile), {
124
+ recursive: true
125
+ });
126
+ await writeFile(metaFile, JSON.stringify(meta), 'utf-8');
127
+ } catch (err) {
128
+ log.warn('Failed to write cache metadata: ' + metaFile, {
129
+ err
130
+ });
131
+ }
132
+ }
@@ -1,39 +1,14 @@
1
- import { type L1ContractsConfig } from '@aztec/ethereum';
2
1
  import type { NetworkNames } from '@aztec/foundation/config';
3
- import type { SharedNodeConfig } from '@aztec/node-lib/config';
4
- import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
5
- export type L2ChainConfig = L1ContractsConfig & Omit<SlasherConfig, 'slashValidatorsNever' | 'slashValidatorsAlways'> & {
6
- l1ChainId: number;
7
- testAccounts: boolean;
8
- sponsoredFPC: boolean;
9
- p2pEnabled: boolean;
10
- p2pBootstrapNodes: string[];
11
- seqMinTxsPerBlock: number;
12
- seqMaxTxsPerBlock: number;
13
- realProofs: boolean;
14
- snapshotsUrls: string[];
15
- autoUpdate: SharedNodeConfig['autoUpdate'];
16
- autoUpdateUrl?: string;
17
- maxTxPoolSize: number;
18
- publicIncludeMetrics?: string[];
19
- publicMetricsCollectorUrl?: string;
20
- publicMetricsCollectFrom?: string[];
21
- skipArchiverInitialSync?: boolean;
22
- blobAllowEmptySources?: boolean;
23
- dbMapSizeKb: number;
24
- archiverStoreMapSizeKb: number;
25
- noteHashTreeMapSizeKb: number;
26
- nullifierTreeMapSizeKb: number;
27
- publicDataTreeMapSizeKb: number;
28
- sentinelEnabled: boolean;
29
- disableTransactions: boolean;
30
- };
31
- export declare const stagingIgnitionL2ChainConfig: L2ChainConfig;
32
- export declare const stagingPublicL2ChainConfig: L2ChainConfig;
33
- export declare const nextNetL2ChainConfig: L2ChainConfig;
34
- export declare const testnetL2ChainConfig: L2ChainConfig;
35
- export declare const mainnetL2ChainConfig: L2ChainConfig;
36
- export declare const devnetL2ChainConfig: L2ChainConfig;
37
- export declare function getL2ChainConfig(networkName: NetworkNames): L2ChainConfig | undefined;
38
- export declare function enrichEnvironmentWithChainConfig(networkName: NetworkNames): void;
39
- //# sourceMappingURL=chain_l2_config.d.ts.map
2
+ /**
3
+ * Sets up environment for the given network.
4
+ *
5
+ * For 'local' network: returns early, using hardcoded defaults from DefaultL1ContractsConfig
6
+ * and DefaultSlasherConfig (which match the 'defaults' section of defaults.yml).
7
+ *
8
+ * For deployed networks: applies network configuration from generated defaults.yml,
9
+ * merging base defaults with network-specific overrides.
10
+ *
11
+ * @param networkName - The network name
12
+ */
13
+ export declare function enrichEnvironmentWithChainName(networkName: NetworkNames): void;
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhaW5fbDJfY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uZmlnL2NoYWluX2wyX2NvbmZpZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQTBCN0Q7Ozs7Ozs7Ozs7R0FVRztBQUNILHdCQUFnQiw4QkFBOEIsQ0FBQyxXQUFXLEVBQUUsWUFBWSxRQXFCdkUifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"chain_l2_config.d.ts","sourceRoot":"","sources":["../../src/config/chain_l2_config.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAYrE,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAC3C,IAAI,CAAC,aAAa,EAAE,sBAAsB,GAAG,uBAAuB,CAAC,GAAG;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC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