@proto-kit/module 0.1.1-develop.600 → 0.1.1-develop.833
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/LICENSE.md +201 -201
- package/dist/method/MethodParameterDecoder.d.ts +10 -10
- package/dist/method/MethodParameterDecoder.js +40 -40
- package/dist/method/MethodParameterEncoder.d.ts +15 -8
- package/dist/method/MethodParameterEncoder.d.ts.map +1 -1
- package/dist/method/MethodParameterEncoder.js +122 -48
- package/dist/method/runtimeMethod.d.ts +6 -5
- package/dist/method/runtimeMethod.d.ts.map +1 -1
- package/dist/method/runtimeMethod.js +13 -26
- package/dist/runtime/MethodIdResolver.d.ts +7 -0
- package/dist/runtime/MethodIdResolver.d.ts.map +1 -1
- package/dist/runtime/MethodIdResolver.js +35 -2
- package/dist/runtime/Runtime.d.ts +6 -5
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +29 -22
- package/dist/runtime/RuntimeEnvironment.d.ts +2 -2
- package/dist/runtime/RuntimeEnvironment.d.ts.map +1 -1
- package/dist/runtime/RuntimeModule.d.ts +2 -2
- package/dist/runtime/RuntimeModule.d.ts.map +1 -1
- package/dist/runtime/RuntimeModule.js +10 -8
- package/dist/src/factories/MethodIdFactory.d.ts +10 -0
- package/dist/src/factories/MethodIdFactory.d.ts.map +1 -0
- package/dist/src/factories/MethodIdFactory.js +10 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +10 -0
- package/dist/src/method/MethodParameterEncoder.d.ts +22 -0
- package/dist/src/method/MethodParameterEncoder.d.ts.map +1 -0
- package/dist/src/method/MethodParameterEncoder.js +103 -0
- package/dist/src/method/runtimeMethod.d.ts +26 -0
- package/dist/src/method/runtimeMethod.d.ts.map +1 -0
- package/dist/src/method/runtimeMethod.js +164 -0
- package/dist/src/module/decorator.d.ts +8 -0
- package/dist/src/module/decorator.d.ts.map +1 -0
- package/dist/src/module/decorator.js +15 -0
- package/dist/src/runtime/MethodIdResolver.d.ts +20 -0
- package/dist/src/runtime/MethodIdResolver.d.ts.map +1 -0
- package/dist/src/runtime/MethodIdResolver.js +100 -0
- package/dist/src/runtime/Runtime.d.ts +71 -0
- package/dist/src/runtime/Runtime.d.ts.map +1 -0
- package/dist/src/runtime/Runtime.js +215 -0
- package/dist/src/runtime/RuntimeEnvironment.d.ts +10 -0
- package/dist/src/runtime/RuntimeEnvironment.d.ts.map +1 -0
- package/dist/src/runtime/RuntimeEnvironment.js +1 -0
- package/dist/src/runtime/RuntimeModule.d.ts +26 -0
- package/dist/src/runtime/RuntimeModule.d.ts.map +1 -0
- package/dist/src/runtime/RuntimeModule.js +85 -0
- package/dist/src/state/InMemoryStateService.d.ts +15 -0
- package/dist/src/state/InMemoryStateService.d.ts.map +1 -0
- package/dist/src/state/InMemoryStateService.js +28 -0
- package/dist/src/state/decorator.d.ts +7 -0
- package/dist/src/state/decorator.d.ts.map +1 -0
- package/dist/src/state/decorator.js +39 -0
- package/dist/state/InMemoryStateService.d.ts +10 -6
- package/dist/state/InMemoryStateService.d.ts.map +1 -1
- package/dist/state/InMemoryStateService.js +10 -8
- package/dist/state/decorator.d.ts.map +1 -1
- package/dist/state/decorator.js +0 -3
- package/dist/test/Runtime.test.d.ts +2 -0
- package/dist/test/Runtime.test.d.ts.map +1 -0
- package/dist/test/Runtime.test.js +24 -0
- package/dist/test/TestingRuntime.d.ts +7 -0
- package/dist/test/TestingRuntime.d.ts.map +1 -0
- package/dist/test/TestingRuntime.js +29 -0
- package/dist/test/method/runtimeMethod.test.d.ts +2 -0
- package/dist/test/method/runtimeMethod.test.d.ts.map +1 -0
- package/dist/test/method/runtimeMethod.test.js +30 -0
- package/dist/test/modules/Admin.d.ts +10 -0
- package/dist/test/modules/Admin.d.ts.map +1 -0
- package/dist/test/modules/Admin.js +29 -0
- package/dist/test/modules/Balances.d.ts +23 -0
- package/dist/test/modules/Balances.d.ts.map +1 -0
- package/dist/test/modules/Balances.js +98 -0
- package/dist/test/modules/Balances.test.d.ts +2 -0
- package/dist/test/modules/Balances.test.d.ts.map +1 -0
- package/dist/test/modules/Balances.test.js +201 -0
- package/dist/test/modules/MethodIdResolver.test.d.ts +2 -0
- package/dist/test/modules/MethodIdResolver.test.d.ts.map +1 -0
- package/dist/test/modules/MethodIdResolver.test.js +67 -0
- package/dist/test/modules/State.test.d.ts +2 -0
- package/dist/test/modules/State.test.d.ts.map +1 -0
- package/dist/test/modules/State.test.js +42 -0
- package/dist/test/runtimeMethod.test.d.ts +2 -0
- package/dist/test/runtimeMethod.test.d.ts.map +1 -0
- package/dist/test/runtimeMethod.test.js +50 -0
- package/package.json +5 -5
- package/src/method/MethodParameterEncoder.ts +192 -81
- package/src/method/runtimeMethod.ts +29 -44
- package/src/runtime/MethodIdResolver.ts +51 -1
- package/src/runtime/Runtime.ts +48 -29
- package/src/runtime/RuntimeEnvironment.ts +4 -7
- package/src/runtime/RuntimeModule.ts +13 -15
- package/src/state/InMemoryStateService.ts +13 -13
- package/src/state/decorator.ts +1 -3
- package/test/Runtime.test.ts +68 -41
- package/test/TestingRuntime.ts +45 -0
- package/test/method/MethodParameterEncoder.test.ts +152 -0
- package/{src/method/decorator.test.ts → test/method/runtimeMethod.test.ts} +2 -2
- package/test/modules/Admin.ts +3 -3
- package/test/modules/Balances.test.ts +57 -61
- package/test/modules/Balances.ts +15 -18
- package/test/modules/{methodId.test.ts → MethodIdResolver.test.ts} +14 -23
- package/test/modules/State.test.ts +41 -50
- package/test/runtimeMethod.test.ts +19 -32
- package/test/tsconfig.json +7 -0
- package/tsconfig.json +2 -2
- package/test/transaction.test.ts +0 -82
- package/tsconfig.test.json +0 -9
|
@@ -1,9 +1,33 @@
|
|
|
1
|
-
/* eslint-disable
|
|
2
|
-
import { Proof } from "o1js";
|
|
1
|
+
/* eslint-disable @typescript-eslint/consistent-type-assertions */
|
|
2
|
+
import { Proof, Provable, DynamicProof, } from "o1js";
|
|
3
|
+
import { filterNonUndefined, } from "@proto-kit/common";
|
|
3
4
|
const errors = {
|
|
4
5
|
fieldLengthNotMatching: (expected, actual) => new Error(`Expected ${expected} field elements, got ${actual}`),
|
|
5
6
|
typeNotCompatible: (name, error) => new Error(`Cannot decode type ${name}, it has to be either a Struct, CircuitValue or built-in snarkyjs type.${error !== undefined ? `Caused by: ${error}` : ""}`),
|
|
6
7
|
};
|
|
8
|
+
function isProofType(type) {
|
|
9
|
+
return type.prototype instanceof Proof;
|
|
10
|
+
}
|
|
11
|
+
function isDynamicProofType(type) {
|
|
12
|
+
return (type.prototype instanceof DynamicProof);
|
|
13
|
+
}
|
|
14
|
+
function isProofBaseType(type) {
|
|
15
|
+
return isProofType(type) || isDynamicProofType(type);
|
|
16
|
+
}
|
|
17
|
+
function getAllPropertyNamesOfPrototypeChain(type) {
|
|
18
|
+
if (type === undefined || type === null) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
return Object.getOwnPropertyNames(type).concat(...getAllPropertyNamesOfPrototypeChain(Object.getPrototypeOf(type)));
|
|
22
|
+
}
|
|
23
|
+
function isFlexibleProvablePure(type) {
|
|
24
|
+
// The required properties are defined on the prototype for Structs and CircuitValues
|
|
25
|
+
// but on the constructor function itself for Field and Bool
|
|
26
|
+
// For aliases like Balance in library, it can even be 2 steps upwards the prototype chain
|
|
27
|
+
const props = getAllPropertyNamesOfPrototypeChain(type);
|
|
28
|
+
const mandatory = ["toFields", "fromFields", "sizeInFields"];
|
|
29
|
+
return mandatory.every((prop) => props.includes(prop));
|
|
30
|
+
}
|
|
7
31
|
export class MethodParameterEncoder {
|
|
8
32
|
static fromMethod(target, methodName) {
|
|
9
33
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -11,80 +35,130 @@ export class MethodParameterEncoder {
|
|
|
11
35
|
if (paramtypes === undefined) {
|
|
12
36
|
throw new Error(`Method with name ${methodName} doesn't exist on this module`);
|
|
13
37
|
}
|
|
38
|
+
const indizes = paramtypes
|
|
39
|
+
.map((type, index) => {
|
|
40
|
+
if (isProofBaseType(type) || isFlexibleProvablePure(type)) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return `${index}`;
|
|
44
|
+
})
|
|
45
|
+
.filter(filterNonUndefined);
|
|
46
|
+
if (indizes.length > 0) {
|
|
47
|
+
const indexString = indizes.reduce((a, b) => `${a}, ${b}`);
|
|
48
|
+
throw new Error(`Not all arguments of method '${target.name}.${methodName}' are provable types or proofs (indizes: [${indexString}])`);
|
|
49
|
+
}
|
|
14
50
|
return new MethodParameterEncoder(paramtypes);
|
|
15
51
|
}
|
|
16
52
|
static fieldSize(type) {
|
|
53
|
+
if (isProofBaseType(type)) {
|
|
54
|
+
return ((MethodParameterEncoder.fieldSize(type.publicInputType) ?? 0) +
|
|
55
|
+
(MethodParameterEncoder.fieldSize(type.publicOutputType) ?? 0));
|
|
56
|
+
}
|
|
17
57
|
// as any, since we shouldn't be using this workaround in the first place
|
|
18
|
-
return type.
|
|
58
|
+
return type.sizeInFields();
|
|
19
59
|
}
|
|
20
60
|
constructor(types) {
|
|
21
61
|
this.types = types;
|
|
22
62
|
}
|
|
23
|
-
decode(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let value;
|
|
27
|
-
try {
|
|
28
|
-
// eslint-disable-next-line max-len
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
30
|
-
value = type.fromJSON(JSON.parse(argsJSON[index]));
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
if (e instanceof Error) {
|
|
34
|
-
throw errors.typeNotCompatible(type.constructor.name, e.message);
|
|
35
|
-
}
|
|
36
|
-
throw errors.typeNotCompatible(type.constructor.name);
|
|
37
|
-
}
|
|
38
|
-
return value;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
decodeFields(fields) {
|
|
42
|
-
if (fields.length < this.fieldSize) {
|
|
43
|
-
throw errors.fieldLengthNotMatching(this.fieldSize, fields.length);
|
|
63
|
+
decode(fields, auxiliary) {
|
|
64
|
+
if (fields.length < this.fieldSize()) {
|
|
65
|
+
throw errors.fieldLengthNotMatching(this.fieldSize(), fields.length);
|
|
44
66
|
}
|
|
45
67
|
let stack = fields.slice();
|
|
46
|
-
|
|
68
|
+
const auxiliaryStack = auxiliary.slice();
|
|
69
|
+
return Promise.all(this.types.map((type) => {
|
|
47
70
|
const numberFieldsNeeded = MethodParameterEncoder.fieldSize(type) ?? -1;
|
|
48
71
|
if (numberFieldsNeeded === -1) {
|
|
49
72
|
throw errors.typeNotCompatible(type.constructor.name);
|
|
50
73
|
}
|
|
51
74
|
const structFields = stack.slice(0, numberFieldsNeeded);
|
|
52
75
|
stack = stack.slice(numberFieldsNeeded);
|
|
53
|
-
|
|
54
|
-
|
|
76
|
+
// Decode proof
|
|
77
|
+
if (isProofBaseType(type)) {
|
|
78
|
+
const auxiliaryData = auxiliaryStack.shift();
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
80
|
+
const proofData = JSON.parse(auxiliaryData);
|
|
81
|
+
const inputFieldSize = MethodParameterEncoder.fieldSize(type.publicInputType);
|
|
82
|
+
const input = structFields
|
|
83
|
+
.slice(0, inputFieldSize)
|
|
84
|
+
.map((x) => x.toString());
|
|
85
|
+
const output = structFields
|
|
86
|
+
.slice(inputFieldSize)
|
|
87
|
+
.map((x) => x.toString());
|
|
88
|
+
// fromJSON has incompatible signature for Proof and DynamicProof
|
|
89
|
+
if (isProofType(type)) {
|
|
90
|
+
return type.fromJSON({
|
|
91
|
+
...proofData,
|
|
92
|
+
publicInput: input,
|
|
93
|
+
publicOutput: output,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (isDynamicProofType(type)) {
|
|
97
|
+
return type.fromJSON({
|
|
98
|
+
...proofData,
|
|
99
|
+
publicInput: input,
|
|
100
|
+
publicOutput: output,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return type.fromFields(structFields);
|
|
105
|
+
}));
|
|
55
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Variant of encode() for provable code that skips the unprovable
|
|
109
|
+
* json encoding
|
|
110
|
+
*/
|
|
56
111
|
encode(args) {
|
|
57
112
|
/**
|
|
58
113
|
* Use the type info obtained previously to convert
|
|
59
114
|
* the args passed to fields
|
|
60
115
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
116
|
+
return args
|
|
117
|
+
.map((argument, index) => {
|
|
118
|
+
if (argument instanceof Proof || argument instanceof DynamicProof) {
|
|
63
119
|
const argumentType = this.types[index];
|
|
64
|
-
const publicOutputType = argumentType
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
120
|
+
const { publicOutputType, publicInputType } = argumentType;
|
|
121
|
+
const inputFields =
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
123
|
+
publicInputType?.toFields(argument.publicInput) ?? [];
|
|
124
|
+
const outputFields =
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
126
|
+
publicOutputType?.toFields(argument.publicOutput) ?? [];
|
|
127
|
+
let auxiliary = "";
|
|
128
|
+
// Has to be asProver, because this function will be called by runtimeMethod
|
|
129
|
+
// to transform the args into a Field[] to compute the argsHash
|
|
130
|
+
// In this case, the auxiliary might be empty, but it isn't used by that method anyways
|
|
131
|
+
Provable.asProver(() => {
|
|
132
|
+
const jsonProof = argument.toJSON();
|
|
133
|
+
auxiliary = JSON.stringify({
|
|
134
|
+
proof: jsonProof.proof,
|
|
135
|
+
maxProofsVerified: jsonProof.maxProofsVerified,
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
fields: [...inputFields, ...outputFields],
|
|
140
|
+
auxiliary,
|
|
141
|
+
};
|
|
76
142
|
}
|
|
77
143
|
const argumentType = this.types[index];
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
144
|
+
return {
|
|
145
|
+
fields: argumentType.toFields(argument),
|
|
146
|
+
auxiliary: undefined,
|
|
147
|
+
};
|
|
148
|
+
})
|
|
149
|
+
.reduce((a, b) => {
|
|
150
|
+
return {
|
|
151
|
+
fields: [...a.fields, ...b.fields],
|
|
152
|
+
auxiliary: b.auxiliary !== undefined
|
|
153
|
+
? [...a.auxiliary, b.auxiliary]
|
|
154
|
+
: a.auxiliary,
|
|
155
|
+
};
|
|
156
|
+
}, { fields: [], auxiliary: [] });
|
|
84
157
|
}
|
|
85
|
-
|
|
158
|
+
fieldSize() {
|
|
86
159
|
return this.types
|
|
87
160
|
.map((type) => MethodParameterEncoder.fieldSize(type) ?? 0)
|
|
88
161
|
.reduce((a, b) => a + b, 0);
|
|
89
162
|
}
|
|
90
163
|
}
|
|
164
|
+
/* eslint-enable @typescript-eslint/consistent-type-assertions */
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { StateTransition, MethodPublicOutput } from "@proto-kit/protocol";
|
|
2
2
|
import { ArgumentTypes } from "@proto-kit/common";
|
|
3
3
|
import type { RuntimeModule } from "../runtime/RuntimeModule.js";
|
|
4
|
-
export declare function toStateTransitionsHash(stateTransitions: StateTransition<any>[]): import("o1js/dist/node/lib/field.js").Field;
|
|
4
|
+
export declare function toStateTransitionsHash(stateTransitions: StateTransition<any>[]): import("o1js/dist/node/lib/provable/field.js").Field;
|
|
5
5
|
export type WrappedMethod = (...args: ArgumentTypes) => MethodPublicOutput;
|
|
6
|
-
export
|
|
6
|
+
export type AsyncWrappedMethod = (...args: ArgumentTypes) => Promise<MethodPublicOutput>;
|
|
7
|
+
export declare function toWrappedMethod(this: RuntimeModule<unknown>, methodName: string, moduleMethod: (...args: ArgumentTypes) => Promise<any>, options: {
|
|
7
8
|
invocationType: RuntimeMethodInvocationType;
|
|
8
|
-
}):
|
|
9
|
+
}): AsyncWrappedMethod;
|
|
9
10
|
export declare function combineMethodName(runtimeModuleName: string, methodName: string): string;
|
|
10
11
|
export declare const runtimeMethodMetadataKey = "yab-method";
|
|
11
12
|
export declare const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
|
|
@@ -20,6 +21,6 @@ export declare const runtimeMethodTypeMetadataKey = "proto-kit-runtime-method-ty
|
|
|
20
21
|
*/
|
|
21
22
|
export declare function isRuntimeMethod(target: RuntimeModule<unknown>, propertyKey: string): boolean;
|
|
22
23
|
export type RuntimeMethodInvocationType = "SIGNATURE" | "INCOMING_MESSAGE";
|
|
23
|
-
export declare function runtimeMessage(): (target: RuntimeModule<unknown>, methodName: string, descriptor:
|
|
24
|
-
export declare function runtimeMethod(): (target: RuntimeModule<unknown>, methodName: string, descriptor:
|
|
24
|
+
export declare function runtimeMessage(): (target: RuntimeModule<unknown>, methodName: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>) => void;
|
|
25
|
+
export declare function runtimeMethod(): (target: RuntimeModule<unknown>, methodName: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>) => void;
|
|
25
26
|
//# sourceMappingURL=runtimeMethod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeMethod.d.ts","sourceRoot":"","sources":["../../src/method/runtimeMethod.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtimeMethod.d.ts","sourceRoot":"","sources":["../../src/method/runtimeMethod.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EAEf,kBAAkB,EAGnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,aAAa,EACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAqBjE,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,wDAczC;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,aAAa,KAAK,kBAAkB,CAAC;AAC3E,MAAM,MAAM,kBAAkB,GAAG,CAC/B,GAAG,IAAI,EAAE,aAAa,KACnB,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEjC,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,GAAG,CAAC,EACtD,OAAO,EAAE;IACP,cAAc,EAAE,2BAA2B,CAAC;CAC7C,GACA,kBAAkB,CA4EpB;AAED,wBAAgB,iBAAiB,CAC/B,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,UAGnB;AAED,eAAO,MAAM,wBAAwB,eAAe,CAAC;AACrD,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AACzE,eAAO,MAAM,4BAA4B,kCAAkC,CAAC;AAE5E;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,WAAW,EAAE,MAAM,WAKpB;AAED,MAAM,MAAM,2BAA2B,GAAG,WAAW,GAAG,kBAAkB,CAAC;AA0G3E,wBAAgB,cAAc,wIAI7B;AAED,wBAAgB,aAAa,wIAI5B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { Bool, Field, Poseidon, } from "o1js";
|
|
1
|
+
import { Bool, Field, Poseidon } from "o1js";
|
|
3
2
|
import { container } from "tsyringe";
|
|
4
|
-
import {
|
|
3
|
+
import { ProvableStateTransition, MethodPublicOutput, RuntimeMethodExecutionContext, StateTransitionReductionList, } from "@proto-kit/protocol";
|
|
5
4
|
import { toProver, } from "@proto-kit/common";
|
|
6
5
|
import { MethodParameterEncoder } from "./MethodParameterEncoder";
|
|
7
6
|
const errors = {
|
|
@@ -10,24 +9,19 @@ const errors = {
|
|
|
10
9
|
runtimeNameNotSet: () => new Error("Runtime name was not set"),
|
|
11
10
|
fieldNotConstant: (name) => new Error(`In-circuit field ${name} not a constant, this is likely a framework bug`),
|
|
12
11
|
};
|
|
13
|
-
export function toStateTransitionsHash(
|
|
14
|
-
|
|
15
|
-
stateTransitions) {
|
|
16
|
-
const stateTransitionsHashList = new DefaultProvableHashList(ProvableStateTransition);
|
|
12
|
+
export function toStateTransitionsHash(stateTransitions) {
|
|
13
|
+
const stateTransitionsHashList = new StateTransitionReductionList(ProvableStateTransition);
|
|
17
14
|
return stateTransitions
|
|
18
15
|
.map((stateTransition) => stateTransition.toProvable())
|
|
19
16
|
.reduce((allStateTransitionsHashList, stateTransition) => allStateTransitionsHashList.push(stateTransition), stateTransitionsHashList)
|
|
20
17
|
.toField();
|
|
21
18
|
}
|
|
22
|
-
export function toWrappedMethod(methodName, moduleMethod,
|
|
19
|
+
export function toWrappedMethod(methodName, moduleMethod, options) {
|
|
23
20
|
const executionContext = container.resolve(RuntimeMethodExecutionContext);
|
|
24
|
-
const wrappedMethod = (...args) => {
|
|
25
|
-
Reflect.apply(moduleMethod, this, args);
|
|
26
|
-
const { result: { stateTransitions, status },
|
|
21
|
+
const wrappedMethod = async (...args) => {
|
|
22
|
+
await Reflect.apply(moduleMethod, this, args);
|
|
23
|
+
const { result: { stateTransitions, status }, } = executionContext.current();
|
|
27
24
|
const stateTransitionsHash = toStateTransitionsHash(stateTransitions);
|
|
28
|
-
if (input === undefined) {
|
|
29
|
-
throw errors.methodInputsNotProvided();
|
|
30
|
-
}
|
|
31
25
|
const { name, runtime } = this;
|
|
32
26
|
if (name === undefined) {
|
|
33
27
|
throw errors.runtimeNameNotSet();
|
|
@@ -47,12 +41,9 @@ export function toWrappedMethod(methodName, moduleMethod, methodArguments, optio
|
|
|
47
41
|
* Use the type info obtained previously to convert
|
|
48
42
|
* the args passed to fields
|
|
49
43
|
*/
|
|
50
|
-
const {
|
|
44
|
+
const { fields } = MethodParameterEncoder.fromMethod(this, methodName).encode(args);
|
|
51
45
|
// Assert that the argsHash that has been signed matches the given arguments
|
|
52
|
-
|
|
53
|
-
// i.e. the result of the if-statement will be the same for all executions
|
|
54
|
-
// of this method
|
|
55
|
-
const argsHash = methodArguments.length > 0 ? Poseidon.hash(argsFields) : Field(0);
|
|
46
|
+
const argsHash = Poseidon.hash(fields);
|
|
56
47
|
transaction.argsHash.assertEquals(argsHash, "argsHash and therefore arguments of transaction and runtime call does not match");
|
|
57
48
|
const isMessage = Bool(options.invocationType === "INCOMING_MESSAGE");
|
|
58
49
|
transaction.assertTransactionType(Bool(isMessage));
|
|
@@ -105,8 +96,8 @@ function runtimeMethodInternal(options) {
|
|
|
105
96
|
Reflect.defineMetadata(runtimeMethodTypeMetadataKey, options.invocationType, target, methodName);
|
|
106
97
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
107
98
|
const simulatedMethod = descriptor.value;
|
|
108
|
-
descriptor.value = function value(...args) {
|
|
109
|
-
const constructorName = this.
|
|
99
|
+
descriptor.value = async function value(...args) {
|
|
100
|
+
const constructorName = this.name;
|
|
110
101
|
/**
|
|
111
102
|
* If its a top level method call, wrap it into a wrapped method,
|
|
112
103
|
* since it'll be turned into a real/mock prover in provableMethod().
|
|
@@ -117,7 +108,6 @@ function runtimeMethodInternal(options) {
|
|
|
117
108
|
const simulatedWrappedMethod = Reflect.apply(toWrappedMethod, this, [
|
|
118
109
|
methodName,
|
|
119
110
|
simulatedMethod,
|
|
120
|
-
args,
|
|
121
111
|
options,
|
|
122
112
|
]);
|
|
123
113
|
/**
|
|
@@ -125,11 +115,9 @@ function runtimeMethodInternal(options) {
|
|
|
125
115
|
* RuntimeMethodExecutionContext state, meaning it enters and exits
|
|
126
116
|
* the context properly.
|
|
127
117
|
*/
|
|
128
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
118
|
async function prover() {
|
|
130
119
|
executionContext.beforeMethod(constructorName, methodName, args);
|
|
131
120
|
const innerProver = toProver(combineMethodName(constructorName, methodName), simulatedWrappedMethod, false, ...args).bind(this);
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
133
121
|
let result;
|
|
134
122
|
try {
|
|
135
123
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -147,10 +135,9 @@ function runtimeMethodInternal(options) {
|
|
|
147
135
|
}
|
|
148
136
|
executionContext.setProver(prover.bind(this.runtime.zkProgrammable));
|
|
149
137
|
}
|
|
150
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
151
138
|
let result;
|
|
152
139
|
try {
|
|
153
|
-
result = Reflect.apply(simulatedMethod, this, args);
|
|
140
|
+
result = await Reflect.apply(simulatedMethod, this, args);
|
|
154
141
|
}
|
|
155
142
|
finally {
|
|
156
143
|
executionContext.afterMethod();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RuntimeMethodIdMapping } from "@proto-kit/protocol";
|
|
1
2
|
import type { Runtime, RuntimeModulesRecord } from "./Runtime";
|
|
2
3
|
/**
|
|
3
4
|
* Please see `getMethodId` to learn more about
|
|
@@ -7,6 +8,12 @@ export declare class MethodIdResolver {
|
|
|
7
8
|
private readonly runtime;
|
|
8
9
|
private readonly dictionary;
|
|
9
10
|
constructor(runtime: Runtime<RuntimeModulesRecord>);
|
|
11
|
+
/**
|
|
12
|
+
* The purpose of this method is to provide a dictionary where
|
|
13
|
+
* we can look up properties like methodId and invocationType
|
|
14
|
+
* for each runtimeMethod using their module name and method name
|
|
15
|
+
*/
|
|
16
|
+
methodIdMap(): RuntimeMethodIdMapping;
|
|
10
17
|
getMethodNameFromId(methodId: bigint): [string, string] | undefined;
|
|
11
18
|
getMethodId(moduleName: string, methodName: string): bigint;
|
|
12
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MethodIdResolver.d.ts","sourceRoot":"","sources":["../../src/runtime/MethodIdResolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MethodIdResolver.d.ts","sourceRoot":"","sources":["../../src/runtime/MethodIdResolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAS5E,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAE/D;;;GAGG;AACH,qBACa,gBAAgB;IAMN,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAEpB;gBAG+B,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAkB5E;;;;OAIG;IACI,WAAW,IAAI,sBAAsB;IAuCrC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;IAcnE,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;CAQnE"}
|
|
@@ -10,14 +10,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
|
+
import { filterNonUndefined } from "@proto-kit/common";
|
|
13
14
|
import { stringToField } from "@proto-kit/protocol";
|
|
14
15
|
import { Poseidon } from "o1js";
|
|
15
16
|
import { inject, injectable } from "tsyringe";
|
|
17
|
+
import { runtimeMethodTypeMetadataKey, } from "../method/runtimeMethod";
|
|
16
18
|
/**
|
|
17
19
|
* Please see `getMethodId` to learn more about
|
|
18
20
|
* methodId encoding
|
|
19
21
|
*/
|
|
20
|
-
let MethodIdResolver = class MethodIdResolver {
|
|
22
|
+
export let MethodIdResolver = class MethodIdResolver {
|
|
21
23
|
constructor(runtime) {
|
|
22
24
|
this.runtime = runtime;
|
|
23
25
|
this.dictionary = {};
|
|
@@ -32,6 +34,38 @@ let MethodIdResolver = class MethodIdResolver {
|
|
|
32
34
|
return dict;
|
|
33
35
|
}, {});
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The purpose of this method is to provide a dictionary where
|
|
39
|
+
* we can look up properties like methodId and invocationType
|
|
40
|
+
* for each runtimeMethod using their module name and method name
|
|
41
|
+
*/
|
|
42
|
+
methodIdMap() {
|
|
43
|
+
const methodIdResolver = this.runtime.dependencyContainer.resolve("MethodIdResolver");
|
|
44
|
+
const rawMappings = this.runtime.moduleNames.flatMap((moduleName) => {
|
|
45
|
+
const module = this.runtime.resolve(moduleName);
|
|
46
|
+
return module.runtimeMethodNames.map((method) => {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
48
|
+
const type = Reflect.getMetadata(runtimeMethodTypeMetadataKey, module, method);
|
|
49
|
+
if (type !== undefined) {
|
|
50
|
+
return {
|
|
51
|
+
name: `${moduleName}.${method}`,
|
|
52
|
+
methodId: methodIdResolver.getMethodId(moduleName, method),
|
|
53
|
+
type,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
return rawMappings
|
|
60
|
+
.filter(filterNonUndefined)
|
|
61
|
+
.reduce((acc, entry) => {
|
|
62
|
+
acc[entry.name] = {
|
|
63
|
+
methodId: entry.methodId,
|
|
64
|
+
type: entry.type,
|
|
65
|
+
};
|
|
66
|
+
return acc;
|
|
67
|
+
}, {});
|
|
68
|
+
}
|
|
35
69
|
getMethodNameFromId(methodId) {
|
|
36
70
|
const methodPath = this.dictionary[methodId.toString()];
|
|
37
71
|
if (methodPath === undefined) {
|
|
@@ -54,4 +88,3 @@ MethodIdResolver = __decorate([
|
|
|
54
88
|
__param(0, inject("Runtime")),
|
|
55
89
|
__metadata("design:paramtypes", [Function])
|
|
56
90
|
], MethodIdResolver);
|
|
57
|
-
export { MethodIdResolver };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZkProgram } from "o1js";
|
|
2
2
|
import { DependencyContainer } from "tsyringe";
|
|
3
3
|
import { StringKeyOf, ModuleContainer, ModulesConfig, ModulesRecord, TypedClass, ZkProgrammable, PlainZkProgram, AreProofsEnabled, ChildContainerProvider } from "@proto-kit/common";
|
|
4
|
-
import { MethodPublicOutput, StateServiceProvider,
|
|
4
|
+
import { MethodPublicOutput, StateServiceProvider, SimpleAsyncStateService } from "@proto-kit/protocol";
|
|
5
5
|
import { RuntimeModule } from "./RuntimeModule";
|
|
6
6
|
import { MethodIdResolver } from "./MethodIdResolver";
|
|
7
7
|
import { RuntimeEnvironment } from "./RuntimeEnvironment";
|
|
8
|
+
export declare function getAllPropertyNames(obj: any): (string | symbol)[];
|
|
8
9
|
/**
|
|
9
10
|
* Record of modules accepted by the Runtime module container.
|
|
10
11
|
*
|
|
@@ -31,7 +32,7 @@ export declare class RuntimeZkProgrammable<Modules extends RuntimeModulesRecord>
|
|
|
31
32
|
*/
|
|
32
33
|
export declare class Runtime<Modules extends RuntimeModulesRecord> extends ModuleContainer<Modules> implements RuntimeEnvironment {
|
|
33
34
|
static from<Modules extends RuntimeModulesRecord>(definition: RuntimeDefinition<Modules>): TypedClass<Runtime<Modules>>;
|
|
34
|
-
program?: ReturnType<typeof
|
|
35
|
+
program?: ReturnType<typeof ZkProgram>;
|
|
35
36
|
definition: RuntimeDefinition<Modules>;
|
|
36
37
|
zkProgrammable: ZkProgrammable<undefined, MethodPublicOutput>;
|
|
37
38
|
/**
|
|
@@ -43,7 +44,7 @@ export declare class Runtime<Modules extends RuntimeModulesRecord> extends Modul
|
|
|
43
44
|
create(childContainerProvider: ChildContainerProvider): void;
|
|
44
45
|
get appChain(): AreProofsEnabled | undefined;
|
|
45
46
|
get stateServiceProvider(): StateServiceProvider;
|
|
46
|
-
get stateService():
|
|
47
|
+
get stateService(): SimpleAsyncStateService;
|
|
47
48
|
get methodIdResolver(): MethodIdResolver;
|
|
48
49
|
/**
|
|
49
50
|
* @returns The dependency injection container of this runtime
|
|
@@ -53,7 +54,7 @@ export declare class Runtime<Modules extends RuntimeModulesRecord> extends Modul
|
|
|
53
54
|
* @param methodId The encoded name of the method to call.
|
|
54
55
|
* Encoding: "stringToField(module.name) << 128 + stringToField(method-name)"
|
|
55
56
|
*/
|
|
56
|
-
getMethodById(methodId: bigint): ((...args: unknown[]) => unknown) | undefined;
|
|
57
|
+
getMethodById(methodId: bigint): ((...args: unknown[]) => Promise<unknown>) | undefined;
|
|
57
58
|
/**
|
|
58
59
|
* Add a name and other respective properties required by RuntimeModules,
|
|
59
60
|
* that come from the current Runtime
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/Runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/Runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAc,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAW7B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,uBAa3C;AAED;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAC9C,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CACnC,CAAC;AAOF;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,oBAAoB;IACrE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACjC;AAED,qBAAa,qBAAqB,CAChC,OAAO,SAAS,oBAAoB,CACpC,SAAQ,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;gBAAzB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAInD,IAAW,QAAQ,iCAElB;IAEM,gBAAgB,IAAI,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC;CAuHzE;AAED;;;GAGG;AACH,qBACa,OAAO,CAAC,OAAO,SAAS,oBAAoB,CACvD,SAAQ,eAAe,CAAC,OAAO,CAC/B,YAAW,kBAAkB;WAEf,IAAI,CAAC,OAAO,SAAS,oBAAoB,EACrD,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACrC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IASxB,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;IAEvC,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAEvC,cAAc,EAAE,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IAErE;;;;OAIG;gBACgB,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC;IAOlD,MAAM,CAAC,sBAAsB,EAAE,sBAAsB;IAM5D,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAElD;IAED,IAAW,oBAAoB,IAAI,oBAAoB,CAItD;IAED,IAAW,YAAY,IAAI,uBAAuB,CAEjD;IAED,IAAW,gBAAgB,IAAI,gBAAgB,CAE9C;IAED;;OAEG;IACH,IAAW,mBAAmB,IAAI,mBAAmB,CAEpD;IAED;;;OAGG;IACI,aAAa,CAClB,QAAQ,EAAE,MAAM,GACf,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS;IAsBzD;;;;;;OAMG;IACI,cAAc,CACnB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,eAAe,EAAE,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAQ9D;;OAEG;IACH,IAAW,kBAAkB,aAE5B;CACF"}
|
package/dist/runtime/Runtime.js
CHANGED
|
@@ -8,19 +8,31 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
var Runtime_1;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { Experimental } from "o1js";
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument */
|
|
12
|
+
import { ZkProgram } from "o1js";
|
|
14
13
|
import { injectable } from "tsyringe";
|
|
15
14
|
import { ModuleContainer, ZkProgrammable, } from "@proto-kit/common";
|
|
16
15
|
import { MethodPublicOutput, } from "@proto-kit/protocol";
|
|
17
|
-
import { combineMethodName, isRuntimeMethod, toWrappedMethod, } from "../method/runtimeMethod";
|
|
16
|
+
import { combineMethodName, isRuntimeMethod, runtimeMethodTypeMetadataKey, toWrappedMethod, } from "../method/runtimeMethod";
|
|
18
17
|
import { MethodIdFactory } from "../factories/MethodIdFactory";
|
|
18
|
+
export function getAllPropertyNames(obj) {
|
|
19
|
+
let currentPrototype = obj;
|
|
20
|
+
let keys = [];
|
|
21
|
+
// if primitive (primitives still have keys) skip the first iteration
|
|
22
|
+
if (!(obj instanceof Object)) {
|
|
23
|
+
currentPrototype = Object.getPrototypeOf(obj);
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
26
|
+
while (currentPrototype) {
|
|
27
|
+
keys = keys.concat(Reflect.ownKeys(currentPrototype));
|
|
28
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
29
|
+
}
|
|
30
|
+
return keys;
|
|
31
|
+
}
|
|
19
32
|
const errors = {
|
|
20
33
|
methodNotFound: (methodKey) => new Error(`Unable to find method with id ${methodKey}`),
|
|
21
34
|
};
|
|
22
35
|
export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
24
36
|
constructor(runtime) {
|
|
25
37
|
super();
|
|
26
38
|
this.runtime = runtime;
|
|
@@ -31,8 +43,7 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
31
43
|
zkProgramFactory() {
|
|
32
44
|
// We need to use explicit type annotations here,
|
|
33
45
|
// therefore we can't use destructuring
|
|
34
|
-
// eslint-disable-next-line
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define,prefer-destructuring,putout/putout
|
|
46
|
+
// eslint-disable-next-line prefer-destructuring
|
|
36
47
|
const runtime = this.runtime;
|
|
37
48
|
const runtimeMethods = runtime.runtimeModuleNames.reduce((allMethods, runtimeModuleName) => {
|
|
38
49
|
runtime.isValidModuleName(runtime.definition.modules, runtimeModuleName);
|
|
@@ -41,19 +52,17 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
41
52
|
* regarding resolving only known modules. We assert in the line above
|
|
42
53
|
* but we cast it to any anyways to satisfy the proof system.
|
|
43
54
|
*/
|
|
44
|
-
// eslint-disable-next-line max-len
|
|
45
55
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
46
56
|
const runtimeModule = runtime.resolve(runtimeModuleName);
|
|
47
|
-
// eslint-disable-next-line max-len
|
|
48
57
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
49
58
|
const modulePrototype = Object.getPrototypeOf(runtimeModule);
|
|
50
|
-
const modulePrototypeMethods =
|
|
59
|
+
const modulePrototypeMethods = getAllPropertyNames(runtimeModule).map((method) => method.toString());
|
|
51
60
|
const moduleMethods = modulePrototypeMethods.reduce((allModuleMethods, methodName) => {
|
|
52
61
|
if (isRuntimeMethod(runtimeModule, methodName)) {
|
|
53
62
|
const combinedMethodName = combineMethodName(runtimeModuleName, methodName);
|
|
54
63
|
const method = modulePrototype[methodName];
|
|
55
|
-
const
|
|
56
|
-
|
|
64
|
+
const invocationType = Reflect.getMetadata(runtimeMethodTypeMetadataKey, runtimeModule, methodName);
|
|
65
|
+
const wrappedMethod = Reflect.apply(toWrappedMethod, runtimeModule, [methodName, method, { invocationType }]);
|
|
57
66
|
// TODO: find out how to import the Tuple type
|
|
58
67
|
const privateInputs = Reflect.getMetadata("design:paramtypes", runtimeModule, methodName);
|
|
59
68
|
return {
|
|
@@ -71,14 +80,13 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
71
80
|
...moduleMethods,
|
|
72
81
|
};
|
|
73
82
|
}, {});
|
|
74
|
-
const sortedRuntimeMethods = Object.fromEntries(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const program = Experimental.ZkProgram({
|
|
83
|
+
const sortedRuntimeMethods = Object.fromEntries(Object.entries(runtimeMethods).sort());
|
|
84
|
+
const program = ZkProgram({
|
|
85
|
+
name: "RuntimeProgram",
|
|
78
86
|
publicOutput: MethodPublicOutput,
|
|
79
87
|
methods: sortedRuntimeMethods,
|
|
80
88
|
});
|
|
81
|
-
const SelfProof =
|
|
89
|
+
const SelfProof = ZkProgram.Proof(program);
|
|
82
90
|
const methods = Object.keys(sortedRuntimeMethods).reduce((boundMethods, methodName) => {
|
|
83
91
|
boundMethods[methodName] = program[methodName].bind(program);
|
|
84
92
|
return boundMethods;
|
|
@@ -86,6 +94,7 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
86
94
|
return {
|
|
87
95
|
compile: program.compile.bind(program),
|
|
88
96
|
verify: program.verify.bind(program),
|
|
97
|
+
analyzeMethods: program.analyzeMethods.bind(program),
|
|
89
98
|
Proof: SelfProof,
|
|
90
99
|
methods,
|
|
91
100
|
};
|
|
@@ -95,7 +104,7 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
95
104
|
* Wrapper for an application specific runtime, which helps orchestrate
|
|
96
105
|
* runtime modules into an interoperable runtime.
|
|
97
106
|
*/
|
|
98
|
-
let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
107
|
+
export let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
99
108
|
static from(definition) {
|
|
100
109
|
return class RuntimeScoped extends Runtime_1 {
|
|
101
110
|
constructor() {
|
|
@@ -113,7 +122,6 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
|
113
122
|
this.definition = definition;
|
|
114
123
|
this.zkProgrammable = new RuntimeZkProgrammable(this);
|
|
115
124
|
}
|
|
116
|
-
// eslint-disable-next-line no-warning-comments
|
|
117
125
|
// TODO Remove after changing DFs to type-based approach
|
|
118
126
|
create(childContainerProvider) {
|
|
119
127
|
super.create(childContainerProvider);
|
|
@@ -149,8 +157,7 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
|
149
157
|
const [moduleName, methodName] = methodDescriptor;
|
|
150
158
|
this.assertIsValidModuleName(moduleName);
|
|
151
159
|
const module = this.resolve(moduleName);
|
|
152
|
-
// eslint-disable-next-line
|
|
153
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions,@typescript-eslint/no-unsafe-member-access
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
154
161
|
const method = module[methodName];
|
|
155
162
|
if (method === undefined) {
|
|
156
163
|
throw errors.methodNotFound(`${moduleName}.${methodName}`);
|
|
@@ -181,4 +188,4 @@ Runtime = Runtime_1 = __decorate([
|
|
|
181
188
|
injectable(),
|
|
182
189
|
__metadata("design:paramtypes", [Object])
|
|
183
190
|
], Runtime);
|
|
184
|
-
|
|
191
|
+
/* eslint-enable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AreProofsEnabled, WithZkProgrammable } from "@proto-kit/common";
|
|
2
|
-
import { MethodPublicOutput,
|
|
2
|
+
import { MethodPublicOutput, SimpleAsyncStateService, StateServiceProvider } from "@proto-kit/protocol";
|
|
3
3
|
import { MethodIdResolver } from "./MethodIdResolver";
|
|
4
4
|
export interface RuntimeEnvironment extends WithZkProgrammable<undefined, MethodPublicOutput> {
|
|
5
5
|
get appChain(): AreProofsEnabled | undefined;
|
|
6
|
-
get stateService():
|
|
6
|
+
get stateService(): SimpleAsyncStateService;
|
|
7
7
|
get stateServiceProvider(): StateServiceProvider;
|
|
8
8
|
get methodIdResolver(): MethodIdResolver;
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeEnvironment.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeEnvironment.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"RuntimeEnvironment.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeEnvironment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,WAAW,kBACf,SAAQ,kBAAkB,CAAC,SAAS,EAAE,kBAAkB,CAAC;IACzD,IAAI,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAAC;IAC7C,IAAI,YAAY,IAAI,uBAAuB,CAAC;IAC5C,IAAI,oBAAoB,IAAI,oBAAoB,CAAC;IACjD,IAAI,gBAAgB,IAAI,gBAAgB,CAAC;CAC1C"}
|