@proto-kit/module 0.1.1-develop.651 → 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 -51
- package/dist/method/runtimeMethod.d.ts +6 -5
- package/dist/method/runtimeMethod.d.ts.map +1 -1
- package/dist/method/runtimeMethod.js +7 -17
- package/dist/runtime/MethodIdResolver.d.ts.map +1 -1
- package/dist/runtime/MethodIdResolver.js +2 -2
- package/dist/runtime/Runtime.d.ts +5 -5
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +16 -23
- package/dist/runtime/RuntimeEnvironment.d.ts +2 -2
- package/dist/runtime/RuntimeEnvironment.d.ts.map +1 -1
- package/dist/runtime/RuntimeModule.d.ts.map +1 -1
- package/dist/runtime/RuntimeModule.js +2 -3
- 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 +186 -84
- package/src/method/runtimeMethod.ts +19 -30
- package/src/runtime/MethodIdResolver.ts +1 -0
- package/src/runtime/Runtime.ts +27 -29
- package/src/runtime/RuntimeEnvironment.ts +4 -7
- package/src/runtime/RuntimeModule.ts +2 -8
- 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, Provable, } 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,83 +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
|
-
|
|
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
|
+
};
|
|
69
142
|
}
|
|
70
143
|
const argumentType = this.types[index];
|
|
71
|
-
return
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
argsFields,
|
|
85
|
-
argsJSON,
|
|
86
|
-
};
|
|
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: [] });
|
|
87
157
|
}
|
|
88
|
-
|
|
158
|
+
fieldSize() {
|
|
89
159
|
return this.types
|
|
90
160
|
.map((type) => MethodParameterEncoder.fieldSize(type) ?? 0)
|
|
91
161
|
.reduce((a, b) => a + b, 0);
|
|
92
162
|
}
|
|
93
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,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
1
|
import { Bool, Field, Poseidon } from "o1js";
|
|
3
2
|
import { container } from "tsyringe";
|
|
4
3
|
import { ProvableStateTransition, MethodPublicOutput, RuntimeMethodExecutionContext, StateTransitionReductionList, } from "@proto-kit/protocol";
|
|
@@ -10,9 +9,7 @@ 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
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
stateTransitions) {
|
|
12
|
+
export function toStateTransitionsHash(stateTransitions) {
|
|
16
13
|
const stateTransitionsHashList = new StateTransitionReductionList(ProvableStateTransition);
|
|
17
14
|
return stateTransitions
|
|
18
15
|
.map((stateTransition) => stateTransition.toProvable())
|
|
@@ -21,11 +18,10 @@ stateTransitions) {
|
|
|
21
18
|
}
|
|
22
19
|
export function toWrappedMethod(methodName, moduleMethod, options) {
|
|
23
20
|
const executionContext = container.resolve(RuntimeMethodExecutionContext);
|
|
24
|
-
const wrappedMethod = (...args) => {
|
|
25
|
-
Reflect.apply(moduleMethod, this, args);
|
|
21
|
+
const wrappedMethod = async (...args) => {
|
|
22
|
+
await Reflect.apply(moduleMethod, this, args);
|
|
26
23
|
const { result: { stateTransitions, status }, } = executionContext.current();
|
|
27
24
|
const stateTransitionsHash = toStateTransitionsHash(stateTransitions);
|
|
28
|
-
const input = this.getInputs();
|
|
29
25
|
const { name, runtime } = this;
|
|
30
26
|
if (name === undefined) {
|
|
31
27
|
throw errors.runtimeNameNotSet();
|
|
@@ -45,12 +41,9 @@ export function toWrappedMethod(methodName, moduleMethod, options) {
|
|
|
45
41
|
* Use the type info obtained previously to convert
|
|
46
42
|
* the args passed to fields
|
|
47
43
|
*/
|
|
48
|
-
const {
|
|
44
|
+
const { fields } = MethodParameterEncoder.fromMethod(this, methodName).encode(args);
|
|
49
45
|
// Assert that the argsHash that has been signed matches the given arguments
|
|
50
|
-
|
|
51
|
-
// i.e. the result of the if-statement will be the same for all executions
|
|
52
|
-
// of this method
|
|
53
|
-
const argsHash = (args ?? []).length > 0 ? Poseidon.hash(argsFields) : Field(0);
|
|
46
|
+
const argsHash = Poseidon.hash(fields);
|
|
54
47
|
transaction.argsHash.assertEquals(argsHash, "argsHash and therefore arguments of transaction and runtime call does not match");
|
|
55
48
|
const isMessage = Bool(options.invocationType === "INCOMING_MESSAGE");
|
|
56
49
|
transaction.assertTransactionType(Bool(isMessage));
|
|
@@ -103,7 +96,7 @@ function runtimeMethodInternal(options) {
|
|
|
103
96
|
Reflect.defineMetadata(runtimeMethodTypeMetadataKey, options.invocationType, target, methodName);
|
|
104
97
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
105
98
|
const simulatedMethod = descriptor.value;
|
|
106
|
-
descriptor.value = function value(...args) {
|
|
99
|
+
descriptor.value = async function value(...args) {
|
|
107
100
|
const constructorName = this.name;
|
|
108
101
|
/**
|
|
109
102
|
* If its a top level method call, wrap it into a wrapped method,
|
|
@@ -122,11 +115,9 @@ function runtimeMethodInternal(options) {
|
|
|
122
115
|
* RuntimeMethodExecutionContext state, meaning it enters and exits
|
|
123
116
|
* the context properly.
|
|
124
117
|
*/
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
118
|
async function prover() {
|
|
127
119
|
executionContext.beforeMethod(constructorName, methodName, args);
|
|
128
120
|
const innerProver = toProver(combineMethodName(constructorName, methodName), simulatedWrappedMethod, false, ...args).bind(this);
|
|
129
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
130
121
|
let result;
|
|
131
122
|
try {
|
|
132
123
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -144,10 +135,9 @@ function runtimeMethodInternal(options) {
|
|
|
144
135
|
}
|
|
145
136
|
executionContext.setProver(prover.bind(this.runtime.zkProgrammable));
|
|
146
137
|
}
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
148
138
|
let result;
|
|
149
139
|
try {
|
|
150
|
-
result = Reflect.apply(simulatedMethod, this, args);
|
|
140
|
+
result = await Reflect.apply(simulatedMethod, this, args);
|
|
151
141
|
}
|
|
152
142
|
finally {
|
|
153
143
|
executionContext.afterMethod();
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
|
@@ -19,7 +19,7 @@ import { runtimeMethodTypeMetadataKey, } from "../method/runtimeMethod";
|
|
|
19
19
|
* Please see `getMethodId` to learn more about
|
|
20
20
|
* methodId encoding
|
|
21
21
|
*/
|
|
22
|
-
let MethodIdResolver = class MethodIdResolver {
|
|
22
|
+
export let MethodIdResolver = class MethodIdResolver {
|
|
23
23
|
constructor(runtime) {
|
|
24
24
|
this.runtime = runtime;
|
|
25
25
|
this.dictionary = {};
|
|
@@ -44,6 +44,7 @@ let MethodIdResolver = class MethodIdResolver {
|
|
|
44
44
|
const rawMappings = this.runtime.moduleNames.flatMap((moduleName) => {
|
|
45
45
|
const module = this.runtime.resolve(moduleName);
|
|
46
46
|
return module.runtimeMethodNames.map((method) => {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
47
48
|
const type = Reflect.getMetadata(runtimeMethodTypeMetadataKey, module, method);
|
|
48
49
|
if (type !== undefined) {
|
|
49
50
|
return {
|
|
@@ -87,4 +88,3 @@ MethodIdResolver = __decorate([
|
|
|
87
88
|
__param(0, inject("Runtime")),
|
|
88
89
|
__metadata("design:paramtypes", [Function])
|
|
89
90
|
], MethodIdResolver);
|
|
90
|
-
export { MethodIdResolver };
|
|
@@ -1,7 +1,7 @@
|
|
|
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";
|
|
@@ -32,7 +32,7 @@ export declare class RuntimeZkProgrammable<Modules extends RuntimeModulesRecord>
|
|
|
32
32
|
*/
|
|
33
33
|
export declare class Runtime<Modules extends RuntimeModulesRecord> extends ModuleContainer<Modules> implements RuntimeEnvironment {
|
|
34
34
|
static from<Modules extends RuntimeModulesRecord>(definition: RuntimeDefinition<Modules>): TypedClass<Runtime<Modules>>;
|
|
35
|
-
program?: ReturnType<typeof
|
|
35
|
+
program?: ReturnType<typeof ZkProgram>;
|
|
36
36
|
definition: RuntimeDefinition<Modules>;
|
|
37
37
|
zkProgrammable: ZkProgrammable<undefined, MethodPublicOutput>;
|
|
38
38
|
/**
|
|
@@ -44,7 +44,7 @@ export declare class Runtime<Modules extends RuntimeModulesRecord> extends Modul
|
|
|
44
44
|
create(childContainerProvider: ChildContainerProvider): void;
|
|
45
45
|
get appChain(): AreProofsEnabled | undefined;
|
|
46
46
|
get stateServiceProvider(): StateServiceProvider;
|
|
47
|
-
get stateService():
|
|
47
|
+
get stateService(): SimpleAsyncStateService;
|
|
48
48
|
get methodIdResolver(): MethodIdResolver;
|
|
49
49
|
/**
|
|
50
50
|
* @returns The dependency injection container of this runtime
|
|
@@ -54,7 +54,7 @@ export declare class Runtime<Modules extends RuntimeModulesRecord> extends Modul
|
|
|
54
54
|
* @param methodId The encoded name of the method to call.
|
|
55
55
|
* Encoding: "stringToField(module.name) << 128 + stringToField(method-name)"
|
|
56
56
|
*/
|
|
57
|
-
getMethodById(methodId: bigint): ((...args: unknown[]) => unknown) | undefined;
|
|
57
|
+
getMethodById(methodId: bigint): ((...args: unknown[]) => Promise<unknown>) | undefined;
|
|
58
58
|
/**
|
|
59
59
|
* Add a name and other respective properties required by RuntimeModules,
|
|
60
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,23 +8,24 @@ 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
16
|
import { combineMethodName, isRuntimeMethod, runtimeMethodTypeMetadataKey, toWrappedMethod, } from "../method/runtimeMethod";
|
|
18
17
|
import { MethodIdFactory } from "../factories/MethodIdFactory";
|
|
19
18
|
export function getAllPropertyNames(obj) {
|
|
19
|
+
let currentPrototype = obj;
|
|
20
20
|
let keys = [];
|
|
21
21
|
// if primitive (primitives still have keys) skip the first iteration
|
|
22
22
|
if (!(obj instanceof Object)) {
|
|
23
|
-
|
|
23
|
+
currentPrototype = Object.getPrototypeOf(obj);
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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);
|
|
28
29
|
}
|
|
29
30
|
return keys;
|
|
30
31
|
}
|
|
@@ -32,7 +33,6 @@ const errors = {
|
|
|
32
33
|
methodNotFound: (methodKey) => new Error(`Unable to find method with id ${methodKey}`),
|
|
33
34
|
};
|
|
34
35
|
export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
36
36
|
constructor(runtime) {
|
|
37
37
|
super();
|
|
38
38
|
this.runtime = runtime;
|
|
@@ -43,8 +43,7 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
43
43
|
zkProgramFactory() {
|
|
44
44
|
// We need to use explicit type annotations here,
|
|
45
45
|
// therefore we can't use destructuring
|
|
46
|
-
// eslint-disable-next-line
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define,prefer-destructuring,putout/putout
|
|
46
|
+
// eslint-disable-next-line prefer-destructuring
|
|
48
47
|
const runtime = this.runtime;
|
|
49
48
|
const runtimeMethods = runtime.runtimeModuleNames.reduce((allMethods, runtimeModuleName) => {
|
|
50
49
|
runtime.isValidModuleName(runtime.definition.modules, runtimeModuleName);
|
|
@@ -53,10 +52,8 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
53
52
|
* regarding resolving only known modules. We assert in the line above
|
|
54
53
|
* but we cast it to any anyways to satisfy the proof system.
|
|
55
54
|
*/
|
|
56
|
-
// eslint-disable-next-line max-len
|
|
57
55
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
58
56
|
const runtimeModule = runtime.resolve(runtimeModuleName);
|
|
59
|
-
// eslint-disable-next-line max-len
|
|
60
57
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
61
58
|
const modulePrototype = Object.getPrototypeOf(runtimeModule);
|
|
62
59
|
const modulePrototypeMethods = getAllPropertyNames(runtimeModule).map((method) => method.toString());
|
|
@@ -66,7 +63,6 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
66
63
|
const method = modulePrototype[methodName];
|
|
67
64
|
const invocationType = Reflect.getMetadata(runtimeMethodTypeMetadataKey, runtimeModule, methodName);
|
|
68
65
|
const wrappedMethod = Reflect.apply(toWrappedMethod, runtimeModule, [methodName, method, { invocationType }]);
|
|
69
|
-
// eslint-disable-next-line no-warning-comments
|
|
70
66
|
// TODO: find out how to import the Tuple type
|
|
71
67
|
const privateInputs = Reflect.getMetadata("design:paramtypes", runtimeModule, methodName);
|
|
72
68
|
return {
|
|
@@ -84,14 +80,13 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
84
80
|
...moduleMethods,
|
|
85
81
|
};
|
|
86
82
|
}, {});
|
|
87
|
-
const sortedRuntimeMethods = Object.fromEntries(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const program = Experimental.ZkProgram({
|
|
83
|
+
const sortedRuntimeMethods = Object.fromEntries(Object.entries(runtimeMethods).sort());
|
|
84
|
+
const program = ZkProgram({
|
|
85
|
+
name: "RuntimeProgram",
|
|
91
86
|
publicOutput: MethodPublicOutput,
|
|
92
87
|
methods: sortedRuntimeMethods,
|
|
93
88
|
});
|
|
94
|
-
const SelfProof =
|
|
89
|
+
const SelfProof = ZkProgram.Proof(program);
|
|
95
90
|
const methods = Object.keys(sortedRuntimeMethods).reduce((boundMethods, methodName) => {
|
|
96
91
|
boundMethods[methodName] = program[methodName].bind(program);
|
|
97
92
|
return boundMethods;
|
|
@@ -109,7 +104,7 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
|
|
|
109
104
|
* Wrapper for an application specific runtime, which helps orchestrate
|
|
110
105
|
* runtime modules into an interoperable runtime.
|
|
111
106
|
*/
|
|
112
|
-
let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
107
|
+
export let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
113
108
|
static from(definition) {
|
|
114
109
|
return class RuntimeScoped extends Runtime_1 {
|
|
115
110
|
constructor() {
|
|
@@ -127,7 +122,6 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
|
127
122
|
this.definition = definition;
|
|
128
123
|
this.zkProgrammable = new RuntimeZkProgrammable(this);
|
|
129
124
|
}
|
|
130
|
-
// eslint-disable-next-line no-warning-comments
|
|
131
125
|
// TODO Remove after changing DFs to type-based approach
|
|
132
126
|
create(childContainerProvider) {
|
|
133
127
|
super.create(childContainerProvider);
|
|
@@ -163,8 +157,7 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
|
163
157
|
const [moduleName, methodName] = methodDescriptor;
|
|
164
158
|
this.assertIsValidModuleName(moduleName);
|
|
165
159
|
const module = this.resolve(moduleName);
|
|
166
|
-
// eslint-disable-next-line
|
|
167
|
-
// 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
|
|
168
161
|
const method = module[methodName];
|
|
169
162
|
if (method === undefined) {
|
|
170
163
|
throw errors.methodNotFound(`${moduleName}.${methodName}`);
|
|
@@ -195,4 +188,4 @@ Runtime = Runtime_1 = __decorate([
|
|
|
195
188
|
injectable(),
|
|
196
189
|
__metadata("design:paramtypes", [Object])
|
|
197
190
|
], Runtime);
|
|
198
|
-
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeModule.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EACL,YAAY,EACZ,kBAAkB,
|
|
1
|
+
{"version":3,"file":"RuntimeModule.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EACL,YAAY,EACZ,kBAAkB,EAElB,0BAA0B,EAE3B,MAAM,qBAAqB,CAAC;AAK7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAM1D;;GAEG;AACH,qBACa,aAAa,CACxB,MAAM,GAAG,QAAQ,CACjB,SAAQ,kBAAkB,CAAC,MAAM,CAAC;IAClC,OAAc,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAM;IAE7C;;OAEG;IACH,SAAgB,kBAAkB,EAAE,MAAM,EAAE,CAAM;IAElD;;;;OAIG;IACI,eAAe,UAAQ;IAEvB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,OAAO,CAAC,EAAE,kBAAkB,CAAC;;IAY7B,SAAS,IAAI,0BAA0B;IAa9C,IAAW,WAAW,IAAI,kBAAkB,CAE3C;IAED,IAAW,OAAO,IAAI,YAAY,CAEjC;CACF"}
|
|
@@ -10,15 +10,15 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
import { ConfigurableModule } from "@proto-kit/common";
|
|
11
11
|
import { container, injectable } from "tsyringe";
|
|
12
12
|
import { RuntimeMethodExecutionContext, RuntimeMethodExecutionDataStruct, } from "@proto-kit/protocol";
|
|
13
|
-
import { runtimeMethodNamesMetadataKey } from "../method/runtimeMethod";
|
|
14
13
|
import { Provable } from "o1js";
|
|
14
|
+
import { runtimeMethodNamesMetadataKey } from "../method/runtimeMethod";
|
|
15
15
|
const errors = {
|
|
16
16
|
inputDataNotSet: () => new Error("Input data for runtime execution not set"),
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* Base class for runtime modules providing the necessary utilities.
|
|
20
20
|
*/
|
|
21
|
-
let RuntimeModule = class RuntimeModule extends ConfigurableModule {
|
|
21
|
+
export let RuntimeModule = class RuntimeModule extends ConfigurableModule {
|
|
22
22
|
constructor() {
|
|
23
23
|
super();
|
|
24
24
|
/**
|
|
@@ -56,4 +56,3 @@ RuntimeModule = __decorate([
|
|
|
56
56
|
injectable(),
|
|
57
57
|
__metadata("design:paramtypes", [])
|
|
58
58
|
], RuntimeModule);
|
|
59
|
-
export { RuntimeModule };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DependencyFactory } from "@proto-kit/common";
|
|
2
|
+
import { MethodIdResolver } from "../runtime/MethodIdResolver";
|
|
3
|
+
export declare class MethodIdFactory implements DependencyFactory {
|
|
4
|
+
dependencies(): {
|
|
5
|
+
methodIdResolver: {
|
|
6
|
+
useClass: typeof MethodIdResolver;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=MethodIdFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MethodIdFactory.d.ts","sourceRoot":"","sources":["../../../src/factories/MethodIdFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,qBAAa,eAAgB,YAAW,iBAAiB;IAChD,YAAY;;;;;CAOpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./method/runtimeMethod";
|
|
2
|
+
export * from "./module/decorator";
|
|
3
|
+
export * from "./runtime/RuntimeModule";
|
|
4
|
+
export * from "./runtime/RuntimeEnvironment";
|
|
5
|
+
export * from "./runtime/Runtime";
|
|
6
|
+
export * from "./state/InMemoryStateService";
|
|
7
|
+
export * from "./state/decorator";
|
|
8
|
+
export * from "./method/MethodParameterEncoder";
|
|
9
|
+
export * from "./runtime/MethodIdResolver";
|
|
10
|
+
export * from "./factories/MethodIdFactory";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./method/runtimeMethod";
|
|
2
|
+
export * from "./module/decorator";
|
|
3
|
+
export * from "./runtime/RuntimeModule";
|
|
4
|
+
export * from "./runtime/RuntimeEnvironment";
|
|
5
|
+
export * from "./runtime/Runtime";
|
|
6
|
+
export * from "./state/InMemoryStateService";
|
|
7
|
+
export * from "./state/decorator";
|
|
8
|
+
export * from "./method/MethodParameterEncoder";
|
|
9
|
+
export * from "./runtime/MethodIdResolver";
|
|
10
|
+
export * from "./factories/MethodIdFactory";
|