@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
|
@@ -5,14 +5,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { container, injectable, injectWithTransform, Lifecycle, scoped, } from "tsyringe";
|
|
8
|
-
let UndefinedDisguise =
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
10
|
-
class UndefinedDisguise {
|
|
8
|
+
let UndefinedDisguise = class UndefinedDisguise {
|
|
11
9
|
};
|
|
12
10
|
UndefinedDisguise = __decorate([
|
|
13
11
|
injectable(),
|
|
14
12
|
scoped(Lifecycle.ResolutionScoped)
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
16
13
|
], UndefinedDisguise);
|
|
17
14
|
class UndefinedTransform {
|
|
18
15
|
transform(incoming) {
|
|
@@ -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,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAMxD,qBAAa,YAAY,CAAC,MAAM,SAAS,YAAY;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA+B;IAEzD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAGhB;IAEX,IAAI,CAAC,GAAG,SAAS,MAAM,MAAM,EAClC,KAAK,EAAE,GAAG,EACV,GAAG,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC;IAarB,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;IAIrE,EAAE,CAAC,GAAG,SAAS,MAAM,MAAM,EAChC,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;IAK1C;;;OAGG;IACI,GAAG,CAAC,GAAG,SAAS,MAAM,MAAM,EACjC,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;CAS3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventEmitterProxy.d.ts","sourceRoot":"","sources":["../../src/events/EventEmitterProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEhF,MAAM,MAAM,kBAAkB,CAAC,MAAM,IAAI,MAAM,SAAS,YAAY,GAChE,MAAM,GACN,EAAE,CAAC;AAEP,MAAM,MAAM,YAAY,CAAC,UAAU,SAAS,cAAc,IACxD,YAAY,CAAC,UAAU,CAAC,SAAS,sBAAsB,CAAC,MAAM,MAAM,CAAC,GACjE,MAAM,GACN,YAAY,CAAC,UAAU,CAAC,SAAS,eAAe,CAAC,MAAM,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"EventEmitterProxy.d.ts","sourceRoot":"","sources":["../../src/events/EventEmitterProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEhF,MAAM,MAAM,kBAAkB,CAAC,MAAM,IAAI,MAAM,SAAS,YAAY,GAChE,MAAM,GACN,EAAE,CAAC;AAEP,MAAM,MAAM,YAAY,CAAC,UAAU,SAAS,cAAc,IACxD,YAAY,CAAC,UAAU,CAAC,SAAS,sBAAsB,CAAC,MAAM,MAAM,CAAC,GACjE,MAAM,GACN,YAAY,CAAC,UAAU,CAAC,SAAS,eAAe,CAAC,MAAM,aAAa,CAAC,GACnE,kBAAkB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,GAClD,YAAY,CAAC;AAErB,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,aAAa,IAAI;KAC1D,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IACnE,mBAAmB,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC;AAE5C,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,aAAa,IAChE,aAAa,CAAC,eAAe,CAAC,OAAO,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/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,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+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,7 +18,7 @@ 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
23
|
export type OverwriteObjectType<Base, New> = {
|
|
24
24
|
[Key in keyof Base]: Key extends keyof New ? New[Key] : Base[Key];
|
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,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AAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,qDAO5D;AAID,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAEzE;AAED,KAAK,aAAa,CAAC,IAAI,IAAI;KACxB,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,QAAQ,GAAG,KAAK,GAAG,GAAG;CAC9D,CAAC,MAAM,IAAI,CAAC,CAAC;AACd,MAAM,MAAM,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC"}
|
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,12 +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>>)>;
|
|
20
|
-
analyzeMethods: ReturnType<typeof
|
|
23
|
+
analyzeMethods: () => Promise<Record<string, Awaited<ReturnType<typeof Provable.constraintSystem>>>>;
|
|
21
24
|
}
|
|
22
25
|
export declare function verifyToMockable<PublicInput, PublicOutput>(verify: Verify<PublicInput, PublicOutput>, { areProofsEnabled }: AreProofsEnabled): (proof: Proof<PublicInput, PublicOutput>) => Promise<boolean>;
|
|
23
|
-
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
|
+
};
|
|
24
30
|
export declare function compileToMockable(compile: Compile, { areProofsEnabled }: AreProofsEnabled): () => Promise<CompileArtifact>;
|
|
25
31
|
export declare abstract class ZkProgrammable<PublicInput = undefined, PublicOutput = void> {
|
|
26
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,gBA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