@aztec/validator-client 0.0.0-test.0 → 0.0.1-commit.001888fc

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 (66) hide show
  1. package/README.md +328 -0
  2. package/dest/block_proposal_handler.d.ts +64 -0
  3. package/dest/block_proposal_handler.d.ts.map +1 -0
  4. package/dest/block_proposal_handler.js +606 -0
  5. package/dest/checkpoint_builder.d.ts +77 -0
  6. package/dest/checkpoint_builder.d.ts.map +1 -0
  7. package/dest/checkpoint_builder.js +250 -0
  8. package/dest/config.d.ts +3 -14
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +66 -8
  11. package/dest/duties/validation_service.d.ts +50 -13
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +117 -17
  14. package/dest/factory.d.ts +28 -6
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +14 -6
  17. package/dest/index.d.ts +5 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +4 -1
  20. package/dest/key_store/ha_key_store.d.ts +99 -0
  21. package/dest/key_store/ha_key_store.d.ts.map +1 -0
  22. package/dest/key_store/ha_key_store.js +208 -0
  23. package/dest/key_store/index.d.ts +4 -1
  24. package/dest/key_store/index.d.ts.map +1 -1
  25. package/dest/key_store/index.js +3 -0
  26. package/dest/key_store/interface.d.ts +85 -6
  27. package/dest/key_store/interface.d.ts.map +1 -1
  28. package/dest/key_store/interface.js +3 -3
  29. package/dest/key_store/local_key_store.d.ts +46 -11
  30. package/dest/key_store/local_key_store.d.ts.map +1 -1
  31. package/dest/key_store/local_key_store.js +68 -17
  32. package/dest/key_store/node_keystore_adapter.d.ts +151 -0
  33. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -0
  34. package/dest/key_store/node_keystore_adapter.js +330 -0
  35. package/dest/key_store/web3signer_key_store.d.ts +66 -0
  36. package/dest/key_store/web3signer_key_store.d.ts.map +1 -0
  37. package/dest/key_store/web3signer_key_store.js +156 -0
  38. package/dest/metrics.d.ts +21 -5
  39. package/dest/metrics.d.ts.map +1 -1
  40. package/dest/metrics.js +75 -22
  41. package/dest/validator.d.ts +101 -59
  42. package/dest/validator.d.ts.map +1 -1
  43. package/dest/validator.js +723 -168
  44. package/package.json +37 -21
  45. package/src/block_proposal_handler.ts +624 -0
  46. package/src/checkpoint_builder.ts +412 -0
  47. package/src/config.ts +77 -22
  48. package/src/duties/validation_service.ts +194 -19
  49. package/src/factory.ts +66 -11
  50. package/src/index.ts +4 -1
  51. package/src/key_store/ha_key_store.ts +269 -0
  52. package/src/key_store/index.ts +3 -0
  53. package/src/key_store/interface.ts +100 -5
  54. package/src/key_store/local_key_store.ts +77 -18
  55. package/src/key_store/node_keystore_adapter.ts +398 -0
  56. package/src/key_store/web3signer_key_store.ts +205 -0
  57. package/src/metrics.ts +104 -23
  58. package/src/validator.ts +961 -219
  59. package/dest/errors/index.d.ts +0 -2
  60. package/dest/errors/index.d.ts.map +0 -1
  61. package/dest/errors/index.js +0 -1
  62. package/dest/errors/validator.error.d.ts +0 -29
  63. package/dest/errors/validator.error.d.ts.map +0 -1
  64. package/dest/errors/validator.error.js +0 -45
  65. package/src/errors/index.ts +0 -1
  66. package/src/errors/validator.error.ts +0 -55
@@ -1,6 +1,11 @@
1
1
  import type { Buffer32 } from '@aztec/foundation/buffer';
2
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import type { Signature } from '@aztec/foundation/eth-signature';
4
+ import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
5
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
+ import type { SigningContext } from '@aztec/validator-ha-signer/types';
7
+
8
+ import type { TypedDataDefinition } from 'viem';
4
9
 
5
10
  /** Key Store
6
11
  *
@@ -8,19 +13,109 @@ import type { Signature } from '@aztec/foundation/eth-signature';
8
13
  */
