@proto-kit/module 0.1.1-develop.165 → 0.1.1-develop.185

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.
Files changed (37) hide show
  1. package/dist/factories/MethodIdFactory.d.ts +9 -0
  2. package/dist/factories/MethodIdFactory.d.ts.map +1 -0
  3. package/dist/factories/MethodIdFactory.js +36 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -0
  7. package/dist/method/runtimeMethod.d.ts +1 -0
  8. package/dist/method/runtimeMethod.d.ts.map +1 -1
  9. package/dist/method/runtimeMethod.js +10 -0
  10. package/dist/runtime/MethodIdResolver.d.ts +18 -0
  11. package/dist/runtime/MethodIdResolver.d.ts.map +1 -0
  12. package/dist/runtime/MethodIdResolver.js +50 -0
  13. package/dist/runtime/Runtime.d.ts +4 -4
  14. package/dist/runtime/Runtime.d.ts.map +1 -1
  15. package/dist/runtime/Runtime.js +21 -20
  16. package/dist/runtime/RuntimeModule.d.ts +6 -0
  17. package/dist/runtime/RuntimeModule.d.ts.map +1 -1
  18. package/dist/runtime/RuntimeModule.js +14 -2
  19. package/package.json +5 -5
  20. package/src/factories/MethodIdFactory.ts +22 -0
  21. package/src/index.ts +1 -0
  22. package/src/method/runtimeMethod.ts +14 -1
  23. package/src/runtime/MethodIdResolver.ts +71 -0
  24. package/src/runtime/Runtime.ts +28 -29
  25. package/src/runtime/RuntimeModule.ts +18 -0
  26. package/test/Runtime.test.ts +21 -14
  27. package/test/modules/Balances.ts +5 -0
  28. package/test/modules/methodId.test.ts +85 -0
  29. package/dist/chain/Chain.d.ts +0 -109
  30. package/dist/chain/Chain.d.ts.map +0 -1
  31. package/dist/chain/Chain.js +0 -229
  32. package/dist/method/MethodExecutionContext.d.ts +0 -73
  33. package/dist/method/MethodExecutionContext.d.ts.map +0 -1
  34. package/dist/method/MethodExecutionContext.js +0 -112
  35. package/dist/method/decorator.d.ts +0 -45
  36. package/dist/method/decorator.d.ts.map +0 -1
  37. package/dist/method/decorator.js +0 -140
@@ -0,0 +1,9 @@
1
+ import { DependencyFactory } from "@proto-kit/common";
2
+ import { MethodIdResolver } from "../runtime/MethodIdResolver";
3
+ import type { Runtime, RuntimeModulesRecord } from "../runtime/Runtime";
4
+ export declare class MethodIdFactory extends DependencyFactory {
5
+ private readonly runtime;
6
+ constructor(runtime: Runtime<RuntimeModulesRecord>);
7
+ methodIdResolver(): MethodIdResolver;
8
+ }
9
+ //# 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,EAEL,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAExE,qBACa,eAAgB,SAAQ,iBAAiB;IAE/B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAMrE,gBAAgB,IAAI,gBAAgB;CAG5C"}
@@ -0,0 +1,36 @@
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
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { dependency, dependencyFactory, DependencyFactory } from "@proto-kit/common";
14
+ import { inject } from "tsyringe";
15
+ import { MethodIdResolver } from "../runtime/MethodIdResolver";
16
+ let MethodIdFactory = class MethodIdFactory extends DependencyFactory {
17
+ constructor(runtime) {
18
+ super();
19
+ this.runtime = runtime;
20
+ }
21
+ methodIdResolver() {
22
+ return new MethodIdResolver(this.runtime, this.runtime.definition.modules);
23
+ }
24
+ };
25
+ __decorate([
26
+ dependency(),
27
+ __metadata("design:type", Function),
28
+ __metadata("design:paramtypes", []),
29
+ __metadata("design:returntype", MethodIdResolver)
30
+ ], MethodIdFactory.prototype, "methodIdResolver", null);
31
+ MethodIdFactory = __decorate([
32
+ dependencyFactory(),
33
+ __param(0, inject("Runtime")),
34
+ __metadata("design:paramtypes", [Function])
35
+ ], MethodIdFactory);
36
+ export { MethodIdFactory };
package/dist/index.d.ts CHANGED
@@ -10,4 +10,5 @@ export * from "./state/StateMap";
10
10
  export * from "./state/StateServiceProvider";
