zkcloudworker 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/lib/ts/src/api/api.d.ts +37 -26
  2. package/lib/ts/src/api/api.js +26 -26
  3. package/lib/ts/src/cloud/cloud.d.ts +175 -0
  4. package/lib/ts/src/cloud/cloud.js +71 -3
  5. package/lib/ts/src/cloud/job.d.ts +47 -0
  6. package/lib/ts/src/cloud/local.d.ts +157 -1
  7. package/lib/ts/src/cloud/local.js +157 -3
  8. package/lib/ts/src/cloud/task.d.ts +18 -0
  9. package/lib/ts/src/networks.d.ts +20 -0
  10. package/lib/ts/src/utils/fee.d.ts +4 -0
  11. package/lib/ts/src/utils/fee.js +5 -1
  12. package/lib/ts/src/utils/fetch.d.ts +20 -0
  13. package/lib/ts/src/utils/fetch.js +20 -0
  14. package/lib/ts/src/utils/fields.d.ts +10 -0
  15. package/lib/ts/src/utils/fields.js +10 -0
  16. package/lib/ts/src/utils/mina.d.ts +24 -0
  17. package/lib/ts/src/utils/mina.js +18 -0
  18. package/lib/ts/tsconfig.tsbuildinfo +1 -1
  19. package/lib/web/src/api/api.d.ts +37 -26
  20. package/lib/web/src/api/api.js +26 -26
  21. package/lib/web/src/api/api.js.map +1 -1
  22. package/lib/web/src/cloud/cloud.d.ts +175 -0
  23. package/lib/web/src/cloud/cloud.js +71 -3
  24. package/lib/web/src/cloud/cloud.js.map +1 -1
  25. package/lib/web/src/cloud/job.d.ts +47 -0
  26. package/lib/web/src/cloud/local.d.ts +157 -1
  27. package/lib/web/src/cloud/local.js +157 -3
  28. package/lib/web/src/cloud/local.js.map +1 -1
  29. package/lib/web/src/cloud/task.d.ts +18 -0
  30. package/lib/web/src/networks.d.ts +20 -0
  31. package/lib/web/src/networks.js.map +1 -1
  32. package/lib/web/src/utils/fee.d.ts +4 -0
  33. package/lib/web/src/utils/fee.js +5 -1
  34. package/lib/web/src/utils/fee.js.map +1 -1
  35. package/lib/web/src/utils/fetch.d.ts +20 -0
  36. package/lib/web/src/utils/fetch.js +20 -0
  37. package/lib/web/src/utils/fetch.js.map +1 -1
  38. package/lib/web/src/utils/fields.d.ts +10 -0
  39. package/lib/web/src/utils/fields.js +10 -0
  40. package/lib/web/src/utils/fields.js.map +1 -1
  41. package/lib/web/src/utils/mina.d.ts +24 -0
  42. package/lib/web/src/utils/mina.js +18 -0
  43. package/lib/web/src/utils/mina.js.map +1 -1
  44. package/lib/web/tsconfig.web.tsbuildinfo +1 -1
  45. package/package.json +1 -1