9
14
  export interface ValidatorKeyStore {
10
15
  /**
11
- * Get the address of the signer
16
+ * Get the address of a signer by index
12
17
  *
18
+ * @param index - The index of the signer
13
19
  * @returns the address
14
20
  */
15
- getAddress(): EthAddress;
21
+ getAddress(index: number): EthAddress;
22
+
23
+ /**
24
+ * Get all addresses
25
+ *
26
+ * @returns all addresses
27
+ */
28
+ getAddresses(): EthAddress[];
29
+
30
+ /**
31
+ * Sign typed data with all keystore private keys
32
+ * @param typedData - The complete EIP-712 typed data structure
33
+ * @param context - Signing context for HA slashing protection
34
+ * @returns signatures (when context provided with HA, only successfully claimed signatures are returned)
35
+ */
36
+ signTypedData(typedData: TypedDataDefinition, context: SigningContext): Promise<Signature[]>;
37
+
38
+ /**
39
+ * Sign typed data with a specific address's private key
40
+ * @param address - The address of the signer to use
41
+ * @param typedData - The complete EIP-712 typed data structure
42
+ * @param context - Signing context for HA slashing protection
43
+ * @returns signature
44
+ */
45
+ signTypedDataWithAddress(
46
+ address: EthAddress,
47
+ typedData: TypedDataDefinition,
48
+ context: SigningContext,
49
+ ): Promise<Signature>;
16
50
 
17
- sign(message: Buffer32): Promise<Signature>;
18
51
  /**
19
52
  * Flavor of sign message that followed EIP-712 eth signed message prefix
20
53
  * Note: this is only required when we are using ecdsa signatures over secp256k1
21
54
  *
22
55
  * @param message - The message to sign.
23
- * @returns The signature.
56
+ * @param context - Signing context for HA slashing protection
57
+ * @returns The signatures (when context provided with HA, only successfully claimed signatures are returned).
58
+ */
59
+ signMessage(message: Buffer32, context: SigningContext): Promise<Signature[]>;
60
+
61
+ /**
62
+ * Sign a message with a specific address's private key
63
+ * @param address - The address of the signer to use
64
+ * @param message - The message to sign
65
+ * @param context - Signing context for HA slashing protection
66
+ * @returns signature
67
+ */
68
+ signMessageWithAddress(address: EthAddress, message: Buffer32, context: SigningContext): Promise<Signature>;
69
+ }
70
+
71
+ /**
72
+ * Extended ValidatorKeyStore interface that supports the new keystore configuration model
73
+ * with role-based address management (attester, coinbase, publisher, fee recipient)
74
+ */
75
+ export interface ExtendedValidatorKeyStore extends ValidatorKeyStore {
76
+ /**
77
+ * Get all attester addresses (maps to existing getAddresses())
78
+ * @returns all attester addresses
79
+ */
80
+ getAttesterAddresses(): EthAddress[];
81
+
82
+ /**
83
+ * Get the coinbase address for a specific attester
84
+ * Falls back to the attester address if not set
85
+ * @param attesterAddress - The attester address to find the coinbase for
86
+ * @returns the coinbase address
87
+ */
88
+ getCoinbaseAddress(attesterAddress: EthAddress): EthAddress;
89
+
90
+ /**
91
+ * Get all publisher addresses for a specific attester (EOAs used for sending block proposal L1 txs)
92
+ * Falls back to the attester addresses if not set
93
+ * @param attesterAddress - The attester address to find the publishers for
94
+ * @returns all publisher addresses for this validator
95
+ */
96
+ getPublisherAddresses(attesterAddress: EthAddress): EthAddress[];
97
+
98
+ /**
99
+ * Get the fee recipient address for a specific attester
100
+ * @param attesterAddress - The attester address to find the fee recipient for
101
+ * @returns the fee recipient address
102
+ */
103
+ getFeeRecipient(attesterAddress: EthAddress): AztecAddress;
104
+
105
+ /**
106
+ * Get the remote signer configuration for a specific attester if available
107
+ * @param attesterAddress - The attester address to find the remote signer config for
108
+ * @returns the remote signer configuration or undefined
109
+ */
110
+ getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined;
111
+
112
+ /**
113
+ * Start the key store
114
+ */
115
+ start(): Promise<void>;
116
+
117
+ /**
118
+ * Stop the key store
24
119
  */
25
- signMessage(message: Buffer32): Promise<Signature>;
120
+ stop(): Promise<void>;
26
121
  }
