@proto-kit/module 0.1.1-develop.164 → 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
@@ -7,6 +7,7 @@ import {
7
7
  RuntimeMethodExecutionData,
8
8
  } from "../method/RuntimeMethodExecutionContext";
9
9
  import { StateService } from "../state/InMemoryStateService";
10
+ import { runtimeMethodNamesMetadataKey } from "../method/runtimeMethod";
10
11
 
11
12
  import type {
12
13
  Runtime,
@@ -36,6 +37,11 @@ export interface PartialRuntime
36
37
  export class RuntimeModule<Config> extends ConfigurableModule<Config> {
37
38
  public static presets: Presets<unknown> = {};
38
39
 
40
+ /**
41
+ * Holds all method names that are callable throw transactions
42
+ */
43
+ public readonly runtimeMethodNames: string[] = [];
44
+
39
45
  /**
40
46
  * This property exists only to typecheck that the RuntimeModule
41
47
  * was extended correctly in e.g. a decorator. We need at least
@@ -45,8 +51,20 @@ export class RuntimeModule<Config> extends ConfigurableModule<Config> {
45
51
 
46
52
  public name?: string;
47
53
 
54
+ public test?: number;
55
+
48
56
  public runtime?: Runtime<RuntimeModulesRecord>;
49
57
 
58
+ public constructor() {
59
+ super();
60
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
61
+ const methodNames: string[] | undefined = Reflect.getMetadata(
62
+ runtimeMethodNamesMetadataKey,
63
+ this
64
+ );
65
+ this.runtimeMethodNames = methodNames ?? [];
66
+ }
67
+
50
68
  private getInputs(): RuntimeMethodExecutionData {
51
69
  const { input } = container.resolve<RuntimeMethodExecutionContext>(
52
70
  RuntimeMethodExecutionContext
@@ -1,23 +1,29 @@
1
+ import { Bool } from "snarkyjs";
2
+
1
3
  import { InMemoryStateService, Runtime } from "../src";
4
+
2
5
  import { Balances } from "./modules/Balances";
3
- import { Bool } from "snarkyjs";
4
6
 
5
7
  describe("runtime", () => {
6
-
7
8
  it("should encode methodnames correctly", () => {
9
+ expect.assertions(2);
10
+
8
11
  const runtime = Runtime.from({
9
12
  state: new InMemoryStateService(),
13
+
10
14
  modules: {
11
- Balances: Balances
15
+ Balances,
12
16
  },
17
+
13
18
  config: {
14
19
  Balances: {
15
- test: Bool(true)
16
- }
17
- }
18
- })
20
+ test: Bool(true),
21
+ },
22
+ },
23
+ });
24
+
25
+ const balances = runtime.resolve("Balances");
19
26
 
20
- const balances = runtime.resolve("Balances")
21
27
  expect(balances).toBeDefined();
22
28
 
23
29
  console.log(Object.keys(balances));
@@ -26,12 +32,13 @@ describe("runtime", () => {
26
32
  const moduleName = "Balances";
27
33
  const methodName = "getTotalSupply";
28
34
 
29
- const methodId = runtime.getMethodId(moduleName, methodName);
30
- const method = runtime.getMethodById(methodId)
35
+ const methodId = runtime.methodIdResolver.getMethodId(
36
+ moduleName,
37
+ methodName
38
+ );
39
+ const method = runtime.getMethodById(methodId);
31
40
 
32
41
  // eslint-disable-next-line jest/no-restricted-matchers
33
42
  expect(method).toBeDefined();
34
-
35
- })
36
-
37
- })
43
+ });
44
+ });
@@ -48,4 +48,9 @@ export class Balances extends RuntimeModule<BalancesConfig> {
48
48
  public getBalance(address: PublicKey): Option<UInt64> {
49
49
  return this.balances.get(address);
50
50
  }
51
+
52
+ @runtimeMethod()
53
+ public setBalanceIf() {
54
+
55
+ }
51
56
  }
@@ -0,0 +1,85 @@
1
+ import "reflect-metadata";
2
+ import { Bool, Field } from "snarkyjs";
3
+ import { beforeAll, beforeEach } from "@jest/globals";
4
+
5
+ import { Runtime } from "../../src/runtime/Runtime";
6
+ import { MethodIdResolver } from "../../src/runtime/MethodIdResolver";
7
+ import {
8
+ assert,
9
+ InMemoryStateService,
10
+ runtimeMethod,
11
+ RuntimeModule,
12
+ runtimeModule,
13
+ } from "../../src";
14
+ import { container } from "tsyringe";
15
+ import { Balances } from "./Balances";
16
+
17
+ interface AdminConfig {}
18
+
19
+ @runtimeModule()
20
+ class Admin extends RuntimeModule<AdminConfig> {
21
+ @runtimeMethod()
22
+ public isAdminWithAVeryVeryVeryVeryLongName() {
23
+ assert(Field(1).equals(Field(1)));
24
+ }
25
+ }
26
+
27
+ describe("methodId", () => {
28
+ let runtime: Runtime<{ Admin: typeof Admin; Balance: typeof Balances }>;
29
+ let resolver: MethodIdResolver;
30
+
31
+ beforeAll(() => {
32
+ container.clearInstances();
33
+
34
+ runtime = Runtime.from({
35
+ modules: {
36
+ Admin,
37
+ Balance: Balances,
38
+ },
39
+
40
+ config: {
41
+ Admin: {},
42
+ Balance: {
43
+ test: Bool(true),
44
+ },
45
+ },
46
+
47
+ state: new InMemoryStateService(),
48
+ });
49
+ runtime.start();
50
+
51
+ resolver =
52
+ runtime.dependencyContainer.resolve<MethodIdResolver>("MethodIdResolver");
53
+ });
54
+
55
+ it.each([
56
+ ["Admin", "isAdminWithAVeryVeryVeryVeryLongName"],
57
+ ["Balance", "getTotalSupply"],
58
+ ["Balance", "getBalance"],
59
+ ["Balance", "setBalanceIf"],
60
+ ])(
61
+ "should pass and encode correctly",
62
+ (givenModuleName, givenMethodName) => {
63
+ expect.assertions(2);
64
+
65
+ const methodId = resolver.getMethodId(givenModuleName, givenMethodName);
66
+
67
+ const [moduleName, methodName] = resolver.getMethodNameFromId(
68
+ methodId
69
+ ) ?? [undefined, undefined];
70
+
71
+ expect(moduleName).toBe(givenModuleName);
72
+ expect(methodName).toBe(givenMethodName);
73
+ }
74
+ );
75
+
76
+ it("should fail for invalid module name", () => {
77
+ expect.assertions(1);
78
+
79
+ expect(() => {
80
+ resolver.getMethodId("Admin2", "isAdminWithAVeryVeryVeryVeryLongName");
81
+ }).toThrow(
82
+ "Only known module names are allowed, using unknown module name: Admin2"
83
+ );
84
+ });
85
+ });
@@ -1,109 +0,0 @@
1
- import { Experimental, Proof } from "snarkyjs";
2
- import { MethodPublicInput, Subclass } from "@yab/protocol";
3
- import { type AnyConstructor } from "../module/decorator.js";
4
- import type { StateService } from "../state/InMemoryStateService.js";
5
- export interface RuntimeModules {
6
- [name: string]: AnyConstructor;
7
- }
8
- export interface ChainConfig<ChainRuntimeModules extends RuntimeModules> {
9
- state: StateService;
10
- runtimeModules: ChainRuntimeModules;
11
- }
12
- /**
13
- * Wrapper for an application specific chain, which helps orchestrate
14
- * runtime modules into an interoperable runtime.
15
- */
16
- export declare class Chain<ChainRuntimeModules extends RuntimeModules> {
17
- config: ChainConfig<ChainRuntimeModules>;
18
- /**
19
- * Alternative constructor for `Chain`.
20
- *
21
- * @param config - Configuration for the returned Chain
22
- * @returns Chain with the provided config
23
- */
24
- static from<ChainRuntimeModules extends RuntimeModules>(config: ChainConfig<ChainRuntimeModules>): Chain<ChainRuntimeModules>;
25
- private readonly runtimeContainer;
26
- areProofsEnabled: boolean;
27
- program?: ReturnType<typeof Experimental.ZkProgram>;
28
- /**
29
- * Creates a new Chain from the provided config
30
- *
31
- * @param config - Configuration object for the constructed Chain
32
- */
33
- constructor(config: ChainConfig<ChainRuntimeModules>);
34
- /**
35
- * Add a name and other respective properties required by RuntimeModules,
36
- * that come from the current Chain
37
- *
38
- * @param name - Name of the runtime module to decorate
39
- */
40
- private decorateRuntimeModule;
41
- /**
42
- * @returns A list of
43
- */
44
- get runtimeModuleNames(): string[];
45
- /**
46
- * Returns a runtime module registred under the given key.
47
- *
48
- * @param name - Name of the runtime module to get
49
- * @returns A runtime module stored under the given key
50
- */
51
- getRuntimeModule<Key extends keyof ChainRuntimeModules>(name: Key): InstanceType<ChainRuntimeModules[Key]>;
52
- /**
53
- * Registers a runtime module under the given name.
54
- *
55
- * @param name - Name of the runtime module to identify it by
56
- * @param runtimeModule - Runtime module to register
57
- */
58
- registerRuntimeModule(name: string, runtimeModule: AnyConstructor): void;
59
- /**
60
- * Sets if proofs are enabled or not
61
- * @param areProofsEnabled
62
- */
63
- setProofsEnabled(areProofsEnabled: boolean): void;
64
- /**
65
- * Precompiles the current runtime modules into a ZkProgram.
66
- *
67
- * @returns - Analysis of the precompiled ZkProgram
68
- */
69
- precompile(): {
70
- analyze: (this: Chain<RuntimeModules>) => {
71
- methodName: string;
72
- analysis: {
73
- rows: number;
74
- gates: import("snarkyjs/dist/node/snarky.js").Gate[];
75
- inputs: [] | [import("snarkyjs/dist/node/snarky.js").Provable<any> | ((new (...args: any) => Proof<unknown>) & {
76
- prototype: Proof<any>;
77
- publicInputType: import("snarkyjs/dist/node/lib/circuit_value.js").FlexibleProvablePure<any>;
78
- tag: () => {
79
- name: string;
80
- };
81
- fromJSON: typeof Proof.fromJSON;
82
- } & {
83
- prototype: Proof<unknown>;
84
- }), ...(import("snarkyjs/dist/node/snarky.js").Provable<any> | ((new (...args: any) => Proof<unknown>) & {
85
- prototype: Proof<any>;
86
- publicInputType: import("snarkyjs/dist/node/lib/circuit_value.js").FlexibleProvablePure<any>;
87
- tag: () => {
88
- name: string;
89
- };
90
- fromJSON: typeof Proof.fromJSON;
91
- } & {
92
- prototype: Proof<unknown>;
93
- }))[]];
94
- };
95
- }[];
96
- toPretty: () => void;
97
- };
98
- getProofClass(): Subclass<typeof Proof<MethodPublicInput>>;
99
- /**
100
- * Compiles the current runtime modules configuration
101
- * into a ZkProgram and then into a verification key.
102
- *
103
- * @returns The resulting artifact of ZkProgram compilation (verification key)
104
- */
105
- compile(): Promise<{
106
- verificationKey: string;
107
- }>;
108
- }
109
- //# sourceMappingURL=Chain.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Chain.d.ts","sourceRoot":"","sources":["../../src/chain/Chain.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAO5D,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,wBAAwB,CAAC;AAE9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,MAAM,WAAW,cAAc;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;CAChC;AAED,MAAM,WAAW,WAAW,CAAC,mBAAmB,SAAS,cAAc;IACrE,KAAK,EAAE,YAAY,CAAC;IACpB,cAAc,EAAE,mBAAmB,CAAC;CACrC;AAyCD;;;GAGG;AACH,qBAAa,KAAK,CAAC,mBAAmB,SAAS,cAAc;IA2BjC,MAAM,EAAE,WAAW,CAAC,mBAAmB,CAAC;IA1BlE;;;;;OAKG;WACW,IAAI,CAAC,mBAAmB,SAAS,cAAc,EAC3D,MAAM,EAAE,WAAW,CAAC,mBAAmB,CAAC;IAM1C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAsB;IAGhD,gBAAgB,UAAS;IAGzB,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;IAE3D;;;;OAIG;gBACuB,MAAM,EAAE,WAAW,CAAC,mBAAmB,CAAC;IASlE;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IAO7B;;OAEG;IACH,IAAW,kBAAkB,aAE5B;IAED;;;;;OAKG;IACI,gBAAgB,CAAC,GAAG,SAAS,MAAM,mBAAmB,EAAE,IAAI,EAAE,GAAG;IAexE;;;;;OAKG;IACI,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc;IAkCxE;;;OAGG;IACI,gBAAgB,CAAC,gBAAgB,EAAE,OAAO;IAIjD;;;;OAIG;IACI,UAAU;wBA8EQ,MAAM,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4CvC,aAAa,IAAI,QAAQ,CAAC,OAAO,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAcjE;;;;;OAKG;IACU,OAAO;;;CAcrB"}
@@ -1,229 +0,0 @@
1
- /* eslint-disable max-lines */
2
- import { container, Lifecycle } from "tsyringe";
3
- import { Experimental, Proof } from "snarkyjs";
4
- import { MethodPublicInput } from "@yab/protocol";
5
- import { combineMethodName, isMethod, toWrappedMethod, } from "../method/decorator.js";
6
- import { isRuntimeModule } from "../module/decorator.js";
7
- const errors = {
8
- onlyStringNames: () => new TypeError("Only string names are supported"),
9
- notRegistredRuntimeModule: (name) => new Error(`Unable to retrieve module: ${name}, it is not registred as a runtime module for this chain`),
10
- missingDecorator: (name, runtimeModuleName) => new Error(`Unable to register module: ${name} / ${runtimeModuleName},
11
- did you forget to add @runtimeModule()?`),
12
- nonModuleDependecy: (runtimeModuleName) => new Error(`
13
- Unable to register module: ${runtimeModuleName}, attempting to inject a non-module dependency`),
14
- unknownDependency: (runtimeModuleName, name) => new Error(`Unable to register module: ${runtimeModuleName},
15
- attempting to inject a dependency that is not registred
16
- as a runtime module for this chain: ${name}`),
17
- unableToAnalyze: (name) => new Error(`Unable to analyze program for chain: ${name}`),
18
- precompileFirst: () => new Error("You have to call precompile() before being able to create the proof class"),
19
- zkProgramMissing: () => new Error("Unable to compile chain, pre-compilation did not produce a zkProgram"),
20
- };
21
- /**
22
- * Wrapper for an application specific chain, which helps orchestrate
23
- * runtime modules into an interoperable runtime.
24
- */
25
- export class Chain {
26
- /**
27
- * Alternative constructor for `Chain`.
28
- *
29
- * @param config - Configuration for the returned Chain
30
- * @returns Chain with the provided config
31
- */
32
- static from(config) {
33
- return new Chain(config);
34
- }
35
- /**
36
- * Creates a new Chain from the provided config
37
- *
38
- * @param config - Configuration object for the constructed Chain
39
- */
40
- constructor(config) {
41
- this.config = config;
42
- // determines whether any proving should be done when running methods
43
- this.areProofsEnabled = false;
44
- this.runtimeContainer = container.createChildContainer();
45
- Object.entries(this.config.runtimeModules).forEach(([name, runtimeModule]) => {
46
- this.registerRuntimeModule(name, runtimeModule);
47
- });
48
- }
49
- /**
50
- * Add a name and other respective properties required by RuntimeModules,
51
- * that come from the current Chain
52
- *
53
- * @param name - Name of the runtime module to decorate
54
- */
55
- decorateRuntimeModule(name) {
56
- const runtimeModuleInstance = this.runtimeContainer.resolve(name);
57
- runtimeModuleInstance.name = name;
58
- runtimeModuleInstance.chain = this;
59
- }
60
- /**
61
- * @returns A list of
62
- */
63
- get runtimeModuleNames() {
64
- return Object.keys(this.config.runtimeModules);
65
- }
66
- /**
67
- * Returns a runtime module registred under the given key.
68
- *
69
- * @param name - Name of the runtime module to get
70
- * @returns A runtime module stored under the given key
71
- */
72
- getRuntimeModule(name) {
73
- if (typeof name !== "string") {
74
- throw errors.onlyStringNames();
75
- }
76
- if (!this.runtimeModuleNames.includes(name)) {
77
- throw errors.notRegistredRuntimeModule(name);
78
- }
79
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
80
- return this.runtimeContainer.resolve(name);
81
- }
82
- /**
83
- * Registers a runtime module under the given name.
84
- *
85
- * @param name - Name of the runtime module to identify it by
86
- * @param runtimeModule - Runtime module to register
87
- */
88
- registerRuntimeModule(name, runtimeModule) {
89
- if (!isRuntimeModule(runtimeModule)) {
90
- throw errors.missingDecorator(name, runtimeModule.name);
91
- }
92
- this.runtimeContainer.register(name, {
93
- useClass: runtimeModule,
94
- }, {
95
- lifecycle: Lifecycle.ContainerScoped,
96
- });
97
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
98
- const dependencies = Reflect.getMetadata("design:paramtypes", runtimeModule);
99
- dependencies?.forEach((dependency) => {
100
- const name = typeof dependency === "string" ? dependency : dependency.name;
101
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
102
- if (!name) {
103
- throw errors.nonModuleDependecy(runtimeModule.name);
104
- }
105
- if (!this.runtimeModuleNames.includes(name)) {
106
- throw errors.unknownDependency(runtimeModule.name, name);
107
- }
108
- });
109
- this.decorateRuntimeModule(name);
110
- }
111
- /**
112
- * Sets if proofs are enabled or not
113
- * @param areProofsEnabled
114
- */
115
- setProofsEnabled(areProofsEnabled) {
116
- this.areProofsEnabled = areProofsEnabled;
117
- }
118
- /**
119
- * Precompiles the current runtime modules into a ZkProgram.
120
- *
121
- * @returns - Analysis of the precompiled ZkProgram
122
- */
123
- precompile() {
124
- const methods = this.runtimeModuleNames.reduce((allMethods, runtimeModuleName) => {
125
- // eslint-disable-next-line max-len
126
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
127
- const runtimeModule = this.getRuntimeModule(runtimeModuleName);
128
- // eslint-disable-next-line max-len
129
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
130
- const modulePrototype = Object.getPrototypeOf(runtimeModule);
131
- const modulePrototypeMethods = Object.getOwnPropertyNames(modulePrototype);
132
- const moduleMethods = modulePrototypeMethods.reduce((allModuleMethods, methodName) => {
133
- if (isMethod(runtimeModule, methodName)) {
134
- const combinedMethodName = combineMethodName(runtimeModuleName, methodName);
135
- const method = modulePrototype[methodName];
136
- const wrappedMethod = Reflect.apply(toWrappedMethod, runtimeModule, [methodName, method]);
137
- // eslint-disable-next-line no-warning-comments
138
- // TODO: find out how to import the Tuple type
139
- // eslint-disable-next-line max-len
140
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
141
- const privateInputs = Reflect.getMetadata("design:paramtypes", runtimeModule, methodName);
142
- return {
143
- ...allModuleMethods,
144
- [combinedMethodName]: {
145
- // eslint-disable-next-line max-len
146
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
147
- privateInputs,
148
- method: wrappedMethod,
149
- },
150
- };
151
- }
152
- return allModuleMethods;
153
- }, {});
154
- return {
155
- ...allMethods,
156
- ...moduleMethods,
157
- };
158
- }, {});
159
- // eslint-disable-next-line @typescript-eslint/require-array-sort-compare
160
- const sortedMethods = Object.fromEntries(Object.entries(methods).sort());
161
- this.program = Experimental.ZkProgram({
162
- publicInput: MethodPublicInput,
163
- methods: sortedMethods,
164
- });
165
- function analyze() {
166
- if (!this.program) {
167
- throw errors.unableToAnalyze(this.constructor.name);
168
- }
169
- const zkProgramAnalysis = this.program.analyzeMethods();
170
- return Object.keys(sortedMethods).map((methodName, index) => {
171
- const { rows, gates } = zkProgramAnalysis[index];
172
- const { privateInputs: inputs } = sortedMethods[methodName];
173
- return {
174
- methodName,
175
- analysis: {
176
- rows,
177
- gates,
178
- inputs,
179
- },
180
- };
181
- });
182
- }
183
- return {
184
- analyze,
185
- toPretty: () => {
186
- Reflect.apply(analyze, this, []).forEach(({ methodName, analysis: methodAnalysis }) => {
187
- const inputs = methodAnalysis.inputs.map(
188
- // eslint-disable-next-line max-len
189
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
190
- (input) => input.name);
191
- console.log(`
192
- Method: ${methodName}
193
- Rows: ${methodAnalysis.rows},
194
- Gates: ${methodAnalysis.gates.length}
195
- Inputs: [${inputs.join(", ")}]
196
- `);
197
- });
198
- },
199
- };
200
- }
201
- getProofClass() {
202
- if (this.program === undefined) {
203
- throw errors.precompileFirst();
204
- }
205
- const { program } = this;
206
- return ((programClosure) => { var _a; return _a = class AppChainProof extends Proof {
207
- },
208
- _a.publicInputType = MethodPublicInput,
209
- _a.tag = () => programClosure,
210
- _a; })(program);
211
- }
212
- /**
213
- * Compiles the current runtime modules configuration
214
- * into a ZkProgram and then into a verification key.
215
- *
216
- * @returns The resulting artifact of ZkProgram compilation (verification key)
217
- */
218
- async compile() {
219
- this.precompile();
220
- if (!this.program) {
221
- throw errors.zkProgramMissing();
222
- }
223
- const { areProofsEnabled, program } = this;
224
- this.setProofsEnabled(false);
225
- const artifact = await program.compile();
226
- this.setProofsEnabled(areProofsEnabled);
227
- return artifact;
228
- }
229
- }
@@ -1,73 +0,0 @@
1
- import { Bool, type Proof } from "snarkyjs";
2
- import type { StateTransition, MethodPublicInput } from "@yab/protocol";
3
- export declare class MethodExecutionResult<ResultValue> {
4
- stateTransitions: StateTransition<any>[];
5
- status: Bool;
6
- statusMessage?: string;
7
- value?: ResultValue;
8
- publicInput?: MethodPublicInput;
9
- prove?: () => Promise<Proof<MethodPublicInput>>;
10
- }
11
- /**
12
- * Execution context used to wrap runtime module methods,
13
- * allowing them to post relevant information (such as execution status)
14
- * into the context without any unnecessary 'prop drilling'.
15
- */
16
- export declare class MethodExecutionContext<ResultValue> {
17
- result: MethodExecutionResult<ResultValue>;
18
- methods: string[];
19
- constructor(result?: MethodExecutionResult<ResultValue>);
20
- /**
21
- * Adds an in-method generated state transition to the current context
22
- * @param stateTransition - State transition to add to the context
23
- */
24
- addStateTransition<Value>(stateTransition: StateTransition<Value>): void;
25
- /**
26
- * @param message - Status message to acompany the current status
27
- */
28
- setStatusMessage(message?: string): void;
29
- /**
30
- * @param status - Execution status of the current method
31
- */
32
- setStatus(status: Bool): void;
33
- /**
34
- * @param value = Return value of the executed method
35
- */
36
- setValue(value: ResultValue): void;
37
- /**
38
- * Adds a method prover to the current execution context,
39
- * which can be collected and ran asynchronously at a later point in time.
40
- *
41
- * @param prove - Prover function to be ran later,
42
- * when the method execution needs to be proven
43
- */
44
- setProve(prove: () => Promise<Proof<MethodPublicInput>>): void;
45
- setPublicInput(publicInput: MethodPublicInput): void;
46
- /**
47
- * Adds a method to the method execution stack, reseting the execution context
48
- * in a case a new top-level (non nested) method call is made.
49
- *
50
- * @param methodName - Name of the method being captured in the context
51
- */
52
- beforeMethod(methodName: string): void;
53
- /**
54
- * Removes the latest method from the execution context stack,
55
- * keeping track of the amount of 'unfinished' methods. Allowing
56
- * for the context to distinguish between top-level and nested method calls.
57
- */
58
- afterMethod(): void;
59
- get isTopLevel(): boolean;
60
- get isFinished(): boolean;
61
- /**
62
- * @returns - Current execution context state
63
- */
64
- current(): {
65
- isFinished: boolean;
66
- result: MethodExecutionResult<ResultValue>;
67
- };
68
- /**
69
- * Manually clears/resets the execution context
70
- */
71
- clear(): void;
72
- }
73
- //# sourceMappingURL=MethodExecutionContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MethodExecutionContext.d.ts","sourceRoot":"","sources":["../../src/method/MethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAExE,qBAAa,qBAAqB,CAAC,WAAW;IAErC,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,CAAM;IAE9C,MAAM,EAAE,IAAI,CAAc;IAE1B,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,KAAK,CAAC,EAAE,WAAW,CAAC;IAEpB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAEhC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;CACxD;AAED;;;;GAIG;AACH,qBACa,sBAAsB,CAAC,WAAW;IAIpC,MAAM,EAAE,qBAAqB,CAAC,WAAW,CAAC;IAH5C,OAAO,EAAE,MAAM,EAAE,CAAM;gBAGrB,MAAM,GAAE,qBAAqB,CAAC,WAAW,CAA+B;IAGjF;;;OAGG;IACI,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,eAAe,CAAC,KAAK,CAAC;IAIxE;;OAEG;IACI,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM;IAIxC;;OAEG;IACI,SAAS,CAAC,MAAM,EAAE,IAAI;IAI7B;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,WAAW;IAIlC;;;;;;OAMG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAIvD,cAAc,CAAC,WAAW,EAAE,iBAAiB;IAEpD;;;;;OAKG;IACI,YAAY,CAAC,UAAU,EAAE,MAAM;IAOtC;;;;OAIG;IACI,WAAW;IAIlB,IAAW,UAAU,YAEpB;IAED,IAAW,UAAU,YAEpB;IAED;;OAEG;IACI,OAAO,IAAI;QAChB,UAAU,EAAE,OAAO,CAAC;QACpB,MAAM,EAAE,qBAAqB,CAAC,WAAW,CAAC,CAAC;KAC5C;IAOD;;OAEG;IACI,KAAK;CAGb"}