@proto-kit/common 0.1.1-develop.457 → 0.1.1-develop.651

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 (44) hide show
  1. package/dist/config/ConfigurableModule.d.ts +1 -1
  2. package/dist/config/ConfigurableModule.d.ts.map +1 -1
  3. package/dist/config/ModuleContainer.d.ts +5 -1
  4. package/dist/config/ModuleContainer.d.ts.map +1 -1
  5. package/dist/config/ModuleContainer.js +13 -9
  6. package/dist/dependencyFactory/DependencyFactory.d.ts +5 -4
  7. package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
  8. package/dist/dependencyFactory/injectOptional.d.ts +16 -0
  9. package/dist/dependencyFactory/injectOptional.d.ts.map +1 -0
  10. package/dist/dependencyFactory/injectOptional.js +42 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -0
  14. package/dist/log.d.ts.map +1 -1
  15. package/dist/log.js +6 -2
  16. package/dist/trees/RollupMerkleTree.d.ts +4 -2
  17. package/dist/trees/RollupMerkleTree.d.ts.map +1 -1
  18. package/dist/trees/RollupMerkleTree.js +7 -1
  19. package/dist/types.d.ts +9 -0
  20. package/dist/types.d.ts.map +1 -1
  21. package/dist/types.js +11 -1
  22. package/dist/utils.d.ts +4 -0
  23. package/dist/utils.d.ts.map +1 -1
  24. package/dist/utils.js +20 -1
  25. package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +1 -1
  26. package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -1
  27. package/dist/zkProgrammable/ZkProgrammable.d.ts +1 -0
  28. package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
  29. package/dist/zkProgrammable/provableMethod.d.ts +3 -3
  30. package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
  31. package/package.json +2 -2
  32. package/src/config/ConfigurableModule.ts +1 -1
  33. package/src/config/ModuleContainer.ts +15 -17
  34. package/src/dependencyFactory/DependencyFactory.ts +12 -3
  35. package/src/dependencyFactory/injectOptional.ts +42 -0
  36. package/src/index.ts +1 -0
  37. package/src/log.ts +6 -2
  38. package/src/trees/RollupMerkleTree.ts +11 -3
  39. package/src/types.ts +20 -0
  40. package/src/utils.ts +28 -1
  41. package/src/zkProgrammable/ProvableMethodExecutionContext.ts +1 -2
  42. package/src/zkProgrammable/ZkProgrammable.ts +1 -0
  43. package/src/zkProgrammable/provableMethod.ts +4 -3
  44. package/test/config/ContainerEvents.test.ts +2 -2
@@ -5,7 +5,7 @@ export type Presets<Config> = Record<string, Preset<Config>>;
5
5
  export interface Configurable<Config> {
6
6
  config: Config;
7
7
  }
8
- export type NoConfig = Record<string, never>;
8
+ export type NoConfig = Record<never, never>;
9
9
  /**
10
10
  * Used by various module sub-types that may need to be configured
11
11
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigurableModule.d.ts","sourceRoot":"","sources":["../../src/config/ConfigurableModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAUhE,MAAM,MAAM,MAAM,CAAC,MAAM,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,CAAC;AACnE,MAAM,MAAM,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAG7D,MAAM,WAAW,YAAY,CAAC,MAAM;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE7C;;GAEG;AACH,qBAAa,kBAAkB,CAAC,MAAM,GAAG,QAAQ,CAC/C,YAAW,sBAAsB;IAEjC;;;OAGG;IACH,SAAS,CAAC,aAAa,EAAE,MAAM,G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6 +32,9 @@ export type RecursivePartial<T> = {
32
32
  */
33
33
  export interface ModuleContainerDefinition<Modules extends ModulesRecord> {
34
34
  modules: Modules;
35
+ /**
36
+ * @deprecated
37
+ */
35
38
  config?: ModulesConfig<Modules>;
36
39
  }
