@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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type Deserializable = {
|
|
2
|
+
fromString(str: string): object;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Register a class here that has a toJSON method that returns:
|
|
6
|
+
* ```
|
|
7
|
+
* {
|
|
8
|
+
* "type": "ExampleClassName",
|
|
9
|
+
* "value": <result of ExampleClassName.toString()>
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
* and has an e.g. ExampleClassName.fromString(string) method.
|
|
13
|
+
* This means you can then easily serialize/deserialize the type using JSON.stringify and JSON.parse.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TypeRegistry {
|
|
16
|
+
private static registry;
|
|
17
|
+
static register(typeName: string, constructor: Deserializable): void;
|
|
18
|
+
static getConstructor(typeName: string): Deserializable | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare function resolver(_: any, value: any): any;
|
|
21
|
+
export declare function reviver(key: string, value: any): any;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=type_registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type_registry.d.ts","sourceRoot":"","sources":["../../src/serialize/type_registry.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IAAE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0C;WAEnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,GAAG,IAAI;WAI7D,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;CAG3E;AAGD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,OAE1C;AAGD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAW9C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register a class here that has a toJSON method that returns:
|
|
3
|
+
* ```
|
|
4
|
+
* {
|
|
5
|
+
* "type": "ExampleClassName",
|
|
6
|
+
* "value": <result of ExampleClassName.toString()>
|
|
7
|
+
* }
|
|
8
|
+
* ```
|
|
9
|
+
* and has an e.g. ExampleClassName.fromString(string) method.
|
|
10
|
+
* This means you can then easily serialize/deserialize the type using JSON.stringify and JSON.parse.
|
|
11
|
+
*/
|
|
12
|
+
export class TypeRegistry {
|
|
13
|
+
static register(typeName, constructor) {
|
|
14
|
+
this.registry.set(typeName, constructor);
|
|
15
|
+
}
|
|
16
|
+
static getConstructor(typeName) {
|
|
17
|
+
return this.registry.get(typeName);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
TypeRegistry.registry = new Map();
|
|
21
|
+
// Resolver function that enables JSON serialization of BigInts.
|
|
22
|
+
export function resolver(_, value) {
|
|
23
|
+
return typeof value === 'bigint' ? value.toString() + 'n' : value;
|
|
24
|
+
}
|
|
25
|
+
// Reviver function that uses TypeRegistry to instantiate objects.
|
|
26
|
+
export function reviver(key, value) {
|
|
27
|
+
if (typeof value === 'string' && /^\d+n$/.test(value)) {
|
|
28
|
+
return BigInt(value.slice(0, -1));
|
|
29
|
+
}
|
|
30
|
+
if (value && typeof value === 'object' && 'type' in value && 'value' in value) {
|
|
31
|
+
const Constructor = TypeRegistry.getConstructor(value.type);
|
|
32
|
+
if (Constructor) {
|
|
33
|
+
return Constructor.fromString(value.value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZV9yZWdpc3RyeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3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ssS0FBSyxRQUFRLElBQUksTUFBTSxJQUFJLEtBQUssSUFBSSxPQUFPLElBQUksS0FBSyxFQUFFLENBQUM7UUFDOUUsTUFBTSxXQUFXLEdBQUcsWUFBWSxDQUFDLGNBQWMsQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDNUQsSUFBSSxXQUFXLEVBQUUsQ0FBQztZQUNoQixPQUFPLFdBQVcsQ0FBQyxVQUFVLENBQUMsS0FBSyxDQUFDLEtBQUssQ0FBQyxDQUFDO1FBQzdDLENBQUM7SUFDSCxDQUFDO0lBQ0QsT0FBTyxLQUFLLENBQUM7QUFDZixDQUFDIn0=
|
|
@@ -18,8 +18,8 @@ export interface DispatchMsg {
|
|
|
18
18
|
* the method to be called ('fn') and an array of arguments to be passed to the method ('args').
|
|
19
19
|
*
|
|
20
20
|
* @param targetFn - A function that returns the target object containing the methods to be dispatched.
|
|
21
|
-
* @param
|
|
21
|
+
* @param log - Optional logging function for debugging purposes.
|
|
22
22
|
* @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
|
|
23
23
|
*/
|
|
24
|
-
export declare function createDispatchFn(targetFn: () => any,
|
|
24
|
+
export declare function createDispatchFn(targetFn: () => any, log?: import("../../log/logger.js").Logger): ({ fn, args }: DispatchMsg) => Promise<any>;
|
|
25
25
|
//# sourceMappingURL=create_dispatch_fn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create_dispatch_fn.d.ts","sourceRoot":"","sources":["../../../src/transport/dispatch/create_dispatch_fn.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"create_dispatch_fn.d.ts","sourceRoot":"","sources":["../../../src/transport/dispatch/create_dispatch_fn.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,GAAG,uCAAiD,kBAC5E,WAAW,kBAKxC"}
|
|
@@ -6,14 +6,14 @@ import { createDebugLogger } from '../../log/index.js';
|
|
|
6
6
|
* the method to be called ('fn') and an array of arguments to be passed to the method ('args').
|
|
7
7
|
*
|
|
8
8
|
* @param targetFn - A function that returns the target object containing the methods to be dispatched.
|
|
9
|
-
* @param
|
|
9
|
+
* @param log - Optional logging function for debugging purposes.
|
|
10
10
|
* @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
|
|
11
11
|
*/
|
|
12
|
-
export function createDispatchFn(targetFn,
|
|
12
|
+
export function createDispatchFn(targetFn, log = createDebugLogger('aztec:foundation:dispatch')) {
|
|
13
13
|
return async ({ fn, args }) => {
|
|
14
14
|
const target = targetFn();
|
|
15
|
-
debug(format(`dispatching to ${target}: ${fn}`, args));
|
|
15
|
+
log.debug(format(`dispatching to ${target}: ${fn}`, args));
|
|
16
16
|
return await target[fn](...args);
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlX2Rpc3BhdGNoX2ZuLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3RyYW5zcG9ydC9kaXNwYXRjaC9jcmVhdGVfZGlzcGF0Y2hfZm4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLE1BQU0sQ0FBQztBQUU5QixPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQWlCdkQ7Ozs7Ozs7O0dBUUc7QUFDSCxNQUFNLFVBQVUsZ0JBQWdCLENBQUMsUUFBbUIsRUFBRSxHQUFHLEdBQUcsaUJBQWlCLENBQUMsMkJBQTJCLENBQUM7SUFDeEcsT0FBTyxLQUFLLEVBQUUsRUFBRSxFQUFFLEVBQUUsSUFBSSxFQUFlLEVBQUUsRUFBRTtRQUN6QyxNQUFNLE1BQU0sR0FBRyxRQUFRLEVBQUUsQ0FBQztRQUMxQixHQUFHLENBQUMsS0FBSyxDQUFDLE1BQU0sQ0FBQyxrQkFBa0IsTUFBTSxLQUFLLEVBQUUsRUFBRSxFQUFFLElBQUksQ0FBQyxDQUFDLENBQUM7UUFDM0QsT0FBTyxNQUFNLE1BQU0sQ0FBQyxFQUFFLENBQUMsQ0FBQyxHQUFHLElBQUksQ0FBQyxDQUFDO0lBQ25DLENBQUMsQ0FBQztBQUNKLENBQUMifQ==
|
|
@@ -2,7 +2,7 @@ import EventEmitter from 'events';
|
|
|
2
2
|
import { format } from 'util';
|
|
3
3
|
import { createDebugLogger } from '../log/index.js';
|
|
4
4
|
import { isEventMessage } from './dispatch/messages.js';
|
|
5
|
-
const
|
|
5
|
+
const log = createDebugLogger('aztec:transport_client');
|
|
6
6
|
/**
|
|
7
7
|
* A TransportClient provides a request/response and event api to a corresponding TransportServer.
|
|
8
8
|
* If `broadcast` is called on TransportServer, TransportClients will emit an `event_msg`.
|
|
@@ -55,7 +55,7 @@ export class TransportClient extends EventEmitter {
|
|
|
55
55
|
}
|
|
56
56
|
const msgId = this.msgId++;
|
|
57
57
|
const msg = { msgId, payload };
|
|
58
|
-
debug(format(`->`, msg));
|
|
58
|
+
log.debug(format(`->`, msg));
|
|
59
59
|
return new Promise((resolve, reject) => {
|
|
60
60
|
this.pendingRequests.push({ resolve, reject, msgId });
|
|
61
61
|
this.socket.send(msg, transfer).catch(reject);
|
|
@@ -74,7 +74,7 @@ export class TransportClient extends EventEmitter {
|
|
|
74
74
|
this.close();
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
|
-
debug(format(`<-`, msg));
|
|
77
|
+
log.debug(format(`<-`, msg));
|
|
78
78
|
if (isEventMessage(msg)) {
|
|
79
79
|
this.emit('event_msg', msg.payload);
|
|
80
80
|
return;
|
|
@@ -92,4 +92,4 @@ export class TransportClient extends EventEmitter {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
95
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNwb3J0X2NsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90cmFuc3BvcnQvdHJhbnNwb3J0X2NsaWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLFlBQVksTUFBTSxRQUFRLENBQUM7QUFDbEMsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLE1BQU0sQ0FBQztBQUU5QixPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUNwRCxPQUFPLEVBQTJDLGNBQWMsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBSWpHLE1BQU0sR0FBRyxHQUFHLGlCQUFpQixDQUFDLHdCQUF3QixDQUFDLENBQUM7QUE4QnhEOzs7OztHQUtHO0FBQ0gsTUFBTSxPQUFPLGVBQXlCLFNBQVEsWUFBWTtJQUt4RCxZQUFvQixnQkFBMkI7UUFDN0MsS0FBSyxFQUFFLENBQUM7UUFEVSxxQkFBZ0IsR0FBaEIsZ0JBQWdCLENBQVc7UUFKdkMsVUFBSyxHQUFHLENBQUMsQ0FBQztRQUNWLG9CQUFlLEdBQXFCL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FLENBQUM7WUFDZCxPQUFPLENBQUMsTUFBTSxDQUFDLElBQUksS0FBSyxDQUFDLEdBQUcsQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDO1FBQ3ZDLENBQUM7YUFBTSxDQUFDO1lBQ04sT0FBTyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDL0IsQ0FBQztJQUNILENBQUM7Q0FDRiJ9
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDebugLogger } from '../log/index.js';
|
|
2
|
-
const
|
|
2
|
+
const log = createDebugLogger('bb:worker_pool');
|
|
3
3
|
/**
|
|
4
4
|
* Allocates a pool of WasmWorker's.
|
|
5
5
|
* Worker 0 is allocated MAX_PAGES memory pages. This is because worker 0 will need to hold the proving key
|
|
@@ -30,12 +30,12 @@ export class WorkerPool {
|
|
|
30
30
|
* @param maxMem - Max memory pages.
|
|
31
31
|
*/
|
|
32
32
|
async init(createWorker, poolSize, maxMem = WorkerPool.MAX_PAGES) {
|
|
33
|
-
debug(`creating ${poolSize} workers...`);
|
|
33
|
+
log.debug(`creating ${poolSize} workers...`);
|
|
34
34
|
const start = new Date().getTime();
|
|
35
35
|
this.workers = await Promise.all(Array(poolSize)
|
|
36
36
|
.fill(0)
|
|
37
37
|
.map((_, i) => createWorker(`${i}`, i === 0 ? Math.min(WorkerPool.MAX_PAGES, maxMem) : 768, maxMem)));
|
|
38
|
-
debug(`created workers: ${new Date().getTime() - start}ms`);
|
|
38
|
+
log.debug(`created workers: ${new Date().getTime() - start}ms`);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Tell all workers in the pool to stop processing.
|
|
@@ -59,4 +59,4 @@ export class WorkerPool {
|
|
|
59
59
|
* The maximum number of memory pages to be used by the webassembly.
|
|
60
60
|
*/
|
|
61
61
|
WorkerPool.MAX_PAGES = 8192;
|
|
62
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
62
|
+
//# sourceMappingUR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/index.js",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
]
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@aztec/bb.js": "0.
|
|
72
|
+
"@aztec/bb.js": "0.35.0",
|
|
73
73
|
"@koa/cors": "^5.0.0",
|
|
74
74
|
"@noble/curves": "^1.2.0",
|
|
75
75
|
"bn.js": "^5.2.1",
|
package/src/abi/abi.ts
CHANGED
|
@@ -383,27 +383,27 @@ export function getDefaultInitializer(contractArtifact: ContractArtifact): Funct
|
|
|
383
383
|
|
|
384
384
|
/**
|
|
385
385
|
* Returns an initializer from the contract.
|
|
386
|
-
* @param
|
|
386
|
+
* @param initializerNameOrArtifact - The name of the constructor, or the artifact of the constructor, or undefined
|
|
387
387
|
* to pick the default initializer.
|
|
388
388
|
*/
|
|
389
389
|
export function getInitializer(
|
|
390
390
|
contract: ContractArtifact,
|
|
391
|
-
|
|
391
|
+
initializerNameOrArtifact: string | undefined | FunctionArtifact,
|
|
392
392
|
): FunctionArtifact | undefined {
|
|
393
|
-
if (typeof
|
|
394
|
-
const found = contract.functions.find(f => f.name ===
|
|
393
|
+
if (typeof initializerNameOrArtifact === 'string') {
|
|
394
|
+
const found = contract.functions.find(f => f.name === initializerNameOrArtifact);
|
|
395
395
|
if (!found) {
|
|
396
|
-
throw new Error(`Constructor method ${
|
|
396
|
+
throw new Error(`Constructor method ${initializerNameOrArtifact} not found in contract artifact`);
|
|
397
397
|
} else if (!found.isInitializer) {
|
|
398
|
-
throw new Error(`Method ${
|
|
398
|
+
throw new Error(`Method ${initializerNameOrArtifact} is not an initializer`);
|
|
399
399
|
}
|
|
400
400
|
return found;
|
|
401
|
-
} else if (
|
|
401
|
+
} else if (initializerNameOrArtifact === undefined) {
|
|
402
402
|
return getDefaultInitializer(contract);
|
|
403
403
|
} else {
|
|
404
|
-
if (!
|
|
405
|
-
throw new Error(`Method ${
|
|
404
|
+
if (!initializerNameOrArtifact.isInitializer) {
|
|
405
|
+
throw new Error(`Method ${initializerNameOrArtifact.name} is not an initializer`);
|
|
406
406
|
}
|
|
407
|
-
return
|
|
407
|
+
return initializerNameOrArtifact;
|
|
408
408
|
}
|
|
409
409
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fromHex, toBigIntBE } from '../bigint-buffer/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { keccak256, randomBytes } from '../crypto/index.js';
|
|
3
3
|
import { type Fr } from '../fields/fields.js';
|
|
4
4
|
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
5
5
|
import { Selector } from './selector.js';
|
|
@@ -44,7 +44,7 @@ export class EventSelector extends Selector {
|
|
|
44
44
|
if (/\s/.test(signature)) {
|
|
45
45
|
throw new Error('Signature cannot contain whitespace');
|
|
46
46
|
}
|
|
47
|
-
return EventSelector.fromBuffer(
|
|
47
|
+
return EventSelector.fromBuffer(keccak256(Buffer.from(signature)).subarray(0, Selector.SIZE));
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fromHex, toBigIntBE } from '../bigint-buffer/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { keccak256, randomBytes } from '../crypto/index.js';
|
|
3
3
|
import { type Fr } from '../fields/fields.js';
|
|
4
4
|
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
5
5
|
import { FieldReader } from '../serialize/field_reader.js';
|
|
@@ -72,7 +72,7 @@ export class FunctionSelector extends Selector {
|
|
|
72
72
|
if (/\s/.test(signature)) {
|
|
73
73
|
throw new Error('Signature cannot contain whitespace');
|
|
74
74
|
}
|
|
75
|
-
return FunctionSelector.fromBuffer(
|
|
75
|
+
return FunctionSelector.fromBuffer(keccak256(Buffer.from(signature)).subarray(0, Selector.SIZE));
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -2,6 +2,7 @@ import { inspect } from 'util';
|
|
|
2
2
|
|
|
3
3
|
import { Fr, fromBuffer } from '../fields/index.js';
|
|
4
4
|
import { type BufferReader, FieldReader } from '../serialize/index.js';
|
|
5
|
+
import { TypeRegistry } from '../serialize/type_registry.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* AztecAddress represents a 32-byte address in the Aztec Protocol.
|
|
@@ -53,4 +54,14 @@ export class AztecAddress extends Fr {
|
|
|
53
54
|
static random() {
|
|
54
55
|
return new AztecAddress(super.random().toBuffer());
|
|
55
56
|
}
|
|
57
|
+
|
|
58
|
+
toJSON() {
|
|
59
|
+
return {
|
|
60
|
+
type: 'AztecAddress',
|
|
61
|
+
value: this.toString(),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
56
64
|
}
|
|
65
|
+
|
|
66
|
+
// For deserializing JSON.
|
|
67
|
+
TypeRegistry.register('AztecAddress', AztecAddress);
|
package/src/crypto/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { BarretenbergSync } from '@aztec/bb.js';
|
|
|
3
3
|
export * from './keccak/index.js';
|
|
4
4
|
export * from './random/index.js';
|
|
5
5
|
export * from './sha256/index.js';
|
|
6
|
+
export * from './sha512/index.js';
|
|
6
7
|
export * from './pedersen/index.js';
|
|
7
8
|
export * from './poseidon/index.js';
|
|
8
9
|
|
|
@@ -6,7 +6,7 @@ import { Keccak } from 'sha3';
|
|
|
6
6
|
* @param input - The input buffer to be hashed.
|
|
7
7
|
* @returns The computed Keccak-256 hash as a Buffer.
|
|
8
8
|
*/
|
|
9
|
-
export function
|
|
9
|
+
export function keccak256(input: Buffer) {
|
|
10
10
|
const hash = new Keccak(256);
|
|
11
11
|
return hash.update(input).digest();
|
|
12
12
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BarretenbergSync, Fr as FrBarretenberg } from '@aztec/bb.js';
|
|
2
2
|
|
|
3
3
|
import { Fr } from '../../fields/fields.js';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Create a pedersen commitment (point) from an array of input fields.
|
|
@@ -20,19 +20,17 @@ export function pedersenCommit(input: Buffer[]) {
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Create a pedersen hash (field) from an array of input fields.
|
|
23
|
-
*
|
|
23
|
+
* @param input - The input fieldables to hash.
|
|
24
|
+
* @param index - The separator index to use for the hash.
|
|
25
|
+
* @returns The pedersen hash.
|
|
24
26
|
*/
|
|
25
|
-
export function pedersenHash(input:
|
|
26
|
-
|
|
27
|
-
if (!bufferredInput.every(i => i.length <= 32)) {
|
|
28
|
-
throw new Error('All Pedersen Hash input buffers must be <= 32 bytes.');
|
|
29
|
-
}
|
|
30
|
-
bufferredInput = bufferredInput.map(i => (i.length < 32 ? Buffer.concat([Buffer.alloc(32 - i.length, 0), i]) : i));
|
|
27
|
+
export function pedersenHash(input: Fieldable[], index = 0): Fr {
|
|
28
|
+
const inputFields = serializeToFields(input);
|
|
31
29
|
return Fr.fromBuffer(
|
|
32
30
|
Buffer.from(
|
|
33
31
|
BarretenbergSync.getSingleton()
|
|
34
32
|
.pedersenHash(
|
|
35
|
-
|
|
33
|
+
inputFields.map(i => new FrBarretenberg(i.toBuffer())), // TODO(#4189): remove this stupid conversion
|
|
36
34
|
index,
|
|
37
35
|
)
|
|
38
36
|
.toBuffer(),
|
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
import { BarretenbergSync, Fr as FrBarretenberg } from '@aztec/bb.js';
|
|
2
2
|
|
|
3
3
|
import { Fr } from '../../fields/fields.js';
|
|
4
|
+
import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Create a poseidon hash (field) from an array of input fields.
|
|
7
|
-
*
|
|
8
|
+
* @param input - The input fields to hash.
|
|
9
|
+
* @returns The poseidon hash.
|
|
8
10
|
*/
|
|
9
|
-
export function
|
|
11
|
+
export function poseidon2Hash(input: Fieldable[]): Fr {
|
|
12
|
+
const inputFields = serializeToFields(input);
|
|
10
13
|
return Fr.fromBuffer(
|
|
11
14
|
Buffer.from(
|
|
12
15
|
BarretenbergSync.getSingleton()
|
|
13
|
-
.
|
|
16
|
+
.poseidon2Hash(
|
|
17
|
+
inputFields.map(i => new FrBarretenberg(i.toBuffer())), // TODO(#4189): remove this stupid conversion
|
|
18
|
+
)
|
|
14
19
|
.toBuffer(),
|
|
15
20
|
),
|
|
16
21
|
);
|
|
17
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Runs a Poseidon2 permutation.
|
|
26
|
+
* @param input the input state. Expected to be of size 4.
|
|
27
|
+
* @returns the output state, size 4.
|
|
28
|
+
*/
|
|
29
|
+
export function poseidon2Permutation(input: Fieldable[]): Fr[] {
|
|
30
|
+
const inputFields = serializeToFields(input);
|
|
31
|
+
// We'd like this assertion but it's not possible to use it in the browser.
|
|
32
|
+
// assert(input.length === 4, 'Input state must be of size 4');
|
|
33
|
+
const res = BarretenbergSync.getSingleton().poseidon2Permutation(
|
|
34
|
+
inputFields.map(i => new FrBarretenberg(i.toBuffer())),
|
|
35
|
+
);
|
|
36
|
+
// We'd like this assertion but it's not possible to use it in the browser.
|
|
37
|
+
// assert(res.length === 4, 'Output state must be of size 4');
|
|
38
|
+
return res.map(o => Fr.fromBuffer(Buffer.from(o.toBuffer())));
|
|
39
|
+
}
|
|
@@ -18,10 +18,10 @@ export class RandomnessSingleton {
|
|
|
18
18
|
private readonly log = createDebugLogger('aztec:randomness_singleton'),
|
|
19
19
|
) {
|
|
20
20
|
if (seed !== undefined) {
|
|
21
|
-
this.log(`Using pseudo-randomness with seed: ${seed}`);
|
|
21
|
+
this.log.info(`Using pseudo-randomness with seed: ${seed}`);
|
|
22
22
|
this.counter = seed;
|
|
23
23
|
} else {
|
|
24
|
-
this.log('Using true randomness');
|
|
24
|
+
this.log.info('Using true randomness');
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { default as hash } from 'hash.js';
|
|
2
|
+
|
|
3
|
+
import { GrumpkinScalar } from '../../fields/fields.js';
|
|
4
|
+
import { type Bufferable, serializeToBuffer } from '../../serialize/serialize.js';
|
|
5
|
+
|
|
6
|
+
export const sha512 = (data: Buffer) => Buffer.from(hash.sha512().update(data).digest());
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @dev We don't truncate in this function (unlike in sha256ToField) because this function is used in situations where
|
|
10
|
+
* we don't care only about collision resistance but we need the output to be uniformly distributed as well. This is
|
|
11
|
+
* because we use it as a pseudo-random function.
|
|
12
|
+
*/
|
|
13
|
+
export const sha512ToGrumpkinScalar = (data: Bufferable[]) => {
|
|
14
|
+
const buffer = serializeToBuffer(data);
|
|
15
|
+
return GrumpkinScalar.fromBufferReduce(sha512(buffer));
|
|
16
|
+
};
|
package/src/eth-address/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { keccak256String } from '../crypto/keccak/index.js';
|
|
|
4
4
|
import { randomBytes } from '../crypto/random/index.js';
|
|
5
5
|
import { Fr } from '../fields/index.js';
|
|
6
6
|
import { BufferReader, FieldReader } from '../serialize/index.js';
|
|
7
|
+
import { TypeRegistry } from '../serialize/type_registry.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Represents an Ethereum address as a 20-byte buffer and provides various utility methods
|
|
@@ -236,4 +237,14 @@ export class EthAddress {
|
|
|
236
237
|
toFriendlyJSON() {
|
|
237
238
|
return this.toString();
|
|
238
239
|
}
|
|
240
|
+
|
|
241
|
+
toJSON() {
|
|
242
|
+
return {
|
|
243
|
+
type: 'EthAddress',
|
|
244
|
+
value: this.toString(),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
239
247
|
}
|
|
248
|
+
|
|
249
|
+
// For deserializing JSON.
|
|
250
|
+
TypeRegistry.register('EthAddress', EthAddress);
|
package/src/fields/fields.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { inspect } from 'util';
|
|
|
3
3
|
import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
|
|
4
4
|
import { randomBytes } from '../crypto/random/index.js';
|
|
5
5
|
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
6
|
+
import { TypeRegistry } from '../serialize/type_registry.js';
|
|
6
7
|
|
|
7
8
|
const ZERO_BUFFER = Buffer.alloc(32);
|
|
8
9
|
|
|
@@ -187,6 +188,7 @@ export interface Fr {
|
|
|
187
188
|
*/
|
|
188
189
|
export class Fr extends BaseField {
|
|
189
190
|
static ZERO = new Fr(0n);
|
|
191
|
+
static ONE = new Fr(1n);
|
|
190
192
|
static MODULUS = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001n;
|
|
191
193
|
|
|
192
194
|
constructor(value: number | bigint | boolean | Fr | Buffer) {
|
|
@@ -257,8 +259,18 @@ export class Fr extends BaseField {
|
|
|
257
259
|
|
|
258
260
|
return new Fr(this.toBigInt() / rhs.toBigInt());
|
|
259
261
|
}
|
|
262
|
+
|
|
263
|
+
toJSON() {
|
|
264
|
+
return {
|
|
265
|
+
type: 'Fr',
|
|
266
|
+
value: this.toString(),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
260
269
|
}
|
|
261
270
|
|
|
271
|
+
// For deserializing JSON.
|
|
272
|
+
TypeRegistry.register('Fr', Fr);
|
|
273
|
+
|
|
262
274
|
/**
|
|
263
275
|
* Branding to ensure fields are not interchangeable types.
|
|
264
276
|
*/
|
|
@@ -319,8 +331,18 @@ export class Fq extends BaseField {
|
|
|
319
331
|
static fromHighLow(high: Fr, low: Fr): Fq {
|
|
320
332
|
return new Fq((high.toBigInt() << Fq.HIGH_SHIFT) + low.toBigInt());
|
|
321
333
|
}
|
|
334
|
+
|
|
335
|
+
toJSON() {
|
|
336
|
+
return {
|
|
337
|
+
type: 'Fq',
|
|
338
|
+
value: this.toString(),
|
|
339
|
+
};
|
|
340
|
+
}
|
|
322
341
|
}
|
|
323
342
|
|
|
343
|
+
// For deserializing JSON.
|
|
344
|
+
TypeRegistry.register('Fq', Fq);
|
|
345
|
+
|
|
324
346
|
// Beware: Performance bottleneck below
|
|
325
347
|
|
|
326
348
|
/**
|
|
@@ -351,7 +373,7 @@ function extendedEuclidean(a: bigint, modulus: bigint): [bigint, bigint, bigint]
|
|
|
351
373
|
/**
|
|
352
374
|
* GrumpkinScalar is an Fq.
|
|
353
375
|
* @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
|
|
354
|
-
* the Aztec
|
|
376
|
+
* the Aztec Protocol Specs.
|
|
355
377
|
*/
|
|
356
378
|
export type GrumpkinScalar = Fq;
|
|
357
379
|
export const GrumpkinScalar = Fq;
|
|
@@ -12,14 +12,14 @@ import { JsonStringify, convertFromJsonObj, convertToJsonObj } from '../convert.
|
|
|
12
12
|
|
|
13
13
|
export { JsonStringify } from '../convert.js';
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const log = createDebugLogger('json-rpc:json_rpc_client');
|
|
16
16
|
/**
|
|
17
17
|
* A normal fetch function that does not retry.
|
|
18
18
|
* Alternatives are a fetch function with retries, or a mocked fetch.
|
|
19
19
|
* @param host - The host URL.
|
|
20
20
|
* @param method - The RPC method name.
|
|
21
21
|
* @param body - The RPC payload.
|
|
22
|
-
* @param noRetry - Whether to throw a `NoRetryError` in case the response is
|
|
22
|
+
* @param noRetry - Whether to throw a `NoRetryError` in case the response is a 5xx error and the body contains an error
|
|
23
23
|
* message (see `retry` function for more details).
|
|
24
24
|
* @returns The parsed JSON response, or throws an error.
|
|
25
25
|
*/
|
|
@@ -30,7 +30,7 @@ export async function defaultFetch(
|
|
|
30
30
|
useApiEndpoints: boolean,
|
|
31
31
|
noRetry = false,
|
|
32
32
|
) {
|
|
33
|
-
debug(format(`JsonRpcClient.fetch`, host, rpcMethod, '->', body));
|
|
33
|
+
log.debug(format(`JsonRpcClient.fetch`, host, rpcMethod, '->', body));
|
|
34
34
|
let resp: Response;
|
|
35
35
|
if (useApiEndpoints) {
|
|
36
36
|
resp = await fetch(`${host}/${rpcMethod}`, {
|
|
@@ -56,7 +56,7 @@ export async function defaultFetch(
|
|
|
56
56
|
throw new Error(`Failed to parse body as JSON: ${resp.text()}`);
|
|
57
57
|
}
|
|
58
58
|
if (!resp.ok) {
|
|
59
|
-
if (noRetry) {
|
|
59
|
+
if (noRetry || (resp.status >= 400 && resp.status < 500)) {
|
|
60
60
|
throw new NoRetryError('(JSON-RPC PROPAGATED) ' + responseJson.error.message);
|
|
61
61
|
} else {
|
|
62
62
|
throw new Error('(JSON-RPC PROPAGATED) ' + responseJson.error.message);
|
|
@@ -112,9 +112,9 @@ export function createJsonRpcClient<T extends object>(
|
|
|
112
112
|
method,
|
|
113
113
|
params: params.map(param => convertToJsonObj(classConverter, param)),
|
|
114
114
|
};
|
|
115
|
-
debug(format(`JsonRpcClient.request`, method, '<-', params));
|
|
115
|
+
log.debug(format(`JsonRpcClient.request`, method, '<-', params));
|
|
116
116
|
const res = await fetch(host, method, body, useApiEndpoints);
|
|
117
|
-
debug(format(`JsonRpcClient.result`, method, '->', res));
|
|
117
|
+
log.debug(format(`JsonRpcClient.result`, method, '->', res));
|
|
118
118
|
if (res.error) {
|
|
119
119
|
throw res.error;
|
|
120
120
|
}
|
|
@@ -138,7 +138,7 @@ export function createJsonRpcClient<T extends object>(
|
|
|
138
138
|
return Reflect.get(target, method);
|
|
139
139
|
}
|
|
140
140
|
return (...params: any[]) => {
|
|
141
|
-
debug(format(`JsonRpcClient.constructor`, 'proxy', rpcMethod, '<-', params));
|
|
141
|
+
log.debug(format(`JsonRpcClient.constructor`, 'proxy', rpcMethod, '<-', params));
|
|
142
142
|
return request(rpcMethod, params);
|
|
143
143
|
};
|
|
144
144
|
},
|
|
@@ -5,7 +5,7 @@ import { ClassConverter, type JsonClassConverterInput, type StringClassConverter
|
|
|
5
5
|
import { convertFromJsonObj, convertToJsonObj } from '../convert.js';
|
|
6
6
|
import { assert, hasOwnProperty } from '../js_utils.js';
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const log = createDebugLogger('json-rpc:json_proxy');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* A map of class names to class constructors.
|
|
@@ -38,7 +38,7 @@ export class JsonProxy {
|
|
|
38
38
|
* @returns The remote result.
|
|
39
39
|
*/
|
|
40
40
|
public async call(methodName: string, jsonParams: any[] = [], skipConversion = false) {
|
|
41
|
-
debug(format(`JsonProxy:call`, methodName, jsonParams));
|
|
41
|
+
log.debug(format(`JsonProxy:call`, methodName, jsonParams));
|
|
42
42
|
// Get access to our class members
|
|
43
43
|
const proto = Object.getPrototypeOf(this.handler);
|
|
44
44
|
assert(hasOwnProperty(proto, methodName), `JsonProxy: Method ${methodName} not found!`);
|
|
@@ -48,13 +48,13 @@ export class JsonProxy {
|
|
|
48
48
|
if (!skipConversion) {
|
|
49
49
|
convertedParams = jsonParams.map(param => convertFromJsonObj(this.classConverter, param));
|
|
50
50
|
}
|
|
51
|
-
debug(format('JsonProxy:call', methodName, '<-', convertedParams));
|
|
51
|
+
log.debug(format('JsonProxy:call', methodName, '<-', convertedParams));
|
|
52
52
|
const rawRet = await (this.handler as any)[methodName](...convertedParams);
|
|
53
53
|
let ret = rawRet;
|
|
54
54
|
if (!skipConversion) {
|
|
55
55
|
ret = convertToJsonObj(this.classConverter, rawRet);
|
|
56
56
|
}
|
|
57
|
-
debug(format('JsonProxy:call', methodName, '->', ret));
|
|
57
|
+
log.debug(format('JsonProxy:call', methodName, '->', ret));
|
|
58
58
|
return ret;
|
|
59
59
|
}
|
|
60
60
|
}
|