@dignetwork/dig-sdk 0.0.1-alpha.54 → 0.0.1-alpha.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,7 +13,7 @@ const ssl_1 = require("../utils/ssl");
|
|
|
13
13
|
const credentialsUtils_1 = require("../utils/credentialsUtils");
|
|
14
14
|
const https_1 = __importDefault(require("https"));
|
|
15
15
|
const cli_progress_1 = __importDefault(require("cli-progress"));
|
|
16
|
-
const
|
|
16
|
+
const colorette_1 = require("colorette"); // For colored output
|
|
17
17
|
const ora_1 = __importDefault(require("ora")); // For spinners
|
|
18
18
|
const config_1 = require("../utils/config");
|
|
19
19
|
const hashUtils_1 = require("../utils/hashUtils");
|
|
@@ -66,24 +66,24 @@ class PropagationServer {
|
|
|
66
66
|
const storeExists = response.headers["x-store-exists"] === "true";
|
|
67
67
|
const rootHashExists = response.headers["x-has-root-hash"] === "true";
|
|
68
68
|
if (storeExists) {
|
|
69
|
-
spinner.succeed(
|
|
69
|
+
spinner.succeed((0, colorette_1.green)(`Store ${this.storeId} exists!`));
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
spinner.fail(
|
|
72
|
+
spinner.fail((0, colorette_1.red)(`Store ${this.storeId} does not exist.`));
|
|
73
73
|
}
|
|
74
74
|
if (rootHash) {
|
|
75
75
|
if (rootHashExists) {
|
|
76
|
-
console.log(
|
|
76
|
+
console.log((0, colorette_1.green)(`Root hash ${rootHash} exists in the store.`));
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
79
|
-
console.log(
|
|
79
|
+
console.log((0, colorette_1.red)(`Root hash ${rootHash} does not exist in the store.`));
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
return { storeExists, rootHashExists };
|
|
83
83
|
}
|
|
84
84
|
catch (error) {
|
|
85
|
-
spinner.fail(
|
|
86
|
-
console.error(
|
|
85
|
+
spinner.fail((0, colorette_1.red)("Error checking if store exists:"));
|
|
86
|
+
console.error((0, colorette_1.red)(error));
|
|
87
87
|
throw error;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -106,11 +106,11 @@ class PropagationServer {
|
|
|
106
106
|
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}`;
|
|
107
107
|
const response = await axios_1.default.post(url, { publicKey: this.publicKey }, config);
|
|
108
108
|
this.sessionId = response.data.sessionId;
|
|
109
|
-
spinner.succeed(
|
|
109
|
+
spinner.succeed((0, colorette_1.green)(`Upload session started for DataStore ${this.storeId} with session ID ${this.sessionId}`));
|
|
110
110
|
}
|
|
111
111
|
catch (error) {
|
|
112
|
-
spinner.fail(
|
|
113
|
-
console.error(
|
|
112
|
+
spinner.fail((0, colorette_1.red)("Error starting upload session:"));
|
|
113
|
+
console.error((0, colorette_1.red)(error));
|
|
114
114
|
throw error;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -125,11 +125,11 @@ class PropagationServer {
|
|
|
125
125
|
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
|
|
126
126
|
const response = await axios_1.default.head(url, config);
|
|
127
127
|
const nonce = response.headers["x-nonce"];
|
|
128
|
-
console.log(
|
|
128
|
+
console.log((0, colorette_1.blue)(`Nonce received for file ${filename}: ${nonce}`));
|
|
129
129
|
return nonce;
|
|
130
130
|
}
|
|
131
131
|
catch (error) {
|
|
132
|
-
console.error(
|
|
132
|
+
console.error((0, colorette_1.red)(`Error generating nonce for file ${filename}:`), error);
|
|
133
133
|
throw error;
|
|
134
134
|
}
|
|
135
135
|
}
|
|
@@ -146,7 +146,7 @@ class PropagationServer {
|
|
|
146
146
|
const fileSize = fs_1.default.statSync(filePath).size;
|
|
147
147
|
// Create a new progress bar for each file
|
|
148
148
|
const progressBar = PropagationServer.multiBar.create(fileSize, 0, {
|
|
149
|
-
filename:
|
|
149
|
+
filename: (0, colorette_1.yellow)(filename),
|
|
150
150
|
percentage: 0,
|
|
151
151
|
});
|
|
152
152
|
let uploadedBytes = 0;
|
|
@@ -169,14 +169,14 @@ class PropagationServer {
|
|
|
169
169
|
try {
|
|
170
170
|
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
|
|
171
171
|
const response = await axios_1.default.put(url, formData, config);
|
|
172
|
-
console.log(
|
|
172
|
+
console.log((0, colorette_1.green)(`✔ File ${filename} uploaded successfully.`));
|
|
173
173
|
// Complete the progress bar
|
|
174
174
|
progressBar.update(fileSize, { percentage: 100 });
|
|
175
175
|
progressBar.stop();
|
|
176
176
|
return response.data;
|
|
177
177
|
}
|
|
178
178
|
catch (error) {
|
|
179
|
-
console.error(
|
|
179
|
+
console.error((0, colorette_1.red)(`✖ Error uploading file ${filename}:`), error);
|
|
180
180
|
progressBar.stop(); // Stop the progress bar in case of error
|
|
181
181
|
throw error;
|
|
182
182
|
}
|
|
@@ -196,7 +196,7 @@ class PropagationServer {
|
|
|
196
196
|
const storeExists = await propagationServer.checkStoreExists();
|
|
197
197
|
// If the store does not exist, prompt for credentials
|
|
198
198
|
if (!storeExists) {
|
|
199
|
-
console.log(
|
|
199
|
+
console.log((0, colorette_1.red)(`Store ${storeId} does not exist. Prompting for credentials...`));
|
|
200
200
|
const credentials = await (0, credentialsUtils_1.promptCredentials)(propagationServer.ipAddress);
|
|
201
201
|
propagationServer.username = credentials.username;
|
|
202
202
|
propagationServer.password = credentials.password;
|
|
@@ -211,7 +211,7 @@ class PropagationServer {
|
|
|
211
211
|
}
|
|
212
212
|
// Stop all progress bars after the files are uploaded
|
|
213
213
|
PropagationServer.multiBar.stop();
|
|
214
|
-
console.log(
|
|
214
|
+
console.log((0, colorette_1.green)(`✔ All files have been uploaded to DataStore ${storeId}.`));
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
217
|
* Fetch a file from the server by sending a GET request and return its content in memory.
|
|
@@ -228,10 +228,10 @@ class PropagationServer {
|
|
|
228
228
|
try {
|
|
229
229
|
const response = await axios_1.default.get(url, config);
|
|
230
230
|
const totalLength = parseInt(response.headers["content-length"], 10);
|
|
231
|
-
console.log(
|
|
231
|
+
console.log((0, colorette_1.cyan)(`Starting fetch for ${dataPath}...`));
|
|
232
232
|
// Create a progress bar for the download
|
|
233
233
|
const progressBar = PropagationServer.multiBar.create(totalLength, 0, {
|
|
234
|
-
dataPath:
|
|
234
|
+
dataPath: (0, colorette_1.yellow)(dataPath),
|
|
235
235
|
percentage: 0,
|
|
236
236
|
});
|
|
237
237
|
let downloadedBytes = 0;
|
|
@@ -245,12 +245,12 @@ class PropagationServer {
|
|
|
245
245
|
// Complete the progress bar once done
|
|
246
246
|
progressBar.update(totalLength, { percentage: 100 });
|
|
247
247
|
progressBar.stop();
|
|
248
|
-
console.log(
|
|
248
|
+
console.log((0, colorette_1.green)(`✔ File ${dataPath} fetched successfully.`));
|
|
249
249
|
// Return the file contents as a Buffer
|
|
250
250
|
return Buffer.from(response.data);
|
|
251
251
|
}
|
|
252
252
|
catch (error) {
|
|
253
|
-
console.error(
|
|
253
|
+
console.error((0, colorette_1.red)(`✖ Error fetching file ${dataPath}:`), error);
|
|
254
254
|
throw error;
|
|
255
255
|
}
|
|
256
256
|
}
|
|
@@ -272,10 +272,10 @@ class PropagationServer {
|
|
|
272
272
|
try {
|
|
273
273
|
const response = await axios_1.default.get(url, config);
|
|
274
274
|
const totalLength = parseInt(response.headers["content-length"], 10);
|
|
275
|
-
console.log(
|
|
275
|
+
console.log((0, colorette_1.cyan)(`Starting download for ${dataPath}...`));
|
|
276
276
|
// Create a progress bar for the download
|
|
277
277
|
const progressBar = PropagationServer.multiBar.create(totalLength, 0, {
|
|
278
|
-
dataPath:
|
|
278
|
+
dataPath: (0, colorette_1.yellow)(dataPath),
|
|
279
279
|
percentage: 0,
|
|
280
280
|
});
|
|
281
281
|
let downloadedBytes = 0;
|
|
@@ -292,18 +292,18 @@ class PropagationServer {
|
|
|
292
292
|
fileWriteStream.on("finish", () => {
|
|
293
293
|
progressBar.update(totalLength, { percentage: 100 });
|
|
294
294
|
progressBar.stop();
|
|
295
|
-
console.log(
|
|
295
|
+
console.log((0, colorette_1.green)(`✔ File ${dataPath} downloaded successfully to ${downloadPath}.`));
|
|
296
296
|
resolve();
|
|
297
297
|
});
|
|
298
298
|
fileWriteStream.on("error", (error) => {
|
|
299
299
|
progressBar.stop();
|
|
300
|
-
console.error(
|
|
300
|
+
console.error((0, colorette_1.red)(`✖ Error downloading file ${dataPath}:`), error);
|
|
301
301
|
reject(error);
|
|
302
302
|
});
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
305
|
catch (error) {
|
|
306
|
-
console.error(
|
|
306
|
+
console.error((0, colorette_1.red)(`✖ Error downloading file ${dataPath}:`), error);
|
|
307
307
|
throw error;
|
|
308
308
|
}
|
|
309
309
|
}
|
|
@@ -329,7 +329,7 @@ class PropagationServer {
|
|
|
329
329
|
const dataPath = (0, hashUtils_1.getFilePathFromSha256)(root.files[fileKey].sha256, "data");
|
|
330
330
|
await propagationServer.downloadFile(dataPath);
|
|
331
331
|
}
|
|
332
|
-
console.log(
|
|
332
|
+
console.log((0, colorette_1.green)(`✔ All files have been downloaded to ${storeId}.`));
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
exports.PropagationServer = PropagationServer;
|
|
@@ -338,8 +338,8 @@ PropagationServer.port = 4159; // Static port used for all requests
|
|
|
338
338
|
PropagationServer.multiBar = new cli_progress_1.default.MultiBar({
|
|
339
339
|
clearOnComplete: false,
|
|
340
340
|
hideCursor: true,
|
|
341
|
-
format:
|
|
342
|
-
|
|
341
|
+
format: (0, colorette_1.green)(" {bar} ") +
|
|
342
|
+
(0, colorette_1.cyan)(" | {filename} | {percentage}% | {value}/{total} bytes"),
|
|
343
343
|
barsize: 40,
|
|
344
344
|
stopOnComplete: true,
|
|
345
345
|
align: "center",
|
|
@@ -12,7 +12,7 @@ const FullNodePeer_1 = require("./FullNodePeer");
|
|
|
12
12
|
const Wallet_1 = require("./Wallet");
|
|
13
13
|
const config_1 = require("../utils/config");
|
|
14
14
|
const coins_1 = require("./coins");
|
|
15
|
-
const
|
|
15
|
+
const colorette_1 = require("colorette");
|
|
16
16
|
const hashUtils_1 = require("../utils/hashUtils");
|
|
17
17
|
const DataIntegrityTree_1 = require("../DataIntegrityTree");
|
|
18
18
|
const prompts_1 = require("../prompts");
|
|
@@ -350,12 +350,12 @@ class DataStore {
|
|
|
350
350
|
// Perform the integrity check before adding to the file set
|
|
351
351
|
const integrityCheck = await DataIntegrityTree_1.DataIntegrityTree.validateKeyIntegrityWithForeignTree(fileKey, datFileContent.files[fileKey].sha256, datFileContent, rootHash, path_1.default.join(config_1.STORE_PATH, this.storeId, "data"));
|
|
352
352
|
if (integrityCheck) {
|
|
353
|
-
console.log(
|
|
353
|
+
console.log((0, colorette_1.green)(`File ${fileKey} has passed the integrity check.`));
|
|
354
354
|
// Add the file to the file set only if the integrity check passes
|
|
355
355
|
filesInvolved.push(filePath);
|
|
356
356
|
}
|
|
357
357
|
else {
|
|
358
|
-
console.error(
|
|
358
|
+
console.error((0, colorette_1.red)(`File ${fileKey} failed the integrity check.`));
|
|
359
359
|
throw new Error(`Integrity check failed for file: ${fileKey}. Aborting.`);
|
|
360
360
|
}
|
|
361
361
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dignetwork/dig-sdk",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.55",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"archiver": "^7.0.1",
|
|
30
30
|
"axios": "^1.7.7",
|
|
31
31
|
"bip39": "^3.1.0",
|
|
32
|
-
"chalk": "^5.3.0",
|
|
33
32
|
"chia-bls": "^1.0.2",
|
|
34
33
|
"chia-config-loader": "^1.0.1",
|
|
35
34
|
"chia-root-resolver": "^1.0.0",
|
|
36
35
|
"chia-server-coin": "^0.0.5",
|
|
37
36
|
"chia-wallet": "^1.0.18",
|
|
38
37
|
"cli-progress": "^3.12.0",
|
|
38
|
+
"colorette": "^2.0.20",
|
|
39
39
|
"crypto-js": "^4.2.0",
|
|
40
40
|
"figures": "^6.1.0",
|
|
41
41
|
"fs-extra": "^11.2.0",
|