@dignetwork/dig-sdk 0.0.1-alpha.99 → 0.2.0
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 +21 -7
- package/README.md +412 -0
- package/dist/adapters.cjs +356 -0
- package/dist/adapters.cjs.map +1 -0
- package/dist/adapters.d.cts +20 -0
- package/dist/adapters.d.ts +20 -0
- package/dist/adapters.js +347 -0
- package/dist/adapters.js.map +1 -0
- package/dist/dev-shim-DfKRA1ok.d.cts +128 -0
- package/dist/dev-shim-DfKRA1ok.d.ts +128 -0
- package/dist/dig-client-entry-ChYxUvBn.d.cts +372 -0
- package/dist/dig-client-entry-ChYxUvBn.d.ts +372 -0
- package/dist/dig-client.cjs +443 -0
- package/dist/dig-client.cjs.map +1 -0
- package/dist/dig-client.d.cts +1 -0
- package/dist/dig-client.d.ts +1 -0
- package/dist/dig-client.js +432 -0
- package/dist/dig-client.js.map +1 -0
- package/dist/index.cjs +1186 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +502 -0
- package/dist/index.d.ts +502 -5
- package/dist/index.js +1156 -19
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +369 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +23 -0
- package/dist/next.d.ts +23 -0
- package/dist/next.js +362 -0
- package/dist/next.js.map +1 -0
- package/dist/spend.cjs +14 -0
- package/dist/spend.cjs.map +1 -0
- package/dist/spend.d.cts +1 -0
- package/dist/spend.d.ts +1 -0
- package/dist/spend.js +3 -0
- package/dist/spend.js.map +1 -0
- package/dist/vite.cjs +381 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +35 -0
- package/dist/vite.d.ts +35 -0
- package/dist/vite.js +375 -0
- package/dist/vite.js.map +1 -0
- package/package.json +87 -59
- package/vendor/PROVENANCE.md +102 -0
- package/vendor/dig_client.d.ts +150 -0
- package/vendor/dig_client.mjs +805 -0
- package/vendor/dig_client_bg.wasm +0 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +0 -163
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +0 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.js +0 -707
- package/dist/DataIntegrityTree/DataLayerError.d.ts +0 -6
- package/dist/DataIntegrityTree/DataLayerError.d.ts.map +0 -1
- package/dist/DataIntegrityTree/DataLayerError.js +0 -17
- package/dist/DataIntegrityTree/index.d.ts +0 -2
- package/dist/DataIntegrityTree/index.d.ts.map +0 -1
- package/dist/DataIntegrityTree/index.js +0 -17
- package/dist/DigNetwork/ContentServer.d.ts +0 -31
- package/dist/DigNetwork/ContentServer.d.ts.map +0 -1
- package/dist/DigNetwork/ContentServer.js +0 -176
- package/dist/DigNetwork/DigChallenge.d.ts +0 -82
- package/dist/DigNetwork/DigChallenge.d.ts.map +0 -1
- package/dist/DigNetwork/DigChallenge.js +0 -144
- package/dist/DigNetwork/DigNetwork.d.ts +0 -14
- package/dist/DigNetwork/DigNetwork.d.ts.map +0 -1
- package/dist/DigNetwork/DigNetwork.js +0 -169
- package/dist/DigNetwork/DigPeer.d.ts +0 -24
- package/dist/DigNetwork/DigPeer.d.ts.map +0 -1
- package/dist/DigNetwork/DigPeer.js +0 -118
- package/dist/DigNetwork/IncentiveServer.d.ts +0 -13
- package/dist/DigNetwork/IncentiveServer.d.ts.map +0 -1
- package/dist/DigNetwork/IncentiveServer.js +0 -76
- package/dist/DigNetwork/PropagationServer.d.ts +0 -81
- package/dist/DigNetwork/PropagationServer.d.ts.map +0 -1
- package/dist/DigNetwork/PropagationServer.js +0 -563
- package/dist/DigNetwork/index.d.ts +0 -4
- package/dist/DigNetwork/index.d.ts.map +0 -1
- package/dist/DigNetwork/index.js +0 -19
- package/dist/blockchain/DataStore.d.ts +0 -67
- package/dist/blockchain/DataStore.d.ts.map +0 -1
- package/dist/blockchain/DataStore.js +0 -413
- package/dist/blockchain/DataStoreSerializer.d.ts +0 -52
- package/dist/blockchain/DataStoreSerializer.d.ts.map +0 -1
- package/dist/blockchain/DataStoreSerializer.js +0 -109
- package/dist/blockchain/FullNodePeer.d.ts +0 -31
- package/dist/blockchain/FullNodePeer.d.ts.map +0 -1
- package/dist/blockchain/FullNodePeer.js +0 -295
- package/dist/blockchain/ServerCoin.d.ts +0 -29
- package/dist/blockchain/ServerCoin.d.ts.map +0 -1
- package/dist/blockchain/ServerCoin.js +0 -324
- package/dist/blockchain/Wallet.d.ts +0 -28
- package/dist/blockchain/Wallet.d.ts.map +0 -1
- package/dist/blockchain/Wallet.js +0 -253
- package/dist/blockchain/coins.d.ts +0 -6
- package/dist/blockchain/coins.d.ts.map +0 -1
- package/dist/blockchain/coins.js +0 -102
- package/dist/blockchain/index.d.ts +0 -8
- package/dist/blockchain/index.d.ts.map +0 -1
- package/dist/blockchain/index.js +0 -36
- package/dist/index.d.ts.map +0 -1
- package/dist/prompts.d.ts +0 -21
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -149
- package/dist/types.d.ts +0 -64
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/utils/ContentScanner.d.ts +0 -63
- package/dist/utils/ContentScanner.d.ts.map +0 -1
- package/dist/utils/ContentScanner.js +0 -175
- package/dist/utils/Environment.d.ts +0 -18
- package/dist/utils/Environment.d.ts.map +0 -1
- package/dist/utils/Environment.js +0 -85
- package/dist/utils/FileCache.d.ts +0 -11
- package/dist/utils/FileCache.d.ts.map +0 -1
- package/dist/utils/FileCache.js +0 -58
- package/dist/utils/FileTransfer.d.ts +0 -47
- package/dist/utils/FileTransfer.d.ts.map +0 -1
- package/dist/utils/FileTransfer.js +0 -209
- package/dist/utils/NconfManager.d.ts +0 -11
- package/dist/utils/NconfManager.d.ts.map +0 -1
- package/dist/utils/NconfManager.js +0 -56
- package/dist/utils/StoreArchiveManager.d.ts +0 -45
- package/dist/utils/StoreArchiveManager.d.ts.map +0 -1
- package/dist/utils/StoreArchiveManager.js +0 -153
- package/dist/utils/asyncPool.d.ts +0 -9
- package/dist/utils/asyncPool.d.ts.map +0 -1
- package/dist/utils/asyncPool.js +0 -23
- package/dist/utils/config.d.ts +0 -68
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -223
- package/dist/utils/connectionUtils.d.ts +0 -10
- package/dist/utils/connectionUtils.d.ts.map +0 -1
- package/dist/utils/connectionUtils.js +0 -18
- package/dist/utils/credentialsUtils.d.ts +0 -8
- package/dist/utils/credentialsUtils.d.ts.map +0 -1
- package/dist/utils/credentialsUtils.js +0 -122
- package/dist/utils/directoryUtils.d.ts +0 -9
- package/dist/utils/directoryUtils.d.ts.map +0 -1
- package/dist/utils/directoryUtils.js +0 -110
- package/dist/utils/encryption.d.ts +0 -8
- package/dist/utils/encryption.d.ts.map +0 -1
- package/dist/utils/encryption.js +0 -55
- package/dist/utils/hashUtils.d.ts +0 -8
- package/dist/utils/hashUtils.d.ts.map +0 -1
- package/dist/utils/hashUtils.js +0 -44
- package/dist/utils/index.d.ts +0 -14
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -29
- package/dist/utils/merkle.d.ts +0 -2
- package/dist/utils/merkle.d.ts.map +0 -1
- package/dist/utils/merkle.js +0 -28
- package/dist/utils/network.d.ts +0 -2
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js +0 -54
- package/dist/utils/spinnerUtils.d.ts +0 -2
- package/dist/utils/spinnerUtils.d.ts.map +0 -1
- package/dist/utils/spinnerUtils.js +0 -47
- package/dist/utils/ssl.d.ts +0 -5
- package/dist/utils/ssl.d.ts.map +0 -1
- package/dist/utils/ssl.js +0 -50
- package/dist/utils/validationUtils.d.ts +0 -9
- package/dist/utils/validationUtils.d.ts.map +0 -1
- package/dist/utils/validationUtils.js +0 -55
package/dist/utils/config.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
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.deleteDigConfigKey = exports.setDigConfigKey = exports.ensureDigConfig = exports.loadDigConfig = exports.getActiveStoreId = exports.getStoresList = exports.getCoinState = exports.setActiveStore = exports.setRemote = exports.createInitialConfig = exports.getHeightFilePath = exports.CONFIG_FILE_PATH = exports.USER_DIR_PATH = exports.STORE_PATH = exports.DIG_FOLDER_PATH = exports.MIN_HEIGHT_HEADER_HASH = exports.MIN_HEIGHT = exports.MAIN_NET_GENISES_CHALLENGE = exports.NETWORK_AGG_SIG_DATA = void 0;
|
|
30
|
-
const fs = __importStar(require("fs"));
|
|
31
|
-
const path = __importStar(require("path"));
|
|
32
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
33
|
-
const os_1 = __importDefault(require("os"));
|
|
34
|
-
const Environment_1 = require("./Environment");
|
|
35
|
-
exports.NETWORK_AGG_SIG_DATA = "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb";
|
|
36
|
-
exports.MAIN_NET_GENISES_CHALLENGE = exports.NETWORK_AGG_SIG_DATA;
|
|
37
|
-
exports.MIN_HEIGHT = 5777842;
|
|
38
|
-
exports.MIN_HEIGHT_HEADER_HASH = "b29a4daac2434fd17a36e15ba1aac5d65012d4a66f99bed0bf2b5342e92e562c";
|
|
39
|
-
exports.DIG_FOLDER_PATH = Environment_1.Environment.DIG_FOLDER_PATH || path.join(process.cwd(), ".dig");
|
|
40
|
-
exports.STORE_PATH = path.join(exports.DIG_FOLDER_PATH, "stores");
|
|
41
|
-
exports.USER_DIR_PATH = path.join(os_1.default.homedir(), ".dig");
|
|
42
|
-
exports.CONFIG_FILE_PATH = path.join(exports.DIG_FOLDER_PATH, "dig.config.json");
|
|
43
|
-
const getHeightFilePath = (storeId) => path.join(exports.STORE_PATH, storeId, "height.json");
|
|
44
|
-
exports.getHeightFilePath = getHeightFilePath;
|
|
45
|
-
const createInitialConfig = () => {
|
|
46
|
-
const initialConfig = { deploy_dir: "./dist", remote: "" };
|
|
47
|
-
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(initialConfig, null, 4));
|
|
48
|
-
console.log("Created dig.config.json file.");
|
|
49
|
-
};
|
|
50
|
-
exports.createInitialConfig = createInitialConfig;
|
|
51
|
-
const setRemote = (remote) => {
|
|
52
|
-
(0, exports.ensureDigConfig)("");
|
|
53
|
-
const config = JSON.parse(fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8"));
|
|
54
|
-
config.remote = remote;
|
|
55
|
-
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4));
|
|
56
|
-
console.log(`Remote set to ${remote}`);
|
|
57
|
-
};
|
|
58
|
-
exports.setRemote = setRemote;
|
|
59
|
-
const setActiveStore = (storeId) => {
|
|
60
|
-
(0, exports.ensureDigConfig)("");
|
|
61
|
-
const config = JSON.parse(fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8"));
|
|
62
|
-
config.active_store = storeId;
|
|
63
|
-
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4));
|
|
64
|
-
console.log(`Active Store set to ${storeId}`);
|
|
65
|
-
};
|
|
66
|
-
exports.setActiveStore = setActiveStore;
|
|
67
|
-
/**
|
|
68
|
-
* Prompts the user to select an active store from a list of folders.
|
|
69
|
-
* @param {string[]} options - The list of folder options to choose from.
|
|
70
|
-
* @returns {Promise<string>} The selected folder name.
|
|
71
|
-
*/
|
|
72
|
-
const promptUserForSelection = async (options) => {
|
|
73
|
-
const questions = [
|
|
74
|
-
{
|
|
75
|
-
type: "list",
|
|
76
|
-
name: "selectedStore",
|
|
77
|
-
message: "Select the active store:",
|
|
78
|
-
choices: options.map((option) => ({ name: option, value: option })),
|
|
79
|
-
},
|
|
80
|
-
];
|
|
81
|
-
const answer = await inquirer_1.default.prompt(questions);
|
|
82
|
-
return answer.selectedStore;
|
|
83
|
-
};
|
|
84
|
-
const getCoinState = (storeId) => {
|
|
85
|
-
const stateFile = path.join(exports.STORE_PATH, `${storeId}.json`);
|
|
86
|
-
if (!fs.existsSync(stateFile)) {
|
|
87
|
-
return {
|
|
88
|
-
metadata: { rootHash: "", bytes: "", label: "", description: "" },
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
const stateContent = fs.readFileSync(stateFile, "utf-8");
|
|
92
|
-
const { latestStore } = JSON.parse(stateContent);
|
|
93
|
-
return latestStore;
|
|
94
|
-
};
|
|
95
|
-
exports.getCoinState = getCoinState;
|
|
96
|
-
/**
|
|
97
|
-
* Retrieves the list of valid store folders.
|
|
98
|
-
* If the STORE_PATH directory does not exist, it is created.
|
|
99
|
-
*
|
|
100
|
-
* @returns {string[]} An array of valid store folder names.
|
|
101
|
-
*/
|
|
102
|
-
const getStoresList = () => {
|
|
103
|
-
// Check if the STORE_PATH exists, create it if not
|
|
104
|
-
if (!fs.existsSync(exports.STORE_PATH)) {
|
|
105
|
-
fs.mkdirSync(exports.STORE_PATH, { recursive: true });
|
|
106
|
-
}
|
|
107
|
-
const folders = fs.readdirSync(exports.STORE_PATH);
|
|
108
|
-
return folders.filter((folder) => /^[a-f0-9]{64}$/.test(folder) &&
|
|
109
|
-
fs.lstatSync(path.join(exports.STORE_PATH, folder)).isDirectory());
|
|
110
|
-
};
|
|
111
|
-
exports.getStoresList = getStoresList;
|
|
112
|
-
/**
|
|
113
|
-
* Retrieves the active_store value from the dig.config.json file within the .dig directory.
|
|
114
|
-
* If not set, checks the subfolders and prompts the user to choose the active one if necessary.
|
|
115
|
-
*
|
|
116
|
-
* @returns {Promise<Buffer | null>} The active_store value as a Buffer if found, otherwise null.
|
|
117
|
-
*/
|
|
118
|
-
const getActiveStoreId = async () => {
|
|
119
|
-
const configFilePath = path.join(exports.DIG_FOLDER_PATH, "dig.config.json");
|
|
120
|
-
if (!fs.existsSync(configFilePath)) {
|
|
121
|
-
(0, exports.createInitialConfig)();
|
|
122
|
-
}
|
|
123
|
-
const configContent = fs.readFileSync(configFilePath, "utf-8");
|
|
124
|
-
const config = JSON.parse(configContent);
|
|
125
|
-
if (config &&
|
|
126
|
-
config.active_store &&
|
|
127
|
-
/^[a-f0-9]{64}$/.test(config.active_store)) {
|
|
128
|
-
return Buffer.from(config.active_store, "hex");
|
|
129
|
-
}
|
|
130
|
-
const validFolders = (0, exports.getStoresList)();
|
|
131
|
-
if (validFolders.length === 1 || Environment_1.Environment.REMOTE_NODE) {
|
|
132
|
-
// If only one valid folder exists, set it as the active_store and return it
|
|
133
|
-
config.active_store = validFolders[0];
|
|
134
|
-
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 4));
|
|
135
|
-
return Buffer.from(validFolders[0], "hex");
|
|
136
|
-
}
|
|
137
|
-
else if (validFolders.length > 1) {
|
|
138
|
-
// Prompt the user to select the active store
|
|
139
|
-
const selectedStore = await promptUserForSelection(validFolders);
|
|
140
|
-
config.active_store = selectedStore;
|
|
141
|
-
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 4));
|
|
142
|
-
return Buffer.from(selectedStore, "hex");
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
};
|
|
146
|
-
exports.getActiveStoreId = getActiveStoreId;
|
|
147
|
-
/**
|
|
148
|
-
* Loads the dig.config.json file from the base directory.
|
|
149
|
-
*
|
|
150
|
-
* @param baseDir - The base directory where the config file is located.
|
|
151
|
-
* @returns {DigConfig} - The parsed configuration object.
|
|
152
|
-
* @throws Will throw an error if the config file does not exist or cannot be parsed.
|
|
153
|
-
*/
|
|
154
|
-
const loadDigConfig = (baseDir) => {
|
|
155
|
-
(0, exports.ensureDigConfig)("");
|
|
156
|
-
try {
|
|
157
|
-
const configContent = fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8");
|
|
158
|
-
const config = JSON.parse(configContent);
|
|
159
|
-
return config;
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
throw new Error(`Failed to load configuration: ${error.message}`);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
exports.loadDigConfig = loadDigConfig;
|
|
166
|
-
/**
|
|
167
|
-
* Ensures that the dig.config.json file exists in the base directory.
|
|
168
|
-
* If the file doesn't exist, it creates it with the deploy_dir set to "./dist".
|
|
169
|
-
*
|
|
170
|
-
* @param baseDir - The base directory where the config file should be located.
|
|
171
|
-
* @returns {DigConfig} - The configuration object.
|
|
172
|
-
*/
|
|
173
|
-
const ensureDigConfig = (baseDir) => {
|
|
174
|
-
if (!fs.existsSync(exports.CONFIG_FILE_PATH)) {
|
|
175
|
-
fs.mkdirSync(exports.DIG_FOLDER_PATH, { recursive: true });
|
|
176
|
-
const defaultConfig = { deploy_dir: "./dist" };
|
|
177
|
-
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(defaultConfig, null, 4), "utf-8");
|
|
178
|
-
console.log(`Created new dig.config.json at ${exports.CONFIG_FILE_PATH}`);
|
|
179
|
-
return defaultConfig;
|
|
180
|
-
}
|
|
181
|
-
try {
|
|
182
|
-
const configContent = fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8");
|
|
183
|
-
const config = JSON.parse(configContent);
|
|
184
|
-
return config;
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
throw new Error(`Failed to load configuration: ${error.message}`);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
exports.ensureDigConfig = ensureDigConfig;
|
|
191
|
-
/**
|
|
192
|
-
* Sets a key-value pair in the dig.config.json file.
|
|
193
|
-
* If the file or key doesn't exist, it will create them.
|
|
194
|
-
*
|
|
195
|
-
* @param baseDir - The base directory where the config file is located.
|
|
196
|
-
* @param key - The configuration key to set.
|
|
197
|
-
* @param value - The value to set for the given key.
|
|
198
|
-
*/
|
|
199
|
-
const setDigConfigKey = (baseDir, key, value) => {
|
|
200
|
-
const config = (0, exports.ensureDigConfig)(baseDir);
|
|
201
|
-
config[key] = value;
|
|
202
|
-
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4), "utf-8");
|
|
203
|
-
console.log(`Set ${key} to ${value} in ${exports.CONFIG_FILE_PATH}`);
|
|
204
|
-
};
|
|
205
|
-
exports.setDigConfigKey = setDigConfigKey;
|
|
206
|
-
/**
|
|
207
|
-
* Deletes a key from the dig.config.json file.
|
|
208
|
-
*
|
|
209
|
-
* @param baseDir - The base directory where the config file is located.
|
|
210
|
-
* @param key - The configuration key to delete.
|
|
211
|
-
*/
|
|
212
|
-
const deleteDigConfigKey = (baseDir, key) => {
|
|
213
|
-
const config = (0, exports.ensureDigConfig)(baseDir);
|
|
214
|
-
if (config.hasOwnProperty(key)) {
|
|
215
|
-
delete config[key];
|
|
216
|
-
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4), "utf-8");
|
|
217
|
-
console.log(`Deleted ${key} from ${exports.CONFIG_FILE_PATH}`);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
console.log(`Key ${key} does not exist in ${exports.CONFIG_FILE_PATH}`);
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
exports.deleteDigConfigKey = deleteDigConfigKey;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Verifies if a connection string is valid based on the given format.
|
|
3
|
-
*
|
|
4
|
-
* Format: hostname:port (optional)
|
|
5
|
-
*
|
|
6
|
-
* @param {string} connectionString - The connection string to verify.
|
|
7
|
-
* @returns {boolean} - Returns true if the connection string is valid, otherwise false.
|
|
8
|
-
*/
|
|
9
|
-
export declare const verifyConnectionString: (connectionString: string) => boolean;
|
|
10
|
-
//# sourceMappingURL=connectionUtils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connectionUtils.d.ts","sourceRoot":"","sources":["../../src/utils/connectionUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,qBAAsB,MAAM,KAAG,OAMjE,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.verifyConnectionString = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Verifies if a connection string is valid based on the given format.
|
|
6
|
-
*
|
|
7
|
-
* Format: hostname:port (optional)
|
|
8
|
-
*
|
|
9
|
-
* @param {string} connectionString - The connection string to verify.
|
|
10
|
-
* @returns {boolean} - Returns true if the connection string is valid, otherwise false.
|
|
11
|
-
*/
|
|
12
|
-
const verifyConnectionString = (connectionString) => {
|
|
13
|
-
// Define the regular expression pattern to match a hostname with an optional port
|
|
14
|
-
const pattern = /^(?!:\/\/)([a-zA-Z0-9.-]+)(:\d{1,5})?$/;
|
|
15
|
-
// Test the connection string against the pattern
|
|
16
|
-
return pattern.test(connectionString);
|
|
17
|
-
};
|
|
18
|
-
exports.verifyConnectionString = verifyConnectionString;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { NconfManager } from "./NconfManager";
|
|
2
|
-
import { Credentials } from "../types";
|
|
3
|
-
export declare const encryptAndStoreCredentials: (nconfManager: NconfManager, remote: string, key: string, value: string) => Promise<void>;
|
|
4
|
-
export declare const retrieveAndDecryptCredentials: (nconfManager: NconfManager, remote: string, key: string) => Promise<string | null>;
|
|
5
|
-
export declare const promptCredentials: (remote: string) => Promise<Credentials>;
|
|
6
|
-
export declare const clearCredentials: (remote: string) => Promise<void>;
|
|
7
|
-
export declare function generateHighEntropyValue(length?: number): string;
|
|
8
|
-
//# sourceMappingURL=credentialsUtils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"credentialsUtils.d.ts","sourceRoot":"","sources":["../../src/utils/credentialsUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAUvC,eAAO,MAAM,0BAA0B,iBACvB,YAAY,UAClB,MAAM,OACT,MAAM,SACJ,MAAM,kBAcd,CAAC;AAGF,eAAO,MAAM,6BAA6B,iBAC1B,YAAY,UAClB,MAAM,OACT,MAAM,KACV,OAAO,CAAC,MAAM,GAAG,IAAI,CASvB,CAAC;AAGF,eAAO,MAAM,iBAAiB,WAAkB,MAAM,KAAG,OAAO,CAAC,WAAW,CAyC3E,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAAkB,MAAM,kBAapD,CAAC;AAEF,wBAAgB,wBAAwB,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM,CAsBpE"}
|
|
@@ -1,122 +0,0 @@
|
|
|
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.clearCredentials = exports.promptCredentials = exports.retrieveAndDecryptCredentials = exports.encryptAndStoreCredentials = void 0;
|
|
30
|
-
exports.generateHighEntropyValue = generateHighEntropyValue;
|
|
31
|
-
const readline = __importStar(require("readline"));
|
|
32
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
33
|
-
const NconfManager_1 = require("./NconfManager");
|
|
34
|
-
const encryption_1 = require("../utils/encryption");
|
|
35
|
-
// Validate that the remote is a valid IP address
|
|
36
|
-
const validateIPAddress = (ip) => {
|
|
37
|
-
const ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
38
|
-
return ipRegex.test(ip);
|
|
39
|
-
};
|
|
40
|
-
// Encrypt and store credentials using the NconfManager
|
|
41
|
-
const encryptAndStoreCredentials = async (nconfManager, remote, key, value) => {
|
|
42
|
-
const encryptedData = (0, encryption_1.encryptData)(value);
|
|
43
|
-
const existingData = await nconfManager.getConfigValue(remote);
|
|
44
|
-
const updatedData = {
|
|
45
|
-
...(existingData || {}),
|
|
46
|
-
[key]: encryptedData,
|
|
47
|
-
};
|
|
48
|
-
await nconfManager.setConfigValue(remote, updatedData);
|
|
49
|
-
console.log(`${key} stored securely for remote ${remote}.`);
|
|
50
|
-
};
|
|
51
|
-
exports.encryptAndStoreCredentials = encryptAndStoreCredentials;
|
|
52
|
-
// Retrieve and decrypt credentials from the NconfManager
|
|
53
|
-
const retrieveAndDecryptCredentials = async (nconfManager, remote, key) => {
|
|
54
|
-
const existingData = await nconfManager.getConfigValue(remote);
|
|
55
|
-
if (existingData && existingData[key]) {
|
|
56
|
-
return (0, encryption_1.decryptData)(existingData[key]);
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
};
|
|
60
|
-
exports.retrieveAndDecryptCredentials = retrieveAndDecryptCredentials;
|
|
61
|
-
// Function to prompt for username and password
|
|
62
|
-
const promptCredentials = async (remote) => {
|
|
63
|
-
if (!validateIPAddress(remote)) {
|
|
64
|
-
throw new Error("Invalid IP address. Please enter a valid IP address.");
|
|
65
|
-
}
|
|
66
|
-
const nconfManager = new NconfManager_1.NconfManager("credentials.json");
|
|
67
|
-
// Check if credentials are already stored
|
|
68
|
-
const storedUsername = await (0, exports.retrieveAndDecryptCredentials)(nconfManager, remote, "username");
|
|
69
|
-
const storedPassword = await (0, exports.retrieveAndDecryptCredentials)(nconfManager, remote, "password");
|
|
70
|
-
if (storedUsername && storedPassword) {
|
|
71
|
-
console.log(`Using stored credentials for remote ${remote}`);
|
|
72
|
-
return { username: storedUsername, password: storedPassword };
|
|
73
|
-
}
|
|
74
|
-
// If not stored, prompt the user for credentials
|
|
75
|
-
const rl = readline.createInterface({
|
|
76
|
-
input: process.stdin,
|
|
77
|
-
output: process.stdout,
|
|
78
|
-
});
|
|
79
|
-
const askQuestion = (question) => new Promise((resolve) => rl.question(question, resolve));
|
|
80
|
-
const username = await askQuestion(`Enter your username for ${remote}: `);
|
|
81
|
-
const password = await askQuestion(`Enter your password for ${remote}: `);
|
|
82
|
-
// Ask if the user wants to store the credentials
|
|
83
|
-
const storeCredentials = await askQuestion(`Would you like to store these credentials for later use? (Remember to add these to your remote node env) (y/n): `);
|
|
84
|
-
rl.close();
|
|
85
|
-
if (storeCredentials.toLowerCase() === "y") {
|
|
86
|
-
await (0, exports.encryptAndStoreCredentials)(nconfManager, remote, "username", username);
|
|
87
|
-
await (0, exports.encryptAndStoreCredentials)(nconfManager, remote, "password", password);
|
|
88
|
-
}
|
|
89
|
-
return { username, password };
|
|
90
|
-
};
|
|
91
|
-
exports.promptCredentials = promptCredentials;
|
|
92
|
-
const clearCredentials = async (remote) => {
|
|
93
|
-
const nconfManager = new NconfManager_1.NconfManager("credentials.json");
|
|
94
|
-
const existingData = await nconfManager.getConfigValue(remote);
|
|
95
|
-
if (existingData && (existingData.username || existingData.password)) {
|
|
96
|
-
await nconfManager.setConfigValue(remote, {}); // Clear the credentials for the remote
|
|
97
|
-
console.log(`Credentials for remote ${remote} have been cleared.`);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
console.log(`No credentials found for remote ${remote}.`);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
exports.clearCredentials = clearCredentials;
|
|
104
|
-
function generateHighEntropyValue(length = 10) {
|
|
105
|
-
const possibleChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
106
|
-
const charSetSize = possibleChars.length;
|
|
107
|
-
let result = "";
|
|
108
|
-
let remainingBytes = crypto_1.default.randomBytes(length * 2); // Generate more random bytes than needed
|
|
109
|
-
for (let i = 0; i < length; i++) {
|
|
110
|
-
let randomValue;
|
|
111
|
-
do {
|
|
112
|
-
if (remainingBytes.length < 1) {
|
|
113
|
-
remainingBytes = crypto_1.default.randomBytes(length * 2); // Refill the buffer if it runs out
|
|
114
|
-
}
|
|
115
|
-
randomValue = remainingBytes[0];
|
|
116
|
-
remainingBytes = remainingBytes.slice(1); // Remove the used byte
|
|
117
|
-
} while (randomValue >= charSetSize * Math.floor(256 / charSetSize)); // Discard biased values
|
|
118
|
-
const randomIndex = randomValue % charSetSize;
|
|
119
|
-
result += possibleChars.charAt(randomIndex);
|
|
120
|
-
}
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DataIntegrityTree } from "../DataIntegrityTree";
|
|
2
|
-
export declare const addDirectory: (datalayer: DataIntegrityTree, dirPath: string, baseDir?: string) => Promise<void>;
|
|
3
|
-
/**
|
|
4
|
-
* Calculate the total size of the DIG_FOLDER_PATH
|
|
5
|
-
* @param folderPath - The path of the folder to calculate size.
|
|
6
|
-
* @returns The total size of the folder in bytes.
|
|
7
|
-
*/
|
|
8
|
-
export declare const calculateFolderSize: (folderPath: string) => bigint;
|
|
9
|
-
//# sourceMappingURL=directoryUtils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AA+BzD,eAAO,MAAM,YAAY,cACZ,iBAAiB,WACnB,MAAM,YACN,MAAM,KACd,OAAO,CAAC,IAAI,CA4Cd,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAiBxD,CAAC"}
|
|
@@ -1,110 +0,0 @@
|
|
|
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 path = __importStar(require("path"));
|
|
31
|
-
const fs = __importStar(require("fs"));
|
|
32
|
-
const ignore_1 = __importDefault(require("ignore"));
|
|
33
|
-
// Custom concurrency handler
|
|
34
|
-
const limitConcurrency = async (concurrencyLimit, tasks) => {
|
|
35
|
-
const executing = [];
|
|
36
|
-
for (const task of tasks) {
|
|
37
|
-
const p = task();
|
|
38
|
-
// Add the new task to the executing array
|
|
39
|
-
executing.push(p);
|
|
40
|
-
// When a task completes, remove it from the executing array
|
|
41
|
-
const cleanup = p.finally(() => {
|
|
42
|
-
executing.splice(executing.indexOf(cleanup), 1);
|
|
43
|
-
});
|
|
44
|
-
// Once the limit is reached, wait for one to complete
|
|
45
|
-
if (executing.length >= concurrencyLimit) {
|
|
46
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
47
|
-
await Promise.race(executing);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Wait for all remaining tasks to complete
|
|
51
|
-
return Promise.all(executing);
|
|
52
|
-
};
|
|
53
|
-
const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
54
|
-
const ig = (0, ignore_1.default)();
|
|
55
|
-
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
56
|
-
// Load .gitignore rules if the file exists
|
|
57
|
-
if (fs.existsSync(gitignorePath)) {
|
|
58
|
-
const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8");
|
|
59
|
-
ig.add(gitignoreContent);
|
|
60
|
-
}
|
|
61
|
-
const files = fs.readdirSync(dirPath);
|
|
62
|
-
const tasks = [];
|
|
63
|
-
for (const file of files) {
|
|
64
|
-
const filePath = path.join(dirPath, file);
|
|
65
|
-
const relativePath = path.relative(baseDir, filePath).replace(/\\/g, "/");
|
|
66
|
-
// Skip the .dig, .git folders and files or directories ignored by .gitignore
|
|
67
|
-
if (file === ".dig" || file === ".git" || ig.ignores(relativePath)) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const stat = fs.statSync(filePath);
|
|
71
|
-
if (stat.isDirectory()) {
|
|
72
|
-
// Recursively process the directory
|
|
73
|
-
tasks.push(() => (0, exports.addDirectory)(datalayer, filePath, baseDir));
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// Add a task for each file to be processed
|
|
77
|
-
tasks.push(() => new Promise((resolve, reject) => {
|
|
78
|
-
const stream = fs.createReadStream(filePath);
|
|
79
|
-
datalayer
|
|
80
|
-
.upsertKey(stream, Buffer.from(relativePath).toString("hex"))
|
|
81
|
-
.then(() => resolve())
|
|
82
|
-
.catch(reject);
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// Run tasks with limited concurrency (set the concurrency limit as needed)
|
|
87
|
-
await limitConcurrency(10, tasks); // Adjust 10 based on your system limits
|
|
88
|
-
};
|
|
89
|
-
exports.addDirectory = addDirectory;
|
|
90
|
-
/**
|
|
91
|
-
* Calculate the total size of the DIG_FOLDER_PATH
|
|
92
|
-
* @param folderPath - The path of the folder to calculate size.
|
|
93
|
-
* @returns The total size of the folder in bytes.
|
|
94
|
-
*/
|
|
95
|
-
const calculateFolderSize = (folderPath) => {
|
|
96
|
-
let totalSize = BigInt(0);
|
|
97
|
-
const files = fs.readdirSync(folderPath);
|
|
98
|
-
for (const file of files) {
|
|
99
|
-
const filePath = path.join(folderPath, file);
|
|
100
|
-
const stat = fs.statSync(filePath);
|
|
101
|
-
if (stat.isDirectory()) {
|
|
102
|
-
totalSize += (0, exports.calculateFolderSize)(filePath);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
totalSize += BigInt(stat.size);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return totalSize;
|
|
109
|
-
};
|
|
110
|
-
exports.calculateFolderSize = calculateFolderSize;
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/utils/encryption.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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;
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/utils/hashUtils.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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;
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export * from './config';
|
|
2
|
-
export * from './connectionUtils';
|
|
3
|
-
export * from './credentialsUtils';
|
|
4
|
-
export * from './directoryUtils';
|
|
5
|
-
export * from './encryption';
|
|
6
|
-
export * from './FileCache';
|
|
7
|
-
export * from './hashUtils';
|
|
8
|
-
export * from './NconfManager';
|
|
9
|
-
export * from './network';
|
|
10
|
-
export * from './spinnerUtils';
|
|
11
|
-
export * from './ssl';
|
|
12
|
-
export * from './validationUtils';
|
|
13
|
-
export * from './Environment';
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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;AAClC,cAAc,eAAe,CAAC"}
|