@proto-kit/module 0.1.1-develop.0

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 (72) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +114 -0
  3. package/dist/factories/MethodIdFactory.d.ts +10 -0
  4. package/dist/factories/MethodIdFactory.d.ts.map +1 -0
  5. package/dist/factories/MethodIdFactory.js +11 -0
  6. package/dist/factories/MethodIdFactory.js.map +1 -0
  7. package/dist/index.d.ts +11 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +11 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/method/MethodParameterEncoder.d.ts +26 -0
  12. package/dist/method/MethodParameterEncoder.d.ts.map +1 -0
  13. package/dist/method/MethodParameterEncoder.js +169 -0
  14. package/dist/method/MethodParameterEncoder.js.map +1 -0
  15. package/dist/method/runtimeMethod.d.ts +33 -0
  16. package/dist/method/runtimeMethod.d.ts.map +1 -0
  17. package/dist/method/runtimeMethod.js +169 -0
  18. package/dist/method/runtimeMethod.js.map +1 -0
  19. package/dist/module/decorator.d.ts +8 -0
  20. package/dist/module/decorator.d.ts.map +1 -0
  21. package/dist/module/decorator.js +16 -0
  22. package/dist/module/decorator.js.map +1 -0
  23. package/dist/runtime/MethodIdResolver.d.ts +20 -0
  24. package/dist/runtime/MethodIdResolver.d.ts.map +1 -0
  25. package/dist/runtime/MethodIdResolver.js +91 -0
  26. package/dist/runtime/MethodIdResolver.js.map +1 -0
  27. package/dist/runtime/Runtime.d.ts +72 -0
  28. package/dist/runtime/Runtime.d.ts.map +1 -0
  29. package/dist/runtime/Runtime.js +231 -0
  30. package/dist/runtime/Runtime.js.map +1 -0
  31. package/dist/runtime/RuntimeEnvironment.d.ts +10 -0
  32. package/dist/runtime/RuntimeEnvironment.d.ts.map +1 -0
  33. package/dist/runtime/RuntimeEnvironment.js +2 -0
  34. package/dist/runtime/RuntimeEnvironment.js.map +1 -0
  35. package/dist/runtime/RuntimeModule.d.ts +37 -0
  36. package/dist/runtime/RuntimeModule.d.ts.map +1 -0
  37. package/dist/runtime/RuntimeModule.js +80 -0
  38. package/dist/runtime/RuntimeModule.js.map +1 -0
  39. package/dist/state/InMemoryStateService.d.ts +15 -0
  40. package/dist/state/InMemoryStateService.d.ts.map +1 -0
  41. package/dist/state/InMemoryStateService.js +24 -0
  42. package/dist/state/InMemoryStateService.js.map +1 -0
  43. package/dist/state/decorator.d.ts +7 -0
  44. package/dist/state/decorator.d.ts.map +1 -0
  45. package/dist/state/decorator.js +40 -0
  46. package/dist/state/decorator.js.map +1 -0
  47. package/jest.config.cjs +12 -0
  48. package/package.json +35 -0
  49. package/src/factories/MethodIdFactory.ts +13 -0
  50. package/src/index.ts +10 -0
  51. package/src/method/MethodParameterEncoder.ts +260 -0
  52. package/src/method/runtimeMethod.ts +308 -0
  53. package/src/module/decorator.ts +21 -0
  54. package/src/runtime/MethodIdResolver.ts +108 -0
  55. package/src/runtime/Runtime.ts +395 -0
  56. package/src/runtime/RuntimeEnvironment.ts +16 -0
  57. package/src/runtime/RuntimeModule.ts +112 -0
  58. package/src/state/InMemoryStateService.ts +25 -0
  59. package/src/state/decorator.ts +61 -0
  60. package/test/Runtime.test.ts +70 -0
  61. package/test/TestingRuntime.ts +45 -0
  62. package/test/method/MethodParameterEncoder.test.ts +121 -0
  63. package/test/method/runtimeMethod-fail.test.ts +50 -0
  64. package/test/method/runtimeMethod.test.ts +46 -0
  65. package/test/modules/Admin.ts +19 -0
  66. package/test/modules/Balances.test.ts +337 -0
  67. package/test/modules/Balances.ts +54 -0
  68. package/test/modules/MethodIdResolver.test.ts +73 -0
  69. package/test/modules/State.test.ts +81 -0
  70. package/test/runtimeMethod.test.ts +215 -0
  71. package/test/tsconfig.json +7 -0
  72. package/tsconfig.json +8 -0