37
40
  export type FilterNeverValues<Type extends Record<string, unknown>> = {
@@ -73,7 +76,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
73
76
  * otherwise it may be just string e.g. when modules are iterated over
74
77
  * using e.g. a for loop.
75
78
  */
76
- assertIsValidModuleName(modules: Modules, moduleName: string): asserts moduleName is StringKeyOf<Modules>;
79
+ assertIsValidModuleName(moduleName: string): asserts moduleName is StringKeyOf<Modules>;
77
80
  isValidModuleName(modules: Modules, moduleName: number | string | symbol): moduleName is StringKeyOf<Modules>;
78
81
  assertContainerInitialized(container: DependencyContainer | undefined): asserts container is DependencyContainer;
79
82
  /**
@@ -101,6 +104,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
101
104
  */
102
105
  configure(config: ModulesConfig<Modules>): void;
103
106
  configurePartial(config: RecursivePartial<ModulesConfig<Modules>>): void;
107
+ get config(): ModulesConfig<Modules>;
104
108
  set config(config: ModulesConfig<Modules>);
105
109
  /**
106
110
  * Resolves a module from the current module container
@@ -1 +1 @@
1
- {"version":3,"file":"ModuleContainer.d.ts","sourceRoot":"","sources":["../../src/config/ModuleContainer.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EACL,mBAAmB,EAGnB,cAAc,EAMf,MAAM,UAAU,CAAC;AAIlB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0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"}
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable max-lines */
2
2
  import "reflect-metadata";
3
- import { instancePerContainerCachingFactory, isClassProvider, isFactoryProvider, isValueProvider, Lifecycle, } from "tsyringe";
3
+ import { instancePerContainerCachingFactory, isClassProvider, isFactoryProvider, isTokenProvider, isValueProvider, Lifecycle, } from "tsyringe";
4
4
  import log from "loglevel";
5
5
  import merge from "lodash/merge";
6
6
  import { ConfigurableModule, } from "./ConfigurableModule";
@@ -34,9 +34,6 @@ export class ModuleContainer extends ConfigurableModule {
34
34
  // DI container holding all the registered modules
35
35
  this.providedContainer = undefined;
36
36
  this.eventEmitterProxy = undefined;
37
- if (definition.config !== undefined) {
38
- this.config = definition.config;
39
- }
40
37
  }
41
38
  /**
42
39
  * @returns list of module names
@@ -73,8 +70,8 @@ export class ModuleContainer extends ConfigurableModule {
73
70
  * otherwise it may be just string e.g. when modules are iterated over
74
71
  * using e.g. a for loop.
75
72
  */
76
- assertIsValidModuleName(modules, moduleName) {
77
- if (!this.isValidModuleName(modules, moduleName)) {
73
+ assertIsValidModuleName(moduleName) {
74
+ if (!this.isValidModuleName(this.definition.modules, moduleName)) {
78
75
  throw errors.onlyValidModuleNames(moduleName);
79
76
  }
80
77
  }
@@ -96,7 +93,7 @@ export class ModuleContainer extends ConfigurableModule {
96
93
  registerModules(modules) {
97
94
  for (const moduleName in modules) {
98
95
  if (Object.prototype.hasOwnProperty.call(modules, moduleName)) {
99
- this.assertIsValidModuleName(modules, moduleName);
96
+ this.assertIsValidModuleName(moduleName);
100
97
  log.debug(`Registering module: ${moduleName}`);
101
98
  const useClass = modules[moduleName];
102
99
  this.container.register(moduleName, { useClass }, { lifecycle: Lifecycle.ContainerScoped });
@@ -140,6 +137,9 @@ export class ModuleContainer extends ConfigurableModule {
140
137
  configurePartial(config) {
141
138
  this.config = merge(this.currentConfig ?? {}, config);
142
139
  }
140
+ get config() {
141
+ return super.config;
142
+ }
143
143
  // eslint-disable-next-line accessor-pairs
144
144
  set config(config) {
145
145
  super.config = merge(this.currentConfig ?? {}, config);
@@ -170,8 +170,7 @@ export class ModuleContainer extends ConfigurableModule {
170
170
  * features or module checks
171
171
  */
172
172
  decorateModule(moduleName, containedModule) {
173
- // Has to be super.config, getters behave really weird when subtyping
174
- const config = super.config?.[moduleName];
173
+ const config = this.config?.[moduleName];
175
174
  // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
176
175
  if (!config) {
177
176
  throw errors.configNotSetInContainer(moduleName.toString());
@@ -226,6 +225,11 @@ export class ModuleContainer extends ConfigurableModule {
226
225
  lifecycle: Lifecycle.Singleton,
227
226
  });
228
227
  }
228
+ else if (isTokenProvider(declaration)) {
229
+ this.container.register(key, declaration, {
230
+ lifecycle: Lifecycle.Singleton,
231
+ });
232
+ }
229
233
  else {
230
234
  // Can never be reached
231
235
  throw new Error("Above if-statement is exhaustive");
@@ -1,7 +1,7 @@
1
- import { ClassProvider, FactoryProvider, ValueProvider } from "tsyringe";
1
+ import { ClassProvider, FactoryProvider, TokenProvider, ValueProvider } from "tsyringe";
2
2
  import { TypedClass } from "../types";
3
- import { BaseModuleInstanceType } from "../config/ModuleContainer";
4
- export type DependencyDeclaration<Dependency> = ClassProvider<Dependency> | FactoryProvider<Dependency> | ValueProvider<Dependency>;
3
+ import type { BaseModuleInstanceType } from "../config/ModuleContainer";
4
+ export type DependencyDeclaration<Dependency> = ClassProvider<Dependency> | FactoryProvider<Dependency> | TokenProvider<Dependency> | ValueProvider<Dependency>;
5
5
  export type DependencyRecord = Record<string, DependencyDeclaration<unknown> & {
6
6
  forceOverwrite?: boolean;
7
7
  }>;
@@ -21,8 +21,9 @@ export interface DependencyFactory {
21
21
  dependencies: () => DependencyRecord;
22
22
  }
23
23
  export type TypeFromDependencyDeclaration<Declaration extends DependencyDeclaration<unknown>> = Declaration extends DependencyDeclaration<infer Dependency> ? Dependency : never;
24
+ export type CapitalizeAny<Key extends string | number | symbol> = Key extends string ? Capitalize<Key> : Key;
24
25
  export type MapDependencyRecordToTypes<Record extends DependencyRecord> = {
25
- [Key in keyof Record]: TypedClass<TypeFromDependencyDeclaration<Record[Key]>>;
26
+ [Key in keyof Record as CapitalizeAny<Key>]: TypedClass<TypeFromDependencyDeclaration<Record[Key]>>;
26
27
  };
27
28
  export type InferDependencies<Class extends BaseModuleInstanceType> = Class extends DependencyFactory ? MapDependencyRecordToTypes<ReturnType<Class["dependencies"]>> : never;
28
29
  //# sourceMappingURL=DependencyFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DependencyFactory.d.ts","sourceRoot":"","sources":["../../src/dependencyFactory/DependencyFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACd,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,MAAM,MAAM,qBAAqB,CAAC,UAAU,IACxC,aAAa,CAAC,UAAU,CAAC,GACzB,eAAe,CAAC,UAAU,CAAC,GAC3B,aAAa,CAAC,UAAU,CAAC,CAAC;AAE9B,MAAM,MAAM,gBAAgB,GAAG,MAAM,CACnC,MAAM,EACN,qBAAqB,CAAC,OAAO,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,CAC9D,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,gBAAgB,CAAC;CACtC;AAED,MAAM,MAAM,6BAA6B,CACvC,WAAW,SAAS,qBAAqB,CAAC,OAAO,CAAC,IAChD,WAAW,SAAS,qBAAqB,CAAC,MAAM,UAAU,CAAC,GAAG,UAAU,GAAG,KAAK,CAAC;AAErF,MAAM,MAAM,0BAA0B,CAAC,MAAM,SAAS,gBAAgB,IAAI;KACvE,GAAG,IAAI,MAAM,MAAM,GAAG,UAAU,CAAC,6BAA6B,CAAC,MAAM,CAAC,GAAG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,IAAI;KACvE,GAAG,IAAI,MAAM,MAAM,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,UAAU,CACrD,6BAA6B,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAC3C;CACF,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,sBAAsB,IAChE,KAAK,SAAS,iBAAiB,GAC3B,0BAA0B,CAAC,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,GAC7D,KAAK,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * This function injects a dependency only if it has been registered, otherwise
3
+ * injects undefined. This can be useful for having optional dependencies, where
4
+ * tsyringe would normally error out and not be able to resolve. With this
5
+ * decorator, we can now do this.
6
+ *
7
+ * The strategy we employ here is that we inject a dummy into the global
8
+ * container that is of type UndefinedDisguise. We can't inject undefined
9
+ * directly, therefore we use this object to disguise itself as undefined.
10
+ * Then a child container registers something under the same token, it by
11
+ * default resolves that new dependency. If that doesn't happen, the
12
+ * resolution hits our disguise, which we then convert into undefined
13
+ * using the Transform
14
+ */
15
+ export declare function injectOptional<T>(token: string): (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => any;
16
+ //# sourceMappingURL=injectOptional.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectOptional.d.ts","sourceRoot":"","sources":["../../src/dependencyFactory/injectOptional.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,0FAG9C"}
@@ -0,0 +1,42 @@
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
+ import { container, injectable, injectWithTransform, Lifecycle, scoped, } from "tsyringe";
8
+ let UndefinedDisguise =
9
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class
10
+ class UndefinedDisguise {
11
+ };
12
+ UndefinedDisguise = __decorate([
13
+ injectable(),
14
+ scoped(Lifecycle.ResolutionScoped)
15
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class
16
+ ], UndefinedDisguise);
17
+ class UndefinedTransform {
18
+ transform(incoming) {
19
+ if (incoming instanceof UndefinedDisguise) {
20
+ return undefined;
21
+ }
22
+ return incoming;
23
+ }
24
+ }
25
+ /**
26
+ * This function injects a dependency only if it has been registered, otherwise
27
+ * injects undefined. This can be useful for having optional dependencies, where
28
+ * tsyringe would normally error out and not be able to resolve. With this
29
+ * decorator, we can now do this.
30
+ *
31
+ * The strategy we employ here is that we inject a dummy into the global
32
+ * container that is of type UndefinedDisguise. We can't inject undefined
33
+ * directly, therefore we use this object to disguise itself as undefined.
34
+ * Then a child container registers something under the same token, it by
35
+ * default resolves that new dependency. If that doesn't happen, the
36
+ * resolution hits our disguise, which we then convert into undefined
37
+ * using the Transform
38
+ */
39
+ export function injectOptional(token) {
40
+ container.register(token, { useClass: UndefinedDisguise });
41
+ return injectWithTransform(token, (UndefinedTransform));
42
+ }
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from "./zkProgrammable/ProvableMethodExecutionContext";
8
8
  export * from "./zkProgrammable/provableMethod";
9
9
  export * from "./utils";
10
10
  export * from "./dependencyFactory/DependencyFactory";
11
+ export * from "./dependencyFactory/injectOptional";
11
12
  export * from "./log";
12
13
  export * from "./events/EventEmittingComponent";
13
14
  export * from "./events/EventEmitter";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,OAAO,CAAC;AACtB,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,oCAAoC,CAAC;AACnD,cAAc,OAAO,CAAC;AACtB,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC"}
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ export * from "./zkProgrammable/ProvableMethodExecutionContext";
8
8
  export * from "./zkProgrammable/provableMethod";
9
9
  export * from "./utils";
10
10
  export * from "./dependencyFactory/DependencyFactory";
11
+ export * from "./dependencyFactory/injectOptional";
11
12
  export * from "./log";
12
13
  export * from "./events/EventEmittingComponent";
13
14
  export * from "./events/EventEmitter";
package/dist/log.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,EAAE,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAyBlD,eAAO,MAAM,GAAG;;wBAEI,OAAO,EAAE;yBAIR,OAAO,EAAE;yBAIT,OAAO,EAAE;yBAIT,OAAO,EAAE;wBAIV,OAAO,EAAE;;oBAKX,OAAO,EAAE;qBAIR,OAAO,EAAE;qBAIT,OAAO,EAAE;qBAIT,OAAO,EAAE;oBAIV,OAAO,EAAE;sBAIP,YAAY;;;CAS/B,CAAC"}
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,EAAE,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAyBlD,eAAO,MAAM,GAAG;;wBAEI,OAAO,EAAE;yBAIR,OAAO,EAAE;yBAIT,OAAO,EAAE;yBAIT,OAAO,EAAE;wBAIV,OAAO,EAAE;;oBAKX,OAAO,EAAE;qBAIR,OAAO,EAAE;qBAIT,OAAO,EAAE;qBAIT,OAAO,EAAE;oBAQV,OAAO,EAAE;sBAIP,YAAY;;;CAS/B,CAAC"}
package/dist/log.js CHANGED
@@ -33,7 +33,7 @@ export const log = {
33
33
  logProvable(loglevel.error, ...args);
34
34
  },
35
35
  trace: (...args) => {
36
- logProvable(loglevel.trace, ...args);
36
+ logProvable(log.trace, ...args);
37
37
  },
38
38
  warn: (...args) => {
39
39
  logProvable(loglevel.warn, ...args);
@@ -49,7 +49,11 @@ export const log = {
49
49
  loglevel.error(...args);
50
50
  },
51
51
  trace: (...args) => {
52
- loglevel.trace(...args);
52
+ // Loglevel prints the stack trace by default. To still be able to use trace
53
+ // inside out application, we use the level, but call debug() under the hood
54
+ if (loglevel.getLevel() <= loglevel.levels.TRACE) {
55
+ loglevel.debug(...args);
56
+ }
53
57
  },
54
58
  warn: (...args) => {
55
59
  loglevel.warn(...args);
@@ -91,8 +91,10 @@ export interface AbstractMerkleTree {
91
91
  fill(leaves: Field[]): void;
92
92
  }
93
93
  export interface AbstractMerkleTreeClass {
94
- new (...args: any[]): AbstractMerkleTree;
95
- WITNESS: TypedClass<AbstractMerkleWitness> & typeof StructTemplate;
94
+ new (store: MerkleTreeStore): AbstractMerkleTree;
95
+ WITNESS: TypedClass<AbstractMerkleWitness> & typeof StructTemplate & {
96
+ dummy: () => AbstractMerkleWitness;
97
+ };
96
98
  HEIGHT: number;
97
99
  EMPTY_ROOT: bigint;
98
100
  get leafCount(): bigint;
@@ -1 +1 @@
1
- {"version":3,"file":"RollupMerkleTree.d.ts","sourceRoot":"","sources":["../../src/trees/RollupMerkleTree.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,KAAK,EAA8B,MAAM,MAAM,CAAC;AAG/D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGpD,cAAM,cAAe,SAAQ,mBAG3B;CAAG;AAEL,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,MAAM,IAAI,MAAM,CAAC;IAEjB;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC;IAElC;;;OAGG;IACH,cAAc,IAAI,KAAK,CAAC;IAExB,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAE7D,uBAAuB,CACrB,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,GACX,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAExB,kBAAkB,IAAI,MAAM,EAAE,CAAC;CAChC;AAED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qBAAqB,CAAC,GACxC,OAAO,cAAc,GAAG;QAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;KAAE,CAAC;IAEjE,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,SAAS,IAAI,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,uBAAuB,CAmOxE;;AAED,qBAAa,gBAAiB,SAAQ,qBAAqB;CAAG;AAC9D,qBAAa,uBAAwB,SAAQ,gBAAgB,CAAC,OAAO;CAAG"}
@@ -95,6 +95,12 @@ export function createMerkleTree(height) {
95
95
  this.isLeft[index].toString(),
96
96
  ].toString());
97
97
  }
98
+ static dummy() {
99
+ return new RollupMerkleWitness({
100
+ isLeft: Array(height - 1).fill(Bool(false)),
101
+ path: Array(height - 1).fill(Field(0)),
102
+ });
103
+ }
98
104
  }
99
105
  RollupMerkleWitness.height = height;
100
106
  return _a = class AbstractRollupMerkleTree {
@@ -129,7 +135,7 @@ export function createMerkleTree(height) {
129
135
  * @returns The root of the Merkle Tree.
130
136
  */
131
137
  getRoot() {
132
- return this.getNode(AbstractRollupMerkleTree.HEIGHT - 1, 0n);
138
+ return this.getNode(AbstractRollupMerkleTree.HEIGHT - 1, 0n).toConstant();
133
139
  }
134
140
  // private in interface
135
141
  setNode(level, index, value) {
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { PublicKey } from "o1js";
1
2
  export type TypedClass<Class> = new (...args: any[]) => Class;
2
3
  export type UnTypedClass = new (...args: any[]) => any;
3
4
  /**
@@ -14,4 +15,12 @@ export type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType exten
14
15
  */
15
16
  export type UnionToIntersection<Union> = (Union extends any ? (x: Union) => void : never) extends (x: infer Intersection) => void ? Intersection : never;
16
17
  export type MergeObjects<Input extends Record<string, unknown>> = UnionToIntersection<Input[keyof Input]>;
18
+ export type OmitKeys<Record, Keys> = {
19
+ [Key in keyof Record as Key extends Keys ? never : Key]: Record[Key];
20
+ };
21
+ export declare const EMPTY_PUBLICKEY_X: import("o1js/dist/node/lib/field").Field;
22
+ export declare const EMPTY_PUBLICKEY: PublicKey;
23
+ export type OverwriteObjectType<Base, New> = {
24
+ [Key in keyof Base]: Key extends keyof New ? New[Key] : Base[Key];
25
+ } & New;
17
26
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,UAAU,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC,GAC5E,MAAM,CAAC;AAGT;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,SAAS,OAAO,EAAE,IAE3D,SAAS,SAAS,SAAS,CAAC,MAAM,WAAW,CAAC,EAAE,GAAG,WAAW,GAAG,KAAK,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,CACvC,KAAK,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,GAAG,KAAK,CAC/C,SAAS,CAAC,CAAC,EAAE,MAAM,YAAY,KAAK,IAAI,GACrC,YAAY,GACZ,KAAK,CAAC;AAEV,MAAM,MAAM,YAAY,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC5D,mBAAmB,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources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IAAI,MAAM,IAAI,GAAG,GAAG,SAAS,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;CAClE,GAAG,GAAG,CAAC"}
package/dist/types.js CHANGED
@@ -1 +1,11 @@
1
- export {};
1
+ // allows to reference interfaces as 'classes' rather than instances
2
+ import { Bool, Field, PublicKey } from "o1js";
3
+ // Because Publickey.empty() is not usable in combination with real
4
+ // cryptographic operations because it's group evaluation isn't defined in Fp,
5
+ // we use some other arbitrary point which we treat as "empty" in our circuits
6
+ // other arbitrary point
7
+ export const EMPTY_PUBLICKEY_X = Field(4600);
8
+ export const EMPTY_PUBLICKEY = PublicKey.fromObject({
9
+ x: EMPTY_PUBLICKEY_X,
10
+ isOdd: Bool(true),
11
+ });
package/dist/utils.d.ts CHANGED
@@ -23,4 +23,8 @@ export interface ProofTypes {
23
23
  publicInputType?: ToFieldableStatic;
24
24
  }
25
25
  export declare function sleep(ms: number): Promise<void>;
26
+ export declare function filterNonNull<Type>(value: Type | null): value is Type;
27
+ export declare function filterNonUndefined<Type>(value: Type | undefined): value is Type;
28
+ export declare function prefixToField(prefix: string): Field;
29
+ export declare function hashWithPrefix(prefix: string, input: Field[]): import("o1js/dist/node/lib/field").Field;
26
30
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAEnD,wBAAgB,WAAW,CACzB,SAAS,EAAE,OAAO,EAClB,eAAe,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GACrC,IAAI,CAMN;AAED,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAS3E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAC9B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B,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,GAAG,CAAC;CACjC;AAED,MAAM,WAAW,UAAU;IACzB,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACrC;AAED,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,iBAGrC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,GAAG,KAAK,IAAI,IAAI,CAErE;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EACrC,KAAK,EAAE,IAAI,GAAG,SAAS,GACtB,KAAK,IAAI,IAAI,CAEf;AAKD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAOnD;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,4CAG5D"}
package/dist/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Field } from "o1js";
1
+ import { Field, Poseidon } from "o1js";
2
2
  export function requireTrue(condition, errorOrFunction) {
3
3
  if (!condition) {
4
4
  throw typeof errorOrFunction === "function"
@@ -31,3 +31,22 @@ export async function sleep(ms) {
31
31
  // eslint-disable-next-line promise/avoid-new,no-promise-executor-return
32
32
  await new Promise((resolve) => setTimeout(resolve, ms));
33
33
  }
34
+ export function filterNonNull(value) {
35
+ return value !== null;
36
+ }
37
+ export function filterNonUndefined(value) {
38
+ return value !== undefined;
39
+ }
40
+ let encoder = new TextEncoder();
41
+ // Copied from o1js binable.ts:317
42
+ export function prefixToField(prefix) {
43
+ let fieldSize = Field.sizeInBytes();
44
+ if (prefix.length >= fieldSize)
45
+ throw Error("prefix too long");
46
+ let stringBytes = [...encoder.encode(prefix)];
47
+ return Field.fromBytes(stringBytes.concat(Array(fieldSize - stringBytes.length).fill(0)));
48
+ }
49
+ export function hashWithPrefix(prefix, input) {
50
+ const salt = Poseidon.update([Field(0), Field(0), Field(0)], [prefixToField(prefix)]);
51
+ return Poseidon.update(salt, input)[0];
52
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Proof } from "o1js";
2
- import { ArgumentTypes } from "./provableMethod";
2
+ import type { ArgumentTypes } from "./provableMethod";
3
3
  export declare class ProvableMethodExecutionResult {
4
4
  moduleName?: string;
5
5
  methodName?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ProvableMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ProvableMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,MAAM,CAAC;AAKpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAWjD,qBAAa,6BAA6B;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,IAAI,CAAC,EAAE,aAAa,CAAC;IAErB,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAE1C,KAAK,CAEhB,SAAS,SAAS,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KACtC,OAAO,CAAC,SAAS,CAAC;CAaxB;AAED;;;;GAIG;AACH,qBACa,8BAA8B;IAClC,EAAE,SAAc;IAEhB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEvB,MAAM,EAAE,6BAA6B,CACN;IAItC;;;;;;OAMG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAI/D;;;;;OAKG;IACI,YAAY,CACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,aAAa;IAYrB;;;;OAIG;IACI,WAAW;IAIlB,IAAW,UAAU,YAEpB;IAED,IAAW,UAAU,YAEpB;IAED;;OAEG;IACI,OAAO;;;;IAOd;;OAEG;IACI,KAAK;CAGb"}
1
+ {"version":3,"file":"ProvableMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ProvableMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,MAAM,CAAC;AAIpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAWtD,qBAAa,6BAA6B;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,IAAI,CAAC,EAAE,aAAa,CAAC;IAErB,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAE1C,KAAK,CAEhB,SAAS,SAAS,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KACtC,OAAO,CAAC,SAAS,CAAC;CAaxB;AAED;;;;GAIG;AACH,qBACa,8BAA8B;IAClC,EAAE,SAAc;IAEhB,OAAO,EAAE,MAAM,EAAE,CAAM;IAEvB,MAAM,EAAE,6BAA6B,CACN;IAItC;;;;;;OAMG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAI/D;;;;;OAKG;IACI,YAAY,CACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,aAAa;IAYrB;;;;OAIG;IACI,WAAW;IAIlB,IAAW,UAAU,YAEpB;IAED,IAAW,UAAU,YAEpB;IAED;;OAEG;IACI,OAAO;;;;IAOd;;OAEG;IACI,KAAK;CAGb"}
@@ -17,6 +17,7 @@ export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
17
17
  verify: Verify<PublicInput, PublicOutput>;
18
18
  Proof: ReturnType<typeof Experimental.ZkProgram.Proof<FlexibleProvablePure<PublicInput>, FlexibleProvablePure<PublicOutput>>>;
19
19
  methods: Record<string, ((...args: any) => Promise<Proof<PublicInput, PublicOutput>>) | ((publicInput: PublicInput, ...args: any) => Promise<Proof<PublicInput, PublicOutput>>)>;
20
+ analyzeMethods: ReturnType<typeof Experimental.ZkProgram>["analyzeMethods"];
20
21
  }
21
22
  export declare function verifyToMockable<PublicInput, PublicOutput>(verify: Verify<PublicInput, PublicOutput>, { areProofsEnabled }: AreProofsEnabled): (proof: Proof<PublicInput, PublicOutput>) => Promise<boolean>;
22
23
  export declare const MOCK_VERIFICATION_KEY = "mock-verification-key";
@@ -1 +1 @@
1
- {"version":3,"file":"ZkProgrammable.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAUjE,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD;AAED,MAAM,WAAW,MAAM,CAAC,WAAW,EAAE,YAAY;IAC/C,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,YAAY,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc,CAAC,WAAW,GAAG,SAAS,EAAE,YAAY,GAAG,IAAI;IAC1E,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAC1C,KAAK,EAAE,UAAU,CACf,OAAO,YAAY,CAAC,SAAS,CAAC,KAAK,CACjC,oBAAoB,CAAC,WAAW,CAAC,EACjC,oBAAoB,CAAC,YAAY,CAAC,CACnC,CACF,CAAC;IACF,OAAO,EAAE,M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,YAAY,CAAC,sBAiBtD;AAED,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAE7D,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,EAAE,gBAAgB,EAAE,EAAE,gBAAgB,GACrC,MAAM,OAAO,CAAC,eAAe,CAAC,CAUhC;AAED,8BAAsB,cAAc,CAClC,WAAW,GAAG,SAAS,EACvB,YAAY,GAAG,IAAI;IAEnB,aAAoB,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAAC;aAE7C,gBAAgB,IAAI,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC;IAE7E,IACW,SAAS,IAAI,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAYhE;CACF;AAED,MAAM,WAAW,kBAAkB,CACjC,WAAW,GAAG,SAAS,EACvB,YAAY,GAAG,IAAI;IAEnB,cAAc,EAAE,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;CAC3D"}
@@ -1,9 +1,9 @@
1
- import { Proof, ProvableExtended } from "o1js";
1
+ import { InferProvable, Proof, ProvableExtended } from "o1js";
2
2
  import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext";
3
3
  import type { WithZkProgrammable, ZkProgrammable } from "./ZkProgrammable";
4
4
  import { ToFieldable } from "../utils";
5
- export type O1JSPrimitive = ProvableExtended<unknown> & ToFieldable;
6
- export type ArgumentTypes = O1JSPrimitive[] | Proof<unknown, unknown>[];
5
+ export type O1JSPrimitive = InferProvable<ProvableExtended<unknown>> & ToFieldable;
6
+ export type ArgumentTypes = (O1JSPrimitive | Proof<unknown, unknown>)[];
7
7
  export type DecoratedMethod = (...args: ArgumentTypes) => unknown;
8
8
  export declare const MOCK_PROOF = "mock-proof";
9
9
  export declare function toProver(methodName: string, simulatedMethod: DecoratedMethod, isFirstParameterPublicInput: boolean, ...args: ArgumentTypes): (this: ZkProgrammable<any, any>) => Promise<Proof<any, any>>;
@@ -1 +1 @@
1
- {"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAGjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC;AACpE,MAAM,MAAM,aAAa,GAAG,aAAa,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;AAGxE,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC;AAElE,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,EAChC,2BAA2B,EAAE,OAAO,EACpC,GAAG,IAAI,EAAE,aAAa,UAGa,eAAe,GAAG,EAAE,GAAG,CAAC,8BAyB5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,2BAA2B,UAAO,EAClC,gBAAgB,GAAE,8BAEjB,wGAOa,MAAM,cACN,kBAAkB,wBA4CjC"}
1
+ {"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAGhF,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,aAAa,GAAG,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAClE,WAAW,CAAC;AACd,MAAM,MAAM,aAAa,GAAG,CAAC,aAAa,GAAG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;AAGxE,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC;AAElE,eAAO,MAAM,UAAU,eAAe,CAAC;AAEvC,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,EAChC,2BAA2B,EAAE,OAAO,EACpC,GAAG,IAAI,EAAE,aAAa,UAGa,eAAe,GAAG,EAAE,GAAG,CAAC,8BAyB5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,2BAA2B,UAAO,EAClC,gBAAgB,GAAE,8BAEjB,wGAOa,MAAM,cACN,kBAAkB,wBA4CjC"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "license": "MIT",
4
4
  "private": false,
5
5
  "type": "module",
6
- "version": "0.1.1-develop.457+467a974",
6
+ "version": "0.1.1-develop.651+7591cb6",
7
7
  "scripts": {
8
8
  "build": "tsc -p tsconfig.json",
9
9
  "dev": "tsc -p tsconfig.json --watch",
@@ -30,5 +30,5 @@
30
30
  "@jest/globals": "^29.5.0",
31
31
  "@types/lodash": "^4.14.194"
32
32
  },
33
- "gitHead": "467a974c8dddb9f57ecf37caf34d3e1e5eb33f2a"
33
+ "gitHead": "7591cb6bdf58a6cd525a10902c25bc292efcfc6b"
34
34
  }
@@ -19,7 +19,7 @@ export interface Configurable<Config> {
19
19
  config: Config;
20
20
  }
21
21
 
22
- export type NoConfig = Record<string, never>;
22
+ export type NoConfig = Record<never, never>;
23
23
 
24
24
  /**
25
25
  * Used by various module sub-types that may need to be configured
@@ -4,11 +4,11 @@ import "reflect-metadata";
4
4
  import {
5
5
  DependencyContainer,
6
6
  Frequency,
7
- injectable,
8
7
  InjectionToken,
9
8
  instancePerContainerCachingFactory,
10
9
  isClassProvider,
11
10
  isFactoryProvider,
11
+ isTokenProvider,
12
12
  isValueProvider,
13
13
  Lifecycle,
14
14
  } from "tsyringe";
@@ -28,14 +28,7 @@ import {
28
28
  } from "./ConfigurableModule";
29
29
  import { ChildContainerProvider } from "./ChildContainerProvider";
30
30
  import { ChildContainerCreatable } from "./ChildContainerCreatable";
31
- import { EventEmitter } from "../events/EventEmitter";
32
- import {
33
- EventEmittingComponent,
34
- EventsRecord,
35
- } from "../events/EventEmittingComponent";
36
31
  import { EventEmitterProxy } from "../events/EventEmitterProxy";
37
- import { memoize } from "lodash";
38
- import { Memoize } from "typescript-memoize";
39
32
 
40
33
  const errors = {
41
34
  configNotSetInContainer: (moduleName: string) =>
@@ -115,6 +108,9 @@ export type RecursivePartial<T> = {
115
108
  export interface ModuleContainerDefinition<Modules extends ModulesRecord> {
116
109
  modules: Modules;
117
110
  // config is optional, as it may be provided by the parent/wrapper class
111
+ /**
112
+ * @deprecated
113
+ */
118
114
  config?: ModulesConfig<Modules>;
119
115
  }
120
116
 
@@ -155,9 +151,6 @@ export class ModuleContainer<
155
151
 
156
152
  public constructor(public definition: ModuleContainerDefinition<Modules>) {
157
153
  super();
158
- if (definition.config !== undefined) {
159
- this.config = definition.config;
160
- }
161
154
  }
162
155
 
163
156
  /**
@@ -207,10 +200,9 @@ export class ModuleContainer<
207
200
  * using e.g. a for loop.
208
201
  */
209
202
  public assertIsValidModuleName(
210
- modules: Modules,
211
203
  moduleName: string
212
204
  ): asserts moduleName is StringKeyOf<Modules> {
213
- if (!this.isValidModuleName(modules, moduleName)) {
205
+ if (!this.isValidModuleName(this.definition.modules, moduleName)) {
214
206
  throw errors.onlyValidModuleNames(moduleName);
215
207
  }
216
208
  }
@@ -240,7 +232,7 @@ export class ModuleContainer<
240
232
  protected registerModules(modules: Modules) {
241
233
  for (const moduleName in modules) {
242
234
  if (Object.prototype.hasOwnProperty.call(modules, moduleName)) {
243
- this.assertIsValidModuleName(modules, moduleName);
235
+ this.assertIsValidModuleName(moduleName);
244
236
 
245
237
  log.debug(`Registering module: ${moduleName}`);
246
238
 
@@ -304,6 +296,10 @@ export class ModuleContainer<
304
296
  >(this.currentConfig ?? {}, config);
305
297
  }
306
298
 
299
+ public get config() {
300
+ return super.config;
301
+ }
302
+
307
303
  // eslint-disable-next-line accessor-pairs
308
304
  public set config(config: ModulesConfig<Modules>) {
309
305
  super.config = merge<
@@ -352,9 +348,7 @@ export class ModuleContainer<
352
348
  moduleName: StringKeyOf<Modules>,
353
349
  containedModule: InstanceType<Modules[StringKeyOf<Modules>]>
354
350
  ) {
355
- // Has to be super.config, getters behave really weird when subtyping
356
- const config = super.config?.[moduleName];
357
-
351
+ const config = this.config?.[moduleName];
358
352
  // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
359
353
  if (!config) {
360
354
  throw errors.configNotSetInContainer(moduleName.toString());
@@ -415,6 +409,10 @@ export class ModuleContainer<
415
409
  this.container.register(key, declaration, {
416
410
  lifecycle: Lifecycle.Singleton,
417
411
  });
412
+ } else if (isTokenProvider(declaration)) {
413
+ this.container.register(key, declaration, {
414
+ lifecycle: Lifecycle.Singleton,
415
+ });
418
416
  } else {
419
417
  // Can never be reached
420
418
  throw new Error("Above if-statement is exhaustive");
@@ -1,15 +1,17 @@
1
1
  import {
2
2
  ClassProvider,
3
3
  FactoryProvider,
4
+ TokenProvider,
4
5
  ValueProvider,
5
6
  } from "tsyringe";
6
7
 
7
8
  import { TypedClass } from "../types";
8
- import { BaseModuleInstanceType } from "../config/ModuleContainer";
9
+ import type { BaseModuleInstanceType } from "../config/ModuleContainer";
9
10
 
10
11
  export type DependencyDeclaration<Dependency> =
11
12
  | ClassProvider<Dependency>
12
13
  | FactoryProvider<Dependency>
14
+ | TokenProvider<Dependency>
13
15
  | ValueProvider<Dependency>;
14
16
 
15
17
  export type DependencyRecord = Record<
@@ -35,10 +37,17 @@ export interface DependencyFactory {
35
37
 
36
38
  export type TypeFromDependencyDeclaration<
37
39
  Declaration extends DependencyDeclaration<unknown>
38
- > = Declaration extends DependencyDeclaration<infer Dependency> ? Dependency : never;
40
+ > = Declaration extends DependencyDeclaration<infer Dependency>
41
+ ? Dependency
42
+ : never;
43
+
44
+ export type CapitalizeAny<Key extends string | number | symbol> =
45
+ Key extends string ? Capitalize<Key> : Key;
39
46
 
40
47
  export type MapDependencyRecordToTypes<Record extends DependencyRecord> = {
41
- [Key in keyof Record]: TypedClass<TypeFromDependencyDeclaration<Record[Key]>>;
48
+ [Key in keyof Record as CapitalizeAny<Key>]: TypedClass<
49
+ TypeFromDependencyDeclaration<Record[Key]>
50
+ >;
42
51
  };
43
52
 
44
53
  export type InferDependencies<Class extends BaseModuleInstanceType> =
@@ -0,0 +1,42 @@
1
+ import {
2
+ container,
3
+ injectable,
4
+ injectWithTransform,
5
+ Lifecycle,
6
+ scoped,
7
+ } from "tsyringe";
8
+
9
+ @injectable()
10
+ @scoped(Lifecycle.ResolutionScoped)
11
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class
12
+ class UndefinedDisguise {}
13
+
14
+ class UndefinedTransform<Dependency> {
15
+ public transform(
16
+ incoming: Dependency | UndefinedDisguise
17
+ ): Dependency | undefined {
18
+ if (incoming instanceof UndefinedDisguise) {
19
+ return undefined;
20
+ }
21
+ return incoming;
22
+ }
23
+ }
24
+
25
+ /**
26
+ * This function injects a dependency only if it has been registered, otherwise
27
+ * injects undefined. This can be useful for having optional dependencies, where
28
+ * tsyringe would normally error out and not be able to resolve. With this
29
+ * decorator, we can now do this.
30
+ *
31
+ * The strategy we employ here is that we inject a dummy into the global
32
+ * container that is of type UndefinedDisguise. We can't inject undefined
33
+ * directly, therefore we use this object to disguise itself as undefined.
34
+ * Then a child container registers something under the same token, it by
35
+ * default resolves that new dependency. If that doesn't happen, the
36
+ * resolution hits our disguise, which we then convert into undefined
37
+ * using the Transform
38
+ */
39
+ export function injectOptional<T>(token: string) {
40
+ container.register(token, { useClass: UndefinedDisguise });
41
+ return injectWithTransform(token, UndefinedTransform<T>);
42
+ }
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ export * from "./zkProgrammable/ProvableMethodExecutionContext";
8
8
  export * from "./zkProgrammable/provableMethod";
9
9
  export * from "./utils";
10
10
  export * from "./dependencyFactory/DependencyFactory";
11
+ export * from "./dependencyFactory/injectOptional";
11
12
  export * from "./log";
12
13
  export * from "./events/EventEmittingComponent";
13
14
  export * from "./events/EventEmitter";
package/src/log.ts CHANGED
@@ -39,7 +39,7 @@ export const log = {
39
39
  },
40
40
 
41
41
  trace: (...args: unknown[]) => {
42
- logProvable(loglevel.trace, ...args);
42
+ logProvable(log.trace, ...args);
43
43
  },
44
44
 
45
45
  warn: (...args: unknown[]) => {
@@ -60,7 +60,11 @@ export const log = {
60
60
  },
61
61
 
62
62
  trace: (...args: unknown[]) => {
63
- loglevel.trace(...args);
63
+ // Loglevel prints the stack trace by default. To still be able to use trace
64
+ // inside out application, we use the level, but call debug() under the hood
65
+ if (loglevel.getLevel() <= loglevel.levels.TRACE) {
66
+ loglevel.debug(...args);
67
+ }
64
68
  },
65
69
 
66
70
  warn: (...args: unknown[]) => {
@@ -87,9 +87,10 @@ export interface AbstractMerkleTree {
87
87
  }
88
88
 
89
89
  export interface AbstractMerkleTreeClass {
90
- new (...args: any[]): AbstractMerkleTree;
90
+ new (store: MerkleTreeStore): AbstractMerkleTree;
91
91
 
92
- WITNESS: TypedClass<AbstractMerkleWitness> & typeof StructTemplate;
92
+ WITNESS: TypedClass<AbstractMerkleWitness> &
93
+ typeof StructTemplate & { dummy: () => AbstractMerkleWitness };
93
94
 
94
95
  HEIGHT: number;
95
96
 
@@ -205,6 +206,13 @@ export function createMerkleTree(height: number): AbstractMerkleTreeClass {
205
206
  ].toString()
206
207
  );
207
208
  }
209
+
210
+ public static dummy() {
211
+ return new RollupMerkleWitness({
212
+ isLeft: Array<Bool>(height - 1).fill(Bool(false)),
213
+ path: Array<Field>(height - 1).fill(Field(0)),
214
+ });
215
+ }
208
216
  }
209
217
 
210
218
  return class AbstractRollupMerkleTree implements AbstractMerkleTree {
@@ -260,7 +268,7 @@ export function createMerkleTree(height: number): AbstractMerkleTreeClass {
260
268
  * @returns The root of the Merkle Tree.
261
269
  */
262
270
  public getRoot(): Field {
263
- return this.getNode(AbstractRollupMerkleTree.HEIGHT - 1, 0n);
271
+ return this.getNode(AbstractRollupMerkleTree.HEIGHT - 1, 0n).toConstant();
264
272
  }
265
273
 
266
274
  // private in interface
package/src/types.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  // allows to reference interfaces as 'classes' rather than instances
2
+ import { Bool, Field, Group, PublicKey } from "o1js";
3
+
2
4
  export type TypedClass<Class> = new (...args: any[]) => Class;
3
5
 
4
6
  export type UnTypedClass = new (...args: any[]) => any;
@@ -29,3 +31,21 @@ export type UnionToIntersection<Union> = (
29
31
 
30
32
  export type MergeObjects<Input extends Record<string, unknown>> =
31
33
  UnionToIntersection<Input[keyof Input]>;
34
+
35
+ export type OmitKeys<Record, Keys> = {
36
+ [Key in keyof Record as Key extends Keys ? never : Key]: Record[Key];
37
+ };
38
+
39
+ // Because Publickey.empty() is not usable in combination with real
40
+ // cryptographic operations because it's group evaluation isn't defined in Fp,
41
+ // we use some other arbitrary point which we treat as "empty" in our circuits
42
+ // other arbitrary point
43
+ export const EMPTY_PUBLICKEY_X = Field(4600);
44
+ export const EMPTY_PUBLICKEY = PublicKey.fromObject({
45
+ x: EMPTY_PUBLICKEY_X,
46
+ isOdd: Bool(true),
47
+ });
48
+
49
+ export type OverwriteObjectType<Base, New> = {
50
+ [Key in keyof Base]: Key extends keyof New ? New[Key] : Base[Key];
51
+ } & New;
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Field, FlexibleProvablePure } from "o1js";
1
+ import { Field, FlexibleProvablePure, Poseidon } from "o1js";
2
2
 
3
3
  export function requireTrue(
4
4
  condition: boolean,
@@ -62,3 +62,30 @@ export async function sleep(ms: number) {
62
62
  // eslint-disable-next-line promise/avoid-new,no-promise-executor-return
63
63
  await new Promise((resolve) => setTimeout(resolve, ms));
64
64
  }
65
+
66
+ export function filterNonNull<Type>(value: Type | null): value is Type {
67
+ return value !== null;
68
+ }
69
+
70
+ export function filterNonUndefined<Type>(
71
+ value: Type | undefined
72
+ ): value is Type {
73
+ return value !== undefined;
74
+ }
75
+
76
+ let encoder = new TextEncoder();
77
+
78
+ // Copied from o1js binable.ts:317
79
+ export function prefixToField(prefix: string): Field {
80
+ let fieldSize = Field.sizeInBytes();
81
+ if (prefix.length >= fieldSize) throw Error("prefix too long");
82
+ let stringBytes = [...encoder.encode(prefix)];
83
+ return Field.fromBytes(
84
+ stringBytes.concat(Array(fieldSize - stringBytes.length).fill(0))
85
+ );
86
+ }
87
+
88
+ export function hashWithPrefix(prefix: string, input: Field[]) {
89
+ const salt = Poseidon.update([Field(0), Field(0), Field(0)], [prefixToField(prefix)])
90
+ return Poseidon.update(salt as [Field, Field, Field], input)[0]
91
+ }
@@ -2,8 +2,7 @@ import type { FlexibleProvable, Proof } from "o1js";
2
2
  import { singleton } from "tsyringe";
3
3
  import uniqueId from "lodash/uniqueId";
4
4
 
5
- import { ToFieldable } from "../utils";
6
- import { ArgumentTypes } from "./provableMethod";
5
+ import type { ArgumentTypes } from "./provableMethod";
7
6
 
8
7
  const errors = {
9
8
  moduleOrMethodNameNotSet: () => new Error("Module or method name not set"),
@@ -46,6 +46,7 @@ export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
46
46
  ...args: any
47
47
  ) => Promise<Proof<PublicInput, PublicOutput>>)
48
48
  >;
49
+ analyzeMethods: ReturnType<typeof Experimental.ZkProgram>["analyzeMethods"];
49
50
  }
50
51
 
51
52
  export function verifyToMockable<PublicInput, PublicOutput>(
@@ -1,12 +1,13 @@
1
- import { FlexibleProvable, Proof, ProvableExtended } from "o1js";
1
+ import { FlexibleProvable, InferProvable, Proof, ProvableExtended } from "o1js";
2
2
  import { container } from "tsyringe";
3
3
 
4
4
  import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext";
5
5
  import type { WithZkProgrammable, ZkProgrammable } from "./ZkProgrammable";
6
6
  import { ToFieldable } from "../utils";
7
7
 
8
- export type O1JSPrimitive = ProvableExtended<unknown> & ToFieldable;
9
- export type ArgumentTypes = O1JSPrimitive[] | Proof<unknown, unknown>[];
8
+ export type O1JSPrimitive = InferProvable<ProvableExtended<unknown>> &
9
+ ToFieldable;
10
+ export type ArgumentTypes = (O1JSPrimitive | Proof<unknown, unknown>)[];
10
11
 
11
12
  // eslint-disable-next-line etc/prefer-interface
12
13
  export type DecoratedMethod = (...args: ArgumentTypes) => unknown;
@@ -22,7 +22,7 @@ class TestContainer<
22
22
  Modules extends ModulesRecord
23
23
  > extends ModuleContainer<Modules> {}
24
24
 
25
- interface TestEvents extends EventsRecord {
25
+ type TestEvents = {
26
26
  test: [string];
27
27
  }
28
28
 
@@ -34,7 +34,7 @@ class TestModule
34
34
  events = new EventEmitter<TestEvents>();
35
35
  }
36
36
 
37
- interface TestEvents2 extends EventsRecord {
37
+ type TestEvents2 = {
38
38
  test2: [number];
39
39
  }
40
40