@proto-kit/module 0.1.1-develop.299 → 0.1.1-develop.334
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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/method/MethodParameterDecoder.d.ts +3 -1
- package/dist/method/MethodParameterDecoder.d.ts.map +1 -1
- package/dist/method/MethodParameterDecoder.js +12 -0
- package/dist/method/runtimeMethod.d.ts +3 -3
- package/dist/method/runtimeMethod.d.ts.map +1 -1
- package/dist/method/runtimeMethod.js +10 -6
- package/dist/runtime/MethodIdResolver.d.ts.map +1 -1
- package/dist/runtime/MethodIdResolver.js +20 -6
- package/dist/runtime/Runtime.d.ts +1 -6
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +6 -11
- package/dist/runtime/RuntimeModule.d.ts +1 -10
- package/dist/runtime/RuntimeModule.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/method/MethodParameterDecoder.ts +17 -0
- package/src/method/runtimeMethod.ts +25 -14
- package/src/runtime/MethodIdResolver.ts +6 -4
- package/src/runtime/Runtime.ts +8 -16
- package/src/runtime/RuntimeModule.ts +0 -11
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC"}
|
|
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,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { FlexibleProvable } from "o1js";
|
|
1
|
+
import { FlexibleProvable, ProvableExtended } from "o1js";
|
|
2
2
|
import { RuntimeModule } from "../runtime/RuntimeModule";
|
|
3
3
|
export declare class MethodParameterDecoder {
|
|
4
4
|
private readonly types;
|
|
5
5
|
static fromMethod(target: RuntimeModule<unknown>, methodName: string): MethodParameterDecoder;
|
|
6
|
+
static fieldSize(type: ProvableExtended<unknown>): number | undefined;
|
|
6
7
|
private constructor();
|
|
7
8
|
fromJSON(argsJSON: string[]): FlexibleProvable<unknown>[];
|
|
9
|
+
get fieldSize(): number;
|
|
8
10
|
}
|
|
9
11
|
//# sourceMappingURL=MethodParameterDecoder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MethodParameterDecoder.d.ts","sourceRoot":"","sources":["../../src/method/MethodParameterDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"MethodParameterDecoder.d.ts","sourceRoot":"","sources":["../../src/method/MethodParameterDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AASzD,qBAAa,sBAAsB;IAuBb,OAAO,CAAC,QAAQ,CAAC,KAAK;WAtB5B,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,MAAM;WAiB7D,SAAS,CAAC,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS;IAK5E,OAAO;IAEA,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,EAAE;IAmBhE,IAAW,SAAS,IAAI,MAAM,CAI7B;CACF"}
|
|
@@ -5,8 +5,15 @@ export class MethodParameterDecoder {
|
|
|
5
5
|
static fromMethod(target, methodName) {
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
7
7
|
const paramtypes = Reflect.getMetadata("design:paramtypes", target, methodName);
|
|
8
|
+
if (paramtypes === undefined) {
|
|
9
|
+
throw new Error(`Method with name ${methodName} doesn't exist on this module`);
|
|
10
|
+
}
|
|
8
11
|
return new MethodParameterDecoder(paramtypes);
|
|
9
12
|
}
|
|
13
|
+
static fieldSize(type) {
|
|
14
|
+
// as any, since we shouldn't be using this workaround in the first place
|
|
15
|
+
return type.prototype._fields?.length ?? type.sizeInFields?.();
|
|
16
|
+
}
|
|
10
17
|
constructor(types) {
|
|
11
18
|
this.types = types;
|
|
12
19
|
}
|
|
@@ -25,4 +32,9 @@ export class MethodParameterDecoder {
|
|
|
25
32
|
return value;
|
|
26
33
|
});
|
|
27
34
|
}
|
|
35
|
+
get fieldSize() {
|
|
36
|
+
return this.types
|
|
37
|
+
.map((type) => MethodParameterDecoder.fieldSize(type) ?? 0)
|
|
38
|
+
.reduce((a, b) => a + b, 0);
|
|
39
|
+
}
|
|
28
40
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { StateTransition, MethodPublicOutput } from "@proto-kit/protocol";
|
|
2
|
-
import {
|
|
2
|
+
import { ArgumentTypes } from "@proto-kit/common";
|
|
3
3
|
import type { RuntimeModule } from "../runtime/RuntimeModule.js";
|
|
4
4
|
export declare function toStateTransitionsHash(stateTransitions: StateTransition<any>[]): import("o1js/dist/node/lib/field.js").Field;
|
|
5
|
-
export type WrappedMethod = (...args:
|
|
6
|
-
export declare function toWrappedMethod(this: RuntimeModule<unknown>, methodName: string, moduleMethod: (...args:
|
|
5
|
+
export type WrappedMethod = (...args: ArgumentTypes) => MethodPublicOutput;
|
|
6
|
+
export declare function toWrappedMethod(this: RuntimeModule<unknown>, methodName: string, moduleMethod: (...args: ArgumentTypes) => unknown, methodArguments: ArgumentTypes): WrappedMethod;
|
|
7
7
|
export declare function combineMethodName(runtimeModuleName: string, methodName: string): string;
|
|
8
8
|
export declare const runtimeMethodMetadataKey = "yab-method";
|
|
9
9
|
export declare const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
|
|
@@ -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":"AASA,OAAO,EACL,eAAe,EAGf,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAOL,aAAa,EAGd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAoBjE,wBAAgB,sBAAsB,CAEpC,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,+CAczC;AAGD,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,aAAa,KAAK,kBAAkB,CAAC;AAE3E,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,aAAa,KAAK,OAAO,EACjD,eAAe,EAAE,aAAa,iBAqG/B;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;AAEzE;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,WAAW,EAAE,MAAM,WAKpB;AAED,wBAAgB,aAAa,aAEjB,cAAc,OAAO,CAAC,cAClB,MAAM,cACN,kBAAkB,UAwFjC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
1
2
|
import { Field, Poseidon, Proof, } from "o1js";
|
|
2
3
|
import { container } from "tsyringe";
|
|
3
4
|
import { DefaultProvableHashList, ProvableStateTransition, MethodPublicOutput, RuntimeMethodExecutionContext, } from "@proto-kit/protocol";
|
|
@@ -40,6 +41,7 @@ export function toWrappedMethod(methodName, moduleMethod, methodArguments) {
|
|
|
40
41
|
throw errors.fieldNotConstant("methodId");
|
|
41
42
|
}
|
|
42
43
|
input.transaction.methodId.assertEquals(thisMethodId, "Runtimemethod called with wrong methodId on the transaction object");
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
43
45
|
const parameterTypes = Reflect.getMetadata("design:paramtypes", this, methodName);
|
|
44
46
|
/**
|
|
45
47
|
* Use the type info obtained previously to convert
|
|
@@ -47,16 +49,18 @@ export function toWrappedMethod(methodName, moduleMethod, methodArguments) {
|
|
|
47
49
|
*/
|
|
48
50
|
const argsFields = args.flatMap((argument, index) => {
|
|
49
51
|
if (argument instanceof Proof) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
52
|
+
// eslint-disable-next-line max-len
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
54
|
+
const argumentType = parameterTypes[index];
|
|
55
|
+
const publicOutputType = argumentType?.publicOutputType;
|
|
56
|
+
const publicInputType = argumentType?.publicInputType;
|
|
53
57
|
const inputFields = publicInputType?.toFields(argument.publicInput) ?? [];
|
|
54
58
|
const outputFields = publicOutputType?.toFields(argument.publicOutput) ?? [];
|
|
55
59
|
return [...inputFields, ...outputFields];
|
|
56
60
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
62
|
+
const argumentType = parameterTypes[index];
|
|
63
|
+
return argumentType.toFields(argument);
|
|
60
64
|
});
|
|
61
65
|
// Assert that the argsHash that has been signed matches the given arguments
|
|
62
66
|
// We can use js-if here, because methodArguments is statically sizes
|
|
@@ -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":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAE/D;;;GAGG;AACH,qBACa,gBAAgB;IAMzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAEpB;gBAGY,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,EACtC,OAAO,EAAE,oBAAoB;IAkBzC,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"}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
1
10
|
import { stringToField } from "@proto-kit/protocol";
|
|
2
11
|
import { Poseidon } from "o1js";
|
|
12
|
+
import { injectable } from "tsyringe";
|
|
3
13
|
/**
|
|
4
14
|
* Please see `getMethodId` to learn more about
|
|
5
15
|
* methodId encoding
|
|
6
16
|
*/
|
|
7
|
-
|
|
17
|
+
let MethodIdResolver = class MethodIdResolver {
|
|
8
18
|
constructor(runtime, modules) {
|
|
9
19
|
this.runtime = runtime;
|
|
10
20
|
this.modules = modules;
|
|
@@ -21,12 +31,11 @@ export class MethodIdResolver {
|
|
|
21
31
|
}, {});
|
|
22
32
|
}
|
|
23
33
|
getMethodNameFromId(methodId) {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
// TODO Replace by throwing exception?
|
|
27
|
-
if (moduleName === undefined || methodName === undefined) {
|
|
34
|
+
const methodPath = this.dictionary[methodId.toString()];
|
|
35
|
+
if (methodPath === undefined) {
|
|
28
36
|
return undefined;
|
|
29
37
|
}
|
|
38
|
+
const { moduleName, methodName } = methodPath;
|
|
30
39
|
this.runtime.assertIsValidModuleName(this.modules, moduleName);
|
|
31
40
|
return [moduleName, methodName];
|
|
32
41
|
}
|
|
@@ -37,4 +46,9 @@ export class MethodIdResolver {
|
|
|
37
46
|
stringToField(methodName),
|
|
38
47
|
]).toBigInt();
|
|
39
48
|
}
|
|
40
|
-
}
|
|
49
|
+
};
|
|
50
|
+
MethodIdResolver = __decorate([
|
|
51
|
+
injectable(),
|
|
52
|
+
__metadata("design:paramtypes", [Function, Object])
|
|
53
|
+
], MethodIdResolver);
|
|
54
|
+
export { MethodIdResolver };
|
|
@@ -16,10 +16,6 @@ export type RuntimeModulesRecord = ModulesRecord<TypedClass<RuntimeModule<unknow
|
|
|
16
16
|
* Definition / required arguments for the Runtime class
|
|
17
17
|
*/
|
|
18
18
|
export interface RuntimeDefinition<Modules extends RuntimeModulesRecord> {
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated
|
|
21
|
-
*/
|
|
22
|
-
state?: StateService;
|
|
23
19
|
modules: Modules;
|
|
24
20
|
config?: ModulesConfig<Modules>;
|
|
25
21
|
}
|
|
@@ -38,7 +34,6 @@ export declare class Runtime<Modules extends RuntimeModulesRecord> extends Modul
|
|
|
38
34
|
program?: ReturnType<typeof Experimental.ZkProgram>;
|
|
39
35
|
definition: RuntimeDefinition<Modules>;
|
|
40
36
|
zkProgrammable: ZkProgrammable<undefined, MethodPublicOutput>;
|
|
41
|
-
private readonly stateServiceProviderInstance;
|
|
42
37
|
/**
|
|
43
38
|
* Creates a new Runtime from the provided config
|
|
44
39
|
*
|
|
@@ -47,8 +42,8 @@ export declare class Runtime<Modules extends RuntimeModulesRecord> extends Modul
|
|
|
47
42
|
constructor(definition: RuntimeDefinition<Modules>);
|
|
48
43
|
create(childContainerProvider: ChildContainerProvider): void;
|
|
49
44
|
get appChain(): AreProofsEnabled | undefined;
|
|
50
|
-
get stateService(): StateService;
|
|
51
45
|
get stateServiceProvider(): StateServiceProvider;
|
|
46
|
+
get stateService(): StateService;
|
|
52
47
|
get methodIdResolver(): MethodIdResolver;
|
|
53
48
|
/**
|
|
54
49
|
* @returns The dependency injection container of this runtime
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/Runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAc,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,EAEd,gBAAgB,
|
|
1
|
+
{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/Runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAc,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,EAEd,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACb,MAAM,qBAAqB,CAAC;AAU7B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;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;IAE3B,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;CAgHzE;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,YAAY,CAAC,SAAS,CAAC,CAAC;IAEpD,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;IAQlD,MAAM,CAAC,sBAAsB,EAAE,sBAAsB;IAI5D,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAElD;IAED,IAAW,oBAAoB,IAAI,oBAAoB,CAItD;IAED,IAAW,YAAY,IAAI,YAAY,CAEtC;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,GAAG,SAAS;IAwBhD;;;;;;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
|
@@ -12,10 +12,9 @@ var Runtime_1;
|
|
|
12
12
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,max-lines */
|
|
13
13
|
import { Experimental } from "o1js";
|
|
14
14
|
import { injectable } from "tsyringe";
|
|
15
|
-
import { ModuleContainer, ZkProgrammable } from "@proto-kit/common";
|
|
16
|
-
import { MethodPublicOutput,
|
|
15
|
+
import { ModuleContainer, ZkProgrammable, } from "@proto-kit/common";
|
|
16
|
+
import { MethodPublicOutput, } from "@proto-kit/protocol";
|
|
17
17
|
import { combineMethodName, isRuntimeMethod, toWrappedMethod, } from "../method/runtimeMethod";
|
|
18
|
-
import { MethodIdFactory } from "../factories/MethodIdFactory";
|
|
19
18
|
const errors = {
|
|
20
19
|
methodNotFound: (methodKey) => new Error(`Unable to find method with id ${methodKey}`),
|
|
21
20
|
};
|
|
@@ -110,9 +109,6 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
|
110
109
|
*/
|
|
111
110
|
constructor(definition) {
|
|
112
111
|
super(definition);
|
|
113
|
-
this.stateServiceProviderInstance = new StateServiceProvider(
|
|
114
|
-
// eslint-disable-next-line etc/no-deprecated
|
|
115
|
-
this.definition.state);
|
|
116
112
|
this.definition = definition;
|
|
117
113
|
this.zkProgrammable = new RuntimeZkProgrammable(this);
|
|
118
114
|
}
|
|
@@ -120,16 +116,15 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
|
|
|
120
116
|
// TODO Remove after changing DFs to type-based approach
|
|
121
117
|
create(childContainerProvider) {
|
|
122
118
|
super.create(childContainerProvider);
|
|
123
|
-
this.registerDependencyFactories([MethodIdFactory]);
|
|
124
119
|
}
|
|
125
120
|
get appChain() {
|
|
126
121
|
return this.container.resolve("AreProofsEnabled");
|
|
127
122
|
}
|
|
128
|
-
get stateService() {
|
|
129
|
-
return this.stateServiceProviderInstance.stateService;
|
|
130
|
-
}
|
|
131
123
|
get stateServiceProvider() {
|
|
132
|
-
return this.
|
|
124
|
+
return this.dependencyContainer.resolve("StateServiceProvider");
|
|
125
|
+
}
|
|
126
|
+
get stateService() {
|
|
127
|
+
return this.stateServiceProvider.stateService;
|
|
133
128
|
}
|
|
134
129
|
get methodIdResolver() {
|
|
135
130
|
return this.container.resolve("MethodIdResolver");
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import { ConfigurableModule, Presets } from "@proto-kit/common";
|
|
2
|
-
import { NetworkState, RuntimeTransaction
|
|
3
|
-
import type { Runtime, RuntimeDefinition, RuntimeModulesRecord } from "./Runtime";
|
|
2
|
+
import { NetworkState, RuntimeTransaction } from "@proto-kit/protocol";
|
|
4
3
|
import { RuntimeEnvironment } from "./RuntimeEnvironment";
|
|
5
|
-
/**
|
|
6
|
-
* This type exists to carry over certain runtime properties
|
|
7
|
-
* to runtime modules, until we can inject them through DI.
|
|
8
|
-
*/
|
|
9
|
-
export interface PartialRuntime extends Pick<Runtime<RuntimeModulesRecord>, "zkProgrammable"> {
|
|
10
|
-
definition: Pick<RuntimeDefinition<RuntimeModulesRecord>, "state">;
|
|
11
|
-
get stateService(): StateService;
|
|
12
|
-
}
|
|
13
4
|
/**
|
|
14
5
|
* Base class for runtime modules providing the necessary utilities.
|
|
15
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeModule.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,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,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EACL,YAAY,EACZ,kBAAkB,EAInB,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAM1D;;GAEG;AACH,qBACa,aAAa,CAAC,MAAM,CAAE,SAAQ,kBAAkB,CAAC,MAAM,CAAC;IACnE,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;;IAYpC,OAAO,CAAC,SAAS;IAWjB,IAAW,WAAW,IAAI,kBAAkB,CAE3C;IAED,IAAW,OAAO,IAAI,YAAY,CAEjC;CACF"}
|
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.334+dbab046",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"o1js": "0.13.1",
|
|
32
32
|
"tsyringe": "^4.7.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "dbab046225087a3fa87542300460bd47e9432dbc"
|
|
35
35
|
}
|
package/src/index.ts
CHANGED
|
@@ -19,9 +19,20 @@ export class MethodParameterDecoder {
|
|
|
19
19
|
methodName
|
|
20
20
|
);
|
|
21
21
|
|
|
22
|
+
if (paramtypes === undefined) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Method with name ${methodName} doesn't exist on this module`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
22
28
|
return new MethodParameterDecoder(paramtypes);
|
|
23
29
|
}
|
|
24
30
|
|
|
31
|
+
public static fieldSize(type: ProvableExtended<unknown>): number | undefined {
|
|
32
|
+
// as any, since we shouldn't be using this workaround in the first place
|
|
33
|
+
return (type as any).prototype._fields?.length ?? type.sizeInFields?.();
|
|
34
|
+
}
|
|
35
|
+
|
|
25
36
|
private constructor(private readonly types: ProvableExtended<unknown>[]) {}
|
|
26
37
|
|
|
27
38
|
public fromJSON(argsJSON: string[]): FlexibleProvable<unknown>[] {
|
|
@@ -42,4 +53,10 @@ export class MethodParameterDecoder {
|
|
|
42
53
|
return value;
|
|
43
54
|
});
|
|
44
55
|
}
|
|
56
|
+
|
|
57
|
+
public get fieldSize(): number {
|
|
58
|
+
return this.types
|
|
59
|
+
.map((type) => MethodParameterDecoder.fieldSize(type) ?? 0)
|
|
60
|
+
.reduce((a, b) => a + b, 0);
|
|
61
|
+
}
|
|
45
62
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
1
2
|
import {
|
|
2
3
|
Field,
|
|
3
4
|
FlexibleProvable,
|
|
@@ -18,6 +19,11 @@ import {
|
|
|
18
19
|
toProver,
|
|
19
20
|
ZkProgrammable,
|
|
20
21
|
ToFieldable,
|
|
22
|
+
ToFieldableStatic,
|
|
23
|
+
ProofTypes,
|
|
24
|
+
ArgumentTypes,
|
|
25
|
+
TypedClass,
|
|
26
|
+
O1JSPrimitive,
|
|
21
27
|
} from "@proto-kit/common";
|
|
22
28
|
|
|
23
29
|
import type { RuntimeModule } from "../runtime/RuntimeModule.js";
|
|
@@ -59,13 +65,13 @@ export function toStateTransitionsHash(
|
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
// eslint-disable-next-line etc/prefer-interface
|
|
62
|
-
export type WrappedMethod = (...args:
|
|
68
|
+
export type WrappedMethod = (...args: ArgumentTypes) => MethodPublicOutput;
|
|
63
69
|
|
|
64
70
|
export function toWrappedMethod(
|
|
65
71
|
this: RuntimeModule<unknown>,
|
|
66
72
|
methodName: string,
|
|
67
|
-
moduleMethod: (...args:
|
|
68
|
-
methodArguments:
|
|
73
|
+
moduleMethod: (...args: ArgumentTypes) => unknown,
|
|
74
|
+
methodArguments: ArgumentTypes
|
|
69
75
|
) {
|
|
70
76
|
const executionContext = container.resolve<RuntimeMethodExecutionContext>(
|
|
71
77
|
RuntimeMethodExecutionContext
|
|
@@ -105,11 +111,9 @@ export function toWrappedMethod(
|
|
|
105
111
|
"Runtimemethod called with wrong methodId on the transaction object"
|
|
106
112
|
);
|
|
107
113
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this,
|
|
111
|
-
methodName
|
|
112
|
-
);
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
115
|
+
const parameterTypes: ProofTypes[] | ToFieldableStatic[] =
|
|
116
|
+
Reflect.getMetadata("design:paramtypes", this, methodName);
|
|
113
117
|
|
|
114
118
|
/**
|
|
115
119
|
* Use the type info obtained previously to convert
|
|
@@ -117,19 +121,26 @@ export function toWrappedMethod(
|
|
|
117
121
|
*/
|
|
118
122
|
const argsFields = args.flatMap((argument, index) => {
|
|
119
123
|
if (argument instanceof Proof) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
124
|
+
// eslint-disable-next-line max-len
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
126
|
+
const argumentType = parameterTypes[index] as ProofTypes;
|
|
127
|
+
|
|
128
|
+
const publicOutputType = argumentType?.publicOutputType;
|
|
129
|
+
|
|
130
|
+
const publicInputType = argumentType?.publicInputType;
|
|
123
131
|
|
|
124
132
|
const inputFields =
|
|
125
133
|
publicInputType?.toFields(argument.publicInput) ?? [];
|
|
134
|
+
|
|
126
135
|
const outputFields =
|
|
127
136
|
publicOutputType?.toFields(argument.publicOutput) ?? [];
|
|
128
137
|
|
|
129
138
|
return [...inputFields, ...outputFields];
|
|
130
|
-
} else {
|
|
131
|
-
return parameterTypes[index].toFields(argument as any);
|
|
132
139
|
}
|
|
140
|
+
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
142
|
+
const argumentType = parameterTypes[index] as ToFieldableStatic;
|
|
143
|
+
return argumentType.toFields(argument);
|
|
133
144
|
});
|
|
134
145
|
|
|
135
146
|
// Assert that the argsHash that has been signed matches the given arguments
|
|
@@ -219,7 +230,7 @@ export function runtimeMethod() {
|
|
|
219
230
|
|
|
220
231
|
descriptor.value = function value(
|
|
221
232
|
this: RuntimeModule<unknown>,
|
|
222
|
-
...args:
|
|
233
|
+
...args: ArgumentTypes
|
|
223
234
|
) {
|
|
224
235
|
const constructorName = this.constructor.name;
|
|
225
236
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { stringToField } from "@proto-kit/protocol";
|
|
2
2
|
import { Poseidon } from "o1js";
|
|
3
|
+
import { injectable } from "tsyringe";
|
|
3
4
|
|
|
4
5
|
import type { Runtime, RuntimeModulesRecord } from "./Runtime";
|
|
5
6
|
|
|
@@ -7,6 +8,7 @@ import type { Runtime, RuntimeModulesRecord } from "./Runtime";
|
|
|
7
8
|
* Please see `getMethodId` to learn more about
|
|
8
9
|
* methodId encoding
|
|
9
10
|
*/
|
|
11
|
+
@injectable()
|
|
10
12
|
export class MethodIdResolver {
|
|
11
13
|
private readonly dictionary: {
|
|
12
14
|
[key: string]: { moduleName: string; methodName: string };
|
|
@@ -33,14 +35,14 @@ export class MethodIdResolver {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
public getMethodNameFromId(methodId: bigint): [string, string] | undefined {
|
|
36
|
-
const
|
|
38
|
+
const methodPath = this.dictionary[methodId.toString()];
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
// TODO Replace by throwing exception?
|
|
40
|
-
if (moduleName === undefined || methodName === undefined) {
|
|
40
|
+
if (methodPath === undefined) {
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
const { moduleName, methodName } = methodPath;
|
|
45
|
+
|
|
44
46
|
this.runtime.assertIsValidModuleName(this.modules, moduleName);
|
|
45
47
|
|
|
46
48
|
return [moduleName, methodName];
|
package/src/runtime/Runtime.ts
CHANGED
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
ZkProgrammable,
|
|
12
12
|
PlainZkProgram,
|
|
13
13
|
WithZkProgrammable,
|
|
14
|
-
AreProofsEnabled,
|
|
14
|
+
AreProofsEnabled,
|
|
15
|
+
ChildContainerProvider,
|
|
15
16
|
} from "@proto-kit/common";
|
|
16
17
|
import {
|
|
17
18
|
MethodPublicOutput,
|
|
@@ -50,10 +51,6 @@ const errors = {
|
|
|
50
51
|
* Definition / required arguments for the Runtime class
|
|
51
52
|
*/
|
|
52
53
|
export interface RuntimeDefinition<Modules extends RuntimeModulesRecord> {
|
|
53
|
-
/**
|
|
54
|
-
* @deprecated
|
|
55
|
-
*/
|
|
56
|
-
state?: StateService;
|
|
57
54
|
modules: Modules;
|
|
58
55
|
config?: ModulesConfig<Modules>;
|
|
59
56
|
}
|
|
@@ -210,11 +207,6 @@ export class Runtime<Modules extends RuntimeModulesRecord>
|
|
|
210
207
|
|
|
211
208
|
public zkProgrammable: ZkProgrammable<undefined, MethodPublicOutput>;
|
|
212
209
|
|
|
213
|
-
private readonly stateServiceProviderInstance = new StateServiceProvider(
|
|
214
|
-
// eslint-disable-next-line etc/no-deprecated
|
|
215
|
-
this.definition.state
|
|
216
|
-
);
|
|
217
|
-
|
|
218
210
|
/**
|
|
219
211
|
* Creates a new Runtime from the provided config
|
|
220
212
|
*
|
|
@@ -230,20 +222,20 @@ export class Runtime<Modules extends RuntimeModulesRecord>
|
|
|
230
222
|
// TODO Remove after changing DFs to type-based approach
|
|
231
223
|
public create(childContainerProvider: ChildContainerProvider) {
|
|
232
224
|
super.create(childContainerProvider);
|
|
233
|
-
|
|
234
|
-
this.registerDependencyFactories([MethodIdFactory]);
|
|
235
225
|
}
|
|
236
226
|
|
|
237
227
|
public get appChain(): AreProofsEnabled | undefined {
|
|
238
228
|
return this.container.resolve<AreProofsEnabled>("AreProofsEnabled");
|
|
239
229
|
}
|
|
240
230
|
|
|
241
|
-
public get
|
|
242
|
-
return this.
|
|
231
|
+
public get stateServiceProvider(): StateServiceProvider {
|
|
232
|
+
return this.dependencyContainer.resolve<StateServiceProvider>(
|
|
233
|
+
"StateServiceProvider"
|
|
234
|
+
);
|
|
243
235
|
}
|
|
244
236
|
|
|
245
|
-
public get
|
|
246
|
-
return this.
|
|
237
|
+
public get stateService(): StateService {
|
|
238
|
+
return this.stateServiceProvider.stateService;
|
|
247
239
|
}
|
|
248
240
|
|
|
249
241
|
public get methodIdResolver(): MethodIdResolver {
|
|
@@ -21,17 +21,6 @@ const errors = {
|
|
|
21
21
|
inputDataNotSet: () => new Error("Input data for runtime execution not set"),
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
* This type exists to carry over certain runtime properties
|
|
26
|
-
* to runtime modules, until we can inject them through DI.
|
|
27
|
-
*/
|
|
28
|
-
export interface PartialRuntime
|
|
29
|
-
extends Pick<Runtime<RuntimeModulesRecord>, "zkProgrammable"> {
|
|
30
|
-
definition: Pick<RuntimeDefinition<RuntimeModulesRecord>, "state">;
|
|
31
|
-
|
|
32
|
-
get stateService(): StateService;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
24
|
/**
|
|
36
25
|
* Base class for runtime modules providing the necessary utilities.
|
|
37
26
|
*/
|