@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
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
1
|
import "reflect-metadata";
|
|
3
2
|
import { instancePerContainerCachingFactory, isClassProvider, isFactoryProvider, isTokenProvider, isValueProvider, Lifecycle, } from "tsyringe";
|
|
4
3
|
import log from "loglevel";
|
|
5
4
|
import merge from "lodash/merge";
|
|
6
|
-
import { ConfigurableModule, } from "./ConfigurableModule";
|
|
7
5
|
import { EventEmitterProxy } from "../events/EventEmitterProxy";
|
|
6
|
+
import { ConfigurableModule, } from "./ConfigurableModule";
|
|
8
7
|
const errors = {
|
|
9
8
|
configNotSetInContainer: (moduleName) => new Error(`Trying to get config of ${moduleName}, but it was not yet set in the module container`),
|
|
10
9
|
onlyValidModuleNames: (moduleName) => new Error(
|
|
11
|
-
// eslint-disable-next-line
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
13
11
|
`Only known module names are allowed, using unknown module name: ${moduleName}`),
|
|
14
12
|
unableToDecorateModule: (moduleName) =>
|
|
15
13
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
@@ -34,9 +32,6 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
34
32
|
// DI container holding all the registered modules
|
|
35
33
|
this.providedContainer = undefined;
|
|
36
34
|
this.eventEmitterProxy = undefined;
|
|
37
|
-
if (definition.config !== undefined) {
|
|
38
|
-
this.config = definition.config;
|
|
39
|
-
}
|
|
40
35
|
}
|
|
41
36
|
/**
|
|
42
37
|
* @returns list of module names
|
|
@@ -94,7 +89,7 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
94
89
|
* @param modules
|
|
95
90
|
*/
|
|
96
91
|
registerModules(modules) {
|
|
97
|
-
|
|
92
|
+
Object.keys(modules).forEach((moduleName) => {
|
|
98
93
|
if (Object.prototype.hasOwnProperty.call(modules, moduleName)) {
|
|
99
94
|
this.assertIsValidModuleName(moduleName);
|
|
100
95
|
log.debug(`Registering module: ${moduleName}`);
|
|
@@ -102,7 +97,7 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
102
97
|
this.container.register(moduleName, { useClass }, { lifecycle: Lifecycle.ContainerScoped });
|
|
103
98
|
this.onAfterModuleResolution(moduleName);
|
|
104
99
|
}
|
|
105
|
-
}
|
|
100
|
+
});
|
|
106
101
|
}
|
|
107
102
|
get events() {
|
|
108
103
|
if (this.eventEmitterProxy === undefined) {
|
|
@@ -114,7 +109,6 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
114
109
|
* Register a non-module value into the current container
|
|
115
110
|
* @param modules
|
|
116
111
|
*/
|
|
117
|
-
// eslint-disable-next-line no-warning-comments
|
|
118
112
|
// TODO Rename to plural since object is param
|
|
119
113
|
registerValue(modules) {
|
|
120
114
|
Object.entries(modules).forEach(([moduleName, useValue]) => {
|
|
@@ -140,7 +134,9 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
140
134
|
configurePartial(config) {
|
|
141
135
|
this.config = merge(this.currentConfig ?? {}, config);
|
|
142
136
|
}
|
|
143
|
-
|
|
137
|
+
get config() {
|
|
138
|
+
return super.config;
|
|
139
|
+
}
|
|
144
140
|
set config(config) {
|
|
145
141
|
super.config = merge(this.currentConfig ?? {}, config);
|
|
146
142
|
}
|
|
@@ -170,7 +166,6 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
170
166
|
* features or module checks
|
|
171
167
|
*/
|
|
172
168
|
decorateModule(moduleName, containedModule) {
|
|
173
|
-
// Has to be super.config, getters behave really weird when subtyping
|
|
174
169
|
const config = super.config?.[moduleName];
|
|
175
170
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
176
171
|
if (!config) {
|
|
@@ -183,7 +178,6 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
183
178
|
containedModule.config = config;
|
|
184
179
|
}
|
|
185
180
|
}
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
181
|
isDependencyFactory(type) {
|
|
188
182
|
return "dependencies" in type;
|
|
189
183
|
}
|
|
@@ -225,6 +219,7 @@ export class ModuleContainer extends ConfigurableModule {
|
|
|
225
219
|
this.container.register(key, declaration, {
|
|
226
220
|
lifecycle: Lifecycle.Singleton,
|
|
227
221
|
});
|
|
222
|
+
// eslint-disable-next-line sonarjs/no-duplicated-branches
|
|
228
223
|
}
|
|
229
224
|
else if (isTokenProvider(declaration)) {
|
|
230
225
|
this.container.register(key, declaration, {
|
|
@@ -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,EACb,aAAa,EACd,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAExE,MAAM,MAAM,qBAAqB,CAAC,UAAU,IACxC,aAAa,CAAC,UAAU,CAAC,GACzB,eAAe,CAAC,UAAU,CAAC,GAC3B,aAAa,CAAC,UAAU,CAAC,GACzB,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,
|
|
1
|
+
{"version":3,"file":"DependencyFactory.d.ts","sourceRoot":"","sources":["../../src/depend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C,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,GAC7D,KAAK,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function injects a dependency only if it has been registered, otherwise
|
|
3
|
+
* injects undefined. This can be useful for having optional dependencies, where
|
|
4
|
+
* tsyringe would normally error out and not be able to resolve. With this
|
|
5
|
+
* decorator, we can now do this.
|
|
6
|
+
*
|
|
7
|
+
* The strategy we employ here is that we inject a dummy into the global
|
|
8
|
+
* container that is of type UndefinedDisguise. We can't inject undefined
|
|
9
|
+
* directly, therefore we use this object to disguise itself as undefined.
|
|
10
|
+
* Then a child container registers something under the same token, it by
|
|
11
|
+
* default resolves that new dependency. If that doesn't happen, the
|
|
12
|
+
* resolution hits our disguise, which we then convert into undefined
|
|
13
|
+
* using the Transform
|
|
14
|
+
*/
|
|
15
|
+
export declare function injectOptional<T>(token: string): (target: any, propertyKey: string | symbol | undefined, parameterIndex: number) => any;
|
|
16
|
+
//# sourceMappingURL=injectOptional.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectOptional.d.ts","sourceRoot":"","sources":["../../src/dependencyFactory/injectOptional.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,0FAG9C"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { container, injectable, injectWithTransform, Lifecycle, scoped, } from "tsyringe";
|
|
8
|
+
let UndefinedDisguise = class UndefinedDisguise {
|
|
9
|
+
};
|
|
10
|
+
UndefinedDisguise = __decorate([
|
|
11
|
+
injectable(),
|
|
12
|
+
scoped(Lifecycle.ResolutionScoped)
|
|
13
|
+
], UndefinedDisguise);
|
|
14
|
+
class UndefinedTransform {
|
|
15
|
+
transform(incoming) {
|
|
16
|
+
if (incoming instanceof UndefinedDisguise) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return incoming;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* This function injects a dependency only if it has been registered, otherwise
|
|
24
|
+
* injects undefined. This can be useful for having optional dependencies, where
|
|
25
|
+
* tsyringe would normally error out and not be able to resolve. With this
|
|
26
|
+
* decorator, we can now do this.
|
|
27
|
+
*
|
|
28
|
+
* The strategy we employ here is that we inject a dummy into the global
|
|
29
|
+
* container that is of type UndefinedDisguise. We can't inject undefined
|
|
30
|
+
* directly, therefore we use this object to disguise itself as undefined.
|
|
31
|
+
* Then a child container registers something under the same token, it by
|
|
32
|
+
* default resolves that new dependency. If that doesn't happen, the
|
|
33
|
+
* resolution hits our disguise, which we then convert into undefined
|
|
34
|
+
* using the Transform
|
|
35
|
+
*/
|
|
36
|
+
export function injectOptional(token) {
|
|
37
|
+
container.register(token, { useClass: UndefinedDisguise });
|
|
38
|
+
return injectWithTransform(token, (UndefinedTransform));
|
|
39
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventEmitter.d.ts","sourceRoot":"","sources":["../../src/events/EventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"EventEmitter.d.ts","sourceRoot":"","sources":["../../src/events/EventEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,Y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,CAAC,CAAC,CAAC;AAE1C,qBAAa,iBAAiB,CAC5B,OAAO,SAAS,aAAa,CAC7B,SAAQ,YAAY,CAAC,kBAAkB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC;IAiBvE,OAAO,CAAC,cAAc;CAOvB"}
|
|
@@ -8,6 +8,7 @@ export class EventEmitterProxy extends EventEmitter {
|
|
|
8
8
|
const module = container.resolve(moduleName);
|
|
9
9
|
if (this.isEventEmitter(module)) {
|
|
10
10
|
module.events.onAll((events, args) => {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
11
12
|
this.emit(events, ...args);
|
|
12
13
|
});
|
|
13
14
|
}
|
|
@@ -15,6 +16,7 @@ export class EventEmitterProxy extends EventEmitter {
|
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
isEventEmitter(module) {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
18
20
|
const emitter = module.events;
|
|
19
21
|
return emitter !== undefined && emitter instanceof EventEmitter;
|
|
20
22
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./zkProgrammable/ProvableMethodExecutionContext";
|
|
|
8
8
|
export * from "./zkProgrammable/provableMethod";
|
|
9
9
|
export * from "./utils";
|
|
10
10
|
export * from "./dependencyFactory/DependencyFactory";
|
|
11
|
+
export * from "./dependencyFactory/injectOptional";
|
|
11
12
|
export * from "./log";
|
|
12
13
|
export * from "./events/EventEmittingComponent";
|
|
13
14
|
export * from "./events/EventEmitter";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,OAAO,CAAC;AACtB,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,SAAS,CAAC;AACxB,cAAc,iCAAiC,CAAC;AAChD,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC;AACxB,cAAc,uCAAuC,CAAC;AACtD,cAAc,oCAAoC,CAAC;AACnD,cAAc,OAAO,CAAC;AACtB,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./zkProgrammable/ProvableMethodExecutionContext";
|
|
|
8
8
|
export * from "./zkProgrammable/provableMethod";
|
|
9
9
|
export * from "./utils";
|
|
10
10
|
export * from "./dependencyFactory/DependencyFactory";
|
|
11
|
+
export * from "./dependencyFactory/injectOptional";
|
|
11
12
|
export * from "./log";
|
|
12
13
|
export * from "./events/EventEmittingComponent";
|
|
13
14
|
export * from "./events/EventEmitter";
|
package/dist/log.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import loglevel, { LogLevelDesc } from "loglevel";
|
|
1
|
+
import loglevel, { LogLevelDesc, LogLevelNames } from "loglevel";
|
|
2
2
|
export declare const log: {
|
|
3
3
|
provable: {
|
|
4
4
|
info: (...args: unknown[]) => void;
|
|
@@ -14,6 +14,7 @@ export declare const log: {
|
|
|
14
14
|
warn: (...args: unknown[]) => void;
|
|
15
15
|
setLevel: (level: LogLevelDesc) => void;
|
|
16
16
|
readonly levels: loglevel.LogLevel;
|
|
17
|
-
getLevel: () => 0 | 2 |
|
|
17
|
+
getLevel: () => 0 | 2 | 3 | 1 | 4 | 5;
|
|
18
18
|
};
|
|
19
|
+
export declare function assertValidTextLogLevel(level: string | number): asserts level is LogLevelNames;
|
|
19
20
|
//# sourceMappingURL=log.d.ts.map
|
package/dist/log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA2BjE,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;AAIF,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,GAAG,MAAM,GACrB,OAAO,CAAC,KAAK,IAAI,aAAa,CAOhC"}
|
package/dist/log.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/unbound-method, putout/putout */
|
|
2
1
|
import loglevel from "loglevel";
|
|
3
2
|
import { Provable } from "o1js";
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
4
4
|
function logProvable(logFunction, ...args) {
|
|
5
5
|
Provable.asProver(() => {
|
|
6
6
|
const prettyArguments = [];
|
|
7
|
-
|
|
7
|
+
args.forEach((argument) => {
|
|
8
8
|
if (argument?.toPretty !== undefined) {
|
|
9
9
|
prettyArguments.push(argument.toPretty());
|
|
10
10
|
}
|
|
@@ -16,11 +16,11 @@ function logProvable(logFunction, ...args) {
|
|
|
16
16
|
prettyArguments.push(argument);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
}
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
19
|
+
});
|
|
21
20
|
logFunction(...prettyArguments);
|
|
22
21
|
});
|
|
23
22
|
}
|
|
23
|
+
/* eslint-enable */
|
|
24
24
|
export const log = {
|
|
25
25
|
provable: {
|
|
26
26
|
info: (...args) => {
|
|
@@ -66,3 +66,10 @@ export const log = {
|
|
|
66
66
|
},
|
|
67
67
|
getLevel: () => loglevel.getLevel(),
|
|
68
68
|
};
|
|
69
|
+
const validLogLevels = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "SILENT"];
|
|
70
|
+
export function assertValidTextLogLevel(level) {
|
|
71
|
+
if (typeof level === "number" ||
|
|
72
|
+
!validLogLevels.includes(level.toUpperCase())) {
|
|
73
|
+
throw new Error(`${level} is not a valid loglevel`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickmaths.d.ts","sourceRoot":"","sources":["../src/quickmaths.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAkBhD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the greatest common divisor of a and b
|
|
3
|
+
* @param a
|
|
4
|
+
* @param b
|
|
5
|
+
*/
|
|
6
|
+
export function gcd(a, b) {
|
|
7
|
+
a = Math.abs(a);
|
|
8
|
+
b = Math.abs(b);
|
|
9
|
+
if (b > a) {
|
|
10
|
+
a = b;
|
|
11
|
+
b = a;
|
|
12
|
+
}
|
|
13
|
+
while (a > 0 && b > 0) {
|
|
14
|
+
if (b === 0) {
|
|
15
|
+
return a;
|
|
16
|
+
}
|
|
17
|
+
a %= b;
|
|
18
|
+
if (a === 0) {
|
|
19
|
+
return b;
|
|
20
|
+
}
|
|
21
|
+
b %= a;
|
|
22
|
+
}
|
|
23
|
+
return 1;
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Field } from "o1js";
|
|
2
|
+
export declare function equalProvable(received: Field[], expected: Field[]): {
|
|
3
|
+
message: () => string;
|
|
4
|
+
pass: boolean;
|
|
5
|
+
};
|
|
6
|
+
interface CustomMatchers<R = void> {
|
|
7
|
+
equalProvable(expected: Field[]): R;
|
|
8
|
+
}
|
|
9
|
+
declare global {
|
|
10
|
+
namespace jest {
|
|
11
|
+
interface Expect extends CustomMatchers {
|
|
12
|
+
}
|
|
13
|
+
interface Matchers<R> extends CustomMatchers<R> {
|
|
14
|
+
}
|
|
15
|
+
interface InverseAsymmetricMatchers extends CustomMatchers {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=equalProvable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"equalProvable.d.ts","sourceRoot":"","sources":["../../src/test/equalProvable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,wBAAgB,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE;;;EAajE;AAMD,UAAU,cAAc,CAAC,CAAC,GAAG,IAAI;IAC/B,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;CACrC;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,IAAI,CAAC;QACb,UAAU,MAAO,SAAQ,cAAc;SAAG;QAC1C,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;SAAG;QAClD,UAAU,yBAA0B,SAAQ,cAAc;SAAG;KAC9D;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function equalProvable(received, expected) {
|
|
2
|
+
expect(received).toHaveLength(expected.length);
|
|
3
|
+
const receivedBigInts = received.map((f) => f.toBigInt());
|
|
4
|
+
const expectedBigInts = expected.map((f) => f.toBigInt());
|
|
5
|
+
const pass = receivedBigInts.every((v, index) => v === expectedBigInts[index]);
|
|
6
|
+
return {
|
|
7
|
+
message: () => `Expected ${expectedBigInts}, received ${receivedBigInts}`,
|
|
8
|
+
pass,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
expect.extend({
|
|
12
|
+
equalProvable,
|
|
13
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockAsyncMerkleStore.d.ts","sourceRoot":"","sources":["../../src/trees/MockAsyncMerkleStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MockAsyncMerkleStore.d.ts","sourceRoot":"","sources":["../../src/trees/MockAsyncMerkleStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,qBAAa,wBAAwB;IACnC,SAAgB,KAAK,4BAAmC;IAEjD,MAAM,IAAI,IAAI;IAId,eAAe,IAAI,IAAI;IAIjB,YAAY,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIjB,YAAY,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;CAGjB"}
|
|
@@ -2,27 +2,42 @@ import { Bool, Field } from "o1js";
|
|
|
2
2
|
import { TypedClass } from "../types";
|
|
3
3
|
import { MerkleTreeStore } from "./MerkleTreeStore";
|
|
4
4
|
declare const StructTemplate_base: (new (value: {
|
|
5
|
-
path: import("o1js/dist/node/lib/field").Field[];
|
|
6
|
-
isLeft: import("o1js/dist/node/lib/bool").Bool[];
|
|
5
|
+
path: import("o1js/dist/node/lib/provable/field").Field[];
|
|
6
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[];
|
|
7
7
|
}) => {
|
|
8
|
-
path: import("o1js/dist/node/lib/field").Field[];
|
|
9
|
-
isLeft: import("o1js/dist/node/lib/bool").Bool[];
|
|
8
|
+
path: import("o1js/dist/node/lib/provable/field").Field[];
|
|
9
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[];
|
|
10
10
|
}) & {
|
|
11
11
|
_isStruct: true;
|
|
12
|
-
} & import("o1js/dist/node/
|
|
13
|
-
path: import("o1js/dist/node/lib/field").Field[];
|
|
14
|
-
isLeft: import("o1js/dist/node/lib/bool").Bool[];
|
|
15
|
-
}
|
|
12
|
+
} & Omit<import("o1js/dist/node/lib/provable/types/provable-intf").Provable<{
|
|
13
|
+
path: import("o1js/dist/node/lib/provable/field").Field[];
|
|
14
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[];
|
|
15
|
+
}, {
|
|
16
|
+
path: bigint[];
|
|
17
|
+
isLeft: boolean[];
|
|
18
|
+
}>, "fromFields"> & {
|
|
19
|
+
fromFields: (fields: import("o1js/dist/node/lib/provable/field").Field[]) => {
|
|
20
|
+
path: import("o1js/dist/node/lib/provable/field").Field[];
|
|
21
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[];
|
|
22
|
+
};
|
|
23
|
+
} & {
|
|
24
|
+
fromValue: (value: {
|
|
25
|
+
path: import("o1js/dist/node/lib/provable/field").Field[] | bigint[];
|
|
26
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[] | boolean[];
|
|
27
|
+
}) => {
|
|
28
|
+
path: import("o1js/dist/node/lib/provable/field").Field[];
|
|
29
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[];
|
|
30
|
+
};
|
|
16
31
|
toInput: (x: {
|
|
17
|
-
path: import("o1js/dist/node/lib/field").Field[];
|
|
18
|
-
isLeft: import("o1js/dist/node/lib/bool").Bool[];
|
|
32
|
+
path: import("o1js/dist/node/lib/provable/field").Field[];
|
|
33
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[];
|
|
19
34
|
}) => {
|
|
20
|
-
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
|
21
|
-
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
|
35
|
+
fields?: import("o1js/dist/node/lib/provable/field").Field[] | undefined;
|
|
36
|
+
packed?: [import("o1js/dist/node/lib/provable/field").Field, number][] | undefined;
|
|
22
37
|
};
|
|
23
38
|
toJSON: (x: {
|
|
24
|
-
path: import("o1js/dist/node/lib/field").Field[];
|
|
25
|
-
isLeft: import("o1js/dist/node/lib/bool").Bool[];
|
|
39
|
+
path: import("o1js/dist/node/lib/provable/field").Field[];
|
|
40
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[];
|
|
26
41
|
}) => {
|
|
27
42
|
path: string[];
|
|
28
43
|
isLeft: boolean[];
|
|
@@ -31,8 +46,12 @@ declare const StructTemplate_base: (new (value: {
|
|
|
31
46
|
path: string[];
|
|
32
47
|
isLeft: boolean[];
|
|
33
48
|
}) => {
|
|
34
|
-
path: import("o1js/dist/node/lib/field").Field[];
|
|
35
|
-
isLeft: import("o1js/dist/node/lib/bool").Bool[];
|
|
49
|
+
path: import("o1js/dist/node/lib/provable/field").Field[];
|
|
50
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[];
|
|
51
|
+
};
|
|
52
|
+
empty: () => {
|
|
53
|
+
path: import("o1js/dist/node/lib/provable/field").Field[];
|
|
54
|
+
isLeft: import("o1js/dist/node/lib/provable/bool").Bool[];
|
|
36
55
|
};
|
|
37
56
|
};
|
|
38
57
|
declare class StructTemplate extends StructTemplate_base {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RollupMerkleTree.d.ts","sourceRoot":"","sources":["../../src/trees/RollupMerkleTree.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RollupMerkleTree.d.ts","sourceRoot":"","sources":["../../src/trees/RollupMerkleTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAA8B,MAAM,MAAM,CAAC;AAG/D,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGpD,cAAM,cAAe,SAAQ,mBAG3B;CAAG;AAEL,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,MAAM,IAAI,MAAM,CAAC;IAEjB;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC;IAElC;;;OAGG;IACH,cAAc,IAAI,KAAK,CAAC;IAExB,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAE7D,uBAAuB,CACrB,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,GACX,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAExB,kBAAkB,IAAI,MAAM,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC;;;;;OAKG;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,CAkOxE;;AAED,qBAAa,gBAAiB,SAAQ,qBAAqB;CAAG;AAC9D,qBAAa,uBAAwB,SAAQ,gBAAgB,CAAC,OAAO;CAAG"}
|
|
@@ -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
|
import { range } from "../utils";
|
|
8
3
|
import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
|
|
@@ -48,7 +43,8 @@ export function createMerkleTree(height) {
|
|
|
48
43
|
* @param leaf Value of the leaf node that belongs to this Witness.
|
|
49
44
|
* @returns The calculated root.
|
|
50
45
|
*/
|
|
51
|
-
calculateRoot(
|
|
46
|
+
calculateRoot(leaf) {
|
|
47
|
+
let hash = leaf;
|
|
52
48
|
const n = this.height();
|
|
53
49
|
for (let index = 1; index < n; ++index) {
|
|
54
50
|
const isLeft = this.isLeft[index - 1];
|
|
@@ -66,9 +62,8 @@ export function createMerkleTree(height) {
|
|
|
66
62
|
let powerOfTwo = Field(1);
|
|
67
63
|
let index = Field(0);
|
|
68
64
|
const n = this.height();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
index = Provable.if(this.isLeft[index_ - 1], index, index.add(powerOfTwo));
|
|
65
|
+
for (let i = 1; i < n; ++i) {
|
|
66
|
+
index = Provable.if(this.isLeft[i - 1], index, index.add(powerOfTwo));
|
|
72
67
|
powerOfTwo = powerOfTwo.mul(2);
|
|
73
68
|
}
|
|
74
69
|
return index;
|
|
@@ -168,19 +163,19 @@ export function createMerkleTree(height) {
|
|
|
168
163
|
this.assertIndexRange(index);
|
|
169
164
|
const path = [];
|
|
170
165
|
const isLefts = [];
|
|
166
|
+
let currentIndex = index;
|
|
171
167
|
for (let level = 0; level < AbstractRollupMerkleTree.HEIGHT - 1; level += 1) {
|
|
172
|
-
const isLeft =
|
|
173
|
-
const sibling = this.getNode(level, isLeft ?
|
|
168
|
+
const isLeft = currentIndex % 2n === 0n;
|
|
169
|
+
const sibling = this.getNode(level, isLeft ? currentIndex + 1n : currentIndex - 1n);
|
|
174
170
|
isLefts.push(Bool(isLeft));
|
|
175
171
|
path.push(sibling);
|
|
176
|
-
|
|
172
|
+
currentIndex /= 2n;
|
|
177
173
|
}
|
|
178
174
|
return new RollupMerkleWitness({
|
|
179
175
|
isLeft: isLefts,
|
|
180
176
|
path,
|
|
181
177
|
});
|
|
182
178
|
}
|
|
183
|
-
// eslint-disable-next-line no-warning-comments, max-len
|
|
184
179
|
// TODO: should this take an optional offset? should it fail if the array is too long?
|
|
185
180
|
/**
|
|
186
181
|
* Fills all leaves of the tree.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MerkleTreeStore } from "./MerkleTreeStore";
|
|
2
|
+
import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
|
|
3
|
+
/**
|
|
4
|
+
* A MemoryMerkleTreeStore that, if falls back to a parent store if it
|
|
5
|
+
* has no data
|
|
6
|
+
*/
|
|
7
|
+
export declare class VirtualMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
8
|
+
private readonly parent;
|
|
9
|
+
constructor(parent: MerkleTreeStore);
|
|
10
|
+
getNode(key: bigint, level: number): bigint | undefined;
|
|
11
|
+
setNode(key: bigint, level: number, value: bigint): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=VirtualMerkleTreeStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualMerkleTreeStore.d.ts","sourceRoot":"","sources":["../../src/trees/VirtualMerkleTreeStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,yBAAyB;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAIpD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIvD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAGhE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InMemoryMerkleTreeStorage } from "./InMemoryMerkleTreeStorage";
|
|
2
|
+
/**
|
|
3
|
+
* A MemoryMerkleTreeStore that, if falls back to a parent store if it
|
|
4
|
+
* has no data
|
|
5
|
+
*/
|
|
6
|
+
export class VirtualMerkleTreeStore extends InMemoryMerkleTreeStorage {
|
|
7
|
+
constructor(parent) {
|
|
8
|
+
super();
|
|
9
|
+
this.parent = parent;
|
|
10
|
+
}
|
|
11
|
+
getNode(key, level) {
|
|
12
|
+
return super.getNode(key, level) ?? this.parent.getNode(key, level);
|
|
13
|
+
}
|
|
14
|
+
setNode(key, level, value) {
|
|
15
|
+
super.setNode(key, level, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from "o1js";
|
|
2
2
|
export type TypedClass<Class> = new (...args: any[]) => Class;
|
|
3
|
-
export type UnTypedClass = new (...args: any[]) =>
|
|
3
|
+
export type UnTypedClass = new (...args: any[]) => unknown;
|
|
4
4
|
/**
|
|
5
5
|
* Using simple `keyof Target` would result into the key
|
|
6
6
|
* being `string | number | symbol`, but we want just a `string`
|
|
@@ -18,6 +18,9 @@ export type MergeObjects<Input extends Record<string, unknown>> = UnionToInterse
|
|
|
18
18
|
export type OmitKeys<Record, Keys> = {
|
|
19
19
|
[Key in keyof Record as Key extends Keys ? never : Key]: Record[Key];
|
|
20
20
|
};
|
|
21
|
-
export declare const EMPTY_PUBLICKEY_X: import("o1js/dist/node/lib/field").Field;
|
|
21
|
+
export declare const EMPTY_PUBLICKEY_X: import("o1js/dist/node/lib/provable/field").Field;
|
|
22
22
|
export declare const EMPTY_PUBLICKEY: PublicKey;
|
|
23
|
+
export type OverwriteObjectType<Base, New> = {
|
|
24
|
+
[Key in keyof Base]: Key extends keyof New ? New[Key] : Base[Key];
|
|
25
|
+
} & New;
|
|
23
26
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,SAAS,EAAE,MAAM,MAAM,CAAC;AAE9C,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,OAAO,CAAC;AAE3D;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,MAAM,IAAI,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC,GAC5E,MAAM,CAAC;AAET;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,SAAS,OAAO,EAAE,IAC3D,SAAS,SAAS,SAAS,CAAC,MAAM,WAAW,CAAC,EAAE,GAAG,WAAW,GAAG,KAAK,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,CACvC,KAAK,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,GAAG,KAAK,CAC/C,SAAS,CAAC,CAAC,EAAE,MAAM,YAAY,KAAK,IAAI,GACrC,YAAY,GACZ,KAAK,CAAC;AAEV,MAAM,MAAM,YAAY,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC5D,mBAAmB,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;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,mDAAc,CAAC;AAC7C,eAAO,MAAM,eAAe,WAG1B,CAAC;AAEH,MAAM,MAAM,mBAAmB,CAAC,IAAI,EAAE,GAAG,IAAI;KAC1C,GAAG,IAAI,MAAM,IAAI,GAAG,GAAG,SAAS,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;CAClE,GAAG,GAAG,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Field, FlexibleProvablePure } from "o1js";
|
|
1
|
+
import { Field, FlexibleProvablePure, DynamicProof, Proof } from "o1js";
|
|
2
2
|
export declare function requireTrue(condition: boolean, errorOrFunction: Error | (() => Error)): void;
|
|
3
|
-
export declare function range(startOrEnd: number,
|
|
3
|
+
export declare function range(startOrEnd: number, endOrNothing: number | undefined): number[];
|
|
4
|
+
export declare function reduceSequential<T, U>(array: T[], callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => Promise<U>, initialValue: U): Promise<U>;
|
|
5
|
+
export declare function mapSequential<T, R>(array: T[], f: (element: T, index: number, array: T[]) => Promise<R>): Promise<R[]>;
|
|
4
6
|
/**
|
|
5
7
|
* Computes a dummy value for the given value type.
|
|
6
8
|
*
|
|
@@ -18,13 +20,16 @@ export interface ToFieldableStatic {
|
|
|
18
20
|
export interface ToJSONableStatic {
|
|
19
21
|
toJSON: (value: unknown) => any;
|
|
20
22
|
}
|
|
21
|
-
export
|
|
22
|
-
publicOutputType?: ToFieldableStatic;
|
|
23
|
-
publicInputType?: ToFieldableStatic;
|
|
24
|
-
}
|
|
23
|
+
export type ProofTypes = typeof Proof<unknown, unknown> | typeof DynamicProof<unknown, unknown>;
|
|
25
24
|
export declare function sleep(ms: number): Promise<void>;
|
|
26
25
|
export declare function filterNonNull<Type>(value: Type | null): value is Type;
|
|
27
26
|
export declare function filterNonUndefined<Type>(value: Type | undefined): value is Type;
|
|
28
27
|
export declare function prefixToField(prefix: string): Field;
|
|
29
|
-
export declare function hashWithPrefix(prefix: string, input: Field[]): import("o1js/dist/node/lib/field").Field;
|
|
28
|
+
export declare function hashWithPrefix(prefix: string, input: Field[]): import("o1js/dist/node/lib/provable/field").Field;
|
|
29
|
+
export declare function expectDefined<T>(value: T | undefined): asserts value is T;
|
|
30
|
+
type NonMethodKeys<Type> = {
|
|
31
|
+
[Key in keyof Type]: Type[Key] extends Function ? never : Key;
|
|
32
|
+
}[keyof Type];
|
|
33
|
+
export type NonMethods<Type> = Pick<Type, NonMethodKeys<Type>>;
|
|
34
|
+
export {};
|
|
30
35
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,oBAAoB,EAEpB,YAAY,EACZ,KAAK,EACN,MAAM,MAAM,CAAC;AAEd,wBAAgB,WAAW,CACzB,SAAS,EAAE,OAAO,EAClB,eAAe,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GACrC,IAAI,CAMN;AAED,wBAAgB,KAAK,CACnB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,MAAM,EAAE,CAQV;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EACnC,KAAK,EAAE,CAAC,EAAE,EACV,UAAU,EAAE,CACV,aAAa,EAAE,CAAC,EAChB,YAAY,EAAE,CAAC,EACf,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,CAAC,EAAE,KACP,OAAO,CAAC,CAAC,CAAC,EACf,YAAY,EAAE,CAAC,cAShB;AAED,wBAAgB,aA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