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

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 (118) 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 +11 -0
  4. package/dist/factories/MethodIdFactory.js.map +1 -0
  5. package/dist/index.d.ts +5 -7
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +6 -7
  8. package/dist/index.js.map +1 -0
  9. package/dist/messages/OutgoingMessage.d.ts +96 -0
  10. package/dist/messages/OutgoingMessage.d.ts.map +1 -0
  11. package/dist/messages/OutgoingMessage.js +68 -0
  12. package/dist/messages/OutgoingMessage.js.map +1 -0
  13. package/dist/messages/OutgoingMessages.d.ts +215 -0
  14. package/dist/messages/OutgoingMessages.d.ts.map +1 -0
  15. package/dist/messages/OutgoingMessages.js +66 -0
  16. package/dist/messages/OutgoingMessages.js.map +1 -0
  17. package/dist/method/MethodParameterEncoder.d.ts +26 -0
  18. package/dist/method/MethodParameterEncoder.d.ts.map +1 -0
  19. package/dist/method/MethodParameterEncoder.js +169 -0
  20. package/dist/method/MethodParameterEncoder.js.map +1 -0
  21. package/dist/method/runtimeMethod.d.ts +22 -5
  22. package/dist/method/runtimeMethod.d.ts.map +1 -1
  23. package/dist/method/runtimeMethod.js +79 -24
  24. package/dist/method/runtimeMethod.js.map +1 -0
  25. package/dist/module/decorator.js +1 -0
  26. package/dist/module/decorator.js.map +1 -0
  27. package/dist/runtime/MethodIdResolver.d.ts +20 -0
  28. package/dist/runtime/MethodIdResolver.d.ts.map +1 -0
  29. package/dist/runtime/MethodIdResolver.js +91 -0
  30. package/dist/runtime/MethodIdResolver.js.map +1 -0
  31. package/dist/runtime/Runtime.d.ts +22 -28
  32. package/dist/runtime/Runtime.d.ts.map +1 -1
  33. package/dist/runtime/Runtime.js +116 -70
  34. package/dist/runtime/Runtime.js.map +1 -0
  35. package/dist/runtime/RuntimeEnvironment.d.ts +10 -0
  36. package/dist/runtime/RuntimeEnvironment.d.ts.map +1 -0
  37. package/dist/runtime/RuntimeEnvironment.js +2 -0
  38. package/dist/runtime/RuntimeEnvironment.js.map +1 -0
  39. package/dist/runtime/RuntimeModule.d.ts +23 -14
  40. package/dist/runtime/RuntimeModule.d.ts.map +1 -1
  41. package/dist/runtime/RuntimeModule.js +47 -10
  42. package/dist/runtime/RuntimeModule.js.map +1 -0
  43. package/dist/state/InMemoryStateService.d.ts +11 -10
  44. package/dist/state/InMemoryStateService.d.ts.map +1 -1
  45. package/dist/state/InMemoryStateService.js +11 -8
  46. package/dist/state/InMemoryStateService.js.map +1 -0
  47. package/dist/state/decorator.d.ts.map +1 -1
  48. package/dist/state/decorator.js +2 -4
  49. package/dist/state/decorator.js.map +1 -0
  50. package/dist/testing/TestingRuntime.d.ts +8 -0
  51. package/dist/testing/TestingRuntime.d.ts.map +1 -0
  52. package/dist/testing/TestingRuntime.js +31 -0
  53. package/dist/testing/TestingRuntime.js.map +1 -0
  54. package/jest.config.cjs +12 -1
  55. package/package.json +10 -11
  56. package/src/factories/MethodIdFactory.ts +13 -0
  57. package/src/index.ts +5 -7
  58. package/src/messages/OutgoingMessages.ts +122 -0
  59. package/src/method/MethodParameterEncoder.ts +260 -0
  60. package/src/method/runtimeMethod.ts +146 -31
  61. package/src/runtime/MethodIdResolver.ts +108 -0
  62. package/src/runtime/Runtime.ts +191 -112
  63. package/src/runtime/RuntimeEnvironment.ts +16 -0
  64. package/src/runtime/RuntimeModule.ts +77 -27
  65. package/src/state/InMemoryStateService.ts +14 -18
  66. package/test/Runtime.test.ts +69 -36
  67. package/test/TestingRuntime.ts +43 -0
  68. package/test/messages/message.test.ts +42 -0
  69. package/test/method/MethodParameterEncoder.test.ts +121 -0
  70. package/test/method/runtimeMethod-fail.test.ts +50 -0
  71. package/{src/method/decorator.test.ts → test/method/runtimeMethod.test.ts} +3 -3
  72. package/test/modules/Admin.ts +4 -4
  73. package/test/modules/Balances.test.ts +92 -78
  74. package/test/modules/Balances.ts +19 -16
  75. package/test/modules/MethodIdResolver.test.ts +73 -0
  76. package/test/modules/State.test.ts +81 -0
  77. package/test/runtimeMethod.test.ts +192 -20
  78. package/test/tsconfig.json +7 -0
  79. package/tsconfig.json +2 -2
  80. package/dist/chain/Chain.d.ts +0 -109
  81. package/dist/chain/Chain.d.ts.map +0 -1
  82. package/dist/chain/Chain.js +0 -229
  83. package/dist/method/MethodExecutionContext.d.ts +0 -73
  84. package/dist/method/MethodExecutionContext.d.ts.map +0 -1
  85. package/dist/method/MethodExecutionContext.js +0 -112
  86. package/dist/method/MethodParameterDecoder.d.ts +0 -22
  87. package/dist/method/MethodParameterDecoder.d.ts.map +0 -1
  88. package/dist/method/MethodParameterDecoder.js +0 -33
  89. package/dist/method/RuntimeMethodExecutionContext.d.ts +0 -57
  90. package/dist/method/RuntimeMethodExecutionContext.d.ts.map +0 -1
  91. package/dist/method/RuntimeMethodExecutionContext.js +0 -92
  92. package/dist/method/assert.d.ts +0 -12
  93. package/dist/method/assert.d.ts.map +0 -1
  94. package/dist/method/assert.js +0 -23
  95. package/dist/method/decorator.d.ts +0 -45
  96. package/dist/method/decorator.d.ts.map +0 -1
  97. package/dist/method/decorator.js +0 -140
  98. package/dist/state/State.d.ts +0 -65
  99. package/dist/state/State.d.ts.map +0 -1
  100. package/dist/state/State.js +0 -114
  101. package/dist/state/StateMap.d.ts +0 -37
  102. package/dist/state/StateMap.d.ts.map +0 -1
  103. package/dist/state/StateMap.js +0 -56
  104. package/dist/state/StateServiceProvider.d.ts +0 -10
  105. package/dist/state/StateServiceProvider.d.ts.map +0 -1
  106. package/dist/state/StateServiceProvider.js +0 -34
  107. package/src/method/MethodParameterDecoder.ts +0 -68
  108. package/src/method/RuntimeMethodExecutionContext.ts +0 -111
  109. package/src/method/assert.test.ts +0 -49
  110. package/src/method/assert.ts +0 -27
  111. package/src/state/State.ts +0 -154
  112. package/src/state/StateMap.ts +0 -69
  113. package/src/state/StateServiceProvider.ts +0 -24
  114. package/src/state/decorator.ts +0 -65
  115. package/test/state/MerkleTree.test.ts +0 -95
  116. package/test/state/MockAsyncMerkleStore.ts +0 -28
  117. package/test/transaction.test.ts +0 -82
  118. package/tsconfig.test.json +0 -9