package/LICENSE.md ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2023] [Stove Labs]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # YAB: Module
2
+
3
+ Set of APIs to define YAB runtime modules and application chains.
4
+
5
+ **Application chain** consists of multiple _runtime modules_. Runtime modules can be either implemented as part of the chain directly, or imported from 3rd parties. Here's an example of how a chain with two runtime modules can be defined:
6
+
7
+ ```typescript
8
+ const chain = Chain.from({
9
+ state: new InMemoryStateService(),
10
+ // specify which modules should the chain consist of
11
+ modules: {
12
+ Balances,
13
+ Admin,
14
+ },
15
+ });
16
+
17
+ // compile the chain into a verification key
18
+ const { verificationKey } = await chain.compile();
19
+ ```
20
+
21
+ Chain works as a wrapper for all circuit logic contained by the runtime module methods. Compilation produces a _wrap circuit_ including all known methods of the configured runtime modules.
22
+
23
+ Here's an example `Balances` runtime module:
24
+
25
+ ```typescript
26
+ @runtimeModule()
27
+ export class Balances extends RuntimeModule {
28
+ @state() public totalSupply = State.from<UInt64>(UInt64);
29
+
30
+ @state() public balances = StateMap.from<PublicKey, UInt64>(
31
+ PublicKey,
32
+ UInt64
33
+ );
34
+
35
+ public constructor(public admin: Admin) {
36
+ super();
37
+ }
38
+
39
+ @runtimeMethod()
40
+ public getTotalSupply() {
41
+ this.totalSupply.get();
42
+ }
43
+
44
+ @runtimeMethod()
45
+ public setTotalSupply() {
46
+ this.totalSupply.set(UInt64.from(20));
47
+ this.admin.isAdmin();
48
+ }
49
+
50
+ @runtimeMethod()
51
+ public getBalance(address: PublicKey): Option<UInt64> {
52
+ return this.balances.get(address);
53
+ }
54
+ }
55
+ ```
56
+
57
+ The Balances runtime module shows how the YAB runtime module API can be used:
58
+
59
+ - `runtimeModule()` - marks the class as a runtime module
60
+ - `class Balance extends RuntimeModule` - introduces runtime module APIs into the runtime module
61
+ - `@state() public totalSupply = State.from<UInt64>(UInt64)` - defines a runtime module state of type `UInt64`, which can be either get or set
62
+ - `@state() public balances = StateMap.from<PublicKey, UInt64>(PublicKey, UInt64)` - defines a runtime module map state, which allows values to be stored under keys, respective of the given key & value types.
63
+ - `public constructor(public admin: Admin)` - injects a runtime module dependency to another runtime module `Admin`, which is a standalone runtime module
64
+ - `@runtimeMethod() public getTotalSupply()` - defines a runtime module method containing circuit logic for a runtime state transition. Methods define how the chain state is transformed from the initial state to the resulting state.
65
+ - `this.admin.isAdmin()` - shows how runtime module interoperability works, a configured runtime module is injected in the constructor, and can be used within the existing methods. Code of the called runtime module becomes part of the original method circuit (setTotalSupply in this case).
66
+
67
+ ## Method wrapper circuit
68
+
69
+ Every runtime module method gets wrapped into an extra outter circuit, which allows the underlying runtime to make assertions about the results of the method execution, such as:
70
+
71
+ - State transitions
72
+ - Execution status
73
+ - Transaction hash (method invocation arguments)
74
+ - Network state (TODO)
75
+
76
+ The good thing is, the YAB runtime module API does this for you automatically, but it pays off to keep this in mind when debugging your runtime modules. Due to the nature of the underlying ZK method lifecycle, methods cannot produce any side effects beyond the state transitions, which are implicitly generated using the `State` API. Again due to method lifecycle implications, your method code will run multiple times at different stages of its lifecycle, such as:
77
+
78
+ - Compilation
79
+ - Simulation
80
+ - Proving
81
+
82
+ > Please be careful about keeping your runtime module methods side-effect free, since it may introduce inconsistencies in the method lifecycle which may lead to the inability to generate an execution proof.
83
+
84
+ ## Testing
85
+
86
+ Runtime module methods can be ran or tested in two different modes:
87
+
88
+ - Simulation
89
+ - Proving
90
+
91
+ Simulation mode means that only the method javascript code will run, and no proving will be done. This is the fastest way of testing your module methods.
92
+
93
+ Provnig mode means that the whole chain needs to be compiled, and then every method execution can be additionally proven by accessing the provers generated during method simulation.
94
+
95
+ Here's an example of how a runtime module method execution proof can be generated, but please keep in mind you also need to enable proofs and compile the chain. More detailed examples can be found in `test/modules`:
96
+
97
+ ```typescript
98
+ const chain = Chain.from({
99
+ state,
100
+
101
+ modules: {
102
+ Balances,
103
+ Admin,
104
+ },
105
+ });
106
+
107
+ const balances = chain.resolve("Balances");
108
+ balances.getTotalSupply();
109
+
110
+ const {
111
+ result: { prove },
112
+ } = container.resolve(MethodExecutionContext);
113
+ const proof = await prove();
114
+ ```
@@ -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
+ import { MethodIdResolver } from "../runtime/MethodIdResolver";
2
+ export class MethodIdFactory {
3
+ dependencies() {
4
+ return {
5
+ methodIdResolver: {
6
+ useClass: MethodIdResolver,
7
+ },
8
+ };
9
+ }
10
+ }
11
+ //# sourceMappingURL=MethodIdFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodIdFactory.js","sourceRoot":"","sources":["../../src/factories/MethodIdFactory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,OAAO,eAAe;IACnB,YAAY;QACjB,OAAO;YACL,gBAAgB,EAAE;gBAChB,QAAQ,EAAE,gBAAgB;aAC3B;SACyB,CAAC;IAC/B,CAAC;CACF"}
@@ -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"}
package/dist/index.js ADDED
@@ -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.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","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,26 @@
1
+ import { Field, Proof, DynamicProof, FlexibleProvablePure } from "o1js";
2
+ import { ArgumentTypes } from "@proto-kit/common";
3
+ import type { RuntimeModule } from "../runtime/RuntimeModule";
4
+ type ArgumentType = FlexibleProvablePure<any> | typeof Proof<unknown, unknown> | typeof DynamicProof<unknown, unknown>;
5
+ type ArgTypeArray = ArgumentType[];
6
+ type ArgArray = ArgumentTypes[];
7
+ export declare function isFlexibleProvablePure(type: unknown): type is FlexibleProvablePure<unknown>;
8
+ export declare function checkArgsProvable(target: RuntimeModule<unknown>, methodName: string): ArgTypeArray;
9
+ export declare class MethodParameterEncoder {
10
+ private readonly types;
11
+ static fromMethod(target: RuntimeModule<unknown>, methodName: string): MethodParameterEncoder;
12
+ static fieldSize(type: ArgumentType): number | undefined;
13
+ constructor(types: ArgTypeArray);
14
+ decode(fields: Field[], auxiliary: string[]): Promise<ArgArray>;
15
+ /**
16
+ * Variant of encode() for provable code that skips the unprovable
17
+ * json encoding
18
+ */
19
+ encode(args: ArgumentTypes): {
20
+ fields: Field[];
21
+ auxiliary: string[];
22
+ };
23
+ fieldSize(): number;
24
+ }
25
+ export {};
26
+ //# sourceMappingURL=MethodParameterEncoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodParameterEncoder.d.ts","sourceRoot":"","sources":["../../src/method/MethodParameterEncoder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,KAAK,EAEL,YAAY,EACZ,oBAAoB,EACrB,MAAM,MAAM,CAAC;AACd,OAAO,EACL,aAAa,EAKd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAc9D,KAAK,YAAY,GACb,oBAAoB,CAAC,GAAG,CAAC,GACzB,OAAO,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,GAC9B,OAAO,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAE1C,KAAK,YAAY,GAAG,YAAY,EAAE,CAAC;AAEnC,KAAK,QAAQ,GAAG,aAAa,EAAE,CAAC;AA2BhC,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAOvC;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,UAAU,EAAE,MAAM,gBA8BnB;AAED,qBAAa,sBAAsB;IAkBd,OAAO,CAAC,QAAQ,CAAC,KAAK;WAjB3B,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,MAAM;WAM7D,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS;gBAW3B,KAAK,EAAE,YAAY;IAEhD,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;IA0DtE;;;OAGG;IACI,MAAM,CAAC,IAAI,EAAE,aAAa;gBA8CnB,KAAK,EAAE;mBACJ,MAAM,EAAE;;IAelB,SAAS,IAAI,MAAM;CAK3B"}
@@ -0,0 +1,169 @@
1
+ /* eslint-disable @typescript-eslint/consistent-type-assertions */
2
+ import { Proof, Provable, DynamicProof, } from "o1js";
3
+ import { filterNonUndefined, } from "@proto-kit/common";
4
+ const errors = {
5
+ fieldLengthNotMatching: (expected, actual) => new Error(`Expected ${expected} field elements, got ${actual}`),
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}` : ""}`),
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
+ export 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
+ }
31
+ export function checkArgsProvable(target, methodName) {
32
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
33
+ const paramtypes = Reflect.getMetadata("design:paramtypes", target, methodName);
34
+ if (paramtypes === undefined) {
35
+ throw new Error(`Method with name ${methodName} doesn't exist on this module`);
36
+ }
37
+ const indizes = paramtypes
38
+ .map((type, index) => {
39
+ if (isProofBaseType(type) || isFlexibleProvablePure(type)) {
40
+ return undefined;
41
+ }
42
+ return `${index}`;
43
+ })
44
+ .filter(filterNonUndefined);
45
+ if (indizes.length > 0) {
46
+ const indexString = indizes.reduce((a, b) => `${a}, ${b}`);
47
+ throw new Error(`Not all arguments of method '${target.name}.${methodName}' are provable types or proofs (indizes: [${indexString}])`);
48
+ }
49
+ return paramtypes;
50
+ }
51
+ export class MethodParameterEncoder {
52
+ static fromMethod(target, methodName) {
53
+ const paramtypes = checkArgsProvable(target, methodName);
54
+ return new MethodParameterEncoder(paramtypes);
55
+ }
56
+ static fieldSize(type) {
57
+ if (isProofBaseType(type)) {
58
+ return ((MethodParameterEncoder.fieldSize(type.publicInputType) ?? 0) +
59
+ (MethodParameterEncoder.fieldSize(type.publicOutputType) ?? 0));
60
+ }
61
+ // as any, since we shouldn't be using this workaround in the first place
62
+ return type.sizeInFields();
63
+ }
64
+ constructor(types) {
65
+ this.types = types;
66
+ }
67
+ decode(fields, auxiliary) {
68
+ if (fields.length < this.fieldSize()) {
69
+ throw errors.fieldLengthNotMatching(this.fieldSize(), fields.length);
70
+ }
71
+ let stack = fields.slice();
72
+ const auxiliaryStack = auxiliary.slice();
73
+ return Promise.all(this.types.map((type) => {
74
+ const numberFieldsNeeded = MethodParameterEncoder.fieldSize(type) ?? -1;
75
+ if (numberFieldsNeeded === -1) {
76
+ throw errors.typeNotCompatible(type.constructor.name);
77
+ }
78
+ const structFields = stack.slice(0, numberFieldsNeeded);
79
+ stack = stack.slice(numberFieldsNeeded);
80
+ // Decode proof
81
+ if (isProofBaseType(type)) {
82
+ const auxiliaryData = auxiliaryStack.shift();
83
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
84
+ const proofData = JSON.parse(auxiliaryData);
85
+ const inputFieldSize = MethodParameterEncoder.fieldSize(type.publicInputType);
86
+ const input = structFields
87
+ .slice(0, inputFieldSize)
88
+ .map((x) => x.toString());
89
+ const output = structFields
90
+ .slice(inputFieldSize)
91
+ .map((x) => x.toString());
92
+ // fromJSON has incompatible signature for Proof and DynamicProof
93
+ if (isProofType(type)) {
94
+ return type.fromJSON({
95
+ ...proofData,
96
+ publicInput: input,
97
+ publicOutput: output,
98
+ });
99
+ }
100
+ if (isDynamicProofType(type)) {
101
+ return type.fromJSON({
102
+ ...proofData,
103
+ publicInput: input,
104
+ publicOutput: output,
105
+ });
106
+ }
107
+ }
108
+ return type.fromFields(structFields);
109
+ }));
110
+ }
111
+ /**
112
+ * Variant of encode() for provable code that skips the unprovable
113
+ * json encoding
114
+ */
115
+ encode(args) {
116
+ /**
117
+ * Use the type info obtained previously to convert
118
+ * the args passed to fields
119
+ */
120
+ return args
121
+ .map((argument, index) => {
122
+ if (argument instanceof Proof || argument instanceof DynamicProof) {
123
+ const argumentType = this.types[index];
124
+ const { publicOutputType, publicInputType } = argumentType;
125
+ const inputFields =
126
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
127
+ publicInputType?.toFields(argument.publicInput) ?? [];
128
+ const outputFields =
129
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
130
+ publicOutputType?.toFields(argument.publicOutput) ?? [];
131
+ let auxiliary = "";
132
+ // Has to be asProver, because this function will be called by runtimeMethod
133
+ // to transform the args into a Field[] to compute the argsHash
134
+ // In this case, the auxiliary might be empty, but it isn't used by that method anyways
135
+ Provable.asProver(() => {
136
+ const jsonProof = argument.toJSON();
137
+ auxiliary = JSON.stringify({
138
+ proof: jsonProof.proof,
139
+ maxProofsVerified: jsonProof.maxProofsVerified,
140
+ });
141
+ });
142
+ return {
143
+ fields: [...inputFields, ...outputFields],
144
+ auxiliary,
145
+ };
146
+ }
147
+ const argumentType = this.types[index];
148
+ return {
149
+ fields: argumentType.toFields(argument),
150
+ auxiliary: undefined,
151
+ };
152
+ })
153
+ .reduce((a, b) => {
154
+ return {
155
+ fields: [...a.fields, ...b.fields],
156
+ auxiliary: b.auxiliary !== undefined
157
+ ? [...a.auxiliary, b.auxiliary]
158
+ : a.auxiliary,
159
+ };
160
+ }, { fields: [], auxiliary: [] });
161
+ }
162
+ fieldSize() {
163
+ return this.types
164
+ .map((type) => MethodParameterEncoder.fieldSize(type) ?? 0)
165
+ .reduce((a, b) => a + b, 0);
166
+ }
167
+ }
168
+ /* eslint-enable @typescript-eslint/consistent-type-assertions */
169
+ //# sourceMappingURL=MethodParameterEncoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodParameterEncoder.js","sourceRoot":"","sources":["../../src/method/MethodParameterEncoder.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,OAAO,EAEL,KAAK,EACL,QAAQ,EACR,YAAY,GAEb,MAAM,MAAM,CAAC;AACd,OAAO,EAKL,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAI3B,MAAM,MAAM,GAAG;IACb,sBAAsB,EAAE,CAAC,QAAgB,EAAE,MAAc,EAAE,EAAE,CAC3D,IAAI,KAAK,CAAC,YAAY,QAAQ,wBAAwB,MAAM,EAAE,CAAC;IAEjE,iBAAiB,EAAE,CAAC,IAAY,EAAE,KAAc,EAAE,EAAE,CAClD,IAAI,KAAK,CACP,sBAAsB,IAAI,0EACxB,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,KAAK,EAAE,CAAC,CAAC,CAAC,EACh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F;AACD,iEAAiE"}
@@ -0,0 +1,33 @@
1
+ import { Bool, FlexibleProvablePure } from "o1js";
2
+ import { StateTransition, MethodPublicOutput } from "@proto-kit/protocol";
3
+ import { ArgumentTypes } from "@proto-kit/common";
4
+ import type { RuntimeModule } from "../runtime/RuntimeModule.js";
5
+ export declare function toStateTransitionsHash(stateTransitions: StateTransition<any>[]): import("o1js/dist/node/lib/provable/field.js").Field;
6
+ export declare function toEventsHash(events: {
7
+ eventType: FlexibleProvablePure<any>;
8
+ event: any;
9
+ eventName: string;
10
+ condition: Bool;
11
+ }[]): import("o1js/dist/node/lib/provable/field.js").Field;
12
+ export type WrappedMethod = (...args: ArgumentTypes) => MethodPublicOutput;
13
+ export type AsyncWrappedMethod = (...args: ArgumentTypes) => Promise<MethodPublicOutput>;
14
+ export declare function toWrappedMethod(this: RuntimeModule<unknown>, methodName: string, moduleMethod: (...args: ArgumentTypes) => Promise<any>, options: {
15
+ invocationType: RuntimeMethodInvocationType;
16
+ }): AsyncWrappedMethod;
17
+ export declare function combineMethodName(runtimeModuleName: string, methodName: string): string;
18
+ export declare const runtimeMethodMetadataKey = "yab-method";
19
+ export declare const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
20
+ export declare const runtimeMethodTypeMetadataKey = "proto-kit-runtime-method-type";
21
+ /**
22
+ * Checks the metadata of the provided runtime module and its method,
23
+ * to see if it has been decorated with @runtimeMethod()
24
+ *
25
+ * @param target - Runtime module to check
26
+ * @param propertyKey - Name of the method to check in the prior runtime module
27
+ * @returns - If the provided method name is a runtime method or not
28
+ */
29
+ export declare function isRuntimeMethod(target: RuntimeModule<unknown>, propertyKey: string): boolean;
30
+ export type RuntimeMethodInvocationType = "SIGNATURE" | "INCOMING_MESSAGE";
31
+ export declare function runtimeMessage(): (target: RuntimeModule<unknown>, methodName: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>) => void;
32
+ export declare function runtimeMethod(): (target: RuntimeModule<unknown>, methodName: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>) => void;
33
+ //# sourceMappingURL=runtimeMethod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeMethod.d.ts","sourceRoot":"","sources":["../../src/method/runtimeMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAS,oBAAoB,EAAY,MAAM,MAAM,CAAC;AAEnE,OAAO,EACL,eAAe,EAEf,kBAAkB,EAInB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,aAAa,EACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAwBjE,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,wDAczC;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE;IACN,SAAS,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC;IACrC,KAAK,EAAE,GAAG,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,IAAI,CAAC;CACjB,EAAE,wDAOJ;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,CA8EpB;AAED,wBAAgB,iBAAiB,CAC/B,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,UAGnB;AAED,eAAO,MAAM,wBAAwB,eAAe,C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