@proto-kit/common 0.1.1-develop.600 → 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 +2 -2
- package/dist/config/ConfigurableModule.d.ts.map +1 -1
- package/dist/config/ConfigurableModule.js +0 -1
- package/dist/config/ModuleContainer.d.ts +14 -2
- package/dist/config/ModuleContainer.d.ts.map +1 -1
- package/dist/config/ModuleContainer.js +8 -13
- package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
- package/dist/dependencyFactory/injectOptional.d.ts +16 -0
- package/dist/dependencyFactory/injectOptional.d.ts.map +1 -0
- package/dist/dependencyFactory/injectOptional.js +39 -0
- 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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -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 +5 -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 -4
- 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 +2 -3
- package/src/config/ModuleContainer.ts +23 -17
- package/src/dependencyFactory/DependencyFactory.ts +5 -4
- package/src/dependencyFactory/injectOptional.ts +41 -0
- package/src/events/EventEmitter.ts +0 -2
- package/src/events/EventEmitterProxy.ts +7 -5
- package/src/index.ts +1 -0
- 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 +6 -4
- package/src/utils.ts +77 -19
- package/src/zkProgrammable/ProvableMethodExecutionContext.ts +2 -4
- package/src/zkProgrammable/ZkProgrammable.ts +19 -12
- package/src/zkProgrammable/provableMethod.ts +13 -14
- package/test/config/ContainerEvents.test.ts +8 -27
- 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
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Field, Poseidon } 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"
|
|
@@ -6,12 +6,28 @@ export function requireTrue(condition, errorOrFunction) {
|
|
|
6
6
|
: errorOrFunction;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export function range(startOrEnd,
|
|
9
|
+
export function range(startOrEnd, endOrNothing) {
|
|
10
|
+
let end = endOrNothing;
|
|
11
|
+
let start = startOrEnd;
|
|
10
12
|
if (end === undefined) {
|
|
11
13
|
end = startOrEnd;
|
|
12
|
-
|
|
14
|
+
start = 0;
|
|
13
15
|
}
|
|
14
|
-
return Array.from({ length: end -
|
|
16
|
+
return Array.from({ length: end - start }, (ignored, index) => index + start);
|
|
17
|
+
}
|
|
18
|
+
export function reduceSequential(array, callbackfn, initialValue) {
|
|
19
|
+
return array.reduce(async (previousPromise, current, index, arr) => {
|
|
20
|
+
const previous = await previousPromise;
|
|
21
|
+
return await callbackfn(previous, current, index, arr);
|
|
22
|
+
}, Promise.resolve(initialValue));
|
|
23
|
+
}
|
|
24
|
+
export function mapSequential(array, f) {
|
|
25
|
+
return array.reduce(async (r, element, index, a) => {
|
|
26
|
+
const ret = await r;
|
|
27
|
+
const next = await f(element, index, a);
|
|
28
|
+
ret.push(next);
|
|
29
|
+
return ret;
|
|
30
|
+
}, Promise.resolve([]));
|
|
15
31
|
}
|
|
16
32
|
/**
|
|
17
33
|
* Computes a dummy value for the given value type.
|
|
@@ -25,11 +41,11 @@ export function dummyValue(valueType) {
|
|
|
25
41
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
26
42
|
return valueType.fromFields(fields);
|
|
27
43
|
}
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
29
44
|
export function noop() { }
|
|
30
45
|
export async function sleep(ms) {
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
await new Promise((resolve) => {
|
|
47
|
+
setTimeout(resolve, ms);
|
|
48
|
+
});
|
|
33
49
|
}
|
|
34
50
|
export function filterNonNull(value) {
|
|
35
51
|
return value !== null;
|
|
@@ -37,16 +53,21 @@ export function filterNonNull(value) {
|
|
|
37
53
|
export function filterNonUndefined(value) {
|
|
38
54
|
return value !== undefined;
|
|
39
55
|
}
|
|
40
|
-
|
|
56
|
+
const encoder = new TextEncoder();
|
|
41
57
|
// Copied from o1js binable.ts:317
|
|
42
58
|
export function prefixToField(prefix) {
|
|
43
|
-
|
|
59
|
+
const fieldSize = Field.sizeInBytes;
|
|
44
60
|
if (prefix.length >= fieldSize)
|
|
45
61
|
throw Error("prefix too long");
|
|
46
|
-
|
|
62
|
+
const stringBytes = [...encoder.encode(prefix)];
|
|
47
63
|
return Field.fromBytes(stringBytes.concat(Array(fieldSize - stringBytes.length).fill(0)));
|
|
48
64
|
}
|
|
49
65
|
export function hashWithPrefix(prefix, input) {
|
|
50
66
|
const salt = Poseidon.update([Field(0), Field(0), Field(0)], [prefixToField(prefix)]);
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
51
68
|
return Poseidon.update(salt, input)[0];
|
|
52
69
|
}
|
|
70
|
+
// end copy
|
|
71
|
+
export function expectDefined(value) {
|
|
72
|
+
expect(value).toBeDefined();
|
|
73
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProvableMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ProvableMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ProvableMethodExecutionContext.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ProvableMethodExecutionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAIlC,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,CAChB,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;IAGtC;;;;;;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"}
|
|
@@ -29,13 +29,12 @@ export class ProvableMethodExecutionResult {
|
|
|
29
29
|
* allowing them to post relevant information (such as execution status)
|
|
30
30
|
* into the context without any unnecessary 'prop drilling'.
|
|
31
31
|
*/
|
|
32
|
-
let ProvableMethodExecutionContext = class ProvableMethodExecutionContext {
|
|
32
|
+
export let ProvableMethodExecutionContext = class ProvableMethodExecutionContext {
|
|
33
33
|
constructor() {
|
|
34
34
|
this.id = uniqueId();
|
|
35
35
|
this.methods = [];
|
|
36
36
|
this.result = new ProvableMethodExecutionResult();
|
|
37
37
|
}
|
|
38
|
-
// eslint-disable-next-line no-warning-comments,max-len
|
|
39
38
|
// TODO See if we should make this class generic, bc I think we can persist the type
|
|
40
39
|
/**
|
|
41
40
|
* Adds a method prover to the current execution context,
|
|
@@ -95,4 +94,3 @@ let ProvableMethodExecutionContext = class ProvableMethodExecutionContext {
|
|
|
95
94
|
ProvableMethodExecutionContext = __decorate([
|
|
96
95
|
singleton()
|
|
97
96
|
], ProvableMethodExecutionContext);
|
|
98
|
-
export { ProvableMethodExecutionContext };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZkProgram, FlexibleProvablePure, Proof, Field, Provable } from "o1js";
|
|
2
2
|
export interface CompileArtifact {
|
|
3
|
-
verificationKey:
|
|
3
|
+
verificationKey: {
|
|
4
|
+
data: string;
|
|
5
|
+
hash: Field;
|
|
6
|
+
};
|
|
4
7
|
}
|
|
5
8
|
export interface AreProofsEnabled {
|
|
6
9
|
areProofsEnabled: boolean;
|
|
@@ -15,11 +18,15 @@ export interface Compile {
|
|
|
15
18
|
export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
|
|
16
19
|
compile: Compile;
|
|
17
20
|
verify: Verify<PublicInput, PublicOutput>;
|
|
18
|
-
Proof: ReturnType<typeof
|
|
21
|
+
Proof: ReturnType<typeof ZkProgram.Proof<FlexibleProvablePure<PublicInput>, FlexibleProvablePure<PublicOutput>>>;
|
|
19
22
|
methods: Record<string, ((...args: any) => Promise<Proof<PublicInput, PublicOutput>>) | ((publicInput: PublicInput, ...args: any) => Promise<Proof<PublicInput, PublicOutput>>)>;
|
|
23
|
+
analyzeMethods: () => Promise<Record<string, Awaited<ReturnType<typeof Provable.constraintSystem>>>>;
|
|
20
24
|
}
|
|
21
25
|
export declare function verifyToMockable<PublicInput, PublicOutput>(verify: Verify<PublicInput, PublicOutput>, { areProofsEnabled }: AreProofsEnabled): (proof: Proof<PublicInput, PublicOutput>) => Promise<boolean>;
|
|
22
|
-
export declare const MOCK_VERIFICATION_KEY
|
|
26
|
+
export declare const MOCK_VERIFICATION_KEY: {
|
|
27
|
+
data: string;
|
|
28
|
+
hash: import("o1js/dist/node/lib/provable/field").Field;
|
|
29
|
+
};
|
|
23
30
|
export declare function compileToMockable(compile: Compile, { areProofsEnabled }: AreProofsEnabled): () => Promise<CompileArtifact>;
|
|
24
31
|
export declare abstract class ZkProgrammable<PublicInput = undefined, PublicOutput = void> {
|
|
25
32
|
abstract get appChain(): AreProofsEnabled | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZkProgrammable.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ZkProgrammable.d.ts","sourceRoot":"","sources":["../../src/zkProgrammable/ZkProgrammable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAY/E,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE;QACf,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,KAAK,CAAC;KACb,CAAC;CACH;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,SAAS,CAAC,KAAK,CACpB,oBAAoB,CAAC,WAAW,CAAC,EACjC,oBAAoB,CAAC,YAAY,CAAC,CACnC,CACF,CAAC;IACF,OAAO,EAAE,MAAM,CACb,MAAM,EACJ,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC,GAC7D,CAAC,CACC,WAAW,EAAE,WAAW,EACxB,GAAG,IAAI,EAAE,GAAG,KACT,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC,CAClD,CAAC;IACF,cAAc,EAAE,MAAM,OAAO,CAC3B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CACtE,CAAC;CACH;AAED,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,YAAY,EACxD,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,EACzC,EAAE,gBAAgB,EAAE,EAAE,gBAAgB,WAEjB,MAAM,WAAW,EAAE,YAAY,CAAC,sBAiBtD;AAED,eAAO,MAAM,qBAAqB;;;CAGjC,CAAC;AAEF,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"}
|
|
@@ -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
|
|
@@ -19,7 +19,7 @@ export interface Configurable<Config> {
|
|
|
19
19
|
config: Config;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export type NoConfig = Record<
|
|
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
|
|
@@ -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
|
/**
|
|
@@ -108,6 +114,9 @@ export type RecursivePartial<T> = {
|
|
|
108
114
|
export interface ModuleContainerDefinition<Modules extends ModulesRecord> {
|
|
109
115
|
modules: Modules;
|
|
110
116
|
// config is optional, as it may be provided by the parent/wrapper class
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated
|
|
119
|
+
*/
|
|
111
120
|
config?: ModulesConfig<Modules>;
|
|
112
121
|
}
|
|
113
122
|
|
|
@@ -133,7 +142,7 @@ export type ResolvableModules<Modules extends ModulesRecord> = MergeObjects<
|
|
|
133
142
|
* configuration, decoration and validation of modules
|
|
134
143
|
*/
|
|
135
144
|
export class ModuleContainer<
|
|
136
|
-
Modules extends ModulesRecord
|
|
145
|
+
Modules extends ModulesRecord,
|
|
137
146
|
> extends ConfigurableModule<ModulesConfig<Modules>> {
|
|
138
147
|
/**
|
|
139
148
|
* Determines how often are modules decorated upon resolution
|
|
@@ -148,9 +157,6 @@ export class ModuleContainer<
|
|
|
148
157
|
|
|
149
158
|
public constructor(public definition: ModuleContainerDefinition<Modules>) {
|
|
150
159
|
super();
|
|
151
|
-
if (definition.config !== undefined) {
|
|
152
|
-
this.config = definition.config;
|
|
153
|
-
}
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
/**
|
|
@@ -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]) => {
|
|
@@ -296,7 +301,10 @@ export class ModuleContainer<
|
|
|
296
301
|
>(this.currentConfig ?? {}, config);
|
|
297
302
|
}
|
|
298
303
|
|
|
299
|
-
|
|
304
|
+
public get config() {
|
|
305
|
+
return super.config;
|
|
306
|
+
}
|
|
307
|
+
|
|
300
308
|
public set config(config: ModulesConfig<Modules>) {
|
|
301
309
|
super.config = merge<
|
|
302
310
|
ModulesConfig<Modules> | NoConfig,
|
|
@@ -344,9 +352,7 @@ export class ModuleContainer<
|
|
|
344
352
|
moduleName: StringKeyOf<Modules>,
|
|
345
353
|
containedModule: InstanceType<Modules[StringKeyOf<Modules>]>
|
|
346
354
|
) {
|
|
347
|
-
// Has to be super.config, getters behave really weird when subtyping
|
|
348
355
|
const config = super.config?.[moduleName];
|
|
349
|
-
|
|
350
356
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
351
357
|
if (!config) {
|
|
352
358
|
throw errors.configNotSetInContainer(moduleName.toString());
|
|
@@ -359,7 +365,6 @@ export class ModuleContainer<
|
|
|
359
365
|
}
|
|
360
366
|
}
|
|
361
367
|
|
|
362
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
363
368
|
private isDependencyFactory(type: any): type is DependencyFactory {
|
|
364
369
|
return "dependencies" in type;
|
|
365
370
|
}
|
|
@@ -407,6 +412,7 @@ export class ModuleContainer<
|
|
|
407
412
|
this.container.register(key, declaration, {
|
|
408
413
|
lifecycle: Lifecycle.Singleton,
|
|
409
414
|
});
|
|
415
|
+
// eslint-disable-next-line sonarjs/no-duplicated-branches
|
|
410
416
|
} else if (isTokenProvider(declaration)) {
|
|
411
417
|
this.container.register(key, declaration, {
|
|
412
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;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
container,
|
|
3
|
+
injectable,
|
|
4
|
+
injectWithTransform,
|
|
5
|
+
Lifecycle,
|
|
6
|
+
scoped,
|
|
7
|
+
} from "tsyringe";
|
|
8
|
+
|
|
9
|
+
@injectable()
|
|
10
|
+
@scoped(Lifecycle.ResolutionScoped)
|
|
11
|
+
class UndefinedDisguise {}
|
|
12
|
+
|
|
13
|
+
class UndefinedTransform<Dependency> {
|
|
14
|
+
public transform(
|
|
15
|
+
incoming: Dependency | UndefinedDisguise
|
|
16
|
+
): Dependency | undefined {
|
|
17
|
+
if (incoming instanceof UndefinedDisguise) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return incoming;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This function injects a dependency only if it has been registered, otherwise
|
|
26
|
+
* injects undefined. This can be useful for having optional dependencies, where
|
|
27
|
+
* tsyringe would normally error out and not be able to resolve. With this
|
|
28
|
+
* decorator, we can now do this.
|
|
29
|
+
*
|
|
30
|
+
* The strategy we employ here is that we inject a dummy into the global
|
|
31
|
+
* container that is of type UndefinedDisguise. We can't inject undefined
|
|
32
|
+
* directly, therefore we use this object to disguise itself as undefined.
|
|
33
|
+
* Then a child container registers something under the same token, it by
|
|
34
|
+
* default resolves that new dependency. If that doesn't happen, the
|
|
35
|
+
* resolution hits our disguise, which we then convert into undefined
|
|
36
|
+
* using the Transform
|
|
37
|
+
*/
|
|
38
|
+
export function injectOptional<T>(token: string) {
|
|
39
|
+
container.register(token, { useClass: UndefinedDisguise });
|
|
40
|
+
return injectWithTransform(token, UndefinedTransform<T>);
|
|
41
|
+
}
|
|
@@ -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/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
|
@@ -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
|
+
}
|