@aztec/validator-client 0.0.1-commit.7d4e6cd → 0.0.1-commit.858058eac

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 (57) hide show
  1. package/README.md +53 -24
  2. package/dest/block_proposal_handler.d.ts +8 -8
  3. package/dest/block_proposal_handler.d.ts.map +1 -1
  4. package/dest/block_proposal_handler.js +27 -32
  5. package/dest/checkpoint_builder.d.ts +21 -25
  6. package/dest/checkpoint_builder.d.ts.map +1 -1
  7. package/dest/checkpoint_builder.js +50 -32
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +12 -14
  11. package/dest/duties/validation_service.d.ts +19 -6
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +72 -19
  14. package/dest/factory.d.ts +2 -2
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +1 -1
  17. package/dest/key_store/ha_key_store.d.ts +99 -0
  18. package/dest/key_store/ha_key_store.d.ts.map +1 -0
  19. package/dest/key_store/ha_key_store.js +208 -0
  20. package/dest/key_store/index.d.ts +2 -1
  21. package/dest/key_store/index.d.ts.map +1 -1
  22. package/dest/key_store/index.js +1 -0
  23. package/dest/key_store/interface.d.ts +36 -6
  24. package/dest/key_store/interface.d.ts.map +1 -1
  25. package/dest/key_store/local_key_store.d.ts +10 -5
  26. package/dest/key_store/local_key_store.d.ts.map +1 -1
  27. package/dest/key_store/local_key_store.js +8 -4
  28. package/dest/key_store/node_keystore_adapter.d.ts +18 -5
  29. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
  30. package/dest/key_store/node_keystore_adapter.js +18 -4
  31. package/dest/key_store/web3signer_key_store.d.ts +10 -5
  32. package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
  33. package/dest/key_store/web3signer_key_store.js +8 -4
  34. package/dest/metrics.d.ts +4 -3
  35. package/dest/metrics.d.ts.map +1 -1
  36. package/dest/metrics.js +34 -5
  37. package/dest/tx_validator/tx_validator_factory.d.ts +4 -3
  38. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  39. package/dest/tx_validator/tx_validator_factory.js +17 -16
  40. package/dest/validator.d.ts +35 -16
  41. package/dest/validator.d.ts.map +1 -1
  42. package/dest/validator.js +194 -91
  43. package/package.json +21 -17
  44. package/src/block_proposal_handler.ts +41 -42
  45. package/src/checkpoint_builder.ts +85 -38
  46. package/src/config.ts +11 -13
  47. package/src/duties/validation_service.ts +91 -23
  48. package/src/factory.ts +1 -0
  49. package/src/key_store/ha_key_store.ts +269 -0
  50. package/src/key_store/index.ts +1 -0
  51. package/src/key_store/interface.ts +44 -5
  52. package/src/key_store/local_key_store.ts +13 -4
  53. package/src/key_store/node_keystore_adapter.ts +27 -4
  54. package/src/key_store/web3signer_key_store.ts +17 -4
  55. package/src/metrics.ts +45 -6
  56. package/src/tx_validator/tx_validator_factory.ts +52 -31
  57. package/src/validator.ts +253 -111
@@ -1,3 +1,9 @@
1
+ import {
2
+ BlockNumber,
3
+ type CheckpointNumber,
4
+ IndexWithinCheckpoint,
5
+ type SlotNumber,
6
+ } from '@aztec/foundation/branded-types';
1
7
  import { Buffer32 } from '@aztec/foundation/buffer';
2
8
  import { keccak256 } from '@aztec/foundation/crypto/keccak';
3
9
  import { Fr } from '@aztec/foundation/curves/bn254';
@@ -18,6 +24,8 @@ import {
18
24
  } from '@aztec/stdlib/p2p';
19
25
  import type { CheckpointHeader } from '@aztec/stdlib/rollup';
20
26
  import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
27
+ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
28
+ import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
21
29
 
22
30
  import type { ValidatorKeyStore } from '../key_store/interface.js';
23
31
 
