@aztec/validator-client 0.0.1-commit.993d240 → 0.0.1-commit.9a89641

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.
@@ -8,6 +8,9 @@ import type { TypedDataDefinition } from 'viem';
8
8
 
9
9
  import type { ValidatorKeyStore } from './interface.js';
10
10
 
11
+ /** Default hard timeout (ms) applied to each Web3Signer HTTP request. */
12
+ const DEFAULT_WEB3SIGNER_REQUEST_TIMEOUT_MS = 30_000;
13
+
11
14
  /**
12
15
  * Web3Signer Key Store
13
16
  *
@@ -15,10 +18,15 @@ import type { ValidatorKeyStore } from './interface.js';
15
18
  * This implementation uses the Web3Signer JSON-RPC API for secp256k1 signatures.
16
19
  */
17
20
  export class Web3SignerKeyStore implements ValidatorKeyStore {
21
+ private readonly requestTimeoutMs: number;
22
+
18
23
  constructor(
19
24
  private addresses: EthAddress[],
20
25
  private baseUrl: string,
21
- ) {}
26
+ requestTimeoutMs: number = DEFAULT_WEB3SIGNER_REQUEST_TIMEOUT_MS,
27
+ ) {
28
+ this.requestTimeoutMs = requestTimeoutMs;
29
+ }
22
30
 
23
31
  /**
24
32
  * Get the address of a signer by index
@@ -108,75 +116,50 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
108
116
  * @param data - The data to sign
109
117
  * @returns The signature
110
118
  */
111
- private async makeJsonRpcSignRequest(address: EthAddress, data: Buffer32): Promise<Signature> {
112
- const url = this.baseUrl;
113
-
114
- // Use JSON-RPC eth_sign method which automatically applies Ethereum message prefixing
115
- const body = {
119
+ private makeJsonRpcSignRequest(address: EthAddress, data: Buffer32): Promise<Signature> {
120
+ // eth_sign automatically applies Ethereum message prefixing to the raw data.
121
+ return this.sendSignRequest({
116
122
  jsonrpc: '2.0',
117
123
  method: 'eth_sign',
118
- params: [
119
- address.toString(), // Ethereum address as identifier
120
- data.toString(), // Raw data to sign (eth_sign will apply Ethereum message prefix)
121
- ],
124
+ params: [address.toString(), data.toString()],
122
125
  id: 1,
123
- };
124
-
125
- const response = await fetch(url, {
126
- method: 'POST',
127
- headers: {
128
- 'Content-Type': 'application/json',
129
- },
130
- body: JSON.stringify(body),
131
126
  });
132
-
133
- if (!response.ok) {
134
- const errorText = await response.text();
135
- throw new Error(`Web3Signer request failed: ${response.status} ${response.statusText} - ${errorText}`);
136
- }
137
-
138
- const result = await response.json();
139
-
140
- // Handle JSON-RPC response format
141
- if (result.error) {
142
- throw new Error(`Web3Signer JSON-RPC error: ${result.error.code} - ${result.error.message}`);
143
- }
144
-
145
- if (!result.result) {
146
- throw new Error('Invalid response from Web3Signer: no result found');
147
- }
148
-
149
- let signatureHex = result.result;
150
-
151
- // Ensure the signature has the 0x prefix
152
- if (!signatureHex.startsWith('0x')) {
153
- signatureHex = '0x' + signatureHex;
154
- }
155
-
156
- // Parse the signature from the hex string
157
- return normalizeSignature(Signature.fromString(signatureHex as `0x${string}`));
158
127
  }
159
128
 
160
- private async makeJsonRpcSignTypedDataRequest(
161
- address: EthAddress,
162
- typedData: TypedDataDefinition,
163
- ): Promise<Signature> {
164
- const url = this.baseUrl;
165
-
166
- const body = {
129
+ private makeJsonRpcSignTypedDataRequest(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature> {
130
+ return this.sendSignRequest({
167
131
  jsonrpc: '2.0',
168
132
  method: 'eth_signTypedData',
169
133
  params: [address.toString(), JSON.stringify(typedData)],
170
134
  id: 1,
171
- };
172
-
173
- const response = await fetch(url, {
174
- method: 'POST',
175
- headers: {
176
- 'Content-Type': 'application/json',
177
- },
178
- body: JSON.stringify(body),
179
135
  });
136
+ }
137
+
138
+ /**
139
+ * Send a JSON-RPC request to Web3Signer under a hard request timeout and parse the signature.
140
+ * A timed-out or aborted request is surfaced as a clear timeout error rather than hanging, so a
141
+ * slow or unreachable signer cannot stall an HA signing operation past its own timeout budget.
142
+ */
143
+ private async sendSignRequest(body: object): Promise<Signature> {
144
+ let response: Response;
145
+ try {
146
+ response = await fetch(this.baseUrl, {
147
+ method: 'POST',
148
+ headers: {
149
+ 'Content-Type': 'application/json',
150
+ },
151
+ body: JSON.stringify(body),
152
+ signal: AbortSignal.timeout(this.requestTimeoutMs),
153
+ });
154
+ } catch (err) {
155
+ if (
156
+ (err instanceof Error || err instanceof DOMException) &&
157
+ (err.name === 'TimeoutError' || err.name === 'AbortError')
158
+ ) {
159
+ throw new Error(`Web3Signer request timed out after ${this.requestTimeoutMs}ms`);
160
+ }
161
+ throw err;
162
+ }
180
163
 
181
164
  if (!response.ok) {
182
165
  const errorText = await response.text();
@@ -185,6 +168,7 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
185
168
 
186
169
  const result = await response.json();
187
170
 
171
+ // Handle JSON-RPC response format
188
172
  if (result.error) {
189
173
  throw new Error(`Web3Signer JSON-RPC error: ${result.error.code} - ${result.error.message}`);
190
174
  }
package/src/metrics.ts CHANGED
@@ -49,6 +49,8 @@ export class ValidatorMetrics {
49
49
  'failed_txs',
50
50
  'in_hash_mismatch',
51
51
  'parent_block_wrong_slot',
52
+ 'duplicate_txs',
53
+ 'invalid_embedded_txs',
52
54
  ],
53
55
  [Attributes.IS_COMMITTEE_MEMBER]: [true, false],
54
56
  },