@proto-kit/common 0.1.1-develop.651 → 0.1.1-develop.833
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.
- package/LICENSE.md +201 -201
- package/dist/config/ChildContainerFactory.d.ts +10 -0
- package/dist/config/ChildContainerFactory.d.ts.map +1 -0
- package/dist/config/ChildContainerFactory.js +23 -0
- package/dist/config/ChildContainerStartable.d.ts +5 -0
- package/dist/config/ChildContainerStartable.d.ts.map +1 -0
- package/dist/config/ChildContainerStartable.js +1 -0
- package/dist/config/ConfigurableModule.d.ts +1 -1
- package/dist/config/ConfigurableModule.d.ts.map +1 -1
- package/dist/config/ConfigurableModule.js +0 -1
- package/dist/config/ModuleContainer.d.ts +10 -2
- package/dist/config/ModuleContainer.d.ts.map +1 -1
- package/dist/config/ModuleContainer.js +6 -10
- package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
- package/dist/dependencyFactory/injectOptional.d.ts.map +1 -1
- package/dist/dependencyFactory/injectOptional.js +1 -4
- package/dist/events/EventEmitter.d.ts.map +1 -1
- package/dist/events/EventEmitter.js +0 -1
- package/dist/events/EventEmitterProxy.d.ts.map +1 -1
- package/dist/events/EventEmitterProxy.js +2 -0
- package/dist/log.d.ts +3 -2
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +11 -4
- package/dist/quickmaths.d.ts +7 -0
- package/dist/quickmaths.d.ts.map +1 -0
- package/dist/quickmaths.js +24 -0
- package/dist/test/equalProvable.d.ts +20 -0
- package/dist/test/equalProvable.d.ts.map +1 -0
- package/dist/test/equalProvable.js +13 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts.map +1 -1
- package/dist/trees/MockAsyncMerkleStore.js +1 -1
- package/dist/trees/RollupMerkleTree.d.ts +35 -16
- package/dist/trees/RollupMerkleTree.d.ts.map +1 -1
- package/dist/trees/RollupMerkleTree.js +8 -13
- package/dist/trees/VirtualMerkleTreeStore.d.ts +13 -0
- package/dist/trees/VirtualMerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/VirtualMerkleTreeStore.js +17 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +12 -7
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -10
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -1
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js +1 -3
- package/dist/zkProgrammable/ZkProgrammable.d.ts +11 -5
- package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
- package/dist/zkProgrammable/ZkProgrammable.js +7 -2
- package/dist/zkProgrammable/provableMethod.d.ts +5 -6
- package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
- package/dist/zkProgrammable/provableMethod.js +2 -5
- package/package.json +5 -5
- package/src/config/ChildContainerCreatable.ts +1 -1
- package/src/config/ConfigurableModule.ts +1 -2
- package/src/config/ModuleContainer.ts +17 -13
- package/src/dependencyFactory/DependencyFactory.ts +5 -4
- package/src/dependencyFactory/injectOptional.ts +0 -1
- package/src/events/EventEmitter.ts +0 -2
- package/src/events/EventEmitterProxy.ts +7 -5
- package/src/log.ts +20 -6
- package/src/trees/MockAsyncMerkleStore.ts +2 -1
- package/src/trees/RollupMerkleTree.ts +11 -17
- package/src/trees/VirtualMerkleTreeStore.ts +2 -3
- package/src/types.ts +2 -4
- package/src/utils.ts +77 -19
- package/src/zkProgrammable/ProvableMethodExecutionContext.ts +2 -4
- package/src/zkProgrammable/ZkProgrammable.ts +19 -13
- package/src/zkProgrammable/provableMethod.ts +13 -15
- package/test/config/ContainerEvents.test.ts +6 -25
- package/test/config/ModuleContainer.test.ts +10 -25
- package/test/trees/MerkleTree.test.ts +3 -2
- package/test/tsconfig.json +5 -2
- package/test/zkProgrammable/ZkProgrammable.test.ts +104 -83
- package/tsconfig.json +1 -1
- package/tsconfig.test.json +0 -9
|
@@ -7,7 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
+
import { Field } from "o1js";
|
|
10
11
|
import { Memoize } from "typescript-memoize";
|
|
12
|
+
import { log } from "../log";
|
|
11
13
|
import { MOCK_PROOF } from "./provableMethod";
|
|
12
14
|
const errors = {
|
|
13
15
|
appChainNotSet: (name) => new Error(`Appchain was not injected for: ${name}`),
|
|
@@ -21,7 +23,7 @@ export function verifyToMockable(verify, { areProofsEnabled }) {
|
|
|
21
23
|
}
|
|
22
24
|
catch (error) {
|
|
23
25
|
// silently fail verification
|
|
24
|
-
|
|
26
|
+
log.error(error);
|
|
25
27
|
verified = false;
|
|
26
28
|
}
|
|
27
29
|
return verified;
|
|
@@ -29,7 +31,10 @@ export function verifyToMockable(verify, { areProofsEnabled }) {
|
|
|
29
31
|
return proof.proof === MOCK_PROOF;
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
|
-
export const MOCK_VERIFICATION_KEY =
|
|
34
|
+
export const MOCK_VERIFICATION_KEY = {
|
|
35
|
+
data: "mock-verification-key",
|
|
36
|
+
hash: Field(0),
|
|
37
|
+
};
|
|
33
38
|
export function compileToMockable(compile, { areProofsEnabled }) {
|
|
34
39
|
return async () => {
|
|
35
40
|
if (areProofsEnabled) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Proof, DynamicProof } from "o1js";
|
|
2
2
|
import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext";
|
|
3
3
|
import type { WithZkProgrammable, ZkProgrammable } from "./ZkProgrammable";
|
|
4
|
-
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
export type DecoratedMethod = (...args: ArgumentTypes) => unknown;
|
|
4
|
+
export type O1JSPrimitive = object | string | boolean | number;
|
|
5
|
+
export type ArgumentTypes = (O1JSPrimitive | Proof<unknown, unknown> | DynamicProof<unknown, unknown>)[];
|
|
6
|
+
export type DecoratedMethod = (...args: ArgumentTypes) => Promise<unknown>;
|
|
8
7
|
export declare const MOCK_PROOF = "mock-proof";
|
|
9
8
|
export declare function toProver(methodName: string, simulatedMethod: DecoratedMethod, isFirstParameterPublicInput: boolean, ...args: ArgumentTypes): (this: ZkProgrammable<any, any>) => Promise<Proof<any, any>>;
|
|
10
9
|
/**
|
|
@@ -16,5 +15,5 @@ export declare function toProver(methodName: string, simulatedMethod: DecoratedM
|
|
|
16
15
|
* @param executionContext
|
|
17
16
|
* @returns
|
|
18
17
|
*/
|
|
19
|
-
export declare function provableMethod(isFirstParameterPublicInput?: boolean, executionContext?: ProvableMethodExecutionContext): <Target extends ZkProgrammable<any, any> | WithZkProgrammable<any, any>>(target: Target, methodName: string, descriptor:
|
|
18
|
+
export declare function provableMethod(isFirstParameterPublicInput?: boolean, executionContext?: ProvableMethodExecutionContext): <Target extends ZkProgrammable<any, any> | WithZkProgrammable<any, any>>(target: Target, methodName: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any> | any>) => TypedPropertyDescriptor<(...args: any[]) => Promise<any> | any>;
|
|
20
19
|
//# sourceMappingURL=provableMethod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"provableMethod.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/provableMethod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAG3C,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAG3E,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAC/D,MAAM,MAAM,aAAa,GAAG,CACxB,aAAa,GACb,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,GACvB,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CACjC,EAAE,CAAC;AAEJ,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE3E,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,UAEa,eAAe,GAAG,EAAE,GAAG,CAAC,8BAwB5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,2BAA2B,UAAO,EAClC,gBAAgB,GAAE,8BAEjB,wGAMa,MAAM,gDAC4B,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,GAAG,GAAG,wCAA5B,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,GAAG,GAAG,EA2C7E"}
|
|
@@ -2,7 +2,6 @@ import { container } from "tsyringe";
|
|
|
2
2
|
import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext";
|
|
3
3
|
export const MOCK_PROOF = "mock-proof";
|
|
4
4
|
export function toProver(methodName, simulatedMethod, isFirstParameterPublicInput, ...args) {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
5
|
return async function prover() {
|
|
7
6
|
const areProofsEnabled = this.appChain?.areProofsEnabled;
|
|
8
7
|
if (areProofsEnabled ?? false) {
|
|
@@ -10,10 +9,9 @@ export function toProver(methodName, simulatedMethod, isFirstParameterPublicInpu
|
|
|
10
9
|
return await Reflect.apply(programProvableMethod, this, args);
|
|
11
10
|
}
|
|
12
11
|
// create a mock proof by simulating method execution in JS
|
|
13
|
-
const publicOutput = Reflect.apply(simulatedMethod, this, args);
|
|
12
|
+
const publicOutput = await Reflect.apply(simulatedMethod, this, args);
|
|
14
13
|
return new this.zkProgram.Proof({
|
|
15
14
|
proof: MOCK_PROOF,
|
|
16
|
-
// eslint-disable-next-line no-warning-comments
|
|
17
15
|
// TODO: provide undefined if public input is not used
|
|
18
16
|
publicInput: isFirstParameterPublicInput ? args[0] : undefined,
|
|
19
17
|
publicOutput,
|
|
@@ -38,7 +36,7 @@ export function provableMethod(isFirstParameterPublicInput = true, executionCont
|
|
|
38
36
|
return (target, methodName, descriptor) => {
|
|
39
37
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
40
38
|
const simulatedMethod = descriptor.value;
|
|
41
|
-
descriptor.value = function value(...args) {
|
|
39
|
+
descriptor.value = async function value(...args) {
|
|
42
40
|
const prover = toProver(methodName, simulatedMethod, isFirstParameterPublicInput, ...args);
|
|
43
41
|
executionContext.beforeMethod(this.constructor.name, methodName, args);
|
|
44
42
|
/**
|
|
@@ -53,7 +51,6 @@ export function provableMethod(isFirstParameterPublicInput = true, executionCont
|
|
|
53
51
|
* or not, execute its simulated (Javascript) version and
|
|
54
52
|
* return the result.
|
|
55
53
|
*/
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
57
54
|
let result;
|
|
58
55
|
try {
|
|
59
56
|
result = Reflect.apply(simulatedMethod, this, args);
|
package/package.json
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.1.1-develop.
|
|
6
|
+
"version": "0.1.1-develop.833+397881ed",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
9
9
|
"dev": "tsc -p tsconfig.json --watch",
|
|
10
10
|
"lint": "eslint ./src ./test",
|
|
11
11
|
"test:file": "node --experimental-vm-modules --experimental-wasm-modules --experimental-wasm-threads ../../node_modules/jest/bin/jest.js",
|
|
12
|
-
"test": "npm run test:file -- ./
|
|
13
|
-
"test:watch": "npm run test:file -- ./
|
|
12
|
+
"test": "npm run test:file -- ./test/**",
|
|
13
|
+
"test:watch": "npm run test:file -- ./test/** --watch"
|
|
14
14
|
},
|
|
15
15
|
"main": "dist/index.js",
|
|
16
16
|
"publishConfig": {
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"typescript-memoize": "^1.1.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"o1js": "
|
|
26
|
+
"o1js": "^1.1.0",
|
|
27
27
|
"tsyringe": "^4.7.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@jest/globals": "^29.5.0",
|
|
31
31
|
"@types/lodash": "^4.14.194"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "397881ed5d8f98f5005bcd7be7f5a12b3bc6f956"
|
|
34
34
|
}
|
|
@@ -11,7 +11,7 @@ const errors = {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// defines how presets can be provided, either a function or a record
|
|
14
|
-
export type Preset<Config> = Config | ((...args:
|
|
14
|
+
export type Preset<Config> = Config | ((...args: unknown[]) => Config);
|
|
15
15
|
export type Presets<Config> = Record<string, Preset<Config>>;
|
|
16
16
|
|
|
17
17
|
// describes the interface of a configurable module
|
|
@@ -46,7 +46,6 @@ export class ConfigurableModule<Config = NoConfig>
|
|
|
46
46
|
this.currentConfig = config;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
50
49
|
public create(childContainerProvider: ChildContainerProvider): void {
|
|
51
50
|
noop();
|
|
52
51
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
1
|
import "reflect-metadata";
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -20,6 +19,7 @@ import {
|
|
|
20
19
|
DependencyFactory,
|
|
21
20
|
InferDependencies,
|
|
22
21
|
} from "../dependencyFactory/DependencyFactory";
|
|
22
|
+
import { EventEmitterProxy } from "../events/EventEmitterProxy";
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
25
|
Configurable,
|
|
@@ -28,7 +28,6 @@ import {
|
|
|
28
28
|
} from "./ConfigurableModule";
|
|
29
29
|
import { ChildContainerProvider } from "./ChildContainerProvider";
|
|
30
30
|
import { ChildContainerCreatable } from "./ChildContainerCreatable";
|
|
31
|
-
import { EventEmitterProxy } from "../events/EventEmitterProxy";
|
|
32
31
|
|
|
33
32
|
const errors = {
|
|
34
33
|
configNotSetInContainer: (moduleName: string) =>
|
|
@@ -38,8 +37,7 @@ const errors = {
|
|
|
38
37
|
|
|
39
38
|
onlyValidModuleNames: (moduleName: NonNullable<unknown>) =>
|
|
40
39
|
new Error(
|
|
41
|
-
// eslint-disable-next-line
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
43
41
|
`Only known module names are allowed, using unknown module name: ${moduleName}`
|
|
44
42
|
),
|
|
45
43
|
|
|
@@ -81,7 +79,7 @@ export type BaseModuleType = TypedClass<BaseModuleInstanceType>;
|
|
|
81
79
|
// allows to specify what kind of modules can be passed into a container
|
|
82
80
|
export interface ModulesRecord<
|
|
83
81
|
// use the default configurable module type
|
|
84
|
-
ModuleType extends BaseModuleType = BaseModuleType
|
|
82
|
+
ModuleType extends BaseModuleType = BaseModuleType,
|
|
85
83
|
> {
|
|
86
84
|
[name: string]: ModuleType;
|
|
87
85
|
}
|
|
@@ -98,8 +96,16 @@ export type ModulesConfig<Modules extends ModulesRecord> = {
|
|
|
98
96
|
: never;
|
|
99
97
|
};
|
|
100
98
|
|
|
99
|
+
/**
|
|
100
|
+
* This type make any config partial (i.e. optional) up to the first level
|
|
101
|
+
* So { Module: { a: { b: string } } }
|
|
102
|
+
* will become
|
|
103
|
+
* { Module?: { a?: { b: string } } }
|
|
104
|
+
* Note that b does not become optional, as we don't want nested objects to
|
|
105
|
+
* become unreasonably partialized (for example Field).
|
|
106
|
+
*/
|
|
101
107
|
export type RecursivePartial<T> = {
|
|
102
|
-
[Key in keyof T]?:
|
|
108
|
+
[Key in keyof T]?: Partial<T[Key]>;
|
|
103
109
|
};
|
|
104
110
|
|
|
105
111
|
/**
|
|
@@ -136,7 +142,7 @@ export type ResolvableModules<Modules extends ModulesRecord> = MergeObjects<
|
|
|
136
142
|
* configuration, decoration and validation of modules
|
|
137
143
|
*/
|
|
138
144
|
export class ModuleContainer<
|
|
139
|
-
Modules extends ModulesRecord
|
|
145
|
+
Modules extends ModulesRecord,
|
|
140
146
|
> extends ConfigurableModule<ModulesConfig<Modules>> {
|
|
141
147
|
/**
|
|
142
148
|
* Determines how often are modules decorated upon resolution
|
|
@@ -230,7 +236,7 @@ export class ModuleContainer<
|
|
|
230
236
|
* @param modules
|
|
231
237
|
*/
|
|
232
238
|
protected registerModules(modules: Modules) {
|
|
233
|
-
|
|
239
|
+
Object.keys(modules).forEach((moduleName) => {
|
|
234
240
|
if (Object.prototype.hasOwnProperty.call(modules, moduleName)) {
|
|
235
241
|
this.assertIsValidModuleName(moduleName);
|
|
236
242
|
|
|
@@ -245,7 +251,7 @@ export class ModuleContainer<
|
|
|
245
251
|
);
|
|
246
252
|
this.onAfterModuleResolution(moduleName);
|
|
247
253
|
}
|
|
248
|
-
}
|
|
254
|
+
});
|
|
249
255
|
}
|
|
250
256
|
|
|
251
257
|
public get events(): EventEmitterProxy<Modules> {
|
|
@@ -259,7 +265,6 @@ export class ModuleContainer<
|
|
|
259
265
|
* Register a non-module value into the current container
|
|
260
266
|
* @param modules
|
|
261
267
|
*/
|
|
262
|
-
// eslint-disable-next-line no-warning-comments
|
|
263
268
|
// TODO Rename to plural since object is param
|
|
264
269
|
public registerValue<Value>(modules: Record<string, Value>) {
|
|
265
270
|
Object.entries(modules).forEach(([moduleName, useValue]) => {
|
|
@@ -300,7 +305,6 @@ export class ModuleContainer<
|
|
|
300
305
|
return super.config;
|
|
301
306
|
}
|
|
302
307
|
|
|
303
|
-
// eslint-disable-next-line accessor-pairs
|
|
304
308
|
public set config(config: ModulesConfig<Modules>) {
|
|
305
309
|
super.config = merge<
|
|
306
310
|
ModulesConfig<Modules> | NoConfig,
|
|
@@ -348,7 +352,7 @@ export class ModuleContainer<
|
|
|
348
352
|
moduleName: StringKeyOf<Modules>,
|
|
349
353
|
containedModule: InstanceType<Modules[StringKeyOf<Modules>]>
|
|
350
354
|
) {
|
|
351
|
-
const config =
|
|
355
|
+
const config = super.config?.[moduleName];
|
|
352
356
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
353
357
|
if (!config) {
|
|
354
358
|
throw errors.configNotSetInContainer(moduleName.toString());
|
|
@@ -361,7 +365,6 @@ export class ModuleContainer<
|
|
|
361
365
|
}
|
|
362
366
|
}
|
|
363
367
|
|
|
364
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
368
|
private isDependencyFactory(type: any): type is DependencyFactory {
|
|
366
369
|
return "dependencies" in type;
|
|
367
370
|
}
|
|
@@ -409,6 +412,7 @@ export class ModuleContainer<
|
|
|
409
412
|
this.container.register(key, declaration, {
|
|
410
413
|
lifecycle: Lifecycle.Singleton,
|
|
411
414
|
});
|
|
415
|
+
// eslint-disable-next-line sonarjs/no-duplicated-branches
|
|
412
416
|
} else if (isTokenProvider(declaration)) {
|
|
413
417
|
this.container.register(key, declaration, {
|
|
414
418
|
lifecycle: Lifecycle.Singleton,
|
|
@@ -36,10 +36,11 @@ export interface DependencyFactory {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export type TypeFromDependencyDeclaration<
|
|
39
|
-
Declaration extends DependencyDeclaration<unknown
|
|
40
|
-
> =
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
Declaration extends DependencyDeclaration<unknown>,
|
|
40
|
+
> =
|
|
41
|
+
Declaration extends DependencyDeclaration<infer Dependency>
|
|
42
|
+
? Dependency
|
|
43
|
+
: never;
|
|
43
44
|
|
|
44
45
|
export type CapitalizeAny<Key extends string | number | symbol> =
|
|
45
46
|
Key extends string ? Capitalize<Key> : Key;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { EventsRecord } from "./EventEmittingComponent";
|
|
2
2
|
|
|
3
3
|
type ListenersHolder<Events extends EventsRecord> = {
|
|
4
|
-
// eslint-disable-next-line putout/putout
|
|
5
4
|
[key in keyof Events]?: ((...args: Events[key]) => void)[];
|
|
6
5
|
};
|
|
7
6
|
|
|
8
7
|
export class EventEmitter<Events extends EventsRecord> {
|
|
9
8
|
private readonly listeners: ListenersHolder<Events> = {};
|
|
10
9
|
|
|
11
|
-
// eslint-disable-next-line putout/putout
|
|
12
10
|
private readonly wildcardListeners: ((
|
|
13
11
|
event: keyof Events,
|
|
14
12
|
args: Events[keyof Events]
|
|
@@ -16,8 +16,8 @@ export type ModuleEvents<ModuleType extends BaseModuleType> =
|
|
|
16
16
|
InstanceType<ModuleType> extends EventEmittingComponent<infer Events>
|
|
17
17
|
? Events
|
|
18
18
|
: InstanceType<ModuleType> extends ModuleContainer<infer NestedModules>
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
? CastToEventsRecord<ContainerEvents<NestedModules>>
|
|
20
|
+
: EventsRecord;
|
|
21
21
|
|
|
22
22
|
export type ContainerEvents<Modules extends ModulesRecord> = {
|
|
23
23
|
[Key in StringKeyOf<Modules>]: ModuleEvents<Modules[Key]>;
|
|
@@ -30,7 +30,7 @@ export type FlattenedContainerEvents<Modules extends ModulesRecord> =
|
|
|
30
30
|
FlattenObject<ContainerEvents<Modules>>;
|
|
31
31
|
|
|
32
32
|
export class EventEmitterProxy<
|
|
33
|
-
Modules extends ModulesRecord
|
|
33
|
+
Modules extends ModulesRecord,
|
|
34
34
|
> extends EventEmitter<CastToEventsRecord<FlattenedContainerEvents<Modules>>> {
|
|
35
35
|
public constructor(private readonly container: ModuleContainer<Modules>) {
|
|
36
36
|
super();
|
|
@@ -40,8 +40,9 @@ export class EventEmitterProxy<
|
|
|
40
40
|
) {
|
|
41
41
|
const module = container.resolve(moduleName);
|
|
42
42
|
if (this.isEventEmitter(module)) {
|
|
43
|
-
module.events.onAll((events: any, args:
|
|
44
|
-
|
|
43
|
+
module.events.onAll((events: any, args: any[]) => {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
45
|
+
this.emit(events, ...args);
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -51,6 +52,7 @@ export class EventEmitterProxy<
|
|
|
51
52
|
private isEventEmitter(
|
|
52
53
|
module: any
|
|
53
54
|
): module is EventEmittingComponent<EventsRecord> {
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
54
56
|
const emitter = module.events;
|
|
55
57
|
return emitter !== undefined && emitter instanceof EventEmitter;
|
|
56
58
|
}
|
package/src/log.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import loglevel, { LogLevelDesc } from "loglevel";
|
|
1
|
+
import loglevel, { LogLevelDesc, LogLevelNames } from "loglevel";
|
|
3
2
|
import { Provable } from "o1js";
|
|
4
3
|
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
5
5
|
function logProvable(
|
|
6
6
|
logFunction: (...args: unknown[]) => void,
|
|
7
7
|
...args: any[]
|
|
8
8
|
) {
|
|
9
9
|
Provable.asProver(() => {
|
|
10
|
-
const prettyArguments = [];
|
|
11
|
-
|
|
10
|
+
const prettyArguments: string[] = [];
|
|
11
|
+
|
|
12
|
+
args.forEach((argument) => {
|
|
12
13
|
if (argument?.toPretty !== undefined) {
|
|
13
14
|
prettyArguments.push(argument.toPretty());
|
|
14
15
|
} else {
|
|
@@ -18,11 +19,11 @@ function logProvable(
|
|
|
18
19
|
prettyArguments.push(argument);
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
}
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
22
|
+
});
|
|
23
23
|
logFunction(...prettyArguments);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
+
/* eslint-enable */
|
|
26
27
|
|
|
27
28
|
export const log = {
|
|
28
29
|
provable: {
|
|
@@ -81,3 +82,16 @@ export const log = {
|
|
|
81
82
|
|
|
82
83
|
getLevel: () => loglevel.getLevel(),
|
|
83
84
|
};
|
|
85
|
+
|
|
86
|
+
const validLogLevels = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "SILENT"];
|
|
87
|
+
|
|
88
|
+
export function assertValidTextLogLevel(
|
|
89
|
+
level: string | number
|
|
90
|
+
): asserts level is LogLevelNames {
|
|
91
|
+
if (
|
|
92
|
+
typeof level === "number" ||
|
|
93
|
+
!validLogLevels.includes(level.toUpperCase())
|
|
94
|
+
) {
|
|
95
|
+
throw new Error(`${level} is not a valid loglevel`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/* eslint-disable id-length */
|
|
2
|
-
/* eslint-disable line-comment-position */
|
|
3
|
-
/* eslint-disable no-inline-comments */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
5
|
-
/* eslint-disable @typescript-eslint/method-signature-style */
|
|
6
1
|
import { Bool, Field, Poseidon, Provable, Struct } from "o1js";
|
|
7
2
|
|
|
8
3
|
import { range } from "../utils";
|
|
@@ -141,7 +136,8 @@ export function createMerkleTree(height: number): AbstractMerkleTreeClass {
|
|
|
141
136
|
* @param leaf Value of the leaf node that belongs to this Witness.
|
|
142
137
|
* @returns The calculated root.
|
|
143
138
|
*/
|
|
144
|
-
public calculateRoot(
|
|
139
|
+
public calculateRoot(leaf: Field): Field {
|
|
140
|
+
let hash = leaf;
|
|
145
141
|
const n = this.height();
|
|
146
142
|
|
|
147
143
|
for (let index = 1; index < n; ++index) {
|
|
@@ -163,13 +159,8 @@ export function createMerkleTree(height: number): AbstractMerkleTreeClass {
|
|
|
163
159
|
let index = Field(0);
|
|
164
160
|
const n = this.height();
|
|
165
161
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
index = Provable.if(
|
|
169
|
-
this.isLeft[index_ - 1],
|
|
170
|
-
index,
|
|
171
|
-
index.add(powerOfTwo)
|
|
172
|
-
);
|
|
162
|
+
for (let i = 1; i < n; ++i) {
|
|
163
|
+
index = Provable.if(this.isLeft[i - 1], index, index.add(powerOfTwo));
|
|
173
164
|
powerOfTwo = powerOfTwo.mul(2);
|
|
174
165
|
}
|
|
175
166
|
|
|
@@ -308,16 +299,20 @@ export function createMerkleTree(height: number): AbstractMerkleTreeClass {
|
|
|
308
299
|
|
|
309
300
|
const path = [];
|
|
310
301
|
const isLefts = [];
|
|
302
|
+
let currentIndex = index;
|
|
311
303
|
for (
|
|
312
304
|
let level = 0;
|
|
313
305
|
level < AbstractRollupMerkleTree.HEIGHT - 1;
|
|
314
306
|
level += 1
|
|
315
307
|
) {
|
|
316
|
-
const isLeft =
|
|
317
|
-
const sibling = this.getNode(
|
|
308
|
+
const isLeft = currentIndex % 2n === 0n;
|
|
309
|
+
const sibling = this.getNode(
|
|
310
|
+
level,
|
|
311
|
+
isLeft ? currentIndex + 1n : currentIndex - 1n
|
|
312
|
+
);
|
|
318
313
|
isLefts.push(Bool(isLeft));
|
|
319
314
|
path.push(sibling);
|
|
320
|
-
|
|
315
|
+
currentIndex /= 2n;
|
|
321
316
|
}
|
|
322
317
|
return new RollupMerkleWitness({
|
|
323
318
|
isLeft: isLefts,
|
|
@@ -325,7 +320,6 @@ export function createMerkleTree(height: number): AbstractMerkleTreeClass {
|
|
|
325
320
|
});
|
|
326
321
|
}
|
|
327
322
|
|
|
328
|
-
// eslint-disable-next-line no-warning-comments, max-len
|
|
329
323
|
// TODO: should this take an optional offset? should it fail if the array is too long?
|
|
330
324
|
/**
|
|
331
325
|
* Fills all leaves of the tree.
|
|
@@ -7,7 +7,7 @@ import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
|
|
|
7
7
|
*/
|
|
8
8
|
export class VirtualMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
9
9
|
public constructor(private readonly parent: MerkleTreeStore) {
|
|
10
|
-
super()
|
|
10
|
+
super();
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
public getNode(key: bigint, level: number): bigint | undefined {
|
|
@@ -17,5 +17,4 @@ export class VirtualMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
|
17
17
|
public setNode(key: bigint, level: number, value: bigint): void {
|
|
18
18
|
super.setNode(key, level, value);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
}
|
|
20
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// allows to reference interfaces as 'classes' rather than instances
|
|
2
|
-
import { Bool, Field,
|
|
2
|
+
import { Bool, Field, PublicKey } from "o1js";
|
|
3
3
|
|
|
4
4
|
export type TypedClass<Class> = new (...args: any[]) => Class;
|
|
5
5
|
|
|
6
|
-
export type UnTypedClass = new (...args: any[]) =>
|
|
6
|
+
export type UnTypedClass = new (...args: any[]) => unknown;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Using simple `keyof Target` would result into the key
|
|
@@ -11,13 +11,11 @@ export type UnTypedClass = new (...args: any[]) => any;
|
|
|
11
11
|
*/
|
|
12
12
|
export type StringKeyOf<Target extends object> = Extract<keyof Target, string> &
|
|
13
13
|
string;
|
|
14
|
-
// export type StringKeyOf<Target extends object> = keyof Target
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Utility type to infer element type from an array type
|
|
18
17
|
*/
|
|
19
18
|
export type ArrayElement<ArrayType extends readonly unknown[]> =
|
|
20
|
-
// eslint-disable-next-line putout/putout
|
|
21
19
|
ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
|
22
20
|
|
|
23
21
|
/**
|