@aztec/validator-client 0.0.0-test.1 → 0.0.1-commit.023c3e5

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 (78) hide show
  1. package/README.md +282 -0
  2. package/dest/block_proposal_handler.d.ts +63 -0
  3. package/dest/block_proposal_handler.d.ts.map +1 -0
  4. package/dest/block_proposal_handler.js +546 -0
  5. package/dest/checkpoint_builder.d.ts +66 -0
  6. package/dest/checkpoint_builder.d.ts.map +1 -0
  7. package/dest/checkpoint_builder.js +173 -0
  8. package/dest/config.d.ts +3 -14
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +41 -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 +123 -17
  14. package/dest/factory.d.ts +28 -6
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +13 -6
  17. package/dest/index.d.ts +6 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +5 -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 +13 -5
  39. package/dest/metrics.d.ts.map +1 -1
  40. package/dest/metrics.js +63 -22
  41. package/dest/tx_validator/index.d.ts +3 -0
  42. package/dest/tx_validator/index.d.ts.map +1 -0
  43. package/dest/tx_validator/index.js +2 -0
  44. package/dest/tx_validator/nullifier_cache.d.ts +14 -0
  45. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
  46. package/dest/tx_validator/nullifier_cache.js +24 -0
  47. package/dest/tx_validator/tx_validator_factory.d.ts +19 -0
  48. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
  49. package/dest/tx_validator/tx_validator_factory.js +54 -0
  50. package/dest/validator.d.ts +73 -58
  51. package/dest/validator.d.ts.map +1 -1
  52. package/dest/validator.js +559 -166
  53. package/package.json +37 -21
  54. package/src/block_proposal_handler.ts +555 -0
  55. package/src/checkpoint_builder.ts +314 -0
  56. package/src/config.ts +52 -22
  57. package/src/duties/validation_service.ts +193 -19
  58. package/src/factory.ts +65 -11
  59. package/src/index.ts +5 -1
  60. package/src/key_store/ha_key_store.ts +269 -0
  61. package/src/key_store/index.ts +3 -0
  62. package/src/key_store/interface.ts +100 -5
  63. package/src/key_store/local_key_store.ts +77 -18
  64. package/src/key_store/node_keystore_adapter.ts +398 -0
  65. package/src/key_store/web3signer_key_store.ts +205 -0
  66. package/src/metrics.ts +86 -23
  67. package/src/tx_validator/index.ts +2 -0
  68. package/src/tx_validator/nullifier_cache.ts +30 -0
  69. package/src/tx_validator/tx_validator_factory.ts +154 -0
  70. package/src/validator.ts +757 -221
  71. package/dest/errors/index.d.ts +0 -2
  72. package/dest/errors/index.d.ts.map +0 -1
  73. package/dest/errors/index.js +0 -1
  74. package/dest/errors/validator.error.d.ts +0 -29
  75. package/dest/errors/validator.error.d.ts.map +0 -1
  76. package/dest/errors/validator.error.js +0 -45
  77. package/src/errors/index.ts +0 -1
  78. package/src/errors/validator.error.ts +0 -55
package/src/factory.ts CHANGED
@@ -1,28 +1,82 @@
1
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
1
2
  import type { EpochCache } from '@aztec/epoch-cache';
2
3
  import type { DateProvider } from '@aztec/foundation/timer';