@@ -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,EAChD,EAAE,CACH;CACJ,CAAC;AAWF,SAAS,WAAW,CAAC,IAAa;IAChC,OAAQ,IAAuC,CAAC,SAAS,YAAY,KAAK,CAAC;AAC7E,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAa;IACvC,OAAO,CACJ,IAAuC,CAAC,SAAS,YAAY,YAAY,CAC3E,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CACtB,IAAa;IAEb,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,mCA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H;YAED,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAsB,CAAC;YAC5D,OAAO;gBACL,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACvC,SAAS,EAAE,SAAS;aACrB,CAAC;QACJ,CAAC,CAAC;aACD,MAAM,CAIL,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACP,OAAO;gBACL,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC;gBAClC,SAAS,EACP,CAAC,CAAC,SAAS,KAAK,SAAS;oBACvB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC;oBAC/B,CAAC,CAAC,CAAC,CAAC,SAAS;aAClB,CAAC;QACJ,CAAC,EACD,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAC9B,CAAC;IACN,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,CAAC,KAAK;aACd,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,sBAAsB,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC1D,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;CACF;AACD,iEAAiE"}
@@ -1,10 +1,25 @@
1
- import { StateTransition, MethodPublicOutput } from "@proto-kit/protocol";
1
+ import { Bool, FlexibleProvablePure } from "o1js";
2
+ import { ProvableStateTransition, MethodPublicOutput } from "@proto-kit/protocol";
3
+ import { ArgumentTypes } from "@proto-kit/common";
2
4
  import type { RuntimeModule } from "../runtime/RuntimeModule.js";