11
11
  export * from "./state/decorator";
12
12
  export * from "./method/MethodParameterDecoder";
13
+ export * from "./runtime/MethodIdResolver";
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -10,3 +10,4 @@ export * from "./state/StateMap";
10
10
  export * from "./state/StateServiceProvider";
11
11
  export * from "./state/decorator";
12
12
  export * from "./method/MethodParameterDecoder";
13
+ export * from "./runtime/MethodIdResolver";
@@ -5,6 +5,7 @@ export type WrappedMethod = (...args: unknown[]) => MethodPublicOutput;
5
5
  export declare function toWrappedMethod(this: RuntimeModule<unknown>, methodName: string, moduleMethod: (...args: unknown[]) => unknown): WrappedMethod;
6
6
  export declare function combineMethodName(runtimeModuleName: string, methodName: string): string;
7
7
  export declare const runtimeMethodMetadataKey = "yab-method";
8
+ export declare const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
8
9
  /**
9
10
  * Checks the metadata of the provided runtime module and its method,
10
11
  * to see if it has been decorated with @runtimeMethod()
@@ -1 +1 @@
1
- {"version":3,"file":"runtimeMethod.d.ts","sourceRoot":"","sources":["../../src/method/runtimeMethod.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EAGf,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAcjE,wBAAgB,sBAAsB,CAEpC,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,mDAczC;AAGD,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,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ACH,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,UAuFjC"}
@@ -43,6 +43,7 @@ export function combineMethodName(runtimeModuleName, methodName) {
43
43
  return `${runtimeModuleName}.${methodName}`;
44
44
  }
45
45
  export const runtimeMethodMetadataKey = "yab-method";
46
+ export const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
46
47
  /**
47
48
  * Checks the metadata of the provided runtime module and its method,
48
49
  * to see if it has been decorated with @runtimeMethod()
@@ -57,6 +58,15 @@ export function isRuntimeMethod(target, propertyKey) {
57
58
  export function runtimeMethod() {
58
59
  return (target, methodName, descriptor) => {
59
60
  const executionContext = container.resolve(RuntimeMethodExecutionContext);
61
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
62
+ let data = Reflect.getMetadata(runtimeMethodNamesMetadataKey, target);
63
+ if (data !== undefined) {
64
+ data.push(methodName);
65
+ }
66
+ else {
67
+ data = [methodName];
68
+ }
69
+ Reflect.defineMetadata(runtimeMethodNamesMetadataKey, data, target);
60
70
  Reflect.defineMetadata(runtimeMethodMetadataKey, true, target, methodName);
61
71
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
62
72
  const simulatedMethod = descriptor.value;
@@ -0,0 +1,18 @@
1
+ import type { Runtime, RuntimeModulesRecord } from "./Runtime";
2
+ /**
3
+ * How do we encode MethodIds
4
+ * A MethodId is defined as the following in little-endian
5
+ * [0
6
+ * ...hash(stringToField(moduleName))[0..128],
7
+ * ...hash(stringToField(methodName))[0..128]
8
+ * ]
9
+ */
10
+ export declare class MethodIdResolver {
11
+ private readonly runtime;
12
+ private readonly modules;
13
+ private readonly dictionary;
14
+ constructor(runtime: Runtime<RuntimeModulesRecord>, modules: RuntimeModulesRecord);
15
+ getMethodNameFromId(methodId: bigint): [string, string] | undefined;
16
+ getMethodId(moduleName: string, methodName: string): bigint;
17
+ }
18
+ //# sourceMappingURL=MethodIdResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodIdResolver.d.ts","sourceRoot":"","sources":["../../src/runtime/MethodIdResolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAM/D;;;;;;;GAOG;AACH,qBAAa,gBAAgB;IAIzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiC;gBAGzC,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,EACtC,OAAO,EAAE,oBAAoB;IAmBzC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;IAsBnE,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;CAQnE"}
@@ -0,0 +1,50 @@
1
+ import { singleFieldToString, stringToField } from "@proto-kit/protocol";
2
+ const offset = 128n;
3
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
4
+ const modulus = 2n ** (offset - 1n);
5
+ /**
6
+ * How do we encode MethodIds
7
+ * A MethodId is defined as the following in little-endian
8
+ * [0
9
+ * ...hash(stringToField(moduleName))[0..128],
10
+ * ...hash(stringToField(methodName))[0..128]
11
+ * ]
12
+ */
13
+ export class MethodIdResolver {
14
+ constructor(runtime, modules) {
15
+ this.runtime = runtime;
16
+ this.modules = modules;
17
+ this.dictionary = {};
18
+ this.dictionary = runtime.runtimeModuleNames.reduce((dict, moduleName) => {
19
+ this.runtime.assertIsValidModuleName(modules, moduleName);
20
+ dict[(stringToField(moduleName).toBigInt() % modulus).toString()] =
21
+ moduleName;
22
+ runtime.resolve(moduleName).runtimeMethodNames.forEach((methodName) => {
23
+ dict[(stringToField(methodName).toBigInt() % modulus).toString()] =
24
+ methodName;
25
+ });
26
+ return dict;
27
+ }, {});
28
+ }
29
+ getMethodNameFromId(methodId) {
30
+ const moduleNameHash = singleFieldToString(methodId >> offset);
31
+ const methodNameHash = singleFieldToString(methodId % modulus);
32
+ const moduleName = this.dictionary[moduleNameHash];
33
+ // eslint-disable-next-line no-warning-comments
34
+ // TODO Replace by throwing exception?
35
+ if (moduleName === undefined) {
36
+ return undefined;
37
+ }
38
+ this.runtime.assertIsValidModuleName(this.modules, moduleName);
39
+ const methodName = this.dictionary[methodNameHash];
40
+ if (methodName === undefined) {
41
+ return undefined;
42
+ }
43
+ return [moduleName, methodName];
44
+ }
45
+ getMethodId(moduleName, methodName) {
46
+ this.runtime.assertIsValidModuleName(this.modules, moduleName);
47
+ return ((stringToField(moduleName).toBigInt() % modulus << offset) +
48
+ (stringToField(methodName).toBigInt() % modulus));
49
+ }
50
+ }
@@ -42,6 +42,7 @@ export declare class Runtime<Modules extends RuntimeModulesRecord> extends Modul
42
42
  * @param modules - Configuration object for the constructed Runtime
