@aztec/foundation 0.71.0 → 0.72.1
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.
- package/dest/abi/decoder.d.ts +1 -1
- package/dest/abi/decoder.d.ts.map +1 -1
- package/dest/abi/decoder.js +11 -2
- package/dest/abi/encoder.d.ts.map +1 -1
- package/dest/abi/encoder.js +12 -2
- package/dest/abi/event_selector.d.ts +1 -2
- package/dest/abi/event_selector.d.ts.map +1 -1
- package/dest/abi/event_selector.js +2 -3
- package/dest/abi/function_selector.d.ts +1 -2
- package/dest/abi/function_selector.d.ts.map +1 -1
- package/dest/abi/function_selector.js +2 -3
- package/dest/abi/index.d.ts +1 -0
- package/dest/abi/index.d.ts.map +1 -1
- package/dest/abi/index.js +2 -1
- package/dest/abi/u128.d.ts +13 -0
- package/dest/abi/u128.d.ts.map +1 -0
- package/dest/abi/u128.js +58 -0
- package/dest/abi/utils.d.ts +5 -0
- package/dest/abi/utils.d.ts.map +1 -1
- package/dest/abi/utils.js +8 -1
- package/dest/array/array.d.ts +8 -0
- package/dest/array/array.d.ts.map +1 -1
- package/dest/array/array.js +13 -1
- package/dest/aztec-address/index.d.ts +3 -3
- package/dest/aztec-address/index.d.ts.map +1 -1
- package/dest/aztec-address/index.js +5 -5
- package/dest/collection/array.d.ts +7 -0
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +13 -1
- package/dest/config/env_var.d.ts +1 -1
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/fields/fields.d.ts +10 -1
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +19 -10
- package/dest/fields/point.d.ts +4 -4
- package/dest/fields/point.d.ts.map +1 -1
- package/dest/fields/point.js +5 -5
- package/dest/json-rpc/client/fetch.d.ts +2 -2
- package/dest/json-rpc/client/fetch.d.ts.map +1 -1
- package/dest/json-rpc/client/fetch.js +7 -7
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +17 -5
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.js +16 -9
- package/dest/json-rpc/server/telemetry.d.ts +2 -0
- package/dest/json-rpc/server/telemetry.d.ts.map +1 -0
- package/dest/json-rpc/server/telemetry.js +2 -0
- package/dest/testing/files/index.d.ts +1 -1
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +3 -3
- package/dest/timer/timeout.js +2 -2
- package/package.json +3 -3
- package/src/abi/decoder.ts +11 -2
- package/src/abi/encoder.ts +11 -1
- package/src/abi/event_selector.ts +1 -2
- package/src/abi/function_selector.ts +1 -2
- package/src/abi/index.ts +1 -0
- package/src/abi/u128.ts +71 -0
- package/src/abi/utils.ts +8 -0
- package/src/array/array.ts +15 -0
- package/src/aztec-address/index.ts +5 -5
- package/src/collection/array.ts +15 -0
- package/src/config/env_var.ts +1 -1
- package/src/fields/fields.ts +19 -10
- package/src/fields/point.ts +6 -6
- package/src/json-rpc/client/fetch.ts +14 -6
- package/src/json-rpc/client/safe_json_rpc_client.ts +0 -1
- package/src/json-rpc/server/safe_json_rpc_server.ts +27 -11
- package/src/json-rpc/server/telemetry.ts +0 -0
- package/src/testing/files/index.ts +2 -2
- package/src/timer/timeout.ts +1 -1
|
@@ -21,6 +21,7 @@ export async function defaultFetch(
|
|
|
21
21
|
rpcMethod: string,
|
|
22
22
|
body: any,
|
|
23
23
|
useApiEndpoints: boolean,
|
|
24
|
+
extraHeaders: Record<string, string> = {},
|
|
24
25
|
noRetry = false,
|
|
25
26
|
) {
|
|
26
27
|
log.debug(format(`JsonRpcClient.fetch`, host, rpcMethod, '->', body));
|
|
@@ -30,13 +31,13 @@ export async function defaultFetch(
|
|
|
30
31
|
resp = await fetch(`${host}/${rpcMethod}`, {
|
|
31
32
|
method: 'POST',
|
|
32
33
|
body: jsonStringify(body),
|
|
33
|
-
headers: { 'content-type': 'application/json' },
|
|
34
|
+
headers: { 'content-type': 'application/json', ...extraHeaders },
|
|
34
35
|
});
|
|
35
36
|
} else {
|
|
36
37
|
resp = await fetch(host, {
|
|
37
38
|
method: 'POST',
|
|
38
39
|
body: jsonStringify({ ...body, method: rpcMethod }),
|
|
39
|
-
headers: { 'content-type': 'application/json' },
|
|
40
|
+
headers: { 'content-type': 'application/json', ...extraHeaders },
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
43
|
} catch (err) {
|
|
@@ -55,7 +56,7 @@ export async function defaultFetch(
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
if (!resp.ok) {
|
|
58
|
-
const errorMessage = `
|
|
59
|
+
const errorMessage = `Error ${resp.status} from server ${host} on ${rpcMethod}: ${responseJson.error.message}`;
|
|
59
60
|
if (noRetry || (resp.status >= 400 && resp.status < 500)) {
|
|
60
61
|
throw new NoRetryError(errorMessage);
|
|
61
62
|
} else {
|
|
@@ -73,10 +74,17 @@ export async function defaultFetch(
|
|
|
73
74
|
* @param log - Optional logger for logging attempts.
|
|
74
75
|
* @returns A fetch function.
|
|
75
76
|
*/
|
|
76
|
-
export function makeFetch(retries: number[], defaultNoRetry: boolean, log?: Logger) {
|
|
77
|
-
return async (
|
|
77
|
+
export function makeFetch(retries: number[], defaultNoRetry: boolean, log?: Logger): typeof defaultFetch {
|
|
78
|
+
return async (
|
|
79
|
+
host: string,
|
|
80
|
+
rpcMethod: string,
|
|
81
|
+
body: any,
|
|
82
|
+
useApiEndpoints: boolean,
|
|
83
|
+
extraHeaders: Record<string, string> = {},
|
|
84
|
+
noRetry?: boolean,
|
|
85
|
+
) => {
|
|
78
86
|
return await retry(
|
|
79
|
-
() => defaultFetch(host, rpcMethod, body, useApiEndpoints, noRetry ?? defaultNoRetry),
|
|
87
|
+
() => defaultFetch(host, rpcMethod, body, useApiEndpoints, extraHeaders, noRetry ?? defaultNoRetry),
|
|
80
88
|
`JsonRpcClient request ${rpcMethod} to ${host}`,
|
|
81
89
|
makeBackoff(retries),
|
|
82
90
|
log,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cors from '@koa/cors';
|
|
2
2
|
import http from 'http';
|
|
3
|
-
import Koa from 'koa';
|
|
3
|
+
import { type default as Application, default as Koa } from 'koa';
|
|
4
4
|
import bodyParser from 'koa-bodyparser';
|
|
5
5
|
import compress from 'koa-compress';
|
|
6
6
|
import Router from 'koa-router';
|
|
@@ -14,6 +14,15 @@ import { type ApiSchema, type ApiSchemaFor, parseWithOptionals, schemaHasMethod
|
|
|
14
14
|
import { jsonStringify } from '../convert.js';
|
|
15
15
|
import { assert } from '../js_utils.js';
|
|
16
16
|
|
|
17
|
+
export type DiagnosticsData = {
|
|
18
|
+
id: number | string | null;
|
|
19
|
+
method: string;
|
|
20
|
+
params: any[];
|
|
21
|
+
headers: http.IncomingHttpHeaders;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type DiagnosticsMiddleware = (ctx: DiagnosticsData, next: () => Promise<void>) => Promise<void>;
|
|
25
|
+
|
|
17
26
|
export class SafeJsonRpcServer {
|
|
18
27
|
/**
|
|
19
28
|
* The HTTP server accepting remote requests.
|
|
@@ -31,6 +40,8 @@ export class SafeJsonRpcServer {
|
|
|
31
40
|
private http200OnError = false,
|
|
32
41
|
/** Health check function */
|
|
33
42
|
private readonly healthCheck: StatusCheckFn = () => true,
|
|
43
|
+
/** Additional middlewares */
|
|
44
|
+
private extraMiddlewares: Application.Middleware[] = [],
|
|
34
45
|
/** Logger */
|
|
35
46
|
private log = createLogger('json-rpc:server'),
|
|
36
47
|
) {}
|
|
@@ -90,8 +101,11 @@ export class SafeJsonRpcServer {
|
|
|
90
101
|
this.log.error(`Error on API handler: ${error}`);
|
|
91
102
|
});
|
|
92
103
|
|
|
93
|
-
app.use(compress({ br: false }
|
|
104
|
+
app.use(compress({ br: false }));
|
|
94
105
|
app.use(jsonResponse);
|
|
106
|
+
for (const middleware of this.extraMiddlewares) {
|
|
107
|
+
app.use(middleware);
|
|
108
|
+
}
|
|
95
109
|
app.use(exceptionHandler);
|
|
96
110
|
app.use(bodyParser({ jsonLimit: '50mb', enableTypes: ['json'], detectJSON: () => true }));
|
|
97
111
|
app.use(cors());
|
|
@@ -114,7 +128,9 @@ export class SafeJsonRpcServer {
|
|
|
114
128
|
// Fail if not a registered function in the proxy
|
|
115
129
|
if (typeof method !== 'string' || method === 'constructor' || !this.proxy.hasMethod(method)) {
|
|
116
130
|
ctx.status = 400;
|
|
117
|
-
|
|
131
|
+
const code = -32601;
|
|
132
|
+
const message = `Method not found: ${method}`;
|
|
133
|
+
ctx.body = { jsonrpc, id, error: { code, message } };
|
|
118
134
|
} else {
|
|
119
135
|
ctx.status = 200;
|
|
120
136
|
const result = await this.proxy.call(method, params);
|
|
@@ -263,10 +279,11 @@ function makeAggregateHealthcheck(namedHandlers: NamespacedApiHandlers, log?: Lo
|
|
|
263
279
|
};
|
|
264
280
|
}
|
|
265
281
|
|
|
266
|
-
type SafeJsonRpcServerOptions = {
|
|
282
|
+
export type SafeJsonRpcServerOptions = {
|
|
267
283
|
http200OnError: boolean;
|
|
268
284
|
healthCheck?: StatusCheckFn;
|
|
269
285
|
log?: Logger;
|
|
286
|
+
middlewares?: Application.Middleware[];
|
|
270
287
|
};
|
|
271
288
|
|
|
272
289
|
/**
|
|
@@ -276,25 +293,24 @@ type SafeJsonRpcServerOptions = {
|
|
|
276
293
|
*/
|
|
277
294
|
export function createNamespacedSafeJsonRpcServer(
|
|
278
295
|
handlers: NamespacedApiHandlers,
|
|
279
|
-
options: Omit<SafeJsonRpcServerOptions, 'healthcheck'
|
|
280
|
-
http200OnError: false,
|
|
296
|
+
options: Partial<Omit<SafeJsonRpcServerOptions, 'healthcheck'>> = {
|
|
281
297
|
log: createLogger('json-rpc:server'),
|
|
282
298
|
},
|
|
283
299
|
): SafeJsonRpcServer {
|
|
284
|
-
const { http200OnError, log } = options;
|
|
300
|
+
const { middlewares, http200OnError, log } = options;
|
|
285
301
|
const proxy = new NamespacedSafeJsonProxy(handlers);
|
|
286
302
|
const healthCheck = makeAggregateHealthcheck(handlers, log);
|
|
287
|
-
return new SafeJsonRpcServer(proxy, http200OnError, healthCheck, log);
|
|
303
|
+
return new SafeJsonRpcServer(proxy, http200OnError, healthCheck, middlewares, log);
|
|
288
304
|
}
|
|
289
305
|
|
|
290
306
|
export function createSafeJsonRpcServer<T extends object = any>(
|
|
291
307
|
handler: T,
|
|
292
308
|
schema: ApiSchemaFor<T>,
|
|
293
|
-
options: SafeJsonRpcServerOptions = {
|
|
309
|
+
options: Partial<SafeJsonRpcServerOptions> = {},
|
|
294
310
|
) {
|
|
295
|
-
const { http200OnError, log, healthCheck } = options;
|
|
311
|
+
const { http200OnError, log, healthCheck, middlewares: extraMiddlewares } = options;
|
|
296
312
|
const proxy = new SafeJsonProxy(handler, schema);
|
|
297
|
-
return new SafeJsonRpcServer(proxy, http200OnError, healthCheck, log);
|
|
313
|
+
return new SafeJsonRpcServer(proxy, http200OnError, healthCheck, extraMiddlewares, log);
|
|
298
314
|
}
|
|
299
315
|
|
|
300
316
|
/**
|
|
File without changes
|
|
@@ -6,12 +6,12 @@ import { fileURLToPath } from '../../url/index.js';
|
|
|
6
6
|
import { isGenerateTestDataEnabled } from '../test_data.js';
|
|
7
7
|
|
|
8
8
|
/** Writes the contents specified to the target file if test data generation is enabled. */
|
|
9
|
-
export function writeTestData(targetFileFromRepoRoot: string, contents: string | Buffer) {
|
|
9
|
+
export function writeTestData(targetFileFromRepoRoot: string, contents: string | Buffer, raw: boolean = false) {
|
|
10
10
|
if (!isGenerateTestDataEnabled()) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const targetFile = getPathToFile(targetFileFromRepoRoot);
|
|
14
|
-
const toWrite = typeof contents === 'string' ? contents : contents.toString('hex');
|
|
14
|
+
const toWrite = raw ? contents : typeof contents === 'string' ? contents : contents.toString('hex');
|
|
15
15
|
writeFileSync(targetFile, toWrite);
|
|
16
16
|
const logger = createConsoleLogger('aztec:testing:test_data');
|
|
17
17
|
logger(`Wrote test data to ${targetFile}`);
|
package/src/timer/timeout.ts
CHANGED
|
@@ -27,7 +27,7 @@ export class TimeoutTask<T> {
|
|
|
27
27
|
* @throws An error with a message indicating the function was interrupted due to exceeding the specified timeout.
|
|
28
28
|
*/
|
|
29
29
|
public async exec() {
|
|
30
|
-
const interruptTimeout =
|
|
30
|
+
const interruptTimeout = setTimeout(this.interrupt, this.timeout);
|
|
31
31
|
try {
|
|
32
32
|
const start = Date.now();
|
|
33
33
|
const result = await Promise.race<T>([this.fn(), this.interruptPromise]);
|