zkcloudworker 0.7.2 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/ts/src/api/api.d.ts +39 -27
- package/lib/ts/src/api/api.js +28 -27
- package/lib/ts/src/cloud/cloud.d.ts +176 -0
- package/lib/ts/src/cloud/cloud.js +72 -3
- package/lib/ts/src/cloud/job.d.ts +47 -0
- package/lib/ts/src/cloud/local.d.ts +157 -1
- package/lib/ts/src/cloud/local.js +157 -3
- package/lib/ts/src/cloud/task.d.ts +18 -0
- package/lib/ts/src/networks.d.ts +20 -0
- package/lib/ts/src/utils/fee.d.ts +4 -0
- package/lib/ts/src/utils/fee.js +5 -1
- package/lib/ts/src/utils/fetch.d.ts +20 -0
- package/lib/ts/src/utils/fetch.js +20 -0
- package/lib/ts/src/utils/fields.d.ts +10 -0
- package/lib/ts/src/utils/fields.js +10 -0
- package/lib/ts/src/utils/mina.d.ts +24 -0
- package/lib/ts/src/utils/mina.js +18 -0
- package/lib/ts/tsconfig.tsbuildinfo +1 -1
- package/lib/web/src/api/api.d.ts +39 -27
- package/lib/web/src/api/api.js +28 -27
- package/lib/web/src/api/api.js.map +1 -1
- package/lib/web/src/cloud/cloud.d.ts +176 -0
- package/lib/web/src/cloud/cloud.js +72 -3
- package/lib/web/src/cloud/cloud.js.map +1 -1
- package/lib/web/src/cloud/job.d.ts +47 -0
- package/lib/web/src/cloud/local.d.ts +157 -1
- package/lib/web/src/cloud/local.js +157 -3
- package/lib/web/src/cloud/local.js.map +1 -1
- package/lib/web/src/cloud/task.d.ts +18 -0
- package/lib/web/src/networks.d.ts +20 -0
- package/lib/web/src/networks.js.map +1 -1
- package/lib/web/src/utils/fee.d.ts +4 -0
- package/lib/web/src/utils/fee.js +5 -1
- package/lib/web/src/utils/fee.js.map +1 -1
- package/lib/web/src/utils/fetch.d.ts +20 -0
- package/lib/web/src/utils/fetch.js +20 -0
- package/lib/web/src/utils/fetch.js.map +1 -1
- package/lib/web/src/utils/fields.d.ts +10 -0
- package/lib/web/src/utils/fields.js +10 -0
- package/lib/web/src/utils/fields.js.map +1 -1
- package/lib/web/src/utils/mina.d.ts +24 -0
- package/lib/web/src/utils/mina.js +18 -0
- package/lib/web/src/utils/mina.js.map +1 -1
- package/lib/web/tsconfig.web.tsbuildinfo +1 -1
- package/package.json +1 -1
package/lib/ts/src/api/api.d.ts
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
import { zkCloudWorker, Cloud } from "../cloud/cloud";
|
2
2
|
import { blockchain } from "../networks";
|
3
|
+
/**
|
4
|
+
* The APICommand type for interacting with the zkCloudWorker
|
5
|
+
* @typedef { "recursiveProof" | "execute" | "sendTransactions" | "jobResult" | "deploy" | "getBalance" | "queryBilling" } ApiCommand
|
6
|
+
* @property recursiveProof The command for the recursiveProof calculation
|
7
|
+
* @property execute The command for the execute function call (sync or async)
|
8
|
+
* @property sendTransactions The command for sending transactions to the cloud
|
9
|
+
* @property jobResult The command for getting the result of the job
|
10
|
+
* @property deploy The command for deploying the code to the cloud, it is recommended use CLI tools for deployment
|
11
|
+
* @property getBalance The command for getting the balance of the user's account with zkCloudWorker
|
12
|
+
* @property queryBilling The command for getting the billing report of the user's account with zkCloudWorker
|
13
|
+
*/
|
3
14
|
export type ApiCommand = "recursiveProof" | "execute" | "sendTransactions" | "jobResult" | "deploy" | "getBalance" | "queryBilling";
|
4
15
|
/**
|
5
16
|
* API class for interacting with the zkCloudWorker
|
6
17
|
* @property jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
|
7
18
|
* @property endpoint The endpoint of the serverless api
|
19
|
+
* @property chain The blockchain network to use
|
20
|
+
* @property webhook The webhook for the serverless api to get the results
|
21
|
+
* @property localWorker The local worker for the serverless api to test the code locally
|
8
22
|
*/
|
9
23
|
export declare class zkCloudWorkerClient {
|
10
24
|
readonly jwt: string;
|
@@ -14,7 +28,11 @@ export declare class zkCloudWorkerClient {
|
|
14
28
|
readonly localWorker?: (cloud: Cloud) => Promise<zkCloudWorker>;
|
15
29
|
/**
|
16
30
|
* Constructor for the API class
|
17
|
-
* @param
|
31
|
+
* @param params the parameters for the API class
|
32
|
+
* @param params.jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
|
33
|
+
* @param params.zkcloudworker The local worker for the serverless api to test the code locally
|
34
|
+
* @param params.chain The blockchain network to use
|
35
|
+
* @param params.webhook The webhook for the serverless api to get the results
|
18
36
|
*/
|
19
37
|
constructor(params: {
|
20
38
|
jwt: string;
|
@@ -24,19 +42,20 @@ export declare class zkCloudWorkerClient {
|
|
24
42
|
});
|
25
43
|
/**
|
26
44
|
* Starts a new job for the proof calculation using serverless api call
|
27
|
-
* The developer and name should correspond to the BackupPlugin of the API
|
28
|
-
* All other parameters should correspond to the parameters of the BackupPlugin
|
29
45
|
* @param data the data for the proof call
|
30
|
-
* @param data.transactions the transactions
|
31
46
|
* @param data.developer the developer
|
32
47
|
* @param data.repo the repo to use
|
48
|
+
* @param data.transactions the transactions
|
33
49
|
* @param data.task the task of the job
|
34
|
-
* @param data.
|
50
|
+
* @param data.userId the userId of the job
|
51
|
+
* @param data.args the arguments of the job, should be serialized JSON or string
|
52
|
+
* @param data.metadata the metadata of the job, should be serialized JSON or string
|
53
|
+
* @param data.webhook the webhook for the job
|
35
54
|
* @returns { success: boolean, error?: string, jobId?: string }
|
36
55
|
* where jonId is the jobId of the job
|
37
56
|
*
|
38
|
-
* The developers repo should provide a
|
39
|
-
* that can be called with the given parameters
|
57
|
+
* The developers repo should provide a zkcloudworker function
|
58
|
+
* that can be called with the given parameters, see the examples
|
40
59
|
*/
|
41
60
|
recursiveProof(data: {
|
42
61
|
developer: string;
|
@@ -54,8 +73,6 @@ export declare class zkCloudWorkerClient {
|
|
54
73
|
}>;
|
55
74
|
/**
|
56
75
|
* Starts a new job for the function call using serverless api call
|
57
|
-
* The developer and name should correspond to the BackupPlugin of the API
|
58
|
-
* All other parameters should correspond to the parameters of the BackupPlugin
|
59
76
|
* @param data the data for the proof call
|
60
77
|
* @param data.developer the developer
|
61
78
|
* @param data.repo the repo to use
|
@@ -65,8 +82,8 @@ export declare class zkCloudWorkerClient {
|
|
65
82
|
* @param data.args the arguments of the job
|
66
83
|
* @param data.metadata the metadata of the job
|
67
84
|
* @param data.mode the mode of the job execution: "sync" will not create a job, it will execute the function synchronously within 30 seconds and with the memory limit of 256 MB
|
68
|
-
* @returns { success: boolean, error?: string, jobId?: string }
|
69
|
-
* where jonId is the jobId of the job
|
85
|
+
* @returns { success: boolean, error?: string, jobId?: string, result?: any }
|
86
|
+
* where jonId is the jobId of the job (for async calls), result is the result of the job (for sync calls)
|
70
87
|
*/
|
71
88
|
execute(data: {
|
72
89
|
developer: string;
|
@@ -84,16 +101,13 @@ export declare class zkCloudWorkerClient {
|
|
84
101
|
result?: any;
|
85
102
|
}>;
|
86
103
|
/**
|
87
|
-
*
|
88
|
-
* The developer and name should correspond to the BackupPlugin of the API
|
89
|
-
* All other parameters should correspond to the parameters of the BackupPlugin
|
104
|
+
* Sends transactions to the blockchain using serverless api call
|
90
105
|
* @param data the data for the proof call
|
91
106
|
* @param data.developer the developer
|
92
107
|
* @param data.repo the repo to use
|
93
|
-
* @param data.
|
94
|
-
* @
|
95
|
-
*
|
96
|
-
* where jonId is the jobId of the job
|
108
|
+
* @param data.transactions the transactions
|
109
|
+
* @returns { success: boolean, error?: string, txId?: string[] }
|
110
|
+
* where txId is the transaction id of the transaction, in the sequence of the input transactions
|
97
111
|
*/
|
98
112
|
sendTransactions(data: {
|
99
113
|
developer: string;
|
@@ -125,15 +139,13 @@ export declare class zkCloudWorkerClient {
|
|
125
139
|
result?: any;
|
126
140
|
}>;
|
127
141
|
/**
|
128
|
-
*
|
142
|
+
* Deploys the code to the cloud using serverless api call
|
129
143
|
* @param data the data for the deploy call
|
130
|
-
* @param data.
|
131
|
-
* @
|
132
|
-
*
|
133
|
-
*
|
134
|
-
*
|
135
|
-
* if the job is finished, the result will be set and error will be undefined
|
136
|
-
* if the job is not found, the result will be undefined and error will be set
|
144
|
+
* @param data.repo the repo to use
|
145
|
+
* @param data.developer the developer
|
146
|
+
* @param data.packageManager the package manager to use
|
147
|
+
* @returns { success: boolean, error?: string, jobId?: string}
|
148
|
+
* where jobId is the jobId of the job
|
137
149
|
*/
|
138
150
|
deploy(data: {
|
139
151
|
repo: string;
|
@@ -157,7 +169,7 @@ export declare class zkCloudWorkerClient {
|
|
157
169
|
/**
|
158
170
|
* Gets the remaining balance
|
159
171
|
* @returns { success: boolean, error?: string, result?: any }
|
160
|
-
* where result is the
|
172
|
+
* where result is the balance
|
161
173
|
*/
|
162
174
|
getBalance(): Promise<{
|
163
175
|
success: boolean;
|
package/lib/ts/src/api/api.js
CHANGED
@@ -14,11 +14,18 @@ const { ZKCLOUDWORKER_AUTH, ZKCLOUDWORKER_API } = config_1.default;
|
|
14
14
|
* API class for interacting with the zkCloudWorker
|
15
15
|
* @property jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
|
16
16
|
* @property endpoint The endpoint of the serverless api
|
17
|
+
* @property chain The blockchain network to use
|
18
|
+
* @property webhook The webhook for the serverless api to get the results
|
19
|
+
* @property localWorker The local worker for the serverless api to test the code locally
|
17
20
|
*/
|
18
21
|
class zkCloudWorkerClient {
|
19
22
|
/**
|
20
23
|
* Constructor for the API class
|
21
|
-
* @param
|
24
|
+
* @param params the parameters for the API class
|
25
|
+
* @param params.jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
|
26
|
+
* @param params.zkcloudworker The local worker for the serverless api to test the code locally
|
27
|
+
* @param params.chain The blockchain network to use
|
28
|
+
* @param params.webhook The webhook for the serverless api to get the results
|
22
29
|
*/
|
23
30
|
constructor(params) {
|
24
31
|
const { jwt, zkcloudworker, chain, webhook } = params;
|
@@ -34,19 +41,20 @@ class zkCloudWorkerClient {
|
|
34
41
|
}
|
35
42
|
/**
|
36
43
|
* Starts a new job for the proof calculation using serverless api call
|
37
|
-
* The developer and name should correspond to the BackupPlugin of the API
|
38
|
-
* All other parameters should correspond to the parameters of the BackupPlugin
|
39
44
|
* @param data the data for the proof call
|
40
|
-
* @param data.transactions the transactions
|
41
45
|
* @param data.developer the developer
|
42
46
|
* @param data.repo the repo to use
|
47
|
+
* @param data.transactions the transactions
|
43
48
|
* @param data.task the task of the job
|
44
|
-
* @param data.
|
49
|
+
* @param data.userId the userId of the job
|
50
|
+
* @param data.args the arguments of the job, should be serialized JSON or string
|
51
|
+
* @param data.metadata the metadata of the job, should be serialized JSON or string
|
52
|
+
* @param data.webhook the webhook for the job
|
45
53
|
* @returns { success: boolean, error?: string, jobId?: string }
|
46
54
|
* where jonId is the jobId of the job
|
47
55
|
*
|
48
|
-
* The developers repo should provide a
|
49
|
-
* that can be called with the given parameters
|
56
|
+
* The developers repo should provide a zkcloudworker function
|
57
|
+
* that can be called with the given parameters, see the examples
|
50
58
|
*/
|
51
59
|
async recursiveProof(data) {
|
52
60
|
const result = await this.apiHub("recursiveProof", data);
|
@@ -77,8 +85,6 @@ class zkCloudWorkerClient {
|
|
77
85
|
}
|
78
86
|
/**
|
79
87
|
* Starts a new job for the function call using serverless api call
|
80
|
-
* The developer and name should correspond to the BackupPlugin of the API
|
81
|
-
* All other parameters should correspond to the parameters of the BackupPlugin
|
82
88
|
* @param data the data for the proof call
|
83
89
|
* @param data.developer the developer
|
84
90
|
* @param data.repo the repo to use
|
@@ -88,8 +94,8 @@ class zkCloudWorkerClient {
|
|
88
94
|
* @param data.args the arguments of the job
|
89
95
|
* @param data.metadata the metadata of the job
|
90
96
|
* @param data.mode the mode of the job execution: "sync" will not create a job, it will execute the function synchronously within 30 seconds and with the memory limit of 256 MB
|
91
|
-
* @returns { success: boolean, error?: string, jobId?: string }
|
92
|
-
* where jonId is the jobId of the job
|
97
|
+
* @returns { success: boolean, error?: string, jobId?: string, result?: any }
|
98
|
+
* where jonId is the jobId of the job (for async calls), result is the result of the job (for sync calls)
|
93
99
|
*/
|
94
100
|
async execute(data) {
|
95
101
|
const result = await this.apiHub("execute", data);
|
@@ -130,16 +136,13 @@ class zkCloudWorkerClient {
|
|
130
136
|
};
|
131
137
|
}
|
132
138
|
/**
|
133
|
-
*
|
134
|
-
* The developer and name should correspond to the BackupPlugin of the API
|
135
|
-
* All other parameters should correspond to the parameters of the BackupPlugin
|
139
|
+
* Sends transactions to the blockchain using serverless api call
|
136
140
|
* @param data the data for the proof call
|
137
141
|
* @param data.developer the developer
|
138
142
|
* @param data.repo the repo to use
|
139
|
-
* @param data.
|
140
|
-
* @
|
141
|
-
*
|
142
|
-
* where jonId is the jobId of the job
|
143
|
+
* @param data.transactions the transactions
|
144
|
+
* @returns { success: boolean, error?: string, txId?: string[] }
|
145
|
+
* where txId is the transaction id of the transaction, in the sequence of the input transactions
|
143
146
|
*/
|
144
147
|
async sendTransactions(data) {
|
145
148
|
const result = await this.apiHub("sendTransactions", data);
|
@@ -184,15 +187,13 @@ class zkCloudWorkerClient {
|
|
184
187
|
};
|
185
188
|
}
|
186
189
|
/**
|
187
|
-
*
|
190
|
+
* Deploys the code to the cloud using serverless api call
|
188
191
|
* @param data the data for the deploy call
|
189
|
-
* @param data.
|
190
|
-
* @
|
191
|
-
*
|
192
|
-
*
|
193
|
-
*
|
194
|
-
* if the job is finished, the result will be set and error will be undefined
|
195
|
-
* if the job is not found, the result will be undefined and error will be set
|
192
|
+
* @param data.repo the repo to use
|
193
|
+
* @param data.developer the developer
|
194
|
+
* @param data.packageManager the package manager to use
|
195
|
+
* @returns { success: boolean, error?: string, jobId?: string}
|
196
|
+
* where jobId is the jobId of the job
|
196
197
|
*/
|
197
198
|
async deploy(data) {
|
198
199
|
// TODO: encrypt env.json
|
@@ -238,7 +239,7 @@ class zkCloudWorkerClient {
|
|
238
239
|
/**
|
239
240
|
* Gets the remaining balance
|
240
241
|
* @returns { success: boolean, error?: string, result?: any }
|
241
|
-
* where result is the
|
242
|
+
* where result is the balance
|
242
243
|
*/
|
243
244
|
async getBalance() {
|
244
245
|
const result = await this.apiHub("getBalance", {});
|
@@ -1,6 +1,17 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { blockchain } from "../networks";
|
3
3
|
import { JobData } from "./job";
|
4
|
+
/**
|
5
|
+
* Interface for the deployed smart contract
|
6
|
+
* Used to get verification keys and addresses of the deployed smart contracts
|
7
|
+
* to be published in the blockchain explorer
|
8
|
+
* @param address: the address of the deployed smart contract
|
9
|
+
* @param name: the name of the deployed smart contract
|
10
|
+
* @param chain: the blockchain network where the smart contract is deployed
|
11
|
+
* @param verificationKey: the verification key of the deployed smart contract
|
12
|
+
* @param verificationKey.hash: the hash of the verification key
|
13
|
+
* @param verificationKey.data: the data of the verification key
|
14
|
+
*/
|
4
15
|
export interface DeployedSmartContract {
|
5
16
|
address: string;
|
6
17
|
name: string;
|
@@ -10,10 +21,24 @@ export interface DeployedSmartContract {
|
|
10
21
|
data: string;
|
11
22
|
};
|
12
23
|
}
|
24
|
+
/**
|
25
|
+
* Interface for the deployer key pair
|
26
|
+
* Used to get the public and private keys of the deployer for test networks only
|
27
|
+
* Devnet and Zeko are supported
|
28
|
+
* @param publicKey: the public key of the deployer
|
29
|
+
* @param privateKey: the private key of the deployer
|
30
|
+
*/
|
13
31
|
export interface DeployerKeyPair {
|
14
32
|
publicKey: string;
|
15
33
|
privateKey: string;
|
16
34
|
}
|
35
|
+
/**
|
36
|
+
* Interface for the cloud transaction
|
37
|
+
* Used to get the transaction id, the transaction, and the time received
|
38
|
+
* @param txId: the transaction id
|
39
|
+
* @param transaction: the transaction
|
40
|
+
* @param timeReceived: the time received
|
41
|
+
*/
|
17
42
|
export interface CloudTransaction {
|
18
43
|
txId: string;
|
19
44
|
transaction: string;
|
@@ -33,6 +58,23 @@ export declare abstract class Cloud {
|
|
33
58
|
readonly metadata?: string;
|
34
59
|
readonly chain: blockchain;
|
35
60
|
readonly isLocalCloud: boolean;
|
61
|
+
/**
|
62
|
+
* Constructor for the Cloud class
|
63
|
+
* @param params the parameters for the Cloud class
|
64
|
+
* @param params.id the id of the user
|
65
|
+
* @param params.jobId the job id
|
66
|
+
* @param params.stepId the step id
|
67
|
+
* @param params.taskId the task id
|
68
|
+
* @param params.cache the cache folder. Use it to get the Cache object: cache = Cache.FileSystem(this.cloud.cache);
|
69
|
+
* @param params.developer the developer id
|
70
|
+
* @param params.repo the repo id
|
71
|
+
* @param params.task the task id
|
72
|
+
* @param params.userId the user id
|
73
|
+
* @param params.args the arguments, should be a string or serialized JSON
|
74
|
+
* @param params.metadata the metadata, should be a string or serialized JSON
|
75
|
+
* @param params.chain the blockchain network
|
76
|
+
* @param params.isLocalCloud a boolean to check if the cloud is local or not
|
77
|
+
*/
|
36
78
|
constructor(params: {
|
37
79
|
id: string;
|
38
80
|
jobId: string;
|
@@ -48,16 +90,69 @@ export declare abstract class Cloud {
|
|
48
90
|
isLocalCloud?: boolean;
|
49
91
|
chain: blockchain;
|
50
92
|
});
|
93
|
+
/**
|
94
|
+
* Abstract method to get the deployer key pair
|
95
|
+
* Used to get the public and private keys of the deployer for test networks only
|
96
|
+
* Devnet and Zeko are supported
|
97
|
+
* @returns the deployer key pair
|
98
|
+
*/
|
51
99
|
abstract getDeployer(): Promise<DeployerKeyPair | undefined>;
|
100
|
+
/**
|
101
|
+
* Abstract method to release the deployer
|
102
|
+
* @param params the public key of the deployer and the transactions hashes
|
103
|
+
* Used to release the deployer after the transactions are sent to the blockchain
|
104
|
+
* @param params.publicKey the public key of the deployer
|
105
|
+
* @param params.txsHashes the transactions hashes
|
106
|
+
*/
|
52
107
|
abstract releaseDeployer(params: {
|
53
108
|
publicKey: string;
|
54
109
|
txsHashes: string[];
|
55
110
|
}): Promise<void>;
|
111
|
+
/**
|
112
|
+
* Abstract method to get the data by key
|
113
|
+
* Used to get the data by key from the cloud storage
|
114
|
+
* @param key the key
|
115
|
+
* @returns the value of the key
|
116
|
+
*/
|
56
117
|
abstract getDataByKey(key: string): Promise<string | undefined>;
|
118
|
+
/**
|
119
|
+
* Abstract method to save the data by key
|
120
|
+
* Used to save the data by key to the cloud storage
|
121
|
+
* @param key the key
|
122
|
+
* @param value the value
|
123
|
+
*/
|
57
124
|
abstract saveDataByKey(key: string, value: string | undefined): Promise<void>;
|
125
|
+
/**
|
126
|
+
* Abstract method to save the file
|
127
|
+
* Used to save the file to the cloud storage
|
128
|
+
* @param filename the filename
|
129
|
+
* @param value the value
|
130
|
+
*/
|
58
131
|
abstract saveFile(filename: string, value: Buffer): Promise<void>;
|
132
|
+
/**
|
133
|
+
* Abstract method to load the file
|
134
|
+
* Used to load the file from the cloud storage
|
135
|
+
* @param filename the filename
|
136
|
+
* @returns the value of the file
|
137
|
+
*/
|
59
138
|
abstract loadFile(filename: string): Promise<Buffer | undefined>;
|
139
|
+
/**
|
140
|
+
* Abstract method to load the environment
|
141
|
+
* Used to load the environment from the cloud storage
|
142
|
+
* @param password the password
|
143
|
+
*/
|
60
144
|
abstract loadEnvironment(password: string): Promise<void>;
|
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
|
+
*/
|
61
156
|
abstract recursiveProof(data: {
|
62
157
|
transactions: string[];
|
63
158
|
task?: string;
|
@@ -65,6 +160,17 @@ export declare abstract class Cloud {
|
|
65
160
|
args?: string;
|
66
161
|
metadata?: string;
|
67
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
|
+
*/
|
68
174
|
abstract execute(data: {
|
69
175
|
transactions: string[];
|
70
176
|
task: string;
|
@@ -72,6 +178,18 @@ export declare abstract class Cloud {
|
|
72
178
|
args?: string;
|
73
179
|
metadata?: string;
|
74
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
|
+
*/
|
75
193
|
abstract addTask(data: {
|
76
194
|
task: string;
|
77
195
|
startTime?: number;
|
@@ -80,19 +198,77 @@ export declare abstract class Cloud {
|
|
80
198
|
metadata?: string;
|
81
199
|
maxAttempts?: number;
|
82
200
|
}): Promise<string>;
|
201
|
+
/**
|
202
|
+
* Abstract method to delete the transaction
|
203
|
+
* Used to delete the transaction
|
204
|
+
* @param txId the transaction id
|
205
|
+
*/
|
83
206
|
abstract deleteTransaction(txId: string): Promise<void>;
|
207
|
+
/**
|
208
|
+
* Abstract method to get the transactions
|
209
|
+
* Used to get the transactions
|
210
|
+
* @returns the transactions
|
211
|
+
*/
|
84
212
|
abstract getTransactions(): Promise<CloudTransaction[]>;
|
213
|
+
/**
|
214
|
+
* Abstract method to delete the task
|
215
|
+
* Used to delete the task
|
216
|
+
* @param taskId the task id
|
217
|
+
*/
|
85
218
|
abstract deleteTask(taskId: string): Promise<void>;
|
219
|
+
/**
|
220
|
+
* Abstract method to process the tasks
|
221
|
+
*/
|
86
222
|
abstract processTasks(): Promise<void>;
|
223
|
+
/**
|
224
|
+
* Abstract method to get the job result
|
225
|
+
* Used to get the job result
|
226
|
+
* @param jobId the job id
|
227
|
+
* @returns the job result
|
228
|
+
*/
|
87
229
|
abstract jobResult(jobId: string): Promise<JobData | undefined>;
|
88
230
|
}
|
231
|
+
/**
|
232
|
+
* Abstract class for the zkCloudWorker
|
233
|
+
* Used to define the zkCloudWorker methods and properties
|
234
|
+
* Should be implemented for by the developer for the zkCloudWorker in the cloud
|
235
|
+
* @param cloud: the cloud
|
236
|
+
*/
|
89
237
|
export declare abstract class zkCloudWorker {
|
90
238
|
readonly cloud: Cloud;
|
239
|
+
/**
|
240
|
+
* Constructor for the zkCloudWorker class
|
241
|
+
* @param cloud the cloud instance provided by the zkCloudWorker in the local environment or in the cloud
|
242
|
+
*/
|
91
243
|
constructor(cloud: Cloud);
|
244
|
+
/**
|
245
|
+
* Returns the deployed smart contracts for verification in the blockchain explorer
|
246
|
+
* @returns the deployed smart contracts
|
247
|
+
*/
|
92
248
|
deployedContracts(): Promise<DeployedSmartContract[]>;
|
249
|
+
/**
|
250
|
+
* Creates a new proof from a transaction
|
251
|
+
* @param transaction the transaction
|
252
|
+
* @returns the serialized proof
|
253
|
+
*/
|
93
254
|
create(transaction: string): Promise<string | undefined>;
|
255
|
+
/**
|
256
|
+
* Merges two proofs
|
257
|
+
* @param proof1 the first proof
|
258
|
+
* @param proof2 the second proof
|
259
|
+
* @returns the merged proof
|
260
|
+
*/
|
94
261
|
merge(proof1: string, proof2: string): Promise<string | undefined>;
|
262
|
+
/**
|
263
|
+
* Executes the transactions
|
264
|
+
* @param transactions the transactions, can be empty list
|
265
|
+
* @returns the result
|
266
|
+
*/
|
95
267
|
execute(transactions: string[]): Promise<string | undefined>;
|
96
268
|
processTransactions(transactions: CloudTransaction[]): Promise<void>;
|
269
|
+
/**
|
270
|
+
* process the task defined by the developer
|
271
|
+
* @returns the result
|
272
|
+
*/
|
97
273
|
task(): Promise<string | undefined>;
|
98
274
|
}
|
@@ -1,7 +1,42 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.zkCloudWorker = exports.Cloud = void 0;
|
4
|
+
/*
|
5
|
+
* Abstract class for the cloud service
|
6
|
+
* Used to define the cloud methods and properties
|
7
|
+
* Should be implemented by for local testing and for the zkCloudWorker in the cloud
|
8
|
+
* @param id the id of the user
|
9
|
+
* @param jobId the job id
|
10
|
+
* @param stepId the step id
|
11
|
+
* @param taskId the task id
|
12
|
+
* @param cache the cache folder. Use it to get the Cache object: cache = Cache.FileSystem(this.cloud.cache);
|
13
|
+
* @param developer the developer id
|
14
|
+
* @param repo the repo id
|
15
|
+
* @param task the task id
|
16
|
+
* @param userId the user id
|
17
|
+
* @param args the arguments, should be a string or serialized JSON
|
18
|
+
* @param metadata the metadata, should be a string or serialized JSON
|
19
|
+
* @param chain the blockchain network
|
20
|
+
* @param isLocalCloud a boolean to check if the cloud is local or not
|
21
|
+
*/
|
4
22
|
class Cloud {
|
23
|
+
/**
|
24
|
+
* Constructor for the Cloud class
|
25
|
+
* @param params the parameters for the Cloud class
|
26
|
+
* @param params.id the id of the user
|
27
|
+
* @param params.jobId the job id
|
28
|
+
* @param params.stepId the step id
|
29
|
+
* @param params.taskId the task id
|
30
|
+
* @param params.cache the cache folder. Use it to get the Cache object: cache = Cache.FileSystem(this.cloud.cache);
|
31
|
+
* @param params.developer the developer id
|
32
|
+
* @param params.repo the repo id
|
33
|
+
* @param params.task the task id
|
34
|
+
* @param params.userId the user id
|
35
|
+
* @param params.args the arguments, should be a string or serialized JSON
|
36
|
+
* @param params.metadata the metadata, should be a string or serialized JSON
|
37
|
+
* @param params.chain the blockchain network
|
38
|
+
* @param params.isLocalCloud a boolean to check if the cloud is local or not
|
39
|
+
*/
|
5
40
|
constructor(params) {
|
6
41
|
const { id, jobId, stepId, taskId, cache, developer, repo, task, userId, args, metadata, isLocalCloud, chain, } = params;
|
7
42
|
this.id = id;
|
@@ -20,28 +55,62 @@ class Cloud {
|
|
20
55
|
}
|
21
56
|
}
|
22
57
|
exports.Cloud = Cloud;
|
58
|
+
/**
|
59
|
+
* Abstract class for the zkCloudWorker
|
60
|
+
* Used to define the zkCloudWorker methods and properties
|
61
|
+
* Should be implemented for by the developer for the zkCloudWorker in the cloud
|
62
|
+
* @param cloud: the cloud
|
63
|
+
*/
|
23
64
|
class zkCloudWorker {
|
65
|
+
/**
|
66
|
+
* Constructor for the zkCloudWorker class
|
67
|
+
* @param cloud the cloud instance provided by the zkCloudWorker in the local environment or in the cloud
|
68
|
+
*/
|
24
69
|
constructor(cloud) {
|
25
70
|
this.cloud = cloud;
|
26
71
|
}
|
27
|
-
|
72
|
+
/**
|
73
|
+
* Returns the deployed smart contracts for verification in the blockchain explorer
|
74
|
+
* @returns the deployed smart contracts
|
75
|
+
*/
|
28
76
|
async deployedContracts() {
|
29
77
|
return [];
|
30
78
|
}
|
31
79
|
// Those methods should be implemented for recursive proofs calculations
|
80
|
+
/**
|
81
|
+
* Creates a new proof from a transaction
|
82
|
+
* @param transaction the transaction
|
83
|
+
* @returns the serialized proof
|
84
|
+
*/
|
32
85
|
async create(transaction) {
|
33
86
|
return undefined;
|
34
87
|
}
|
88
|
+
/**
|
89
|
+
* Merges two proofs
|
90
|
+
* @param proof1 the first proof
|
91
|
+
* @param proof2 the second proof
|
92
|
+
* @returns the merged proof
|
93
|
+
*/
|
35
94
|
async merge(proof1, proof2) {
|
36
95
|
return undefined;
|
37
96
|
}
|
38
97
|
// Those methods should be implemented for anything except for recursive proofs
|
98
|
+
/**
|
99
|
+
* Executes the transactions
|
100
|
+
* @param transactions the transactions, can be empty list
|
101
|
+
* @returns the result
|
102
|
+
*/
|
39
103
|
async execute(transactions) {
|
40
104
|
return undefined;
|
41
105
|
}
|
42
|
-
|
106
|
+
/* Process the transactions received by the cloud
|
107
|
+
* @param transactions: the transactions
|
108
|
+
*/
|
43
109
|
async processTransactions(transactions) { }
|
44
|
-
|
110
|
+
/**
|
111
|
+
* process the task defined by the developer
|
112
|
+
* @returns the result
|
113
|
+
*/
|
45
114
|
async task() {
|
46
115
|
return undefined;
|
47
116
|
}
|
@@ -1,10 +1,57 @@
|
|
1
1
|
import { blockchain } from "../networks";
|
2
2
|
export type JobStatus = "created" | "started" | "finished" | "failed" | "used";
|
3
|
+
/**
|
4
|
+
* LogStream is a subset of the log stream data returned by AWS CloudWatch Logs when running the worker
|
5
|
+
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/cloudwatch-logs/command/GetLogEventsCommand/
|
6
|
+
* example:
|
7
|
+
* {
|
8
|
+
* logGroupName: '/aws/lambda/zkcloudworker-dev-test',
|
9
|
+
* logStreamName: '2024/05/09/[$LATEST]52d048f64e894d2e8ba2800df93629c5'
|
10
|
+
* awsRequestId: '581d0d45-9165-47e8-84d9-678599938811',
|
11
|
+
* }
|
12
|
+
* @param logGroupName the log group name
|
13
|
+
* @param logStreamName the log stream name
|
14
|
+
* @param awsRequestId the AWS request ID
|
15
|
+
*/
|
3
16
|
export interface LogStream {
|
4
17
|
logGroupName: string;
|
5
18
|
logStreamName: string;
|
6
19
|
awsRequestId: string;
|
7
20
|
}
|
21
|
+
/**
|
22
|
+
* JobData is the data structure for a job, keeping track of the job status, result, logs, and metadata
|
23
|
+
* @param id the id of the user
|
24
|
+
* @param jobId the id of the job
|
25
|
+
* @param taskId the id of the task
|
26
|
+
* @param developer the developer of the repo executing the job
|
27
|
+
* @param repo the repo executing the job
|
28
|
+
* @param task the task to execute
|
29
|
+
* @param userId the id of the user
|
30
|
+
* @param args the arguments for the job
|
31
|
+
* @param metadata the metadata for the job
|
32
|
+
* @param chain the blockchain to execute the job on
|
33
|
+
* @param webhook the webhook to call after the job finishes
|
34
|
+
* @param cloudhook the cloudhook to call after the job finishes
|
35
|
+
* @param cloudIteration the recursive call number, must be less than 5
|
36
|
+
* @param previousJob the previous job data, provided in case of the cloudhook
|
37
|
+
*
|
38
|
+
* @param filename the filename where transactions data is stored
|
39
|
+
* @param txNumber the number of transactions
|
40
|
+
* @param timeCreated the time the job was created
|
41
|
+
* @param timeCreatedString the time the job was created as a string
|
42
|
+
* @param timeStarted the time the job was started
|
43
|
+
* @param timeFinished the time the job was finished
|
44
|
+
* @param timeFailed the time the job failed
|
45
|
+
* @param timeUsed the time the job result was used
|
46
|
+
* @param billedDuration the duration the job was billed for
|
47
|
+
* @param feeMINA the fee in MINA
|
48
|
+
* @param feeUSD the fee in USD
|
49
|
+
* @param jobStatus the status of the job
|
50
|
+
* @param maxAttempts the maximum number of attempts
|
51
|
+
* @param result the result of the job
|
52
|
+
* @param logStreams the log streams of the job
|
53
|
+
* @param logs the logs of the job
|
54
|
+
*/
|
8
55
|
export interface JobData {
|
9
56
|
id: string;
|
10
57
|
jobId: string;
|