@@ -1,46 +1,105 @@
1
- import type { Buffer32 } from '@aztec/foundation/buffer';
2
- import { Secp256k1Signer } from '@aztec/foundation/crypto';
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
3
3
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
4
  import type { Signature } from '@aztec/foundation/eth-signature';
5
+ import type { SigningContext } from '@aztec/validator-ha-signer/types';
6
+
7
+ import { type TypedDataDefinition, hashTypedData } from 'viem';
5
8
 
6
9
  import type { ValidatorKeyStore } from './interface.js';
7
10
 
8
11
  /**
9
12
  * Local Key Store
10
13
  *
11
- * An implementation of the Key store using an in memory private key.
14
+ * An implementation of the Key store using in memory private keys.
12
15
  */
13
16
  export class LocalKeyStore implements ValidatorKeyStore {
14
- private signer: Secp256k1Signer;
17
+ private signers: Secp256k1Signer[];
18
+ private signersByAddress: Map<`0x${string}`, Secp256k1Signer>;
15
19
 
16
- constructor(privateKey: Buffer32) {
17
- this.signer = new Secp256k1Signer(privateKey);
20
+ constructor(privateKeys: Buffer32[]) {
21
+ this.signers = privateKeys.map(privateKey => new Secp256k1Signer(privateKey));
22
+ this.signersByAddress = new Map(this.signers.map(signer => [signer.address.toString(), signer]));
18
23
  }
19
24
 
20
25
  /**
21
- * Get the address of the signer
26
+ * Get the address of a signer by index
22
27
  *
28
+ * @param index - The index of the signer
23
29
  * @returns the address
24
30
  */
25
- public getAddress(): EthAddress {
26
- return this.signer.address;
31
+ public getAddress(index: number): EthAddress {
32
+ if (index >= this.signers.length) {
33
+ throw new Error(`Index ${index} is out of bounds.`);
34
+ }
35
+ return this.signers[index].address;
27
36
  }
28
37
 
29
38
  /**
30
- * Sign a message with the keystore private key
39
+ * Get the addresses of all signers
31
40
  *
32
- * @param messageBuffer - The message buffer to sign
41
+ * @returns the addresses
42
+ */
43
+ public getAddresses(): EthAddress[] {
44
+ return this.signers.map(signer => signer.address);
45
+ }
46
+
47
+ /**
48
+ * Sign a message with all keystore private keys
49
+ * @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
50
+ * @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
33
51
  * @return signature
34
52
  */
35
- public sign(digest: Buffer32): Promise<Signature> {
36
- const signature = this.signer.sign(digest);
53
+ public signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
54
+ const digest = hashTypedData(typedData);
55
+ return Promise.all(this.signers.map(signer => signer.sign(Buffer32.fromString(digest))));
56
+ }
37
57
 
38
- return Promise.resolve(signature);
58
+ /**
59
+ * Sign a message with a specific address's private key
60
+ * @param address - The address of the signer to use
61
+ * @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
62
+ * @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
63
+ * @returns signature for the specified address
64
+ * @throws Error if the address is not found in the keystore
65
+ */
66
+ public signTypedDataWithAddress(
67
+ address: EthAddress,
68
+ typedData: TypedDataDefinition,
69
+ _context: SigningContext,
70
+ ): Promise<Signature> {
71
+ const signer = this.signersByAddress.get(address.toString());
72
+ if (!signer) {
73
+ throw new Error(`No signer found for address ${address.toString()}`);
74
+ }
75
+ const digest = hashTypedData(typedData);
76
+ return Promise.resolve(signer.sign(Buffer32.fromString(digest)));
39
77
  }
40
78
 
41
- public signMessage(message: Buffer32): Promise<Signature> {
42
- // Sign message adds eth sign prefix and hashes before signing
43
- const signature = this.signer.signMessage(message);
44
- return Promise.resolve(signature);
79
+ /**
80
+ * Sign a message using eth_sign with all keystore private keys
81
+ *
82
+ * @param message - The message to sign
83
+ * @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
84
+ * @return signatures
85
+ */
86
+ public signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
87
+ return Promise.all(this.signers.map(signer => signer.signMessage(message)));
88
+ }
89
+
90
+ /**
91
+ * Sign a message using eth_sign with a specific address's private key
92
+ * @param address - The address of the signer to use
93
+ * @param message - The message to sign
94
+ * @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
95
+ * @returns signature for the specified address
96
+ * @throws Error if the address is not found in the keystore
97
+ */
98
+ public signMessageWithAddress(address: EthAddress, message: Buffer32, _context: SigningContext): Promise<Signature> {
99
+ const signer = this.signersByAddress.get(address.toString());
100
+ if (!signer) {
101
+ throw new Error(`No signer found for address ${address.toString()}`);
102
+ }
103
+ return Promise.resolve(signer.signMessage(message));
45
104
  }
46
105
  }
@@ -0,0 +1,398 @@
1
+ import type { EthSigner } from '@aztec/ethereum/eth-signer';
2
+ import type { Buffer32 } from '@aztec/foundation/buffer';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import type { Signature } from '@aztec/foundation/eth-signature';
5
+ import { KeystoreManager, loadKeystoreFile } from '@aztec/node-keystore';
6
+ import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
7
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
8
+ import { InvalidValidatorPrivateKeyError } from '@aztec/stdlib/validators';
9
+ import type { SigningContext } from '@aztec/validator-ha-signer/types';
10
+
11
+ import type { TypedDataDefinition } from 'viem';
12
+ import { privateKeyToAccount } from 'viem/accounts';
13
+
14
+ import type { ExtendedValidatorKeyStore } from './interface.js';
15
+
16
+ type AddressHex = string;
17
+ type ValidatorIndex = number;
18
+
19
+ interface ValidatorCache {
20
+ attesters: EthSigner[];
21
+ publishers: EthSigner[];
22
+ all: EthSigner[];
23
+ byAddress: Map<AddressHex, EthSigner>; // all signers, any role
24
+ attesterSet: Set<AddressHex>; // attester addresses only
25
+ }
26
+
27
+ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
28
+ private readonly keystoreManager: KeystoreManager;
29
+
30
+ // Per-validator cache (lazy)
31
+ private readonly validators = new Map<ValidatorIndex, ValidatorCache>();
32
+
33
+ private readonly addressIndex = new Map<AddressHex, { signer: EthSigner; validatorIndex: ValidatorIndex }>();
34
+
35
+ private constructor(keystoreManager: KeystoreManager) {
36
+ this.keystoreManager = keystoreManager;
37
+ }
38
+
39
+ /**
40
+ * Create an adapter from a keystore JSON file on disk.
41
+ * @param keystoreFilePath Absolute or relative path to a keystore JSON file
42
+ * @returns A configured NodeKeystoreAdapter instance
43
+ * @throws Error when the file fails schema validation or cannot be read
44
+ */
45
+ static fromKeystoreFile(keystoreFilePath: string): NodeKeystoreAdapter {
46
+ const keystoreConfig = loadKeystoreFile(keystoreFilePath);
47
+ return NodeKeystoreAdapter.fromKeystoreConfig(keystoreConfig);
48
+ }
49
+
50
+ /**
51
+ * Create an adapter from an in-memory keystore-like object.
52
+ * Validates resolved duplicate attester addresses across validators and sources.
53
+ * @param keystoreConfig Parsed config object (typically result of loadKeystoreFile)
54
+ * @returns A configured NodeKeystoreAdapter instance
55
+ * @throws Error when resolved duplicate attester addresses are detected
56
+ */
57
+ static fromKeystoreConfig(keystoreConfig: unknown): NodeKeystoreAdapter {
58
+ const keystoreManager = new KeystoreManager(keystoreConfig as any);
59
+ // Validate resolved attester addresses (covers JSON V3 and mnemonic duplicates across validators)
60
+ keystoreManager.validateResolvedUniqueAttesterAddresses();
61
+ return new NodeKeystoreAdapter(keystoreManager);
62
+ }
63
+
64
+ /**
65
+ * Build an adapter directly from a list of validator private keys.
66
+ * Each key becomes a separate validator using the same key for attester and publisher,
67
+ * coinbase defaults to the derived EOA address, and feeRecipient is a 32-byte padded address.
68
+ * Note: Fee recipient is a temporary placeholder, replace with actual fee recipient when implemented.
69
+ */
70
+ static fromPrivateKeys(privateKeys: string[]): NodeKeystoreAdapter {
71
+ // Minimal validation: 0x + 64 hex
72
+ const isPk = (s: string) => /^0x[0-9a-fA-F]{64}$/.test(s);
73
+ for (const pk of privateKeys) {
74
+ if (!isPk(pk)) {
75
+ throw new InvalidValidatorPrivateKeyError();
76
+ }
77
+ }
78
+
79
+ const validators = privateKeys.map(pk => {
80
+ const account = privateKeyToAccount(pk as `0x${string}`);
81
+ const ethAddress = account.address as `0x${string}`;
82
+ // TODO: Temporary fee recipient, replace with actual fee recipient when implemented
83
+ const feeRecipient = `0x${ethAddress.slice(2).padStart(64, '0')}` as `0x${string}`;
84
+ return {
85
+ attester: pk as `0x${string}`,
86
+ publisher: pk as `0x${string}`,
87
+ coinbase: ethAddress,
88
+ feeRecipient,
89
+ };
90
+ });
91
+
92
+ const cfg = { schemaVersion: 1, validators } as const;
93
+ return NodeKeystoreAdapter.fromKeystoreConfig(cfg);
94
+ }
95
+
96
+ /**
97
+ * Build an adapter for a Web3Signer setup by providing the signer URL and the EOA addresses.
98
+ * Each address becomes a separate validator; attester and publisher point to the same remote signer entry.
99
+ * Note: Fee recipient is a temporary placeholder, replace with actual fee recipient when implemented.
100
+ */
101
+ static fromWeb3Signer(web3SignerUrl: string, addresses: EthAddress[]): NodeKeystoreAdapter {
102
+ const validators = addresses.map(address => {
103
+ const ethAddress = address.toString() as `0x${string}`;
104
+ // TODO: Temporary fee recipient, replace with actual fee recipient when implemented
105
+ const feeRecipient = `0x${ethAddress.slice(2).padStart(64, '0')}` as `0x${string}`;
106
+ return {
107
+ attester: { address: ethAddress, remoteSignerUrl: web3SignerUrl },
108
+ publisher: { address: ethAddress, remoteSignerUrl: web3SignerUrl },
109
+ coinbase: ethAddress,
110
+ feeRecipient,
111
+ };
112
+ });
113
+
114
+ const cfg = { schemaVersion: 1, validators } as const;
115
+ return NodeKeystoreAdapter.fromKeystoreConfig(cfg);
116
+ }
117
+
118
+ static fromKeyStoreManager(manager: KeystoreManager): NodeKeystoreAdapter {
119
+ return new NodeKeystoreAdapter(manager);
120
+ }
121
+
122
+ /**
123
+ * Normalize address keys to lowercase hex strings for map/set usage.
124
+ */
125
+ private static key(addr: EthAddress | AddressHex): AddressHex {
126
+ return typeof addr === 'string' ? addr.toLowerCase() : addr.toString().toLowerCase();
127
+ }
128
+
129
+ /**
130
+ * Ensure per-validator signer cache exists; build it by creating
131
+ * attester/publisher signers and populating indices when missing.
132
+ * @param validatorIndex Index of the validator in the keystore
133
+ * @returns The cached validator entry
134
+ */
135
+ private ensureValidator(validatorIndex: number): ValidatorCache {
136
+ const cached = this.validators.get(validatorIndex);
137
+ if (cached) {
138
+ return cached;
139
+ }
140
+
141
+ const attesters = this.keystoreManager.createAttesterSigners(validatorIndex);
142
+ const publishers = this.keystoreManager.createPublisherSigners(validatorIndex);
143
+
144
+ // Build 'all' + indices
145
+ const byAddress = new Map<AddressHex, EthSigner>();
146
+ const attesterSet = new Set<AddressHex>();
147
+
148
+ for (const s of attesters) {
149
+ const k = NodeKeystoreAdapter.key(s.address);
150
+ byAddress.set(k, s);
151
+ attesterSet.add(k);
152
+ }
153
+ for (const s of publishers) {
154
+ const k = NodeKeystoreAdapter.key(s.address);
155
+ if (!byAddress.has(k)) {
156
+ byAddress.set(k, s);
157
+ }
158
+ }
159
+
160
+ const all = Array.from(byAddress.values());
161
+
162
+ // Populate global index
163
+ for (const [k, signer] of byAddress.entries()) {
164
+ this.addressIndex.set(k, { signer, validatorIndex });
165
+ }
166
+
167
+ const built: ValidatorCache = { attesters, publishers, all, byAddress, attesterSet };
168
+ this.validators.set(validatorIndex, built);
169
+ return built;
170
+ }
171
+
172
+ /**
173
+ * Iterate all validator indices in the keystore manager.
174
+ */
175
+ private *validatorIndices(): Iterable<number> {
176
+ const n = this.keystoreManager.getValidatorCount();
177
+ for (let i = 0; i < n; i++) {
178
+ yield i;
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Find the validator index that contains the given attester address.
184
+ * @param attesterAddress Address to locate
185
+ * @returns Validator index
186
+ * @throws Error when no validator contains the attester
187
+ */
188
+ private findValidatorIndexForAttester(attesterAddress: EthAddress): number {
189
+ const key = NodeKeystoreAdapter.key(attesterAddress);
190
+
191
+ // Fast path: if we’ve already cached any validator that includes this as attester
192
+ for (const i of this.validatorIndices()) {
193
+ const v = this.ensureValidator(i);
194
+ if (v.attesterSet.has(key)) {
195
+ return i;
196
+ }
197
+ }
198
+
199
+ throw new Error(`Attester address ${attesterAddress.toString()} not found in any validator configuration`);
200
+ }
201
+
202
+ /**
203
+ * Get attester address by flat index across all validators' attester sets.
204
+ * @param index Zero-based flat index across all attesters
205
+ * @returns EthAddress for the indexed attester
206
+ * @throws Error when index is out of bounds
207
+ */
208
+ getAddress(index: number): EthAddress {
209
+ const all = this.getAddresses();
210
+ if (index < 0 || index >= all.length) {
211
+ throw new Error(`Index ${index} is out of bounds (0..${all.length - 1}).`);
212
+ }
213
+ return all[index];
214
+ }
215
+
216
+ /**
217
+ * Get all attester addresses across validators (legacy-compatible view).
218
+ */
219
+ getAddresses(): EthAddress[] {
220
+ const out: EthAddress[] = [];
221
+ for (const i of this.validatorIndices()) {
222
+ const v = this.ensureValidator(i);
223
+ // attester addresses only for backward compatibility
224
+ for (const s of v.attesters) {
225
+ out.push(s.address);
226
+ }
227
+ }
228
+ return out;
229
+ }
230
+
231
+ /**
232
+ * Sign typed data with all attester signers across validators.
233
+ * @param typedData EIP-712 typed data
234
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
235
+ * @returns Array of signatures in validator order, flattened
236
+ */
237
+ async signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
238
+ const jobs: Promise<Signature>[] = [];
239
+ for (const i of this.validatorIndices()) {
240
+ const v = this.ensureValidator(i);
241
+ for (const s of v.attesters) {
242
+ jobs.push(this.keystoreManager.signTypedData(s, typedData));
243
+ }
244
+ }
245
+ return await Promise.all(jobs);
246
+ }
247
+
248
+ /**
249
+ * Sign a message with all attester signers across validators.
250
+ * @param message 32-byte message (already hashed/padded as needed)
251
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
252
+ * @returns Array of signatures in validator order, flattened
253
+ */
254
+ async signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
255
+ const jobs: Promise<Signature>[] = [];
256
+ for (const i of this.validatorIndices()) {
257
+ const v = this.ensureValidator(i);
258
+ for (const s of v.attesters) {
259
+ jobs.push(this.keystoreManager.signMessage(s, message));
260
+ }
261
+ }
262
+ return await Promise.all(jobs);
263
+ }
264
+
265
+ /**
266
+ * Sign typed data with a signer identified by address (any role).
267
+ * Hydrates caches on-demand when the address is first seen.
268
+ * @param address Address to sign with
269
+ * @param typedData EIP-712 typed data
270
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
271
+ * @returns Signature from the signer matching the address
272
+ * @throws Error when no signer exists for the address
273
+ */
274
+ async signTypedDataWithAddress(
275
+ address: EthAddress,
276
+ typedData: TypedDataDefinition,
277
+ _context: SigningContext,
278
+ ): Promise<Signature> {
279
+ const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
280
+ if (entry) {
281
+ return await this.keystoreManager.signTypedData(entry.signer, typedData);
282
+ }
283
+
284
+ // If not in global index yet, lazily hydrate all validators once and retry
285
+ for (const i of this.validatorIndices()) {
286
+ this.ensureValidator(i);
287
+ }
288
+ const second = this.addressIndex.get(NodeKeystoreAdapter.key(address));
289
+ if (second) {
290
+ return await this.keystoreManager.signTypedData(second.signer, typedData);
291
+ }
292
+
293
+ throw new Error(`No signer found for address ${address.toString()}`);
294
+ }
295
+
296
+ /**
297
+ * Sign a message with a signer identified by address (any role).
298
+ * Hydrates caches on-demand when the address is first seen.
299
+ * @param address Address to sign with
300
+ * @param message 32-byte message
301
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
302
+ * @returns Signature from the signer matching the address
303
+ * @throws Error when no signer exists for the address
304
+ */
305
+ async signMessageWithAddress(address: EthAddress, message: Buffer32, _context: SigningContext): Promise<Signature> {
306
+ const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
307
+ if (entry) {
308
+ return await this.keystoreManager.signMessage(entry.signer, message);
309
+ }
310
+
311
+ for (const i of this.validatorIndices()) {
312
+ this.ensureValidator(i);
313
+ }
314
+ const second = this.addressIndex.get(NodeKeystoreAdapter.key(address));
315
+ if (second) {
316
+ return await this.keystoreManager.signMessage(second.signer, message);
317
+ }
318
+
319
+ throw new Error(`No signer found for address ${address.toString()}`);
320
+ }
321
+
322
+ /**
323
+ * Get all attester addresses across validators (alias of getAddresses).
324
+ */
325
+ getAttesterAddresses(): EthAddress[] {
326
+ return this.getAddresses();
327
+ }
328
+
329
+ /**
330
+ * Get the effective coinbase address for the validator that contains the given attester.
331
+ * @param attesterAddress Address of an attester belonging to the validator
332
+ * @returns Coinbase EthAddress
333
+ */
334
+ getCoinbaseAddress(attesterAddress: EthAddress): EthAddress {
335
+ const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
336
+ return this.keystoreManager.getCoinbaseAddress(validatorIndex, attesterAddress);
337
+ }
338
+
339
+ /**
340
+ * Get the publisher addresses for the validator that contains the given attester.
341
+ * @param attesterAddress Address of an attester belonging to the validator
342
+ * @returns Array of publisher addresses
343
+ */
344
+ getPublisherAddresses(attesterAddress: EthAddress): EthAddress[] {
345
+ const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
346
+ const v = this.ensureValidator(validatorIndex);
347
+ return v.publishers.map(s => s.address);
348
+ }
349
+
350
+ getAttestorForPublisher(publisherAddress: EthAddress): EthAddress {
351
+ const attestorAddresses = this.getAttesterAddresses();
352
+ for (const attestor of attestorAddresses) {
353
+ const publishers = this.getPublisherAddresses(attestor);
354
+ const found = publishers.some(publisher => publisher.equals(publisherAddress));
355
+ if (found) {
356
+ return attestor;
357
+ }
358
+ }
359
+ // Could not find an attestor for this publisher
360
+ throw new Error(`Failed to find attestor for publisher ${publisherAddress.toString()}`);
361
+ }
362
+
363
+ /**
364
+ * Get the fee recipient for the validator that contains the given attester.
365
+ * @param attesterAddress Address of an attester belonging to the validator
366
+ * @returns Fee recipient as AztecAddress
367
+ */
368
+ getFeeRecipient(attesterAddress: EthAddress): AztecAddress {
369
+ const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
370
+ return this.keystoreManager.getFeeRecipient(validatorIndex);
371
+ }
372
+
373
+ /**
374
+ * Get the effective remote signer configuration for the attester.
375
+ * Precedence: account-level override > validator-level override > file-level default.
376
+ * Returns undefined for local signers (private key / JSON-V3 / mnemonic).
377
+ * @param attesterAddress Address of an attester belonging to the validator
378
+ * @returns Effective remote signer configuration or undefined
379
+ */
380
+ getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined {
381
+ const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
382
+ return this.keystoreManager.getEffectiveRemoteSignerConfig(validatorIndex, attesterAddress);
383
+ }
384
+
385
+ /**
386
+ * Start the key store - no-op
387
+ */
388
+ start(): Promise<void> {
389
+ return Promise.resolve();
390
+ }
391
+
392
+ /**
393
+ * Stop the key store - no-op
394
+ */
395
+ stop(): Promise<void> {
396
+ return Promise.resolve();
397
+ }
398
+ }