zkcloudworker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +79 -0
- package/lib/ts/src/api/api.d.ts +93 -0
- package/lib/ts/src/api/api.js +188 -0
- package/lib/ts/src/cloud/cloud.d.ts +7 -0
- package/lib/ts/src/cloud/cloud.js +9 -0
- package/lib/ts/src/config.d.ts +6 -0
- package/lib/ts/src/config.js +8 -0
- package/lib/ts/src/fee.d.ts +2 -0
- package/lib/ts/src/fee.js +13 -0
- package/lib/ts/src/index.d.ts +5 -0
- package/lib/ts/src/index.js +21 -0
- package/lib/ts/src/mina.d.ts +22 -0
- package/lib/ts/src/mina.js +110 -0
- package/lib/ts/src/networks.d.ts +13 -0
- package/lib/ts/src/networks.js +27 -0
- package/lib/ts/tsconfig.tsbuildinfo +1 -0
- package/lib/web/src/api/api.d.ts +93 -0
- package/lib/web/src/api/api.js +194 -0
- package/lib/web/src/api/api.js.map +1 -0
- package/lib/web/src/cloud/cloud.d.ts +7 -0
- package/lib/web/src/cloud/cloud.js +6 -0
- package/lib/web/src/cloud/cloud.js.map +1 -0
- package/lib/web/src/config.d.ts +6 -0
- package/lib/web/src/config.js +7 -0
- package/lib/web/src/config.js.map +1 -0
- package/lib/web/src/fee.d.ts +2 -0
- package/lib/web/src/fee.js +10 -0
- package/lib/web/src/fee.js.map +1 -0
- package/lib/web/src/index.d.ts +5 -0
- package/lib/web/src/index.js +6 -0
- package/lib/web/src/index.js.map +1 -0
- package/lib/web/src/mina.d.ts +22 -0
- package/lib/web/src/mina.js +107 -0
- package/lib/web/src/mina.js.map +1 -0
- package/lib/web/src/networks.d.ts +13 -0
- package/lib/web/src/networks.js +23 -0
- package/lib/web/src/networks.js.map +1 -0
- package/lib/web/tsconfig.web.tsbuildinfo +1 -0
- package/package.json +46 -0
package/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# zkCloudWorker library
|
2
|
+
|
3
|
+
In the fast-paced realm of ZK proving, zkCloudWorker stands out as a potential game-changer for both zkApp developers and users.
|
4
|
+
|
5
|
+
By delivering ultra-fast proving in the cloud, along with robust isolation, composability, and an excellent user experience (UX), zkCloudWorker has the potential to significantly streamline and expedite the development of MINA zkApps both on web and mobile devices.
|
6
|
+
|
7
|
+
Instead of downloading 1 GB of proving keys, compiling, and performing proofs on a web or mobile worker, a simple API call can be made to the powerful zkCloudWorker to launch a worker in the cloud. This offers ample memory, CPU power, and parallel processing capabilities for recursive proof calculations.
|
8
|
+
|
9
|
+
Privacy is maintained through the isolation of processes, encryption of all data, and the ability to process private data on the web using technologies like hashing and Merkle Tree calculations. Preprocessed data is then sent to the cloud worker.
|
10
|
+
|
11
|
+
This opens doors for a diverse range of Web2 developers to seamlessly enter the exciting world of the MINA protocol and o1js.
|
12
|
+
|
13
|
+
## Features
|
14
|
+
|
15
|
+
- Compiling the contract in the cloud.
|
16
|
+
|
17
|
+
- Calculating transactions proofs tx.prove().
|
18
|
+
|
19
|
+
- Calculating recursive proofs.
|
20
|
+
|
21
|
+
- Sending transactions to network.
|
22
|
+
|
23
|
+
- Verifying proofs.
|
24
|
+
|
25
|
+
- Providing deployers to pay the tx fee.
|
26
|
+
|
27
|
+
- API to be accessed inside the zkCloudWorker.
|
28
|
+
|
29
|
+
- API to be accessed inside the web application.
|
30
|
+
|
31
|
+
- Billing panel to show the cost of the running zkCloudWorkers to the developer.
|
32
|
+
|
33
|
+
- Web dashboard to easily deploy and access deployed zkCloudWorkers and their logs.
|
34
|
+
|
35
|
+
- Providing key-value off-chain storage for zkApps, up to 400K size for values.
|
36
|
+
|
37
|
+
- Providing file storage for zkApps, unlimited size.
|
38
|
+
|
39
|
+
- Encryption utilities for sending and storing the data in the encrypted form.
|
40
|
+
|
41
|
+
- Verifying the text of the contracts for uploading to the minascan.io explorer.
|
42
|
+
|
43
|
+
- Providing additional metadata for the transactions, including custom metadata defined by the developer and the conversion of the actions and events to the human-readable form as defined by the developer for publishing on the minascan.io explorer.
|
44
|
+
|
45
|
+
- Code templates and question-answer sets for the zkApp Umstad AI Chatbot.
|
46
|
+
|
47
|
+
- The CLI tool to deploy the code to the cloud and verify the code on the minascan.io.
|
48
|
+
|
49
|
+
- Availability of the zkCloudWorker for SmartContract, ZkProgram and general calculations, including running ProtoKit chains in case ProtoKit will support running on the serverless infrastructure, that is possible in principle.
|
50
|
+
|
51
|
+
- Custom integration of the zkApps for the cases that do not fit in the standard framework for some reason.
|
52
|
+
|
53
|
+
## Installation
|
54
|
+
|
55
|
+
```
|
56
|
+
yarn add zkcloudworker
|
57
|
+
```
|
58
|
+
|
59
|
+
## Documentation
|
60
|
+
|
61
|
+
https://docs.zkcloudworker.com
|
62
|
+
|
63
|
+
## Website
|
64
|
+
|
65
|
+
https://zkcloudworker.com
|
66
|
+
|
67
|
+
## Library on NPM
|
68
|
+
|
69
|
+
https://www.npmjs.com/package/zkcloudworker
|
70
|
+
|
71
|
+
## Homomorphic Encryption Example
|
72
|
+
|
73
|
+
https://github.com/dfstio/he-contract-demo
|
74
|
+
|
75
|
+
## Faucet
|
76
|
+
|
77
|
+
https://faucet.minaprotocol.com
|
78
|
+
|
79
|
+
https://minanft.io/faucet
|
@@ -0,0 +1,93 @@
|
|
1
|
+
/**
|
2
|
+
* API class for interacting with the zkCloudWorker
|
3
|
+
* @property jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
|
4
|
+
* @property endpoint The endpoint of the serverless api
|
5
|
+
*/
|
6
|
+
export declare class zkCloudWorker {
|
7
|
+
jwt: string;
|
8
|
+
endpoint: string;
|
9
|
+
/**
|
10
|
+
* Constructor for the API class
|
11
|
+
* @param jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
|
12
|
+
*/
|
13
|
+
constructor(jwt: string);
|
14
|
+
/**
|
15
|
+
* Starts a new job for the proof calculation using serverless api call
|
16
|
+
* The developer and name should correspond to the BackupPlugin of the API
|
17
|
+
* All other parameters should correspond to the parameters of the BackupPlugin
|
18
|
+
* @param data the data for the proof call
|
19
|
+
* @param data.transactions the transactions
|
20
|
+
* @param data.developer the developer
|
21
|
+
* @param data.name the name of the job
|
22
|
+
* @param data.task the task of the job
|
23
|
+
* @param data.args the arguments of the job
|
24
|
+
* @returns { success: boolean, error?: string, jobId?: string }
|
25
|
+
* where jonId is the jobId of the job
|
26
|
+
*/
|
27
|
+
createJob(data: {
|
28
|
+
transactions: string[];
|
29
|
+
developer: string;
|
30
|
+
name: string;
|
31
|
+
task: string;
|
32
|
+
args: string[];
|
33
|
+
}): Promise<{
|
34
|
+
success: boolean;
|
35
|
+
error?: string;
|
36
|
+
jobId?: string;
|
37
|
+
}>;
|
38
|
+
/**
|
39
|
+
* Gets the result of the job using serverless api call
|
40
|
+
* @param data the data for the jobResult call
|
41
|
+
* @param data.jobId the jobId of the job
|
42
|
+
* @returns { success: boolean, error?: string, result?: any }
|
43
|
+
* where result is the result of the job
|
44
|
+
* if the job is not finished yet, the result will be undefined
|
45
|
+
* if the job failed, the result will be undefined and error will be set
|
46
|
+
* if the job is finished, the result will be set and error will be undefined
|
47
|
+
* if the job is not found, the result will be undefined and error will be set
|
48
|
+
*/
|
49
|
+
jobResult(data: {
|
50
|
+
jobId: string;
|
51
|
+
}): Promise<{
|
52
|
+
success: boolean;
|
53
|
+
error?: string;
|
54
|
+
result?: any;
|
55
|
+
}>;
|
56
|
+
/**
|
57
|
+
* Gets the billing report for the jobs sent using JWT
|
58
|
+
* @returns { success: boolean, error?: string, result?: any }
|
59
|
+
* where result is the billing report
|
60
|
+
*/
|
61
|
+
queryBilling(): Promise<{
|
62
|
+
success: boolean;
|
63
|
+
error?: string;
|
64
|
+
result?: any;
|
65
|
+
}>;
|
66
|
+
/**
|
67
|
+
* Waits for the job to finish
|
68
|
+
* @param data the data for the waitForJobResult call
|
69
|
+
* @param data.jobId the jobId of the job
|
70
|
+
* @param data.maxAttempts the maximum number of attempts, default is 360 (2 hours)
|
71
|
+
* @param data.interval the interval between attempts, default is 20000 (20 seconds)
|
72
|
+
* @param data.maxErrors the maximum number of network errors, default is 10
|
73
|
+
* @returns { success: boolean, error?: string, result?: any }
|
74
|
+
* where result is the result of the job
|
75
|
+
*/
|
76
|
+
waitForJobResult(data: {
|
77
|
+
jobId: string;
|
78
|
+
maxAttempts?: number;
|
79
|
+
interval?: number;
|
80
|
+
maxErrors?: number;
|
81
|
+
}): Promise<{
|
82
|
+
success: boolean;
|
83
|
+
error?: string;
|
84
|
+
result?: any;
|
85
|
+
}>;
|
86
|
+
/**
|
87
|
+
* Calls the serverless API
|
88
|
+
* @param command the command of the API
|
89
|
+
* @param data the data of the API
|
90
|
+
* */
|
91
|
+
private apiHub;
|
92
|
+
private isError;
|
93
|
+
}
|
@@ -0,0 +1,188 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.zkCloudWorker = void 0;
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
8
|
+
const mina_1 = require("../mina");
|
9
|
+
const config_1 = __importDefault(require("../config"));
|
10
|
+
const { ZKCLOUDWORKER_AUTH, ZKCLOUDWORKER_API } = config_1.default;
|
11
|
+
/**
|
12
|
+
* API class for interacting with the zkCloudWorker
|
13
|
+
* @property jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
|
14
|
+
* @property endpoint The endpoint of the serverless api
|
15
|
+
*/
|
16
|
+
class zkCloudWorker {
|
17
|
+
/**
|
18
|
+
* Constructor for the API class
|
19
|
+
* @param jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
|
20
|
+
*/
|
21
|
+
constructor(jwt) {
|
22
|
+
this.jwt = jwt;
|
23
|
+
this.endpoint = ZKCLOUDWORKER_API;
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* 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
|
+
* @param data the data for the proof call
|
30
|
+
* @param data.transactions the transactions
|
31
|
+
* @param data.developer the developer
|
32
|
+
* @param data.name the name of the job
|
33
|
+
* @param data.task the task of the job
|
34
|
+
* @param data.args the arguments of the job
|
35
|
+
* @returns { success: boolean, error?: string, jobId?: string }
|
36
|
+
* where jonId is the jobId of the job
|
37
|
+
*/
|
38
|
+
async createJob(data) {
|
39
|
+
const result = await this.apiHub("createJob", data);
|
40
|
+
if (result.data === "error")
|
41
|
+
return {
|
42
|
+
success: false,
|
43
|
+
error: result.error,
|
44
|
+
};
|
45
|
+
else
|
46
|
+
return {
|
47
|
+
success: result.success,
|
48
|
+
jobId: result.data,
|
49
|
+
error: result.error,
|
50
|
+
};
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* Gets the result of the job using serverless api call
|
54
|
+
* @param data the data for the jobResult call
|
55
|
+
* @param data.jobId the jobId of the job
|
56
|
+
* @returns { success: boolean, error?: string, result?: any }
|
57
|
+
* where result is the result of the job
|
58
|
+
* if the job is not finished yet, the result will be undefined
|
59
|
+
* if the job failed, the result will be undefined and error will be set
|
60
|
+
* if the job is finished, the result will be set and error will be undefined
|
61
|
+
* if the job is not found, the result will be undefined and error will be set
|
62
|
+
*/
|
63
|
+
async jobResult(data) {
|
64
|
+
const result = await this.apiHub("jobResult", data);
|
65
|
+
if (this.isError(result.data))
|
66
|
+
return {
|
67
|
+
success: false,
|
68
|
+
error: result.error,
|
69
|
+
result: result.data,
|
70
|
+
};
|
71
|
+
else
|
72
|
+
return {
|
73
|
+
success: result.success,
|
74
|
+
error: result.error,
|
75
|
+
result: result.data,
|
76
|
+
};
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* Gets the billing report for the jobs sent using JWT
|
80
|
+
* @returns { success: boolean, error?: string, result?: any }
|
81
|
+
* where result is the billing report
|
82
|
+
*/
|
83
|
+
async queryBilling() {
|
84
|
+
const result = await this.apiHub("queryBilling", {});
|
85
|
+
if (this.isError(result.data))
|
86
|
+
return {
|
87
|
+
success: false,
|
88
|
+
error: result.error,
|
89
|
+
result: result.data,
|
90
|
+
};
|
91
|
+
else
|
92
|
+
return {
|
93
|
+
success: result.success,
|
94
|
+
error: result.error,
|
95
|
+
result: result.data,
|
96
|
+
};
|
97
|
+
}
|
98
|
+
/**
|
99
|
+
* Waits for the job to finish
|
100
|
+
* @param data the data for the waitForJobResult call
|
101
|
+
* @param data.jobId the jobId of the job
|
102
|
+
* @param data.maxAttempts the maximum number of attempts, default is 360 (2 hours)
|
103
|
+
* @param data.interval the interval between attempts, default is 20000 (20 seconds)
|
104
|
+
* @param data.maxErrors the maximum number of network errors, default is 10
|
105
|
+
* @returns { success: boolean, error?: string, result?: any }
|
106
|
+
* where result is the result of the job
|
107
|
+
*/
|
108
|
+
async waitForJobResult(data) {
|
109
|
+
const maxAttempts = data?.maxAttempts ?? 360; // 2 hours
|
110
|
+
const interval = data?.interval ?? 20000;
|
111
|
+
const maxErrors = data?.maxErrors ?? 10;
|
112
|
+
const errorDelay = 30000; // 30 seconds
|
113
|
+
let attempts = 0;
|
114
|
+
let errors = 0;
|
115
|
+
while (attempts < maxAttempts) {
|
116
|
+
const result = await this.apiHub("jobResult", data);
|
117
|
+
if (result.success === false) {
|
118
|
+
errors++;
|
119
|
+
if (errors > maxErrors) {
|
120
|
+
return {
|
121
|
+
success: false,
|
122
|
+
error: "Too many network errors",
|
123
|
+
result: undefined,
|
124
|
+
};
|
125
|
+
}
|
126
|
+
await (0, mina_1.sleep)(errorDelay * errors);
|
127
|
+
}
|
128
|
+
else {
|
129
|
+
if (this.isError(result.data))
|
130
|
+
return {
|
131
|
+
success: false,
|
132
|
+
error: result.error,
|
133
|
+
result: result.data,
|
134
|
+
};
|
135
|
+
else if (result.data?.result !== undefined) {
|
136
|
+
return {
|
137
|
+
success: result.success,
|
138
|
+
error: result.error,
|
139
|
+
result: result.data,
|
140
|
+
};
|
141
|
+
}
|
142
|
+
await (0, mina_1.sleep)(interval);
|
143
|
+
}
|
144
|
+
attempts++;
|
145
|
+
}
|
146
|
+
return {
|
147
|
+
success: false,
|
148
|
+
error: "Timeout",
|
149
|
+
result: undefined,
|
150
|
+
};
|
151
|
+
}
|
152
|
+
/**
|
153
|
+
* Calls the serverless API
|
154
|
+
* @param command the command of the API
|
155
|
+
* @param data the data of the API
|
156
|
+
* */
|
157
|
+
async apiHub(command,
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
159
|
+
data
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
161
|
+
) {
|
162
|
+
const apiData = {
|
163
|
+
auth: ZKCLOUDWORKER_AUTH,
|
164
|
+
command: command,
|
165
|
+
jwtToken: this.jwt,
|
166
|
+
data: data,
|
167
|
+
};
|
168
|
+
try {
|
169
|
+
const response = await axios_1.default.post(this.endpoint, apiData);
|
170
|
+
return { success: true, data: response.data };
|
171
|
+
}
|
172
|
+
catch (error) {
|
173
|
+
console.error("catch api", error);
|
174
|
+
return { success: false, error: error };
|
175
|
+
}
|
176
|
+
}
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
178
|
+
isError(data) {
|
179
|
+
if (data === "error")
|
180
|
+
return true;
|
181
|
+
if (data?.jobStatus === "failed")
|
182
|
+
return true;
|
183
|
+
if (typeof data === "string" && data.toLowerCase().startsWith("error"))
|
184
|
+
return true;
|
185
|
+
return false;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
exports.zkCloudWorker = zkCloudWorker;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const config = {
|
4
|
+
MINAFEE: "200000000",
|
5
|
+
ZKCLOUDWORKER_AUTH: "AkRjS8yioA7i1CwvB3nOvcyLYh6sNMi4em7C0ybmYy67lhDC2KxEQtm1z45llEAR",
|
6
|
+
ZKCLOUDWORKER_API: "https://n1zjzclr99.execute-api.eu-west-1.amazonaws.com/dev/api",
|
7
|
+
};
|
8
|
+
exports.default = config;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.fee = void 0;
|
7
|
+
const o1js_1 = require("o1js");
|
8
|
+
const config_1 = __importDefault(require("./config"));
|
9
|
+
async function fee() {
|
10
|
+
//TODO: update after mainnet launch
|
11
|
+
return o1js_1.UInt64.fromJSON(config_1.default.MINAFEE);
|
12
|
+
}
|
13
|
+
exports.fee = fee;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export { zkCloudWorker } from "./api/api";
|
2
|
+
export { Cloud } from "./cloud/cloud";
|
3
|
+
export { blockchain, initBlockchain, Memory, makeString, sleep, accountBalance, accountBalanceMina, formatTime, MinaNetwork, } from "./mina";
|
4
|
+
export { fee } from "./fee";
|
5
|
+
export { MinaNetworkURL, Berkeley, Lightnet, TestWorld2 } from "./networks";
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TestWorld2 = exports.Lightnet = exports.Berkeley = exports.fee = exports.formatTime = exports.accountBalanceMina = exports.accountBalance = exports.sleep = exports.makeString = exports.Memory = exports.initBlockchain = exports.Cloud = exports.zkCloudWorker = void 0;
|
4
|
+
var api_1 = require("./api/api");
|
5
|
+
Object.defineProperty(exports, "zkCloudWorker", { enumerable: true, get: function () { return api_1.zkCloudWorker; } });
|
6
|
+
var cloud_1 = require("./cloud/cloud");
|
7
|
+
Object.defineProperty(exports, "Cloud", { enumerable: true, get: function () { return cloud_1.Cloud; } });
|
8
|
+
var mina_1 = require("./mina");
|
9
|
+
Object.defineProperty(exports, "initBlockchain", { enumerable: true, get: function () { return mina_1.initBlockchain; } });
|
10
|
+
Object.defineProperty(exports, "Memory", { enumerable: true, get: function () { return mina_1.Memory; } });
|
11
|
+
Object.defineProperty(exports, "makeString", { enumerable: true, get: function () { return mina_1.makeString; } });
|
12
|
+
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return mina_1.sleep; } });
|
13
|
+
Object.defineProperty(exports, "accountBalance", { enumerable: true, get: function () { return mina_1.accountBalance; } });
|
14
|
+
Object.defineProperty(exports, "accountBalanceMina", { enumerable: true, get: function () { return mina_1.accountBalanceMina; } });
|
15
|
+
Object.defineProperty(exports, "formatTime", { enumerable: true, get: function () { return mina_1.formatTime; } });
|
16
|
+
var fee_1 = require("./fee");
|
17
|
+
Object.defineProperty(exports, "fee", { enumerable: true, get: function () { return fee_1.fee; } });
|
18
|
+
var networks_1 = require("./networks");
|
19
|
+
Object.defineProperty(exports, "Berkeley", { enumerable: true, get: function () { return networks_1.Berkeley; } });
|
20
|
+
Object.defineProperty(exports, "Lightnet", { enumerable: true, get: function () { return networks_1.Lightnet; } });
|
21
|
+
Object.defineProperty(exports, "TestWorld2", { enumerable: true, get: function () { return networks_1.TestWorld2; } });
|
@@ -0,0 +1,22 @@
|
|
1
|
+
export { blockchain, initBlockchain, Memory, makeString, sleep, accountBalance, accountBalanceMina, formatTime, MinaNetwork, };
|
2
|
+
import { PublicKey, PrivateKey, UInt64 } from "o1js";
|
3
|
+
import { MinaNetworkURL } from "./networks";
|
4
|
+
type blockchain = "local" | "berkeley" | "lighnet" | "mainnet" | "testworld2";
|
5
|
+
interface MinaNetwork {
|
6
|
+
keys: {
|
7
|
+
publicKey: PublicKey;
|
8
|
+
privateKey: PrivateKey;
|
9
|
+
}[];
|
10
|
+
url?: MinaNetworkURL;
|
11
|
+
}
|
12
|
+
declare function initBlockchain(instance: blockchain): MinaNetwork;
|
13
|
+
declare function accountBalance(address: PublicKey): Promise<UInt64>;
|
14
|
+
declare function accountBalanceMina(address: PublicKey): Promise<number>;
|
15
|
+
declare function sleep(ms: number): Promise<unknown>;
|
16
|
+
declare function makeString(length: number): string;
|
17
|
+
declare function formatTime(ms: number): string;
|
18
|
+
declare class Memory {
|
19
|
+
static rss: number;
|
20
|
+
constructor();
|
21
|
+
static info(description?: string, fullInfo?: boolean): void;
|
22
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.formatTime = exports.accountBalanceMina = exports.accountBalance = exports.sleep = exports.makeString = exports.Memory = exports.initBlockchain = void 0;
|
4
|
+
const o1js_1 = require("o1js");
|
5
|
+
const networks_1 = require("./networks");
|
6
|
+
function initBlockchain(instance) {
|
7
|
+
if (instance === "local") {
|
8
|
+
const Local = o1js_1.Mina.LocalBlockchain({ proofsEnabled: true });
|
9
|
+
o1js_1.Mina.setActiveInstance(Local);
|
10
|
+
return { keys: Local.testAccounts };
|
11
|
+
}
|
12
|
+
else if (instance === "berkeley") {
|
13
|
+
const network = o1js_1.Mina.Network({
|
14
|
+
mina: networks_1.Berkeley.graphql,
|
15
|
+
archive: networks_1.Berkeley.archive,
|
16
|
+
});
|
17
|
+
o1js_1.Mina.setActiveInstance(network);
|
18
|
+
return { keys: [], url: networks_1.Berkeley };
|
19
|
+
}
|
20
|
+
else if (instance === "testworld2") {
|
21
|
+
const network = o1js_1.Mina.Network({
|
22
|
+
mina: networks_1.TestWorld2.graphql,
|
23
|
+
archive: networks_1.TestWorld2.archive,
|
24
|
+
});
|
25
|
+
o1js_1.Mina.setActiveInstance(network);
|
26
|
+
return { keys: [], url: networks_1.TestWorld2 };
|
27
|
+
}
|
28
|
+
else if (instance === "lighnet") {
|
29
|
+
const network = o1js_1.Mina.Network({
|
30
|
+
mina: networks_1.Lightnet.graphql,
|
31
|
+
archive: networks_1.Lightnet.archive,
|
32
|
+
lightnetAccountManager: networks_1.Lightnet.accountManager,
|
33
|
+
});
|
34
|
+
o1js_1.Mina.setActiveInstance(network);
|
35
|
+
return { keys: [], url: networks_1.Lightnet };
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
throw new Error("Mainnet is not supported yet by zkApps");
|
39
|
+
}
|
40
|
+
}
|
41
|
+
exports.initBlockchain = initBlockchain;
|
42
|
+
async function accountBalance(address) {
|
43
|
+
await (0, o1js_1.fetchAccount)({ publicKey: address });
|
44
|
+
if (o1js_1.Mina.hasAccount(address))
|
45
|
+
return o1js_1.Mina.getBalance(address);
|
46
|
+
else
|
47
|
+
return o1js_1.UInt64.from(0);
|
48
|
+
}
|
49
|
+
exports.accountBalance = accountBalance;
|
50
|
+
async function accountBalanceMina(address) {
|
51
|
+
return Number((await accountBalance(address)).toBigInt()) / 1e9;
|
52
|
+
}
|
53
|
+
exports.accountBalanceMina = accountBalanceMina;
|
54
|
+
function sleep(ms) {
|
55
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
56
|
+
}
|
57
|
+
exports.sleep = sleep;
|
58
|
+
function makeString(length) {
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
60
|
+
let outString = ``;
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
62
|
+
const inOptions = `abcdefghijklmnopqrstuvwxyz0123456789`;
|
63
|
+
for (let i = 0; i < length; i++) {
|
64
|
+
outString += inOptions.charAt(Math.floor(Math.random() * inOptions.length));
|
65
|
+
}
|
66
|
+
return outString;
|
67
|
+
}
|
68
|
+
exports.makeString = makeString;
|
69
|
+
function formatTime(ms) {
|
70
|
+
if (ms === undefined)
|
71
|
+
return "";
|
72
|
+
if (ms < 1000)
|
73
|
+
return ms.toString() + " ms";
|
74
|
+
if (ms < 60 * 1000)
|
75
|
+
return parseInt((ms / 1000).toString()).toString() + " sec";
|
76
|
+
if (ms < 60 * 60 * 1000)
|
77
|
+
return parseInt((ms / 1000 / 60).toString()).toString() + " min";
|
78
|
+
return parseInt((ms / 1000 / 60 / 60).toString()).toString() + " h";
|
79
|
+
}
|
80
|
+
exports.formatTime = formatTime;
|
81
|
+
class Memory {
|
82
|
+
constructor() {
|
83
|
+
Memory.rss = 0;
|
84
|
+
}
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
86
|
+
static info(description = ``, fullInfo = false) {
|
87
|
+
const memoryData = process.memoryUsage();
|
88
|
+
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024)} MB`;
|
89
|
+
const oldRSS = Memory.rss;
|
90
|
+
Memory.rss = Math.round(memoryData.rss / 1024 / 1024);
|
91
|
+
const memoryUsage = fullInfo
|
92
|
+
? {
|
93
|
+
step: `${description}:`,
|
94
|
+
rssDelta: `${(oldRSS === 0
|
95
|
+
? 0
|
96
|
+
: Memory.rss - oldRSS).toString()} MB -> Resident Set Size memory change`,
|
97
|
+
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated`,
|
98
|
+
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
|
99
|
+
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
|
100
|
+
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
|
101
|
+
}
|
102
|
+
: `RSS memory ${description}: ${formatMemoryUsage(memoryData.rss)}${oldRSS === 0
|
103
|
+
? ``
|
104
|
+
: `, changed by ` + (Memory.rss - oldRSS).toString() + ` MB`}`;
|
105
|
+
console.log(memoryUsage);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
exports.Memory = Memory;
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
110
|
+
Memory.rss = 0;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
export { MinaNetworkURL, Berkeley, Lightnet, TestWorld2 };
|
2
|
+
interface MinaNetworkURL {
|
3
|
+
graphql: string;
|
4
|
+
archive: string;
|
5
|
+
chainId?: string;
|
6
|
+
name?: string;
|
7
|
+
accountManager?: string;
|
8
|
+
explorerAccountUrl?: string;
|
9
|
+
explorerTransactionUrl?: string;
|
10
|
+
}
|
11
|
+
declare const Berkeley: MinaNetworkURL;
|
12
|
+
declare const TestWorld2: MinaNetworkURL;
|
13
|
+
declare const Lightnet: MinaNetworkURL;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TestWorld2 = exports.Lightnet = exports.Berkeley = void 0;
|
4
|
+
const Berkeley = {
|
5
|
+
graphql: "https://api.minascan.io/node/berkeley/v1/graphql",
|
6
|
+
archive: "https://api.minascan.io/archive/berkeley/v1/graphql", // "https://api.minascan.io/archive/berkeley/v1/graphql"
|
7
|
+
explorerAccountUrl: "https://minascan.io/berkeley/account/",
|
8
|
+
explorerTransactionUrl: "https://minascan.io/berkeley/tx/",
|
9
|
+
chainId: 'berkeley',
|
10
|
+
name: 'Berkeley'
|
11
|
+
};
|
12
|
+
exports.Berkeley = Berkeley;
|
13
|
+
const TestWorld2 = {
|
14
|
+
graphql: "https://api.minascan.io/node/testworld/v1/graphql",
|
15
|
+
archive: "https://archive.testworld.minaexplorer.com",
|
16
|
+
explorerAccountUrl: "https://minascan.io/testworld/account/",
|
17
|
+
explorerTransactionUrl: "https://minascan.io/testworld/tx/",
|
18
|
+
chainId: 'testworld2',
|
19
|
+
name: 'TestWorld2'
|
20
|
+
};
|
21
|
+
exports.TestWorld2 = TestWorld2;
|
22
|
+
const Lightnet = {
|
23
|
+
graphql: "http://localhost:8080/graphql",
|
24
|
+
archive: "http://localhost:8282 ",
|
25
|
+
accountManager: "http://localhost:8181",
|
26
|
+
};
|
27
|
+
exports.Lightnet = Lightnet;
|