@@ -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;
@@ -15,6 +29,9 @@ export declare class zkCloudWorkerClient {
15
29
  /**
16
30
  * Constructor for the API class
17
31
  * @param jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
32
+ * @param zkcloudworker The local worker for the serverless api to test the code locally
33
+ * @param chain The blockchain network to use
34
+ * @param webhook The webhook for the serverless api to get the results
18
35
  */
19
36
  constructor(params: {
20
37
  jwt: string;
@@ -24,19 +41,20 @@ export declare class zkCloudWorkerClient {
24
41
  });
25
42
  /**
26
43
  * 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
44
  * @param data the data for the proof call
30
- * @param data.transactions the transactions
31
45
  * @param data.developer the developer
32
46
  * @param data.repo the repo to use
47
+ * @param data.transactions the transactions
33
48
  * @param data.task the task of the job
34
- * @param data.args the arguments of the job
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
35
53
  * @returns { success: boolean, error?: string, jobId?: string }
36
54
  * where jonId is the jobId of the job
37
55
  *
38
- * The developers repo should provide a BackupPlugin with the name task
39
- * 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
40
58
  */
41
59
  recursiveProof(data: {
42
60
  developer: string;
@@ -54,8 +72,6 @@ export declare class zkCloudWorkerClient {
54
72
  }>;
55
73
  /**
56
74
  * 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
75
  * @param data the data for the proof call
60
76
  * @param data.developer the developer
61
77
  * @param data.repo the repo to use
@@ -65,8 +81,8 @@ export declare class zkCloudWorkerClient {
65
81
  * @param data.args the arguments of the job
66
82
  * @param data.metadata the metadata of the job
67
83
  * @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
84
+ * @returns { success: boolean, error?: string, jobId?: string, result?: any }
85
+ * where jonId is the jobId of the job (for async calls), result is the result of the job (for sync calls)
70
86
  */
71
87
  execute(data: {
72
88
  developer: string;
@@ -84,16 +100,13 @@ export declare class zkCloudWorkerClient {
84
100
  result?: any;
85
101
  }>;
86
102
  /**
87
- * Starts a new job for the function call using serverless api call
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
103
+ * Sends transactions to the blockchain using serverless api call
90
104
  * @param data the data for the proof call
91
105
  * @param data.developer the developer
92
106
  * @param data.repo the repo to use
93
- * @param data.task the task of the job
94
- * @param data.args the arguments of the job
95
- * @returns { success: boolean, error?: string, jobId?: string }
96
- * where jonId is the jobId of the job
107
+ * @param data.transactions the transactions
108
+ * @returns { success: boolean, error?: string, txId?: string[] }
109
+ * where txId is the transaction id of the transaction, in the sequence of the input transactions
97
110
  */
98
111
  sendTransactions(data: {
99
112
  developer: string;
@@ -125,15 +138,13 @@ export declare class zkCloudWorkerClient {
125
138
  result?: any;
126
139
  }>;
127
140
  /**
128
- * Gets the result of the job using serverless api call
141
+ * Deploys the code to the cloud using serverless api call
129
142
  * @param data the data for the deploy call
130
- * @param data.packageName the name of the zip file with the code to be deployed
131
- * @returns { success: boolean, error?: string, result?: any }
132
- * where result is the result of the job
133
- * if the job is not finished yet, the result will be undefined
134
- * if the job failed, the result will be undefined and error will be set
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
143
+ * @param data.repo the repo to use
144
+ * @param data.developer the developer
145
+ * @param data.packageManager the package manager to use
146
+ * @returns { success: boolean, error?: string, jobId?: string}
147
+ * where jobId is the jobId of the job
137
148
  */
138
149
  deploy(data: {
139
150
  repo: string;
@@ -157,7 +168,7 @@ export declare class zkCloudWorkerClient {
157
168
  /**
158
169
  * Gets the remaining balance
159
170
  * @returns { success: boolean, error?: string, result?: any }
160
- * where result is the billing report
171
+ * where result is the balance
161
172
  */
162
173
  getBalance(): Promise<{
163
174
  success: boolean;
@@ -14,11 +14,17 @@ 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
24
  * @param jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
25
+ * @param zkcloudworker The local worker for the serverless api to test the code locally
26
+ * @param chain The blockchain network to use
27
+ * @param webhook The webhook for the serverless api to get the results
22
28
  */
23
29
  constructor(params) {
24
30
  const { jwt, zkcloudworker, chain, webhook } = params;
@@ -34,19 +40,20 @@ class zkCloudWorkerClient {
34
40
  }
35
41
  /**
36
42
  * 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
43
  * @param data the data for the proof call
40
- * @param data.transactions the transactions
41
44
  * @param data.developer the developer
42
45
  * @param data.repo the repo to use
46
+ * @param data.transactions the transactions
43
47
  * @param data.task the task of the job
44
- * @param data.args the arguments of the job
48
+ * @param data.userId the userId of the job
49
+ * @param data.args the arguments of the job, should be serialized JSON or string
50
+ * @param data.metadata the metadata of the job, should be serialized JSON or string
51
+ * @param data.webhook the webhook for the job
45
52
  * @returns { success: boolean, error?: string, jobId?: string }
46
53
  * where jonId is the jobId of the job
47
54
  *
48
- * The developers repo should provide a BackupPlugin with the name task
49
- * that can be called with the given parameters
55
+ * The developers repo should provide a zkcloudworker function
56
+ * that can be called with the given parameters, see the examples
50
57
  */
51
58
  async recursiveProof(data) {
52
59
  const result = await this.apiHub("recursiveProof", data);
@@ -77,8 +84,6 @@ class zkCloudWorkerClient {
77
84
  }
78
85
  /**
79
86
  * 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
87
  * @param data the data for the proof call
83
88
  * @param data.developer the developer
84
89
  * @param data.repo the repo to use
@@ -88,8 +93,8 @@ class zkCloudWorkerClient {
88
93
  * @param data.args the arguments of the job
89
94
  * @param data.metadata the metadata of the job
90
95
  * @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
96
+ * @returns { success: boolean, error?: string, jobId?: string, result?: any }
97
+ * where jonId is the jobId of the job (for async calls), result is the result of the job (for sync calls)
93
98
  */
94
99
  async execute(data) {
95
100
  const result = await this.apiHub("execute", data);
@@ -130,16 +135,13 @@ class zkCloudWorkerClient {
130
135
  };
131
136
  }
132
137
  /**
133
- * Starts a new job for the function call using serverless api call
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
138
+ * Sends transactions to the blockchain using serverless api call
136
139
  * @param data the data for the proof call
137
140
  * @param data.developer the developer
138
141
  * @param data.repo the repo to use
139
- * @param data.task the task of the job
140
- * @param data.args the arguments of the job
141
- * @returns { success: boolean, error?: string, jobId?: string }
142
- * where jonId is the jobId of the job
142
+ * @param data.transactions the transactions
143
+ * @returns { success: boolean, error?: string, txId?: string[] }
144
+ * where txId is the transaction id of the transaction, in the sequence of the input transactions
143
145
  */
144
146
  async sendTransactions(data) {
145
147
  const result = await this.apiHub("sendTransactions", data);
@@ -184,15 +186,13 @@ class zkCloudWorkerClient {
184
186
  };
185
187
  }
186
188
  /**
187
- * Gets the result of the job using serverless api call
189
+ * Deploys the code to the cloud using serverless api call
188
190
  * @param data the data for the deploy call
189
- * @param data.packageName the name of the zip file with the code to be deployed
190
- * @returns { success: boolean, error?: string, result?: any }
191
- * where result is the result of the job
192
- * if the job is not finished yet, the result will be undefined
193
- * if the job failed, the result will be undefined and error will be set
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
191
+ * @param data.repo the repo to use
192
+ * @param data.developer the developer
193
+ * @param data.packageManager the package manager to use
194
+ * @returns { success: boolean, error?: string, jobId?: string}
195
+ * where jobId is the jobId of the job
196
196
  */
197
197
  async deploy(data) {
198
198
  // TODO: encrypt env.json
@@ -238,7 +238,7 @@ class zkCloudWorkerClient {
238
238
  /**
239
239
  * Gets the remaining balance
240
240
  * @returns { success: boolean, error?: string, result?: any }
241
- * where result is the billing report
241
+ * where result is the balance
242
242
  */
243
243
  async getBalance() {
244
244
  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,22 @@ 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 id: the id of the user
64
+ * @param jobId: the job id
65
+ * @param stepId: the step id
66
+ * @param taskId: the task id
67
+ * @param cache: the cache folder. Use it to get the Cache object: cache = Cache.FileSystem(this.cloud.cache);
68
+ * @param developer: the developer id
69
+ * @param repo: the repo id
70
+ * @param task: the task id
71
+ * @param userId: the user id
72
+ * @param args: the arguments, should be a string or serialized JSON
73
+ * @param metadata: the metadata, should be a string or serialized JSON
74
+ * @param chain: the blockchain network
75
+ * @param isLocalCloud: a boolean to check if the cloud is local or not
76
+ */
36
77
  constructor(params: {
37
78
  id: string;
38
79
  jobId: string;
@@ -48,16 +89,69 @@ export declare abstract class Cloud {
48
89
  isLocalCloud?: boolean;
49
90
  chain: blockchain;
50
91
  });
92
+ /**
93
+ * Abstract method to get the deployer key pair
94
+ * Used to get the public and private keys of the deployer for test networks only
95
+ * Devnet and Zeko are supported
96
+ * @returns the deployer key pair
97
+ */
51
98
  abstract getDeployer(): Promise<DeployerKeyPair | undefined>;
99
+ /**
100
+ * Abstract method to release the deployer
101
+ * @param params: the public key of the deployer and the transactions hashes
102
+ * Used to release the deployer after the transactions are sent to the blockchain
103
+ * @param publicKey: the public key of the deployer
104
+ * @param txsHashes: the transactions hashes
105
+ */
52
106
  abstract releaseDeployer(params: {
53
107
  publicKey: string;
54
108
  txsHashes: string[];
55
109
  }): Promise<void>;
110
+ /**
111
+ * Abstract method to get the data by key
112
+ * Used to get the data by key from the cloud storage
113
+ * @param key: the key
114
+ * @returns the value of the key
115
+ */
56
116
  abstract getDataByKey(key: string): Promise<string | undefined>;
117
+ /**
118
+ * Abstract method to save the data by key
119
+ * Used to save the data by key to the cloud storage
120
+ * @param key: the key
121
+ * @param value: the value
122
+ */
57
123
  abstract saveDataByKey(key: string, value: string | undefined): Promise<void>;
124
+ /**
125
+ * Abstract method to save the file
126
+ * Used to save the file to the cloud storage
127
+ * @param filename: the filename
128
+ * @param value: the value
129
+ */
58
130
  abstract saveFile(filename: string, value: Buffer): Promise<void>;
131
+ /**
132
+ * Abstract method to load the file
133
+ * Used to load the file from the cloud storage
134
+ * @param filename: the filename
135
+ * @returns the value of the file
136
+ */
59
137
  abstract loadFile(filename: string): Promise<Buffer | undefined>;
138
+ /**
139
+ * Abstract method to load the environment
140
+ * Used to load the environment from the cloud storage
141
+ * @param password: the password
142
+ */
60
143
  abstract loadEnvironment(password: string): Promise<void>;
144
+ /**
145
+ * Abstract method to calculate the recursive proof
146
+ * Used to calculate the recursive proof
147
+ * @param data: the data
148
+ * @param data.transactions: the transactions
149
+ * @param data.task: the task
150
+ * @param data.userId: the user id
151
+ * @param data.args: the arguments
152
+ * @param data.metadata: the metadata
153
+ * @returns the proof
154
+ */
61
155
  abstract recursiveProof(data: {
62
156
  transactions: string[];
63
157
  task?: string;
@@ -65,6 +159,17 @@ export declare abstract class Cloud {
65
159
  args?: string;
66
160
  metadata?: string;
67
161
  }): Promise<string>;
162
+ /**
163
+ * Abstract method to execute the transactions
164
+ * Used to execute the transactions
165
+ * @param data: the data
166
+ * @param data.transactions: the transactions
167
+ * @param data.task: the task
168
+ * @param data.userId: the user id
169
+ * @param data.args: the arguments
170
+ * @param data.metadata: the metadata
171
+ * @returns the result
172
+ */
68
173
  abstract execute(data: {
69
174
  transactions: string[];
70
175
  task: string;
@@ -72,6 +177,18 @@ export declare abstract class Cloud {
72
177
  args?: string;
73
178
  metadata?: string;
74
179
  }): Promise<string>;
180
+ /**
181
+ * Abstract method to add the task
182
+ * Used to add the task
183
+ * @param data: the data
184
+ * @param data.task: the task
185
+ * @param data.startTime: the start time
186
+ * @param data.userId: the user id
187
+ * @param data.args: the arguments
188
+ * @param data.metadata: the metadata
189
+ * @param data.maxAttempts: the maximum attempts
190
+ * @returns the task id
191
+ */
75
192
  abstract addTask(data: {
76
193
  task: string;
77
194
  startTime?: number;
@@ -80,19 +197,77 @@ export declare abstract class Cloud {
80
197
  metadata?: string;
81
198
  maxAttempts?: number;
82
199
  }): Promise<string>;
200
+ /**
201
+ * Abstract method to delete the transaction
202
+ * Used to delete the transaction
203
+ * @param txId: the transaction id
204
+ */
83
205
  abstract deleteTransaction(txId: string): Promise<void>;
206
+ /**
207
+ * Abstract method to get the transactions
208
+ * Used to get the transactions
209
+ * @returns the transactions
210
+ */
84
211
  abstract getTransactions(): Promise<CloudTransaction[]>;
212
+ /**
213
+ * Abstract method to delete the task
214
+ * Used to delete the task
215
+ * @param taskId: the task id
216
+ */
85
217
  abstract deleteTask(taskId: string): Promise<void>;
218
+ /**
219
+ * Abstract method to process the tasks
220
+ */
86
221
  abstract processTasks(): Promise<void>;
222
+ /**
223
+ * Abstract method to get the job result
224
+ * Used to get the job result
225
+ * @param jobId: the job id
226
+ * @returns the job result
227
+ */
87
228
  abstract jobResult(jobId: string): Promise<JobData | undefined>;
88
229
  }
230
+ /**
231
+ * Abstract class for the zkCloudWorker
232
+ * Used to define the zkCloudWorker methods and properties
233
+ * Should be implemented for by the developer for the zkCloudWorker in the cloud
234
+ * @param cloud: the cloud
235
+ */
89
236
  export declare abstract class zkCloudWorker {
90
237
  readonly cloud: Cloud;
238
+ /**
239
+ * Constructor for the zkCloudWorker class
240
+ * @param cloud: the cloud instance provided by the zkCloudWorker in the local environment or in the cloud
241
+ */
91
242
  constructor(cloud: Cloud);
243
+ /**
244
+ * Returns the deployed smart contracts for verification in the blockchain explorer
245
+ * @returns the deployed smart contracts
246
+ */
92
247
  deployedContracts(): Promise<DeployedSmartContract[]>;
248
+ /**
249
+ * Creates a new proof from a transaction
250
+ * @param transaction: the transaction
251
+ * @returns the serialized proof
252
+ */
93
253
  create(transaction: string): Promise<string | undefined>;
254
+ /**
255
+ * Merges two proofs
256
+ * @param proof1: the first proof
257
+ * @param proof2: the second proof
258
+ * @returns the merged proof
259
+ */
94
260
  merge(proof1: string, proof2: string): Promise<string | undefined>;
261
+ /**
262
+ * Executes the transactions
263
+ * @param transactions: the transactions, can be empty list
264
+ * @returns the result
265
+ */
95
266
  execute(transactions: string[]): Promise<string | undefined>;
96
267
  processTransactions(transactions: CloudTransaction[]): Promise<void>;
268
+ /**
269
+ * process the task defined by the developer
270
+ * @returns the result
271
+ */
97
272
  task(): Promise<string | undefined>;
98
273
  }
@@ -1,7 +1,41 @@
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
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 id: the id of the user
26
+ * @param jobId: the job id
27
+ * @param stepId: the step id
28
+ * @param taskId: the task id
29
+ * @param cache: the cache folder. Use it to get the Cache object: cache = Cache.FileSystem(this.cloud.cache);
30
+ * @param developer: the developer id
31
+ * @param repo: the repo id
32
+ * @param task: the task id
33
+ * @param userId: the user id
34
+ * @param args: the arguments, should be a string or serialized JSON
35
+ * @param metadata: the metadata, should be a string or serialized JSON
36
+ * @param chain: the blockchain network
37
+ * @param isLocalCloud: a boolean to check if the cloud is local or not
38
+ */
5
39
  constructor(params) {
6
40
  const { id, jobId, stepId, taskId, cache, developer, repo, task, userId, args, metadata, isLocalCloud, chain, } = params;
7
41
  this.id = id;
@@ -20,28 +54,62 @@ class Cloud {
20
54
  }
21
55
  }
22
56
  exports.Cloud = Cloud;
57
+ /**
58
+ * Abstract class for the zkCloudWorker
59
+ * Used to define the zkCloudWorker methods and properties
60
+ * Should be implemented for by the developer for the zkCloudWorker in the cloud
61
+ * @param cloud: the cloud
62
+ */
23
63
  class zkCloudWorker {
64
+ /**
65
+ * Constructor for the zkCloudWorker class
66
+ * @param cloud: the cloud instance provided by the zkCloudWorker in the local environment or in the cloud
67
+ */
24
68
  constructor(cloud) {
25
69
  this.cloud = cloud;
26
70
  }
27
- // To verify the SmartContract code
71
+ /**
72
+ * Returns the deployed smart contracts for verification in the blockchain explorer
73
+ * @returns the deployed smart contracts
74
+ */
28
75
  async deployedContracts() {
29
76
  return [];
30
77
  }
31
78
  // Those methods should be implemented for recursive proofs calculations
79
+ /**
80
+ * Creates a new proof from a transaction
81
+ * @param transaction: the transaction
82
+ * @returns the serialized proof
83
+ */
32
84
  async create(transaction) {
33
85
  return undefined;
34
86
  }
87
+ /**
88
+ * Merges two proofs
89
+ * @param proof1: the first proof
90
+ * @param proof2: the second proof
91
+ * @returns the merged proof
92
+ */
35
93
  async merge(proof1, proof2) {
36
94
  return undefined;
37
95
  }
38
96
  // Those methods should be implemented for anything except for recursive proofs
97
+ /**
98
+ * Executes the transactions
99
+ * @param transactions: the transactions, can be empty list
100
+ * @returns the result
101
+ */
39
102
  async execute(transactions) {
40
103
  return undefined;
41
104
  }
42
- // process the transactions received by the cloud
105
+ /* Process the transactions received by the cloud
106
+ * @param transactions: the transactions
107
+ */
43
108
  async processTransactions(transactions) { }
44
- // process the task defined by the developer
109
+ /**
110
+ * process the task defined by the developer
111
+ * @returns the result
112
+ */
45
113
  async task() {
46
114
  return undefined;
47
115
  }
@@ -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;