@proto-kit/common 0.1.1-develop.211 → 0.1.1-develop.2137
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/dist/cache/CacheManifest.d.ts +11 -0
- package/dist/cache/CacheManifest.d.ts.map +1 -0
- package/dist/cache/CacheManifest.js +56 -0
- package/dist/cache/CacheManifest.js.map +1 -0
- package/dist/cache/ProxyCache.d.ts +13 -0
- package/dist/cache/ProxyCache.d.ts.map +1 -0
- package/dist/cache/ProxyCache.js +24 -0
- package/dist/cache/ProxyCache.js.map +1 -0
- package/dist/cache/RemoteCache.d.ts +8 -0
- package/dist/cache/RemoteCache.d.ts.map +1 -0
- package/dist/cache/RemoteCache.js +2 -0
- package/dist/cache/RemoteCache.js.map +1 -0
- package/dist/cache/RemoteCacheCompiler.d.ts +16 -0
- package/dist/cache/RemoteCacheCompiler.d.ts.map +1 -0
- package/dist/cache/RemoteCacheCompiler.js +104 -0
- package/dist/cache/RemoteCacheCompiler.js.map +1 -0
- package/dist/compiling/AtomicCompileHelper.d.ts +15 -0
- package/dist/compiling/AtomicCompileHelper.d.ts.map +1 -0
- package/dist/compiling/AtomicCompileHelper.js +61 -0
- package/dist/compiling/AtomicCompileHelper.js.map +1 -0
- package/dist/compiling/CompilableModule.d.ts +6 -0
- package/dist/compiling/CompilableModule.d.ts.map +1 -0
- package/dist/compiling/CompilableModule.js +2 -0
- package/dist/compiling/CompilableModule.js.map +1 -0
- package/dist/compiling/CompileRegistry.d.ts +25 -0
- package/dist/compiling/CompileRegistry.d.ts.map +1 -0
- package/dist/compiling/CompileRegistry.js +62 -0
- package/dist/compiling/CompileRegistry.js.map +1 -0
- package/dist/compiling/services/ChildVerificationKeyService.d.ts +10 -0
- package/dist/compiling/services/ChildVerificationKeyService.d.ts.map +1 -0
- package/dist/compiling/services/ChildVerificationKeyService.js +27 -0
- package/dist/compiling/services/ChildVerificationKeyService.js.map +1 -0
- package/dist/config/ChildContainerCreatable.d.ts +5 -0
- package/dist/config/ChildContainerCreatable.d.ts.map +1 -0
- package/dist/config/ChildContainerCreatable.js +2 -0
- package/dist/config/ChildContainerCreatable.js.map +1 -0
- package/dist/config/ChildContainerProvider.d.ts +5 -0
- package/dist/config/ChildContainerProvider.d.ts.map +1 -0
- package/dist/config/ChildContainerProvider.js +2 -0
- package/dist/config/ChildContainerProvider.js.map +1 -0
- package/dist/config/ConfigurableModule.d.ts +6 -2
- package/dist/config/ConfigurableModule.d.ts.map +1 -1
- package/dist/config/ConfigurableModule.js +5 -0
- package/dist/config/ConfigurableModule.js.map +1 -0
- package/dist/config/ModuleContainer.d.ts +70 -23
- package/dist/config/ModuleContainer.d.ts.map +1 -1
- package/dist/config/ModuleContainer.js +164 -31
- package/dist/config/ModuleContainer.js.map +1 -0
- package/dist/config/Startable.d.ts +4 -0
- package/dist/config/Startable.d.ts.map +1 -0
- package/dist/config/Startable.js +2 -0
- package/dist/config/Startable.js.map +1 -0
- package/dist/config/injectAlias.d.ts +18 -0
- package/dist/config/injectAlias.d.ts.map +1 -0
- package/dist/config/injectAlias.js +47 -0
- package/dist/config/injectAlias.js.map +1 -0
- package/dist/dependencyFactory/DependencyFactory.d.ts +14 -9
- package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
- package/dist/dependencyFactory/DependencyFactory.js +2 -96
- package/dist/dependencyFactory/DependencyFactory.js.map +1 -0
- package/dist/dependencyFactory/injectOptional.d.ts +16 -0
- package/dist/dependencyFactory/injectOptional.d.ts.map +1 -0
- package/dist/dependencyFactory/injectOptional.js +40 -0
- package/dist/dependencyFactory/injectOptional.js.map +1 -0
- package/dist/dummyVerificationKey.d.ts +3 -0
- package/dist/dummyVerificationKey.d.ts.map +1 -0
- package/dist/dummyVerificationKey.js +8 -0
- package/dist/dummyVerificationKey.js.map +1 -0
- package/dist/events/EventEmitter.d.ts +19 -0
- package/dist/events/EventEmitter.d.ts.map +1 -0
- package/dist/events/EventEmitter.js +35 -0
- package/dist/events/EventEmitter.js.map +1 -0
- package/dist/events/EventEmitterProxy.d.ts +18 -0
- package/dist/events/EventEmitterProxy.d.ts.map +1 -0
- package/dist/events/EventEmitterProxy.js +35 -0
- package/dist/events/EventEmitterProxy.js.map +1 -0
- package/dist/events/EventEmittingComponent.d.ts +9 -0
- package/dist/events/EventEmittingComponent.d.ts.map +1 -0
- package/dist/events/EventEmittingComponent.js +2 -0
- package/dist/events/EventEmittingComponent.js.map +1 -0
- package/dist/events/ReplayingSingleUseEventEmitter.d.ts +17 -0
- package/dist/events/ReplayingSingleUseEventEmitter.d.ts.map +1 -0
- package/dist/events/ReplayingSingleUseEventEmitter.js +34 -0
- package/dist/events/ReplayingSingleUseEventEmitter.js.map +1 -0
- package/dist/index.d.ts +27 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +37 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +117 -0
- package/dist/log.js.map +1 -0
- package/dist/trees/InMemoryLinkedLeafStore.d.ts +21 -0
- package/dist/trees/InMemoryLinkedLeafStore.d.ts.map +1 -0
- package/dist/trees/InMemoryLinkedLeafStore.js +26 -0
- package/dist/trees/InMemoryLinkedLeafStore.js.map +1 -0
- package/dist/trees/InMemoryLinkedMerkleLeafStore.d.ts +7 -0
- package/dist/trees/InMemoryLinkedMerkleLeafStore.d.ts.map +1 -0
- package/dist/trees/InMemoryLinkedMerkleLeafStore.js +6 -0
- package/dist/trees/InMemoryLinkedMerkleLeafStore.js.map +1 -0
- package/dist/trees/InMemoryMerkleTreeStorage.d.ts +11 -0
- package/dist/trees/InMemoryMerkleTreeStorage.d.ts.map +1 -0
- package/dist/trees/InMemoryMerkleTreeStorage.js +13 -0
- package/dist/trees/InMemoryMerkleTreeStorage.js.map +1 -0
- package/dist/trees/LinkedMerkleTree.d.ts +345 -0
- package/dist/trees/LinkedMerkleTree.d.ts.map +1 -0
- package/dist/trees/LinkedMerkleTree.js +337 -0
- package/dist/trees/LinkedMerkleTree.js.map +1 -0
- package/dist/trees/LinkedMerkleTreeStore.d.ts +24 -0
- package/dist/trees/LinkedMerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/LinkedMerkleTreeStore.js +2 -0
- package/dist/trees/LinkedMerkleTreeStore.js.map +1 -0
- package/dist/trees/MerkleTreeStore.d.ts +5 -0
- package/dist/trees/MerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/MerkleTreeStore.js +2 -0
- package/dist/trees/MerkleTreeStore.js.map +1 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts +9 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts.map +1 -0
- package/dist/trees/MockAsyncMerkleStore.js +20 -0
- package/dist/trees/MockAsyncMerkleStore.js.map +1 -0
- package/dist/trees/RollupMerkleTree.d.ts +147 -0
- package/dist/trees/RollupMerkleTree.d.ts.map +1 -0
- package/dist/trees/RollupMerkleTree.js +218 -0
- package/dist/trees/RollupMerkleTree.js.map +1 -0
- package/dist/trees/VirtualMerkleTreeStore.d.ts +13 -0
- package/dist/trees/VirtualMerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/VirtualMerkleTreeStore.js +18 -0
- package/dist/trees/VirtualMerkleTreeStore.js.map +1 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts +288 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.d.ts.map +1 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.js +22 -0
- package/dist/trees/lmt/AbstractLinkedMerkleTree.js.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts +21 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.d.ts.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.js +26 -0
- package/dist/trees/lmt/InMemoryLinkedLeafStore.js.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.d.ts +7 -0
- package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.d.ts.map +1 -0
- package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.js +6 -0
- package/dist/trees/lmt/InMemoryLinkedMerkleLeafStore.js.map +1 -0
- package/dist/trees/lmt/LinkedLeafStore.d.ts +16 -0
- package/dist/trees/lmt/LinkedLeafStore.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedLeafStore.js +2 -0
- package/dist/trees/lmt/LinkedLeafStore.js.map +1 -0
- package/dist/trees/lmt/LinkedLinkedStore.d.ts +16 -0
- package/dist/trees/lmt/LinkedLinkedStore.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedLinkedStore.js +2 -0
- package/dist/trees/lmt/LinkedLinkedStore.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTree.d.ts +11 -0
- package/dist/trees/lmt/LinkedMerkleTree.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTree.js +241 -0
- package/dist/trees/lmt/LinkedMerkleTree.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts +113 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js +113 -0
- package/dist/trees/lmt/LinkedMerkleTreeCircuitOps.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeDatabase.d.ts +7 -0
- package/dist/trees/lmt/LinkedMerkleTreeDatabase.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeDatabase.js +2 -0
- package/dist/trees/lmt/LinkedMerkleTreeDatabase.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeStore.d.ts +16 -0
- package/dist/trees/lmt/LinkedMerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeStore.js +2 -0
- package/dist/trees/lmt/LinkedMerkleTreeStore.js.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts +74 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.d.ts.map +1 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.js +50 -0
- package/dist/trees/lmt/LinkedMerkleTreeTypes.js.map +1 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts +11 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.d.ts.map +1 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.js +13 -0
- package/dist/trees/sparse/InMemoryMerkleTreeStorage.js.map +1 -0
- package/dist/trees/sparse/MerkleTreeStore.d.ts +5 -0
- package/dist/trees/sparse/MerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/sparse/MerkleTreeStore.js +2 -0
- package/dist/trees/sparse/MerkleTreeStore.js.map +1 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.d.ts +9 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.d.ts.map +1 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.js +20 -0
- package/dist/trees/sparse/MockAsyncMerkleStore.js.map +1 -0
- package/dist/trees/sparse/RollupMerkleTree.d.ts +158 -0
- package/dist/trees/sparse/RollupMerkleTree.d.ts.map +1 -0
- package/dist/trees/sparse/RollupMerkleTree.js +330 -0
- package/dist/trees/sparse/RollupMerkleTree.js.map +1 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -1
- package/dist/types.js.map +1 -0
- package/dist/union/union.d.ts +177 -0
- package/dist/union/union.d.ts.map +1 -0
- package/dist/union/union.js +35 -0
- package/dist/union/union.js.map +1 -0
- package/dist/utils.d.ts +57 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +153 -4
- package/dist/utils.js.map +1 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +4 -3
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -1
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js +2 -3
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js.map +1 -0
- package/dist/zkProgrammable/ZkProgrammable.d.ts +32 -11
- package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
- package/dist/zkProgrammable/ZkProgrammable.js +36 -17
- package/dist/zkProgrammable/ZkProgrammable.js.map +1 -0
- package/dist/zkProgrammable/provableMethod.d.ts +7 -4
- package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
- package/dist/zkProgrammable/provableMethod.js +30 -14
- package/dist/zkProgrammable/provableMethod.js.map +1 -0
- package/jest.config.cjs +12 -1
- package/package.json +9 -7
- package/src/cache/CacheManifest.ts +57 -0
- package/src/cache/ProxyCache.ts +30 -0
- package/src/cache/RemoteCache.ts +9 -0
- package/src/cache/RemoteCacheCompiler.ts +131 -0
- package/src/compiling/AtomicCompileHelper.ts +71 -0
- package/src/compiling/CompilableModule.ts +6 -0
- package/src/compiling/CompileRegistry.ts +64 -0
- package/src/compiling/services/ChildVerificationKeyService.ts +26 -0
- package/src/config/ChildContainerCreatable.ts +5 -0
- package/src/config/ChildContainerProvider.ts +5 -0
- package/src/config/ConfigurableModule.ts +15 -2
- package/src/config/ModuleContainer.ts +286 -58
- package/src/config/Startable.ts +3 -0
- package/src/config/injectAlias.ts +70 -0
- package/src/dependencyFactory/DependencyFactory.ts +34 -109
- package/src/dummyVerificationKey.ts +10 -0
- package/src/events/EventEmitter.ts +61 -0
- package/src/events/EventEmitterProxy.ts +81 -0
- package/src/events/EventEmittingComponent.ts +11 -0
- package/src/events/ReplayingSingleUseEventEmitter.ts +42 -0
- package/src/index.ts +27 -2
- package/src/log.ts +145 -0
- package/src/trees/lmt/AbstractLinkedMerkleTree.ts +102 -0
- package/src/trees/lmt/InMemoryLinkedLeafStore.ts +42 -0
- package/src/trees/lmt/LinkedLeafStore.ts +13 -0
- package/src/trees/lmt/LinkedMerkleTree.ts +335 -0
- package/src/trees/lmt/LinkedMerkleTreeCircuitOps.ts +188 -0
- package/src/trees/lmt/LinkedMerkleTreeTypes.ts +53 -0
- package/src/trees/sparse/InMemoryMerkleTreeStorage.ts +17 -0
- package/src/trees/sparse/MerkleTreeStore.ts +5 -0
- package/src/trees/sparse/MockAsyncMerkleStore.ts +30 -0
- package/src/trees/sparse/RollupMerkleTree.ts +512 -0
- package/src/types.ts +53 -2
- package/src/utils.ts +281 -5
- package/src/zkProgrammable/ProvableMethodExecutionContext.ts +6 -6
- package/src/zkProgrammable/ZkProgrammable.ts +90 -35
- package/src/zkProgrammable/provableMethod.ts +50 -23
- package/test/config/ContainerEvents.test.ts +65 -0
- package/test/config/ModuleContainer.test.ts +146 -15
- package/test/config/injectAlias.test.ts +28 -0
- package/test/trees/LinkedMerkleTree.test.ts +124 -0
- package/test/trees/LinkedMerkleTreeCircuitOps.test.ts +147 -0
- package/test/trees/MerkleTree.test.ts +251 -0
- package/test/tsconfig.json +5 -2
- package/test/zkProgrammable/ZkProgrammable.test.ts +145 -119
- package/tsconfig.json +1 -1
- package/LICENSE.md +0 -201
- package/tsconfig.test.json +0 -9
package/package.json
CHANGED
|
@@ -3,32 +3,34 @@
|
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.1.1-develop.
|
|
6
|
+
"version": "0.1.1-develop.2137+8a7eca31",
|
|
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
|
-
"test:file": "node --experimental-vm-modules --experimental-wasm-modules
|
|
12
|
-
"test": "npm run test:file -- ./
|
|
13
|
-
"test:watch": "npm run test:file -- ./
|
|
11
|
+
"test:file": "node --experimental-vm-modules --experimental-wasm-modules ../../node_modules/jest/bin/jest.js",
|
|
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": {
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"cachedir": "^2.4.0",
|
|
20
21
|
"lodash": "^4.17.21",
|
|
21
22
|
"loglevel": "^1.8.1",
|
|
22
23
|
"reflect-metadata": "^0.1.13",
|
|
24
|
+
"ts-mixer": "^6.0.3",
|
|
23
25
|
"typescript-memoize": "^1.1.1"
|
|
24
26
|
},
|
|
25
27
|
"peerDependencies": {
|
|
26
|
-
"
|
|
27
|
-
"tsyringe": "^4.
|
|
28
|
+
"o1js": "^2.10.0",
|
|
29
|
+
"tsyringe": "^4.10.0"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
32
|
"@jest/globals": "^29.5.0",
|
|
31
33
|
"@types/lodash": "^4.14.194"
|
|
32
34
|
},
|
|
33
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8a7eca319272a15162dc4ad04bdc134b1017716d"
|
|
34
36
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
|
|
4
|
+
import { injectable, singleton } from "tsyringe";
|
|
5
|
+
import cachedir from "cachedir";
|
|
6
|
+
|
|
7
|
+
@injectable()
|
|
8
|
+
@singleton()
|
|
9
|
+
export class CacheManifest {
|
|
10
|
+
public manifestFile(): string {
|
|
11
|
+
return path.format({
|
|
12
|
+
dir: cachedir("o1js"),
|
|
13
|
+
name: "protokit-cache-manifest",
|
|
14
|
+
ext: "json",
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
manifestRead = false;
|
|
19
|
+
|
|
20
|
+
manifest: string[] = [];
|
|
21
|
+
|
|
22
|
+
private readManifest(): string[] {
|
|
23
|
+
const file = this.manifestFile();
|
|
24
|
+
if (fs.existsSync(file)) {
|
|
25
|
+
return JSON.parse(fs.readFileSync(file).toString());
|
|
26
|
+
}
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private ensureManifestRead() {
|
|
31
|
+
if (!this.manifestRead) {
|
|
32
|
+
this.manifest = this.readManifest();
|
|
33
|
+
this.manifestRead = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public getManifest() {
|
|
38
|
+
this.ensureManifestRead();
|
|
39
|
+
|
|
40
|
+
return this.manifest;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public writeToManifest(program: string) {
|
|
44
|
+
this.ensureManifestRead();
|
|
45
|
+
|
|
46
|
+
if (!this.manifest.includes(program)) {
|
|
47
|
+
this.manifest.push(program);
|
|
48
|
+
fs.writeFileSync(this.manifestFile(), JSON.stringify(this.manifest));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public includes(program: string): boolean {
|
|
53
|
+
this.ensureManifestRead();
|
|
54
|
+
|
|
55
|
+
return this.manifest.includes(program);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CacheHeader, Cache as O1Cache } from "o1js";
|
|
2
|
+
|
|
3
|
+
export class ProxyCache implements O1Cache {
|
|
4
|
+
private realCache = O1Cache.FileSystemDefault;
|
|
5
|
+
|
|
6
|
+
private log: string[] = [];
|
|
7
|
+
|
|
8
|
+
canWrite = true;
|
|
9
|
+
|
|
10
|
+
debug = false;
|
|
11
|
+
|
|
12
|
+
cacheDirectory = this.realCache.cacheDirectory;
|
|
13
|
+
|
|
14
|
+
public read(header: CacheHeader): Uint8Array | undefined {
|
|
15
|
+
return this.realCache.read(header);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public write(header: CacheHeader, value: Uint8Array): void {
|
|
19
|
+
this.log.push(header.persistentId);
|
|
20
|
+
return this.realCache.write(header, value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public getLog() {
|
|
24
|
+
return this.log;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public startLog() {
|
|
28
|
+
this.log = [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
|
|
3
|
+
export interface RemoteCache {
|
|
4
|
+
storeObject(program: string, object: string, file: Readable): Promise<void>;
|
|
5
|
+
|
|
6
|
+
getObjects(program: string): Promise<string[]>;
|
|
7
|
+
|
|
8
|
+
readObject(program: string, object: string): Promise<Readable>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { inject, injectable, Lifecycle, scoped } from "tsyringe";
|
|
5
|
+
import cachedir from "cachedir";
|
|
6
|
+
|
|
7
|
+
import { log } from "../log";
|
|
8
|
+
import { mapSequential } from "../utils";
|
|
9
|
+
import {
|
|
10
|
+
CompileArtifact,
|
|
11
|
+
PlainZkProgram,
|
|
12
|
+
} from "../zkProgrammable/ZkProgrammable";
|
|
13
|
+
|
|
14
|
+
import { RemoteCache } from "./RemoteCache";
|
|
15
|
+
import { ProxyCache } from "./ProxyCache";
|
|
16
|
+
import { CacheManifest } from "./CacheManifest";
|
|
17
|
+
|
|
18
|
+
@injectable()
|
|
19
|
+
@scoped(Lifecycle.ContainerScoped)
|
|
20
|
+
export class RemoteCacheCompiler {
|
|
21
|
+
public constructor(
|
|
22
|
+
@inject("RemoteCache", { isOptional: true })
|
|
23
|
+
private readonly remoteCache: RemoteCache | undefined,
|
|
24
|
+
private readonly manifest: CacheManifest
|
|
25
|
+
) {
|
|
26
|
+
if (remoteCache === undefined) {
|
|
27
|
+
log.debug(
|
|
28
|
+
"No remote cache configured, only using local file system cache for circuits"
|
|
29
|
+
);
|
|
30
|
+
} else {
|
|
31
|
+
log.debug("Using remote cache for circuit caching");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private getFileFromObjectName(object: string): string {
|
|
36
|
+
const dir = cachedir("o1js");
|
|
37
|
+
|
|
38
|
+
return path.format({
|
|
39
|
+
dir,
|
|
40
|
+
base: object,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private async download(remoteCache: RemoteCache, name: string) {
|
|
45
|
+
const objects = await remoteCache.getObjects(name);
|
|
46
|
+
|
|
47
|
+
log.debug(`Downloading ${objects.length} cached objects for ${name}`);
|
|
48
|
+
|
|
49
|
+
await mapSequential(objects, async (object) => {
|
|
50
|
+
const readable = await remoteCache.readObject(name, object);
|
|
51
|
+
const file = this.getFileFromObjectName(object);
|
|
52
|
+
|
|
53
|
+
const writeStream = fs.createWriteStream(file);
|
|
54
|
+
readable.pipe(writeStream);
|
|
55
|
+
|
|
56
|
+
await new Promise<void>((res) => {
|
|
57
|
+
writeStream.on("close", res);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private async uploadFile(
|
|
63
|
+
remoteCache: RemoteCache,
|
|
64
|
+
program: string,
|
|
65
|
+
fileName: string
|
|
66
|
+
) {
|
|
67
|
+
const file = path.resolve(cachedir("o1js"), fileName);
|
|
68
|
+
const readStream = fs.createReadStream(file);
|
|
69
|
+
await remoteCache.storeObject(program, fileName, readStream);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private async upload(
|
|
73
|
+
remoteCache: RemoteCache,
|
|
74
|
+
name: string,
|
|
75
|
+
identifiers: string[]
|
|
76
|
+
) {
|
|
77
|
+
await mapSequential(identifiers, async (identifier) => {
|
|
78
|
+
await this.uploadFile(remoteCache, name, identifier);
|
|
79
|
+
await this.uploadFile(remoteCache, name, `${identifier}.header`);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private isSRSFile(file: string): boolean {
|
|
84
|
+
return file.includes("srs-") || file.includes("lagrange-");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async compileWithRemoteCache(
|
|
88
|
+
remoteCache: RemoteCache,
|
|
89
|
+
program: Pick<PlainZkProgram, "name" | "compile">
|
|
90
|
+
) {
|
|
91
|
+
const { name } = program;
|
|
92
|
+
|
|
93
|
+
if (!this.manifest.includes("srs")) {
|
|
94
|
+
await this.download(remoteCache, "srs");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!this.manifest.includes(name)) {
|
|
98
|
+
await this.download(remoteCache, name);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const cache = new ProxyCache();
|
|
102
|
+
cache.startLog();
|
|
103
|
+
|
|
104
|
+
const result = await program.compile({
|
|
105
|
+
cache,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const files = cache.getLog();
|
|
109
|
+
log.debug("Uploading files", files);
|
|
110
|
+
|
|
111
|
+
const srsFiles = files.filter((file) => this.isSRSFile(file));
|
|
112
|
+
await this.upload(remoteCache, "srs", srsFiles);
|
|
113
|
+
this.manifest.writeToManifest("srs");
|
|
114
|
+
|
|
115
|
+
const circuitFiles = files.filter((file) => !this.isSRSFile(file));
|
|
116
|
+
await this.upload(remoteCache, name, circuitFiles);
|
|
117
|
+
this.manifest.writeToManifest(name);
|
|
118
|
+
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public async compileWithCache(
|
|
123
|
+
program: Pick<PlainZkProgram, "name" | "compile">
|
|
124
|
+
): Promise<CompileArtifact> {
|
|
125
|
+
if (this.remoteCache !== undefined) {
|
|
126
|
+
return await this.compileWithRemoteCache(this.remoteCache, program);
|
|
127
|
+
} else {
|
|
128
|
+
return await program.compile();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { inject, injectable } from "tsyringe";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AreProofsEnabled,
|
|
5
|
+
CompileArtifact,
|
|
6
|
+
MOCK_VERIFICATION_KEY,
|
|
7
|
+
} from "../zkProgrammable/ZkProgrammable";
|
|
8
|
+
import { isSubtypeOfName } from "../utils";
|
|
9
|
+
import { TypedClass } from "../types";
|
|
10
|
+
import { log } from "../log";
|
|
11
|
+
import { RemoteCacheCompiler } from "../cache/RemoteCacheCompiler";
|
|
12
|
+
|
|
13
|
+
export type ArtifactRecord = Record<string, CompileArtifact>;
|
|
14
|
+
|
|
15
|
+
export type CompileTarget = {
|
|
16
|
+
name: string;
|
|
17
|
+
compile: () => Promise<CompileArtifact>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
@injectable()
|
|
21
|
+
export class AtomicCompileHelper {
|
|
22
|
+
public constructor(
|
|
23
|
+
@inject("AreProofsEnabled")
|
|
24
|
+
private readonly areProofsEnabled: AreProofsEnabled,
|
|
25
|
+
private readonly remoteCacheCompiler: RemoteCacheCompiler
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
private compilationPromises: {
|
|
29
|
+
[key: string]: Promise<CompileArtifact>;
|
|
30
|
+
} = {};
|
|
31
|
+
|
|
32
|
+
public async compileContract(
|
|
33
|
+
contract: CompileTarget,
|
|
34
|
+
overrideProofsEnabled?: boolean
|
|
35
|
+
): Promise<CompileArtifact> {
|
|
36
|
+
let newPromise = false;
|
|
37
|
+
const { name } = contract;
|
|
38
|
+
if (this.compilationPromises[name] === undefined) {
|
|
39
|
+
const proofsEnabled =
|
|
40
|
+
overrideProofsEnabled ?? this.areProofsEnabled.areProofsEnabled;
|
|
41
|
+
|
|
42
|
+
// We only care about proofs enabled here if it's a contract, because
|
|
43
|
+
// in all other cases, ZkProgrammable already handles this switch, and we
|
|
44
|
+
// want to preserve the artifact layout (which might be more than one
|
|
45
|
+
// entry for ZkProgrammables)
|
|
46
|
+
if (
|
|
47
|
+
proofsEnabled ||
|
|
48
|
+
!isSubtypeOfName(
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
50
|
+
contract as unknown as TypedClass<any>,
|
|
51
|
+
"SmartContract"
|
|
52
|
+
)
|
|
53
|
+
) {
|
|
54
|
+
log.time(`Compiling ${name}`);
|
|
55
|
+
this.compilationPromises[name] =
|
|
56
|
+
this.remoteCacheCompiler.compileWithCache(contract);
|
|
57
|
+
newPromise = true;
|
|
58
|
+
} else {
|
|
59
|
+
log.debug(`Compiling ${name} - mock`);
|
|
60
|
+
this.compilationPromises[name] = Promise.resolve({
|
|
61
|
+
verificationKey: MOCK_VERIFICATION_KEY,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const result = await this.compilationPromises[name];
|
|
66
|
+
if (newPromise) {
|
|
67
|
+
log.timeEnd.info(`Compiling ${name}`);
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { injectable, singleton } from "tsyringe";
|
|
2
|
+
|
|
3
|
+
import { CompileArtifact } from "../zkProgrammable/ZkProgrammable";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
ArtifactRecord,
|
|
7
|
+
AtomicCompileHelper,
|
|
8
|
+
CompileTarget,
|
|
9
|
+
} from "./AtomicCompileHelper";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The CompileRegistry compiles "compilable modules"
|
|
13
|
+
* (i.e. zkprograms, contracts or contractmodules)
|
|
14
|
+
* while making sure they don't get compiled twice in the same process in parallel.
|
|
15
|
+
*/
|
|
16
|
+
@injectable()
|
|
17
|
+
@singleton()
|
|
18
|
+
export class CompileRegistry {
|
|
19
|
+
public constructor(private readonly compiler: AtomicCompileHelper) {}
|
|
20
|
+
|
|
21
|
+
private artifacts: ArtifactRecord = {};
|
|
22
|
+
|
|
23
|
+
private inForceProverBlock = 0;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This function forces compilation even if the artifact itself is in the registry.
|
|
27
|
+
* Basically the statement is: The artifact along is not enough, we need to
|
|
28
|
+
* actually have the prover compiled.
|
|
29
|
+
* This is true for non-sideloaded circuit dependencies.
|
|
30
|
+
*/
|
|
31
|
+
public async forceProverExists<R>(
|
|
32
|
+
f: (registry: CompileRegistry) => Promise<R>
|
|
33
|
+
): Promise<R> {
|
|
34
|
+
this.inForceProverBlock += 1;
|
|
35
|
+
const result = await f(this);
|
|
36
|
+
this.inForceProverBlock -= 1;
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public async compile(target: CompileTarget, nameOverride?: string) {
|
|
41
|
+
const name = nameOverride ?? target.name;
|
|
42
|
+
if (this.artifacts[name] === undefined || this.inForceProverBlock > 0) {
|
|
43
|
+
const artifact = await this.compiler.compileContract(target);
|
|
44
|
+
this.artifacts[name] = artifact;
|
|
45
|
+
return artifact;
|
|
46
|
+
}
|
|
47
|
+
return this.artifacts[name];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public getArtifact(name: string): CompileArtifact | undefined {
|
|
51
|
+
return this.artifacts[name];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public addArtifactsRaw(artifacts: ArtifactRecord) {
|
|
55
|
+
this.artifacts = {
|
|
56
|
+
...this.artifacts,
|
|
57
|
+
...artifacts,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public getAllArtifacts() {
|
|
62
|
+
return this.artifacts;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { injectable, Lifecycle, scoped } from "tsyringe";
|
|
2
|
+
|
|
3
|
+
import { CompileRegistry } from "../CompileRegistry";
|
|
4
|
+
|
|
5
|
+
@injectable()
|
|
6
|
+
@scoped(Lifecycle.ContainerScoped)
|
|
7
|
+
export class ChildVerificationKeyService {
|
|
8
|
+
private compileRegistry?: CompileRegistry;
|
|
9
|
+
|
|
10
|
+
public setCompileRegistry(registry: CompileRegistry) {
|
|
11
|
+
this.compileRegistry = registry;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public getVerificationKey(name: string) {
|
|
15
|
+
if (this.compileRegistry === undefined) {
|
|
16
|
+
throw new Error("CompileRegistry hasn't been set yet");
|
|
17
|
+
}
|
|
18
|
+
const artifact = this.compileRegistry.getArtifact(name);
|
|
19
|
+
if (artifact === undefined) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Verification Key for child program ${name} not found in registry`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return artifact.verificationKey;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { noop } from "../utils";
|
|
2
|
+
|
|
3
|
+
import { ChildContainerProvider } from "./ChildContainerProvider";
|
|
4
|
+
import type { BaseModuleInstanceType } from "./ModuleContainer";
|
|
5
|
+
|
|
1
6
|
const errors = {
|
|
2
7
|
configNotSet: (moduleName: string) =>
|
|
3
8
|
new Error(
|
|
@@ -6,7 +11,7 @@ const errors = {
|
|
|
6
11
|
};
|
|
7
12
|
|
|
8
13
|
// defines how presets can be provided, either a function or a record
|
|
9
|
-
export type Preset<Config> = Config | ((...args:
|
|
14
|
+
export type Preset<Config> = Config | ((...args: unknown[]) => Config);
|
|
10
15
|
export type Presets<Config> = Record<string, Preset<Config>>;
|
|
11
16
|
|
|
12
17
|
// describes the interface of a configurable module
|
|
@@ -14,10 +19,14 @@ export interface Configurable<Config> {
|
|
|
14
19
|
config: Config;
|
|
15
20
|
}
|
|
16
21
|
|
|
22
|
+
export type NoConfig = Record<never, never>;
|
|
23
|
+
|
|
17
24
|
/**
|
|
18
25
|
* Used by various module sub-types that may need to be configured
|
|
19
26
|
*/
|
|
20
|
-
export class ConfigurableModule<Config
|
|
27
|
+
export class ConfigurableModule<Config = NoConfig>
|
|
28
|
+
implements BaseModuleInstanceType
|
|
29
|
+
{
|
|
21
30
|
/**
|
|
22
31
|
* Store the config separately, so that we can apply additional
|
|
23
32
|
* checks when retrieving it via the getter
|
|
@@ -36,6 +45,10 @@ export class ConfigurableModule<Config> implements Configurable<Config> {
|
|
|
36
45
|
public set config(config: Config) {
|
|
37
46
|
this.currentConfig = config;
|
|
38
47
|
}
|
|
48
|
+
|
|
49
|
+
public create(childContainerProvider: ChildContainerProvider): void {
|
|
50
|
+
noop();
|
|
51
|
+
}
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
// Helps ensure that the target class implements static presets
|