@aztec/foundation 0.1.0-alpha23 → 0.1.0-alpha25
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/.prettierrc.json +5 -1
- package/.tsbuildinfo +1 -1
- package/dest/abi/abi.d.ts +137 -0
- package/dest/abi/abi.d.ts.map +1 -0
- package/dest/abi/abi.js +18 -0
- package/dest/abi/abi_coder.d.ts +8 -1
- package/dest/abi/abi_coder.d.ts.map +1 -1
- package/dest/abi/abi_coder.js +12 -3
- package/dest/abi/decoder.d.ts +1 -1
- package/dest/abi/decoder.d.ts.map +1 -1
- package/dest/abi/index.d.ts +1 -136
- package/dest/abi/index.d.ts.map +1 -1
- package/dest/abi/index.js +2 -18
- package/dest/aztec-address/index.d.ts +7 -0
- package/dest/aztec-address/index.d.ts.map +1 -1
- package/dest/aztec-address/index.js +10 -1
- package/dest/crypto/random/index.js +2 -2
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +1 -1
- package/dest/crypto/sha256/index.test.js +2 -2
- package/dest/fields/fields.d.ts +6 -0
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +10 -2
- package/dest/fields/point.d.ts +8 -23
- package/dest/fields/point.d.ts.map +1 -1
- package/dest/fields/point.js +10 -31
- package/dest/fifo/bounded_serial_queue.d.ts +1 -1
- package/dest/fifo/bounded_serial_queue.d.ts.map +1 -1
- package/dest/fifo/bounded_serial_queue.js +3 -3
- package/dest/fifo/memory_fifo.d.ts +1 -1
- package/dest/fifo/memory_fifo.d.ts.map +1 -1
- package/dest/fifo/memory_fifo.js +3 -3
- package/dest/json-rpc/client/index.d.ts +1 -1
- package/dest/json-rpc/client/index.d.ts.map +1 -1
- package/dest/json-rpc/client/index.js +2 -2
- package/dest/json-rpc/client/json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/json_rpc_client.js +8 -4
- package/dest/json-rpc/client/json_rpc_client.test.js +2 -2
- package/dest/json-rpc/convert.d.ts.map +1 -1
- package/dest/json-rpc/convert.js +1 -1
- package/dest/json-rpc/convert.test.js +2 -2
- package/dest/json-rpc/index.d.ts +1 -1
- package/dest/json-rpc/index.d.ts.map +1 -1
- package/dest/json-rpc/index.js +2 -2
- package/dest/json-rpc/server/json_proxy.d.ts +1 -1
- package/dest/json-rpc/server/json_proxy.d.ts.map +1 -1
- package/dest/json-rpc/server/json_proxy.js +3 -2
- package/dest/json-rpc/server/json_rpc_server.d.ts +2 -2
- package/dest/json-rpc/server/json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/json_rpc_server.js +7 -7
- package/dest/json-rpc/server/json_rpc_server.test.js +2 -2
- package/dest/log/console.d.ts +2 -7
- package/dest/log/console.d.ts.map +1 -1
- package/dest/log/console.js +2 -3
- package/dest/log/debug.d.ts +2 -5
- package/dest/log/debug.d.ts.map +1 -1
- package/dest/log/debug.js +2 -2
- package/dest/log/index.d.ts +5 -0
- package/dest/log/index.d.ts.map +1 -1
- package/dest/log/index.js +2 -1
- package/dest/log/log_history.test.js +4 -4
- package/dest/log/logger.d.ts +27 -0
- package/dest/log/logger.d.ts.map +1 -0
- package/dest/log/logger.js +66 -0
- package/dest/mutex/mutex.test.d.ts.map +1 -1
- package/dest/mutex/mutex.test.js +1 -1
- package/dest/retry/index.d.ts +1 -1
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +3 -3
- package/dest/serialize/buffer_reader.d.ts +1 -1
- package/dest/serialize/buffer_reader.js +1 -1
- package/dest/serialize/buffer_reader.test.js +2 -2
- package/dest/serialize/serialize.test.js +2 -2
- package/dest/serialize/serializer.js +2 -2
- package/dest/transport/browser/shared_worker_listener.d.ts.map +1 -1
- package/dest/transport/browser/shared_worker_listener.js +1 -1
- package/dest/transport/browser/worker_listener.d.ts.map +1 -1
- package/dest/transport/browser/worker_listener.js +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.js +1 -1
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +2 -2
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_proxy.js +1 -1
- package/dest/transport/interface/listener.d.ts.map +1 -1
- package/dest/transport/node/node_connector.d.ts.map +1 -1
- package/dest/transport/node/node_connector.js +1 -1
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
- package/dest/transport/node/node_connector_socket.js +1 -1
- package/dest/transport/node/node_listener.d.ts.map +1 -1
- package/dest/transport/node/node_listener.js +2 -2
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
- package/dest/transport/node/node_listener_socket.js +1 -1
- package/dest/transport/transport_client.d.ts.map +1 -1
- package/dest/transport/transport_client.js +2 -2
- package/dest/wasm/wasm/empty_wasi_sdk.d.ts +1 -1
- package/dest/wasm/wasm/empty_wasi_sdk.js +3 -3
- package/dest/wasm/wasm/wasm_module.d.ts +3 -3
- package/dest/wasm/wasm/wasm_module.d.ts.map +1 -1
- package/dest/wasm/wasm/wasm_module.js +4 -4
- package/dest/wasm/wasm/wasm_module.test.js +3 -3
- package/dest/wasm/worker/browser/web_data_store.d.ts.map +1 -1
- package/dest/wasm/worker/browser/web_data_store.js +1 -1
- package/dest/wasm/worker/node/node_data_store.d.ts.map +1 -1
- package/dest/wasm/worker/node/node_data_store.js +2 -2
- package/dest/wasm/worker/node/node_worker.d.ts.map +1 -1
- package/dest/wasm/worker/node/node_worker.js +2 -2
- package/dest/wasm/worker/node/start_node_module.d.ts.map +1 -1
- package/dest/wasm/worker/node/start_node_module.js +1 -1
- package/package.json +1 -1
- package/src/abi/abi.ts +147 -0
- package/src/abi/abi_coder.ts +13 -3
- package/src/abi/decoder.ts +1 -1
- package/src/abi/index.ts +1 -148
- package/src/aztec-address/index.ts +10 -0
- package/src/crypto/random/index.ts +1 -1
- package/src/crypto/sha256/index.test.ts +2 -1
- package/src/crypto/sha256/index.ts +1 -0
- package/src/fields/fields.ts +12 -2
- package/src/fields/point.ts +11 -34
- package/src/fifo/bounded_serial_queue.ts +2 -2
- package/src/fifo/memory_fifo.ts +2 -2
- package/src/json-rpc/client/index.ts +1 -1
- package/src/json-rpc/client/json_rpc_client.test.ts +2 -1
- package/src/json-rpc/client/json_rpc_client.ts +7 -5
- package/src/json-rpc/convert.test.ts +2 -2
- package/src/json-rpc/convert.ts +2 -1
- package/src/json-rpc/index.ts +1 -1
- package/src/json-rpc/server/json_proxy.ts +3 -2
- package/src/json-rpc/server/json_rpc_server.test.ts +2 -1
- package/src/json-rpc/server/json_rpc_server.ts +7 -7
- package/src/log/console.ts +2 -8
- package/src/log/debug.ts +3 -6
- package/src/log/index.ts +6 -0
- package/src/log/log_history.test.ts +4 -3
- package/src/log/logger.ts +87 -0
- package/src/mutex/mutex.test.ts +1 -0
- package/src/retry/index.ts +2 -2
- package/src/serialize/buffer_reader.test.ts +2 -1
- package/src/serialize/buffer_reader.ts +1 -1
- package/src/serialize/serialize.test.ts +3 -3
- package/src/serialize/serializer.ts +1 -1
- package/src/transport/browser/shared_worker_listener.ts +1 -0
- package/src/transport/browser/worker_listener.ts +1 -0
- package/src/transport/dispatch/create_dispatch_fn.ts +1 -1
- package/src/transport/dispatch/create_dispatch_proxy.ts +4 -3
- package/src/transport/interface/listener.ts +1 -0
- package/src/transport/node/node_connector.ts +1 -0
- package/src/transport/node/node_connector_socket.ts +1 -0
- package/src/transport/node/node_listener.ts +2 -1
- package/src/transport/node/node_listener_socket.ts +1 -0
- package/src/transport/transport_client.ts +3 -2
- package/src/wasm/wasm/empty_wasi_sdk.ts +2 -2
- package/src/wasm/wasm/wasm_module.test.ts +3 -2
- package/src/wasm/wasm/wasm_module.ts +6 -5
- package/src/wasm/worker/browser/web_data_store.ts +2 -1
- package/src/wasm/worker/node/node_data_store.ts +3 -2
- package/src/wasm/worker/node/node_worker.ts +2 -1
- package/src/wasm/worker/node/start_node_module.ts +2 -1
package/src/fields/point.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Fr } from './fields.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
@@ -7,7 +7,7 @@ import { Coordinate } from './coordinate.js';
|
|
|
7
7
|
* converting instances to various output formats, and checking the equality of points.
|
|
8
8
|
*/
|
|
9
9
|
export class Point {
|
|
10
|
-
static ZERO = new Point(
|
|
10
|
+
static ZERO = new Point(Fr.ZERO, Fr.ZERO);
|
|
11
11
|
|
|
12
12
|
/** Used to differentiate this class from AztecAddress */
|
|
13
13
|
public readonly kind = 'point';
|
|
@@ -16,11 +16,11 @@ export class Point {
|
|
|
16
16
|
/**
|
|
17
17
|
* The point's x coordinate
|
|
18
18
|
*/
|
|
19
|
-
public readonly x:
|
|
19
|
+
public readonly x: Fr,
|
|
20
20
|
/**
|
|
21
21
|
* The point's y coordinate
|
|
22
22
|
*/
|
|
23
|
-
public readonly y:
|
|
23
|
+
public readonly y: Fr,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -30,7 +30,7 @@ export class Point {
|
|
|
30
30
|
*/
|
|
31
31
|
static random() {
|
|
32
32
|
// TODO is this a random point on the curve?
|
|
33
|
-
return new Point(
|
|
33
|
+
return new Point(Fr.random(), Fr.random());
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -42,17 +42,7 @@ export class Point {
|
|
|
42
42
|
*/
|
|
43
43
|
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
44
44
|
const reader = BufferReader.asReader(buffer);
|
|
45
|
-
return new this(
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Creates a point instance from its x and y coordinates.
|
|
50
|
-
* @param x - X coordinate.
|
|
51
|
-
* @param y - Y coordinate.
|
|
52
|
-
* @returns A Point instance.
|
|
53
|
-
*/
|
|
54
|
-
static fromCoordinates(x: Coordinate, y: Coordinate) {
|
|
55
|
-
return new this(x, y);
|
|
45
|
+
return new this(Fr.fromBuffer(reader.readBytes(32)), Fr.fromBuffer(reader.readBytes(32)));
|
|
56
46
|
}
|
|
57
47
|
|
|
58
48
|
/**
|
|
@@ -68,22 +58,11 @@ export class Point {
|
|
|
68
58
|
}
|
|
69
59
|
|
|
70
60
|
/**
|
|
71
|
-
*
|
|
72
|
-
* The
|
|
73
|
-
* This method is useful for serialization and deserialization of the Point object.
|
|
74
|
-
*
|
|
75
|
-
* @returns A Buffer representation of the Point instance.
|
|
76
|
-
*/
|
|
77
|
-
toFieldsBuffer() {
|
|
78
|
-
return Buffer.concat([this.x.toFieldsBuffer(), this.y.toFieldsBuffer()]);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Returns the contents of the point as an array of 4 fields.
|
|
83
|
-
* @returns The point as an array of 4 fields
|
|
61
|
+
* Returns the contents of the point as an array of 2 fields.
|
|
62
|
+
* @returns The point as an array of 2 fields
|
|
84
63
|
*/
|
|
85
64
|
toFields() {
|
|
86
|
-
return this.x
|
|
65
|
+
return [this.x, this.y];
|
|
87
66
|
}
|
|
88
67
|
|
|
89
68
|
/**
|
|
@@ -91,11 +70,9 @@ export class Point {
|
|
|
91
70
|
* @returns The point as BigInts
|
|
92
71
|
*/
|
|
93
72
|
toBigInts() {
|
|
94
|
-
const x = this.x.toBigInt();
|
|
95
|
-
const y = this.y.toBigInt();
|
|
96
73
|
return {
|
|
97
|
-
x,
|
|
98
|
-
y,
|
|
74
|
+
x: this.x.value,
|
|
75
|
+
y: this.y.value,
|
|
99
76
|
};
|
|
100
77
|
}
|
|
101
78
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createDebugLogger } from '../log/index.js';
|
|
2
2
|
import { Semaphore } from './semaphore.js';
|
|
3
3
|
import { SerialQueue } from './serial_queue.js';
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ export class BoundedSerialQueue {
|
|
|
10
10
|
private readonly queue = new SerialQueue();
|
|
11
11
|
private semaphore: Semaphore;
|
|
12
12
|
|
|
13
|
-
constructor(maxQueueSize: number, private log =
|
|
13
|
+
constructor(maxQueueSize: number, private log = createDebugLogger('aztec:foundation:bounded_serial_queue')) {
|
|
14
14
|
this.semaphore = new Semaphore(maxQueueSize);
|
|
15
15
|
}
|
|
16
16
|
|
package/src/fifo/memory_fifo.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createDebugLogger } from '../log/index.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A simple fifo queue. It can grow unbounded. It can have multiple producers and consumers.
|
|
@@ -10,7 +10,7 @@ export class MemoryFifo<T> {
|
|
|
10
10
|
private items: T[] = [];
|
|
11
11
|
private flushing = false;
|
|
12
12
|
|
|
13
|
-
constructor(private log =
|
|
13
|
+
constructor(private log = createDebugLogger('aztec:foundation:memory_fifo')) {}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Returns the current number of items in the queue.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createJsonRpcClient, JsonStringify } from './json_rpc_client.js';
|
|
1
|
+
export { createJsonRpcClient, JsonStringify, mustSucceedFetch, defaultFetch } from './json_rpc_client.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
|
+
|
|
3
|
+
import { TestNote, TestState } from '../fixtures/test_state.js';
|
|
2
4
|
import { JsonRpcServer } from '../server/json_rpc_server.js';
|
|
3
|
-
import { TestState, TestNote } from '../fixtures/test_state.js';
|
|
4
5
|
import { createJsonRpcClient } from './json_rpc_client.js';
|
|
5
6
|
|
|
6
7
|
test('test an RPC function over client', async () => {
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
// This takes a {foo(): T} and makes {foo(): Promise<T>}
|
|
4
4
|
// while avoiding Promise of Promise.
|
|
5
5
|
import { RemoteObject } from 'comlink';
|
|
6
|
+
|
|
6
7
|
import { createDebugLogger } from '../../log/index.js';
|
|
7
8
|
import { retry } from '../../retry/index.js';
|
|
8
|
-
import { ClassConverter,
|
|
9
|
+
import { ClassConverter, JsonClassConverterInput, StringClassConverterInput } from '../class_converter.js';
|
|
9
10
|
import { JsonStringify, convertFromJsonObj, convertToJsonObj } from '../convert.js';
|
|
10
11
|
|
|
11
12
|
export { JsonStringify } from '../convert.js';
|
|
@@ -91,12 +92,13 @@ export function createJsonRpcClient<T extends object>(
|
|
|
91
92
|
return new Proxy(
|
|
92
93
|
{},
|
|
93
94
|
{
|
|
94
|
-
get:
|
|
95
|
-
(
|
|
96
|
-
(...params: any[]) => {
|
|
95
|
+
get: (target, rpcMethod: string) => {
|
|
96
|
+
if (['then', 'catch'].includes(rpcMethod)) return Reflect.get(target, rpcMethod);
|
|
97
|
+
return (...params: any[]) => {
|
|
97
98
|
debug(`JsonRpcClient.constructor`, 'proxy', rpcMethod, '<-', params);
|
|
98
99
|
return request(rpcMethod, params);
|
|
99
|
-
}
|
|
100
|
+
};
|
|
101
|
+
},
|
|
100
102
|
},
|
|
101
103
|
) as RemoteObject<T>;
|
|
102
104
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
|
|
1
3
|
import { ClassConverter } from './class_converter.js';
|
|
2
4
|
import { convertFromJsonObj, convertToJsonObj } from './convert.js';
|
|
3
5
|
import { TestNote } from './fixtures/test_state.js';
|
|
4
6
|
|
|
5
|
-
import { Buffer } from 'buffer';
|
|
6
|
-
|
|
7
7
|
const TEST_BASE64 = 'YmFzZTY0IGRlY29kZXI=';
|
|
8
8
|
test('test an RPC function over client', () => {
|
|
9
9
|
const cc = new ClassConverter({ TestNote });
|
package/src/json-rpc/convert.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ClassConverter } from './class_converter.js';
|
|
2
1
|
import { Buffer } from 'buffer';
|
|
3
2
|
|
|
3
|
+
import { ClassConverter } from './class_converter.js';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Recursively looks through an object for bigints and converts them to object format.
|
|
6
7
|
* @param obj - The object to convert.
|
package/src/json-rpc/index.ts
CHANGED
|
@@ -5,4 +5,4 @@ export {
|
|
|
5
5
|
ClassConverter,
|
|
6
6
|
} from './class_converter.js';
|
|
7
7
|
export { JsonRpcServer, JsonProxy } from './server/index.js';
|
|
8
|
-
export { createJsonRpcClient, JsonStringify } from './client/index.js';
|
|
8
|
+
export { createJsonRpcClient, JsonStringify, mustSucceedFetch, defaultFetch } from './client/index.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDebugLogger } from '../../log/index.js';
|
|
2
|
-
import { ClassConverter,
|
|
2
|
+
import { ClassConverter, JsonClassConverterInput, StringClassConverterInput } from '../class_converter.js';
|
|
3
3
|
import { convertFromJsonObj, convertToJsonObj } from '../convert.js';
|
|
4
4
|
import { assert, hasOwnProperty } from '../js_utils.js';
|
|
5
5
|
|
|
@@ -25,9 +25,10 @@ export class JsonProxy {
|
|
|
25
25
|
* @returns The remote result.
|
|
26
26
|
*/
|
|
27
27
|
public async call(methodName: string, jsonParams: any[] = []) {
|
|
28
|
+
debug(`JsonProxy:call`, methodName, jsonParams);
|
|
28
29
|
// Get access to our class members
|
|
29
30
|
const proto = Object.getPrototypeOf(this.handler);
|
|
30
|
-
assert(hasOwnProperty(proto, methodName),
|
|
31
|
+
assert(hasOwnProperty(proto, methodName), `JsonProxy: Method ${methodName} not found!`);
|
|
31
32
|
assert(Array.isArray(jsonParams), 'JsonProxy: Params not an array!');
|
|
32
33
|
// convert the params from json representation to classes
|
|
33
34
|
const convertedParams = jsonParams.map(param => convertFromJsonObj(this.classConverter, param));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { TestNote, TestState } from '../fixtures/test_state.js';
|
|
3
4
|
import { JsonRpcServer } from './json_rpc_server.js';
|
|
4
5
|
|
|
5
6
|
test('test an RPC function with a primitive parameter', async () => {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import http from 'http';
|
|
2
|
-
import Router from 'koa-router';
|
|
3
1
|
import cors from '@koa/cors';
|
|
4
|
-
import
|
|
2
|
+
import http from 'http';
|
|
5
3
|
import Koa from 'koa';
|
|
6
4
|
import bodyParser from 'koa-bodyparser';
|
|
5
|
+
import compress from 'koa-compress';
|
|
6
|
+
import Router from 'koa-router';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { JsonProxy } from './json_proxy.js';
|
|
8
|
+
import { createDebugLogger } from '../../log/index.js';
|
|
9
|
+
import { JsonClassConverterInput, StringClassConverterInput } from '../class_converter.js';
|
|
11
10
|
import { convertBigintsInObj } from '../convert.js';
|
|
11
|
+
import { JsonProxy } from './json_proxy.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* JsonRpcServer.
|
|
@@ -22,7 +22,7 @@ export class JsonRpcServer {
|
|
|
22
22
|
objectClassMap: JsonClassConverterInput,
|
|
23
23
|
private createApi: boolean,
|
|
24
24
|
private disallowedMethods: string[] = [],
|
|
25
|
-
private log =
|
|
25
|
+
private log = createDebugLogger('aztec:foundation:json-rpc:server'),
|
|
26
26
|
) {
|
|
27
27
|
this.proxy = new JsonProxy(handler, stringClassMap, objectClassMap);
|
|
28
28
|
}
|
package/src/log/console.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Logger is a utility type that represents a logging function that accepts any number of arguments.
|
|
5
|
-
* It is used to provide customizable logging functionality, allowing developers to easily log messages
|
|
6
|
-
* with optional prefixes and custom formatting or output destinations.
|
|
7
|
-
*/
|
|
8
|
-
export type Logger = (...args: any[]) => void;
|
|
2
|
+
import { LogFn } from './index.js';
|
|
9
3
|
|
|
10
4
|
/**
|
|
11
5
|
* ConsoleLogger is a utility class that provides customizable console logging functionality.
|
|
@@ -36,7 +30,7 @@ class ConsoleLogger {
|
|
|
36
30
|
* @param prefix - The optional string to prepend to each log message.
|
|
37
31
|
* @returns A Logger function that accepts any number of arguments and logs them with the specified prefix.
|
|
38
32
|
*/
|
|
39
|
-
export function
|
|
33
|
+
export function createConsoleLogger(prefix?: string): LogFn {
|
|
40
34
|
if (prefix) {
|
|
41
35
|
const logger = new ConsoleLogger(prefix, console.log);
|
|
42
36
|
return (...args: any[]) => logger.log(...args);
|
package/src/log/debug.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
2
|
|
|
3
|
+
import { LogFn } from './index.js';
|
|
4
|
+
|
|
3
5
|
let preLogHook: ((...args: any[]) => void) | undefined;
|
|
4
6
|
let postLogHook: ((...args: any[]) => void) | undefined;
|
|
5
7
|
|
|
@@ -23,17 +25,12 @@ function theFunctionThroughWhichAllLogsPass(logger: any, ...args: any[]) {
|
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
/**
|
|
27
|
-
* A debug logger.
|
|
28
|
-
*/
|
|
29
|
-
export type DebugLogger = (...args: any[]) => void;
|
|
30
|
-
|
|
31
28
|
/**
|
|
32
29
|
* Return a logger, meant to be silent by default and verbose during debugging.
|
|
33
30
|
* @param name - The module name of the logger.
|
|
34
31
|
* @returns A callable log function.
|
|
35
32
|
*/
|
|
36
|
-
export function
|
|
33
|
+
export function createDebugOnlyLogger(name: string): LogFn {
|
|
37
34
|
const logger = debug(name);
|
|
38
35
|
return (...args: any[]) => theFunctionThroughWhichAllLogsPass(logger, ...args);
|
|
39
36
|
}
|
package/src/log/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jest } from '@jest/globals';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { createDebugOnlyLogger, enableLogs } from './debug.js';
|
|
3
4
|
import { LogHistory } from './log_history.js';
|
|
4
5
|
|
|
5
6
|
jest.useFakeTimers({ doNotFake: ['performance'] });
|
|
@@ -11,7 +12,7 @@ describe('log history', () => {
|
|
|
11
12
|
const name = 'test:a';
|
|
12
13
|
|
|
13
14
|
beforeEach(() => {
|
|
14
|
-
debug =
|
|
15
|
+
debug = createDebugOnlyLogger(name);
|
|
15
16
|
enableLogs(name);
|
|
16
17
|
logHistory = new LogHistory();
|
|
17
18
|
});
|
|
@@ -52,7 +53,7 @@ describe('log history', () => {
|
|
|
52
53
|
it('only keeps logs with enabled namespace', () => {
|
|
53
54
|
logHistory.enable();
|
|
54
55
|
const name2 = 'test:b';
|
|
55
|
-
const debug2 =
|
|
56
|
+
const debug2 = createDebugOnlyLogger(name2);
|
|
56
57
|
debug('0');
|
|
57
58
|
debug2('zero');
|
|
58
59
|
expect(logHistory.getLogs()).toEqual([[timestemp, name, '0']]);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import isNode from 'detect-node';
|
|
3
|
+
import { isatty } from 'tty';
|
|
4
|
+
|
|
5
|
+
import { LogFn } from './index.js';
|
|
6
|
+
|
|
7
|
+
const LogLevels = ['silent', 'fatal', 'error', 'warn', 'info', 'debug'] as const;
|
|
8
|
+
const DefaultLogLevel = 'info' as const;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A valid log severity level.
|
|
12
|
+
*/
|
|
13
|
+
type LogLevel = (typeof LogLevels)[number];
|
|
14
|
+
|
|
15
|
+
const envLogLevel = process.env.LOG_LEVEL?.toLowerCase() as LogLevel;
|
|
16
|
+
const currentLevel = LogLevels.includes(envLogLevel) ? envLogLevel : DefaultLogLevel;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Logger that supports multiple severity levels.
|
|
20
|
+
*/
|
|
21
|
+
export type Logger = { [K in LogLevel]: LogFn };
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Logger that supports multiple severity levels and can be called directly to issue a debug statement.
|
|
25
|
+
* Intended as a drop-in replacement for the debug module.
|
|
26
|
+
*/
|
|
27
|
+
export type DebugLogger = LogFn & Logger;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new DebugLogger for the current module, defaulting to the LOG_LEVEL env var.
|
|
31
|
+
* If DEBUG="[module]" env is set, will enable debug logging if the module matches.
|
|
32
|
+
* Uses npm debug for debug level and console.error for other levels.
|
|
33
|
+
* @param name - Name of the module.
|
|
34
|
+
* @returns A debug logger.
|
|
35
|
+
*/
|
|
36
|
+
export function createDebugLogger(name: string): DebugLogger {
|
|
37
|
+
const debugLogger = debug(name);
|
|
38
|
+
if (currentLevel === 'debug') debugLogger.enabled = true;
|
|
39
|
+
|
|
40
|
+
const logger = {
|
|
41
|
+
silent: () => {},
|
|
42
|
+
fatal: (...args: any[]) => logWithDebug(debugLogger, 'fatal', args),
|
|
43
|
+
error: (...args: any[]) => logWithDebug(debugLogger, 'error', args),
|
|
44
|
+
warn: (...args: any[]) => logWithDebug(debugLogger, 'warn', args),
|
|
45
|
+
info: (...args: any[]) => logWithDebug(debugLogger, 'info', args),
|
|
46
|
+
debug: (...args: any[]) => logWithDebug(debugLogger, 'debug', args),
|
|
47
|
+
};
|
|
48
|
+
return Object.assign(debugLogger, logger);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Logs args to npm debug if enabled or log level is debug, console.error otherwise.
|
|
53
|
+
* @param debug - Instance of npm debug.
|
|
54
|
+
* @param level - Intended log level.
|
|
55
|
+
* @param args - Args to log.
|
|
56
|
+
*/
|
|
57
|
+
function logWithDebug(debug: debug.Debugger, level: LogLevel, args: any[]) {
|
|
58
|
+
if (debug.enabled) {
|
|
59
|
+
debug(args[0], ...args.slice(1));
|
|
60
|
+
} else if (LogLevels.indexOf(level) <= LogLevels.indexOf(currentLevel)) {
|
|
61
|
+
printLog([getPrefix(debug, level), ...args]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Returns a log prefix that emulates that of npm debug. Uses colors if in node and in a tty.
|
|
67
|
+
* @param debugLogger - Instance of npm debug logger.
|
|
68
|
+
* @param level - Intended log level (printed out if strictly above current log level).
|
|
69
|
+
* @returns Log prefix.
|
|
70
|
+
*/
|
|
71
|
+
function getPrefix(debugLogger: debug.Debugger, level: LogLevel) {
|
|
72
|
+
const levelLabel = currentLevel !== level ? ` ${level.toUpperCase}` : '';
|
|
73
|
+
const prefix = `${debugLogger.namespace.replace(/^aztec:/, '')}${levelLabel}`;
|
|
74
|
+
if (!isNode || !isatty(process.stderr.fd)) return prefix;
|
|
75
|
+
const colorIndex = debug.selectColor(debugLogger.namespace) as number;
|
|
76
|
+
const colorCode = '\u001B[3' + (colorIndex < 8 ? colorIndex : '8;5;' + colorIndex);
|
|
77
|
+
return ` ${colorCode};1m${prefix}\u001B[0m`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Outputs to console error.
|
|
82
|
+
* @param args - Args to log.
|
|
83
|
+
*/
|
|
84
|
+
function printLog(args: any[]) {
|
|
85
|
+
// eslint-disable-next-line no-console
|
|
86
|
+
console.error(...args);
|
|
87
|
+
}
|
package/src/mutex/mutex.test.ts
CHANGED
package/src/retry/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createDebugLogger } from '../log/index.js';
|
|
2
2
|
import { sleep } from '../sleep/index.js';
|
|
3
3
|
import { Timer } from '../timer/index.js';
|
|
4
4
|
|
|
@@ -32,7 +32,7 @@ export async function retry<Result>(
|
|
|
32
32
|
fn: () => Promise<Result>,
|
|
33
33
|
name = 'Operation',
|
|
34
34
|
backoff = backoffGenerator(),
|
|
35
|
-
log =
|
|
35
|
+
log = createDebugLogger('aztec:foundation:retry'),
|
|
36
36
|
) {
|
|
37
37
|
while (true) {
|
|
38
38
|
try {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jest } from '@jest/globals';
|
|
2
|
+
|
|
3
|
+
import { randomBytes } from '../crypto/index.js';
|
|
2
4
|
import { Fq, Fr } from '../fields/fields.js';
|
|
3
5
|
import { BufferReader } from './buffer_reader.js';
|
|
4
6
|
import { serializeBufferArrayToVector } from './free_funcs.js';
|
|
5
|
-
import { randomBytes } from '../crypto/index.js';
|
|
6
7
|
|
|
7
8
|
const ARRAY = Array.from(Array(32)).map((_, idx) => (idx % 2 === 0 ? 0 : 1));
|
|
8
9
|
const BUFFER = Buffer.from(ARRAY);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { randomBytes } from '../crypto/index.js';
|
|
2
2
|
import { Fr } from '../fields/fields.js';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
deserializeArrayFromVector,
|
|
5
5
|
deserializeBufferFromVector,
|
|
6
|
-
deserializeUInt32,
|
|
7
6
|
deserializeField,
|
|
7
|
+
deserializeUInt32,
|
|
8
8
|
serializeBufferArrayToVector,
|
|
9
|
-
|
|
9
|
+
serializeBufferToVector,
|
|
10
10
|
} from './index.js';
|
|
11
11
|
|
|
12
12
|
describe('serialize', () => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { serializeBufferArrayToVector } from './index.js';
|
|
2
1
|
import {
|
|
3
2
|
boolToByte,
|
|
4
3
|
numToInt32BE,
|
|
@@ -7,6 +6,7 @@ import {
|
|
|
7
6
|
serializeBufferToVector,
|
|
8
7
|
serializeDate,
|
|
9
8
|
} from './free_funcs.js';
|
|
9
|
+
import { serializeBufferArrayToVector } from './index.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The Serializer class provides a convenient and efficient way to serialize various data types into binary format.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { DispatchMsg } from './create_dispatch_fn.js';
|
|
2
|
-
import { TransportClient } from '../transport_client.js';
|
|
3
1
|
import { EventEmitter } from 'events';
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
import { TransferDescriptor, isTransferDescriptor } from '../interface/transferable.js';
|
|
4
|
+
import { TransportClient } from '../transport_client.js';
|
|
5
|
+
import { DispatchMsg } from './create_dispatch_fn.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* FilterOutAttributes type filters out all non-method properties of an object, leaving only the attributes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { createDebugLogger } from '../log/index.js';
|
|
4
|
+
import { EventMessage, ResponseMessage, isEventMessage } from './dispatch/messages.js';
|
|
3
5
|
import { Connector } from './interface/connector.js';
|
|
4
6
|
import { Socket } from './interface/socket.js';
|
|
5
|
-
import { createDebugLogger } from '../log/index.js';
|
|
6
7
|
|
|
7
8
|
const debug = createDebugLogger('aztec:transport_client');
|
|
8
9
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createDebugOnlyLogger } from '../../log/index.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Dummy implementation of a necessary part of the wasi api:
|
|
@@ -7,7 +7,7 @@ import { createDebugLogger } from '../../log/index.js';
|
|
|
7
7
|
* TODO find a way to update off of wasi 12.
|
|
8
8
|
*/
|
|
9
9
|
/* eslint-disable camelcase */
|
|
10
|
-
export const getEmptyWasiSdk = (debug =
|
|
10
|
+
export const getEmptyWasiSdk = (debug = createDebugOnlyLogger('wasm:empty_wasi_sdk')) => ({
|
|
11
11
|
/**
|
|
12
12
|
* Retrieves the current time from the system clock.
|
|
13
13
|
* This function is a dummy implementation of the WASI API's `clock_time_get` method,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { WasmModule } from './wasm_module.js';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
1
|
import { readFile } from 'fs/promises';
|
|
4
2
|
import { dirname } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
import { WasmModule } from './wasm_module.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Fetch a simple WASM.
|