@aztec-labs/validator-client 6.0.0-nightly.20260829

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +327 -0
  2. package/dest/checkpoint_builder.d.ts +92 -0
  3. package/dest/checkpoint_builder.d.ts.map +1 -0
  4. package/dest/checkpoint_builder.js +272 -0
  5. package/dest/config.d.ts +17 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/config.js +102 -0
  8. package/dest/duties/validation_service.d.ts +65 -0
  9. package/dest/duties/validation_service.d.ts.map +1 -0
  10. package/dest/duties/validation_service.js +128 -0
  11. package/dest/factory.d.ts +41 -0
  12. package/dest/factory.d.ts.map +1 -0
  13. package/dest/factory.js +19 -0
  14. package/dest/index.d.ts +7 -0
  15. package/dest/index.d.ts.map +1 -0
  16. package/dest/index.js +6 -0
  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 +6 -0
  21. package/dest/key_store/index.d.ts.map +1 -0
  22. package/dest/key_store/index.js +5 -0
  23. package/dest/key_store/interface.d.ts +104 -0
  24. package/dest/key_store/interface.d.ts.map +1 -0
  25. package/dest/key_store/interface.js +4 -0
  26. package/dest/key_store/local_key_store.d.ts +63 -0
  27. package/dest/key_store/local_key_store.d.ts.map +1 -0
  28. package/dest/key_store/local_key_store.js +83 -0
  29. package/dest/key_store/node_keystore_adapter.d.ts +151 -0
  30. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -0
  31. package/dest/key_store/node_keystore_adapter.js +330 -0
  32. package/dest/key_store/web3signer_key_store.d.ts +74 -0
  33. package/dest/key_store/web3signer_key_store.d.ts.map +1 -0
  34. package/dest/key_store/web3signer_key_store.js +147 -0
  35. package/dest/metrics.d.ts +31 -0
  36. package/dest/metrics.d.ts.map +1 -0
  37. package/dest/metrics.js +101 -0
  38. package/dest/proposal_handler.d.ts +188 -0
  39. package/dest/proposal_handler.d.ts.map +1 -0
  40. package/dest/proposal_handler.js +1438 -0
  41. package/dest/streaming_inbox_checks.d.ts +103 -0
  42. package/dest/streaming_inbox_checks.d.ts.map +1 -0
  43. package/dest/streaming_inbox_checks.js +112 -0
  44. package/dest/validator.d.ts +137 -0
  45. package/dest/validator.d.ts.map +1 -0
  46. package/dest/validator.js +771 -0
  47. package/package.json +110 -0
  48. package/src/checkpoint_builder.ts +449 -0
  49. package/src/config.ts +130 -0
  50. package/src/duties/validation_service.ts +224 -0
  51. package/src/factory.ts +95 -0
  52. package/src/index.ts +6 -0
  53. package/src/key_store/ha_key_store.ts +268 -0
  54. package/src/key_store/index.ts +5 -0
  55. package/src/key_store/interface.ts +120 -0
  56. package/src/key_store/local_key_store.ts +104 -0
  57. package/src/key_store/node_keystore_adapter.ts +397 -0
  58. package/src/key_store/web3signer_key_store.ts +188 -0
  59. package/src/metrics.ts +150 -0
  60. package/src/proposal_handler.ts +1598 -0
  61. package/src/streaming_inbox_checks.ts +198 -0
  62. package/src/validator.ts +1125 -0
