@silvana-one/prover 0.2.0
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/README.md +1 -0
- package/dist/node/config.d.ts +8 -0
- package/dist/node/config.js +9 -0
- package/dist/node/config.js.map +1 -0
- package/dist/node/index.cjs +551 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.js +5 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/networks.d.ts +32 -0
- package/dist/node/networks.js +81 -0
- package/dist/node/networks.js.map +1 -0
- package/dist/node/utils/base64.d.ts +6 -0
- package/dist/node/utils/base64.js +83 -0
- package/dist/node/utils/base64.js.map +1 -0
- package/dist/node/utils/graphql.d.ts +11 -0
- package/dist/node/utils/graphql.js +225 -0
- package/dist/node/utils/graphql.js.map +1 -0
- package/dist/node/utils/index.d.ts +3 -0
- package/dist/node/utils/index.js +4 -0
- package/dist/node/utils/index.js.map +1 -0
- package/dist/node/utils/utils.d.ts +8 -0
- package/dist/node/utils/utils.js +61 -0
- package/dist/node/utils/utils.js.map +1 -0
- package/dist/node/worker/cloud.d.ts +250 -0
- package/dist/node/worker/cloud.js +54 -0
- package/dist/node/worker/cloud.js.map +1 -0
- package/dist/node/worker/index.d.ts +5 -0
- package/dist/node/worker/index.js +6 -0
- package/dist/node/worker/index.js.map +1 -0
- package/dist/node/worker/job.d.ts +87 -0
- package/dist/node/worker/job.js +2 -0
- package/dist/node/worker/job.js.map +1 -0
- package/dist/node/worker/task.d.ts +32 -0
- package/dist/node/worker/task.js +2 -0
- package/dist/node/worker/task.js.map +1 -0
- package/dist/node/worker/transaction.d.ts +11 -0
- package/dist/node/worker/transaction.js +8 -0
- package/dist/node/worker/transaction.js.map +1 -0
- package/dist/node/worker/worker.d.ts +40 -0
- package/dist/node/worker/worker.js +53 -0
- package/dist/node/worker/worker.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/tsconfig.web.tsbuildinfo +1 -0
- package/dist/web/config.d.ts +8 -0
- package/dist/web/config.js +9 -0
- package/dist/web/config.js.map +1 -0
- package/dist/web/index.d.ts +4 -0
- package/dist/web/index.js +5 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/networks.d.ts +32 -0
- package/dist/web/networks.js +81 -0
- package/dist/web/networks.js.map +1 -0
- package/dist/web/utils/base64.d.ts +6 -0
- package/dist/web/utils/base64.js +83 -0
- package/dist/web/utils/base64.js.map +1 -0
- package/dist/web/utils/graphql.d.ts +11 -0
- package/dist/web/utils/graphql.js +225 -0
- package/dist/web/utils/graphql.js.map +1 -0
- package/dist/web/utils/index.d.ts +3 -0
- package/dist/web/utils/index.js +4 -0
- package/dist/web/utils/index.js.map +1 -0
- package/dist/web/utils/utils.d.ts +8 -0
- package/dist/web/utils/utils.js +61 -0
- package/dist/web/utils/utils.js.map +1 -0
- package/dist/web/worker/cloud.d.ts +250 -0
- package/dist/web/worker/cloud.js +54 -0
- package/dist/web/worker/cloud.js.map +1 -0
- package/dist/web/worker/index.d.ts +5 -0
- package/dist/web/worker/index.js +6 -0
- package/dist/web/worker/index.js.map +1 -0
- package/dist/web/worker/job.d.ts +87 -0
- package/dist/web/worker/job.js +2 -0
- package/dist/web/worker/job.js.map +1 -0
- package/dist/web/worker/task.d.ts +32 -0
- package/dist/web/worker/task.js +2 -0
- package/dist/web/worker/task.js.map +1 -0
- package/dist/web/worker/transaction.d.ts +11 -0
- package/dist/web/worker/transaction.js +8 -0
- package/dist/web/worker/transaction.js.map +1 -0
- package/dist/web/worker/worker.d.ts +40 -0
- package/dist/web/worker/worker.js +53 -0
- package/dist/web/worker/worker.js.map +1 -0
- package/package.json +59 -0
- package/src/LICENSE +201 -0
- package/src/README.md +77 -0
- package/src/config.ts +10 -0
- package/src/index.ts +4 -0
- package/src/networks.ts +130 -0
- package/src/utils/base64.ts +87 -0
- package/src/utils/graphql.ts +252 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/utils.ts +79 -0
- package/src/worker/cloud.ts +326 -0
- package/src/worker/index.ts +5 -0
- package/src/worker/job.ts +123 -0
- package/src/worker/task.ts +45 -0
- package/src/worker/transaction.ts +12 -0
- package/src/worker/worker.ts +62 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
export const defaultToken = "wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf";
|
|
2
|
+
export async function getBalanceFromGraphQL(params) {
|
|
3
|
+
const { publicKey, mina } = params;
|
|
4
|
+
const tokenId = params.tokenId ?? defaultToken;
|
|
5
|
+
if (mina.length === 0)
|
|
6
|
+
throw new Error("no mina endpoints provided");
|
|
7
|
+
const account = await fetchAccountInternal({
|
|
8
|
+
publicKey,
|
|
9
|
+
tokenId,
|
|
10
|
+
mina,
|
|
11
|
+
queryType: "balance",
|
|
12
|
+
});
|
|
13
|
+
//console.log("getBalanceFromGraphQL account:", account);
|
|
14
|
+
const balance = account?.account?.balance?.total;
|
|
15
|
+
return balance ? BigInt(balance) : 0n;
|
|
16
|
+
}
|
|
17
|
+
export async function getAccountFromGraphQL(params) {
|
|
18
|
+
const { publicKey, mina } = params;
|
|
19
|
+
const tokenId = params.tokenId ?? defaultToken;
|
|
20
|
+
if (mina.length === 0)
|
|
21
|
+
throw new Error("no mina endpoints provided");
|
|
22
|
+
const account = await fetchAccountInternal({
|
|
23
|
+
publicKey,
|
|
24
|
+
tokenId,
|
|
25
|
+
mina,
|
|
26
|
+
queryType: "account",
|
|
27
|
+
});
|
|
28
|
+
return account?.account;
|
|
29
|
+
}
|
|
30
|
+
async function fetchAccountInternal(params) {
|
|
31
|
+
const { publicKey, tokenId, mina, timeout, queryType } = params;
|
|
32
|
+
const query = queryType === "balance"
|
|
33
|
+
? balanceQuery(publicKey, tokenId)
|
|
34
|
+
: accountQuery(publicKey, tokenId);
|
|
35
|
+
let [response, error] = await makeGraphqlRequest({
|
|
36
|
+
query,
|
|
37
|
+
mina,
|
|
38
|
+
timeout,
|
|
39
|
+
});
|
|
40
|
+
if (error !== undefined)
|
|
41
|
+
return { account: undefined, error };
|
|
42
|
+
const account = response?.data?.account;
|
|
43
|
+
if (!account) {
|
|
44
|
+
return {
|
|
45
|
+
account: undefined,
|
|
46
|
+
error: {
|
|
47
|
+
statusCode: 404,
|
|
48
|
+
statusText: `fetchAccount: Account with public key ${publicKey} does not exist.`,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
account,
|
|
54
|
+
error: undefined,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function makeGraphqlRequest(params) {
|
|
58
|
+
const defaultTimeout = 5 * 60 * 1000; // 5 minutes
|
|
59
|
+
const timeout = params.timeout ?? defaultTimeout;
|
|
60
|
+
const { query, mina } = params;
|
|
61
|
+
const graphqlEndpoint = mina[0];
|
|
62
|
+
const fallbackEndpoints = mina.slice(1);
|
|
63
|
+
if (graphqlEndpoint === "none")
|
|
64
|
+
throw Error("Should have made a graphql request, but don't know to which endpoint.");
|
|
65
|
+
let timeouts = [];
|
|
66
|
+
const clearTimeouts = () => {
|
|
67
|
+
timeouts.forEach((t) => clearTimeout(t));
|
|
68
|
+
timeouts = [];
|
|
69
|
+
};
|
|
70
|
+
const makeRequest = async (url) => {
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
73
|
+
timeouts.push(timer);
|
|
74
|
+
let body = JSON.stringify({
|
|
75
|
+
operationName: null,
|
|
76
|
+
query,
|
|
77
|
+
variables: {},
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
let response = await fetch(url, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: { "Content-Type": "application/json" },
|
|
83
|
+
body,
|
|
84
|
+
signal: controller.signal,
|
|
85
|
+
});
|
|
86
|
+
return checkResponseStatus(response);
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
clearTimeouts();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
// try to fetch from endpoints in pairs
|
|
93
|
+
let timeoutErrors = [];
|
|
94
|
+
let urls = [graphqlEndpoint, ...fallbackEndpoints];
|
|
95
|
+
for (let i = 0; i < urls.length; i += 2) {
|
|
96
|
+
let url1 = urls[i];
|
|
97
|
+
let url2 = urls[i + 1];
|
|
98
|
+
if (url2 === undefined) {
|
|
99
|
+
try {
|
|
100
|
+
return await makeRequest(url1);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return [undefined, inferError(error)];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
return await Promise.race([makeRequest(url1), makeRequest(url2)]);
|
|
108
|
+
}
|
|
109
|
+
catch (unknownError) {
|
|
110
|
+
let error = inferError(unknownError);
|
|
111
|
+
if (error.statusCode === 408) {
|
|
112
|
+
// If the request timed out, try the next 2 endpoints
|
|
113
|
+
timeoutErrors.push({ url1, url2, error });
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// If the request failed for some other reason (e.g. o1js error), return the error
|
|
117
|
+
return [undefined, error];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const statusText = timeoutErrors
|
|
122
|
+
.map(({ url1, url2, error }) => `Request to ${url1} and ${url2} timed out. Error: ${error}`)
|
|
123
|
+
.join("\n");
|
|
124
|
+
return [undefined, { statusCode: 408, statusText }];
|
|
125
|
+
}
|
|
126
|
+
function inferError(error) {
|
|
127
|
+
let errorMessage = JSON.stringify(error);
|
|
128
|
+
if (error instanceof AbortSignal) {
|
|
129
|
+
return { statusCode: 408, statusText: `Request Timeout: ${errorMessage}` };
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return {
|
|
133
|
+
statusCode: 500,
|
|
134
|
+
statusText: `Unknown Error: ${errorMessage}`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function checkResponseStatus(response) {
|
|
139
|
+
if (response.ok) {
|
|
140
|
+
const jsonResponse = (await response.json());
|
|
141
|
+
if (jsonResponse.errors && jsonResponse.errors.length > 0) {
|
|
142
|
+
return [
|
|
143
|
+
undefined,
|
|
144
|
+
{
|
|
145
|
+
statusCode: response.status,
|
|
146
|
+
statusText: jsonResponse.errors
|
|
147
|
+
.map((error) => error.message)
|
|
148
|
+
.join("\n"),
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
else if (jsonResponse.data === undefined) {
|
|
153
|
+
return [
|
|
154
|
+
undefined,
|
|
155
|
+
{
|
|
156
|
+
statusCode: response.status,
|
|
157
|
+
statusText: `GraphQL response data is undefined`,
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
return [jsonResponse, undefined];
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return [
|
|
165
|
+
undefined,
|
|
166
|
+
{
|
|
167
|
+
statusCode: response.status,
|
|
168
|
+
statusText: response.statusText,
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const balanceQuery = (publicKey, tokenId) => `{
|
|
174
|
+
account(publicKey: "${publicKey}", token: "${tokenId}") {
|
|
175
|
+
balance { total }
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
`;
|
|
179
|
+
const accountQuery = (publicKey, tokenId) => `{
|
|
180
|
+
account(publicKey: "${publicKey}", token: "${tokenId}") {
|
|
181
|
+
publicKey
|
|
182
|
+
token
|
|
183
|
+
nonce
|
|
184
|
+
balance { total }
|
|
185
|
+
tokenSymbol
|
|
186
|
+
receiptChainHash
|
|
187
|
+
timing {
|
|
188
|
+
initialMinimumBalance
|
|
189
|
+
cliffTime
|
|
190
|
+
cliffAmount
|
|
191
|
+
vestingPeriod
|
|
192
|
+
vestingIncrement
|
|
193
|
+
}
|
|
194
|
+
permissions {
|
|
195
|
+
editState
|
|
196
|
+
access
|
|
197
|
+
send
|
|
198
|
+
receive
|
|
199
|
+
setDelegate
|
|
200
|
+
setPermissions
|
|
201
|
+
setVerificationKey {
|
|
202
|
+
auth
|
|
203
|
+
txnVersion
|
|
204
|
+
}
|
|
205
|
+
setZkappUri
|
|
206
|
+
editActionState
|
|
207
|
+
setTokenSymbol
|
|
208
|
+
incrementNonce
|
|
209
|
+
setVotingFor
|
|
210
|
+
setTiming
|
|
211
|
+
}
|
|
212
|
+
delegateAccount { publicKey }
|
|
213
|
+
votingFor
|
|
214
|
+
zkappState
|
|
215
|
+
verificationKey {
|
|
216
|
+
verificationKey
|
|
217
|
+
hash
|
|
218
|
+
}
|
|
219
|
+
actionState
|
|
220
|
+
provedState
|
|
221
|
+
zkappUri
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
`;
|
|
225
|
+
//# sourceMappingURL=graphql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../src/utils/graphql.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GACvB,oDAAoD,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,MAI3C;IACC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACnC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,YAAY,CAAC;IAC/C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACrE,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC;QACzC,SAAS;QACT,OAAO;QACP,IAAI;QACJ,SAAS,EAAE,SAAS;KACrB,CAAC,CAAC;IACH,yDAAyD;IACzD,MAAM,OAAO,GAAI,OAAe,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC;IAC1D,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACxC,CAAC;AAED,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AAS;gBACT;oBACE,UAAU,EAAE,QAAQ,CAAC,MAAM;oBAC3B,UAAU,EAAE,oCAAoC;iBACjD;aACF,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,OAAO;YACL,SAAS;YACT;gBACE,UAAU,EAAE,QAAQ,CAAC,MAAM;gBAC3B,UAAU,EAAE,QAAQ,CAAC,UAAU;aAChC;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAE,OAAe,EAAE,EAAE,CAAC;wBACrC,SAAS,cAAc,OAAO;;;;CAIrD,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAE,OAAe,EAAE,EAAE,CAAC;wBACrC,SAAS,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4CrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function sleep(ms: number): Promise<unknown>;
|
|
2
|
+
export declare function makeString(length: number): string;
|
|
3
|
+
export declare function formatTime(ms: number): string;
|
|
4
|
+
export declare class Memory {
|
|
5
|
+
static rss: number;
|
|
6
|
+
constructor();
|
|
7
|
+
static info(description?: string, fullInfo?: boolean): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export function sleep(ms) {
|
|
2
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3
|
+
}
|
|
4
|
+
export function makeString(length) {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
6
|
+
let outString = ``;
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
8
|
+
const inOptions = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`;
|
|
9
|
+
for (let i = 0; i < length; i++) {
|
|
10
|
+
outString += inOptions.charAt(Math.floor(Math.random() * inOptions.length));
|
|
11
|
+
}
|
|
12
|
+
return outString;
|
|
13
|
+
}
|
|
14
|
+
export function formatTime(ms) {
|
|
15
|
+
if (ms === undefined)
|
|
16
|
+
return "";
|
|
17
|
+
if (ms < 1000)
|
|
18
|
+
return ms.toString() + " ms";
|
|
19
|
+
if (ms < 60 * 1000)
|
|
20
|
+
return parseInt((ms / 1000).toString()).toString() + " sec";
|
|
21
|
+
if (ms < 60 * 60 * 1000) {
|
|
22
|
+
const minutes = parseInt((ms / 1000 / 60).toString());
|
|
23
|
+
const seconds = parseInt(((ms - minutes * 60 * 1000) / 1000).toString());
|
|
24
|
+
return minutes.toString() + " min " + seconds.toString() + " sec";
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const hours = parseInt((ms / 1000 / 60 / 60).toString());
|
|
28
|
+
const minutes = parseInt(((ms - hours * 60 * 60 * 1000) / 1000 / 60).toString());
|
|
29
|
+
return hours.toString() + " h " + minutes.toString() + " min";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class Memory {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
34
|
+
static { this.rss = 0; }
|
|
35
|
+
constructor() {
|
|
36
|
+
Memory.rss = 0;
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
39
|
+
static info(description = ``, fullInfo = false) {
|
|
40
|
+
const memoryData = process.memoryUsage();
|
|
41
|
+
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024)} MB`;
|
|
42
|
+
const oldRSS = Memory.rss;
|
|
43
|
+
Memory.rss = Math.round(memoryData.rss / 1024 / 1024);
|
|
44
|
+
const memoryUsage = fullInfo
|
|
45
|
+
? {
|
|
46
|
+
step: `${description}:`,
|
|
47
|
+
rssDelta: `${(oldRSS === 0
|
|
48
|
+
? 0
|
|
49
|
+
: Memory.rss - oldRSS).toString()} MB -> Resident Set Size memory change`,
|
|
50
|
+
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated`,
|
|
51
|
+
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
|
|
52
|
+
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
|
|
53
|
+
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
|
|
54
|
+
}
|
|
55
|
+
: `RSS memory ${description}: ${formatMemoryUsage(memoryData.rss)}${oldRSS === 0
|
|
56
|
+
? ``
|
|
57
|
+
: `, changed by ` + (Memory.rss - oldRSS).toString() + ` MB`}`;
|
|
58
|
+
console.log(memoryUsage);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,kEAAkE;IAClE,IAAI,SAAS,GAAW,EAAE,CAAC;IAC3B,kEAAkE;IAClE,MAAM,SAAS,GAAW,gEAAgE,CAAC;IAE3F,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,SAAS,IAAI,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS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AAK,CAAC;gBACV,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,eAAe,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,QAAQ,EAAE,GAAG,KAC3D,EAAE,CAAC;QAEP,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3B,CAAC"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { blockchain } from "../networks.js";
|
|
2
|
+
import { JobData } from "./job.js";
|
|
3
|
+
import { TransactionMetadata } from "./transaction.js";
|
|
4
|
+
/**
|
|
5
|
+
* Interface for the deployer key pair
|
|
6
|
+
* Used to get the public and private keys of the deployer for test networks only.
|
|
7
|
+
* Devnet and Zeko are supported.
|
|
8
|
+
*/
|
|
9
|
+
export interface DeployerKeyPair {
|
|
10
|
+
/** The public key of the deployer */
|
|
11
|
+
publicKey: string;
|
|
12
|
+
/** The private key of the deployer */
|
|
13
|
+
privateKey: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Interface for the cloud transaction
|
|
17
|
+
* Used to get the transaction id, the transaction, and the time received
|
|
18
|
+
*/
|
|
19
|
+
export interface CloudTransaction {
|
|
20
|
+
/** The transaction id */
|
|
21
|
+
txId: string;
|
|
22
|
+
/** The transaction */
|
|
23
|
+
transaction: string;
|
|
24
|
+
/** The time received */
|
|
25
|
+
timeReceived: number;
|
|
26
|
+
/** The status of the transaction */
|
|
27
|
+
status: string;
|
|
28
|
+
}
|
|
29
|
+
export declare abstract class Cloud {
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly jobId: string;
|
|
32
|
+
readonly stepId: string;
|
|
33
|
+
readonly taskId: string;
|
|
34
|
+
readonly cache: string;
|
|
35
|
+
readonly developer: string;
|
|
36
|
+
readonly repo: string;
|
|
37
|
+
readonly task?: string;
|
|
38
|
+
readonly userId?: string;
|
|
39
|
+
readonly args?: string;
|
|
40
|
+
readonly metadata?: string;
|
|
41
|
+
readonly chain: blockchain;
|
|
42
|
+
readonly isLocalCloud: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Constructor for the Cloud class
|
|
45
|
+
* @param params the parameters for the Cloud class
|
|
46
|
+
* @param params.id the id of the user
|
|
47
|
+
* @param params.jobId the job id
|
|
48
|
+
* @param params.stepId the step id
|
|
49
|
+
* @param params.taskId the task id
|
|
50
|
+
* @param params.cache the cache folder. Use it to get the Cache object: cache = Cache.FileSystem(this.cloud.cache);
|
|
51
|
+
* @param params.developer the developer id
|
|
52
|
+
* @param params.repo the repo id
|
|
53
|
+
* @param params.task the task id
|
|
54
|
+
* @param params.userId the user id
|
|
55
|
+
* @param params.args the arguments, should be a string or serialized JSON
|
|
56
|
+
* @param params.metadata the metadata, should be a string or serialized JSON
|
|
57
|
+
* @param params.chain the blockchain network
|
|
58
|
+
* @param params.isLocalCloud a boolean to check if the cloud is local or not
|
|
59
|
+
*/
|
|
60
|
+
constructor(params: {
|
|
61
|
+
id: string;
|
|
62
|
+
jobId: string;
|
|
63
|
+
stepId: string;
|
|
64
|
+
taskId: string;
|
|
65
|
+
cache: string;
|
|
66
|
+
developer: string;
|
|
67
|
+
repo: string;
|
|
68
|
+
task?: string;
|
|
69
|
+
userId?: string;
|
|
70
|
+
args?: string;
|
|
71
|
+
metadata?: string;
|
|
72
|
+
isLocalCloud?: boolean;
|
|
73
|
+
chain: blockchain;
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Abstract method to get the deployer key pair
|
|
77
|
+
* Used to get the public and private keys of the deployer for test networks only
|
|
78
|
+
* Devnet and Zeko are supported
|
|
79
|
+
* @returns the deployer key pair
|
|
80
|
+
*/
|
|
81
|
+
abstract getDeployer(): Promise<DeployerKeyPair | undefined>;
|
|
82
|
+
/**
|
|
83
|
+
* Abstract method to release the deployer
|
|
84
|
+
* @param params the public key of the deployer and the transactions hashes
|
|
85
|
+
* Used to release the deployer after the transactions are sent to the blockchain
|
|
86
|
+
* @param params.publicKey the public key of the deployer
|
|
87
|
+
* @param params.txsHashes the transactions hashes
|
|
88
|
+
*/
|
|
89
|
+
abstract releaseDeployer(params: {
|
|
90
|
+
publicKey: string;
|
|
91
|
+
txsHashes: string[];
|
|
92
|
+
}): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Abstract method to get the data by key
|
|
95
|
+
* Used to get the data by key from the cloud storage
|
|
96
|
+
* @param key the key
|
|
97
|
+
* @returns the value of the key
|
|
98
|
+
*/
|
|
99
|
+
abstract getDataByKey(key: string): Promise<string | undefined>;
|
|
100
|
+
/**
|
|
101
|
+
* Abstract method to save the data by key
|
|
102
|
+
* Used to save the data by key to the cloud storage
|
|
103
|
+
* @param key the key
|
|
104
|
+
* @param value the value
|
|
105
|
+
*/
|
|
106
|
+
abstract saveDataByKey(key: string, value: string | undefined): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Abstract method to save the file
|
|
109
|
+
* Used to save the file to the cloud storage
|
|
110
|
+
* @param filename the filename
|
|
111
|
+
* @param value the value
|
|
112
|
+
*/
|
|
113
|
+
abstract saveFile(filename: string, value: Buffer): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Abstract method to load the file
|
|
116
|
+
* Used to load the file from the cloud storage
|
|
117
|
+
* @param filename the filename
|
|
118
|
+
* @returns the value of the file
|
|
119
|
+
*/
|
|
120
|
+
abstract loadFile(filename: string): Promise<Buffer | undefined>;
|
|
121
|
+
/**
|
|
122
|
+
* Abstract method to encrypt the data
|
|
123
|
+
* @param params
|
|
124
|
+
* @param params.data the data
|
|
125
|
+
* @param params.context the context
|
|
126
|
+
* @param params.keyId the key id, optional
|
|
127
|
+
*/
|
|
128
|
+
abstract encrypt(params: {
|
|
129
|
+
data: string;
|
|
130
|
+
context: string;
|
|
131
|
+
keyId?: string;
|
|
132
|
+
}): Promise<string | undefined>;
|
|
133
|
+
/**
|
|
134
|
+
* Abstract method to decrypt the data
|
|
135
|
+
* @param params
|
|
136
|
+
* @param params.data the data
|
|
137
|
+
* @param params.context the context
|
|
138
|
+
* @param params.keyId the key id, optional
|
|
139
|
+
*/
|
|
140
|
+
abstract decrypt(params: {
|
|
141
|
+
data: string;
|
|
142
|
+
context: string;
|
|
143
|
+
keyId?: string;
|
|
144
|
+
}): Promise<string | undefined>;
|
|
145
|
+
/**
|
|
146
|
+
* Abstract method to calculate the recursive proof
|
|
147
|
+
* Used to calculate the recursive proof
|
|
148
|
+
* @param data the data
|
|
149
|
+
* @param data.transactions the transactions
|
|
150
|
+
* @param data.task the task
|
|
151
|
+
* @param data.userId the user id
|
|
152
|
+
* @param data.args the arguments
|
|
153
|
+
* @param data.metadata the metadata
|
|
154
|
+
* @returns the proof
|
|
155
|
+
*/
|
|
156
|
+
abstract recursiveProof(data: {
|
|
157
|
+
transactions: string[];
|
|
158
|
+
task?: string;
|
|
159
|
+
userId?: string;
|
|
160
|
+
args?: string;
|
|
161
|
+
metadata?: string;
|
|
162
|
+
}): Promise<string>;
|
|
163
|
+
/**
|
|
164
|
+
* Abstract method to execute the transactions
|
|
165
|
+
* Used to execute the transactions
|
|
166
|
+
* @param data the data
|
|
167
|
+
* @param data.transactions the transactions
|
|
168
|
+
* @param data.task the task
|
|
169
|
+
* @param data.userId the user id
|
|
170
|
+
* @param data.args the arguments
|
|
171
|
+
* @param data.metadata the metadata
|
|
172
|
+
* @returns the result
|
|
173
|
+
*/
|
|
174
|
+
abstract execute(data: {
|
|
175
|
+
transactions: string[];
|
|
176
|
+
task: string;
|
|
177
|
+
userId?: string;
|
|
178
|
+
args?: string;
|
|
179
|
+
metadata?: string;
|
|
180
|
+
}): Promise<string>;
|
|
181
|
+
/**
|
|
182
|
+
* Abstract method to add the task
|
|
183
|
+
* Used to add the task
|
|
184
|
+
* @param data the data
|
|
185
|
+
* @param data.task the task
|
|
186
|
+
* @param data.startTime the start time
|
|
187
|
+
* @param data.userId the user id
|
|
188
|
+
* @param data.args the arguments
|
|
189
|
+
* @param data.metadata the metadata
|
|
190
|
+
* @param data.maxAttempts the maximum attempts
|
|
191
|
+
* @returns the task id
|
|
192
|
+
*/
|
|
193
|
+
abstract addTask(data: {
|
|
194
|
+
task: string;
|
|
195
|
+
startTime?: number;
|
|
196
|
+
userId?: string;
|
|
197
|
+
args?: string;
|
|
198
|
+
metadata?: string;
|
|
199
|
+
maxAttempts?: number;
|
|
200
|
+
}): Promise<string>;
|
|
201
|
+
/**
|
|
202
|
+
* Abstract method to send the transactions
|
|
203
|
+
* @param transactions
|
|
204
|
+
*/
|
|
205
|
+
abstract sendTransactions(transactions: string[] | CloudTransaction[]): Promise<CloudTransaction[]>;
|
|
206
|
+
/**
|
|
207
|
+
* Abstract method to delete the transaction
|
|
208
|
+
* Used to delete the transaction
|
|
209
|
+
* @param txId the transaction id
|
|
210
|
+
*/
|
|
211
|
+
abstract deleteTransaction(txId: string): Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* Abstract method to get the transactions
|
|
214
|
+
* Used to get the transactions
|
|
215
|
+
* @returns the transactions
|
|
216
|
+
*/
|
|
217
|
+
abstract getTransactions(): Promise<CloudTransaction[]>;
|
|
218
|
+
/**
|
|
219
|
+
* Publish the transaction metadata in human-readable format
|
|
220
|
+
* @param params
|
|
221
|
+
* @param params.txId the transaction id
|
|
222
|
+
* @param params.metadata the metadata
|
|
223
|
+
*/
|
|
224
|
+
abstract publishTransactionMetadata(params: {
|
|
225
|
+
txId: string;
|
|
226
|
+
metadata: TransactionMetadata;
|
|
227
|
+
}): Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* Abstract method to delete the task
|
|
230
|
+
* Used to delete the task
|
|
231
|
+
* @param taskId the task id
|
|
232
|
+
*/
|
|
233
|
+
abstract deleteTask(taskId: string): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Abstract method to process the tasks
|
|
236
|
+
*/
|
|
237
|
+
abstract processTasks(): Promise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* Abstract method to get the job result
|
|
240
|
+
* Used to get the job result
|
|
241
|
+
* @param jobId the job id
|
|
242
|
+
* @returns the job result
|
|
243
|
+
*/
|
|
244
|
+
abstract jobResult(jobId: string): Promise<JobData | undefined>;
|
|
245
|
+
/**
|
|
246
|
+
* forces the worker to restart the AWS lambda container
|
|
247
|
+
* See https://github.com/o1-labs/o1js/issues/1651
|
|
248
|
+
*/
|
|
249
|
+
abstract forceWorkerRestart(): Promise<void>;
|
|
250
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Abstract class for the cloud service
|
|
3
|
+
* Used to define the cloud methods and properties
|
|
4
|
+
* Should be implemented by for local testing and for the zkCloudWorker in the cloud
|
|
5
|
+
* @param id the id of the user
|
|
6
|
+
* @param jobId the job id
|
|
7
|
+
* @param stepId the step id
|
|
8
|
+
* @param taskId the task id
|
|
9
|
+
* @param cache the cache folder. Use it to get the Cache object: cache = Cache.FileSystem(this.cloud.cache);
|
|
10
|
+
* @param developer the developer id
|
|
11
|
+
* @param repo the repo id
|
|
12
|
+
* @param task the task id
|
|
13
|
+
* @param userId the user id
|
|
14
|
+
* @param args the arguments, should be a string or serialized JSON
|
|
15
|
+
* @param metadata the metadata, should be a string or serialized JSON
|
|
16
|
+
* @param chain the blockchain network
|
|
17
|
+
* @param isLocalCloud a boolean to check if the cloud is local or not
|
|
18
|
+
*/
|
|
19
|
+
export class Cloud {
|
|
20
|
+
/**
|
|
21
|
+
* Constructor for the Cloud class
|
|
22
|
+
* @param params the parameters for the Cloud class
|
|
23
|
+
* @param params.id the id of the user
|
|
24
|
+
* @param params.jobId the job id
|
|
25
|
+
* @param params.stepId the step id
|
|
26
|
+
* @param params.taskId the task id
|
|
27
|
+
* @param params.cache the cache folder. Use it to get the Cache object: cache = Cache.FileSystem(this.cloud.cache);
|
|
28
|
+
* @param params.developer the developer id
|
|
29
|
+
* @param params.repo the repo id
|
|
30
|
+
* @param params.task the task id
|
|
31
|
+
* @param params.userId the user id
|
|
32
|
+
* @param params.args the arguments, should be a string or serialized JSON
|
|
33
|
+
* @param params.metadata the metadata, should be a string or serialized JSON
|
|
34
|
+
* @param params.chain the blockchain network
|
|
35
|
+
* @param params.isLocalCloud a boolean to check if the cloud is local or not
|
|
36
|
+
*/
|
|
37
|
+
constructor(params) {
|
|
38
|
+
const { id, jobId, stepId, taskId, cache, developer, repo, task, userId, args, metadata, isLocalCloud, chain, } = params;
|
|
39
|
+
this.id = id;
|
|
40
|
+
this.jobId = jobId;
|
|
41
|
+
this.stepId = stepId;
|
|
42
|
+
this.taskId = taskId;
|
|
43
|
+
this.cache = cache;
|
|
44
|
+
this.developer = developer;
|
|
45
|
+
this.repo = repo;
|
|
46
|
+
this.task = task;
|
|
47
|
+
this.userId = userId;
|
|
48
|
+
this.args = args;
|
|
49
|
+
this.metadata = metadata;
|
|
50
|
+
this.isLocalCloud = isLocalCloud ?? false;
|
|
51
|
+
this.chain = chain;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=cloud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud.js","sourceRoot":"","sources":["../../../src/worker/cloud.ts"],"names":[],"mappings":"AAmCA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAgB,KAAK;IAezB;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,MAcX;QACC,MAAM,EACJ,EAAE,EACF,KAAK,EACL,MAAM,EACN,MAAM,EACN,KAAK,EACL,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,KAAK,GACN,GAAG,MAAM,CAAC;QACX,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,KAAK,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CAqMF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/worker/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|