@aztec/foundation 0.0.1-commit.ffe5b04ea → 0.0.1-commit.fff30aa
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/branded-types/slot.d.ts +4 -1
- package/dest/branded-types/slot.d.ts.map +1 -1
- package/dest/branded-types/slot.js +3 -0
- package/dest/buffer/index.d.ts +2 -1
- package/dest/buffer/index.d.ts.map +1 -1
- package/dest/buffer/index.js +1 -0
- package/dest/buffer/utils.d.ts +3 -0
- package/dest/buffer/utils.d.ts.map +1 -0
- package/dest/buffer/utils.js +7 -0
- package/dest/collection/array.d.ts +3 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +15 -0
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/network_config.d.ts +13 -7
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +3 -2
- package/dest/config/network_name.d.ts +2 -2
- package/dest/config/network_name.d.ts.map +1 -1
- package/dest/config/network_name.js +0 -2
- package/dest/crypto/poseidon/index.d.ts +1 -1
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +40 -33
- package/dest/curves/grumpkin/point.d.ts +4 -4
- package/dest/curves/grumpkin/point.d.ts.map +1 -1
- package/dest/curves/grumpkin/point.js +7 -4
- package/dest/jest/setup.js +0 -24
- package/dest/schemas/api.d.ts +2 -2
- package/dest/schemas/api.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.d.ts +20 -7
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +18 -5
- package/dest/serialize/field_reader.d.ts +13 -5
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.js +13 -0
- package/dest/sleep/index.d.ts +1 -2
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +1 -10
- package/dest/timer/date.d.ts +1 -3
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +0 -4
- package/package.json +2 -2
- package/src/branded-types/slot.ts +5 -0
- package/src/buffer/index.ts +1 -0
- package/src/buffer/utils.ts +8 -0
- package/src/collection/array.ts +14 -0
- package/src/config/env_var.ts +5 -3
- package/src/config/network_config.ts +2 -1
- package/src/config/network_name.ts +1 -4
- package/src/crypto/poseidon/index.ts +42 -34
- package/src/curves/grumpkin/point.ts +6 -3
- package/src/jest/setup.mjs +0 -27
- package/src/schemas/api.ts +4 -1
- package/src/serialize/buffer_reader.ts +29 -6
- package/src/serialize/field_reader.ts +22 -4
- package/src/sleep/index.ts +1 -10
- package/src/timer/date.ts +0 -6
- package/src/trees/membership_witness.ts +2 -2
package/src/jest/setup.mjs
CHANGED
|
@@ -10,30 +10,3 @@ import pretty from 'pino-pretty';
|
|
|
10
10
|
if (!parseBooleanEnv(process.env.LOG_JSON)) {
|
|
11
11
|
overwriteLoggingStream(pretty(pinoPrettyOpts));
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
// Prevent timers from keeping the process alive after tests complete.
|
|
15
|
-
// Libraries like viem create internal polling loops (via setTimeout) that
|
|
16
|
-
// reschedule themselves indefinitely. In test environments we never want a
|
|
17
|
-
// timer to be the reason the process can't exit. We also unref stdout/stderr
|
|
18
|
-
// which, when they are pipes (as in Jest workers), remain ref'd by default.
|
|
19
|
-
{
|
|
20
|
-
const origSetTimeout = globalThis.setTimeout;
|
|
21
|
-
const origSetInterval = globalThis.setInterval;
|
|
22
|
-
globalThis.setTimeout = function unrefSetTimeout(...args) {
|
|
23
|
-
const id = origSetTimeout.apply(this, args);
|
|
24
|
-
id?.unref?.();
|
|
25
|
-
return id;
|
|
26
|
-
};
|
|
27
|
-
// Preserve .unref, .__promisify__ etc. that may exist on the original
|
|
28
|
-
Object.setPrototypeOf(globalThis.setTimeout, origSetTimeout);
|
|
29
|
-
|
|
30
|
-
globalThis.setInterval = function unrefSetInterval(...args) {
|
|
31
|
-
const id = origSetInterval.apply(this, args);
|
|
32
|
-
id?.unref?.();
|
|
33
|
-
return id;
|
|
34
|
-
};
|
|
35
|
-
Object.setPrototypeOf(globalThis.setInterval, origSetInterval);
|
|
36
|
-
|
|
37
|
-
if (process.stdout?._handle?.unref) process.stdout._handle.unref();
|
|
38
|
-
if (process.stderr?._handle?.unref) process.stderr._handle.unref();
|
|
39
|
-
}
|
package/src/schemas/api.ts
CHANGED
|
@@ -37,7 +37,10 @@ export type ApiSchema = {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
/** Return whether an API schema defines a valid function schema for a given method name. */
|
|
40
|
-
export function schemaHasMethod
|
|
40
|
+
export function schemaHasMethod<T extends ApiSchema>(
|
|
41
|
+
schema: T,
|
|
42
|
+
methodName: string,
|
|
43
|
+
): methodName is Extract<keyof T, string> {
|
|
41
44
|
return (
|
|
42
45
|
typeof methodName === 'string' &&
|
|
43
46
|
Object.hasOwn(schema, methodName) &&
|
|
@@ -286,16 +286,39 @@ export class BufferReader {
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
/**
|
|
289
|
-
* Read an array
|
|
290
|
-
*
|
|
291
|
-
* and returns an instance of the desired deserialized data type T.
|
|
292
|
-
* This method will call the 'fromBuffer' method for each element in the array and return the resulting array.
|
|
289
|
+
* Read an array from the buffer using lazy allocation (new Array + loop).
|
|
290
|
+
* Safe for use with untrusted sizes — does not pre-allocate memory proportional to size.
|
|
293
291
|
*
|
|
294
|
-
* @param size - The
|
|
292
|
+
* @param size - The number of elements to read.
|
|
295
293
|
* @param itemDeserializer - An object with a 'fromBuffer' method to deserialize individual elements of type T.
|
|
296
294
|
* @returns An array of instances of type T.
|
|
297
295
|
*/
|
|
298
|
-
public readArray<T
|
|
296
|
+
public readArray<T>(
|
|
297
|
+
size: number,
|
|
298
|
+
itemDeserializer: {
|
|
299
|
+
/**
|
|
300
|
+
* A function for deserializing data from a BufferReader instance.
|
|
301
|
+
*/
|
|
302
|
+
fromBuffer: (reader: BufferReader) => T;
|
|
303
|
+
},
|
|
304
|
+
): T[] {
|
|
305
|
+
const result = new Array<T>(size);
|
|
306
|
+
for (let i = 0; i < size; i++) {
|
|
307
|
+
result[i] = itemDeserializer.fromBuffer(this);
|
|
308
|
+
}
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Read a fixed-size tuple from the buffer using dense allocation (Array.from).
|
|
314
|
+
* Only use with compile-time constant sizes — the size parameter MUST NOT come from untrusted input
|
|
315
|
+
* as Array.from pre-allocates memory proportional to size.
|
|
316
|
+
*
|
|
317
|
+
* @param size - The fixed number of elements (must be a compile-time constant).
|
|
318
|
+
* @param itemDeserializer - An object with a 'fromBuffer' method to deserialize individual elements of type T.
|
|
319
|
+
* @returns A densely-allocated tuple of instances of type T.
|
|
320
|
+
*/
|
|
321
|
+
public readTuple<T, N extends number>(
|
|
299
322
|
size: N,
|
|
300
323
|
itemDeserializer: {
|
|
301
324
|
/**
|
|
@@ -169,12 +169,30 @@ export class FieldReader {
|
|
|
169
169
|
* @param itemDeserializer - An object with a 'fromFields' method to deserialize individual elements of type T.
|
|
170
170
|
* @returns An array of instances of type T.
|
|
171
171
|
*/
|
|
172
|
-
|
|
172
|
+
/**
|
|
173
|
+
* Read an array from the field array using lazy allocation (new Array + loop).
|
|
174
|
+
* Safe for use with untrusted sizes.
|
|
175
|
+
*/
|
|
176
|
+
public readArray<T>(
|
|
177
|
+
size: number,
|
|
178
|
+
itemDeserializer: {
|
|
179
|
+
fromFields: (reader: FieldReader) => T;
|
|
180
|
+
},
|
|
181
|
+
): T[] {
|
|
182
|
+
const result = new Array<T>(size);
|
|
183
|
+
for (let i = 0; i < size; i++) {
|
|
184
|
+
result[i] = itemDeserializer.fromFields(this);
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Read a fixed-size tuple from the field array using dense allocation (Array.from).
|
|
191
|
+
* Only use with compile-time constant sizes — the size parameter MUST NOT come from untrusted input.
|
|
192
|
+
*/
|
|
193
|
+
public readTuple<T, N extends number>(
|
|
173
194
|
size: N,
|
|
174
195
|
itemDeserializer: {
|
|
175
|
-
/**
|
|
176
|
-
* A function for deserializing data from a FieldReader instance.
|
|
177
|
-
*/
|
|
178
196
|
fromFields: (reader: FieldReader) => T;
|
|
179
197
|
},
|
|
180
198
|
): Tuple<T, N> {
|
package/src/sleep/index.ts
CHANGED
|
@@ -22,7 +22,6 @@ import { InterruptError } from '../error/index.js';
|
|
|
22
22
|
*/
|
|
23
23
|
export class InterruptibleSleep {
|
|
24
24
|
private interrupts: Array<(shouldThrow: boolean) => void> = [];
|
|
25
|
-
private timeoutIds: NodeJS.Timeout[] = [];
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* Sleep for a specified amount of time in milliseconds.
|
|
@@ -39,15 +38,9 @@ export class InterruptibleSleep {
|
|
|
39
38
|
this.interrupts.push(resolve);
|
|
40
39
|
});
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
const timeoutPromise = new Promise<boolean>(resolve => {
|
|
44
|
-
timeoutId = setTimeout(() => resolve(false), ms);
|
|
45
|
-
this.timeoutIds.push(timeoutId);
|
|
46
|
-
});
|
|
41
|
+
const timeoutPromise = new Promise<boolean>(resolve => setTimeout(() => resolve(false), ms));
|
|
47
42
|
const shouldThrow = await Promise.race([interruptPromise, timeoutPromise]);
|
|
48
43
|
|
|
49
|
-
clearTimeout(timeoutId!);
|
|
50
|
-
this.timeoutIds = this.timeoutIds.filter(id => id !== timeoutId);
|
|
51
44
|
this.interrupts = this.interrupts.filter(res => res !== interruptResolve);
|
|
52
45
|
|
|
53
46
|
if (shouldThrow) {
|
|
@@ -65,8 +58,6 @@ export class InterruptibleSleep {
|
|
|
65
58
|
public interrupt(sleepShouldThrow = false): void {
|
|
66
59
|
this.interrupts.forEach(resolve => resolve(sleepShouldThrow));
|
|
67
60
|
this.interrupts = [];
|
|
68
|
-
this.timeoutIds.forEach(id => clearTimeout(id));
|
|
69
|
-
this.timeoutIds = [];
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
|
package/src/timer/date.ts
CHANGED
|
@@ -32,12 +32,6 @@ export class TestDateProvider extends DateProvider {
|
|
|
32
32
|
this.logger.warn(`Time set to ${new Date(timeMs).toISOString()}`, { offset: this.offset, timeMs });
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/** Resets the time back to real time (offset = 0). */
|
|
36
|
-
public reset() {
|
|
37
|
-
this.offset = 0;
|
|
38
|
-
this.logger.warn('Time reset to real time');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
35
|
/** Advances the time by the given number of seconds. */
|
|
42
36
|
public advanceTime(seconds: number) {
|
|
43
37
|
this.offset += seconds * 1000;
|
|
@@ -94,7 +94,7 @@ export class MembershipWitness<N extends number> {
|
|
|
94
94
|
static fromBuffer<N extends number>(buffer: Buffer | BufferReader, size: N): MembershipWitness<N> {
|
|
95
95
|
const reader = BufferReader.asReader(buffer);
|
|
96
96
|
const leafIndex = toBigIntBE(reader.readBytes(32));
|
|
97
|
-
const siblingPath = reader.readArray(size, Fr)
|
|
97
|
+
const siblingPath = reader.readArray(size, Fr) as Tuple<Fr, N>;
|
|
98
98
|
return new MembershipWitness(size, leafIndex, siblingPath);
|
|
99
99
|
}
|
|
100
100
|
|
|
@@ -108,7 +108,7 @@ export class MembershipWitness<N extends number> {
|
|
|
108
108
|
fromBuffer: (buffer: Buffer | BufferReader) => {
|
|
109
109
|
const reader = BufferReader.asReader(buffer);
|
|
110
110
|
const leafIndex = toBigIntBE(reader.readBytes(32));
|
|
111
|
-
const siblingPath = reader.readArray(size, Fr)
|
|
111
|
+
const siblingPath = reader.readArray(size, Fr) as Tuple<Fr, N>;
|
|
112
112
|
return new MembershipWitness(size, leafIndex, siblingPath);
|
|
113
113
|
},
|
|
114
114
|
};
|