@aztec/foundation 0.33.0 → 0.35.0
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/abi.d.ts +2 -2
- package/dest/abi/abi.d.ts.map +1 -1
- package/dest/abi/abi.js +11 -11
- package/dest/abi/event_selector.js +3 -3
- package/dest/abi/function_selector.js +3 -3
- package/dest/aztec-address/index.d.ts +4 -0
- package/dest/aztec-address/index.d.ts.map +1 -1
- package/dest/aztec-address/index.js +10 -1
- package/dest/crypto/index.d.ts +1 -0
- package/dest/crypto/index.d.ts.map +1 -1
- package/dest/crypto/index.js +2 -1
- package/dest/crypto/keccak/index.d.ts +1 -1
- package/dest/crypto/keccak/index.d.ts.map +1 -1
- package/dest/crypto/keccak/index.js +2 -2
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +5 -3
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +8 -9
- package/dest/crypto/poseidon/index.d.ts +10 -3
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +21 -4
- package/dest/crypto/random/randomness_singleton.js +3 -3
- package/dest/crypto/sha512/index.d.ts +10 -0
- package/dest/crypto/sha512/index.d.ts.map +1 -0
- package/dest/crypto/sha512/index.js +14 -0
- package/dest/eth-address/index.d.ts +4 -0
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +10 -1
- package/dest/fields/fields.d.ts +10 -1
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +19 -1
- package/dest/fifo/bounded_serial_queue.d.ts +1 -1
- package/dest/fifo/bounded_serial_queue.d.ts.map +1 -1
- package/dest/fifo/memory_fifo.d.ts +1 -1
- package/dest/fifo/memory_fifo.d.ts.map +1 -1
- package/dest/json-rpc/client/json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/json_rpc_client.js +8 -8
- package/dest/json-rpc/server/json_proxy.js +5 -5
- 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/log/logger.d.ts +2 -2
- package/dest/log/logger.d.ts.map +1 -1
- package/dest/log/logger.js +5 -6
- package/dest/noir/noir_package_config.d.ts +2 -2
- package/dest/retry/index.d.ts +1 -1
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +2 -2
- package/dest/serialize/index.d.ts +1 -0
- package/dest/serialize/index.d.ts.map +1 -1
- package/dest/serialize/index.js +2 -1
- package/dest/serialize/serialize.d.ts +9 -3
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +16 -7
- package/dest/serialize/type_registry.d.ts +23 -0
- package/dest/serialize/type_registry.d.ts.map +1 -0
- package/dest/serialize/type_registry.js +38 -0
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +2 -2
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.js +4 -4
- package/dest/transport/transport_client.js +4 -4
- package/dest/worker/worker_pool.js +4 -4
- package/package.json +2 -2
- package/src/abi/abi.ts +10 -10
- package/src/abi/event_selector.ts +2 -2
- package/src/abi/function_selector.ts +2 -2
- package/src/aztec-address/index.ts +11 -0
- package/src/crypto/index.ts +1 -0
- package/src/crypto/keccak/index.ts +1 -1
- package/src/crypto/pedersen/pedersen.wasm.ts +7 -9
- package/src/crypto/poseidon/index.ts +25 -3
- package/src/crypto/random/randomness_singleton.ts +2 -2
- package/src/crypto/sha512/index.ts +16 -0
- package/src/eth-address/index.ts +11 -0
- package/src/fields/fields.ts +23 -1
- package/src/json-rpc/client/json_rpc_client.ts +7 -7
- package/src/json-rpc/server/json_proxy.ts +4 -4
- package/src/log/logger.ts +5 -6
- package/src/retry/index.ts +1 -1
- package/src/serialize/index.ts +1 -0
- package/src/serialize/serialize.ts +23 -9
- package/src/serialize/type_registry.ts +43 -0
- package/src/transport/dispatch/create_dispatch_fn.ts +3 -3
- package/src/transport/transport_client.ts +3 -3
- package/src/worker/worker_pool.ts +3 -3
package/src/log/logger.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { isatty } from 'tty';
|
|
|
4
4
|
|
|
5
5
|
import { type LogData, type LogFn } from './log_fn.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const LogLevels = ['silent', 'error', 'warn', 'info', 'verbose', 'debug', 'trace'] as const;
|
|
7
|
+
const LogLevels = ['silent', 'error', 'warn', 'info', 'verbose', 'debug'] as const;
|
|
9
8
|
const DefaultLogLevel = process.env.NODE_ENV === 'test' ? ('silent' as const) : ('info' as const);
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -28,7 +27,7 @@ export type Logger = { [K in LogLevel]: LogFn } & { /** Error log function */ er
|
|
|
28
27
|
* Logger that supports multiple severity levels and can be called directly to issue a debug statement.
|
|
29
28
|
* Intended as a drop-in replacement for the debug module.
|
|
30
29
|
*/
|
|
31
|
-
export type DebugLogger =
|
|
30
|
+
export type DebugLogger = Logger;
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* Creates a new DebugLogger for the current module, defaulting to the LOG_LEVEL env var.
|
|
@@ -50,7 +49,6 @@ export function createDebugLogger(name: string): DebugLogger {
|
|
|
50
49
|
info: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'info', msg, data),
|
|
51
50
|
verbose: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'verbose', msg, data),
|
|
52
51
|
debug: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data),
|
|
53
|
-
trace: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'trace', msg, data),
|
|
54
52
|
};
|
|
55
53
|
return Object.assign((msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data), logger);
|
|
56
54
|
}
|
|
@@ -99,7 +97,7 @@ function logWithDebug(debug: debug.Debugger, level: LogLevel, msg: string, data?
|
|
|
99
97
|
function getPrefix(debugLogger: debug.Debugger, level: LogLevel) {
|
|
100
98
|
const levelLabel = currentLevel !== level ? ` ${level.toUpperCase()}` : '';
|
|
101
99
|
const prefix = `${debugLogger.namespace.replace(/^aztec:/, '')}${levelLabel}`;
|
|
102
|
-
if (!isNode || !isatty(process.stderr.fd)) {
|
|
100
|
+
if ((!isNode || !isatty(process.stderr.fd)) && !process.env.DEBUG_COLORS) {
|
|
103
101
|
return prefix;
|
|
104
102
|
}
|
|
105
103
|
const colorIndex = debug.selectColor(debugLogger.namespace) as number;
|
|
@@ -112,7 +110,8 @@ function getPrefix(debugLogger: debug.Debugger, level: LogLevel) {
|
|
|
112
110
|
* @param msg - What to log.
|
|
113
111
|
*/
|
|
114
112
|
function printLog(msg: string) {
|
|
115
|
-
|
|
113
|
+
// eslint-disable-next-line no-console
|
|
114
|
+
isNode ? process.stderr.write(msg + '\n') : console.error(msg);
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
/**
|
package/src/retry/index.ts
CHANGED
|
@@ -63,7 +63,7 @@ export async function retry<Result>(
|
|
|
63
63
|
if (s === undefined) {
|
|
64
64
|
throw err;
|
|
65
65
|
}
|
|
66
|
-
log(`${name} failed. Will retry in ${s}s...`);
|
|
66
|
+
log.verbose(`${name} failed. Will retry in ${s}s...`);
|
|
67
67
|
!failSilently && log.error(err);
|
|
68
68
|
await sleep(s * 1000);
|
|
69
69
|
continue;
|
package/src/serialize/index.ts
CHANGED
|
@@ -121,11 +121,19 @@ export type Bufferable =
|
|
|
121
121
|
| Bufferable[];
|
|
122
122
|
|
|
123
123
|
/** A type that can be converted to a Field or a Field array. */
|
|
124
|
-
export type
|
|
124
|
+
export type Fieldable =
|
|
125
125
|
| Fr
|
|
126
126
|
| boolean
|
|
127
127
|
| number
|
|
128
128
|
| bigint
|
|
129
|
+
| Buffer
|
|
130
|
+
| {
|
|
131
|
+
/**
|
|
132
|
+
* Serialize to a field.
|
|
133
|
+
* @dev Duplicate to `toField` but left as is as it is used in AVM codebase.
|
|
134
|
+
*/
|
|
135
|
+
toFr: () => Fr;
|
|
136
|
+
}
|
|
129
137
|
| {
|
|
130
138
|
/** Serialize to a field. */
|
|
131
139
|
toField: () => Fr;
|
|
@@ -134,7 +142,7 @@ export type Fieldeable =
|
|
|
134
142
|
/** Serialize to an array of fields. */
|
|
135
143
|
toFields: () => Fr[];
|
|
136
144
|
}
|
|
137
|
-
|
|
|
145
|
+
| Fieldable[];
|
|
138
146
|
|
|
139
147
|
/**
|
|
140
148
|
* Serializes a list of objects contiguously.
|
|
@@ -142,10 +150,10 @@ export type Fieldeable =
|
|
|
142
150
|
* @returns A buffer list with the concatenation of all fields.
|
|
143
151
|
*/
|
|
144
152
|
export function serializeToBufferArray(...objs: Bufferable[]): Buffer[] {
|
|
145
|
-
|
|
153
|
+
const ret: Buffer[] = [];
|
|
146
154
|
for (const obj of objs) {
|
|
147
155
|
if (Array.isArray(obj)) {
|
|
148
|
-
ret
|
|
156
|
+
ret.push(...serializeToBufferArray(...obj));
|
|
149
157
|
} else if (Buffer.isBuffer(obj)) {
|
|
150
158
|
ret.push(obj);
|
|
151
159
|
} else if (typeof obj === 'boolean') {
|
|
@@ -176,19 +184,25 @@ export function serializeToBufferArray(...objs: Bufferable[]): Buffer[] {
|
|
|
176
184
|
* @param objs - Objects to serialize.
|
|
177
185
|
* @returns An array of fields with the concatenation of all fields.
|
|
178
186
|
*/
|
|
179
|
-
export function serializeToFields(...objs:
|
|
180
|
-
|
|
187
|
+
export function serializeToFields(...objs: Fieldable[]): Fr[] {
|
|
188
|
+
const ret: Fr[] = [];
|
|
181
189
|
for (const obj of objs) {
|
|
182
190
|
if (Array.isArray(obj)) {
|
|
183
|
-
ret
|
|
191
|
+
ret.push(...serializeToFields(...obj));
|
|
184
192
|
} else if (obj instanceof Fr) {
|
|
185
193
|
ret.push(obj);
|
|
186
194
|
} else if (typeof obj === 'boolean' || typeof obj === 'number' || typeof obj === 'bigint') {
|
|
187
195
|
ret.push(new Fr(obj));
|
|
188
196
|
} else if ('toFields' in obj) {
|
|
189
|
-
ret
|
|
190
|
-
} else {
|
|
197
|
+
ret.push(...obj.toFields());
|
|
198
|
+
} else if ('toFr' in obj) {
|
|
199
|
+
ret.push(obj.toFr());
|
|
200
|
+
} else if ('toField' in obj) {
|
|
191
201
|
ret.push(obj.toField());
|
|
202
|
+
} else if (Buffer.isBuffer(obj)) {
|
|
203
|
+
ret.push(Fr.fromBuffer(obj));
|
|
204
|
+
} else {
|
|
205
|
+
throw new Error(`Cannot serialize input to field: ${typeof obj} ${(obj as any).constructor?.name}`);
|
|
192
206
|
}
|
|
193
207
|
}
|
|
194
208
|
return ret;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
type Deserializable = { fromString(str: string): object };
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Register a class here that has a toJSON method that returns:
|
|
5
|
+
* ```
|
|
6
|
+
* {
|
|
7
|
+
* "type": "ExampleClassName",
|
|
8
|
+
* "value": <result of ExampleClassName.toString()>
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
* and has an e.g. ExampleClassName.fromString(string) method.
|
|
12
|
+
* This means you can then easily serialize/deserialize the type using JSON.stringify and JSON.parse.
|
|
13
|
+
*/
|
|
14
|
+
export class TypeRegistry {
|
|
15
|
+
private static registry: Map<string, Deserializable> = new Map();
|
|
16
|
+
|
|
17
|
+
public static register(typeName: string, constructor: Deserializable): void {
|
|
18
|
+
this.registry.set(typeName, constructor);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static getConstructor(typeName: string): Deserializable | undefined {
|
|
22
|
+
return this.registry.get(typeName);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Resolver function that enables JSON serialization of BigInts.
|
|
27
|
+
export function resolver(_: any, value: any) {
|
|
28
|
+
return typeof value === 'bigint' ? value.toString() + 'n' : value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Reviver function that uses TypeRegistry to instantiate objects.
|
|
32
|
+
export function reviver(key: string, value: any) {
|
|
33
|
+
if (typeof value === 'string' && /^\d+n$/.test(value)) {
|
|
34
|
+
return BigInt(value.slice(0, -1));
|
|
35
|
+
}
|
|
36
|
+
if (value && typeof value === 'object' && 'type' in value && 'value' in value) {
|
|
37
|
+
const Constructor = TypeRegistry.getConstructor(value.type);
|
|
38
|
+
if (Constructor) {
|
|
39
|
+
return Constructor.fromString(value.value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
@@ -23,13 +23,13 @@ export interface DispatchMsg {
|
|
|
23
23
|
* the method to be called ('fn') and an array of arguments to be passed to the method ('args').
|
|
24
24
|
*
|
|
25
25
|
* @param targetFn - A function that returns the target object containing the methods to be dispatched.
|
|
26
|
-
* @param
|
|
26
|
+
* @param log - Optional logging function for debugging purposes.
|
|
27
27
|
* @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
|
|
28
28
|
*/
|
|
29
|
-
export function createDispatchFn(targetFn: () => any,
|
|
29
|
+
export function createDispatchFn(targetFn: () => any, log = createDebugLogger('aztec:foundation:dispatch')) {
|
|
30
30
|
return async ({ fn, args }: DispatchMsg) => {
|
|
31
31
|
const target = targetFn();
|
|
32
|
-
debug(format(`dispatching to ${target}: ${fn}`, args));
|
|
32
|
+
log.debug(format(`dispatching to ${target}: ${fn}`, args));
|
|
33
33
|
return await target[fn](...args);
|
|
34
34
|
};
|
|
35
35
|
}
|
|
@@ -6,7 +6,7 @@ import { type EventMessage, type ResponseMessage, isEventMessage } from './dispa
|
|
|
6
6
|
import { type Connector } from './interface/connector.js';
|
|
7
7
|
import { type Socket } from './interface/socket.js';
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const log = createDebugLogger('aztec:transport_client');
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Represents a pending request in the TransportClient.
|
|
@@ -92,7 +92,7 @@ export class TransportClient<Payload> extends EventEmitter {
|
|
|
92
92
|
}
|
|
93
93
|
const msgId = this.msgId++;
|
|
94
94
|
const msg = { msgId, payload };
|
|
95
|
-
debug(format(`->`, msg));
|
|
95
|
+
log.debug(format(`->`, msg));
|
|
96
96
|
return new Promise<any>((resolve, reject) => {
|
|
97
97
|
this.pendingRequests.push({ resolve, reject, msgId });
|
|
98
98
|
this.socket!.send(msg, transfer).catch(reject);
|
|
@@ -112,7 +112,7 @@ export class TransportClient<Payload> extends EventEmitter {
|
|
|
112
112
|
this.close();
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
|
-
debug(format(`<-`, msg));
|
|
115
|
+
log.debug(format(`<-`, msg));
|
|
116
116
|
if (isEventMessage(msg)) {
|
|
117
117
|
this.emit('event_msg', msg.payload);
|
|
118
118
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createDebugLogger } from '../log/index.js';
|
|
2
2
|
import { type WasmWorker } from './wasm_worker.js';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const log = createDebugLogger('bb:worker_pool');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Type of a worker factory.
|
|
@@ -53,7 +53,7 @@ export class WorkerPool {
|
|
|
53
53
|
* @param maxMem - Max memory pages.
|
|
54
54
|
*/
|
|
55
55
|
public async init(createWorker: CreateWorker, poolSize: number, maxMem = WorkerPool.MAX_PAGES) {
|
|
56
|
-
debug(`creating ${poolSize} workers...`);
|
|
56
|
+
log.debug(`creating ${poolSize} workers...`);
|
|
57
57
|
const start = new Date().getTime();
|
|
58
58
|
this.workers = await Promise.all(
|
|
59
59
|
Array(poolSize)
|
|
@@ -61,7 +61,7 @@ export class WorkerPool {
|
|
|
61
61
|
.map((_, i) => createWorker(`${i}`, i === 0 ? Math.min(WorkerPool.MAX_PAGES, maxMem) : 768, maxMem)),
|
|
62
62
|
);
|
|
63
63
|
|
|
64
|
-
debug(`created workers: ${new Date().getTime() - start}ms`);
|
|
64
|
+
log.debug(`created workers: ${new Date().getTime() - start}ms`);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|