@proto-kit/common 0.1.1-develop.456 → 0.1.1-develop.600

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.
@@ -73,7 +73,7 @@ export declare class ModuleContainer<Modules extends ModulesRecord> extends Conf
73
73
  * otherwise it may be just string e.g. when modules are iterated over
74
74
  * using e.g. a for loop.
75
75
  */
76
- assertIsValidModuleName(modules: Modules, moduleName: string): asserts moduleName is StringKeyOf<Modules>;
76
+ assertIsValidModuleName(moduleName: string): asserts moduleName is StringKeyOf<Modules>;
77
77
  isValidModuleName(modules: Modules, moduleName: number | string | symbol): moduleName is StringKeyOf<Modules>;
78
78
  assertContainerInitialized(container: DependencyContainer | undefined): asserts container is DependencyContainer;
79
79
  /**
@@ -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,0BAA0B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAMpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AA2ChE,eAAO,MAAM,qBAAqB;0CAtCM,MAAM;uCAKT,YAAY,OAAO,CAAC;yCAOlB,eAAe,OAAO,CAAC;6CAInB,MAAM;2CAIR,MAAM,QAAQ,MAAM;2CAOpB,MAAM;sCAKX,MAAM,kBAAkB,MAAM;CAMvB,CAAC;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AC;IAQxE,IAAW,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAK/C;IAED;;;;;;;;;OASG;IACI,OAAO,CAAC,OAAO,SAAS,WAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,EACpE,UAAU,EAAE,OAAO,GAClB,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;IAM7C,aAAa,CAAC,UAAU,EAC7B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC;IAYpC;;;OAGG;IACH,SAAS,CAAC,cAAc,CACtB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAChC,eAAe,EAAE,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAkB9D,OAAO,CAAC,mBAAmB;IAI3B;;;OAGG;IACH,SAAS,CAAC,6BAA6B,CAAC,SAAS,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE;IAMzE;;;;;;;OAOG;IACH,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,iBAAiB;IAuCzD;;;OAGG;IACH,SAAS,CAAC,uBAAuB,CAAC,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC;IAwBlE;;;;OAIG;IACI,MAAM,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,IAAI;CAUpE"}
@@ -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";
@@ -73,8 +73,8 @@ export class ModuleContainer extends ConfigurableModule {
73
73
  * otherwise it may be just string e.g. when modules are iterated over
74
74
  * using e.g. a for loop.
75
75
  */
76
- assertIsValidModuleName(modules, moduleName) {
77
- if (!this.isValidModuleName(modules, moduleName)) {
76
+ assertIsValidModuleName(moduleName) {
77
+ if (!this.isValidModuleName(this.definition.modules, moduleName)) {
78
78
  throw errors.onlyValidModuleNames(moduleName);
79
79
  }
80
80
  }
@@ -96,7 +96,7 @@ export class ModuleContainer extends ConfigurableModule {
96
96
  registerModules(modules) {
97
97
  for (const moduleName in modules) {
98
98
  if (Object.prototype.hasOwnProperty.call(modules, moduleName)) {
99
- this.assertIsValidModuleName(modules, moduleName);
99
+ this.assertIsValidModuleName(moduleName);
100
100
  log.debug(`Registering module: ${moduleName}`);
101
101
  const useClass = modules[moduleName];
102
102
  this.container.register(moduleName, { useClass }, { lifecycle: Lifecycle.ContainerScoped });
@@ -226,6 +226,11 @@ export class ModuleContainer extends ConfigurableModule {
226
226
  lifecycle: Lifecycle.Singleton,
227
227
  });
228
228
  }
229
+ else if (isTokenProvider(declaration)) {
230
+ this.container.register(key, declaration, {
231
+ lifecycle: Lifecycle.Singleton,
232
+ });
233
+ }
229
234
  else {
230
235
  // Can never be reached
231
236
  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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,MAAM,MAAM,aAAa,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAC5D,GAAG,SAAS,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AAE7C,MAAM,MAAM,0BAA0B,CAAC,MAAM,SAAS,gBAAgB,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"}
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,mBA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AKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;IAE7C;;;OAGG;IACH,OAAO,IAAI,KAAK,CAAC;IAEjB;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IAE1C;;;;;;OAMG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,qBAAqB,CAAC;IAEjD;;;OAGG;IACH,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,KAAK,EAAE,eAAe,GAAG,kBAAkB,CAAC;IAEjD,OAAO,EAAE,UAAU,CAAC,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,9 @@ 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;
17
23
  //# 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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AO,CAAC,IAC5D,mBAAmB,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;AAE1C,MAAM,MAAM,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI;KAClC,GAAG,IAAI,MAAM,MAAM,IAAI,GAAG,SAAS,IAAI,GAAG,KAAK,GAAG,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;CACrE,CAAC;AAMF,eAAO,MAAM,iBAAiB,0CAAc,CAAC;AAC7C,eAAO,MAAM,eAAe,WAG1B,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,CAA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AAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,KAAK,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/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"}
@@ -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,GAAG,WAAW,CAAC;AACnF,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.456+bdb345d",
6
+ "version": "0.1.1-develop.600+699a7df",
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": "bdb345d9e6132387a870c8a4236d8fe295502ce4"
33
+ "gitHead": "699a7dfa3b5d3415ab4500f0cd495d6781365c6a"
34
34
  }
@@ -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) =>
@@ -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
 
@@ -415,6 +407,10 @@ export class ModuleContainer<
415
407
  this.container.register(key, declaration, {
416
408
  lifecycle: Lifecycle.Singleton,
417
409
  });
410
+ } else if (isTokenProvider(declaration)) {
411
+ this.container.register(key, declaration, {
412
+ lifecycle: Lifecycle.Singleton,
413
+ });
418
414
  } else {
419
415
  // Can never be reached
420
416
  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> =
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,17 @@ 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
+ });
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"),
@@ -1,12 +1,12 @@
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>> & ToFieldable;
9
+ export type ArgumentTypes = (O1JSPrimitive | Proof<unknown, unknown>)[];
10
10
 
11
11
  // eslint-disable-next-line etc/prefer-interface
12
12
  export type DecoratedMethod = (...args: ArgumentTypes) => unknown;