zkcloudworker 0.6.3 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/ts/src/api/api.js +3 -1
- package/lib/ts/src/cloud/cloud.d.ts +2 -3
- package/lib/ts/src/cloud/index.d.ts +0 -1
- package/lib/ts/src/cloud/index.js +0 -1
- package/lib/ts/src/cloud/local.d.ts +1 -2
- package/lib/ts/src/cloud/local.js +7 -8
- package/lib/ts/tsconfig.tsbuildinfo +1 -1
- package/lib/web/src/api/api.js +3 -1
- package/lib/web/src/api/api.js.map +1 -1
- package/lib/web/src/cloud/cloud.d.ts +2 -3
- package/lib/web/src/cloud/cloud.js.map +1 -1
- package/lib/web/src/cloud/index.d.ts +0 -1
- package/lib/web/src/cloud/index.js +0 -1
- package/lib/web/src/cloud/index.js.map +1 -1
- package/lib/web/src/cloud/local.d.ts +1 -2
- package/lib/web/src/cloud/local.js +7 -8
- package/lib/web/src/cloud/local.js.map +1 -1
- package/lib/web/tsconfig.web.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/lib/ts/src/cloud/cache.d.ts +0 -97
- package/lib/ts/src/cloud/cache.js +0 -98
- package/lib/web/src/cloud/cache.d.ts +0 -97
- package/lib/web/src/cloud/cache.js +0 -97
- package/lib/web/src/cloud/cache.js.map +0 -1
@@ -1,98 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Cache = void 0;
|
4
|
-
const node_fs_1 = require("node:fs");
|
5
|
-
const node_path_1 = require("node:path");
|
6
|
-
const jsEnvironment = "node";
|
7
|
-
const cacheHeaderVersion = 1;
|
8
|
-
function withVersion(header, version = cacheHeaderVersion) {
|
9
|
-
let uniqueId = `${header.uniqueId}-${version}`;
|
10
|
-
return { ...header, version, uniqueId };
|
11
|
-
}
|
12
|
-
function readCache(cache, header, transform) {
|
13
|
-
try {
|
14
|
-
let result = cache.read(header);
|
15
|
-
if (result === undefined) {
|
16
|
-
if (cache.debug)
|
17
|
-
console.trace("cache miss");
|
18
|
-
return undefined;
|
19
|
-
}
|
20
|
-
if (transform === undefined)
|
21
|
-
return result;
|
22
|
-
return transform(result);
|
23
|
-
}
|
24
|
-
catch (e) {
|
25
|
-
if (cache.debug)
|
26
|
-
console.log("Failed to read cache", e);
|
27
|
-
return undefined;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
function writeCache(cache, header, value) {
|
31
|
-
if (!cache.canWrite)
|
32
|
-
return false;
|
33
|
-
try {
|
34
|
-
cache.write(header, value);
|
35
|
-
return true;
|
36
|
-
}
|
37
|
-
catch (e) {
|
38
|
-
if (cache.debug)
|
39
|
-
console.log("Failed to write cache", e);
|
40
|
-
return false;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
const None = {
|
44
|
-
read() {
|
45
|
-
throw Error("not available");
|
46
|
-
},
|
47
|
-
write() {
|
48
|
-
throw Error("not available");
|
49
|
-
},
|
50
|
-
canWrite: false,
|
51
|
-
};
|
52
|
-
const FileSystem = (cacheDirectory, debug) => ({
|
53
|
-
read({ persistentId, uniqueId, dataType }) {
|
54
|
-
if (jsEnvironment !== "node")
|
55
|
-
throw Error("file system not available");
|
56
|
-
// read current uniqueId, return data if it matches
|
57
|
-
let currentId = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(cacheDirectory, `${persistentId}.header`), "utf8");
|
58
|
-
if (currentId !== uniqueId)
|
59
|
-
return undefined;
|
60
|
-
if (dataType === "string") {
|
61
|
-
let string = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(cacheDirectory, persistentId), "utf8");
|
62
|
-
return new TextEncoder().encode(string);
|
63
|
-
}
|
64
|
-
else {
|
65
|
-
let buffer = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(cacheDirectory, persistentId));
|
66
|
-
return new Uint8Array(buffer.buffer);
|
67
|
-
}
|
68
|
-
},
|
69
|
-
write({ persistentId, uniqueId, dataType }, data) {
|
70
|
-
if (jsEnvironment !== "node")
|
71
|
-
throw Error("file system not available");
|
72
|
-
(0, node_fs_1.mkdirSync)(cacheDirectory, { recursive: true });
|
73
|
-
(0, node_fs_1.writeFileSync)((0, node_path_1.resolve)(cacheDirectory, `${persistentId}.header`), uniqueId, {
|
74
|
-
encoding: "utf8",
|
75
|
-
});
|
76
|
-
(0, node_fs_1.writeFileSync)((0, node_path_1.resolve)(cacheDirectory, persistentId), data, {
|
77
|
-
encoding: dataType === "string" ? "utf8" : undefined,
|
78
|
-
});
|
79
|
-
},
|
80
|
-
canWrite: jsEnvironment === "node",
|
81
|
-
debug,
|
82
|
-
});
|
83
|
-
const Cache = {
|
84
|
-
/**
|
85
|
-
* Store data on the file system, in a directory of your choice.
|
86
|
-
*
|
87
|
-
* Data will be stored in two files per cache entry: a data file and a `.header` file.
|
88
|
-
* The header file just contains a unique string which is used to determine whether we can use the cached data.
|
89
|
-
*
|
90
|
-
* Note: this {@link Cache} only caches data in Node.js.
|
91
|
-
*/
|
92
|
-
FileSystem,
|
93
|
-
/**
|
94
|
-
* Don't store anything.
|
95
|
-
*/
|
96
|
-
None,
|
97
|
-
};
|
98
|
-
exports.Cache = Cache;
|
@@ -1,97 +0,0 @@
|
|
1
|
-
export { Cache };
|
2
|
-
/**
|
3
|
-
* Interface for storing and retrieving values, for caching.
|
4
|
-
* `read()` and `write()` can just throw errors on failure.
|
5
|
-
*
|
6
|
-
* The data that will be passed to the cache for writing is exhaustively described by the {@link CacheHeader} type.
|
7
|
-
* It represents one of the following:
|
8
|
-
* - The SRS. This is a deterministic lists of curve points (one per curve) that needs to be generated just once,
|
9
|
-
* to be used for polynomial commitments.
|
10
|
-
* - Lagrange basis commitments. Similar to the SRS, this will be created once for every power-of-2 circuit size.
|
11
|
-
* - Prover and verifier keys for every compiled circuit.
|
12
|
-
*
|
13
|
-
* Per smart contract or ZkProgram, several different keys are created:
|
14
|
-
* - a step prover key (`step-pk`) and verification key (`step-vk`) _for every method_.
|
15
|
-
* - a wrap prover key (`wrap-pk`) and verification key (`wrap-vk`) for the entire contract.
|
16
|
-
*/
|
17
|
-
type Cache = {
|
18
|
-
/**
|
19
|
-
* Read a value from the cache.
|
20
|
-
*
|
21
|
-
* @param header A small header to identify what is read from the cache.
|
22
|
-
*/
|
23
|
-
read(header: CacheHeader): Uint8Array | undefined;
|
24
|
-
/**
|
25
|
-
* Write a value to the cache.
|
26
|
-
*
|
27
|
-
* @param header A small header to identify what is written to the cache. This will be used by `read()` to retrieve the data.
|
28
|
-
* @param value The value to write to the cache, as a byte array.
|
29
|
-
*/
|
30
|
-
write(header: CacheHeader, value: Uint8Array): void;
|
31
|
-
/**
|
32
|
-
* Indicates whether the cache is writable.
|
33
|
-
*/
|
34
|
-
canWrite: boolean;
|
35
|
-
/**
|
36
|
-
* If `debug` is toggled, `read()` and `write()` errors are logged to the console.
|
37
|
-
*
|
38
|
-
* By default, cache errors are silent, because they don't necessarily represent an error condition,
|
39
|
-
* but could just be a cache miss, or file system permissions incompatible with writing data.
|
40
|
-
*/
|
41
|
-
debug?: boolean;
|
42
|
-
};
|
43
|
-
type CommonHeader = {
|
44
|
-
/**
|
45
|
-
* Header version to avoid parsing incompatible headers.
|
46
|
-
*/
|
47
|
-
version: number;
|
48
|
-
/**
|
49
|
-
* An identifier that is persistent even as versions of the data change. Safe to use as a file path.
|
50
|
-
*/
|
51
|
-
persistentId: string;
|
52
|
-
/**
|
53
|
-
* A unique identifier for the data to be read. Safe to use as a file path.
|
54
|
-
*/
|
55
|
-
uniqueId: string;
|
56
|
-
/**
|
57
|
-
* Specifies whether the data to be read is a utf8-encoded string or raw binary data. This was added
|
58
|
-
* because node's `fs.readFileSync` returns garbage when reading string files without specifying the encoding.
|
59
|
-
*/
|
60
|
-
dataType: "string" | "bytes";
|
61
|
-
};
|
62
|
-
type StepKeyHeader<Kind> = {
|
63
|
-
kind: Kind;
|
64
|
-
programName: string;
|
65
|
-
methodName: string;
|
66
|
-
methodIndex: number;
|
67
|
-
hash: string;
|
68
|
-
};
|
69
|
-
type WrapKeyHeader<Kind> = {
|
70
|
-
kind: Kind;
|
71
|
-
programName: string;
|
72
|
-
hash: string;
|
73
|
-
};
|
74
|
-
type PlainHeader<Kind> = {
|
75
|
-
kind: Kind;
|
76
|
-
};
|
77
|
-
/**
|
78
|
-
* A header that is passed to the caching layer, to support rich caching strategies.
|
79
|
-
*
|
80
|
-
* Both `uniqueId` and `programId` can safely be used as a file path.
|
81
|
-
*/
|
82
|
-
type CacheHeader = (StepKeyHeader<"step-pk"> | StepKeyHeader<"step-vk"> | WrapKeyHeader<"wrap-pk"> | WrapKeyHeader<"wrap-vk"> | PlainHeader<"srs"> | PlainHeader<"lagrange-basis">) & CommonHeader;
|
83
|
-
declare const Cache: {
|
84
|
-
/**
|
85
|
-
* Store data on the file system, in a directory of your choice.
|
86
|
-
*
|
87
|
-
* Data will be stored in two files per cache entry: a data file and a `.header` file.
|
88
|
-
* The header file just contains a unique string which is used to determine whether we can use the cached data.
|
89
|
-
*
|
90
|
-
* Note: this {@link Cache} only caches data in Node.js.
|
91
|
-
*/
|
92
|
-
FileSystem: (cacheDirectory: string, debug?: boolean) => Cache;
|
93
|
-
/**
|
94
|
-
* Don't store anything.
|
95
|
-
*/
|
96
|
-
None: Cache;
|
97
|
-
};
|
@@ -1,97 +0,0 @@
|
|
1
|
-
import { writeFileSync, readFileSync, mkdirSync } from "node:fs";
|
2
|
-
import { resolve } from "node:path";
|
3
|
-
const jsEnvironment = "node";
|
4
|
-
// external API
|
5
|
-
export { Cache };
|
6
|
-
const cacheHeaderVersion = 1;
|
7
|
-
function withVersion(header, version = cacheHeaderVersion) {
|
8
|
-
let uniqueId = `${header.uniqueId}-${version}`;
|
9
|
-
return { ...header, version, uniqueId };
|
10
|
-
}
|
11
|
-
function readCache(cache, header, transform) {
|
12
|
-
try {
|
13
|
-
let result = cache.read(header);
|
14
|
-
if (result === undefined) {
|
15
|
-
if (cache.debug)
|
16
|
-
console.trace("cache miss");
|
17
|
-
return undefined;
|
18
|
-
}
|
19
|
-
if (transform === undefined)
|
20
|
-
return result;
|
21
|
-
return transform(result);
|
22
|
-
}
|
23
|
-
catch (e) {
|
24
|
-
if (cache.debug)
|
25
|
-
console.log("Failed to read cache", e);
|
26
|
-
return undefined;
|
27
|
-
}
|
28
|
-
}
|
29
|
-
function writeCache(cache, header, value) {
|
30
|
-
if (!cache.canWrite)
|
31
|
-
return false;
|
32
|
-
try {
|
33
|
-
cache.write(header, value);
|
34
|
-
return true;
|
35
|
-
}
|
36
|
-
catch (e) {
|
37
|
-
if (cache.debug)
|
38
|
-
console.log("Failed to write cache", e);
|
39
|
-
return false;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
const None = {
|
43
|
-
read() {
|
44
|
-
throw Error("not available");
|
45
|
-
},
|
46
|
-
write() {
|
47
|
-
throw Error("not available");
|
48
|
-
},
|
49
|
-
canWrite: false,
|
50
|
-
};
|
51
|
-
const FileSystem = (cacheDirectory, debug) => ({
|
52
|
-
read({ persistentId, uniqueId, dataType }) {
|
53
|
-
if (jsEnvironment !== "node")
|
54
|
-
throw Error("file system not available");
|
55
|
-
// read current uniqueId, return data if it matches
|
56
|
-
let currentId = readFileSync(resolve(cacheDirectory, `${persistentId}.header`), "utf8");
|
57
|
-
if (currentId !== uniqueId)
|
58
|
-
return undefined;
|
59
|
-
if (dataType === "string") {
|
60
|
-
let string = readFileSync(resolve(cacheDirectory, persistentId), "utf8");
|
61
|
-
return new TextEncoder().encode(string);
|
62
|
-
}
|
63
|
-
else {
|
64
|
-
let buffer = readFileSync(resolve(cacheDirectory, persistentId));
|
65
|
-
return new Uint8Array(buffer.buffer);
|
66
|
-
}
|
67
|
-
},
|
68
|
-
write({ persistentId, uniqueId, dataType }, data) {
|
69
|
-
if (jsEnvironment !== "node")
|
70
|
-
throw Error("file system not available");
|
71
|
-
mkdirSync(cacheDirectory, { recursive: true });
|
72
|
-
writeFileSync(resolve(cacheDirectory, `${persistentId}.header`), uniqueId, {
|
73
|
-
encoding: "utf8",
|
74
|
-
});
|
75
|
-
writeFileSync(resolve(cacheDirectory, persistentId), data, {
|
76
|
-
encoding: dataType === "string" ? "utf8" : undefined,
|
77
|
-
});
|
78
|
-
},
|
79
|
-
canWrite: jsEnvironment === "node",
|
80
|
-
debug,
|
81
|
-
});
|
82
|
-
const Cache = {
|
83
|
-
/**
|
84
|
-
* Store data on the file system, in a directory of your choice.
|
85
|
-
*
|
86
|
-
* Data will be stored in two files per cache entry: a data file and a `.header` file.
|
87
|
-
* The header file just contains a unique string which is used to determine whether we can use the cached data.
|
88
|
-
*
|
89
|
-
* Note: this {@link Cache} only caches data in Node.js.
|
90
|
-
*/
|
91
|
-
FileSystem,
|
92
|
-
/**
|
93
|
-
* Don't store anything.
|
94
|
-
*/
|
95
|
-
None,
|
96
|
-
};
|
97
|
-
//# sourceMappingURL=cache.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../../../src/cloud/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,MAAM,aAAa,GAAG,MAAM,CAAC;AAE7B,eAAe;AACf,OAAO,EAAE,KAAK,EAAE,CAAC;AA+CjB,MAAM,kBAAkB,GAAG,CAAC,CAAC;AA+C7B,SAAS,WAAW,CAClB,MAAoC,EACpC,OAAO,GAAG,kBAAkB;IAE5B,IAAI,QAAQ,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,OAAO,EAAE,CAAC;IAC/C,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAiB,CAAC;AACzD,CAAC;AAUD,SAAS,SAAS,CAChB,KAAY,EACZ,MAAmB,EACnB,SAAgC;IAEhC,IAAI,CAAC;QACH,IAAI,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,KAAK,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