3
- import type { P2P } from '@aztec/p2p';
4
+ import type { KeystoreManager } from '@aztec/node-keystore';
5
+ import { BlockProposalValidator, type P2PClient } from '@aztec/p2p';
6
+ import type { L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
7
+ import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
8
+ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
4
9
  import type { TelemetryClient } from '@aztec/telemetry-client';
5
10
 
6
- import { generatePrivateKey } from 'viem/accounts';
7
-
8
- import type { ValidatorClientConfig } from './config.js';
11
+ import { BlockProposalHandler } from './block_proposal_handler.js';
12
+ import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
13
+ import { ValidatorMetrics } from './metrics.js';
9
14
  import { ValidatorClient } from './validator.js';
10
15
 
16
+ export function createBlockProposalHandler(
17
+ config: ValidatorClientFullConfig,
18
+ deps: {
19
+ checkpointsBuilder: FullNodeCheckpointsBuilder;
20
+ worldState: WorldStateSynchronizer;
21
+ blockSource: L2BlockSource & L2BlockSink;
22
+ l1ToL2MessageSource: L1ToL2MessageSource;
23
+ p2pClient: P2PClient;
24
+ epochCache: EpochCache;
25
+ dateProvider: DateProvider;
26
+ telemetry: TelemetryClient;
27
+ },
28
+ ) {
29
+ const metrics = new ValidatorMetrics(deps.telemetry);
30
+ const blockProposalValidator = new BlockProposalValidator(deps.epochCache, {
31
+ txsPermitted: !config.disableTransactions,
32
+ });
33
+ return new BlockProposalHandler(
34
+ deps.checkpointsBuilder,
35
+ deps.worldState,
36
+ deps.blockSource,
37
+ deps.l1ToL2MessageSource,
38
+ deps.p2pClient.getTxProvider(),
39
+ blockProposalValidator,
40
+ deps.epochCache,
41
+ config,
42
+ metrics,
43
+ deps.dateProvider,
44
+ deps.telemetry,
45
+ );
46
+ }
47
+
11
48
  export function createValidatorClient(
12
- config: ValidatorClientConfig,
49
+ config: ValidatorClientFullConfig,
13
50
  deps: {
14
- p2pClient: P2P;
51
+ checkpointsBuilder: FullNodeCheckpointsBuilder;
52
+ worldState: WorldStateSynchronizer;
53
+ p2pClient: P2PClient;
54
+ blockSource: L2BlockSource & L2BlockSink;
55
+ l1ToL2MessageSource: L1ToL2MessageSource;
15
56
  telemetry: TelemetryClient;
16
57
  dateProvider: DateProvider;
17
58
  epochCache: EpochCache;
59
+ keyStoreManager: KeystoreManager | undefined;
60
+ blobClient: BlobClientInterface;
18
61
  },
19
62
  ) {
20
- if (config.disableValidator) {
63
+ if (config.disableValidator || !deps.keyStoreManager) {
21
64
  return undefined;
22
65
  }
23
- if (config.validatorPrivateKey === undefined || config.validatorPrivateKey === '') {
24
- config.validatorPrivateKey = generatePrivateKey();
25
- }
26
66
 
27
- return ValidatorClient.new(config, deps.epochCache, deps.p2pClient, deps.dateProvider, deps.telemetry);
67
+ const txProvider = deps.p2pClient.getTxProvider();
68
+ return ValidatorClient.new(
69
+ config,
70
+ deps.checkpointsBuilder,
71
+ deps.worldState,
72
+ deps.epochCache,
73
+ deps.p2pClient,
74
+ deps.blockSource,
75
+ deps.l1ToL2MessageSource,
76
+ txProvider,
77
+ deps.keyStoreManager,
78
+ deps.blobClient,
79
+ deps.dateProvider,
80
+ deps.telemetry,
81
+ );
28
82
  }
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ export * from './block_proposal_handler.js';
2
+ export * from './checkpoint_builder.js';
1
3
  export * from './config.js';
2
- export * from './validator.js';
3
4
  export * from './factory.js';
5
+ export * from './validator.js';
6
+ export * from './key_store/index.js';
7
+ export * from './tx_validator/index.js';
@@ -0,0 +1,269 @@
1
+ /**
2
+ * High Availability Key Store
3
+ *
4
+ * A ValidatorKeyStore wrapper that adds slashing protection for HA validator setups.
5
+ * When multiple validator nodes are running, only one node will sign for a given duty.
6
+ */
7
+ import { Buffer32 } from '@aztec/foundation/buffer';
8
+ import type { EthAddress } from '@aztec/foundation/eth-address';
9
+ import type { Signature } from '@aztec/foundation/eth-signature';
10
+ import { createLogger } from '@aztec/foundation/log';
11
+ import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
12
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
14
+ import {
15
+ type HAProtectedSigningContext,
16
+ type SigningContext,
17
+ isHAProtectedContext,
18
+ } from '@aztec/validator-ha-signer/types';
19
+ import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
20
+
21
+ import { type TypedDataDefinition, hashTypedData } from 'viem';
22
+
23
+ import type { ExtendedValidatorKeyStore } from './interface.js';
24
+
25
+ /**
26
+ * High Availability Key Store
27
+ *
28
+ * Wraps a base ExtendedValidatorKeyStore and ValidatorHASigner to provide
29
+ * HA-protected signing operations (when context is provided).
30
+ *
31
+ * The extended interface methods (getAttesterAddresses, getCoinbaseAddress, etc.)
32
+ * are pure pass-through since they don't require HA coordination.
33
+ *
34
+ * Usage:
35
+ * ```typescript
36
+ * const baseKeyStore = NodeKeystoreAdapter.fromPrivateKeys(privateKeys);
37
+ * const haSigner = new ValidatorHASigner(db, config);
38
+ * const haKeyStore = new HAKeyStore(baseKeyStore, haSigner);
39
+ *
40
+ * // Without context - signs directly (no HA protection)
41
+ * const sig = await haKeyStore.signMessageWithAddress(addr, msg);
42
+ *
43
+ * // With context - HA protected, throws DutyAlreadySignedError if already signed
44
+ * const result = await haKeyStore.signMessageWithAddress(addr, msg, {
45
+ * slot: 100n,
46
+ * blockNumber: 50n,
47
+ * dutyType: DutyType.BLOCK_PROPOSAL,
48
+ * });
49
+ * ```
50
+ */
51
+ export class HAKeyStore implements ExtendedValidatorKeyStore {
52
+ private readonly log = createLogger('ha-key-store');
53
+
54
+ constructor(
55
+ private readonly baseKeyStore: ExtendedValidatorKeyStore,
56
+ private readonly haSigner: ValidatorHASigner,
57
+ ) {
58
+ this.log.info('HAKeyStore initialized', {
59
+ nodeId: haSigner.nodeId,
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Sign typed data with all addresses.
65
+ * Coordinates across nodes to prevent double-signing for most duty types.
66
+ * AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
67
+ * Returns only signatures that were successfully claimed by this node.
68
+ */
69
+ async signTypedData(typedData: TypedDataDefinition, context: SigningContext): Promise<Signature[]> {
70
+ // no need for HA protection on auth request and txs signatures
71
+ if (!isHAProtectedContext(context)) {
72
+ return this.baseKeyStore.signTypedData(typedData, context);
73
+ }
74
+
75
+ // Sign each address with HA protection
76
+ const addresses = this.getAddresses();
77
+ const results = await Promise.allSettled(
78
+ addresses.map(addr => this.signTypedDataWithAddress(addr, typedData, context)),
79
+ );
80
+
81
+ // Filter out failures (already signed by other nodes or other errors)
82
+ return results
83
+ .filter((result): result is PromiseFulfilledResult<Signature> => {
84
+ if (result.status === 'fulfilled') {
85
+ return true;
86
+ }
87
+ // Log expected HA errors (already signed) at debug level
88
+ if (result.reason instanceof DutyAlreadySignedError) {
89
+ this.log.debug(`Duty already signed by another node`, {
90
+ dutyType: context.dutyType,
91
+ slot: context.slot,
92
+ signedByNode: result.reason.signedByNode,
93
+ });
94
+ return false;
95
+ }
96
+ // Re-throw unexpected errors
97
+ throw result.reason;
98
+ })
99
+ .map(result => result.value);
100
+ }
101
+
102
+ /**
103
+ * Sign a message with all addresses.
104
+ * Coordinates across nodes to prevent double-signing for most duty types.
105
+ * AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
106
+ * Returns only signatures that were successfully claimed by this node.
107
+ */
108
+ async signMessage(message: Buffer32, context: SigningContext): Promise<Signature[]> {
109
+ // no need for HA protection on auth request and txs signatures
110
+ if (!isHAProtectedContext(context)) {
111
+ return this.baseKeyStore.signMessage(message, context);
112
+ }
113
+
114
+ // Sign each address with HA protection
115
+ const addresses = this.getAddresses();
116
+ const results = await Promise.allSettled(
117
+ addresses.map(addr => this.signMessageWithAddress(addr, message, context)),
118
+ );
119
+
120
+ // Filter out failures (already signed by other nodes or other errors)
121
+ return results
122
+ .filter((result): result is PromiseFulfilledResult<Signature> => {
123
+ if (result.status === 'fulfilled') {
124
+ return true;
125
+ }
126
+ // Log expected HA errors (already signed) at debug level
127
+ if (result.reason instanceof DutyAlreadySignedError) {
128
+ this.log.debug(`Duty already signed by another node`, {
129
+ dutyType: context.dutyType,
130
+ slot: context.slot,
131
+ signedByNode: result.reason.signedByNode,
132
+ });
133
+ return false;
134
+ }
135
+ // Re-throw unexpected errors
136
+ throw result.reason;
137
+ })
138
+ .map(result => result.value);
139
+ }
140
+
141
+ /**
142
+ * Sign typed data with a specific address.
143
+ * Coordinates across nodes to prevent double-signing for most duty types.
144
+ * AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
145
+ * @throws DutyAlreadySignedError if the duty was already signed by another node
146
+ * @throws SlashingProtectionError if attempting to sign different data for the same slot
147
+ */
148
+ async signTypedDataWithAddress(
149
+ address: EthAddress,
150
+ typedData: TypedDataDefinition,
151
+ context: SigningContext,
152
+ ): Promise<Signature> {
153
+ // AUTH_REQUEST and TXS bypass HA protection - multiple signatures are safe
154
+ if (!isHAProtectedContext(context)) {
155
+ return this.baseKeyStore.signTypedDataWithAddress(address, typedData, context);
156
+ }
157
+
158
+ // Compute signing root from typed data for HA tracking
159
+ const digest = hashTypedData(typedData);
160
+ const messageHash = Buffer32.fromString(digest);
161
+
162
+ try {
163
+ return await this.haSigner.signWithProtection(address, messageHash, context, () =>
164
+ this.baseKeyStore.signTypedDataWithAddress(address, typedData, context),
165
+ );
166
+ } catch (error) {
167
+ this.processSigningError(error, context);
168
+ throw error;
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Sign a message with a specific address.
174
+ * Coordinates across nodes to prevent double-signing for most duty types.
175
+ * AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
176
+ * @throws DutyAlreadySignedError if the duty was already signed by another node
177
+ * @throws SlashingProtectionError if attempting to sign different data for the same slot
178
+ */
179
+ async signMessageWithAddress(address: EthAddress, message: Buffer32, context: SigningContext): Promise<Signature> {
180
+ // no need for HA protection on auth request and txs signatures
181
+ if (!isHAProtectedContext(context)) {
182
+ return this.baseKeyStore.signMessageWithAddress(address, message, context);
183
+ }
184
+
185
+ try {
186
+ return await this.haSigner.signWithProtection(address, message, context, messageHash =>
187
+ this.baseKeyStore.signMessageWithAddress(address, messageHash, context),
188
+ );
189
+ } catch (error) {
190
+ this.processSigningError(error, context);
191
+ throw error;
192
+ }
193
+ }
194
+
195
+ // ─────────────────────────────────────────────────────────────────────────────
196
+ // pass-through methods (no HA logic needed)
197
+ // ─────────────────────────────────────────────────────────────────────────────
198
+
199
+ getAddress(index: number): EthAddress {
200
+ return this.baseKeyStore.getAddress(index);
201
+ }
202
+
203
+ getAddresses(): EthAddress[] {
204
+ return this.baseKeyStore.getAddresses();
205
+ }
206
+
207
+ getAttesterAddresses(): EthAddress[] {
208
+ return this.baseKeyStore.getAttesterAddresses();
209
+ }
210
+
211
+ getCoinbaseAddress(attesterAddress: EthAddress): EthAddress {
212
+ return this.baseKeyStore.getCoinbaseAddress(attesterAddress);
213
+ }
214
+
215
+ getPublisherAddresses(attesterAddress: EthAddress): EthAddress[] {
216
+ return this.baseKeyStore.getPublisherAddresses(attesterAddress);
217
+ }
218
+
219
+ getFeeRecipient(attesterAddress: EthAddress): AztecAddress {
220
+ return this.baseKeyStore.getFeeRecipient(attesterAddress);
221
+ }
222
+
223
+ getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined {
224
+ return this.baseKeyStore.getRemoteSignerConfig(attesterAddress);
225
+ }
226
+
227
+ /**
228
+ * Process signing errors from the HA signer.
229
+ * Logs expected HA errors (already signed) at appropriate levels.
230
+ * Re-throws unexpected errors.
231
+ */
232
+ private processSigningError(error: unknown, context: HAProtectedSigningContext) {
233
+ if (error instanceof DutyAlreadySignedError) {
234
+ this.log.debug(`Duty already signed by another node with the same payload`, {
235
+ dutyType: context.dutyType,
236
+ slot: context.slot,
237
+ signedByNode: error.signedByNode,
238
+ });
239
+ return;
240
+ }
241
+
242
+ if (error instanceof SlashingProtectionError) {
243
+ this.log.warn(`Duty already signed by another node with different payload`, {
244
+ dutyType: context.dutyType,
245
+ slot: context.slot,
246
+ existingMessageHash: error.existingMessageHash,
247
+ attemptedMessageHash: error.attemptedMessageHash,
248
+ });
249
+ return;
250
+ }
251
+
252
+ // Re-throw errors
253
+ throw error;
254
+ }
255
+
256
+ /**
257
+ * Start the high-availability key store
258
+ */
259
+ public start(): Promise<void> {
260
+ return Promise.resolve(this.haSigner.start());
261
+ }
262
+
263
+ /**
264
+ * Stop the high-availability key store
265
+ */
266
+ public async stop() {
267
+ await this.haSigner.stop();
268
+ }
269
+ }
@@ -1,2 +1,5 @@
1
1
  export * from './interface.js';
2
2
  export * from './local_key_store.js';
3
+ export * from './node_keystore_adapter.js';
4
+ export * from './web3signer_key_store.js';
5
+ export * from './ha_key_store.js';
@@ -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
  }