@aztec/foundation 0.65.0 → 0.65.2
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 +9 -9
- package/dest/abi/abi.js +2 -2
- package/dest/abi/event_selector.d.ts +2 -4
- package/dest/abi/event_selector.d.ts.map +1 -1
- package/dest/abi/event_selector.js +6 -5
- package/dest/abi/function_selector.d.ts +2 -4
- package/dest/abi/function_selector.d.ts.map +1 -1
- package/dest/abi/function_selector.js +6 -5
- package/dest/abi/note_selector.d.ts +2 -5
- package/dest/abi/note_selector.d.ts.map +1 -1
- package/dest/abi/note_selector.js +5 -7
- package/dest/abi/selector.d.ts.map +1 -1
- package/dest/abi/selector.js +3 -2
- package/dest/aztec-address/index.d.ts +2 -4
- package/dest/aztec-address/index.d.ts.map +1 -1
- package/dest/aztec-address/index.js +6 -5
- package/dest/buffer/buffer32.d.ts +2 -12
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +3 -16
- package/dest/config/env_var.d.ts +1 -1
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +1 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +2 -2
- package/dest/crypto/poseidon/index.d.ts +1 -0
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +7 -1
- package/dest/eth-address/index.d.ts +2 -9
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +7 -12
- package/dest/eth-signature/eth_signature.d.ts +5 -3
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/eth_signature.js +18 -9
- package/dest/fields/fields.d.ts +4 -8
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +10 -10
- package/dest/fields/point.d.ts +6 -4
- package/dest/fields/point.d.ts.map +1 -1
- package/dest/fields/point.js +14 -6
- package/dest/json-rpc/client/fetch.d.ts.map +1 -1
- package/dest/json-rpc/client/fetch.js +20 -14
- package/dest/json-rpc/convert.d.ts.map +1 -1
- package/dest/json-rpc/convert.js +5 -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/noir/noir_package_config.d.ts +2 -2
- package/dest/schemas/schemas.d.ts +24 -43
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +29 -48
- package/dest/schemas/utils.d.ts +18 -7
- package/dest/schemas/utils.d.ts.map +1 -1
- package/dest/schemas/utils.js +20 -8
- package/dest/serialize/type_registry.d.ts.map +1 -1
- package/dest/serialize/type_registry.js +29 -2
- package/dest/string/index.d.ts +1 -0
- package/dest/string/index.d.ts.map +1 -1
- package/dest/string/index.js +4 -1
- package/dest/testing/test_data.js +2 -2
- package/package.json +2 -2
- package/src/abi/abi.ts +1 -1
- package/src/abi/event_selector.ts +6 -4
- package/src/abi/function_selector.ts +6 -4
- package/src/abi/note_selector.ts +4 -6
- package/src/abi/selector.ts +2 -1
- package/src/aztec-address/index.ts +6 -4
- package/src/buffer/buffer32.ts +3 -17
- package/src/config/env_var.ts +11 -2
- package/src/config/index.ts +1 -1
- package/src/crypto/poseidon/index.ts +11 -0
- package/src/eth-address/index.ts +6 -11
- package/src/eth-signature/eth_signature.ts +20 -9
- package/src/fields/fields.ts +11 -9
- package/src/fields/point.ts +15 -5
- package/src/json-rpc/client/fetch.ts +18 -13
- package/src/json-rpc/convert.ts +3 -1
- package/src/json-rpc/index.ts +1 -1
- package/src/schemas/schemas.ts +28 -51
- package/src/schemas/utils.ts +29 -10
- package/src/serialize/type_registry.ts +33 -1
- package/src/string/index.ts +4 -0
- package/src/testing/test_data.ts +1 -1
package/src/schemas/utils.ts
CHANGED
|
@@ -15,6 +15,17 @@ import { type ZodFor } from './types.js';
|
|
|
15
15
|
|
|
16
16
|
export const hexSchema = z.string().refine(isHex, 'Not a valid hex string').transform(withoutHexPrefix);
|
|
17
17
|
|
|
18
|
+
// Copied from zod internals, which was copied from https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
19
|
+
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
20
|
+
|
|
21
|
+
/** Schema for a buffer represented as a base64 string. */
|
|
22
|
+
export const bufferSchema = z
|
|
23
|
+
.string()
|
|
24
|
+
// We only test the str for base64 if it's shorter than 1024 bytes, otherwise we've run into maximum
|
|
25
|
+
// stack size exceeded errors when trying to validate excessively long strings (such as contract bytecode).
|
|
26
|
+
.refine(str => str.length > 1024 || base64Regex.test(str), 'Not a valid base64 string')
|
|
27
|
+
.transform(data => Buffer.from(data, 'base64'));
|
|
28
|
+
|
|
18
29
|
export class ZodNullableOptional<T extends ZodTypeAny> extends ZodOptional<T> {
|
|
19
30
|
_isNullableOptional = true;
|
|
20
31
|
|
|
@@ -43,6 +54,8 @@ export function optional<T extends ZodTypeAny>(schema: T) {
|
|
|
43
54
|
return ZodNullableOptional.create(schema);
|
|
44
55
|
}
|
|
45
56
|
|
|
57
|
+
type ToJsonIs<T, TRet> = T extends { toJSON(): TRet } ? T : never;
|
|
58
|
+
|
|
46
59
|
/**
|
|
47
60
|
* Creates a schema that accepts a hex string and uses it to hydrate an instance.
|
|
48
61
|
* @param klazz - Class that implements either fromString or fromBuffer.
|
|
@@ -50,28 +63,34 @@ export function optional<T extends ZodTypeAny>(schema: T) {
|
|
|
50
63
|
*/
|
|
51
64
|
export function hexSchemaFor<TClass extends { fromString(str: string): any } | { fromBuffer(buf: Buffer): any }>(
|
|
52
65
|
klazz: TClass,
|
|
66
|
+
refinement?: (input: string) => boolean,
|
|
53
67
|
): ZodType<
|
|
54
68
|
TClass extends { fromString(str: string): infer TInstance } | { fromBuffer(buf: Buffer): infer TInstance }
|
|
55
|
-
? TInstance
|
|
69
|
+
? ToJsonIs<TInstance, string>
|
|
56
70
|
: never,
|
|
57
71
|
any,
|
|
58
72
|
string
|
|
59
73
|
> {
|
|
74
|
+
const stringSchema = refinement ? z.string().refine(refinement, `Not a valid instance`) : z.string();
|
|
75
|
+
const hexSchema = stringSchema.refine(isHex, 'Not a valid hex string').transform(withoutHexPrefix);
|
|
60
76
|
return 'fromString' in klazz
|
|
61
77
|
? hexSchema.transform(klazz.fromString.bind(klazz))
|
|
62
78
|
: hexSchema.transform(str => Buffer.from(str, 'hex')).transform(klazz.fromBuffer.bind(klazz));
|
|
63
79
|
}
|
|
64
80
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Creates a schema that accepts a base64 string and uses it to hydrate an instance.
|
|
83
|
+
* @param klazz - Class that implements fromBuffer.
|
|
84
|
+
* @returns A schema for the class.
|
|
85
|
+
*/
|
|
86
|
+
export function bufferSchemaFor<TClass extends { fromBuffer(buf: Buffer): any }>(
|
|
68
87
|
klazz: TClass,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
): ZodType<
|
|
89
|
+
TClass extends { fromBuffer(buf: Buffer): infer TInstance } ? ToJsonIs<TInstance, Buffer> : never,
|
|
90
|
+
any,
|
|
91
|
+
string
|
|
92
|
+
> {
|
|
93
|
+
return bufferSchema.transform(klazz.fromBuffer.bind(klazz));
|
|
75
94
|
}
|
|
76
95
|
|
|
77
96
|
/** Creates a schema for a js Map type that matches the serialization used in jsonStringify. */
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { mapValues } from '../collection/object.js';
|
|
2
|
+
|
|
1
3
|
type Deserializable = { fromString(str: string): object };
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -23,9 +25,39 @@ export class TypeRegistry {
|
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
function replace<T>(value: T) {
|
|
29
|
+
if (
|
|
30
|
+
value &&
|
|
31
|
+
typeof value === 'object' &&
|
|
32
|
+
'toString' in value &&
|
|
33
|
+
TypeRegistry.getConstructor(value.constructor.name)
|
|
34
|
+
) {
|
|
35
|
+
return {
|
|
36
|
+
type: value.constructor.name,
|
|
37
|
+
value: value.toString(),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
// Resolver function that enables JSON serialization of BigInts.
|
|
27
45
|
export function resolver(_: any, value: any) {
|
|
28
|
-
|
|
46
|
+
if (typeof value === 'bigint') {
|
|
47
|
+
return value.toString() + 'n';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (typeof value === 'object' && value) {
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
return value.map(replace);
|
|
53
|
+
} else if (Buffer.isBuffer(value)) {
|
|
54
|
+
return { type: 'buffer', value: value.toString('hex') };
|
|
55
|
+
} else {
|
|
56
|
+
return mapValues(value, replace);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return value;
|
|
29
61
|
}
|
|
30
62
|
|
|
31
63
|
// Reviver function that uses TypeRegistry to instantiate objects.
|
package/src/string/index.ts
CHANGED
|
@@ -14,6 +14,10 @@ export function hexToBuffer(str: string): Buffer {
|
|
|
14
14
|
return Buffer.from(withoutHexPrefix(str), 'hex');
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export function bufferToHex(buffer: Buffer): `0x${string}` {
|
|
18
|
+
return `0x${buffer.toString('hex')}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
export function pluralize(str: string, count: number | bigint, plural?: string): string {
|
|
18
22
|
return count === 1 || count === 1n ? str : plural ?? `${str}s`;
|
|
19
23
|
}
|
package/src/testing/test_data.ts
CHANGED
|
@@ -66,7 +66,7 @@ export function updateInlineTestData(targetFileFromRepoRoot: string, itemName: s
|
|
|
66
66
|
const logger = createConsoleLogger('aztec:testing:test_data');
|
|
67
67
|
const targetFile = getPathToFile(targetFileFromRepoRoot);
|
|
68
68
|
const contents = readFileSync(targetFile, 'utf8').toString();
|
|
69
|
-
const regex = new RegExp(`let ${itemName} =
|
|
69
|
+
const regex = new RegExp(`let ${itemName} =[\\s\\S]*?;`, 'g');
|
|
70
70
|
if (!regex.exec(contents)) {
|
|
71
71
|
throw new Error(`Test data marker for ${itemName} not found in ${targetFile}`);
|
|
72
72
|
}
|