@@ -31,34 +39,40 @@ export class ValidationService {
31
39
  * Create a block proposal with the given header, archive, and transactions
32
40
  *
33
41
  * @param blockHeader - The block header
34
- * @param indexWithinCheckpoint - Index of this block within the checkpoint (0-indexed)
42
+ * @param blockIndexWithinCheckpoint - The block index within checkpoint for HA signing context
35
43
  * @param inHash - Hash of L1 to L2 messages for this checkpoint
36
44
  * @param archive - The archive of the current block
37
- * @param txs - TxHash[] ordered list of transactions
45
+ * @param txs - Ordered list of transactions (Tx[])
46
+ * @param proposerAttesterAddress - The address of the proposer/attester, or undefined
38
47
  * @param options - Block proposal options (including broadcastInvalidBlockProposal for testing)
39
48
  *
40
49
  * @returns A block proposal signing the above information
50
+ * @throws DutyAlreadySignedError if HA signer indicates duty already signed by another node
51
+ * @throws SlashingProtectionError if attempting to sign different data for same slot
41
52
  */
42
53
  public createBlockProposal(
43
54
  blockHeader: BlockHeader,
44
- indexWithinCheckpoint: number,
55
+ blockIndexWithinCheckpoint: IndexWithinCheckpoint,
45
56
  inHash: Fr,
46
57
  archive: Fr,
47
58
  txs: Tx[],
48
59
  proposerAttesterAddress: EthAddress | undefined,
49
60
  options: BlockProposalOptions,
50
61
  ): Promise<BlockProposal> {
51
- const payloadSigner = this.getPayloadSigner(proposerAttesterAddress);
52
-
53
62
  // For testing: change the new archive to trigger state_mismatch validation failure
54
63
  if (options.broadcastInvalidBlockProposal) {
55
64
  archive = Fr.random();
56
65
  this.log.warn(`Creating INVALID block proposal for slot ${blockHeader.globalVariables.slotNumber}`);
57
66
  }
58
67
 
68
+ // Create a signer that uses the appropriate address
69
+ const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
70
+ const payloadSigner = (payload: Buffer32, context: SigningContext) =>
71
+ this.keyStore.signMessageWithAddress(address, payload, context);
72
+
59
73
  return BlockProposal.createProposalFromSigner(
60
74
  blockHeader,
61
- indexWithinCheckpoint,
75
+ blockIndexWithinCheckpoint,
62
76
  inHash,
63
77
  archive,
64
78
  txs.map(tx => tx.getTxHash()),
@@ -85,14 +99,18 @@ export class ValidationService {
85
99
  proposerAttesterAddress: EthAddress | undefined,
86
100
  options: CheckpointProposalOptions,
87
101
  ): Promise<CheckpointProposal> {
88
- const payloadSigner = this.getPayloadSigner(proposerAttesterAddress);
89
-
90
102
  // For testing: change the archive to trigger state_mismatch validation failure
91
103
  if (options.broadcastInvalidCheckpointProposal) {
92
104
  archive = Fr.random();
93
105
  this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
94
106
  }
95
107
 
108
+ // Create a signer that takes payload and context, and uses the appropriate address
109
+ const payloadSigner = (payload: Buffer32, context: SigningContext) => {
110
+ const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
111
+ return this.keyStore.signMessageWithAddress(address, payload, context);
112
+ };
113
+
96
114
  // Last block to include in the proposal
97
115
  const lastBlock = lastBlockInfo && {
98
116
  blockHeader: lastBlockInfo.blockHeader,
@@ -104,16 +122,6 @@ export class ValidationService {
104
122
  return CheckpointProposal.createProposalFromSigner(checkpointHeader, archive, lastBlock, payloadSigner);
105
123
  }
106
124
 
107
- private getPayloadSigner(proposerAttesterAddress: EthAddress | undefined): (payload: Buffer32) => Promise<Signature> {
108
- if (proposerAttesterAddress !== undefined) {
109
- return (payload: Buffer32) => this.keyStore.signMessageWithAddress(proposerAttesterAddress, payload);
110
- } else {
111
- // if there is no proposer attester address, just use the first signer
112
- const signer = this.keyStore.getAddress(0);
113
- return (payload: Buffer32) => this.keyStore.signMessageWithAddress(signer, payload);
114
- }
115
- }
116
-
117
125
  /**
118
126
  * Attest with selection of validators to the given checkpoint proposal
119
127
  *
@@ -133,19 +141,79 @@ export class ValidationService {
133
141
  const buf = Buffer32.fromBuffer(
134
142
  keccak256(payload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation)),
135
143
  );
136
- const signatures = await Promise.all(
137
- attestors.map(attestor => this.keyStore.signMessageWithAddress(attestor, buf)),
144
+
145
+ // TODO(spy/ha): Use checkpointNumber instead of blockNumber once CheckpointHeader includes it.
146
+ // Currently using lastBlock.blockNumber as a proxy for checkpoint identification in HA signing.
147
+ // blockNumber is NOT used for the primary key so it's safe to use here.
148
+ // See CheckpointHeader TODO and SigningContext types documentation.
149
+ let blockNumber: BlockNumber;
150
+ try {
151
+ blockNumber = proposal.blockNumber;
152
+ } catch {
153
+ // Checkpoint proposal may not have lastBlock, use 0 as fallback
154
+ blockNumber = BlockNumber(0);
155
+ }
156
+ const context: SigningContext = {
157
+ slot: proposal.slotNumber,
158
+ blockNumber,
159
+ dutyType: DutyType.ATTESTATION,
160
+ };
161
+
162
+ // Sign each attestor in parallel, catching HA errors per-attestor
163
+ const results = await Promise.allSettled(
164
+ attestors.map(async attestor => {
165
+ const sig = await this.keyStore.signMessageWithAddress(attestor, buf, context);
166
+ // return new BlockAttestation(proposal.payload, sig, proposal.signature);
167
+ return new CheckpointAttestation(payload, sig, proposal.signature);
168
+ }),
138
169
  );
139
- return signatures.map(sig => new CheckpointAttestation(payload, sig, proposal.signature));
170
+
171
+ const attestations: CheckpointAttestation[] = [];
172
+ for (let i = 0; i < results.length; i++) {
173
+ const result = results[i];
174
+ if (result.status === 'fulfilled') {
175
+ attestations.push(result.value);
176
+ } else {
177
+ const error = result.reason;
178
+ if (error instanceof DutyAlreadySignedError || error instanceof SlashingProtectionError) {
179
+ this.log.info(
180
+ `Attestation for slot ${proposal.slotNumber} by ${attestors[i]} already signed by another High-Availability node`,
181
+ );
182
+ // Continue with remaining attestors
183
+ } else {
184
+ throw error;
185
+ }
186
+ }
187
+ }
188
+
189
+ return attestations;
140
190
  }
141
191
 
142
- async signAttestationsAndSigners(
192
+ /**
193
+ * Sign attestations and signers payload
194
+ * @param attestationsAndSigners - The attestations and signers to sign
195
+ * @param proposer - The proposer address to sign with
196
+ * @param slot - The slot number for HA signing context
197
+ * @param blockNumber - The block or checkpoint number for HA signing context
198
+ * @returns signature
199
+ * @throws DutyAlreadySignedError if already signed by another HA node
200
+ * @throws SlashingProtectionError if attempting to sign different data for same slot
201
+ */
202
+ signAttestationsAndSigners(
143
203
  attestationsAndSigners: CommitteeAttestationsAndSigners,
144
204
  proposer: EthAddress,
205
+ slot: SlotNumber,
206
+ blockNumber: BlockNumber | CheckpointNumber,
145
207
  ): Promise<Signature> {
208
+ const context: SigningContext = {
209
+ slot,
210
+ blockNumber,
211
+ dutyType: DutyType.ATTESTATIONS_AND_SIGNERS,
212
+ };
213
+
146
214
  const buf = Buffer32.fromBuffer(
147
215
  keccak256(attestationsAndSigners.getPayloadToSign(SignatureDomainSeparator.attestationsAndSigners)),
148
216
  );
149
- return await this.keyStore.signMessageWithAddress(proposer, buf);
217
+ return this.keyStore.signMessageWithAddress(proposer, buf, context);
150
218
  }
151
219
  }
package/src/factory.ts CHANGED
@@ -37,6 +37,7 @@ export function createBlockProposalHandler(
37
37
  deps.l1ToL2MessageSource,
38
38
  deps.p2pClient.getTxProvider(),
39
39
  blockProposalValidator,
40
+ deps.epochCache,
40
41
  config,
41
42
  metrics,
42
43
  deps.dateProvider,
@@ -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 async start() {
260
+ await 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
+ }
@@ -2,3 +2,4 @@ export * from './interface.js';
2
2
  export * from './local_key_store.js';
3
3
  export * from './node_keystore_adapter.js';
4
4
  export * from './web3signer_key_store.js';
5
+ export * from './ha_key_store.js';
@@ -3,6 +3,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import type { Signature } from '@aztec/foundation/eth-signature';
4
4
  import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
5
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
+ import type { SigningContext } from '@aztec/validator-ha-signer/types';
6
7
 
7
8
  import type { TypedDataDefinition } from 'viem';
8
9
 
@@ -26,17 +27,45 @@ export interface ValidatorKeyStore {
26
27
  */
27
28
  getAddresses(): EthAddress[];
28
29
 
29
- signTypedData(typedData: TypedDataDefinition): Promise<Signature[]>;
30
- signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature>;
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>;
50
+
31
51
  /**
32
52
  * Flavor of sign message that followed EIP-712 eth signed message prefix
33
53
  * Note: this is only required when we are using ecdsa signatures over secp256k1
34
54
  *
35
55
  * @param message - The message to sign.
36
- * @returns The signatures.
56
+ * @param context - Signing context for HA slashing protection
57
+ * @returns The signatures (when context provided with HA, only successfully claimed signatures are returned).
37
58
  */
38
- signMessage(message: Buffer32): Promise<Signature[]>;
39
- signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature>;
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>;
40
69
  }
41
70
 
42
71
  /**
@@ -79,4 +108,14 @@ export interface ExtendedValidatorKeyStore extends ValidatorKeyStore {
79
108
  * @returns the remote signer configuration or undefined
80
109
  */
81
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
119
+ */
120
+ stop(): Promise<void>;
82
121
  }
@@ -2,6 +2,7 @@ import { Buffer32 } from '@aztec/foundation/buffer';
2
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';
5
6
 
6
7
  import { type TypedDataDefinition, hashTypedData } from 'viem';
7
8
 
@@ -46,9 +47,10 @@ export class LocalKeyStore implements ValidatorKeyStore {
46
47
  /**
47
48
  * Sign a message with all keystore private keys
48
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)
49
51
  * @return signature
50
52
  */
51
- public signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
53
+ public signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
52
54
  const digest = hashTypedData(typedData);
53
55
  return Promise.all(this.signers.map(signer => signer.sign(Buffer32.fromString(digest))));
54
56
  }
@@ -57,10 +59,15 @@ export class LocalKeyStore implements ValidatorKeyStore {
57
59
  * Sign a message with a specific address's private key
58
60
  * @param address - The address of the signer to use
59
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)
60
63
  * @returns signature for the specified address
61
64
  * @throws Error if the address is not found in the keystore
62
65
  */
63
- public signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature> {
66
+ public signTypedDataWithAddress(
67
+ address: EthAddress,
68
+ typedData: TypedDataDefinition,
69
+ _context: SigningContext,
70
+ ): Promise<Signature> {
64
71
  const signer = this.signersByAddress.get(address.toString());
65
72
  if (!signer) {
66
73
  throw new Error(`No signer found for address ${address.toString()}`);
@@ -73,9 +80,10 @@ export class LocalKeyStore implements ValidatorKeyStore {
73
80
  * Sign a message using eth_sign with all keystore private keys
74
81
  *
75
82
  * @param message - The message to sign
83
+ * @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
76
84
  * @return signatures
77
85
  */
78
- public signMessage(message: Buffer32): Promise<Signature[]> {
86
+ public signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
79
87
  return Promise.all(this.signers.map(signer => signer.signMessage(message)));
80
88
  }
81
89
 
@@ -83,10 +91,11 @@ export class LocalKeyStore implements ValidatorKeyStore {
83
91
  * Sign a message using eth_sign with a specific address's private key
84
92
  * @param address - The address of the signer to use
85
93
  * @param message - The message to sign
94
+ * @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
86
95
  * @returns signature for the specified address
87
96
  * @throws Error if the address is not found in the keystore
88
97
  */
89
- public signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature> {
98
+ public signMessageWithAddress(address: EthAddress, message: Buffer32, _context: SigningContext): Promise<Signature> {
90
99
  const signer = this.signersByAddress.get(address.toString());
91
100
  if (!signer) {
92
101
  throw new Error(`No signer found for address ${address.toString()}`);
@@ -6,6 +6,7 @@ import { KeystoreManager, loadKeystoreFile } from '@aztec/node-keystore';
6
6
  import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
7
7
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
8
8
  import { InvalidValidatorPrivateKeyError } from '@aztec/stdlib/validators';
9
+ import type { SigningContext } from '@aztec/validator-ha-signer/types';
9
10
 
10
11
  import type { TypedDataDefinition } from 'viem';
11
12
  import { privateKeyToAccount } from 'viem/accounts';
@@ -230,9 +231,10 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
230
231
  /**
231
232
  * Sign typed data with all attester signers across validators.
232
233
  * @param typedData EIP-712 typed data
234
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
233
235
  * @returns Array of signatures in validator order, flattened
234
236
  */
235
- async signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
237
+ async signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
236
238
  const jobs: Promise<Signature>[] = [];
237
239
  for (const i of this.validatorIndices()) {
238
240
  const v = this.ensureValidator(i);
@@ -246,9 +248,10 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
246
248
  /**
247
249
  * Sign a message with all attester signers across validators.
248
250
  * @param message 32-byte message (already hashed/padded as needed)
251
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
249
252
  * @returns Array of signatures in validator order, flattened
250
253
  */
251
- async signMessage(message: Buffer32): Promise<Signature[]> {
254
+ async signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
252
255
  const jobs: Promise<Signature>[] = [];
253
256
  for (const i of this.validatorIndices()) {
254
257
  const v = this.ensureValidator(i);
@@ -264,10 +267,15 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
264
267
  * Hydrates caches on-demand when the address is first seen.
265
268
  * @param address Address to sign with
266
269
  * @param typedData EIP-712 typed data
270
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
267
271
  * @returns Signature from the signer matching the address
268
272
  * @throws Error when no signer exists for the address
269
273
  */
270
- async signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature> {
274
+ async signTypedDataWithAddress(
275
+ address: EthAddress,
276
+ typedData: TypedDataDefinition,
277
+ _context: SigningContext,
278
+ ): Promise<Signature> {
271
279
  const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
272
280
  if (entry) {
273
281
  return await this.keystoreManager.signTypedData(entry.signer, typedData);
@@ -290,10 +298,11 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
290
298
  * Hydrates caches on-demand when the address is first seen.
291
299
  * @param address Address to sign with
292
300
  * @param message 32-byte message
301
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
293
302
  * @returns Signature from the signer matching the address
294
303
  * @throws Error when no signer exists for the address
295
304
  */
296
- async signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature> {
305
+ async signMessageWithAddress(address: EthAddress, message: Buffer32, _context: SigningContext): Promise<Signature> {
297
306
  const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
298
307
  if (entry) {
299
308
  return await this.keystoreManager.signMessage(entry.signer, message);
@@ -372,4 +381,18 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
372
381
  const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
373
382
  return this.keystoreManager.getEffectiveRemoteSignerConfig(validatorIndex, attesterAddress);
374
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
+ }
375
398
  }