@aztec/foundation 0.7.9 → 0.8.4
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/encoder.d.ts.map +1 -1
- package/dest/abi/encoder.js +9 -5
- package/dest/abi/function_selector.js +1 -1
- 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/utils.d.ts +20 -0
- package/dest/abi/utils.d.ts.map +1 -0
- package/dest/abi/utils.js +25 -0
- package/dest/fields/coordinate.d.ts +5 -5
- package/dest/fields/coordinate.js +5 -5
- package/dest/fields/fields.d.ts +4 -0
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +9 -1
- package/dest/fifo/memory_fifo.js +2 -2
- package/dest/json-rpc/client/json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/json_rpc_client.js +8 -7
- package/dest/json-rpc/convert.d.ts.map +1 -1
- package/dest/json-rpc/convert.js +10 -9
- package/dest/json-rpc/server/json_proxy.d.ts.map +1 -1
- package/dest/json-rpc/server/json_proxy.js +5 -4
- package/dest/json-rpc/server/json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/json_rpc_server.js +52 -7
- package/dest/log/index.d.ts +4 -4
- package/dest/log/index.d.ts.map +1 -1
- package/dest/log/index.js +1 -1
- package/dest/log/logger.d.ts +7 -3
- package/dest/log/logger.d.ts.map +1 -1
- package/dest/log/logger.js +36 -16
- package/dest/timer/elapsed.d.ts +14 -0
- package/dest/timer/elapsed.d.ts.map +1 -0
- package/dest/timer/elapsed.js +22 -0
- package/dest/timer/index.d.ts +1 -0
- package/dest/timer/index.d.ts.map +1 -1
- package/dest/timer/index.js +2 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.js +3 -2
- package/dest/transport/transport_client.d.ts.map +1 -1
- package/dest/transport/transport_client.js +4 -3
- package/dest/wasm/wasm_module.js +4 -4
- package/package.json +65 -3
- package/src/abi/encoder.ts +8 -4
- package/src/abi/function_selector.ts +1 -1
- package/src/abi/index.ts +1 -0
- package/src/abi/utils.ts +28 -0
- package/src/fields/coordinate.ts +5 -5
- package/src/fields/fields.ts +10 -0
- package/src/fifo/memory_fifo.ts +1 -1
- package/src/json-rpc/client/json_rpc_client.ts +7 -6
- package/src/json-rpc/convert.ts +10 -9
- package/src/json-rpc/server/json_proxy.ts +5 -3
- package/src/json-rpc/server/json_rpc_server.ts +50 -6
- package/src/log/index.ts +5 -4
- package/src/log/logger.ts +45 -19
- package/src/timer/elapsed.ts +23 -0
- package/src/timer/index.ts +1 -0
- package/src/transport/dispatch/create_dispatch_fn.ts +3 -1
- package/src/transport/transport_client.ts +3 -2
- package/src/wasm/wasm_module.ts +3 -3
- package/.eslintrc.cjs +0 -134
- package/.prettierrc.json +0 -10
- package/.tsbuildinfo +0 -1
- package/dest/abi/decoder.test.d.ts +0 -2
- package/dest/abi/decoder.test.d.ts.map +0 -1
- package/dest/abi/decoder.test.js +0 -70
- package/dest/abi/encoder.test.d.ts +0 -2
- package/dest/abi/encoder.test.d.ts.map +0 -1
- package/dest/abi/encoder.test.js +0 -74
- package/dest/async-map/async_map.test.d.ts +0 -2
- package/dest/async-map/async_map.test.d.ts.map +0 -1
- package/dest/async-map/async_map.test.js +0 -9
- package/dest/bigint-buffer/bigint-buffer.test.d.ts +0 -2
- package/dest/bigint-buffer/bigint-buffer.test.d.ts.map +0 -1
- package/dest/bigint-buffer/bigint-buffer.test.js +0 -18
- package/dest/committable/committable.test.d.ts +0 -2
- package/dest/committable/committable.test.d.ts.map +0 -1
- package/dest/committable/committable.test.js +0 -26
- package/dest/crypto/random/index.test.d.ts +0 -2
- package/dest/crypto/random/index.test.d.ts.map +0 -1
- package/dest/crypto/random/index.test.js +0 -13
- package/dest/crypto/sha256/index.test.d.ts +0 -2
- package/dest/crypto/sha256/index.test.d.ts.map +0 -1
- package/dest/crypto/sha256/index.test.js +0 -11
- package/dest/eth-address/eth_address.test.d.ts +0 -2
- package/dest/eth-address/eth_address.test.d.ts.map +0 -1
- package/dest/eth-address/eth_address.test.js +0 -95
- package/dest/fields/coordinate.test.d.ts +0 -2
- package/dest/fields/coordinate.test.d.ts.map +0 -1
- package/dest/fields/coordinate.test.js +0 -22
- package/dest/fields/grumpkin_scalar.test.d.ts +0 -2
- package/dest/fields/grumpkin_scalar.test.d.ts.map +0 -1
- package/dest/fields/grumpkin_scalar.test.js +0 -45
- package/dest/json-rpc/client/json_rpc_client.test.d.ts +0 -2
- package/dest/json-rpc/client/json_rpc_client.test.d.ts.map +0 -1
- package/dest/json-rpc/client/json_rpc_client.test.js +0 -20
- package/dest/json-rpc/convert.test.d.ts +0 -2
- package/dest/json-rpc/convert.test.d.ts.map +0 -1
- package/dest/json-rpc/convert.test.js +0 -68
- package/dest/json-rpc/server/json_rpc_server.test.d.ts +0 -2
- package/dest/json-rpc/server/json_rpc_server.test.d.ts.map +0 -1
- package/dest/json-rpc/server/json_rpc_server.test.js +0 -22
- package/dest/log/log_history.test.d.ts +0 -2
- package/dest/log/log_history.test.d.ts.map +0 -1
- package/dest/log/log_history.test.js +0 -78
- package/dest/mutex/mutex.test.d.ts +0 -9
- package/dest/mutex/mutex.test.d.ts.map +0 -1
- package/dest/mutex/mutex.test.js +0 -58
- package/dest/serialize/buffer_reader.test.d.ts +0 -2
- package/dest/serialize/buffer_reader.test.d.ts.map +0 -1
- package/dest/serialize/buffer_reader.test.js +0 -156
- package/dest/serialize/serialize.test.d.ts +0 -2
- package/dest/serialize/serialize.test.d.ts.map +0 -1
- package/dest/serialize/serialize.test.js +0 -68
- package/dest/wasm/wasm_module.test.d.ts +0 -2
- package/dest/wasm/wasm_module.test.d.ts.map +0 -1
- package/dest/wasm/wasm_module.test.js +0 -24
- package/src/abi/decoder.test.ts +0 -77
- package/src/abi/encoder.test.ts +0 -80
- package/src/async-map/async_map.test.ts +0 -9
- package/src/bigint-buffer/bigint-buffer.test.ts +0 -21
- package/src/committable/committable.test.ts +0 -32
- package/src/crypto/random/index.test.ts +0 -13
- package/src/crypto/sha256/index.test.ts +0 -14
- package/src/eth-address/eth_address.test.ts +0 -114
- package/src/fields/coordinate.test.ts +0 -26
- package/src/fields/grumpkin_scalar.test.ts +0 -55
- package/src/json-rpc/client/json_rpc_client.test.ts +0 -21
- package/src/json-rpc/convert.test.ts +0 -77
- package/src/json-rpc/server/json_rpc_server.test.ts +0 -24
- package/src/log/log_history.test.ts +0 -88
- package/src/mutex/mutex.test.ts +0 -76
- package/src/serialize/buffer_reader.test.ts +0 -176
- package/src/serialize/serialize.test.ts +0 -89
- package/src/wasm/wasm_module.test.ts +0 -28
- package/tsconfig.dest.json +0 -5
- package/tsconfig.json +0 -10
package/src/json-rpc/convert.ts
CHANGED
|
@@ -88,7 +88,7 @@ export function convertFromJsonObj(cc: ClassConverter, obj: any): any {
|
|
|
88
88
|
if (cc.isRegisteredClassName(obj.type)) {
|
|
89
89
|
return cc.toClassObj(obj);
|
|
90
90
|
} else {
|
|
91
|
-
throw new Error(`Object ${obj.type} not registered for
|
|
91
|
+
throw new Error(`Object ${obj.type} not registered for serialization FROM JSON`);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -117,6 +117,14 @@ export function convertFromJsonObj(cc: ClassConverter, obj: any): any {
|
|
|
117
117
|
* @returns The encoded object.
|
|
118
118
|
*/
|
|
119
119
|
export function convertToJsonObj(cc: ClassConverter, obj: any): any {
|
|
120
|
+
// Bigint is a primitive type that needs special handling since it's not serialisable
|
|
121
|
+
if (typeof obj === 'bigint') {
|
|
122
|
+
return {
|
|
123
|
+
type: 'bigint',
|
|
124
|
+
data: obj.toString(),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
120
128
|
if (!obj) {
|
|
121
129
|
return obj; // Primitive type
|
|
122
130
|
}
|
|
@@ -126,13 +134,6 @@ export function convertToJsonObj(cc: ClassConverter, obj: any): any {
|
|
|
126
134
|
return { type: 'Buffer', data: obj.toString('base64') };
|
|
127
135
|
}
|
|
128
136
|
|
|
129
|
-
if (typeof obj === 'bigint') {
|
|
130
|
-
return {
|
|
131
|
-
type: 'bigint',
|
|
132
|
-
data: obj.toString(),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
137
|
// Is this a convertible type?
|
|
137
138
|
if (cc.isRegisteredClass(obj.constructor)) {
|
|
138
139
|
return cc.toJsonObj(obj);
|
|
@@ -153,7 +154,7 @@ export function convertToJsonObj(cc: ClassConverter, obj: any): any {
|
|
|
153
154
|
return newObj;
|
|
154
155
|
} else {
|
|
155
156
|
// Throw if this is a non-primitive class that was not registered
|
|
156
|
-
throw new Error(`Object ${obj.constructor.name} not registered for
|
|
157
|
+
throw new Error(`Object ${obj.constructor.name} not registered for serialization TO JSON`);
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { format } from 'util';
|
|
2
|
+
|
|
1
3
|
import { createDebugLogger } from '../../log/index.js';
|
|
2
4
|
import { ClassConverter, JsonClassConverterInput, StringClassConverterInput } from '../class_converter.js';
|
|
3
5
|
import { convertFromJsonObj, convertToJsonObj } from '../convert.js';
|
|
@@ -25,17 +27,17 @@ export class JsonProxy {
|
|
|
25
27
|
* @returns The remote result.
|
|
26
28
|
*/
|
|
27
29
|
public async call(methodName: string, jsonParams: any[] = []) {
|
|
28
|
-
debug(`JsonProxy:call`, methodName, jsonParams);
|
|
30
|
+
debug(format(`JsonProxy:call`, methodName, jsonParams));
|
|
29
31
|
// Get access to our class members
|
|
30
32
|
const proto = Object.getPrototypeOf(this.handler);
|
|
31
33
|
assert(hasOwnProperty(proto, methodName), `JsonProxy: Method ${methodName} not found!`);
|
|
32
34
|
assert(Array.isArray(jsonParams), 'JsonProxy: Params not an array!');
|
|
33
35
|
// convert the params from json representation to classes
|
|
34
36
|
const convertedParams = jsonParams.map(param => convertFromJsonObj(this.classConverter, param));
|
|
35
|
-
debug('JsonProxy:call', methodName, '<-', convertedParams);
|
|
37
|
+
debug(format('JsonProxy:call', methodName, '<-', convertedParams));
|
|
36
38
|
const rawRet = await (this.handler as any)[methodName](...convertedParams);
|
|
37
39
|
const ret = convertToJsonObj(this.classConverter, rawRet);
|
|
38
|
-
debug('JsonProxy:call', methodName, '->', ret);
|
|
40
|
+
debug(format('JsonProxy:call', methodName, '->', ret));
|
|
39
41
|
return ret;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
@@ -39,22 +39,43 @@ export class JsonRpcServer {
|
|
|
39
39
|
await next();
|
|
40
40
|
} catch (err: any) {
|
|
41
41
|
this.log.error(err);
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
if (err instanceof SyntaxError) {
|
|
43
|
+
ctx.status = 400;
|
|
44
|
+
ctx.body = {
|
|
45
|
+
jsonrpc: '2.0',
|
|
46
|
+
id: null,
|
|
47
|
+
error: {
|
|
48
|
+
code: -32700,
|
|
49
|
+
message: 'Parse error',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
} else {
|
|
53
|
+
ctx.status = 500;
|
|
54
|
+
ctx.body = {
|
|
55
|
+
jsonrpc: '2.0',
|
|
56
|
+
id: null,
|
|
57
|
+
error: {
|
|
58
|
+
code: -32603,
|
|
59
|
+
message: 'Internal error',
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
44
63
|
}
|
|
45
64
|
};
|
|
46
65
|
const app = new Koa();
|
|
47
66
|
app.on('error', error => {
|
|
48
67
|
this.log.error(`Error on API handler: ${error}`);
|
|
49
68
|
});
|
|
69
|
+
app.use(exceptionHandler);
|
|
50
70
|
app.use(compress({ br: false } as any));
|
|
51
71
|
app.use(
|
|
52
72
|
bodyParser({
|
|
53
73
|
jsonLimit: '10mb',
|
|
74
|
+
enableTypes: ['json'],
|
|
75
|
+
detectJSON: () => true,
|
|
54
76
|
}),
|
|
55
77
|
);
|
|
56
78
|
app.use(cors());
|
|
57
|
-
app.use(exceptionHandler);
|
|
58
79
|
app.use(router.routes());
|
|
59
80
|
app.use(router.allowedMethods());
|
|
60
81
|
|
|
@@ -96,7 +117,15 @@ export class JsonRpcServer {
|
|
|
96
117
|
// Propagate the error message to the client. Plenty of the errors are expected to occur (e.g. adding
|
|
97
118
|
// a duplicate recipient) so this is necessary.
|
|
98
119
|
ctx.status = 400;
|
|
99
|
-
ctx.body = {
|
|
120
|
+
ctx.body = {
|
|
121
|
+
jsonrpc,
|
|
122
|
+
id,
|
|
123
|
+
error: {
|
|
124
|
+
// TODO assign error codes - https://github.com/AztecProtocol/aztec-packages/issues/2633
|
|
125
|
+
code: -32000,
|
|
126
|
+
message: err.message,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
100
129
|
}
|
|
101
130
|
});
|
|
102
131
|
}
|
|
@@ -111,7 +140,14 @@ export class JsonRpcServer {
|
|
|
111
140
|
this.disallowedMethods.includes(method)
|
|
112
141
|
) {
|
|
113
142
|
ctx.status = 400;
|
|
114
|
-
ctx.body = {
|
|
143
|
+
ctx.body = {
|
|
144
|
+
jsonrpc,
|
|
145
|
+
id,
|
|
146
|
+
error: {
|
|
147
|
+
code: -32601,
|
|
148
|
+
message: 'Method not found',
|
|
149
|
+
},
|
|
150
|
+
};
|
|
115
151
|
} else {
|
|
116
152
|
try {
|
|
117
153
|
const result = await this.proxy.call(method, params);
|
|
@@ -125,7 +161,15 @@ export class JsonRpcServer {
|
|
|
125
161
|
// Propagate the error message to the client. Plenty of the errors are expected to occur (e.g. adding
|
|
126
162
|
// a duplicate recipient) so this is necessary.
|
|
127
163
|
ctx.status = 400;
|
|
128
|
-
ctx.body = {
|
|
164
|
+
ctx.body = {
|
|
165
|
+
jsonrpc,
|
|
166
|
+
id,
|
|
167
|
+
error: {
|
|
168
|
+
// TODO assign error codes - https://github.com/AztecProtocol/aztec-packages/issues/2633
|
|
169
|
+
code: -32000,
|
|
170
|
+
message: err.message,
|
|
171
|
+
},
|
|
172
|
+
};
|
|
129
173
|
}
|
|
130
174
|
}
|
|
131
175
|
});
|
package/src/log/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/** Structured log data to include with the message. */
|
|
2
|
+
export type LogData = Record<string, string | number | bigint | boolean>;
|
|
3
|
+
|
|
4
|
+
/** A callable logger instance. */
|
|
5
|
+
export type LogFn = (msg: string, data?: LogData) => void;
|
|
5
6
|
|
|
6
7
|
export * from './console.js';
|
|
7
8
|
export * from './debug.js';
|
package/src/log/logger.ts
CHANGED
|
@@ -2,24 +2,27 @@ import debug from 'debug';
|
|
|
2
2
|
import isNode from 'detect-node';
|
|
3
3
|
import { isatty } from 'tty';
|
|
4
4
|
|
|
5
|
-
import { LogFn } from './index.js';
|
|
5
|
+
import { LogData, LogFn } from './index.js';
|
|
6
6
|
|
|
7
7
|
// Matches a subset of Winston log levels
|
|
8
8
|
const LogLevels = ['silent', 'error', 'warn', 'info', 'verbose', 'debug'] as const;
|
|
9
|
-
const DefaultLogLevel = 'info' as const;
|
|
9
|
+
const DefaultLogLevel = process.env.NODE_ENV === 'test' ? ('silent' as const) : ('info' as const);
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* A valid log severity level.
|
|
13
13
|
*/
|
|
14
|
-
type LogLevel = (typeof LogLevels)[number];
|
|
14
|
+
export type LogLevel = (typeof LogLevels)[number];
|
|
15
15
|
|
|
16
16
|
const envLogLevel = process.env.LOG_LEVEL?.toLowerCase() as LogLevel;
|
|
17
17
|
const currentLevel = LogLevels.includes(envLogLevel) ? envLogLevel : DefaultLogLevel;
|
|
18
18
|
|
|
19
|
+
/** Log function that accepts an exception object */
|
|
20
|
+
type ErrorLogFn = (msg: string, err?: Error | unknown, data?: LogData) => void;
|
|
21
|
+
|
|
19
22
|
/**
|
|
20
23
|
* Logger that supports multiple severity levels.
|
|
21
24
|
*/
|
|
22
|
-
export type Logger = { [K in LogLevel]: LogFn };
|
|
25
|
+
export type Logger = { [K in LogLevel]: LogFn } & { /** Error log function */ error: ErrorLogFn };
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* Logger that supports multiple severity levels and can be called directly to issue a debug statement.
|
|
@@ -40,17 +43,17 @@ export function createDebugLogger(name: string): DebugLogger {
|
|
|
40
43
|
|
|
41
44
|
const logger = {
|
|
42
45
|
silent: () => {},
|
|
43
|
-
error: (
|
|
44
|
-
warn: (
|
|
45
|
-
info: (
|
|
46
|
-
verbose: (
|
|
47
|
-
debug: (
|
|
46
|
+
error: (msg: string, err?: unknown, data?: LogData) => logWithDebug(debugLogger, 'error', fmtErr(msg, err), data),
|
|
47
|
+
warn: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'warn', msg, data),
|
|
48
|
+
info: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'info', msg, data),
|
|
49
|
+
verbose: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'verbose', msg, data),
|
|
50
|
+
debug: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data),
|
|
48
51
|
};
|
|
49
|
-
return Object.assign((
|
|
52
|
+
return Object.assign((msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data), logger);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
/** A callback to capture all logs. */
|
|
53
|
-
export type LogHandler = (level: LogLevel, namespace: string,
|
|
56
|
+
export type LogHandler = (level: LogLevel, namespace: string, msg: string, data?: LogData) => void;
|
|
54
57
|
|
|
55
58
|
const logHandlers: LogHandler[] = [];
|
|
56
59
|
|
|
@@ -68,14 +71,16 @@ export function onLog(handler: LogHandler) {
|
|
|
68
71
|
* @param level - Intended log level.
|
|
69
72
|
* @param args - Args to log.
|
|
70
73
|
*/
|
|
71
|
-
function logWithDebug(debug: debug.Debugger, level: LogLevel,
|
|
74
|
+
function logWithDebug(debug: debug.Debugger, level: LogLevel, msg: string, data?: LogData) {
|
|
72
75
|
for (const handler of logHandlers) {
|
|
73
|
-
handler(level, debug.namespace,
|
|
76
|
+
handler(level, debug.namespace, msg, data);
|
|
74
77
|
}
|
|
78
|
+
|
|
79
|
+
const msgWithData = data ? `${msg} ${fmtLogData(data)}` : msg;
|
|
75
80
|
if (debug.enabled) {
|
|
76
|
-
debug(
|
|
77
|
-
} else if (LogLevels.indexOf(level) <= LogLevels.indexOf(currentLevel)
|
|
78
|
-
printLog(
|
|
81
|
+
debug(msgWithData);
|
|
82
|
+
} else if (LogLevels.indexOf(level) <= LogLevels.indexOf(currentLevel)) {
|
|
83
|
+
printLog(`${getPrefix(debug, level)} ${msgWithData}`);
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
|
|
@@ -96,9 +101,30 @@ function getPrefix(debugLogger: debug.Debugger, level: LogLevel) {
|
|
|
96
101
|
|
|
97
102
|
/**
|
|
98
103
|
* Outputs to console error.
|
|
99
|
-
* @param
|
|
104
|
+
* @param msg - What to log.
|
|
100
105
|
*/
|
|
101
|
-
function printLog(
|
|
106
|
+
function printLog(msg: string) {
|
|
102
107
|
// eslint-disable-next-line no-console
|
|
103
|
-
console.error(
|
|
108
|
+
console.error(msg);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Concatenates a log message and an exception.
|
|
113
|
+
* @param msg - Log message
|
|
114
|
+
* @param err - Error to log
|
|
115
|
+
* @returns A string with both the log message and the error message.
|
|
116
|
+
*/
|
|
117
|
+
function fmtErr(msg: string, err?: Error | unknown): string {
|
|
118
|
+
const errStr = err && [(err as Error).name, (err as Error).message].filter(x => !!x).join(' ');
|
|
119
|
+
return err ? `${msg}: ${errStr || err}` : msg;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Formats structured log data as a string for console output.
|
|
124
|
+
* @param data - Optional log data.
|
|
125
|
+
*/
|
|
126
|
+
function fmtLogData(data?: LogData): string {
|
|
127
|
+
return Object.entries(data ?? {})
|
|
128
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
129
|
+
.join(' ');
|
|
104
130
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Timer } from './timer.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Measures the elapsed execution time of a function call or promise once it is awaited.
|
|
5
|
+
* @param fn - Function or promise.
|
|
6
|
+
* @returns A timer object and the result.
|
|
7
|
+
*/
|
|
8
|
+
export async function elapsed<T>(fn: Promise<T> | (() => T | Promise<T>)): Promise<[Timer, T]> {
|
|
9
|
+
const timer = new Timer();
|
|
10
|
+
const result = await (typeof fn === 'function' ? fn() : fn);
|
|
11
|
+
return [timer, result];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Measures the elapsed execution time of a synchronous function call once it is awaited.
|
|
16
|
+
* @param fn - Function.
|
|
17
|
+
* @returns A timer object and the result.
|
|
18
|
+
*/
|
|
19
|
+
export function elapsedSync<T>(fn: () => T): [Timer, T] {
|
|
20
|
+
const timer = new Timer();
|
|
21
|
+
const result = fn();
|
|
22
|
+
return [timer, result];
|
|
23
|
+
}
|
package/src/timer/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { format } from 'util';
|
|
2
|
+
|
|
1
3
|
import { createDebugLogger } from '../../log/index.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -27,7 +29,7 @@ export interface DispatchMsg {
|
|
|
27
29
|
export function createDispatchFn(targetFn: () => any, debug = createDebugLogger('aztec:foundation:dispatch')) {
|
|
28
30
|
return async ({ fn, args }: DispatchMsg) => {
|
|
29
31
|
const target = targetFn();
|
|
30
|
-
debug(`dispatching to ${target}: ${fn}`, args);
|
|
32
|
+
debug(format(`dispatching to ${target}: ${fn}`, args));
|
|
31
33
|
return await target[fn](...args);
|
|
32
34
|
};
|
|
33
35
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
|
+
import { format } from 'util';
|
|
2
3
|
|
|
3
4
|
import { createDebugLogger } from '../log/index.js';
|
|
4
5
|
import { EventMessage, ResponseMessage, isEventMessage } from './dispatch/messages.js';
|
|
@@ -91,7 +92,7 @@ export class TransportClient<Payload> extends EventEmitter {
|
|
|
91
92
|
}
|
|
92
93
|
const msgId = this.msgId++;
|
|
93
94
|
const msg = { msgId, payload };
|
|
94
|
-
debug(`->`, msg);
|
|
95
|
+
debug(format(`->`, msg));
|
|
95
96
|
return new Promise<any>((resolve, reject) => {
|
|
96
97
|
this.pendingRequests.push({ resolve, reject, msgId });
|
|
97
98
|
this.socket!.send(msg, transfer).catch(reject);
|
|
@@ -111,7 +112,7 @@ export class TransportClient<Payload> extends EventEmitter {
|
|
|
111
112
|
this.close();
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
114
|
-
debug(`<-`, msg);
|
|
115
|
+
debug(format(`<-`, msg));
|
|
115
116
|
if (isEventMessage(msg)) {
|
|
116
117
|
this.emit('event_msg', msg.payload);
|
|
117
118
|
return;
|
package/src/wasm/wasm_module.ts
CHANGED
|
@@ -149,9 +149,9 @@ export class WasmModule implements IWasmModule {
|
|
|
149
149
|
*/
|
|
150
150
|
public addLogger(logger: LogFn) {
|
|
151
151
|
const oldDebug = this.debug;
|
|
152
|
-
this.debug = (
|
|
153
|
-
logger(
|
|
154
|
-
oldDebug(
|
|
152
|
+
this.debug = (msg: string) => {
|
|
153
|
+
logger(msg);
|
|
154
|
+
oldDebug(msg);
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
|
package/.eslintrc.cjs
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
// See https://typescript-eslint.io/play/#ts=5.1.6&showAST=es&fileType=.ts
|
|
2
|
-
const contexts = [
|
|
3
|
-
// All methods in an interface
|
|
4
|
-
'TSInterfaceDeclaration TSMethodSignature',
|
|
5
|
-
// All public methods in a class that does not implement an interface
|
|
6
|
-
'ClassDeclaration[implements.length=0] MethodDefinition[accessibility=public]',
|
|
7
|
-
// TODO: All methods public by default in a class that does not implement an interface
|
|
8
|
-
// 'ClassDeclaration[implements.length=0] MethodDefinition[accessibility=undefined][key.type=Identifier]',
|
|
9
|
-
// TODO: All export const from the top level of a file
|
|
10
|
-
// 'ExportNamedDeclaration[declaration.type=VariableDeclaration]',
|
|
11
|
-
// Legacy contexts (needs review)
|
|
12
|
-
'TSParameterProperty[accessibility=public]',
|
|
13
|
-
'TSPropertySignature',
|
|
14
|
-
'PropertySignature',
|
|
15
|
-
'TSInterfaceDeclaration',
|
|
16
|
-
'InterfaceDeclaration',
|
|
17
|
-
'TSPropertyDefinition[accessibility=public]',
|
|
18
|
-
'PropertyDefinition[accessibility=public]',
|
|
19
|
-
'TSTypeAliasDeclaration',
|
|
20
|
-
'TypeAliasDeclaration',
|
|
21
|
-
'TSTypeDeclaration',
|
|
22
|
-
'TypeDeclaration',
|
|
23
|
-
'TSEnumDeclaration',
|
|
24
|
-
'EnumDeclaration',
|
|
25
|
-
'TSClassDeclaration',
|
|
26
|
-
'ClassDeclaration',
|
|
27
|
-
'TSClassExpression',
|
|
28
|
-
'ClassExpression',
|
|
29
|
-
'TSFunctionExpression',
|
|
30
|
-
'FunctionExpression',
|
|
31
|
-
'TSInterfaceExpression',
|
|
32
|
-
'InterfaceExpression',
|
|
33
|
-
'TSEnumExpression',
|
|
34
|
-
'EnumExpression',
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
const JSDOC_RULES_LEVEL = 'error';
|
|
38
|
-
|
|
39
|
-
module.exports = {
|
|
40
|
-
extends: [
|
|
41
|
-
'eslint:recommended',
|
|
42
|
-
'plugin:@typescript-eslint/recommended',
|
|
43
|
-
'plugin:import/recommended',
|
|
44
|
-
'plugin:import/typescript',
|
|
45
|
-
'prettier',
|
|
46
|
-
],
|
|
47
|
-
settings: {
|
|
48
|
-
'import/resolver': {
|
|
49
|
-
typescript: true,
|
|
50
|
-
node: true,
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
root: true,
|
|
54
|
-
parser: '@typescript-eslint/parser',
|
|
55
|
-
plugins: ['@typescript-eslint', 'eslint-plugin-tsdoc', 'jsdoc'],
|
|
56
|
-
overrides: [
|
|
57
|
-
{
|
|
58
|
-
files: ['*.ts', '*.tsx'],
|
|
59
|
-
parserOptions: {
|
|
60
|
-
// hacky workaround for CI not having the same tsconfig setup
|
|
61
|
-
project: true,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
files: '*.test.ts',
|
|
66
|
-
rules: {
|
|
67
|
-
'jsdoc/require-jsdoc': 'off',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
env: {
|
|
72
|
-
node: true,
|
|
73
|
-
},
|
|
74
|
-
rules: {
|
|
75
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
76
|
-
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
77
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
78
|
-
'@typescript-eslint/no-empty-function': 'off',
|
|
79
|
-
'@typescript-eslint/await-thenable': 'error',
|
|
80
|
-
'@typescript-eslint/no-floating-promises': 2,
|
|
81
|
-
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
|
|
82
|
-
'require-await': 2,
|
|
83
|
-
'no-console': 'error',
|
|
84
|
-
'no-constant-condition': 'off',
|
|
85
|
-
camelcase: 2,
|
|
86
|
-
'no-restricted-imports': [
|
|
87
|
-
'error',
|
|
88
|
-
{
|
|
89
|
-
patterns: [
|
|
90
|
-
{
|
|
91
|
-
group: ['client-dest'],
|
|
92
|
-
message: "Fix this absolute garbage import. It's your duty to solve it before it spreads.",
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
group: ['dest'],
|
|
96
|
-
message: 'You should not be importing from a build directory. Did you accidentally do a relative import?',
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
'import/no-unresolved': [
|
|
102
|
-
'error',
|
|
103
|
-
{
|
|
104
|
-
ignore: [
|
|
105
|
-
// See https://github.com/import-js/eslint-plugin-import/issues/2703
|
|
106
|
-
'@libp2p/bootstrap',
|
|
107
|
-
// Seems like ignoring l1-artifacts in the eslint call messes up no-unresolved
|
|
108
|
-
'@aztec/l1-artifacts',
|
|
109
|
-
],
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
'import/no-extraneous-dependencies': 'error',
|
|
113
|
-
'tsdoc/syntax': JSDOC_RULES_LEVEL,
|
|
114
|
-
'jsdoc/require-jsdoc': [
|
|
115
|
-
JSDOC_RULES_LEVEL,
|
|
116
|
-
{
|
|
117
|
-
contexts,
|
|
118
|
-
checkConstructors: false,
|
|
119
|
-
checkGetters: true,
|
|
120
|
-
checkSetters: true,
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
'jsdoc/require-description': [JSDOC_RULES_LEVEL, { contexts }],
|
|
124
|
-
'jsdoc/require-hyphen-before-param-description': [JSDOC_RULES_LEVEL],
|
|
125
|
-
'jsdoc/require-param': [JSDOC_RULES_LEVEL, { contexts, checkDestructured: false }],
|
|
126
|
-
'jsdoc/require-param-description': [JSDOC_RULES_LEVEL, { contexts }],
|
|
127
|
-
'jsdoc/require-param-name': [JSDOC_RULES_LEVEL, { contexts }],
|
|
128
|
-
'jsdoc/require-property': [JSDOC_RULES_LEVEL, { contexts }],
|
|
129
|
-
'jsdoc/require-property-description': [JSDOC_RULES_LEVEL, { contexts }],
|
|
130
|
-
'jsdoc/require-property-name': [JSDOC_RULES_LEVEL, { contexts }],
|
|
131
|
-
'jsdoc/require-returns': 'off',
|
|
132
|
-
},
|
|
133
|
-
ignorePatterns: ['node_modules', 'dest*', 'dist', '*.js', '.eslintrc.cjs'],
|
|
134
|
-
};
|
package/.prettierrc.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"singleQuote": true,
|
|
3
|
-
"trailingComma": "all",
|
|
4
|
-
"printWidth": 120,
|
|
5
|
-
"arrowParens": "avoid",
|
|
6
|
-
"importOrder": ["^@aztec/(.*)$", "<THIRD_PARTY_MODULES>", "^\\./|\\.\\./"],
|
|
7
|
-
"importOrderSeparation": true,
|
|
8
|
-
"importOrderSortSpecifiers": true,
|
|
9
|
-
"importOrderParserPlugins": ["importAssertions", "typescript"]
|
|
10
|
-
}
|