@aztec/foundation 0.1.0-alpha22 → 0.1.0-alpha24
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/.prettierrc.json +9 -2
- package/.tsbuildinfo +1 -1
- package/dest/abi/abi.d.ts +137 -0
- package/dest/abi/abi.d.ts.map +1 -0
- package/dest/abi/abi.js +18 -0
- package/dest/abi/abi_coder.d.ts +35 -0
- package/dest/abi/abi_coder.d.ts.map +1 -0
- package/dest/abi/abi_coder.js +58 -0
- package/dest/abi/decoder.d.ts +19 -0
- package/dest/abi/decoder.d.ts.map +1 -0
- package/dest/abi/decoder.js +71 -0
- package/dest/abi/encoder.d.ts +10 -0
- package/dest/abi/encoder.d.ts.map +1 -0
- package/dest/abi/encoder.js +80 -0
- package/dest/abi/index.d.ts +4 -136
- package/dest/abi/index.d.ts.map +1 -1
- package/dest/abi/index.js +5 -18
- package/dest/aztec-address/index.d.ts +7 -0
- package/dest/aztec-address/index.d.ts.map +1 -1
- package/dest/aztec-address/index.js +10 -1
- package/dest/crypto/random/index.js +2 -2
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +1 -1
- package/dest/crypto/sha256/index.test.js +2 -2
- package/dest/fields/fields.d.ts +6 -0
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +10 -2
- package/dest/fields/point.d.ts +8 -23
- package/dest/fields/point.d.ts.map +1 -1
- package/dest/fields/point.js +10 -31
- package/dest/json-rpc/client/json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/json_rpc_client.js +1 -1
- package/dest/json-rpc/client/json_rpc_client.test.js +2 -2
- package/dest/json-rpc/convert.d.ts.map +1 -1
- package/dest/json-rpc/convert.js +1 -1
- package/dest/json-rpc/convert.test.js +2 -2
- package/dest/json-rpc/server/json_proxy.d.ts +1 -1
- package/dest/json-rpc/server/json_proxy.d.ts.map +1 -1
- package/dest/json-rpc/server/json_rpc_server.d.ts +1 -1
- package/dest/json-rpc/server/json_rpc_server.d.ts.map +1 -1
- package/dest/json-rpc/server/json_rpc_server.js +5 -5
- package/dest/json-rpc/server/json_rpc_server.test.js +2 -2
- package/dest/log/log_history.test.js +1 -1
- package/dest/mutex/mutex.test.d.ts.map +1 -1
- package/dest/mutex/mutex.test.js +1 -1
- package/dest/serialize/buffer_reader.d.ts +1 -1
- package/dest/serialize/buffer_reader.js +1 -1
- package/dest/serialize/buffer_reader.test.js +2 -2
- package/dest/serialize/serialize.test.js +2 -2
- package/dest/serialize/serializer.js +2 -2
- package/dest/transport/browser/shared_worker_listener.d.ts.map +1 -1
- package/dest/transport/browser/shared_worker_listener.js +1 -1
- package/dest/transport/browser/worker_listener.d.ts.map +1 -1
- package/dest/transport/browser/worker_listener.js +1 -1
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts +2 -2
- package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_proxy.js +1 -1
- package/dest/transport/interface/listener.d.ts.map +1 -1
- package/dest/transport/node/node_connector.d.ts.map +1 -1
- package/dest/transport/node/node_connector.js +1 -1
- package/dest/transport/node/node_connector_socket.d.ts.map +1 -1
- package/dest/transport/node/node_connector_socket.js +1 -1
- package/dest/transport/node/node_listener.d.ts.map +1 -1
- package/dest/transport/node/node_listener.js +2 -2
- package/dest/transport/node/node_listener_socket.d.ts.map +1 -1
- package/dest/transport/node/node_listener_socket.js +1 -1
- package/dest/transport/transport_client.d.ts.map +1 -1
- package/dest/transport/transport_client.js +2 -2
- package/dest/wasm/wasm/wasm_module.d.ts.map +1 -1
- package/dest/wasm/wasm/wasm_module.js +2 -2
- package/dest/wasm/wasm/wasm_module.test.js +3 -3
- package/dest/wasm/worker/browser/web_data_store.d.ts.map +1 -1
- package/dest/wasm/worker/browser/web_data_store.js +1 -1
- package/dest/wasm/worker/node/node_data_store.d.ts.map +1 -1
- package/dest/wasm/worker/node/node_data_store.js +2 -2
- package/dest/wasm/worker/node/node_worker.d.ts.map +1 -1
- package/dest/wasm/worker/node/node_worker.js +2 -2
- package/dest/wasm/worker/node/start_node_module.d.ts.map +1 -1
- package/dest/wasm/worker/node/start_node_module.js +1 -1
- package/package.json +1 -1
- package/src/abi/abi.ts +147 -0
- package/src/abi/abi_coder.ts +62 -0
- package/src/abi/decoder.ts +79 -0
- package/src/abi/encoder.ts +79 -0
- package/src/abi/index.ts +4 -147
- package/src/aztec-address/index.ts +10 -0
- package/src/crypto/random/index.ts +1 -1
- package/src/crypto/sha256/index.test.ts +2 -1
- package/src/crypto/sha256/index.ts +1 -0
- package/src/fields/fields.ts +12 -2
- package/src/fields/point.ts +11 -34
- package/src/json-rpc/client/json_rpc_client.test.ts +2 -1
- package/src/json-rpc/client/json_rpc_client.ts +2 -1
- package/src/json-rpc/convert.test.ts +2 -2
- package/src/json-rpc/convert.ts +2 -1
- package/src/json-rpc/server/json_proxy.ts +1 -1
- package/src/json-rpc/server/json_rpc_server.test.ts +2 -1
- package/src/json-rpc/server/json_rpc_server.ts +5 -5
- package/src/log/log_history.test.ts +1 -0
- package/src/mutex/mutex.test.ts +1 -0
- package/src/serialize/buffer_reader.test.ts +2 -1
- package/src/serialize/buffer_reader.ts +1 -1
- package/src/serialize/serialize.test.ts +3 -3
- package/src/serialize/serializer.ts +1 -1
- package/src/transport/browser/shared_worker_listener.ts +1 -0
- package/src/transport/browser/worker_listener.ts +1 -0
- package/src/transport/dispatch/create_dispatch_proxy.ts +4 -3
- package/src/transport/interface/listener.ts +1 -0
- package/src/transport/node/node_connector.ts +1 -0
- package/src/transport/node/node_connector_socket.ts +1 -0
- package/src/transport/node/node_listener.ts +2 -1
- package/src/transport/node/node_listener_socket.ts +1 -0
- package/src/transport/transport_client.ts +3 -2
- package/src/wasm/wasm/wasm_module.test.ts +3 -2
- package/src/wasm/wasm/wasm_module.ts +3 -2
- package/src/wasm/worker/browser/web_data_store.ts +2 -1
- package/src/wasm/worker/node/node_data_store.ts +3 -2
- package/src/wasm/worker/node/node_worker.ts +2 -1
- package/src/wasm/worker/node/start_node_module.ts +2 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ABIType, FunctionAbi } from '@aztec/foundation/abi';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The type of our decoded ABI.
|
|
6
|
+
*/
|
|
7
|
+
type DecodedReturn = bigint | boolean | DecodedReturn[] | { [key: string]: DecodedReturn };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Decodes return values from a function call.
|
|
11
|
+
* Missing support for integer and string.
|
|
12
|
+
*/
|
|
13
|
+
class ReturnValuesDecoder {
|
|
14
|
+
constructor(private abi: FunctionAbi, private flattened: Fr[]) {}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Decodes a single return value from field to the given type.
|
|
18
|
+
* @param abiType - The type of the return value.
|
|
19
|
+
* @returns The decoded return value.
|
|
20
|
+
*/
|
|
21
|
+
private decodeReturn(abiType: ABIType): DecodedReturn {
|
|
22
|
+
switch (abiType.kind) {
|
|
23
|
+
case 'field':
|
|
24
|
+
return this.getNextField().value;
|
|
25
|
+
case 'boolean':
|
|
26
|
+
return !this.getNextField().isZero();
|
|
27
|
+
case 'array': {
|
|
28
|
+
const array = [];
|
|
29
|
+
for (let i = 0; i < abiType.length; i += 1) {
|
|
30
|
+
array.push(this.decodeReturn(abiType.type));
|
|
31
|
+
}
|
|
32
|
+
return array;
|
|
33
|
+
}
|
|
34
|
+
case 'struct': {
|
|
35
|
+
const struct: { [key: string]: DecodedReturn } = {};
|
|
36
|
+
for (const field of abiType.fields) {
|
|
37
|
+
struct[field.name] = this.decodeReturn(field.type);
|
|
38
|
+
}
|
|
39
|
+
return struct;
|
|
40
|
+
}
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`Unsupported type: ${abiType.kind}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Gets the next field in the flattened return values.
|
|
48
|
+
* @returns The next field in the flattened return values.
|
|
49
|
+
*/
|
|
50
|
+
private getNextField(): Fr {
|
|
51
|
+
const field = this.flattened.shift();
|
|
52
|
+
if (!field) {
|
|
53
|
+
throw new Error('Not enough return values');
|
|
54
|
+
}
|
|
55
|
+
return field;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Decodes all the return values for the given function ABI.
|
|
60
|
+
* @returns The decoded return values.
|
|
61
|
+
*/
|
|
62
|
+
public decode() {
|
|
63
|
+
const returnValues = [];
|
|
64
|
+
for (let i = 0; i < this.abi.returnTypes.length; i += 1) {
|
|
65
|
+
returnValues.push(this.decodeReturn(this.abi.returnTypes[i]));
|
|
66
|
+
}
|
|
67
|
+
return returnValues;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Decodes return values from a function call.
|
|
73
|
+
* @param abi - The ABI entry of the function.
|
|
74
|
+
* @param returnValues - The decoded return values.
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
export function decodeReturnValues(abi: FunctionAbi, returnValues: Fr[]) {
|
|
78
|
+
return new ReturnValuesDecoder(abi, returnValues.slice()).decode();
|
|
79
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ABIType, FunctionAbi } from '@aztec/foundation/abi';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Encodes arguments for a function call.
|
|
6
|
+
* Missing support for integer and string.
|
|
7
|
+
*/
|
|
8
|
+
class ArgumentEncoder {
|
|
9
|
+
private flattened: Fr[] = [];
|
|
10
|
+
|
|
11
|
+
constructor(private abi: FunctionAbi, private args: any[]) {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Encodes a single argument from the given type to field.
|
|
15
|
+
* @param abiType - The abi type of the argument.
|
|
16
|
+
* @param arg - The value to encode.
|
|
17
|
+
* @param name - Name.
|
|
18
|
+
*/
|
|
19
|
+
private encodeArgument(abiType: ABIType, arg: any, name?: string) {
|
|
20
|
+
if (arg === undefined || arg == null) {
|
|
21
|
+
throw new Error(`Undefined argument ${name ?? 'unnamed'} of type ${abiType.kind}`);
|
|
22
|
+
}
|
|
23
|
+
switch (abiType.kind) {
|
|
24
|
+
case 'field':
|
|
25
|
+
if (typeof arg === 'number') {
|
|
26
|
+
this.flattened.push(new Fr(BigInt(arg)));
|
|
27
|
+
} else if (typeof arg === 'bigint') {
|
|
28
|
+
this.flattened.push(new Fr(arg));
|
|
29
|
+
} else if (typeof arg === 'object') {
|
|
30
|
+
if (typeof arg.toField === 'function') {
|
|
31
|
+
this.flattened.push(arg.toField());
|
|
32
|
+
} else {
|
|
33
|
+
this.flattened.push(arg);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case 'boolean':
|
|
38
|
+
this.flattened.push(new Fr(arg ? 1n : 0n));
|
|
39
|
+
break;
|
|
40
|
+
case 'array':
|
|
41
|
+
for (let i = 0; i < abiType.length; i += 1) {
|
|
42
|
+
this.encodeArgument(abiType.type, arg[i], `${name}[${i}]`);
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case 'struct':
|
|
46
|
+
for (const field of abiType.fields) {
|
|
47
|
+
this.encodeArgument(field.type, arg[field.name], `${name}.${field.name}`);
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
case 'integer':
|
|
51
|
+
this.flattened.push(new Fr(arg));
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
throw new Error(`Unsupported type: ${abiType.kind}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Encodes all the arguments for the given function ABI.
|
|
60
|
+
* @returns The encoded arguments.
|
|
61
|
+
*/
|
|
62
|
+
public encode() {
|
|
63
|
+
for (let i = 0; i < this.abi.parameters.length; i += 1) {
|
|
64
|
+
const parameterAbi = this.abi.parameters[i];
|
|
65
|
+
this.encodeArgument(parameterAbi.type, this.args[i], parameterAbi.name);
|
|
66
|
+
}
|
|
67
|
+
return this.flattened;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Encodes all the arguments for a function call.
|
|
73
|
+
* @param abi - The function ABI entry.
|
|
74
|
+
* @param args - The arguments to encode.
|
|
75
|
+
* @returns The encoded arguments.
|
|
76
|
+
*/
|
|
77
|
+
export function encodeArguments(abi: FunctionAbi, args: any[]) {
|
|
78
|
+
return new ArgumentEncoder(abi, args).encode();
|
|
79
|
+
}
|
package/src/abi/index.ts
CHANGED
|
@@ -1,147 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
/**
|
|
6
|
-
* The name of the variable.
|
|
7
|
-
*/
|
|
8
|
-
name: string;
|
|
9
|
-
/**
|
|
10
|
-
* The type of the variable.
|
|
11
|
-
*/
|
|
12
|
-
type: ABIType;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Indicates whether a parameter is public or secret/private.
|
|
17
|
-
*/
|
|
18
|
-
export enum ABIParameterVisibility {
|
|
19
|
-
PUBLIC = 'public',
|
|
20
|
-
SECRET = 'secret',
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A function parameter.
|
|
25
|
-
*/
|
|
26
|
-
export interface ABIParameter extends ABIVariable {
|
|
27
|
-
/**
|
|
28
|
-
* Indicates whether a parameter is public or secret/private.
|
|
29
|
-
*/
|
|
30
|
-
visibility: ABIParameterVisibility;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A basic type.
|
|
35
|
-
*/
|
|
36
|
-
export interface BasicType<T extends string> {
|
|
37
|
-
/**
|
|
38
|
-
* The kind of the type.
|
|
39
|
-
*/
|
|
40
|
-
kind: T;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* A variable type.
|
|
45
|
-
*/
|
|
46
|
-
export type ABIType = BasicType<'field'> | BasicType<'boolean'> | IntegerType | ArrayType | StringType | StructType;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* An integer type.
|
|
50
|
-
*/
|
|
51
|
-
export interface IntegerType extends BasicType<'integer'> {
|
|
52
|
-
/**
|
|
53
|
-
* The sign of the integer.
|
|
54
|
-
*/
|
|
55
|
-
sign: string;
|
|
56
|
-
/**
|
|
57
|
-
* The width of the integer in bits.
|
|
58
|
-
*/
|
|
59
|
-
width: number;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* An array type.
|
|
64
|
-
*/
|
|
65
|
-
export interface ArrayType extends BasicType<'array'> {
|
|
66
|
-
/**
|
|
67
|
-
* The length of the array.
|
|
68
|
-
*/
|
|
69
|
-
length: number;
|
|
70
|
-
/**
|
|
71
|
-
* The type of the array elements.
|
|
72
|
-
*/
|
|
73
|
-
type: ABIType;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* A string type.
|
|
78
|
-
*/
|
|
79
|
-
export interface StringType extends BasicType<'string'> {
|
|
80
|
-
/**
|
|
81
|
-
* The length of the string.
|
|
82
|
-
*/
|
|
83
|
-
length: number;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* A struct type.
|
|
88
|
-
*/
|
|
89
|
-
export interface StructType extends BasicType<'struct'> {
|
|
90
|
-
/**
|
|
91
|
-
* The fields of the struct.
|
|
92
|
-
*/
|
|
93
|
-
fields: ABIVariable[];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Noir function types.
|
|
98
|
-
*/
|
|
99
|
-
export enum FunctionType {
|
|
100
|
-
SECRET = 'secret',
|
|
101
|
-
OPEN = 'open',
|
|
102
|
-
UNCONSTRAINED = 'unconstrained',
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* The ABI entry of a function.
|
|
107
|
-
*/
|
|
108
|
-
export interface FunctionAbi {
|
|
109
|
-
/**
|
|
110
|
-
* The name of the function.
|
|
111
|
-
*/
|
|
112
|
-
name: string;
|
|
113
|
-
/**
|
|
114
|
-
* Whether the function is secret.
|
|
115
|
-
*/
|
|
116
|
-
functionType: FunctionType;
|
|
117
|
-
/**
|
|
118
|
-
* Function parameters.
|
|
119
|
-
*/
|
|
120
|
-
parameters: ABIParameter[];
|
|
121
|
-
/**
|
|
122
|
-
* The types of the return values.
|
|
123
|
-
*/
|
|
124
|
-
returnTypes: ABIType[];
|
|
125
|
-
/**
|
|
126
|
-
* The ACIR bytecode of the function.
|
|
127
|
-
*/
|
|
128
|
-
bytecode: string;
|
|
129
|
-
/**
|
|
130
|
-
* The verification key of the function.
|
|
131
|
-
*/
|
|
132
|
-
verificationKey?: string;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Defines ABI of a contract.
|
|
137
|
-
*/
|
|
138
|
-
export interface ContractAbi {
|
|
139
|
-
/**
|
|
140
|
-
* The name of the contract.
|
|
141
|
-
*/
|
|
142
|
-
name: string;
|
|
143
|
-
/**
|
|
144
|
-
* The functions of the contract.
|
|
145
|
-
*/
|
|
146
|
-
functions: FunctionAbi[];
|
|
147
|
-
}
|
|
1
|
+
export * from './abi.js';
|
|
2
|
+
export * from './abi_coder.js';
|
|
3
|
+
export * from './encoder.js';
|
|
4
|
+
export * from './decoder.js';
|
|
@@ -65,6 +65,16 @@ export class AztecAddress {
|
|
|
65
65
|
return new AztecAddress(buf);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Creates an AztecAddress from a bigint.
|
|
70
|
+
* The provided value must be within the range of a field.
|
|
71
|
+
* @param address - The bigint representation of the address.
|
|
72
|
+
* @returns An AztecAddress instance.
|
|
73
|
+
*/
|
|
74
|
+
static fromBigInt(address: bigint) {
|
|
75
|
+
return new AztecAddress(toBufferBE(address, AztecAddress.SIZE_IN_BYTES));
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
/**
|
|
69
79
|
* Converts the AztecAddress instance into a Buffer.
|
|
70
80
|
* This method should be used when encoding the address for storage, transmission or serialization purposes.
|
package/src/fields/fields.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from 'crypto';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { toBigIntBE, toBufferBE, toHex } from '../bigint-buffer/index.js';
|
|
4
|
+
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Fr represents a field of integers modulo the prime number MODULUS.
|
|
@@ -16,7 +17,7 @@ export class Fr {
|
|
|
16
17
|
/**
|
|
17
18
|
* The numeric value of the field element as a bigint.
|
|
18
19
|
*/
|
|
19
|
-
public readonly value;
|
|
20
|
+
public readonly value: bigint;
|
|
20
21
|
|
|
21
22
|
constructor(value: bigint | number) {
|
|
22
23
|
this.value = BigInt(value);
|
|
@@ -94,6 +95,15 @@ export class Fr {
|
|
|
94
95
|
return toHex(this.value, padTo32);
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves the underlying bigint.
|
|
100
|
+
* This method mostly exists to match user expectations, as value is already public.
|
|
101
|
+
* @returns The underlying bigint.
|
|
102
|
+
*/
|
|
103
|
+
public toBigInt(): bigint {
|
|
104
|
+
return this.value;
|
|
105
|
+
}
|
|
106
|
+
|
|
97
107
|
/**
|
|
98
108
|
* Returns a shortened string representation of the Fr value, formatted with '0x' prefix and ellipsis in the middle.
|
|
99
109
|
* The resulting string has first 10 characters (including '0x') and last 4 characters of the full hexadecimal value.
|
package/src/fields/point.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BufferReader } from '../serialize/buffer_reader.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Fr } from './fields.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents a Point on an elliptic curve with x and y coordinates.
|
|
@@ -7,7 +7,7 @@ import { Coordinate } from './coordinate.js';
|
|
|
7
7
|
* converting instances to various output formats, and checking the equality of points.
|
|
8
8
|
*/
|
|
9
9
|
export class Point {
|
|
10
|
-
static ZERO = new Point(
|
|
10
|
+
static ZERO = new Point(Fr.ZERO, Fr.ZERO);
|
|
11
11
|
|
|
12
12
|
/** Used to differentiate this class from AztecAddress */
|
|
13
13
|
public readonly kind = 'point';
|
|
@@ -16,11 +16,11 @@ export class Point {
|
|
|
16
16
|
/**
|
|
17
17
|
* The point's x coordinate
|
|
18
18
|
*/
|
|
19
|
-
public readonly x:
|
|
19
|
+
public readonly x: Fr,
|
|
20
20
|
/**
|
|
21
21
|
* The point's y coordinate
|
|
22
22
|
*/
|
|
23
|
-
public readonly y:
|
|
23
|
+
public readonly y: Fr,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -30,7 +30,7 @@ export class Point {
|
|
|
30
30
|
*/
|
|
31
31
|
static random() {
|
|
32
32
|
// TODO is this a random point on the curve?
|
|
33
|
-
return new Point(
|
|
33
|
+
return new Point(Fr.random(), Fr.random());
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -42,17 +42,7 @@ export class Point {
|
|
|
42
42
|
*/
|
|
43
43
|
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
44
44
|
const reader = BufferReader.asReader(buffer);
|
|
45
|
-
return new this(
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Creates a point instance from its x and y coordinates.
|
|
50
|
-
* @param x - X coordinate.
|
|
51
|
-
* @param y - Y coordinate.
|
|
52
|
-
* @returns A Point instance.
|
|
53
|
-
*/
|
|
54
|
-
static fromCoordinates(x: Coordinate, y: Coordinate) {
|
|
55
|
-
return new this(x, y);
|
|
45
|
+
return new this(Fr.fromBuffer(reader.readBytes(32)), Fr.fromBuffer(reader.readBytes(32)));
|
|
56
46
|
}
|
|
57
47
|
|
|
58
48
|
/**
|
|
@@ -68,22 +58,11 @@ export class Point {
|
|
|
68
58
|
}
|
|
69
59
|
|
|
70
60
|
/**
|
|
71
|
-
*
|
|
72
|
-
* The
|
|
73
|
-
* This method is useful for serialization and deserialization of the Point object.
|
|
74
|
-
*
|
|
75
|
-
* @returns A Buffer representation of the Point instance.
|
|
76
|
-
*/
|
|
77
|
-
toFieldsBuffer() {
|
|
78
|
-
return Buffer.concat([this.x.toFieldsBuffer(), this.y.toFieldsBuffer()]);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Returns the contents of the point as an array of 4 fields.
|
|
83
|
-
* @returns The point as an array of 4 fields
|
|
61
|
+
* Returns the contents of the point as an array of 2 fields.
|
|
62
|
+
* @returns The point as an array of 2 fields
|
|
84
63
|
*/
|
|
85
64
|
toFields() {
|
|
86
|
-
return this.x
|
|
65
|
+
return [this.x, this.y];
|
|
87
66
|
}
|
|
88
67
|
|
|
89
68
|
/**
|
|
@@ -91,11 +70,9 @@ export class Point {
|
|
|
91
70
|
* @returns The point as BigInts
|
|
92
71
|
*/
|
|
93
72
|
toBigInts() {
|
|
94
|
-
const x = this.x.toBigInt();
|
|
95
|
-
const y = this.y.toBigInt();
|
|
96
73
|
return {
|
|
97
|
-
x,
|
|
98
|
-
y,
|
|
74
|
+
x: this.x.value,
|
|
75
|
+
y: this.y.value,
|
|
99
76
|
};
|
|
100
77
|
}
|
|
101
78
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
|
+
|
|
3
|
+
import { TestNote, TestState } from '../fixtures/test_state.js';
|
|
2
4
|
import { JsonRpcServer } from '../server/json_rpc_server.js';
|
|
3
|
-
import { TestState, TestNote } from '../fixtures/test_state.js';
|
|
4
5
|
import { createJsonRpcClient } from './json_rpc_client.js';
|
|
5
6
|
|
|
6
7
|
test('test an RPC function over client', async () => {
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
// This takes a {foo(): T} and makes {foo(): Promise<T>}
|
|
4
4
|
// while avoiding Promise of Promise.
|
|
5
5
|
import { RemoteObject } from 'comlink';
|
|
6
|
+
|
|
6
7
|
import { createDebugLogger } from '../../log/index.js';
|
|
7
8
|
import { retry } from '../../retry/index.js';
|
|
8
|
-
import { ClassConverter,
|
|
9
|
+
import { ClassConverter, JsonClassConverterInput, StringClassConverterInput } from '../class_converter.js';
|
|
9
10
|
import { JsonStringify, convertFromJsonObj, convertToJsonObj } from '../convert.js';
|
|
10
11
|
|
|
11
12
|
export { JsonStringify } from '../convert.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
|
|
1
3
|
import { ClassConverter } from './class_converter.js';
|
|
2
4
|
import { convertFromJsonObj, convertToJsonObj } from './convert.js';
|
|
3
5
|
import { TestNote } from './fixtures/test_state.js';
|
|
4
6
|
|
|
5
|
-
import { Buffer } from 'buffer';
|
|
6
|
-
|
|
7
7
|
const TEST_BASE64 = 'YmFzZTY0IGRlY29kZXI=';
|
|
8
8
|
test('test an RPC function over client', () => {
|
|
9
9
|
const cc = new ClassConverter({ TestNote });
|
package/src/json-rpc/convert.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ClassConverter } from './class_converter.js';
|
|
2
1
|
import { Buffer } from 'buffer';
|
|
3
2
|
|
|
3
|
+
import { ClassConverter } from './class_converter.js';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Recursively looks through an object for bigints and converts them to object format.
|
|
6
7
|
* @param obj - The object to convert.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDebugLogger } from '../../log/index.js';
|
|
2
|
-
import { ClassConverter,
|
|
2
|
+
import { ClassConverter, JsonClassConverterInput, StringClassConverterInput } from '../class_converter.js';
|
|
3
3
|
import { convertFromJsonObj, convertToJsonObj } from '../convert.js';
|
|
4
4
|
import { assert, hasOwnProperty } from '../js_utils.js';
|
|
5
5
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { TestNote, TestState } from '../fixtures/test_state.js';
|
|
3
4
|
import { JsonRpcServer } from './json_rpc_server.js';
|
|
4
5
|
|
|
5
6
|
test('test an RPC function with a primitive parameter', async () => {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import http from 'http';
|
|
2
|
-
import Router from 'koa-router';
|
|
3
1
|
import cors from '@koa/cors';
|
|
4
|
-
import
|
|
2
|
+
import http from 'http';
|
|
5
3
|
import Koa from 'koa';
|
|
6
4
|
import bodyParser from 'koa-bodyparser';
|
|
5
|
+
import compress from 'koa-compress';
|
|
6
|
+
import Router from 'koa-router';
|
|
7
7
|
|
|
8
8
|
import { createLogger } from '../../log/index.js';
|
|
9
|
-
import {
|
|
10
|
-
import { JsonProxy } from './json_proxy.js';
|
|
9
|
+
import { JsonClassConverterInput, StringClassConverterInput } from '../class_converter.js';
|
|
11
10
|
import { convertBigintsInObj } from '../convert.js';
|
|
11
|
+
import { JsonProxy } from './json_proxy.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* JsonRpcServer.
|
package/src/mutex/mutex.test.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jest } from '@jest/globals';
|
|
2
|
+
|
|
3
|
+
import { randomBytes } from '../crypto/index.js';
|
|
2
4
|
import { Fq, Fr } from '../fields/fields.js';
|
|
3
5
|
import { BufferReader } from './buffer_reader.js';
|
|
4
6
|
import { serializeBufferArrayToVector } from './free_funcs.js';
|
|
5
|
-
import { randomBytes } from '../crypto/index.js';
|
|
6
7
|
|
|
7
8
|
const ARRAY = Array.from(Array(32)).map((_, idx) => (idx % 2 === 0 ? 0 : 1));
|
|
8
9
|
const BUFFER = Buffer.from(ARRAY);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { randomBytes } from '../crypto/index.js';
|
|
2
2
|
import { Fr } from '../fields/fields.js';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
deserializeArrayFromVector,
|
|
5
5
|
deserializeBufferFromVector,
|
|
6
|
-
deserializeUInt32,
|
|
7
6
|
deserializeField,
|
|
7
|
+
deserializeUInt32,
|
|
8
8
|
serializeBufferArrayToVector,
|
|
9
|
-
|
|
9
|
+
serializeBufferToVector,
|
|
10
10
|
} from './index.js';
|
|
11
11
|
|
|
12
12
|
describe('serialize', () => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { serializeBufferArrayToVector } from './index.js';
|
|
2
1
|
import {
|
|
3
2
|
boolToByte,
|
|
4
3
|
numToInt32BE,
|
|
@@ -7,6 +6,7 @@ import {
|
|
|
7
6
|
serializeBufferToVector,
|
|
8
7
|
serializeDate,
|
|
9
8
|
} from './free_funcs.js';
|
|
9
|
+
import { serializeBufferArrayToVector } from './index.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The Serializer class provides a convenient and efficient way to serialize various data types into binary format.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { DispatchMsg } from './create_dispatch_fn.js';
|
|
2
|
-
import { TransportClient } from '../transport_client.js';
|
|
3
1
|
import { EventEmitter } from 'events';
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
import { TransferDescriptor, isTransferDescriptor } from '../interface/transferable.js';
|
|
4
|
+
import { TransportClient } from '../transport_client.js';
|
|
5
|
+
import { DispatchMsg } from './create_dispatch_fn.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* FilterOutAttributes type filters out all non-method properties of an object, leaving only the attributes
|