@@ -0,0 +1,224 @@
1
+ import { type CheckpointNumber, IndexWithinCheckpoint, type SlotNumber } from '@aztec-labs/foundation/branded-types';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import type { EthAddress } from '@aztec-labs/foundation/eth-address';
4
+ import type { Signature } from '@aztec-labs/foundation/eth-signature';
5
+ import { createLogger } from '@aztec-labs/foundation/log';
6
+ import { CommitteeAttestationsAndSigners } from '@aztec-labs/stdlib/block';
7
+ import type { InboxBucketRef } from '@aztec-labs/stdlib/messaging';
8
+ import {
9
+ BlockProposal,
10
+ type BlockProposalOptions,
11
+ CheckpointAttestation,
12
+ CheckpointProposal,
13
+ type CheckpointProposalCore,
14
+ type CheckpointProposalOptions,
15
+ ConsensusPayload,
16
+ type CoordinationSignatureContext,
17
+ getCoordinationSignatureTypedData,
18
+ } from '@aztec-labs/stdlib/p2p';
19
+ import { CheckpointHeader } from '@aztec-labs/stdlib/rollup';
20
+ import type { BlockHeader, Tx } from '@aztec-labs/stdlib/tx';
21
+ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec-labs/validator-ha-signer/errors';
22
+ import { DutyType, type SigningContext } from '@aztec-labs/validator-ha-signer/types';
23
+
24
+ import type { ValidatorKeyStore } from '../key_store/interface.js';
25
+
26
+ export class ValidationService {
27
+ constructor(
28
+ private keyStore: ValidatorKeyStore,
29
+ private signatureContext: CoordinationSignatureContext,
30
+ private log = createLogger('validator:validation-service'),
31
+ ) {}
32
+
33
+ /**
34
+ * Create a block proposal with the given header, archive, and transactions
35
+ *
36
+ * @param blockHeader - The block header
37
+ * @param blockIndexWithinCheckpoint - The block index within checkpoint for HA signing context
38
+ * @param archive - The archive of the current block
39
+ * @param txs - Ordered list of transactions (Tx[])
40
+ * @param proposerAttesterAddress - The address of the proposer/attester, or undefined
41
+ * @param options - Block proposal options (including broadcastInvalidBlockProposal for testing)
42
+ *
43
+ * @returns A block proposal signing the above information
44
+ * @throws DutyAlreadySignedError if HA signer indicates duty already signed by another node
45
+ * @throws SlashingProtectionError if attempting to sign different data for same slot
46
+ */
47
+ public createBlockProposal(
48
+ blockHeader: BlockHeader,
49
+ checkpointNumber: CheckpointNumber,
50
+ blockIndexWithinCheckpoint: IndexWithinCheckpoint,
51
+ archive: Fr,
52
+ txs: Tx[],
53
+ proposerAttesterAddress: EthAddress | undefined,
54
+ options: BlockProposalOptions,
55
+ bucketRef?: InboxBucketRef,
56
+ ): Promise<BlockProposal> {
57
+ // For testing: change the new archive to trigger state_mismatch validation failure
58
+ if (options.broadcastInvalidBlockProposal) {
59
+ archive = Fr.random();
60
+ this.log.warn(`Creating INVALID block proposal for slot ${blockHeader.globalVariables.slotNumber}`);
61
+ }
62
+
63
+ // Create a signer that uses the appropriate address
64
+ const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
65
+ const payloadSigner = (
66
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
67
+ context: SigningContext,
68
+ ) => this.keyStore.signTypedDataWithAddress(address, typedData, context);
69
+ const txsSigner = (
70
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
71
+ context: SigningContext,
72
+ ) => this.keyStore.signTypedDataWithAddress(address, typedData, context);
73
+
74
+ return BlockProposal.createProposalFromSigner(
75
+ blockHeader,
76
+ checkpointNumber,
77
+ blockIndexWithinCheckpoint,
78
+ archive,
79
+ txs.map(tx => tx.getTxHash()),
80
+ options.publishFullTxs ? txs : undefined,
81
+ this.signatureContext,
82
+ payloadSigner,
83
+ txsSigner,
84
+ bucketRef,
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Create a checkpoint proposal with the last block header and checkpoint header
90
+ *
91
+ * @param checkpointHeader - The checkpoint header containing aggregated data
92
+ * @param archive - The archive of the checkpoint
93
+ * @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
94
+ * @param proposerAttesterAddress - The address of the proposer
95
+ * @param options - Checkpoint proposal options
96
+ *
97
+ * @returns A checkpoint proposal signing the above information
98
+ */
99
+ public createCheckpointProposal(
100
+ checkpointHeader: CheckpointHeader,
101
+ archive: Fr,
102
+ checkpointNumber: CheckpointNumber,
103
+ feeAssetPriceModifier: bigint,
104
+ lastBlockProposal: BlockProposal | undefined,
105
+ proposerAttesterAddress: EthAddress | undefined,
106
+ options: CheckpointProposalOptions,
107
+ ): Promise<CheckpointProposal> {
108
+ // For testing: corrupt the checkpoint so observers' checkpoint validation fails.
109
+ //
110
+ // Keep `archive` aligned with `lastBlockProposal.archiveRoot` so the archive-based lookup
111
+ // in `validateCheckpointProposal` (`getBlockData({ archive })`) still succeeds
112
+ if (options.broadcastInvalidCheckpointProposal) {
113
+ archive = lastBlockProposal?.archiveRoot ?? Fr.random();
114
+ checkpointHeader = CheckpointHeader.from({
115
+ ...checkpointHeader,
116
+ epochOutHash: Fr.random(),
117
+ });
118
+ this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
119
+ }
120
+
121
+ // Create a signer that takes payload and context, and uses the appropriate address
122
+ const payloadSigner = (
123
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
124
+ context: SigningContext,
125
+ ) => {
126
+ const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
127
+ return this.keyStore.signTypedDataWithAddress(address, typedData, context);
128
+ };
129
+
130
+ return CheckpointProposal.createProposalFromSigner(
131
+ checkpointHeader,
132
+ archive,
133
+ checkpointNumber,
134
+ feeAssetPriceModifier,
135
+ lastBlockProposal,
136
+ this.signatureContext,
137
+ payloadSigner,
138
+ );
139
+ }
140
+
141
+ /**
142
+ * Attest with selection of validators to the given checkpoint proposal
143
+ *
144
+ * NOTE: This is just a blind signing.
145
+ * We assume that the proposal is valid and DA guarantees have been checked previously.
146
+ *
147
+ * @param proposal - The checkpoint proposal (core version without lastBlock) to attest to
148
+ * @param attestors - The validators to attest with
149
+ * @returns checkpoint attestations
150
+ */
151
+ async attestToCheckpointProposal(
152
+ proposal: CheckpointProposalCore,
153
+ attestors: EthAddress[],
154
+ checkpointNumber: CheckpointNumber,
155
+ ): Promise<CheckpointAttestation[]> {
156
+ // Create the attestation payload from the checkpoint proposal
157
+ const payload = new ConsensusPayload(
158
+ proposal.checkpointHeader,
159
+ proposal.archive,
160
+ proposal.feeAssetPriceModifier,
161
+ this.signatureContext,
162
+ );
163
+ const typedData = getCoordinationSignatureTypedData(payload);
164
+
165
+ const context: SigningContext = {
166
+ slot: proposal.slotNumber,
167
+ checkpointNumber,
168
+ dutyType: DutyType.ATTESTATION,
169
+ };
170
+
171
+ // Sign each attestor in parallel, catching HA errors per-attestor
172
+ const results = await Promise.allSettled(
173
+ attestors.map(async attestor => {
174
+ const sig = await this.keyStore.signTypedDataWithAddress(attestor, typedData, context);
175
+ return new CheckpointAttestation(payload, sig, proposal.signature);
176
+ }),
177
+ );
178
+
179
+ const attestations: CheckpointAttestation[] = [];
180
+ for (let i = 0; i < results.length; i++) {
181
+ const result = results[i];
182
+ if (result.status === 'fulfilled') {
183
+ attestations.push(result.value);
184
+ } else {
185
+ const error = result.reason;
186
+ if (error instanceof DutyAlreadySignedError || error instanceof SlashingProtectionError) {
187
+ this.log.verbose(
188
+ `Attestation for slot ${proposal.slotNumber} by ${attestors[i]} already signed by another High-Availability node`,
189
+ );
190
+ // Continue with remaining attestors
191
+ } else {
192
+ throw error;
193
+ }
194
+ }
195
+ }
196
+
197
+ return attestations;
198
+ }
199
+
200
+ /**
201
+ * Sign attestations and signers payload
202
+ * @param attestationsAndSigners - The attestations and signers to sign
203
+ * @param proposer - The proposer address to sign with
204
+ * @param slot - The slot number for HA signing context
205
+ * @returns signature
206
+ * @throws DutyAlreadySignedError if already signed by another HA node
207
+ * @throws SlashingProtectionError if attempting to sign different data for same slot
208
+ */
209
+ signAttestationsAndSigners(
210
+ attestationsAndSigners: CommitteeAttestationsAndSigners,
211
+ proposer: EthAddress,
212
+ slot: SlotNumber,
213
+ checkpointNumber: CheckpointNumber,
214
+ ): Promise<Signature> {
215
+ const context: SigningContext = {
216
+ slot,
217
+ checkpointNumber,
218
+ dutyType: DutyType.ATTESTATIONS_AND_SIGNERS,
219
+ };
220
+
221
+ const typedData = getCoordinationSignatureTypedData(attestationsAndSigners);
222
+ return this.keyStore.signTypedDataWithAddress(proposer, typedData, context);
223
+ }
224
+ }
package/src/factory.ts ADDED
@@ -0,0 +1,95 @@
1
+ import type { BlobClientInterface } from '@aztec-labs/blob-client/client';
2
+ import type { EpochCache } from '@aztec-labs/epoch-cache';
3
+ import type { DateProvider } from '@aztec-labs/foundation/timer';
4
+ import type { KeystoreManager } from '@aztec-labs/node-keystore';
5
+ import type { P2PClient } from '@aztec-labs/p2p';
6
+ import type { L2BlockSink, L2BlockSource } from '@aztec-labs/stdlib/block';
7
+ import type { CheckpointReexecutionTracker } from '@aztec-labs/stdlib/checkpoint';
8
+ import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec-labs/stdlib/interfaces/server';
9
+ import type { L1ToL2MessageSource } from '@aztec-labs/stdlib/messaging';
10
+ import { ConsensusTimetable } from '@aztec-labs/stdlib/timetable';
11
+ import type { TelemetryClient } from '@aztec-labs/telemetry-client';
12
+ import type { SlashingProtectionDatabase } from '@aztec-labs/validator-ha-signer/types';
13
+
14
+ import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
15
+ import { ValidatorMetrics } from './metrics.js';
16
+ import { ProposalHandler } from './proposal_handler.js';
17
+ import { ValidatorClient } from './validator.js';
18
+
19
+ export function createProposalHandler(
20
+ config: ValidatorClientFullConfig,
21
+ deps: {
22
+ checkpointsBuilder: FullNodeCheckpointsBuilder;
23
+ worldState: WorldStateSynchronizer;
24
+ blockSource: L2BlockSource & L2BlockSink;
25
+ l1ToL2MessageSource: L1ToL2MessageSource;
26
+ p2pClient: P2PClient;
27
+ epochCache: EpochCache;
28
+ blobClient: BlobClientInterface;
29
+ dateProvider: DateProvider;
30
+ telemetry: TelemetryClient;
31
+ reexecutionTracker: CheckpointReexecutionTracker;
32
+ },
33
+ ) {
34
+ const metrics = new ValidatorMetrics(deps.telemetry);
35
+ const consensusTimetable = new ConsensusTimetable({
36
+ l1Constants: deps.epochCache.getL1Constants(),
37
+ blockDuration: config.blockDurationMs / 1000,
38
+ });
39
+ return new ProposalHandler(
40
+ deps.checkpointsBuilder,
41
+ deps.worldState,
42
+ deps.blockSource,
43
+ deps.l1ToL2MessageSource,
44
+ deps.p2pClient.getTxProvider(),
45
+ deps.epochCache,
46
+ consensusTimetable,
47
+ config,
48
+ deps.blobClient,
49
+ deps.reexecutionTracker,
50
+ metrics,
51
+ deps.dateProvider,
52
+ deps.telemetry,
53
+ undefined,
54
+ );
55
+ }
56
+
57
+ export function createValidatorClient(
58
+ config: ValidatorClientFullConfig,
59
+ deps: {
60
+ checkpointsBuilder: FullNodeCheckpointsBuilder;
61
+ worldState: WorldStateSynchronizer;
62
+ p2pClient: P2PClient;
63
+ blockSource: L2BlockSource & L2BlockSink;
64
+ l1ToL2MessageSource: L1ToL2MessageSource;
65
+ telemetry: TelemetryClient;
66
+ dateProvider: DateProvider;
67
+ epochCache: EpochCache;
68
+ keyStoreManager: KeystoreManager | undefined;
69
+ blobClient: BlobClientInterface;
70
+ reexecutionTracker: CheckpointReexecutionTracker;
71
+ slashingProtectionDb?: SlashingProtectionDatabase;
72
+ },
73
+ ) {
74
+ if (config.disableValidator || !deps.keyStoreManager) {
75
+ return undefined;
76
+ }
77
+
78
+ const txProvider = deps.p2pClient.getTxProvider();
79
+ return ValidatorClient.new(
80
+ config,
81
+ deps.checkpointsBuilder,
82
+ deps.worldState,
83
+ deps.epochCache,
84
+ deps.p2pClient,
85
+ deps.blockSource,
86
+ deps.l1ToL2MessageSource,
87
+ txProvider,
88
+ deps.keyStoreManager,
89
+ deps.blobClient,
90
+ deps.reexecutionTracker,
91
+ deps.dateProvider,
92
+ deps.telemetry,
93
+ deps.slashingProtectionDb,
94
+ );
95
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './proposal_handler.js';
2
+ export * from './checkpoint_builder.js';
3
+ export * from './config.js';
4
+ export * from './factory.js';
5
+ export * from './validator.js';
6
+ export * from './key_store/index.js';
@@ -0,0 +1,268 @@
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-labs/foundation/buffer';
8
+ import type { EthAddress } from '@aztec-labs/foundation/eth-address';
9
+ import type { Signature } from '@aztec-labs/foundation/eth-signature';
10
+ import { createLogger } from '@aztec-labs/foundation/log';
11
+ import type { EthRemoteSignerConfig } from '@aztec-labs/node-keystore';
12
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
13
+ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec-labs/validator-ha-signer/errors';
14
+ import {
15
+ type HAProtectedSigningContext,
16
+ type SigningContext,
17
+ isHAProtectedContext,
18
+ } from '@aztec-labs/validator-ha-signer/types';
19
+ import type { ValidatorHASigner } from '@aztec-labs/validator-ha-signer/validator-ha-signer';
20
+ import { type TypedDataDefinition, hashTypedData } from 'viem';
21
+
22
+ import type { ExtendedValidatorKeyStore } from './interface.js';
23
+
24
+ /**
25
+ * High Availability Key Store
26
+ *
27
+ * Wraps a base ExtendedValidatorKeyStore and ValidatorHASigner to provide
28
+ * HA-protected signing operations (when context is provided).
29
+ *
30
+ * The extended interface methods (getAttesterAddresses, getCoinbaseAddress, etc.)
31
+ * are pure pass-through since they don't require HA coordination.
32
+ *
33
+ * Usage:
34
+ * ```typescript
35
+ * const baseKeyStore = NodeKeystoreAdapter.fromPrivateKeys(privateKeys);
36
+ * const haSigner = new ValidatorHASigner(db, config);
37
+ * const haKeyStore = new HAKeyStore(baseKeyStore, haSigner);
38
+ *
39
+ * // Without context - signs directly (no HA protection)
40
+ * const sig = await haKeyStore.signMessageWithAddress(addr, msg);
41
+ *
42
+ * // With context - HA protected, throws DutyAlreadySignedError if already signed
43
+ * const result = await haKeyStore.signMessageWithAddress(addr, msg, {
44
+ * slot: 100n,
45
+ * blockNumber: 50n,
46
+ * dutyType: DutyType.BLOCK_PROPOSAL,
47
+ * });
48
+ * ```
49
+ */
50
+ export class HAKeyStore implements ExtendedValidatorKeyStore {
51
+ private readonly log = createLogger('ha-key-store');
52
+
53
+ constructor(
54
+ private readonly baseKeyStore: ExtendedValidatorKeyStore,
55
+ private readonly haSigner: ValidatorHASigner,
56
+ ) {
57
+ this.log.info('HAKeyStore initialized', {
58
+ nodeId: haSigner.nodeId,
59
+ });
60
+ }
61
+
62
+ /**
63
+ * Sign typed data with all addresses.
64
+ * Coordinates across nodes to prevent double-signing for most duty types.
65
+ * AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
66
+ * Returns only signatures that were successfully claimed by this node.
67
+ */
68
+ async signTypedData(typedData: TypedDataDefinition, context: SigningContext): Promise<Signature[]> {
69
+ // no need for HA protection on auth request and txs signatures
70
+ if (!isHAProtectedContext(context)) {
71
+ return this.baseKeyStore.signTypedData(typedData, context);
72
+ }
73
+
74
+ // Sign each address with HA protection
75
+ const addresses = this.getAddresses();
76
+ const results = await Promise.allSettled(
77
+ addresses.map(addr => this.signTypedDataWithAddress(addr, typedData, context)),
78
+ );
79
+
80
+ // Filter out failures (already signed by other nodes or other errors)
81
+ return results
82
+ .filter((result): result is PromiseFulfilledResult<Signature> => {
83
+ if (result.status === 'fulfilled') {
84
+ return true;
85
+ }
86
+ // Log expected HA errors (already signed) at debug level
87
+ if (result.reason instanceof DutyAlreadySignedError) {
88
+ this.log.debug(`Duty already signed by another node`, {
89
+ dutyType: context.dutyType,
90
+ slot: context.slot,
91
+ signedByNode: result.reason.signedByNode,
92
+ });
93
+ return false;
94
+ }
95
+ // Re-throw unexpected errors
96
+ throw result.reason;
97
+ })
98
+ .map(result => result.value);
99
+ }
100
+
101
+ /**
102
+ * Sign a message with all addresses.
103
+ * Coordinates across nodes to prevent double-signing for most duty types.
104
+ * AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
105
+ * Returns only signatures that were successfully claimed by this node.
106
+ */
107
+ async signMessage(message: Buffer32, context: SigningContext): Promise<Signature[]> {
108
+ // no need for HA protection on auth request and txs signatures
109
+ if (!isHAProtectedContext(context)) {
110
+ return this.baseKeyStore.signMessage(message, context);
111
+ }
112
+
113
+ // Sign each address with HA protection
114
+ const addresses = this.getAddresses();
115
+ const results = await Promise.allSettled(
116
+ addresses.map(addr => this.signMessageWithAddress(addr, message, context)),
117
+ );
118
+
119
+ // Filter out failures (already signed by other nodes or other errors)
120
+ return results
121
+ .filter((result): result is PromiseFulfilledResult<Signature> => {
122
+ if (result.status === 'fulfilled') {
123
+ return true;
124
+ }
125
+ // Log expected HA errors (already signed) at debug level
126
+ if (result.reason instanceof DutyAlreadySignedError) {
127
+ this.log.debug(`Duty already signed by another node`, {
128
+ dutyType: context.dutyType,
129
+ slot: context.slot,
130
+ signedByNode: result.reason.signedByNode,
131
+ });
132
+ return false;
133
+ }
134
+ // Re-throw unexpected errors
135
+ throw result.reason;
136
+ })
137
+ .map(result => result.value);
138
+ }
139
+
140
+ /**
141
+ * Sign typed data with a specific address.
142
+ * Coordinates across nodes to prevent double-signing for most duty types.
143
+ * AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
144
+ * @throws DutyAlreadySignedError if the duty was already signed by another node
145
+ * @throws SlashingProtectionError if attempting to sign different data for the same slot
146
+ */
147
+ async signTypedDataWithAddress(
148
+ address: EthAddress,
149
+ typedData: TypedDataDefinition,
150
+ context: SigningContext,
151
+ ): Promise<Signature> {
152
+ // AUTH_REQUEST and TXS bypass HA protection - multiple signatures are safe
153
+ if (!isHAProtectedContext(context)) {
154
+ return this.baseKeyStore.signTypedDataWithAddress(address, typedData, context);
155
+ }
156
+
157
+ // Compute signing root from typed data for HA tracking
158
+ const digest = hashTypedData(typedData);
159
+ const messageHash = Buffer32.fromString(digest);
160
+
161
+ try {
162
+ return await this.haSigner.signWithProtection(address, messageHash, context, () =>
163
+ this.baseKeyStore.signTypedDataWithAddress(address, typedData, context),
164
+ );
165
+ } catch (error) {
166
+ this.processSigningError(error, context);
167
+ throw error;
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Sign a message with a specific address.
173
+ * Coordinates across nodes to prevent double-signing for most duty types.
174
+ * AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
175
+ * @throws DutyAlreadySignedError if the duty was already signed by another node
176
+ * @throws SlashingProtectionError if attempting to sign different data for the same slot
177
+ */
178
+ async signMessageWithAddress(address: EthAddress, message: Buffer32, context: SigningContext): Promise<Signature> {
179
+ // no need for HA protection on auth request and txs signatures
180
+ if (!isHAProtectedContext(context)) {
181
+ return this.baseKeyStore.signMessageWithAddress(address, message, context);
182
+ }
183
+
184
+ try {
185
+ return await this.haSigner.signWithProtection(address, message, context, messageHash =>
186
+ this.baseKeyStore.signMessageWithAddress(address, messageHash, context),
187
+ );
188
+ } catch (error) {
189
+ this.processSigningError(error, context);
190
+ throw error;
191
+ }
192
+ }
193
+
194
+ // ─────────────────────────────────────────────────────────────────────────────
195
+ // pass-through methods (no HA logic needed)
196
+ // ─────────────────────────────────────────────────────────────────────────────
197
+
198
+ getAddress(index: number): EthAddress {
199
+ return this.baseKeyStore.getAddress(index);
200
+ }
201
+
202
+ getAddresses(): EthAddress[] {
203
+ return this.baseKeyStore.getAddresses();
204
+ }
205
+
206
+ getAttesterAddresses(): EthAddress[] {
207
+ return this.baseKeyStore.getAttesterAddresses();
208
+ }
209
+
210
+ getCoinbaseAddress(attesterAddress: EthAddress): EthAddress {
211
+ return this.baseKeyStore.getCoinbaseAddress(attesterAddress);
212
+ }
213
+
214
+ getPublisherAddresses(attesterAddress: EthAddress): EthAddress[] {
215
+ return this.baseKeyStore.getPublisherAddresses(attesterAddress);
216
+ }
217
+
218
+ getFeeRecipient(attesterAddress: EthAddress): AztecAddress {
219
+ return this.baseKeyStore.getFeeRecipient(attesterAddress);
220
+ }
221
+
222
+ getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined {
223
+ return this.baseKeyStore.getRemoteSignerConfig(attesterAddress);
224
+ }
225
+
226
+ /**
227
+ * Process signing errors from the HA signer.
228
+ * Logs expected HA errors (already signed) at appropriate levels.
229
+ * Re-throws unexpected errors.
230
+ */
231
+ private processSigningError(error: unknown, context: HAProtectedSigningContext) {
232
+ if (error instanceof DutyAlreadySignedError) {
233
+ this.log.debug(`Duty already signed by another node with the same payload`, {
234
+ dutyType: context.dutyType,
235
+ slot: context.slot,
236
+ signedByNode: error.signedByNode,
237
+ });
238
+ return;
239
+ }
240
+
241
+ if (error instanceof SlashingProtectionError) {
242
+ this.log.info(`Duty already signed by another node with different payload`, {
243
+ dutyType: context.dutyType,
244
+ slot: context.slot,
245
+ existingMessageHash: error.existingMessageHash,
246
+ attemptedMessageHash: error.attemptedMessageHash,
247
+ });
248
+ return;
249
+ }
250
+
251
+ // Re-throw errors
252
+ throw error;
253
+ }
254
+
255
+ /**
256
+ * Start the high-availability key store
257
+ */
258
+ public async start() {
259
+ await this.haSigner.start();
260
+ }
261
+
262
+ /**
263
+ * Stop the high-availability key store
264
+ */
265
+ public async stop() {
266
+ await this.haSigner.stop();
267
+ }
268
+ }
@@ -0,0 +1,5 @@
1
+ export * from './interface.js';
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';