43
43
  */
44
44
  constructor(definition: RuntimeDefinition<Modules>);
45
+ start(): void;
45
46
  get appChain(): AreProofsEnabled | undefined;
46
47
  get stateService(): StateService;
47
48
  get stateServiceProvider(): StateServiceProvider;
@@ -53,14 +54,13 @@ 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;
57
- getMethodNameFromId(methodId: bigint): [string, string];
58
- getMethodId(moduleName: string, methodName: string): bigint;
57
+ getMethodById(methodId: bigint): ((...args: unknown[]) => unknown) | undefined;
59
58
  /**
60
59
  * Add a name and other respective properties required by RuntimeModules,
61
60
  * that come from the current Runtime
62
61
  *
63
- * @param name - Name of the runtime module to decorate
62
+ * @param moduleName - Name of the runtime module to decorate
63
+ * @param containedModule
64
64
  */
65
65
  decorateModule(moduleName: StringKeyOf<Modules>, containedModule: InstanceType<Modules[StringKeyOf<Modules>]>): void;
66
66
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/Runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAc,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGL,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;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,KAAK,EAAE,YAAY,CAAC;IACpB,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;AAC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CAAC,OAAO,CAAC;IAMjC,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;IAIrE,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAE3C;IAEF;;;;OAIG;gBACgB,UAAU,EAAE,iBAAiB,CAAC,OAAO,CAAC;IAUlD,KAAK;IAOZ,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAElD;IAED,IAAW,YAAY,IAAI,YAAY,CAEtC;IAED,IAAW,oBAAoB,IAAI,oBAAoB,CAEtD;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"}
@@ -9,13 +9,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  var Runtime_1;
11
11
  // eslint-disable-next-line max-len
12
- /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment */
12
+ /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,max-lines */
13
13
  import { Experimental } from "snarkyjs";
14
14
  import { injectable } from "tsyringe";
15
15
  import { ModuleContainer, ZkProgrammable, } from "@proto-kit/common";
16
- import { fieldToString, stringToField, MethodPublicOutput, } from "@proto-kit/protocol";
16
+ import { MethodPublicOutput } from "@proto-kit/protocol";
17
17
  import { combineMethodName, isRuntimeMethod, toWrappedMethod, } from "../method/runtimeMethod.js";