3
- export declare function toStateTransitionsHash(stateTransitions: StateTransition<any>[]): import("snarkyjs/dist/node/lib/field.js").Field;
4
- export type WrappedMethod = (...args: unknown[]) => MethodPublicOutput;
5
- export declare function toWrappedMethod(this: RuntimeModule<unknown>, methodName: string, moduleMethod: (...args: unknown[]) => unknown): WrappedMethod;
5
+ export declare function toStateTransitionsHash(stateTransitions: {
6
+ toProvable: () => ProvableStateTransition;
7
+ }[]): import("o1js/dist/node/lib/provable/field.js").Field;
8
+ export declare function toEventsHash(events: {
9
+ eventType: FlexibleProvablePure<any>;
10
+ event: any;
11
+ eventName: string;
12
+ condition: Bool;
13
+ }[]): import("o1js/dist/node/lib/provable/field.js").Field;
14
+ export type WrappedMethod = (...args: ArgumentTypes) => MethodPublicOutput;
15
+ export type AsyncWrappedMethod = (...args: ArgumentTypes) => Promise<MethodPublicOutput>;
16
+ export declare function toWrappedMethod(this: RuntimeModule<unknown>, methodName: string, moduleMethod: (...args: ArgumentTypes) => Promise<any>, options: {
17
+ invocationType: RuntimeMethodInvocationType;
18
+ }): AsyncWrappedMethod;
6
19
  export declare function combineMethodName(runtimeModuleName: string, methodName: string): string;
7
20
  export declare const runtimeMethodMetadataKey = "yab-method";
21
+ export declare const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
22
+ export declare const runtimeMethodTypeMetadataKey = "proto-kit-runtime-method-type";
8
23
  /**
9
24
  * Checks the metadata of the provided runtime module and its method,
10
25
  * to see if it has been decorated with @runtimeMethod()
@@ -14,5 +29,7 @@ export declare const runtimeMethodMetadataKey = "yab-method";
14
29
  * @returns - If the provided method name is a runtime method or not
15
30
  */
16
31
  export declare function isRuntimeMethod(target: RuntimeModule<unknown>, propertyKey: string): boolean;
17
- export declare function runtimeMethod(): (target: RuntimeModule<unknown>, methodName: string, descriptor: PropertyDescriptor) => void;
32
+ export type RuntimeMethodInvocationType = "SIGNATURE" | "INCOMING_MESSAGE";
33
+ export declare function runtimeMessage(): (target: RuntimeModule<unknown>, methodName: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>) => void;
34
+ export declare function runtimeMethod(): (target: RuntimeModule<unknown>, methodName: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>) => void;
18
35
  //# sourceMappingURL=runtimeMethod.d.ts.map
