@proto-kit/module 0.1.1-develop.156 → 0.1.1-develop.160
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.
|
@@ -6,9 +6,11 @@ export interface Fieldable {
|
|
|
6
6
|
export interface FromFieldClass {
|
|
7
7
|
new: (...args: any[]) => any;
|
|
8
8
|
fromFields: (fields: Field[]) => Fieldable;
|
|
9
|
+
name: string;
|
|
9
10
|
prototype: {
|
|
10
|
-
_fields
|
|
11
|
+
_fields?: any[];
|
|
11
12
|
};
|
|
13
|
+
sizeInFields?: () => number;
|
|
12
14
|
}
|
|
13
15
|
export declare class MethodParameterDecoder {
|
|
14
16
|
private readonly types;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MethodParameterDecoder.d.ts","sourceRoot":"","sources":["../../src/method/MethodParameterDecoder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MethodParameterDecoder.d.ts","sourceRoot":"","sources":["../../src/method/MethodParameterDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,KAAK,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAC7B,UAAU,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,SAAS,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;IAEb,SAAS,EAAE;QACT,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;KACjB,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAYD,qBAAa,sBAAsB;IAWb,OAAO,CAAC,QAAQ,CAAC,KAAK;WAV5B,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,MAAM;IAU3E,OAAO;IAEA,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE;IAiB/C,IAAW,SAAS,IAAI,MAAM,CAM7B;CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const errors = {
|
|
2
2
|
fieldLengthNotMatching: (expected, actual) => new Error(`Expected ${expected} field elements, got ${actual}`),
|
|
3
|
+
typeNotCompatible: (name) => new Error(`Cannot decode type ${name}, it has to be either a Struct, CircuitValue or built-in snarkyjs type`),
|
|
3
4
|
};
|
|
4
5
|
export class MethodParameterDecoder {
|
|
5
6
|
static fromMethod(target, methodName) {
|
|
@@ -15,8 +16,10 @@ export class MethodParameterDecoder {
|
|
|
15
16
|
}
|
|
16
17
|
let stack = fields.slice();
|
|
17
18
|
return this.types.map((type) => {
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
const numberFieldsNeeded = type.prototype._fields?.length ?? type.sizeInFields?.() ?? -1;
|
|
20
|
+
if (numberFieldsNeeded === -1) {
|
|
21
|
+
throw errors.typeNotCompatible(type.name);
|
|
22
|
+
}
|
|
20
23
|
const structFields = stack.slice(0, numberFieldsNeeded);
|
|
21
24
|
stack = stack.slice(numberFieldsNeeded);
|
|
22
25
|
return type.fromFields(structFields);
|
|
@@ -24,7 +27,7 @@ export class MethodParameterDecoder {
|
|
|
24
27
|
}
|
|
25
28
|
get fieldSize() {
|
|
26
29
|
return this.types
|
|
27
|
-
.map((type) => type.prototype._fields.
|
|
30
|
+
.map((type) => type.prototype._fields?.length ?? type.sizeInFields?.() ?? 0)
|
|
28
31
|
.reduce((a, b) => a + b);
|
|
29
32
|
}
|
|
30
33
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@proto-kit/module",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.1.1-develop.
|
|
5
|
+
"version": "0.1.1-develop.160+5120680",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@proto-kit/common": "0.1.1-develop.
|
|
21
|
-
"@proto-kit/protocol": "0.1.1-develop.
|
|
20
|
+
"@proto-kit/common": "0.1.1-develop.160+5120680",
|
|
21
|
+
"@proto-kit/protocol": "0.1.1-develop.160+5120680",
|
|
22
22
|
"lodash": "^4.17.21",
|
|
23
23
|
"loglevel": "^1.8.1",
|
|
24
24
|
"reflect-metadata": "^0.1.13",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"snarkyjs": "0.11.0",
|
|
33
33
|
"tsyringe": "^4.7.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "51206808f0eba77c4ad8c1af476a6dbdd478d2a3"
|
|
36
36
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
1
2
|
import { Field } from "snarkyjs";
|
|
2
3
|
|
|
3
4
|
import { RuntimeModule } from "../runtime/RuntimeModule";
|
|
@@ -9,15 +10,22 @@ export interface Fieldable {
|
|
|
9
10
|
export interface FromFieldClass {
|
|
10
11
|
new: (...args: any[]) => any;
|
|
11
12
|
fromFields: (fields: Field[]) => Fieldable;
|
|
13
|
+
name: string;
|
|
12
14
|
// Maybe this is wrong IDK
|
|
13
15
|
prototype: {
|
|
14
|
-
_fields
|
|
16
|
+
_fields?: any[];
|
|
15
17
|
};
|
|
18
|
+
sizeInFields?: () => number;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
const errors = {
|
|
19
22
|
fieldLengthNotMatching: (expected: number, actual: number) =>
|
|
20
23
|
new Error(`Expected ${expected} field elements, got ${actual}`),
|
|
24
|
+
|
|
25
|
+
typeNotCompatible: (name: string) =>
|
|
26
|
+
new Error(
|
|
27
|
+
`Cannot decode type ${name}, it has to be either a Struct, CircuitValue or built-in snarkyjs type`
|
|
28
|
+
),
|
|
21
29
|
};
|
|
22
30
|
|
|
23
31
|
export class MethodParameterDecoder {
|
|
@@ -39,8 +47,11 @@ export class MethodParameterDecoder {
|
|
|
39
47
|
}
|
|
40
48
|
let stack = fields.slice();
|
|
41
49
|
return this.types.map((type) => {
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
const numberFieldsNeeded =
|
|
51
|
+
type.prototype._fields?.length ?? type.sizeInFields?.() ?? -1;
|
|
52
|
+
if (numberFieldsNeeded === -1) {
|
|
53
|
+
throw errors.typeNotCompatible(type.name);
|
|
54
|
+
}
|
|
44
55
|
const structFields = stack.slice(0, numberFieldsNeeded);
|
|
45
56
|
stack = stack.slice(numberFieldsNeeded);
|
|
46
57
|
return type.fromFields(structFields);
|
|
@@ -49,7 +60,9 @@ export class MethodParameterDecoder {
|
|
|
49
60
|
|
|
50
61
|
public get fieldSize(): number {
|
|
51
62
|
return this.types
|
|
52
|
-
.map(
|
|
63
|
+
.map(
|
|
64
|
+
(type) => type.prototype._fields?.length ?? type.sizeInFields?.() ?? 0
|
|
65
|
+
)
|
|
53
66
|
.reduce((a, b) => a + b);
|
|
54
67
|
}
|
|
55
68
|
}
|