@proto-kit/module 0.1.1-develop.263 → 0.1.1-develop.298

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 (36) hide show
  1. package/dist/method/MethodParameterDecoder.d.ts +2 -15
  2. package/dist/method/MethodParameterDecoder.d.ts.map +1 -1
  3. package/dist/method/MethodParameterDecoder.js +13 -18
  4. package/dist/method/runtimeMethod.d.ts +1 -1
  5. package/dist/method/runtimeMethod.d.ts.map +1 -1
  6. package/dist/method/runtimeMethod.js +14 -4
  7. package/dist/runtime/MethodIdResolver.js +1 -1
  8. package/dist/runtime/Runtime.d.ts +8 -5
  9. package/dist/runtime/Runtime.d.ts.map +1 -1
  10. package/dist/runtime/Runtime.js +13 -8
  11. package/dist/runtime/RuntimeEnvironment.d.ts +10 -0
  12. package/dist/runtime/RuntimeEnvironment.d.ts.map +1 -0
  13. package/dist/runtime/RuntimeEnvironment.js +1 -0
  14. package/dist/runtime/RuntimeModule.d.ts +2 -1
  15. package/dist/runtime/RuntimeModule.d.ts.map +1 -1
  16. package/dist/state/InMemoryStateService.d.ts +1 -1
  17. package/dist/state/InMemoryStateService.d.ts.map +1 -1
  18. package/package.json +3 -3
  19. package/src/method/MethodParameterDecoder.ts +20 -45
  20. package/src/method/decorator.test.ts +1 -1
  21. package/src/method/runtimeMethod.ts +13 -7
  22. package/src/runtime/MethodIdResolver.ts +1 -1
  23. package/src/runtime/Runtime.ts +18 -10
  24. package/src/runtime/RuntimeEnvironment.ts +19 -0
  25. package/src/runtime/RuntimeModule.ts +2 -1
  26. package/src/state/InMemoryStateService.ts +1 -1
  27. package/test/Runtime.test.ts +4 -5
  28. package/test/modules/Admin.ts +1 -1
  29. package/test/modules/Balances.test.ts +2 -2
  30. package/test/modules/Balances.ts +1 -1
  31. package/test/modules/State.test.ts +4 -7
  32. package/test/modules/methodId.test.ts +11 -13
  33. package/test/runtimeMethod.test.ts +1 -1
  34. package/test/state/MerkleTree.test.ts +1 -1
  35. package/test/state/MockAsyncMerkleStore.ts +5 -4
  36. package/test/transaction.test.ts +1 -1
@@ -1,22 +1,9 @@
1
- import { Field } from "snarkyjs";
1
+ import { FlexibleProvable } from "o1js";
2
2
  import { RuntimeModule } from "../runtime/RuntimeModule";
3
- export interface Fieldable {
4
- toFields: () => Field[];
5
- }
6
- export interface FromFieldClass {
7
- new: (...args: any[]) => any;
8
- fromFields: (fields: Field[]) => Fieldable;
9
- name: string;
10
- prototype: {
11
- _fields?: any[];
12
- };
13
- sizeInFields?: () => number;
14
- }
15
3
  export declare class MethodParameterDecoder {
16
4
  private readonly types;
17
5
  static fromMethod(target: RuntimeModule<unknown>, methodName: string): MethodParameterDecoder;
18
6
  private constructor();
19
- fromFields(fields: Field[]): Fieldable[];
20
- get fieldSize(): number;
7
+ fromJSON(argsJSON: string[]): FlexibleProvable<unknown>[];
21
8
  }
22
9
  //# sourceMappingURL=MethodParameterDecoder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MethodParameterDecoder.d.ts","sourceRoot":"","sources":["../../src/method/MethodParameterDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,KAAK,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAC7B,UAAU,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,SAAS,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;IAEb,SAAS,EAAE;QACT,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;KACjB,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAYD,qBAAa,sBAAsB;IAWb,OAAO,CAAC,QAAQ,CAAC,KAAK;WAV5B,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,MAAM;IAU3E,OAAO;IAEA,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE;IAmB/C,IAAW,SAAS,IAAI,MAAM,CAM7B;CACF"}