18
18
  import { StateServiceProvider } from "../state/StateServiceProvider";
19
+ import { MethodIdFactory } from "../factories/MethodIdFactory";
19
20
  const errors = {
20
21
  methodNotFound: (methodKey) => new Error(`Unable to find method with id ${methodKey}`),
21
22
  };
@@ -111,9 +112,15 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
111
112
  this.stateServiceProviderInstance = new StateServiceProvider(this.definition.state);
112
113
  this.definition = definition;
113
114
  this.zkProgrammable = new RuntimeZkProgrammable(this);
114
- // this.registerValue({
115
- // Runtime: this,
116
- // });
115
+ // this.registerDependencyFactories([MethodIdFactory]);
116
+ }
117
+ // eslint-disable-next-line no-warning-comments
118
+ // TODO Remove after changing DFs to type-based approach
119
+ start() {
120
+ this.registerValue({
121
+ Runtime: this,
122
+ });
123
+ this.registerDependencyFactories([MethodIdFactory]);
117
124
  }
118
125
  get appChain() {
119
126
  return this.container.resolve("AppChain");
@@ -135,7 +142,13 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
135
142
  * Encoding: "stringToField(module.name) << 128 + stringToField(method-name)"
136
143
  */
137
144
  getMethodById(methodId) {
138
- const [moduleName, methodName] = this.getMethodNameFromId(methodId);
145
+ const methodDescriptor = this.container
146
+ .resolve("MethodIdResolver")
147
+ .getMethodNameFromId(methodId);
148
+ if (methodDescriptor === undefined) {
149
+ return undefined;
150
+ }
151
+ const [moduleName, methodName] = methodDescriptor;
139
152
  this.isValidModuleName(this.definition.modules, moduleName);
140
153
  const module = this.resolve(moduleName);
141
154
  // eslint-disable-next-line max-len
@@ -147,24 +160,12 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
147
160
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
148
161
  return method.bind(module);
149
162
  }
150
- getMethodNameFromId(methodId) {
151
- // eslint-disable-next-line @typescript-eslint/no-magic-numbers
152
- const moduleName = fieldToString(methodId >> 128n);
153
- // eslint-disable-next-line @typescript-eslint/no-magic-numbers
154
- const methodName = fieldToString(methodId % 2n ** 128n);
155
- return [moduleName, methodName];
156
- }
157
- getMethodId(moduleName, methodName) {
158
- return (
159
- // eslint-disable-next-line @typescript-eslint/no-magic-numbers
160
- (stringToField(moduleName).toBigInt() << 128n) +
161
- stringToField(methodName).toBigInt());
162
- }
163
163
  /**
164
164
  * Add a name and other respective properties required by RuntimeModules,
165
165
  * that come from the current Runtime
166
166
  *
167
- * @param name - Name of the runtime module to decorate
167
+ * @param moduleName - Name of the runtime module to decorate
168
+ * @param containedModule
168
169
  */
169
170
  decorateModule(moduleName, containedModule) {
170
171
  containedModule.name = moduleName;
@@ -15,6 +15,10 @@ export interface PartialRuntime extends Pick<Runtime<RuntimeModulesRecord>, "zkP
15
15
  */
16
16
  export declare class RuntimeModule<Config> extends ConfigurableModule<Config> {
17
17
  static presets: Presets<unknown>;
18
+ /**
19
+ * Holds all method names that are callable throw transactions
20
+ */
21
+ readonly runtimeMethodNames: string[];
18
22
  /**
19
23
  * This property exists only to typecheck that the RuntimeModule
20
24
  * was extended correctly in e.g. a decorator. We need at least
@@ -22,7 +26,9 @@ export declare class RuntimeModule<Config> extends ConfigurableModule<Config> {
22
26
  */
23
27
  isRuntimeModule: boolean;
24
28
  name?: string;
29
+ test?: number;
25
30
  runtime?: Runtime<RuntimeModulesRecord>;
31
+ constructor();
26
32
  private getInputs;
27
33
  get transaction(): RuntimeTransaction;
28
34
  get network(): NetworkState;
@@ -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,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAMvE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,KAAK,E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Y,CAAC;CAClC;AAED;;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,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;;IAY/C,OAAO,CAAC,SAAS;IAWjB,IAAW,WAAW,IAAI,kBAAkB,CAE3C;IAED,IAAW,OAAO,IAAI,YAAY,CAEjC;CACF"}
@@ -4,9 +4,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
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
+ };
7
10
  import { ConfigurableModule } from "@proto-kit/common";
8
11
  import { container, injectable } from "tsyringe";
9
12
  import { RuntimeMethodExecutionContext, } from "../method/RuntimeMethodExecutionContext";
13
+ import { runtimeMethodNamesMetadataKey } from "../method/runtimeMethod";
10
14
  const errors = {
11
15
  inputDataNotSet: () => new Error("Input data for runtime execution not set"),
12
16
  };
@@ -15,13 +19,20 @@ const errors = {
15
19
  */
16
20
  let RuntimeModule = class RuntimeModule extends ConfigurableModule {
17
21
  constructor() {
18
- super(...arguments);
22
+ super();
23
+ /**
24
+ * Holds all method names that are callable throw transactions
25
+ */
26
+ this.runtimeMethodNames = [];
19
27
  /**
20
28
  * This property exists only to typecheck that the RuntimeModule
21
29
  * was extended correctly in e.g. a decorator. We need at least
22
30
  * one non-optional property in this class to make the typechecking work.
23
31
  */
24
32
  this.isRuntimeModule = true;
33
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
34
+ const methodNames = Reflect.getMetadata(runtimeMethodNamesMetadataKey, this);
35
+ this.runtimeMethodNames = methodNames ?? [];
25
36
  }
26
37
  getInputs() {
27
38
  const { input } = container.resolve(RuntimeMethodExecutionContext);
@@ -39,6 +50,7 @@ let RuntimeModule = class RuntimeModule extends ConfigurableModule {
39
50
  };
40
51
  RuntimeModule.presets = {};
41
52
  RuntimeModule = __decorate([
42
- injectable()
53
+ injectable(),
54
+ __metadata("design:paramtypes", [])
43
55
  ], RuntimeModule);
44
56
  export { RuntimeModule };
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.165+e99182d",
5
+ "version": "0.1.1-develop.185+513fbd8",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "tsc -p tsconfig.json",
@@ -17,8 +17,8 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@proto-kit/common": "0.1.1-develop.165+e99182d",
21
- "@proto-kit/protocol": "0.1.1-develop.165+e99182d",
20
+ "@proto-kit/common": "0.1.1-develop.185+513fbd8",
21
+ "@proto-kit/protocol": "0.1.1-develop.185+513fbd8",
22
22
  "lodash": "^4.17.21",
23
23
  "loglevel": "^1.8.1",
24
24
  "reflect-metadata": "^0.1.13",
@@ -29,8 +29,8 @@
29
29
  "@types/lodash": "^4.14.194"
30
30
  },
31
31
  "peerDependencies": {
32
- "snarkyjs": "0.11.0",
32
+ "snarkyjs": "0.12.0",
33
33
  "tsyringe": "^4.7.0"
34
34
  },
35
- "gitHead": "e99182de6df97193927541c180c2023aceed243a"
35
+ "gitHead": "513fbd83cb6540fba01736d55ab0b4f7c1f71f78"
36
36
  }
@@ -0,0 +1,22 @@
1
+ import {
2
+ dependency, dependencyFactory,
3
+ DependencyFactory
4
+ } from "@proto-kit/common";
5
+ import { inject, injectable } from "tsyringe";
6
+
7
+ import { MethodIdResolver } from "../runtime/MethodIdResolver";
8
+ import type { Runtime, RuntimeModulesRecord } from "../runtime/Runtime";
9
+
10
+ @dependencyFactory()
11
+ export class MethodIdFactory extends DependencyFactory {
12
+ public constructor(
13
+ @inject("Runtime") private readonly runtime: Runtime<RuntimeModulesRecord>
14
+ ) {
15
+ super();
16
+ }
17
+
18
+ @dependency()
19
+ public methodIdResolver(): MethodIdResolver {
20
+ return new MethodIdResolver(this.runtime, this.runtime.definition.modules);
21
+ }
22
+ }
package/src/index.ts CHANGED
@@ -10,3 +10,4 @@ export * from "./state/StateMap";
10
10
  export * from "./state/StateServiceProvider";
11
11
  export * from "./state/decorator";
12
12
  export * from "./method/MethodParameterDecoder";
13
+ export * from "./runtime/MethodIdResolver";
@@ -1,4 +1,4 @@
1
- import { Bool, Field, FlexibleProvable, Struct } from "snarkyjs";
1
+ import { FlexibleProvable } from "snarkyjs";
2
2
  import { container } from "tsyringe";
3
3
  import {
4
4
  StateTransition,
@@ -92,6 +92,7 @@ export function combineMethodName(
92
92
  }
93
93
 
94
94
  export const runtimeMethodMetadataKey = "yab-method";
95
+ export const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
95
96
 
96
97
  /**
97
98
  * Checks the metadata of the provided runtime module and its method,
@@ -120,6 +121,18 @@ export function runtimeMethod() {
120
121
  RuntimeMethodExecutionContext
121
122
  );
122
123
 
124
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
125
+ let data: string[] | undefined = Reflect.getMetadata(
126
+ runtimeMethodNamesMetadataKey,
127
+ target
128
+ );
129
+ if (data !== undefined) {
130
+ data.push(methodName);
131
+ } else {
132
+ data = [methodName];
133
+ }
134
+ Reflect.defineMetadata(runtimeMethodNamesMetadataKey, data, target);
135
+
123
136
  Reflect.defineMetadata(runtimeMethodMetadataKey, true, target, methodName);
124
137
 
125
138
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
@@ -0,0 +1,71 @@
1
+ import { singleFieldToString, stringToField } from "@proto-kit/protocol";
2
+
3
+ import type { Runtime, RuntimeModulesRecord } from "./Runtime";
4
+
5
+ const offset = 128n;
6
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
7
+ const modulus = 2n ** (offset - 1n);
8
+
9
+ /**
10
+ * How do we encode MethodIds
11
+ * A MethodId is defined as the following in little-endian
12
+ * [0
13
+ * ...hash(stringToField(moduleName))[0..128],
14
+ * ...hash(stringToField(methodName))[0..128]
15
+ * ]
16
+ */
17
+ export class MethodIdResolver {
18
+ private readonly dictionary: { [key: string]: string } = {};
19
+
20
+ public constructor(
21
+ private readonly runtime: Runtime<RuntimeModulesRecord>,
22
+ private readonly modules: RuntimeModulesRecord
23
+ ) {
24
+ this.dictionary = runtime.runtimeModuleNames.reduce<Record<string, string>>(
25
+ (dict, moduleName) => {
26
+ this.runtime.assertIsValidModuleName(modules, moduleName);
27
+
28
+ dict[(stringToField(moduleName).toBigInt() % modulus).toString()] =
29
+ moduleName;
30
+
31
+ runtime.resolve(moduleName).runtimeMethodNames.forEach((methodName) => {
32
+ dict[(stringToField(methodName).toBigInt() % modulus).toString()] =
33
+ methodName;
34
+ });
35
+ return dict;
36
+ },
37
+ {}
38
+ );
39
+ }
40
+
41
+ public getMethodNameFromId(methodId: bigint): [string, string] | undefined {
42
+ const moduleNameHash = singleFieldToString(methodId >> offset);
43
+ const methodNameHash = singleFieldToString(methodId % modulus);
44
+
45
+ const moduleName: string | undefined = this.dictionary[moduleNameHash];
46
+
47
+ // eslint-disable-next-line no-warning-comments
48
+ // TODO Replace by throwing exception?
49
+ if (moduleName === undefined) {
50
+ return undefined;
51
+ }
52
+ this.runtime.assertIsValidModuleName(this.modules, moduleName);
53
+
54
+ const methodName: string | undefined = this.dictionary[methodNameHash];
55
+
56
+ if (methodName === undefined) {
57
+ return undefined;
58
+ }
59
+
60
+ return [moduleName, methodName];
61
+ }
62
+
63
+ public getMethodId(moduleName: string, methodName: string): bigint {
64
+ this.runtime.assertIsValidModuleName(this.modules, moduleName);
65
+
66
+ return (
67
+ (stringToField(moduleName).toBigInt() % modulus << offset) +
68
+ (stringToField(methodName).toBigInt() % modulus)
69
+ );
70
+ }
71
+ }
@@ -1,5 +1,5 @@
1
1
  // eslint-disable-next-line max-len
2
- /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,max-lines */
3
3
  import { Experimental } from "snarkyjs";
4
4
  import { DependencyContainer, injectable } from "tsyringe";
5
5
  import {
@@ -13,11 +13,7 @@ import {
13
13
  WithZkProgrammable,
14
14
  AreProofsEnabled,
15
15
  } from "@proto-kit/common";
16
- import {
17
- fieldToString,
18
- stringToField,
19
- MethodPublicOutput,
20
- } from "@proto-kit/protocol";
16
+ import { MethodPublicOutput } from "@proto-kit/protocol";
21
17
 
22
18
  import {
23
19
  combineMethodName,
@@ -27,8 +23,10 @@ import {
27
23
  } from "../method/runtimeMethod.js";
28
24
  import { StateService } from "../state/InMemoryStateService.js";
29
25
  import { StateServiceProvider } from "../state/StateServiceProvider";
26
+ import { MethodIdFactory } from "../factories/MethodIdFactory";
30
27
 
31
28
  import { RuntimeModule } from "./RuntimeModule.js";
29
+ import { MethodIdResolver } from "./MethodIdResolver";
32
30
 
33
31
  /**
34
32
  * Record of modules accepted by the Runtime module container.
@@ -217,9 +215,17 @@ export class Runtime<Modules extends RuntimeModulesRecord>
217
215
  super(definition);
218
216
  this.definition = definition;
219
217
  this.zkProgrammable = new RuntimeZkProgrammable<Modules>(this);
220
- // this.registerValue({
221
- // Runtime: this,
222
- // });
218
+
219
+ // this.registerDependencyFactories([MethodIdFactory]);
220
+ }
221
+
222
+ // eslint-disable-next-line no-warning-comments
223
+ // TODO Remove after changing DFs to type-based approach
224
+ public start() {
225
+ this.registerValue({
226
+ Runtime: this,
227
+ });
228
+ this.registerDependencyFactories([MethodIdFactory]);
223
229
  }
224
230
 
225
231
  public get appChain(): AreProofsEnabled | undefined {
@@ -245,8 +251,17 @@ export class Runtime<Modules extends RuntimeModulesRecord>
245
251
  * @param methodId The encoded name of the method to call.
246
252
  * Encoding: "stringToField(module.name) << 128 + stringToField(method-name)"
247
253
  */
248
- public getMethodById(methodId: bigint): (...args: unknown[]) => unknown {
249
- const [moduleName, methodName] = this.getMethodNameFromId(methodId);
254
+ public getMethodById(
255
+ methodId: bigint
256
+ ): ((...args: unknown[]) => unknown) | undefined {
257
+ const methodDescriptor = this.container
258
+ .resolve<MethodIdResolver>("MethodIdResolver")
259
+ .getMethodNameFromId(methodId);
260
+
261
+ if (methodDescriptor === undefined) {
262
+ return undefined;
263
+ }
264
+ const [moduleName, methodName] = methodDescriptor;
250
265
 
251
266
  this.isValidModuleName(this.definition.modules, moduleName);
252
267
  const module = this.resolve(moduleName);
@@ -262,28 +277,12 @@ export class Runtime<Modules extends RuntimeModulesRecord>
262
277
  return (method as (...args: unknown[]) => unknown).bind(module);
263
278
  }
264
279
 
265
- public getMethodNameFromId(methodId: bigint): [string, string] {
266
- // eslint-disable-next-line @typescript-eslint/no-magic-numbers
267
- const moduleName = fieldToString(methodId >> 128n);
268
- // eslint-disable-next-line @typescript-eslint/no-magic-numbers
269
- const methodName = fieldToString(methodId % 2n ** 128n);
270
-
271
- return [moduleName, methodName];
272
- }
273
-
274
- public getMethodId(moduleName: string, methodName: string): bigint {
275
- return (
276
- // eslint-disable-next-line @typescript-eslint/no-magic-numbers
277
- (stringToField(moduleName).toBigInt() << 128n) +
278
- stringToField(methodName).toBigInt()
279
- );
280
- }
281
-
282
280
  /**
283
281
  * Add a name and other respective properties required by RuntimeModules,
284
282
  * that come from the current Runtime
285
283
  *
286
- * @param name - Name of the runtime module to decorate
284
+ * @param moduleName - Name of the runtime module to decorate
285
+ * @param containedModule
287
286
  */
288
287
  public decorateModule(
289
288
  moduleName: StringKeyOf<Modules>,