@dignetwork/dig-sdk 0.0.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +160 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.js +648 -0
- package/dist/DataIntegrityTree/DataLayerError.d.ts +6 -0
- package/dist/DataIntegrityTree/DataLayerError.d.ts.map +1 -0
- package/dist/DataIntegrityTree/DataLayerError.js +17 -0
- package/dist/DataIntegrityTree/index.d.ts +2 -0
- package/dist/DataIntegrityTree/index.d.ts.map +1 -0
- package/dist/DataIntegrityTree/index.js +17 -0
- package/dist/DigNetwork/ContentServer.d.ts +28 -0
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -0
- package/dist/DigNetwork/ContentServer.js +243 -0
- package/dist/DigNetwork/DigChallenge.d.ts +82 -0
- package/dist/DigNetwork/DigChallenge.d.ts.map +1 -0
- package/dist/DigNetwork/DigChallenge.js +144 -0
- package/dist/DigNetwork/DigNetwork.d.ts +19 -0
- package/dist/DigNetwork/DigNetwork.d.ts.map +1 -0
- package/dist/DigNetwork/DigNetwork.js +222 -0
- package/dist/DigNetwork/DigPeer.d.ts +19 -0
- package/dist/DigNetwork/DigPeer.d.ts.map +1 -0
- package/dist/DigNetwork/DigPeer.js +164 -0
- package/dist/DigNetwork/IncentiveServer.d.ts +13 -0
- package/dist/DigNetwork/IncentiveServer.d.ts.map +1 -0
- package/dist/DigNetwork/IncentiveServer.js +76 -0
- package/dist/DigNetwork/PropagationServer.d.ts +41 -0
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -0
- package/dist/DigNetwork/PropagationServer.js +415 -0
- package/dist/DigNetwork/index.d.ts +4 -0
- package/dist/DigNetwork/index.d.ts.map +1 -0
- package/dist/DigNetwork/index.js +19 -0
- package/dist/blockchain/DataStore.d.ts +54 -0
- package/dist/blockchain/DataStore.d.ts.map +1 -0
- package/dist/blockchain/DataStore.js +410 -0
- package/dist/blockchain/DataStoreSerializer.d.ts +52 -0
- package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -0
- package/dist/blockchain/DataStoreSerializer.js +109 -0
- package/dist/blockchain/FullNodePeer.d.ts +17 -0
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -0
- package/dist/blockchain/FullNodePeer.js +215 -0
- package/dist/blockchain/ServerCoin.d.ts +21 -0
- package/dist/blockchain/ServerCoin.d.ts.map +1 -0
- package/dist/blockchain/ServerCoin.js +261 -0
- package/dist/blockchain/Wallet.d.ts +28 -0
- package/dist/blockchain/Wallet.d.ts.map +1 -0
- package/dist/blockchain/Wallet.js +220 -0
- package/dist/blockchain/coins.d.ts +6 -0
- package/dist/blockchain/coins.d.ts.map +1 -0
- package/dist/blockchain/coins.js +101 -0
- package/dist/blockchain/index.d.ts +8 -0
- package/dist/blockchain/index.d.ts.map +1 -0
- package/dist/blockchain/index.js +36 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/prompts.d.ts +21 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +149 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/utils/FileCache.d.ts +11 -0
- package/dist/utils/FileCache.d.ts.map +1 -0
- package/dist/utils/FileCache.js +58 -0
- package/dist/utils/NconfManager.d.ts +11 -0
- package/dist/utils/NconfManager.d.ts.map +1 -0
- package/dist/utils/NconfManager.js +55 -0
- package/dist/utils/config.d.ts +67 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +223 -0
- package/dist/utils/connectionUtils.d.ts +10 -0
- package/dist/utils/connectionUtils.d.ts.map +1 -0
- package/dist/utils/connectionUtils.js +18 -0
- package/dist/utils/credentialsUtils.d.ts +8 -0
- package/dist/utils/credentialsUtils.d.ts.map +1 -0
- package/dist/utils/credentialsUtils.js +122 -0
- package/dist/utils/deltaUtils.d.ts +2 -0
- package/dist/utils/deltaUtils.d.ts.map +1 -0
- package/dist/utils/deltaUtils.js +83 -0
- package/dist/utils/directoryUtils.d.ts +15 -0
- package/dist/utils/directoryUtils.d.ts.map +1 -0
- package/dist/utils/directoryUtils.js +91 -0
- package/dist/utils/encryption.d.ts +8 -0
- package/dist/utils/encryption.d.ts.map +1 -0
- package/dist/utils/encryption.js +55 -0
- package/dist/utils/hashUtils.d.ts +8 -0
- package/dist/utils/hashUtils.d.ts.map +1 -0
- package/dist/utils/hashUtils.js +44 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +29 -0
- package/dist/utils/network.d.ts +2 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +38 -0
- package/dist/utils/spinnerUtils.d.ts +2 -0
- package/dist/utils/spinnerUtils.d.ts.map +1 -0
- package/dist/utils/spinnerUtils.js +47 -0
- package/dist/utils/ssl.d.ts +5 -0
- package/dist/utils/ssl.d.ts.map +1 -0
- package/dist/utils/ssl.js +50 -0
- package/dist/utils/validationUtils.d.ts +9 -0
- package/dist/utils/validationUtils.d.ts.map +1 -0
- package/dist/utils/validationUtils.js +55 -0
- package/package.json +64 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getDeltaFiles = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const hashUtils_1 = require("./hashUtils");
|
|
30
|
+
const getDeltaFiles = async (storeId, generationIndex = 0, directoryPath) => {
|
|
31
|
+
if (isNaN(generationIndex)) {
|
|
32
|
+
generationIndex = 0;
|
|
33
|
+
}
|
|
34
|
+
// Load manifest file
|
|
35
|
+
const manifestFilePath = path.join(directoryPath, storeId, "manifest.dat");
|
|
36
|
+
if (!fs.existsSync(manifestFilePath)) {
|
|
37
|
+
console.error("Manifest file not found", manifestFilePath);
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
const manifestHashes = fs
|
|
41
|
+
.readFileSync(manifestFilePath, "utf-8")
|
|
42
|
+
.split("\n")
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
console.log("");
|
|
45
|
+
console.log(`Uploading delta from generation ${generationIndex}`);
|
|
46
|
+
const filesInvolved = [];
|
|
47
|
+
// Include the height.dat file at the top of the directory
|
|
48
|
+
const heightDatFilePath = path.join(directoryPath, storeId, "height.json");
|
|
49
|
+
if (fs.existsSync(heightDatFilePath)) {
|
|
50
|
+
filesInvolved.push(heightDatFilePath);
|
|
51
|
+
}
|
|
52
|
+
// Collect files starting from generationIndex + 1
|
|
53
|
+
for (let i = generationIndex; i < manifestHashes.length; i++) {
|
|
54
|
+
const rootHash = manifestHashes[i];
|
|
55
|
+
const datFilePath = path.join(directoryPath, storeId, `${rootHash}.dat`);
|
|
56
|
+
if (!fs.existsSync(datFilePath)) {
|
|
57
|
+
console.error(`Data file for root hash ${rootHash} not found`);
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const datFileContent = JSON.parse(fs.readFileSync(datFilePath, "utf-8"));
|
|
61
|
+
if (datFileContent.root !== rootHash) {
|
|
62
|
+
console.error(`Root hash in data file does not match: ${datFileContent.root} !== ${rootHash}`);
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
// Add the .dat file itself to the list of files involved
|
|
66
|
+
filesInvolved.push(datFilePath);
|
|
67
|
+
// Collect all files involved, ensuring correct paths
|
|
68
|
+
for (const file of Object.keys(datFileContent.files)) {
|
|
69
|
+
const filePath = (0, hashUtils_1.getFilePathFromSha256)(datFileContent.files[file].sha256, path.join(directoryPath, storeId, "data"));
|
|
70
|
+
filesInvolved.push(filePath);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (process.env.DIG_DEBUG === "1") {
|
|
74
|
+
console.log("Files involved in the delta:");
|
|
75
|
+
console.table(filesInvolved);
|
|
76
|
+
}
|
|
77
|
+
// list the manifest file last, this actually
|
|
78
|
+
// helps with upload because by overriding the manifest file last,
|
|
79
|
+
// the store can still be considered valid even when the upload is interrupted
|
|
80
|
+
filesInvolved.push(manifestFilePath);
|
|
81
|
+
return filesInvolved;
|
|
82
|
+
};
|
|
83
|
+
exports.getDeltaFiles = getDeltaFiles;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DataIntegrityTree } from "../DataIntegrityTree";
|
|
2
|
+
/**
|
|
3
|
+
* Recursively add all files in a directory to the Merkle tree, skipping the .dig, .git folders, and files in .gitignore.
|
|
4
|
+
* @param datalayer - The DataStoreManager instance.
|
|
5
|
+
* @param dirPath - The directory path.
|
|
6
|
+
* @param baseDir - The base directory for relative paths.
|
|
7
|
+
*/
|
|
8
|
+
export declare const addDirectory: (datalayer: DataIntegrityTree, dirPath: string, baseDir?: string) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Calculate the total size of the DIG_FOLDER_PATH
|
|
11
|
+
* @param folderPath - The path of the folder to calculate size.
|
|
12
|
+
* @returns The total size of the folder in bytes.
|
|
13
|
+
*/
|
|
14
|
+
export declare const calculateFolderSize: (folderPath: string) => bigint;
|
|
15
|
+
//# sourceMappingURL=directoryUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,cACZ,iBAAiB,WACnB,MAAM,YACN,MAAM,KACd,OAAO,CAAC,IAAI,CAmCd,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAiBxD,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.calculateFolderSize = exports.addDirectory = void 0;
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const ignore_1 = __importDefault(require("ignore"));
|
|
33
|
+
/**
|
|
34
|
+
* Recursively add all files in a directory to the Merkle tree, skipping the .dig, .git folders, and files in .gitignore.
|
|
35
|
+
* @param datalayer - The DataStoreManager instance.
|
|
36
|
+
* @param dirPath - The directory path.
|
|
37
|
+
* @param baseDir - The base directory for relative paths.
|
|
38
|
+
*/
|
|
39
|
+
const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
40
|
+
const ig = (0, ignore_1.default)();
|
|
41
|
+
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
42
|
+
// Load .gitignore rules if the file exists
|
|
43
|
+
if (fs.existsSync(gitignorePath)) {
|
|
44
|
+
const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8");
|
|
45
|
+
ig.add(gitignoreContent);
|
|
46
|
+
}
|
|
47
|
+
const files = fs.readdirSync(dirPath);
|
|
48
|
+
for (const file of files) {
|
|
49
|
+
const filePath = path.join(dirPath, file);
|
|
50
|
+
const relativePath = path.relative(baseDir, filePath).replace(/\\/g, "/");
|
|
51
|
+
// Skip the .dig, .git folders and files or directories ignored by .gitignore
|
|
52
|
+
if (file === ".dig" || file === ".git" || ig.ignores(relativePath)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const stat = fs.statSync(filePath);
|
|
56
|
+
if (stat.isDirectory()) {
|
|
57
|
+
await (0, exports.addDirectory)(datalayer, filePath, baseDir);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await new Promise((resolve, reject) => {
|
|
61
|
+
const stream = fs.createReadStream(filePath);
|
|
62
|
+
datalayer
|
|
63
|
+
.upsertKey(stream, Buffer.from(relativePath).toString("hex"))
|
|
64
|
+
.then(resolve)
|
|
65
|
+
.catch(reject);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.addDirectory = addDirectory;
|
|
71
|
+
/**
|
|
72
|
+
* Calculate the total size of the DIG_FOLDER_PATH
|
|
73
|
+
* @param folderPath - The path of the folder to calculate size.
|
|
74
|
+
* @returns The total size of the folder in bytes.
|
|
75
|
+
*/
|
|
76
|
+
const calculateFolderSize = (folderPath) => {
|
|
77
|
+
let totalSize = BigInt(0);
|
|
78
|
+
const files = fs.readdirSync(folderPath);
|
|
79
|
+
for (const file of files) {
|
|
80
|
+
const filePath = path.join(folderPath, file);
|
|
81
|
+
const stat = fs.statSync(filePath);
|
|
82
|
+
if (stat.isDirectory()) {
|
|
83
|
+
totalSize += (0, exports.calculateFolderSize)(filePath);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
totalSize += BigInt(stat.size);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return totalSize;
|
|
90
|
+
};
|
|
91
|
+
exports.calculateFolderSize = calculateFolderSize;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface EncryptedData {
|
|
2
|
+
data: string;
|
|
3
|
+
nonce: string;
|
|
4
|
+
salt: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const encryptData: (data: string) => EncryptedData;
|
|
7
|
+
export declare const decryptData: (encryptedData: EncryptedData) => string;
|
|
8
|
+
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../src/utils/encryption.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAMD,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,aAW1C,CAAC;AAEF,eAAO,MAAM,WAAW,kBAAmB,aAAa,KAAG,MAY1D,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.decryptData = exports.encryptData = void 0;
|
|
27
|
+
// encryption.ts
|
|
28
|
+
const crypto = __importStar(require("crypto"));
|
|
29
|
+
const ALGORITHM = "aes-256-gcm";
|
|
30
|
+
const generateKey = (salt) => {
|
|
31
|
+
return crypto.pbkdf2Sync("mnemonic-seed", salt, 100000, 32, "sha512");
|
|
32
|
+
};
|
|
33
|
+
const encryptData = (data) => {
|
|
34
|
+
const nonce = crypto.randomBytes(12).toString("hex");
|
|
35
|
+
const salt = crypto.randomBytes(16).toString("hex");
|
|
36
|
+
const key = generateKey(salt);
|
|
37
|
+
const cipher = crypto.createCipheriv(ALGORITHM, key, Buffer.from(nonce, "hex"));
|
|
38
|
+
let encrypted = cipher.update(data, "utf8", "hex");
|
|
39
|
+
encrypted += cipher.final("hex");
|
|
40
|
+
const tag = cipher.getAuthTag().toString("hex");
|
|
41
|
+
return { data: encrypted + tag, nonce, salt };
|
|
42
|
+
};
|
|
43
|
+
exports.encryptData = encryptData;
|
|
44
|
+
const decryptData = (encryptedData) => {
|
|
45
|
+
const { data, nonce, salt } = encryptedData;
|
|
46
|
+
const encryptedText = data.slice(0, -32);
|
|
47
|
+
const tag = Buffer.from(data.slice(-32), "hex");
|
|
48
|
+
const key = generateKey(salt);
|
|
49
|
+
const decipher = crypto.createDecipheriv(ALGORITHM, key, Buffer.from(nonce, "hex"));
|
|
50
|
+
decipher.setAuthTag(tag);
|
|
51
|
+
let decrypted = decipher.update(encryptedText, "hex", "utf8");
|
|
52
|
+
decrypted += decipher.final("utf8");
|
|
53
|
+
return decrypted;
|
|
54
|
+
};
|
|
55
|
+
exports.decryptData = decryptData;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the SHA-256 hash of a buffer using the crypto module.
|
|
3
|
+
* @param buffer - The buffer.
|
|
4
|
+
* @returns The SHA-256 hash of the buffer.
|
|
5
|
+
*/
|
|
6
|
+
export declare const calculateSHA256: (buffer: Buffer) => string;
|
|
7
|
+
export declare const getFilePathFromSha256: (sha256: string, dataDir: string) => string;
|
|
8
|
+
//# sourceMappingURL=hashUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashUtils.d.ts","sourceRoot":"","sources":["../../src/utils/hashUtils.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,eAAe,WAAY,MAAM,KAAG,MAIhD,CAAC;AAGF,eAAO,MAAM,qBAAqB,WACxB,MAAM,WACL,MAAM,KACd,MAEF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getFilePathFromSha256 = exports.calculateSHA256 = void 0;
|
|
27
|
+
const crypto = __importStar(require("crypto"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
/**
|
|
30
|
+
* Calculate the SHA-256 hash of a buffer using the crypto module.
|
|
31
|
+
* @param buffer - The buffer.
|
|
32
|
+
* @returns The SHA-256 hash of the buffer.
|
|
33
|
+
*/
|
|
34
|
+
const calculateSHA256 = (buffer) => {
|
|
35
|
+
const hash = crypto.createHash("sha256");
|
|
36
|
+
hash.update(buffer);
|
|
37
|
+
return hash.digest("hex");
|
|
38
|
+
};
|
|
39
|
+
exports.calculateSHA256 = calculateSHA256;
|
|
40
|
+
// Helper function to derive file path from SHA256 hash
|
|
41
|
+
const getFilePathFromSha256 = (sha256, dataDir) => {
|
|
42
|
+
return path.join(dataDir, sha256.match(/.{1,2}/g).join("/"));
|
|
43
|
+
};
|
|
44
|
+
exports.getFilePathFromSha256 = getFilePathFromSha256;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './config';
|
|
2
|
+
export * from './connectionUtils';
|
|
3
|
+
export * from './credentialsUtils';
|
|
4
|
+
export * from './deltaUtils';
|
|
5
|
+
export * from './directoryUtils';
|
|
6
|
+
export * from './encryption';
|
|
7
|
+
export * from './FileCache';
|
|
8
|
+
export * from './hashUtils';
|
|
9
|
+
export * from './NconfManager';
|
|
10
|
+
export * from './network';
|
|
11
|
+
export * from './spinnerUtils';
|
|
12
|
+
export * from './ssl';
|
|
13
|
+
export * from './validationUtils';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,OAAO,CAAC;AACtB,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./config"), exports);
|
|
18
|
+
__exportStar(require("./connectionUtils"), exports);
|
|
19
|
+
__exportStar(require("./credentialsUtils"), exports);
|
|
20
|
+
__exportStar(require("./deltaUtils"), exports);
|
|
21
|
+
__exportStar(require("./directoryUtils"), exports);
|
|
22
|
+
__exportStar(require("./encryption"), exports);
|
|
23
|
+
__exportStar(require("./FileCache"), exports);
|
|
24
|
+
__exportStar(require("./hashUtils"), exports);
|
|
25
|
+
__exportStar(require("./NconfManager"), exports);
|
|
26
|
+
__exportStar(require("./network"), exports);
|
|
27
|
+
__exportStar(require("./spinnerUtils"), exports);
|
|
28
|
+
__exportStar(require("./ssl"), exports);
|
|
29
|
+
__exportStar(require("./validationUtils"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA8BrE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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.getPublicIpAddress = void 0;
|
|
7
|
+
const superagent_1 = __importDefault(require("superagent"));
|
|
8
|
+
const MAX_RETRIES = 5;
|
|
9
|
+
const RETRY_DELAY = 2000; // in milliseconds
|
|
10
|
+
const getPublicIpAddress = async () => {
|
|
11
|
+
const publicIp = process.env.PUBLIC_IP;
|
|
12
|
+
if (publicIp) {
|
|
13
|
+
console.log('Public IP address from env:', publicIp);
|
|
14
|
+
return publicIp;
|
|
15
|
+
}
|
|
16
|
+
let attempt = 0;
|
|
17
|
+
while (attempt < MAX_RETRIES) {
|
|
18
|
+
try {
|
|
19
|
+
const response = await superagent_1.default.get('https://api.datalayer.storage/user/v1/get_user_ip');
|
|
20
|
+
if (response.body && response.body.success) {
|
|
21
|
+
console.log('Public IP address:', response.body);
|
|
22
|
+
return response.body.ip_address;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw new Error('Failed to retrieve public IP address');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
attempt++;
|
|
30
|
+
console.error(`Error fetching public IP address (Attempt ${attempt}):`, error.message);
|
|
31
|
+
if (attempt >= MAX_RETRIES) {
|
|
32
|
+
throw new Error('Could not retrieve public IP address after several attempts');
|
|
33
|
+
}
|
|
34
|
+
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.getPublicIpAddress = getPublicIpAddress;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spinnerUtils.d.ts","sourceRoot":"","sources":["../../src/utils/spinnerUtils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,GAAU,CAAC,aACzB,MAAM,OAAO,CAAC,CAAC,CAAC,gBACd,MAAM,gBACN,MAAM,cACR,MAAM,KAChB,OAAO,CAAC,CAAC,CA8CX,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForPromise = void 0;
|
|
4
|
+
const nanospinner_1 = require("nanospinner");
|
|
5
|
+
const waitForPromise = async (promiseFn, spinnerText = "Processing...", successText = "OK!", errorText = "Error.") => {
|
|
6
|
+
const spinner = (0, nanospinner_1.createSpinner)(spinnerText).start();
|
|
7
|
+
// Store original console.log and console.error, and collect log messages
|
|
8
|
+
const originalConsoleLog = console.log;
|
|
9
|
+
const originalConsoleError = console.error;
|
|
10
|
+
let logMessages = [];
|
|
11
|
+
let errorMessages = [];
|
|
12
|
+
console.log = (...args) => {
|
|
13
|
+
logMessages.push(args.map(arg => (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' '));
|
|
14
|
+
};
|
|
15
|
+
console.error = (...args) => {
|
|
16
|
+
errorMessages.push(args.map(arg => (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' '));
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
const result = await promiseFn();
|
|
20
|
+
if (result) {
|
|
21
|
+
spinner.success({ text: successText });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(errorText);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
spinner.error({ text: errorText });
|
|
30
|
+
// Print collected log messages and error messages on error
|
|
31
|
+
if (logMessages.length > 0) {
|
|
32
|
+
originalConsoleLog("\nCollected logs:");
|
|
33
|
+
logMessages.forEach((message) => originalConsoleLog(message));
|
|
34
|
+
}
|
|
35
|
+
if (errorMessages.length > 0) {
|
|
36
|
+
originalConsoleError("\nCollected errors:");
|
|
37
|
+
errorMessages.forEach((message) => originalConsoleError(message));
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
// Restore the original console.log and console.error functions
|
|
43
|
+
console.log = originalConsoleLog;
|
|
44
|
+
console.error = originalConsoleError;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.waitForPromise = waitForPromise;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssl.d.ts","sourceRoot":"","sources":["../../src/utils/ssl.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mBAAmB;;;CAqB/B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getOrCreateSSLCerts = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const chia_server_coin_1 = require("chia-server-coin");
|
|
30
|
+
const config_1 = require("./config");
|
|
31
|
+
const getOrCreateSSLCerts = () => {
|
|
32
|
+
const sslDir = path.join(config_1.USER_DIR_PATH, "ssl");
|
|
33
|
+
const certPath = path.join(sslDir, "client.cert");
|
|
34
|
+
const keyPath = path.join(sslDir, "client.key");
|
|
35
|
+
// Ensure the SSL directory exists
|
|
36
|
+
if (!fs.existsSync(sslDir)) {
|
|
37
|
+
fs.mkdirSync(sslDir, { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
// Check if the certificate and key exist, if not, generate them
|
|
40
|
+
if (!fs.existsSync(certPath) || !fs.existsSync(keyPath)) {
|
|
41
|
+
new chia_server_coin_1.Tls(certPath, keyPath);
|
|
42
|
+
console.log("Client certificate and key generated successfully.");
|
|
43
|
+
}
|
|
44
|
+
// Return the paths to the cert and key files
|
|
45
|
+
return {
|
|
46
|
+
certPath,
|
|
47
|
+
keyPath,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
exports.getOrCreateSSLCerts = getOrCreateSSLCerts;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates if the SHA256 hash of the decompressed file matches the provided hash.
|
|
3
|
+
*
|
|
4
|
+
* @param sha256 - The expected SHA256 hash of the decompressed file.
|
|
5
|
+
* @param dataDir - The root folder where the data files are stored.
|
|
6
|
+
* @returns A boolean indicating whether the decompressed file's hash matches the provided hash.
|
|
7
|
+
*/
|
|
8
|
+
export declare const validateFileSha256: (sha256: string, dataDir: string) => boolean;
|
|
9
|
+
//# sourceMappingURL=validationUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../../src/utils/validationUtils.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,WACrB,MAAM,WACL,MAAM,KACd,OAoBF,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.validateFileSha256 = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const zlib = __importStar(require("zlib"));
|
|
29
|
+
const crypto = __importStar(require("crypto"));
|
|
30
|
+
const hashUtils_1 = require("./hashUtils");
|
|
31
|
+
/**
|
|
32
|
+
* Validates if the SHA256 hash of the decompressed file matches the provided hash.
|
|
33
|
+
*
|
|
34
|
+
* @param sha256 - The expected SHA256 hash of the decompressed file.
|
|
35
|
+
* @param dataDir - The root folder where the data files are stored.
|
|
36
|
+
* @returns A boolean indicating whether the decompressed file's hash matches the provided hash.
|
|
37
|
+
*/
|
|
38
|
+
const validateFileSha256 = (sha256, dataDir) => {
|
|
39
|
+
// Derive the file path from the SHA256 hash
|
|
40
|
+
const filePath = (0, hashUtils_1.getFilePathFromSha256)(sha256, dataDir);
|
|
41
|
+
if (!fs.existsSync(filePath)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
// Read and decompress the file
|
|
45
|
+
const fileBuffer = fs.readFileSync(filePath);
|
|
46
|
+
const decompressedBuffer = zlib.gunzipSync(fileBuffer);
|
|
47
|
+
// Calculate the SHA256 hash of the decompressed content
|
|
48
|
+
const hash = crypto
|
|
49
|
+
.createHash("sha256")
|
|
50
|
+
.update(decompressedBuffer)
|
|
51
|
+
.digest("hex");
|
|
52
|
+
// Compare the calculated hash with the provided hash
|
|
53
|
+
return hash === sha256;
|
|
54
|
+
};
|
|
55
|
+
exports.validateFileSha256 = validateFileSha256;
|