1
+ {"version":3,"file":"MethodParameterDecoder.d.ts","sourceRoot":"","sources":["../../src/method/MethodParameterDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAoB,MAAM,MAAM,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AASzD,qBAAa,sBAAsB;IAYb,OAAO,CAAC,QAAQ,CAAC,KAAK;WAX5B,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,MAAM;IAW3E,OAAO;IAEA,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,EAAE;CAkBjE"}
@@ -1,33 +1,28 @@
1
1
  const errors = {
2
- fieldLengthNotMatching: (expected, actual) => new Error(`Expected ${expected} field elements, got ${actual}`),
3
2
  typeNotCompatible: (name) => new Error(`Cannot decode type ${name}, it has to be either a Struct, CircuitValue or built-in snarkyjs type`),
4
3
  };
5
4
  export class MethodParameterDecoder {
6
5
  static fromMethod(target, methodName) {
6
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
7
7
  const paramtypes = Reflect.getMetadata("design:paramtypes", target, methodName);
8
8
  return new MethodParameterDecoder(paramtypes);
9
9
  }
10
10
  constructor(types) {
11
11
  this.types = types;
12
12
  }
13
- fromFields(fields) {
14
- if (fields.length < this.fieldSize) {
15
- throw errors.fieldLengthNotMatching(this.fieldSize, fields.length);
16
- }
17
- let stack = fields.slice();
18
- return this.types.map((type) => {
19
- const numberFieldsNeeded = type.prototype._fields?.length ?? type.sizeInFields?.() ?? -1;
20
- if (numberFieldsNeeded === -1) {
21
- throw errors.typeNotCompatible(type.name);
13
+ fromJSON(argsJSON) {
14
+ return this.types.map((type, index) => {
15
+ // eslint-disable-next-line @typescript-eslint/init-declarations
16
+ let value;
17
+ try {
18
+ // eslint-disable-next-line max-len
19
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
20
+ value = type.fromJSON(JSON.parse(argsJSON[index]));
22
21
  }
23
- const structFields = stack.slice(0, numberFieldsNeeded);
24
- stack = stack.slice(numberFieldsNeeded);
25
- return type.fromFields(structFields);
22
+ catch {
23
+ throw errors.typeNotCompatible(type.constructor.name);
24
+ }
25
+ return value;
26
26
  });
27
27
  }
28
- get fieldSize() {
29
- return this.types
30
- .map((type) => type.prototype._fields?.length ?? type.sizeInFields?.() ?? 0)
31
- .reduce((a, b) => a + b, 0);
32
- }
33
28
  }
@@ -1,7 +1,7 @@
1
1
  import { StateTransition, MethodPublicOutput } from "@proto-kit/protocol";
2
2
  import { ToFieldable } from "@proto-kit/common";
3
3
  import type { RuntimeModule } from "../runtime/RuntimeModule.js";
4
- export declare function toStateTransitionsHash(stateTransitions: StateTransition<any>[]): import("snarkyjs/dist/node/lib/field.js").Field;
4
+ export declare function toStateTransitionsHash(stateTransitions: StateTransition<any>[]): import("o1js/dist/node/lib/field.js").Field;
5
5
  export type WrappedMethod = (...args: unknown[]) => MethodPublicOutput;
6
6
  export declare function toWrappedMethod(this: RuntimeModule<unknown>, methodName: string, moduleMethod: (...args: unknown[]) => unknown, methodArguments: ToFieldable[]): WrappedMethod;
7
7
  export declare function combineMethodName(runtimeModuleName: string, methodName: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"runtimeMethod.d.ts","sourceRoot":"","sources":["../../src/method/runtimeMethod.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EAGf,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,aAAa,EAAE,M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AC,EAC5B,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAC7C,eAAe,EAAE,WAAW,EAAE,iBA0F/B;AAED,wBAAgB,iBAAiB,CAC/B,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,UAGnB;AAED,eAAO,MAAM,wBAAwB,eAAe,CAAC;AACrD,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAC9B,WAAW,EAAE,MAAM,WAKpB;AAED,wBAAgB,aAAa,aAEjB,cAAc,OAAO,CAAC,cAClB,MAAM,cACN,kBAAkB,UAwFjC"}
@@ -1,4 +1,4 @@
1
- import { Field, Poseidon } from "snarkyjs";
1
+ import { Field, Poseidon, Proof } from "o1js";
2
2
  import { container } from "tsyringe";
3
3
  import { DefaultProvableHashList, ProvableStateTransition, MethodPublicOutput, RuntimeMethodExecutionContext, } from "@proto-kit/protocol";
4
4
  import { toProver, } from "@proto-kit/common";
@@ -34,18 +34,28 @@ export function toWrappedMethod(methodName, moduleMethod, methodArguments) {
34
34
  throw errors.runtimeNotProvided(name);
35
35
  }
36
36
  // Assert that the given transaction has the correct methodId
37
- const methodIdResolver = runtime.dependencyContainer.resolve("MethodIdResolver");
37
+ const { methodIdResolver } = runtime;
38
38
  const thisMethodId = Field(methodIdResolver.getMethodId(name, methodName));
39
39
  if (!thisMethodId.isConstant()) {
40
40
  throw errors.fieldNotConstant("methodId");
41
41
  }
42
42
  input.transaction.methodId.assertEquals(thisMethodId, "Runtimemethod called with wrong methodId on the transaction object");
43
- const paramTypes = Reflect.getMetadata("design:paramtypes", this, methodName);
43
+ const parameterTypes = Reflect.getMetadata("design:paramtypes", this, methodName);
44
44
  /**
45
45
  * Use the type info obtained previously to convert
46
46
  * the args passed to fields
47
47
  */
48
- const argsFields = args.flatMap((arg, index) => paramTypes[index].toFields(arg));
48
+ const argsFields = args.flatMap((argument, index) => {
49
+ if (argument instanceof Proof) {
50
+ return [
51
+ ...argument.publicInput?.toFields(),
52
+ ...argument.publicOutput?.toFields(),
53
+ ];
54
+ }
55
+ else {
56
+ return parameterTypes[index].toFields(argument);
57
+ }
58
+ });
49
59
  // Assert that the argsHash that has been signed matches the given arguments
50
60
  // We can use js-if here, because methodArguments is statically sizes
51
61
  // i.e. the result of the if-statement will be the same for all executions
@@ -1,5 +1,5 @@
1
1
  import { stringToField } from "@proto-kit/protocol";
2
- import { Poseidon } from "snarkyjs";
2
+ import { Poseidon } from "o1js";
3
3
  /**
4
4
  * Please see `getMethodId` to learn more about
5
5
  * methodId encoding
@@ -1,8 +1,10 @@
1
- import { Experimental } from "snarkyjs";
1
+ import { Experimental } from "o1js";
2
2
  import { DependencyContainer } from "tsyringe";
3
- import { StringKeyOf, ModuleContainer, ModulesConfig, ModulesRecord, TypedClass, ZkProgrammable, PlainZkProgram, WithZkProgrammable, AreProofsEnabled } from "@proto-kit/common";
3
+ import { StringKeyOf, ModuleContainer, ModulesConfig, ModulesRecord, TypedClass, ZkProgrammable, PlainZkProgram, AreProofsEnabled, ChildContainerProvider } from "@proto-kit/common";
4
4
  import { MethodPublicOutput, StateServiceProvider, StateService } from "@proto-kit/protocol";
5
5
  import { RuntimeModule } from "./RuntimeModule";
6
+ import { MethodIdResolver } from "./MethodIdResolver";
7
+ import { RuntimeEnvironment } from "./RuntimeEnvironment";
6
8
  /**
7
9
  * Record of modules accepted by the Runtime module container.
8
10
  *
@@ -31,8 +33,8 @@ export declare class RuntimeZkProgrammable<Modules extends RuntimeModulesRecord>
31
33
  * Wrapper for an application specific runtime, which helps orchestrate
32
34
  * runtime modules into an interoperable runtime.
33
35
  */
34
- export declare class Runtime<Modules extends RuntimeModulesRecord> extends ModuleContainer<Modules> implements WithZkProgrammable<undefined, MethodPublicOutput> {
35
- static from<Modules extends RuntimeModulesRecord>(definition: RuntimeDefinition<Modules>): Runtime<Modules>;
36
+ export declare class Runtime<Modules extends RuntimeModulesRecord> extends ModuleContainer<Modules> implements RuntimeEnvironment {
37
+ static from<Modules extends RuntimeModulesRecord>(definition: RuntimeDefinition<Modules>): TypedClass<Runtime<Modules>>;
36
38
  program?: ReturnType<typeof Experimental.ZkProgram>;
37
39
  definition: RuntimeDefinition<Modules>;
38
40
  zkProgrammable: ZkProgrammable<undefined, MethodPublicOutput>;
@@ -43,10 +45,11 @@ export declare class Runtime<Modules extends RuntimeModulesRecord> extends Modul
43
45
  * @param modules - Configuration object for the constructed Runtime
44
46
  */
45
47
  constructor(definition: RuntimeDefinition<Modules>);
46
- start(): void;
48
+ create(childContainerProvider: ChildContainerProvider): void;
47
49
  get appChain(): AreProofsEnabled | undefined;
48
50
  get stateService(): StateService;
49
51
  get stateServiceProvider(): StateServiceProvider;
52
+ get methodIdResolver(): MethodIdResolver;
50
53
  /**
51
54
  * @returns The dependency injection container of this runtime
52
55
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/Runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAc,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACb,MAAM,qBAAqB,CAAC;AAU7B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAC9C,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CACnC,CAAC;AAOF;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,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AC,OAAO,CAAC,CAAC,CAAC;IAQ9D;;OAEG;IACH,IAAW,kBAAkB,aAE5B;CACF"}
@@ -10,9 +10,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  var Runtime_1;
11
11
  // eslint-disable-next-line max-len
12
12
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,max-lines */
13
- import { Experimental } from "snarkyjs";
13
+ import { Experimental } from "o1js";
14
14
  import { injectable } from "tsyringe";
15
- import { ModuleContainer, ZkProgrammable, } from "@proto-kit/common";
15
+ import { ModuleContainer, ZkProgrammable } from "@proto-kit/common";
16
16
  import { MethodPublicOutput, StateServiceProvider, } from "@proto-kit/protocol";
17
17
  import { combineMethodName, isRuntimeMethod, toWrappedMethod, } from "../method/runtimeMethod";
18
18
  import { MethodIdFactory } from "../factories/MethodIdFactory";
@@ -97,7 +97,11 @@ export class RuntimeZkProgrammable extends ZkProgrammable {
97
97
  */
98
98
  let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
99
99
  static from(definition) {
100
- return new Runtime_1(definition);
100
+ return class RuntimeScoped extends Runtime_1 {
101
+ constructor() {
102
+ super(definition);
103
+ }
104
+ };
101
105
  }
102
106
  /**
103
107
  * Creates a new Runtime from the provided config
@@ -114,14 +118,12 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
114
118
  }
115
119
  // eslint-disable-next-line no-warning-comments
116
120
  // TODO Remove after changing DFs to type-based approach
117
- start() {
118
- this.registerValue({
119
- Runtime: this,
120
- });
121
+ create(childContainerProvider) {
122
+ super.create(childContainerProvider);
121
123
  this.registerDependencyFactories([MethodIdFactory]);
122
124
  }
123
125
  get appChain() {
124
- return this.container.resolve("AppChain");
126
+ return this.container.resolve("AreProofsEnabled");
125
127
  }
126
128
  get stateService() {
127
129
  return this.stateServiceProviderInstance.stateService;
@@ -129,6 +131,9 @@ let Runtime = Runtime_1 = class Runtime extends ModuleContainer {
129
131
  get stateServiceProvider() {
130
132
  return this.stateServiceProviderInstance;
131
133
  }
134
+ get methodIdResolver() {
135
+ return this.container.resolve("MethodIdResolver");
136
+ }
132
137
  /**
133
138
  * @returns The dependency injection container of this runtime
134
139
  */
@@ -0,0 +1,10 @@
1
+ import { AreProofsEnabled, WithZkProgrammable } from "@proto-kit/common";
2
+ import { MethodPublicOutput, StateService, StateServiceProvider } from "@proto-kit/protocol";
3
+ import { MethodIdResolver } from "./MethodIdResolver";
4
+ export interface RuntimeEnvironment extends WithZkProgrammable<undefined, MethodPublicOutput> {
5
+ get appChain(): AreProofsEnabled | undefined;
6
+ get stateService(): StateService;
7
+ get stateServiceProvider(): StateServiceProvider;
8
+ get methodIdResolver(): MethodIdResolver;
9
+ }
10
+ //# sourceMappingURL=RuntimeEnvironment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RuntimeEnvironment.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeEnvironment.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAEnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,WAAW,kBACf,SAAQ,kBAAkB,CAAC,SAAS,EAAE,kBAAkB,CAAC;IACzD,IAAI,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAAC;IAC7C,IAAI,YAAY,IAAI,YAAY,CAAC;IACjC,IAAI,oBAAoB,IAAI,oBAAoB,CAAC;IACjD,IAAI,gBAAgB,IAAI,gBAAgB,CAAC;CAC1C"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { ConfigurableModule, Presets } from "@proto-kit/common";
2
2
  import { NetworkState, RuntimeTransaction, StateService } from "@proto-kit/protocol";
3
3
  import type { Runtime, RuntimeDefinition, RuntimeModulesRecord } from "./Runtime";
4
+ import { RuntimeEnvironment } from "./RuntimeEnvironment";
4
5
  /**
5
6
  * This type exists to carry over certain runtime properties
6
7
  * to runtime modules, until we can inject them through DI.
@@ -25,7 +26,7 @@ export declare class RuntimeModule<Config> extends ConfigurableModule<Config> {
25
26
  */
26
27
  isRuntimeModule: boolean;
27
28
  name?: string;
28
- runtime?: Runtime<RuntimeModulesRecord>;
29
+ runtime?: RuntimeEnvironment;
29
30
  constructor();
30
31
  private getInputs;
31
32
  get transaction(): RuntimeTransaction;
@@ -1 +1 @@
1
- {"version":3,"file":"RuntimeModule.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,WAAW,CAAC;AAMnB;;;GAGG;AACH,MAAM,WAAW,cACf,SAAQ,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,gBAAgB,CAAC;IAC7D,UAAU,EAAE,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAC;IAEnE,IAAI,YAAY,IAAI,YAAY,CAAC;CAClC;AAED;;GAEG;AACH,qBACa,aAAa,CAAC,MAAM,CAAE,SAAQ,kBAAkB,CAAC,MAAM,CAAC;IACnE,OAAc,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAM;IAE7C;;OAEG;IACH,SAAgB,kBAAkB,EAAE,MAAM,EAAE,CAAM;IAElD;;;;OAIG;IACI,eAAe,UAAQ;IAEvB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;;IAY/C,OAAO,CAAC,SAAS;IAWjB,IAAW,WAAW,IAAI,kBAAkB,CAE3C;IAED,IAAW,OAAO,IAAI,YAAY,CAEjC;CACF"}
1
+ {"version":3,"file":"RuntimeModule.d.ts","sourceRoot":"","sources":["../../src/runtime/RuntimeModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAM1D;;;GAGG;AACH,MAAM,WAAW,cACf,SAAQ,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,gBAAgB,CAAC;IAC7D,UAAU,EAAE,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAC;IAEnE,IAAI,YAAY,IAAI,YAAY,CAAC;CAClC;AAED;;GAEG;AACH,qBACa,aAAa,CAAC,MAAM,CAAE,SAAQ,kBAAkB,CAAC,MAAM,CAAC;IACnE,OAAc,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAM;IAE7C;;OAEG;IACH,SAAgB,kBAAkB,EAAE,MAAM,EAAE,CAAM;IAElD;;;;OAIG;IACI,eAAe,UAAQ;IAEvB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,OAAO,CAAC,EAAE,kBAAkB,CAAC;;IAYpC,OAAO,CAAC,SAAS;IAWjB,IAAW,WAAW,IAAI,kBAAkB,CAE3C;IAED,IAAW,OAAO,IAAI,YAAY,CAEjC;CACF"}
@@ -1,4 +1,4 @@
1
- import { Field } from "snarkyjs";
1
+ import { Field } from "o1js";
2
2
  import { StateService } from "@proto-kit/protocol";
3
3
  /**
4
4
  * Naive implementation of a StateService for testing purposes
@@ -1 +1 @@
1
- {"version":3,"file":"InMemoryStateService.d.ts","sourceRoot":"","sources":["../../src/state/InMemoryStateService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;GAEG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IAChD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,CAAM;IAEjD,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,SAAS;IAIpC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS;CAWlD"}
1
+ {"version":3,"file":"InMemoryStateService.d.ts","sourceRoot":"","sources":["../../src/state/InMemoryStateService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;GAEG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IAChD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,CAAM;IAEjD,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,SAAS;IAIpC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS;CAWlD"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@proto-kit/module",
3
3
  "license": "MIT",
4
4
  "private": false,
5
- "version": "0.1.1-develop.263+f167699",
5
+ "version": "0.1.1-develop.298+188a8c8",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "tsc -p tsconfig.json",
@@ -28,8 +28,8 @@
28
28
  "peerDependencies": {
29
29
  "@proto-kit/common": "*",
30
30
  "@proto-kit/protocol": "*",
31
- "snarkyjs": "0.12.0",
31
+ "o1js": "0.13.1",
32
32
  "tsyringe": "^4.7.0"
33
33
  },
34
- "gitHead": "f167699bddb5831155c4aa9587b4da032c30db0d"
34
+ "gitHead": "188a8c85859be7432b5c196219589d559356171b"
35
35
  }
@@ -1,27 +1,9 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
- import { Field } from "snarkyjs";
2
+ import { FlexibleProvable, ProvableExtended } from "o1js";
3
3
 
4
4
  import { RuntimeModule } from "../runtime/RuntimeModule";
5
5
 
6
- export interface Fieldable {
7
- toFields: () => Field[];
8
- }
9
-
10
- export interface FromFieldClass {
11
- new: (...args: any[]) => any;
12
- fromFields: (fields: Field[]) => Fieldable;
13
- name: string;
14
- // Maybe this is wrong IDK
15
- prototype: {
16
- _fields?: any[];
17
- };
18
- sizeInFields?: () => number;
19
- }
20
-
21
6
  const errors = {
22
- fieldLengthNotMatching: (expected: number, actual: number) =>
23
- new Error(`Expected ${expected} field elements, got ${actual}`),
24
-
25
7
  typeNotCompatible: (name: string) =>
26
8
  new Error(
27
9
  `Cannot decode type ${name}, it has to be either a Struct, CircuitValue or built-in snarkyjs type`
@@ -30,7 +12,8 @@ const errors = {
30
12
 
31
13
  export class MethodParameterDecoder {
32
14
  public static fromMethod(target: RuntimeModule<unknown>, methodName: string) {
33
- const paramtypes = Reflect.getMetadata(
15
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
16
+ const paramtypes: ProvableExtended<unknown>[] = Reflect.getMetadata(
34
17
  "design:paramtypes",
35
18
  target,
36
19
  methodName
@@ -39,32 +22,24 @@ export class MethodParameterDecoder {
39
22
  return new MethodParameterDecoder(paramtypes);
40
23
  }
41
24
 
42
- private constructor(private readonly types: FromFieldClass[]) {}
43
-
44
- public fromFields(fields: Field[]): Fieldable[] {
45
- if (fields.length < this.fieldSize) {
46
- throw errors.fieldLengthNotMatching(this.fieldSize, fields.length);
47
- }
48
-
49
- let stack = fields.slice();
50
-
51
- return this.types.map((type) => {
52
- const numberFieldsNeeded =
53
- type.prototype._fields?.length ?? type.sizeInFields?.() ?? -1;
54
- if (numberFieldsNeeded === -1) {
55
- throw errors.typeNotCompatible(type.name);
25
+ private constructor(private readonly types: ProvableExtended<unknown>[]) {}
26
+
27
+ public fromJSON(argsJSON: string[]): FlexibleProvable<unknown>[] {
28
+ return this.types.map((type, index) => {
29
+ // eslint-disable-next-line @typescript-eslint/init-declarations
30
+ let value: FlexibleProvable<unknown>;
31
+
32
+ try {
33
+ // eslint-disable-next-line max-len
34
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
35
+ value = type.fromJSON(
36
+ JSON.parse(argsJSON[index])
37
+ ) as FlexibleProvable<unknown>;
38
+ } catch {
39
+ throw errors.typeNotCompatible(type.constructor.name);
56
40
  }
57
- const structFields = stack.slice(0, numberFieldsNeeded);
58
- stack = stack.slice(numberFieldsNeeded);
59
- return type.fromFields(structFields);
60
- });
61
- }
62
41
 
63
- public get fieldSize(): number {
64
- return this.types
65
- .map(
66
- (type) => type.prototype._fields?.length ?? type.sizeInFields?.() ?? 0
67
- )
68
- .reduce((a, b) => a + b, 0);
42
+ return value;
43
+ });
69
44
  }
70
45
  }
@@ -1,6 +1,6 @@
1
1
  import "reflect-metadata";
2
2
 
3
- import { Bool, Field } from "snarkyjs";
3
+ import { Bool, Field } from "o1js";
4
4
  import { Option, StateTransition } from "@proto-kit/protocol";
5
5
 
6
6
  import { toStateTransitionsHash } from "./runtimeMethod.js";
@@ -1,4 +1,4 @@
1
- import { Field, FlexibleProvable, Poseidon } from "snarkyjs";
1
+ import { Field, FlexibleProvable, Poseidon, Proof } from "o1js";
2
2
  import { container } from "tsyringe";
3
3
  import {
4
4
  StateTransition,
@@ -88,8 +88,7 @@ export function toWrappedMethod(
88
88
  }
89
89
 
90
90
  // Assert that the given transaction has the correct methodId
91
- const methodIdResolver =
92
- runtime.dependencyContainer.resolve<MethodIdResolver>("MethodIdResolver");
91
+ const { methodIdResolver } = runtime;
93
92
  const thisMethodId = Field(methodIdResolver.getMethodId(name, methodName));
94
93
  if (!thisMethodId.isConstant()) {
95
94
  throw errors.fieldNotConstant("methodId");
@@ -100,7 +99,7 @@ export function toWrappedMethod(
100
99
  "Runtimemethod called with wrong methodId on the transaction object"
101
100
  );
102
101
 
103
- const paramTypes: FlexibleProvable<unknown>[] = Reflect.getMetadata(
102
+ const parameterTypes: FlexibleProvable<unknown>[] = Reflect.getMetadata(
104
103
  "design:paramtypes",
105
104
  this,
106
105
  methodName
@@ -110,9 +109,16 @@ export function toWrappedMethod(
110
109
  * Use the type info obtained previously to convert
111
110
  * the args passed to fields
112
111
  */
113
- const argsFields = args.flatMap((arg, index) =>
114
- paramTypes[index].toFields(arg as any)
115
- );
112
+ const argsFields = args.flatMap((argument, index) => {
113
+ if (argument instanceof Proof) {
114
+ return [
115
+ ...argument.publicInput?.toFields(),
116
+ ...argument.publicOutput?.toFields(),
117
+ ];
118
+ } else {
119
+ return parameterTypes[index].toFields(argument as any);
120
+ }
121
+ });
116
122
 
117
123
  // Assert that the argsHash that has been signed matches the given arguments
118
124
  // We can use js-if here, because methodArguments is statically sizes
@@ -1,5 +1,5 @@
1
1
  import { stringToField } from "@proto-kit/protocol";
2
- import { Poseidon } from "snarkyjs";
2
+ import { Poseidon } from "o1js";
3
3
 
4
4
  import type { Runtime, RuntimeModulesRecord } from "./Runtime";
5
5
 
@@ -1,6 +1,6 @@
1
1
  // eslint-disable-next-line max-len
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,max-lines */
3
- import { Experimental } from "snarkyjs";
3
+ import { Experimental } from "o1js";
4
4
  import { DependencyContainer, injectable } from "tsyringe";
5
5
  import {
6
6
  StringKeyOf,
@@ -11,7 +11,7 @@ import {
11
11
  ZkProgrammable,
12
12
  PlainZkProgram,
13
13
  WithZkProgrammable,
14
- AreProofsEnabled,
14
+ AreProofsEnabled, ChildContainerProvider
15
15
  } from "@proto-kit/common";
16
16
  import {
17
17
  MethodPublicOutput,
@@ -29,6 +29,7 @@ import { MethodIdFactory } from "../factories/MethodIdFactory";
29
29
 
30
30
  import { RuntimeModule } from "./RuntimeModule";
31
31
  import { MethodIdResolver } from "./MethodIdResolver";
32
+ import { RuntimeEnvironment } from "./RuntimeEnvironment";
32
33
 
33
34
  /**
34
35
  * Record of modules accepted by the Runtime module container.
@@ -190,12 +191,16 @@ export class RuntimeZkProgrammable<
190
191
  @injectable()
191
192
  export class Runtime<Modules extends RuntimeModulesRecord>
192
193
  extends ModuleContainer<Modules>
193
- implements WithZkProgrammable<undefined, MethodPublicOutput>
194
+ implements RuntimeEnvironment
194
195
  {
195
196
  public static from<Modules extends RuntimeModulesRecord>(
196
197
  definition: RuntimeDefinition<Modules>
197
- ) {
198
- return new Runtime(definition);
198
+ ): TypedClass<Runtime<Modules>> {
199
+ return class RuntimeScoped extends Runtime<Modules> {
200
+ public constructor() {
201
+ super(definition);
202
+ }
203
+ };
199
204
  }
200
205
 
201
206
  // runtime modules composed into a ZkProgram
@@ -223,15 +228,14 @@ export class Runtime<Modules extends RuntimeModulesRecord>
223
228
 
224
229
  // eslint-disable-next-line no-warning-comments
225
230
  // TODO Remove after changing DFs to type-based approach
226
- public start() {
227
- this.registerValue({
228
- Runtime: this,
229
- });
231
+ public create(childContainerProvider: ChildContainerProvider) {
232
+ super.create(childContainerProvider);
233
+
230
234
  this.registerDependencyFactories([MethodIdFactory]);
231
235
  }
232
236
 
233
237
  public get appChain(): AreProofsEnabled | undefined {
234
- return this.container.resolve<AreProofsEnabled>("AppChain");
238
+ return this.container.resolve<AreProofsEnabled>("AreProofsEnabled");
235
239
  }
236
240
 
237
241
  public get stateService(): StateService {
@@ -242,6 +246,10 @@ export class Runtime<Modules extends RuntimeModulesRecord>
242
246
  return this.stateServiceProviderInstance;
243
247
  }
244
248
 
249
+ public get methodIdResolver(): MethodIdResolver {
250
+ return this.container.resolve<MethodIdResolver>("MethodIdResolver");
251
+ }
252
+
245
253
  /**
246
254
  * @returns The dependency injection container of this runtime
247
255
  */
@@ -0,0 +1,19 @@
1
+ import {
2
+ AreProofsEnabled,
3
+ WithZkProgrammable,
4
+ ZkProgrammable,
5
+ } from "@proto-kit/common";
6
+ import {
7
+ MethodPublicOutput,
8
+ StateService,
9
+ StateServiceProvider,
10
+ } from "@proto-kit/protocol";
11
+ import { MethodIdResolver } from "./MethodIdResolver";
12
+
13
+ export interface RuntimeEnvironment
14
+ extends WithZkProgrammable<undefined, MethodPublicOutput> {
15
+ get appChain(): AreProofsEnabled | undefined;
16
+ get stateService(): StateService;
17
+ get stateServiceProvider(): StateServiceProvider;
18
+ get methodIdResolver(): MethodIdResolver;
19
+ }
@@ -15,6 +15,7 @@ import type {
15
15
  RuntimeDefinition,
16
16
  RuntimeModulesRecord,
17
17
  } from "./Runtime";
18
+ import { RuntimeEnvironment } from "./RuntimeEnvironment";
18
19
 
19
20
  const errors = {
20
21
  inputDataNotSet: () => new Error("Input data for runtime execution not set"),
@@ -52,7 +53,7 @@ export class RuntimeModule<Config> extends ConfigurableModule<Config> {
52
53
 
53
54
  public name?: string;
54
55
 
55
- public runtime?: Runtime<RuntimeModulesRecord>;
56
+ public runtime?: RuntimeEnvironment;
56
57
 
57
58
  public constructor() {
58
59
  super();
@@ -1,4 +1,4 @@
1
- import { Field } from "snarkyjs";
1
+ import { Field } from "o1js";
2
2
  import { StateService } from "@proto-kit/protocol";
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { Bool } from "snarkyjs";
1
+ import { Bool } from "o1js";
2
2
 
3
3
  import { InMemoryStateService, MethodIdResolver, Runtime } from "../src";
4
4
 
@@ -32,10 +32,9 @@ describe("runtime", () => {
32
32
  const moduleName = "Balances";
33
33
  const methodName = "getTotalSupply";
34
34
 
35
- const methodId = runtime.dependencyContainer.resolve<MethodIdResolver>("MethodIdResolver").getMethodId(
36
- moduleName,
37
- methodName
38
- );
35
+ const methodId = runtime.dependencyContainer
36
+ .resolve<MethodIdResolver>("MethodIdResolver")
37
+ .getMethodId(moduleName, methodName);
39
38
  const method = runtime.getMethodById(methodId);
40
39
 
41
40
  // eslint-disable-next-line jest/no-restricted-matchers
@@ -1,4 +1,4 @@
1
- import { PublicKey } from "snarkyjs";
1
+ import { PublicKey } from "o1js";
2
2
 
3
3
  import { runtimeModule } from "../../src/module/decorator.js";
4
4
  import { RuntimeModule } from "../../src/runtime/RuntimeModule.js";
@@ -8,7 +8,7 @@ import {
8
8
  Proof,
9
9
  PublicKey,
10
10
  UInt64,
11
- } from "snarkyjs";
11
+ } from "o1js";
12
12
  import { container } from "tsyringe";
13
13
  import {
14
14
  type ProvableStateTransition,
@@ -60,7 +60,7 @@ describe("balances", () => {
60
60
  },
61
61
  });
62
62
 
63
- runtime.dependencyContainer.register("AppChain", {
63
+ runtime.dependencyContainer.register("AreProofsEnabled", {
64
64
  useValue: {
65
65
  areProofsEnabled: false,
66
66
 
@@ -1,4 +1,4 @@
1
- import { Bool, PublicKey, UInt64 } from "snarkyjs";
1
+ import { Bool, PublicKey, UInt64 } from "o1js";
2
2
  import { Option, State, StateMap } from "@proto-kit/protocol";
3
3
  import { Presets } from "@proto-kit/common";
4
4
 
@@ -1,18 +1,15 @@
1
1
  import "reflect-metadata";
2
- import { Bool, PublicKey, UInt64 } from "snarkyjs";
2
+ import { Bool, PublicKey, UInt64 } from "o1js";
3
3
  import { container } from "tsyringe";
4
4
  import {
5
5
  NetworkState,
6
6
  Option,
7
7
  RuntimeMethodExecutionContext,
8
8
  RuntimeTransaction,
9
- StateService
9
+ StateService,
10
10
  } from "@proto-kit/protocol";
11
11
 
12
- import {
13
- InMemoryStateService,
14
- Runtime
15
- } from "../../src";
12
+ import { InMemoryStateService, Runtime } from "../../src";
16
13
 
17
14
  import { Admin } from "./Admin";
18
15
  import { Balances } from "./Balances";
@@ -39,7 +36,7 @@ describe("transient state", () => {
39
36
  },
40
37
  });
41
38
 
42
- runtime.dependencyContainer.register("AppChain", {
39
+ runtime.dependencyContainer.register("AreProofsEnabled", {
43
40
  useValue: {
44
41
  areProofsEnabled: false,
45
42
 
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { Bool, Field } from "snarkyjs";
2
+ import { Bool, Field } from "o1js";
3
3
  import { beforeAll, beforeEach } from "@jest/globals";
4
4
 
5
5
  import { Runtime } from "../../src/runtime/Runtime";
@@ -56,21 +56,19 @@ describe("methodId", () => {
56
56
  ["Admin", "isAdminWithAVeryVeryVeryVeryLongName"],
57
57
  ["Balance", "getTotalSupply"],
58
58
  ["Balance", "getBalance"],
59
- ])(
60
- "should pass and encode correctly",
61
- (givenModuleName, givenMethodName) => {
62
- expect.assertions(2);
59
+ ])("should pass and encode correctly", (givenModuleName, givenMethodName) => {
60
+ expect.assertions(2);
63
61
 
64
- const methodId = resolver.getMethodId(givenModuleName, givenMethodName);
62
+ const methodId = resolver.getMethodId(givenModuleName, givenMethodName);
65
63
 
66
- const [moduleName, methodName] = resolver.getMethodNameFromId(
67
- methodId
68
- ) ?? [undefined, undefined];
64
+ const [moduleName, methodName] = resolver.getMethodNameFromId(methodId) ?? [
65
+ undefined,
66
+ undefined,
67
+ ];
69
68
 
70
- expect(moduleName).toBe(givenModuleName);
71
- expect(methodName).toBe(givenMethodName);
72
- }
73
- );
69
+ expect(moduleName).toBe(givenModuleName);
70
+ expect(methodName).toBe(givenMethodName);
71
+ });
74
72
 
75
73
  it("should fail for invalid module name", () => {
76
74
  expect.assertions(1);
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { Bool, Field, PublicKey, UInt64 } from "snarkyjs";
2
+ import { Bool, Field, PublicKey, UInt64 } from "o1js";
3
3
  import {
4
4
  NetworkState,
5
5
  RuntimeMethodExecutionContext,
@@ -5,7 +5,7 @@ import {
5
5
  } from "@proto-kit/protocol";
6
6
  import { MockAsyncMerkleTreeStore } from "./MockAsyncMerkleStore";
7
7
  import { beforeEach } from "@jest/globals";
8
- import { Field, Poseidon } from "snarkyjs";
8
+ import { Field, Poseidon } from "o1js";
9
9
  import { log } from "@proto-kit/common";
10
10
 
11
11
  describe("cachedMerkleTree", () => {
@@ -1,4 +1,5 @@
1
- import { AsyncMerkleTreeStore, InMemoryMerkleTreeStorage, noop } from "@proto-kit/protocol";
1
+ import { AsyncMerkleTreeStore, InMemoryMerkleTreeStorage } from "@proto-kit/protocol";
2
+ import { noop } from "@proto-kit/common";
2
3
 
3
4
  export class MockAsyncMerkleTreeStore implements AsyncMerkleTreeStore {
4
5
  public readonly store = new InMemoryMerkleTreeStorage();
@@ -11,18 +12,18 @@ export class MockAsyncMerkleTreeStore implements AsyncMerkleTreeStore {
11
12
  noop();
12
13
  }
13
14
 
14
- public async getNode(
15
+ public async getNodeAsync(
15
16
  key: bigint,
16
17
  level: number
17
18
  ): Promise<bigint | undefined> {
18
19
  return this.store.getNode(key, level);
19
20
  }
20
21
 
21
- public async setNode(
22
+ public async setNodeAsync(
22
23
  key: bigint,
23
24
  level: number,
24
25
  value: bigint
25
26
  ): Promise<void> {
26
27
  this.store.setNode(key, level, value);
27
28
  }
28
- }
29
+ }
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { PrivateKey, Proof, PublicKey, UInt64 } from "snarkyjs";
2
+ import { PrivateKey, Proof, PublicKey, UInt64 } from "o1js";
3
3
  import { container } from "tsyringe";
4
4
  import {
5
5
  InMemoryStateService,