@@ -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,OAAO,EAAE,KAAK,kBAAkB,CAAC;AAEvE,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,iBAoC9C;AAED,wBAAgB,iBAAiB,CAC/B,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,UAGnB;AAED,eAAO,MAAM,wBAAwB,eAAe,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,WAAW,EAAE,MAAM,WAKpB;AAED,wBAAgB,aAAa,aAEjB,cAAc,OAAO,CAAC,cAClB,MAAM,cACN,kBAAkB,UA2EjC"}
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,uBAAuB,EACvB,kBAAkB,EAInB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,aAAa,EACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BA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import { container } from "tsyringe";
2
- import { DefaultProvableHashList, ProvableStateTransition, MethodPublicOutput, } from "@proto-kit/protocol";
3
- import { toProver } from "@proto-kit/common";
4
- import { RuntimeMethodExecutionContext } from "./RuntimeMethodExecutionContext.js";
3
+ import { ProvableStateTransition, MethodPublicOutput, RuntimeMethodExecutionContext, StateTransitionReductionList, DefaultProvableHashList, } from "@proto-kit/protocol";
4
+ import { toProver, } from "@proto-kit/common";
5
+ import { MethodParameterEncoder, checkArgsProvable, } from "./MethodParameterEncoder";
5
6
  const errors = {
6
7
  runtimeNotProvided: (name) => new Error(`Runtime was not provided for module: ${name}`),
7
8
  methodInputsNotProvided: () => new Error("Method execution inputs not provided, provide them via context.inputs"),
9
+ runtimeNameNotSet: () => new Error("Runtime name was not set"),
10
+ fieldNotConstant: (name) => new Error(`In-circuit field ${name} not a constant, this is likely a framework bug`),
8
11
  };
