@aztec/foundation 0.41.0 → 0.43.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/decoder.d.ts +2 -2
- package/dest/abi/decoder.d.ts.map +1 -1
- package/dest/abi/decoder.js +8 -8
- package/dest/abi/encoder.d.ts.map +1 -1
- package/dest/abi/encoder.js +11 -2
- package/dest/array/array.js +2 -2
- package/dest/collection/array.d.ts +13 -0
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +12 -1
- package/dest/crypto/random/randomness_singleton.js +3 -3
- package/dest/error/index.d.ts +1 -1
- package/dest/error/index.d.ts.map +1 -1
- package/dest/error/index.js +2 -2
- package/dest/fields/fields.d.ts +5 -3
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +40 -15
- package/dest/fields/point.d.ts +7 -0
- package/dest/fields/point.d.ts.map +1 -1
- package/dest/fields/point.js +24 -2
- package/dest/fs/index.d.ts +2 -0
- package/dest/fs/index.d.ts.map +1 -0
- package/dest/fs/index.js +2 -0
- package/dest/fs/run_in_dir.d.ts +2 -0
- package/dest/fs/run_in_dir.d.ts.map +1 -0
- package/dest/fs/run_in_dir.js +18 -0
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/json-rpc/client/json_rpc_client.js +2 -2
- package/dest/promise/running-promise.d.ts +1 -1
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/running-promise.js +1 -1
- package/dest/serialize/free_funcs.d.ts +1 -0
- package/dest/serialize/free_funcs.d.ts.map +1 -1
- package/dest/serialize/free_funcs.js +8 -1
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +4 -1
- package/dest/testing/test_data.d.ts +2 -6
- package/dest/testing/test_data.d.ts.map +1 -1
- package/dest/testing/test_data.js +1 -1
- package/dest/types/index.d.ts +4 -0
- package/dest/types/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/abi/decoder.ts +7 -7
- package/src/abi/encoder.ts +8 -1
- package/src/array/array.ts +2 -2
- package/src/collection/array.ts +14 -0
- package/src/crypto/random/randomness_singleton.ts +2 -2
- package/src/error/index.ts +1 -1
- package/src/fields/fields.ts +46 -15
- package/src/fields/point.ts +28 -2
- package/src/fs/index.ts +1 -0
- package/src/fs/run_in_dir.ts +23 -0
- package/src/index.ts +1 -0
- package/src/json-rpc/client/json_rpc_client.ts +1 -1
- package/src/promise/running-promise.ts +1 -1
- package/src/serialize/free_funcs.ts +8 -0
- package/src/serialize/serialize.ts +2 -0
- package/src/testing/test_data.ts +3 -3
- package/src/types/index.ts +3 -0
package/src/fields/point.ts
CHANGED
|
@@ -23,7 +23,9 @@ export class Point {
|
|
|
23
23
|
* The point's y coordinate
|
|
24
24
|
*/
|
|
25
25
|
public readonly y: Fr,
|
|
26
|
-
) {
|
|
26
|
+
) {
|
|
27
|
+
// TODO: Do we want to check if the point is on the curve here?
|
|
28
|
+
}
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* Generate a random Point instance.
|
|
@@ -44,7 +46,7 @@ export class Point {
|
|
|
44
46
|
*/
|
|
45
47
|
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
46
48
|
const reader = BufferReader.asReader(buffer);
|
|
47
|
-
return new this(Fr.fromBuffer(reader
|
|
49
|
+
return new this(Fr.fromBuffer(reader), Fr.fromBuffer(reader));
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
@@ -134,6 +136,30 @@ export class Point {
|
|
|
134
136
|
hash() {
|
|
135
137
|
return poseidon2Hash(this.toFields());
|
|
136
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Check if this is point at infinity.
|
|
142
|
+
* Check this is consistent with how bb is encoding the point at infinity
|
|
143
|
+
*/
|
|
144
|
+
public get inf() {
|
|
145
|
+
return this.x == Fr.ZERO;
|
|
146
|
+
}
|
|
147
|
+
public toFieldsWithInf() {
|
|
148
|
+
return [this.x, this.y, new Fr(this.inf)];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
isOnGrumpkin() {
|
|
152
|
+
// TODO: Check this against how bb handles curve check and infinity point check
|
|
153
|
+
if (this.inf) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// p.y * p.y == p.x * p.x * p.x - 17
|
|
158
|
+
const A = new Fr(17);
|
|
159
|
+
const lhs = this.y.square();
|
|
160
|
+
const rhs = this.x.square().mul(this.x).sub(A);
|
|
161
|
+
return lhs.equals(rhs);
|
|
162
|
+
}
|
|
137
163
|
}
|
|
138
164
|
|
|
139
165
|
/**
|
package/src/fs/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './run_in_dir.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
// Create a random directory underneath a 'base' directory
|
|
5
|
+
// Calls a provided method, ensures the random directory is cleaned up afterwards
|
|
6
|
+
export async function runInDirectory<T>(
|
|
7
|
+
workingDirBase: string,
|
|
8
|
+
fn: (dir: string) => Promise<T>,
|
|
9
|
+
cleanup: boolean = true,
|
|
10
|
+
): Promise<T> {
|
|
11
|
+
// Create random directory to be used for temp files
|
|
12
|
+
const workingDirectory = await fs.mkdtemp(path.join(workingDirBase, 'tmp-'));
|
|
13
|
+
|
|
14
|
+
await fs.access(workingDirectory);
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
return await fn(workingDirectory);
|
|
18
|
+
} finally {
|
|
19
|
+
if (cleanup) {
|
|
20
|
+
await fs.rm(workingDirectory, { recursive: true, force: true });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * as errors from './error/index.js';
|
|
|
10
10
|
export * as ethAddress from './eth-address/index.js';
|
|
11
11
|
export * as fields from './fields/index.js';
|
|
12
12
|
export * as fifo from './fifo/index.js';
|
|
13
|
+
export * as fs from './fs/index.js';
|
|
13
14
|
export * as jsonRpc from './json-rpc/index.js';
|
|
14
15
|
export * as jsonRpcClient from './json-rpc/client/index.js';
|
|
15
16
|
export * as jsonRpcServer from './json-rpc/server/index.js';
|
|
@@ -10,7 +10,7 @@ export class RunningPromise {
|
|
|
10
10
|
private runningPromise = Promise.resolve();
|
|
11
11
|
private interruptibleSleep = new InterruptibleSleep();
|
|
12
12
|
|
|
13
|
-
constructor(private fn: () => Promise<void>, private pollingIntervalMS = 10000) {}
|
|
13
|
+
constructor(private fn: () => void | Promise<void>, private pollingIntervalMS = 10000) {}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Starts the running promise.
|
|
@@ -194,3 +194,11 @@ export function fromTruncField(field: Fr): Buffer {
|
|
|
194
194
|
export function fromFieldsTuple(fields: Tuple<Fr, 2>): Buffer {
|
|
195
195
|
return from2Fields(fields[0], fields[1]);
|
|
196
196
|
}
|
|
197
|
+
|
|
198
|
+
export function toHumanReadable(buf: Buffer, maxLen?: number): string {
|
|
199
|
+
const result = buf.every(byte => byte >= 32 && byte <= 126) ? buf.toString('ascii') : `0x${buf.toString('hex')}`;
|
|
200
|
+
if (maxLen && result.length > maxLen) {
|
|
201
|
+
return result.slice(0, maxLen) + '...';
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
@@ -242,6 +242,8 @@ export function toFriendlyJSON(obj: object): string {
|
|
|
242
242
|
).toFriendlyJSON
|
|
243
243
|
) {
|
|
244
244
|
return value.toFriendlyJSON();
|
|
245
|
+
} else if (value && value.type && ['Fr', 'Fq', 'AztecAddress'].includes(value.type)) {
|
|
246
|
+
return value.value;
|
|
245
247
|
} else {
|
|
246
248
|
return value;
|
|
247
249
|
}
|
package/src/testing/test_data.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { dirname, join, resolve } from 'path';
|
|
|
4
4
|
import { createConsoleLogger } from '../log/console.js';
|
|
5
5
|
import { fileURLToPath } from '../url/index.js';
|
|
6
6
|
|
|
7
|
-
const testData: { [key: string]:
|
|
7
|
+
const testData: { [key: string]: unknown[] } = {};
|
|
8
8
|
|
|
9
9
|
/** Returns whether test data generation is enabled */
|
|
10
10
|
export function isGenerateTestDataEnabled() {
|
|
@@ -12,7 +12,7 @@ export function isGenerateTestDataEnabled() {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/** Pushes test data with the given name, only if test data generation is enabled. */
|
|
15
|
-
export function pushTestData(itemName: string, data:
|
|
15
|
+
export function pushTestData<T>(itemName: string, data: T) {
|
|
16
16
|
if (!isGenerateTestDataEnabled()) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
@@ -31,7 +31,7 @@ export function pushTestData(itemName: string, data: { toBuffer(): Buffer }) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/** Returns all instances of pushed test data with the given name, or empty if test data generation is not enabled. */
|
|
34
|
-
export function getTestData(itemName: string):
|
|
34
|
+
export function getTestData(itemName: string): unknown[] {
|
|
35
35
|
if (!isGenerateTestDataEnabled()) {
|
|
36
36
|
return [];
|
|
37
37
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -12,3 +12,6 @@ export type FunctionsOf<T> = {
|
|
|
12
12
|
|
|
13
13
|
/** Marks a set of properties of a type as optional. */
|
|
14
14
|
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
15
|
+
|
|
16
|
+
/** Removes readonly modifiers for a type. */
|
|
17
|
+
export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
|