9
- export function toStateTransitionsHash(
10
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
- stateTransitions) {
12
- const stateTransitionsHashList = new DefaultProvableHashList(ProvableStateTransition);
12
+ export function toStateTransitionsHash(stateTransitions) {
13
+ const stateTransitionsHashList = new StateTransitionReductionList(ProvableStateTransition);
13
14
  return stateTransitions
14
15
  .map((stateTransition) => stateTransition.toProvable())
15
16
  .reduce((allStateTransitionsHashList, stateTransition) => allStateTransitionsHashList.push(stateTransition), stateTransitionsHashList)
16
17
  .toField();
17
18
  }
18
- export function toWrappedMethod(methodName, moduleMethod) {
19
+ export function toEventsHash(events) {
20
+ return events.reduce((acc, event) => {
21
+ const hashList = new DefaultProvableHashList(event.eventType, acc);
22
+ hashList.pushIf(event.event, event.condition);
23
+ return hashList.commitment;
24
+ }, Field(0));
25
+ }
26
+ export function toWrappedMethod(methodName, moduleMethod, options) {
19
27
  const executionContext = container.resolve(RuntimeMethodExecutionContext);
20
- const wrappedMethod = (...args) => {
21
- Reflect.apply(moduleMethod, this, args);
22
- const { result: { stateTransitions, status }, input, } = executionContext.current();
28
+ const wrappedMethod = async (...args) => {
29
+ await Reflect.apply(moduleMethod, this, args);
30
+ const { result: { stateTransitions, status, events }, } = executionContext.current();
23
31
  const stateTransitionsHash = toStateTransitionsHash(stateTransitions);
24
- if (input === undefined) {
25
- throw errors.methodInputsNotProvided();
32
+ const eventsHash = toEventsHash(events);
33
+ const { name, parent: runtime } = this;
34
+ if (name === undefined) {
35
+ throw errors.runtimeNameNotSet();
36
+ }
37
+ if (runtime === undefined) {
38
+ throw errors.runtimeNotProvided(name);
39
+ }
40
+ const { transaction, networkState } = executionContext.witnessInput();
41
+ const { methodIdResolver } = runtime;
42
+ // Assert that the given transaction has the correct methodId
43
+ const thisMethodId = Field(methodIdResolver.getMethodId(name, methodName));
44
+ if (!thisMethodId.isConstant()) {
45
+ throw errors.fieldNotConstant("methodId");
26
46
  }
27
- const transactionHash = input.transaction.hash();
28
- const networkStateHash = input.networkState.hash();
47
+ transaction.methodId.assertEquals(thisMethodId, "Runtimemethod called with wrong methodId on the transaction object");
48
+ /**
49
+ * Use the type info obtained previously to convert
50
+ * the args passed to fields
51
+ */
52
+ const { fields } = MethodParameterEncoder.fromMethod(this, methodName).encode(args);
53
+ // Assert that the argsHash that has been signed matches the given arguments
54
+ const argsHash = Poseidon.hash(fields);
55
+ transaction.argsHash.assertEquals(argsHash, "argsHash and therefore arguments of transaction and runtime call does not match");
56
+ const isMessage = Bool(options.invocationType === "INCOMING_MESSAGE");
57
+ transaction.assertTransactionType(Bool(isMessage));
58
+ const transactionHash = transaction.hash();
59
+ const networkStateHash = networkState.hash();
29
60
  return new MethodPublicOutput({
30
61
  stateTransitionsHash,
31
62
  status,
32
63
  transactionHash,
33
64
  networkStateHash,
65
+ isMessage,
66
+ eventsHash,
34
67
  });
35
68
  };
36
69
  Object.defineProperty(wrappedMethod, "name", {
@@ -43,6 +76,8 @@ export function combineMethodName(runtimeModuleName, methodName) {
43
76
  return `${runtimeModuleName}.${methodName}`;
44
77
  }
45
78
  export const runtimeMethodMetadataKey = "yab-method";
79
+ export const runtimeMethodNamesMetadataKey = "proto-kit-runtime-methods";
80
+ export const runtimeMethodTypeMetadataKey = "proto-kit-runtime-method-type";
46
81
  /**
47
82
  * Checks the metadata of the provided runtime module and its method,
48
83
  * to see if it has been decorated with @runtimeMethod()
@@ -54,14 +89,25 @@ export const runtimeMethodMetadataKey = "yab-method";
54
89
  export function isRuntimeMethod(target, propertyKey) {
55
90
  return Boolean(Reflect.getMetadata(runtimeMethodMetadataKey, target, propertyKey));
56
91
  }
57
- export function runtimeMethod() {
92
+ function runtimeMethodInternal(options) {
58
93
  return (target, methodName, descriptor) => {
94
+ checkArgsProvable(target, methodName);
59
95
  const executionContext = container.resolve(RuntimeMethodExecutionContext);
96
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
97
+ let data = Reflect.getMetadata(runtimeMethodNamesMetadataKey, target);
98
+ if (data !== undefined) {
99
+ data.push(methodName);
100
+ }
101
+ else {
102
+ data = [methodName];
103
+ }
104
+ Reflect.defineMetadata(runtimeMethodNamesMetadataKey, data, target);
60
105
  Reflect.defineMetadata(runtimeMethodMetadataKey, true, target, methodName);
106
+ Reflect.defineMetadata(runtimeMethodTypeMetadataKey, options.invocationType, target, methodName);
61
107
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
62
108
  const simulatedMethod = descriptor.value;
63
- descriptor.value = function value(...args) {
64
- const constructorName = this.constructor.name;
109
+ descriptor.value = async function value(...args) {
110
+ const constructorName = this.name;
65
111
  /**
66
112
  * If its a top level method call, wrap it into a wrapped method,
67
113
  * since it'll be turned into a real/mock prover in provableMethod().
@@ -72,17 +118,16 @@ export function runtimeMethod() {
72
118
  const simulatedWrappedMethod = Reflect.apply(toWrappedMethod, this, [
73
119
  methodName,
74
120
  simulatedMethod,
121
+ options,
75
122
  ]);
76
123
  /**
77
124
  * Before the prover runs, make sure it is operating on the correct
78
125
  * RuntimeMethodExecutionContext state, meaning it enters and exits
79
126
  * the context properly.
80
127
  */
81
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
128
  async function prover() {
83
129
  executionContext.beforeMethod(constructorName, methodName, args);
84
130
  const innerProver = toProver(combineMethodName(constructorName, methodName), simulatedWrappedMethod, false, ...args).bind(this);
85
- // eslint-disable-next-line @typescript-eslint/init-declarations
86
131
  let result;
87
132
  try {
88
133
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -95,15 +140,14 @@ export function runtimeMethod() {
95
140
  }
96
141
  executionContext.beforeMethod(constructorName, methodName, args);
97
142
  if (executionContext.isTopLevel) {
98
- if (!this.runtime) {
143
+ if (!this.parent) {
99
144
  throw errors.runtimeNotProvided(constructorName);
100
145
  }
101
- executionContext.setProver(prover.bind(this.runtime.zkProgrammable));
146
+ executionContext.setProver(prover.bind(this.parent.zkProgrammable));
102
147
  }
103
- // eslint-disable-next-line @typescript-eslint/init-declarations
104
148
  let result;
105
149
  try {
106
- result = Reflect.apply(simulatedMethod, this, args);
150
+ result = await Reflect.apply(simulatedMethod, this, args);
107
151
  }
108
152
  finally {
109
153
  executionContext.afterMethod();
@@ -112,3 +156,14 @@ export function runtimeMethod() {
112
156
  };
113
157
  };
114
158
  }
159
+ export function runtimeMessage() {
160
+ return runtimeMethodInternal({
161
+ invocationType: "INCOMING_MESSAGE",
162
+ });
163
+ }
164
+ export function runtimeMethod() {
165
+ return runtimeMethodInternal({
166
+ invocationType: "SIGNATURE",
167
+ });
168
+ }
169
+ //# sourceMappingURL=runtimeMethod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeMethod.js","sourceRoot":"","sources":["../../src/method/runtimeMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAwB,QAAQ,EAAE,MAAM,MAAM,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,6BAA6B,EAC7B,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,qBAAqB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,3 +13,4 @@ export function runtimeModule() {
13
13
  injectable()(target);
14
14
  };
15
15
  }
16
+ //# sourceMappingURL=decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/module/decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAKtC;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO;IACL;;;OAGG;IACH,MACoC,EACpC,EAAE;QACF,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { RuntimeMethodIdMapping } from "@proto-kit/protocol";
2
+ import type { Runtime, RuntimeModulesRecord } from "./Runtime";
3
+ /**
4
+ * Please see `getMethodId` to learn more about
5
+ * methodId encoding
6
+ */
7
+ export declare class MethodIdResolver {
8
+ private readonly runtime;
9
+ private readonly dictionary;
10
+ constructor(runtime: Runtime<RuntimeModulesRecord>);
11
+ /**
12
+ * The purpose of this method is to provide a dictionary where
13
+ * we can look up properties like methodId and invocationType
14
+ * for each runtimeMethod using their module name and method name
15
+ */
16
+ methodIdMap(): RuntimeMethodIdMapping;
17
+ getMethodNameFromId(methodId: bigint): [string, string] | undefined;
18
+ getMethodId(moduleName: string, methodName: string): bigint;
19
+ }
20
+ //# sourceMappingURL=MethodIdResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodIdResolver.d.ts","sourceRoot":"","sources":["../../src/runtime/MethodIdResolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAS5E,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAE/D;;;GAGG;AACH,qBACa,gBAAgB;IAMN,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAEpB;gBAG+B,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAkB5E;;;;OAIG;IACI,WAAW,IAAI,sBAAsB;IAuCrC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;IAcnE,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;CAQnE"}
@@ -0,0 +1,91 @@
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 { filterNonUndefined } from "@proto-kit/common";
14
+ import { stringToField } from "@proto-kit/protocol";
15
+ import { Poseidon } from "o1js";
16
+ import { inject, injectable } from "tsyringe";
17
+ import { runtimeMethodTypeMetadataKey, } from "../method/runtimeMethod";
18
+ /**
19
+ * Please see `getMethodId` to learn more about
20
+ * methodId encoding
21
+ */
22
+ export let MethodIdResolver = class MethodIdResolver {
23
+ constructor(runtime) {
24
+ this.runtime = runtime;
25
+ this.dictionary = {};
26
+ this.dictionary = runtime.runtimeModuleNames.reduce((dict, moduleName) => {
27
+ this.runtime.assertIsValidModuleName(moduleName);
28
+ runtime.resolve(moduleName).runtimeMethodNames.forEach((methodName) => {
29
+ dict[this.getMethodId(moduleName, methodName).toString()] = {
30
+ moduleName,
31
+ methodName,
32
+ };
33
+ });
34
+ return dict;
35
+ }, {});
36
+ }
37
+ /**
38
+ * The purpose of this method is to provide a dictionary where
39
+ * we can look up properties like methodId and invocationType
40
+ * for each runtimeMethod using their module name and method name
41
+ */
42
+ methodIdMap() {
43
+ const methodIdResolver = this.runtime.dependencyContainer.resolve("MethodIdResolver");
44
+ const rawMappings = this.runtime.moduleNames.flatMap((moduleName) => {
45
+ const module = this.runtime.resolve(moduleName);
46
+ return module.runtimeMethodNames.map((method) => {
47
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
48
+ const type = Reflect.getMetadata(runtimeMethodTypeMetadataKey, module, method);
49
+ if (type !== undefined) {
50
+ return {
51
+ name: `${moduleName}.${method}`,
52
+ methodId: methodIdResolver.getMethodId(moduleName, method),
53
+ type,
54
+ };
55
+ }
56
+ return undefined;
57
+ });
58
+ });
59
+ return rawMappings
60
+ .filter(filterNonUndefined)
61
+ .reduce((acc, entry) => {
62
+ acc[entry.name] = {
63
+ methodId: entry.methodId,
64
+ type: entry.type,
65
+ };
66
+ return acc;
67
+ }, {});
68
+ }
69
+ getMethodNameFromId(methodId) {
70
+ const methodPath = this.dictionary[methodId.toString()];
71
+ if (methodPath === undefined) {
72
+ return undefined;
73
+ }
74
+ const { moduleName, methodName } = methodPath;
75
+ this.runtime.assertIsValidModuleName(moduleName);
76
+ return [moduleName, methodName];
77
+ }
78
+ getMethodId(moduleName, methodName) {
79
+ this.runtime.assertIsValidModuleName(moduleName);
80
+ return Poseidon.hash([
81
+ stringToField(moduleName),
82
+ stringToField(methodName),
83
+ ]).toBigInt();
84
+ }
85
+ };
86
+ MethodIdResolver = __decorate([
87
+ injectable(),
88
+ __param(0, inject("Runtime")),
89
+ __metadata("design:paramtypes", [Function])
90
+ ], MethodIdResolver);
91
+ //# sourceMappingURL=MethodIdResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodIdResolver.js","sourceRoot":"","sources":["../../src/runtime/Meth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AAuB,CAAC,UAAU,CAAC,CAAC;QAEjD,OAAO,QAAQ,CAAC,IAAI,CAAC;YACnB,aAAa,CAAC,UAAU,CAAC;YACzB,aAAa,CAAC,UAAU,CAAC;SAC1B,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChB,CAAC;CACF,CAAA;AA1FY,gBAAgB;IAD5B,UAAU,EAAE;IAOR,WAAA,MAAM,CAAC,SAAS,CAAC,CAAA;;GANT,gBAAgB,CA0F5B"}
@@ -1,10 +1,11 @@
1
- import { Experimental } from "snarkyjs";
1
+ import { ZkProgram } from "o1js";
2
2
  import { DependencyContainer } from "tsyringe";
3
- import { StringKeyOf, ModuleContainer, ModulesConfig, ModulesRecord, TypedClass, ZkProgrammable, PlainZkProgram, WithZkProgrammable, AreProofsEnabled } from "@proto-kit/common";
4
- import { MethodPublicOutput } from "@proto-kit/protocol";
5
- import { StateService } from "../state/InMemoryStateService.js";
6
- import { StateServiceProvider } from "../state/StateServiceProvider";
7
- import { RuntimeModule } from "./RuntimeModule.js";
3
+ import { StringKeyOf, ModuleContainer, ModulesRecord, TypedClass, ZkProgrammable, PlainZkProgram, AreProofsEnabled, ChildContainerProvider, CompilableModule, CompileRegistry } from "@proto-kit/common";
4
+ import { MethodPublicOutput, StateServiceProvider, SimpleAsyncStateService } from "@proto-kit/protocol";
5
+ import { RuntimeModule } from "./RuntimeModule";
6
+ import { MethodIdResolver } from "./MethodIdResolver";
7
+ import { RuntimeEnvironment } from "./RuntimeEnvironment";
8
+ export declare function getAllPropertyNames(obj: any): (string | symbol)[];
8
9
  /**
9
10
  * Record of modules accepted by the Runtime module container.
10
11
  *
@@ -12,39 +13,32 @@ import { RuntimeModule } from "./RuntimeModule.js";
12
13
  * is an abstract class
13
14
  */
14
15
  export type RuntimeModulesRecord = ModulesRecord<TypedClass<RuntimeModule<unknown>>>;
15
- /**
16
- * Definition / required arguments for the Runtime class
17
- */
18
- export interface RuntimeDefinition<Modules extends RuntimeModulesRecord> {
19
- state: StateService;
20
- modules: Modules;
21
- config?: ModulesConfig<Modules>;
22
- }
23
16
  export declare class RuntimeZkProgrammable<Modules extends RuntimeModulesRecord> extends ZkProgrammable<undefined, MethodPublicOutput> {
24
17
  runtime: Runtime<Modules>;
25
18
  constructor(runtime: Runtime<Modules>);
26
- get appChain(): AreProofsEnabled | undefined;
27
- zkProgramFactory(): PlainZkProgram<undefined, MethodPublicOutput>;
19
+ get areProofsEnabled(): AreProofsEnabled | undefined;
20
+ zkProgramFactory(): PlainZkProgram<undefined, MethodPublicOutput>[];
28
21
  }
29
22
  /**
30
23
  * Wrapper for an application specific runtime, which helps orchestrate
31
24
  * runtime modules into an interoperable runtime.
32
25
  */
33
- export declare class Runtime<Modules extends RuntimeModulesRecord> extends ModuleContainer<Modules> implements WithZkProgrammable<undefined, MethodPublicOutput> {
34
- static from<Modules extends RuntimeModulesRecord>(definition: RuntimeDefinition<Modules>): Runtime<Modules>;
35
- program?: ReturnType<typeof Experimental.ZkProgram>;
36
- definition: RuntimeDefinition<Modules>;
26
+ export declare class Runtime<Modules extends RuntimeModulesRecord> extends ModuleContainer<Modules> implements RuntimeEnvironment, CompilableModule {
27
+ static from<Modules extends RuntimeModulesRecord>(definition: Modules): TypedClass<Runtime<Modules>>;
28
+ program?: ReturnType<typeof ZkProgram>;
29
+ definition: Modules;
37
30
  zkProgrammable: ZkProgrammable<undefined, MethodPublicOutput>;
38
- private readonly stateServiceProviderInstance;
39
31
  /**
40
32
  * Creates a new Runtime from the provided config
41
33
  *
42
34
  * @param modules - Configuration object for the constructed Runtime
43
35
  */
44
- constructor(definition: RuntimeDefinition<Modules>);
45
- get appChain(): AreProofsEnabled | undefined;
46
- get stateService(): StateService;
36
+ constructor(definition: Modules);
37
+ create(childContainerProvider: ChildContainerProvider): void;
38
+ get areProofsEnabled(): AreProofsEnabled | undefined;
47
39
  get stateServiceProvider(): StateServiceProvider;
40
+ get stateService(): SimpleAsyncStateService;
41
+ get methodIdResolver(): MethodIdResolver;
48
42
  /**
49
43
  * @returns The dependency injection container of this runtime
50
44
  */
@@ -53,19 +47,19 @@ export declare class Runtime<Modules extends RuntimeModulesRecord> extends Modul
53
47
  * @param methodId The encoded name of the method to call.
54
48
  * Encoding: "stringToField(module.name) << 128 + stringToField(method-name)"
55
49
  */
56
- getMethodById(methodId: bigint): (...args: unknown[]) => unknown;
57
- getMethodNameFromId(methodId: bigint): [string, string];
58
- getMethodId(moduleName: string, methodName: string): bigint;
50
+ getMethodById(methodId: bigint): ((...args: unknown[]) => Promise<unknown>) | undefined;
59
51
  /**
60
52
  * Add a name and other respective properties required by RuntimeModules,
61
53
  * that come from the current Runtime
62
54
  *
63
- * @param name - Name of the runtime module to decorate
55
+ * @param moduleName - Name of the runtime module to decorate
56
+ * @param containedModule
64
57
  */
65
58
  decorateModule(moduleName: StringKeyOf<Modules>, containedModule: InstanceType<Modules[StringKeyOf<Modules>]>): void;
66
59
  /**
67
60
  * @returns A list of names of all the registered module names
68
61
  */
69
62
  get runtimeModuleNames(): string[];
63
+ compile(registry: CompileRegistry): Promise<Record<string, import("@proto-kit/common").CompileArtifact>>;
70
64
  }
71
65
  //# sourceMappingURL=Runtime.d.ts.map