@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,11 @@
|
|
|
1
|
+
export declare class FileCache<T> {
|
|
2
|
+
private cacheDir;
|
|
3
|
+
constructor(relativeFilePath: string);
|
|
4
|
+
private ensureDirectoryExists;
|
|
5
|
+
private getCacheFilePath;
|
|
6
|
+
get(key: string): T | null;
|
|
7
|
+
set(key: string, data: T): void;
|
|
8
|
+
delete(key: string): void;
|
|
9
|
+
getCachedKeys(): string[];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=FileCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileCache.d.ts","sourceRoot":"","sources":["../../src/utils/FileCache.ts"],"names":[],"mappings":"AAIA,qBAAa,SAAS,CAAC,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAS;gBAEb,gBAAgB,EAAE,MAAM;IAMpC,OAAO,CAAC,qBAAqB;IAO7B,OAAO,CAAC,gBAAgB;IAKjB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAY1B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;IAO/B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IASzB,aAAa,IAAI,MAAM,EAAE;CAUjC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
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.FileCache = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
class FileCache {
|
|
11
|
+
constructor(relativeFilePath) {
|
|
12
|
+
this.cacheDir = path_1.default.join(config_1.DIG_FOLDER_PATH, relativeFilePath);
|
|
13
|
+
this.ensureDirectoryExists();
|
|
14
|
+
}
|
|
15
|
+
// Ensure the directory exists or create it
|
|
16
|
+
ensureDirectoryExists() {
|
|
17
|
+
if (!fs_1.default.existsSync(this.cacheDir)) {
|
|
18
|
+
fs_1.default.mkdirSync(this.cacheDir, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// Get the cache file path for the given key
|
|
22
|
+
getCacheFilePath(key) {
|
|
23
|
+
return path_1.default.join(this.cacheDir, `${key}.json`);
|
|
24
|
+
}
|
|
25
|
+
// Retrieve cached data by key
|
|
26
|
+
get(key) {
|
|
27
|
+
const cacheFilePath = this.getCacheFilePath(key);
|
|
28
|
+
if (!fs_1.default.existsSync(cacheFilePath)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const rawData = fs_1.default.readFileSync(cacheFilePath, "utf-8");
|
|
32
|
+
return JSON.parse(rawData);
|
|
33
|
+
}
|
|
34
|
+
// Save data to the cache
|
|
35
|
+
set(key, data) {
|
|
36
|
+
const cacheFilePath = this.getCacheFilePath(key);
|
|
37
|
+
const serializedData = JSON.stringify(data);
|
|
38
|
+
fs_1.default.writeFileSync(cacheFilePath, serializedData);
|
|
39
|
+
}
|
|
40
|
+
// Delete cache data by key
|
|
41
|
+
delete(key) {
|
|
42
|
+
const cacheFilePath = this.getCacheFilePath(key);
|
|
43
|
+
if (fs_1.default.existsSync(cacheFilePath)) {
|
|
44
|
+
fs_1.default.unlinkSync(cacheFilePath);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Retrieve all cached keys in the directory
|
|
48
|
+
getCachedKeys() {
|
|
49
|
+
if (!fs_1.default.existsSync(this.cacheDir)) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return fs_1.default
|
|
53
|
+
.readdirSync(this.cacheDir)
|
|
54
|
+
.filter((file) => file.endsWith(".json"))
|
|
55
|
+
.map((file) => file.replace(".json", ""));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.FileCache = FileCache;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class NconfManager {
|
|
2
|
+
private configFilePath;
|
|
3
|
+
constructor(relativePath: string);
|
|
4
|
+
private initializeConfig;
|
|
5
|
+
getConfigValue<T>(key: string): Promise<T | null>;
|
|
6
|
+
setConfigValue(key: string, value: any): Promise<void>;
|
|
7
|
+
deleteConfigValue(key: string): Promise<void>;
|
|
8
|
+
configExists(): Promise<boolean>;
|
|
9
|
+
getFullConfig(): Promise<Record<string, any>>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=NconfManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NconfManager.d.ts","sourceRoot":"","sources":["../../src/utils/NconfManager.ts"],"names":[],"mappings":"AAQA,qBAAa,YAAY;IACvB,OAAO,CAAC,cAAc,CAAS;gBAEnB,YAAY,EAAE,MAAM;YAKlB,gBAAgB;IAejB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAMjD,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAStD,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAKhC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAI3D"}
|
|
@@ -0,0 +1,55 @@
|
|
|
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.NconfManager = void 0;
|
|
7
|
+
const nconf_1 = __importDefault(require("nconf"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const config_1 = require("./config");
|
|
11
|
+
const CONF_FOLDER_PATH = process.env.DIG_FOLDER_PATH || config_1.USER_DIR_PATH;
|
|
12
|
+
class NconfManager {
|
|
13
|
+
constructor(relativePath) {
|
|
14
|
+
this.configFilePath = path_1.default.join(CONF_FOLDER_PATH, relativePath);
|
|
15
|
+
this.initializeConfig();
|
|
16
|
+
}
|
|
17
|
+
async initializeConfig() {
|
|
18
|
+
const directory = path_1.default.dirname(this.configFilePath);
|
|
19
|
+
if (!(await fs_extra_1.default.pathExists(directory))) {
|
|
20
|
+
await fs_extra_1.default.mkdirp(directory);
|
|
21
|
+
console.log("Directory created:", directory);
|
|
22
|
+
}
|
|
23
|
+
if (!(await fs_extra_1.default.pathExists(this.configFilePath))) {
|
|
24
|
+
await fs_extra_1.default.writeFile(this.configFilePath, "{}");
|
|
25
|
+
console.log("Configuration file created:", this.configFilePath);
|
|
26
|
+
}
|
|
27
|
+
nconf_1.default.file({ file: this.configFilePath });
|
|
28
|
+
}
|
|
29
|
+
async getConfigValue(key) {
|
|
30
|
+
await this.initializeConfig();
|
|
31
|
+
const value = nconf_1.default.get(key);
|
|
32
|
+
return value !== undefined ? value : null;
|
|
33
|
+
}
|
|
34
|
+
async setConfigValue(key, value) {
|
|
35
|
+
await this.initializeConfig();
|
|
36
|
+
nconf_1.default.set(key, value);
|
|
37
|
+
await new Promise((resolve, reject) => nconf_1.default.save((err) => (err ? reject(err) : resolve(undefined))));
|
|
38
|
+
console.log(`${key} saved to config file.`);
|
|
39
|
+
}
|
|
40
|
+
async deleteConfigValue(key) {
|
|
41
|
+
await this.initializeConfig();
|
|
42
|
+
nconf_1.default.clear(key);
|
|
43
|
+
await new Promise((resolve, reject) => nconf_1.default.save((err) => (err ? reject(err) : resolve(undefined))));
|
|
44
|
+
console.log(`${key} deleted from config file.`);
|
|
45
|
+
}
|
|
46
|
+
async configExists() {
|
|
47
|
+
return await fs_extra_1.default.pathExists(this.configFilePath);
|
|
48
|
+
}
|
|
49
|
+
// Method to get the full configuration as a key-value object
|
|
50
|
+
async getFullConfig() {
|
|
51
|
+
await this.initializeConfig();
|
|
52
|
+
return nconf_1.default.get() || {};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.NconfManager = NconfManager;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DigConfig } from "../types";
|
|
2
|
+
export declare const NETWORK_AGG_SIG_DATA = "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb";
|
|
3
|
+
export declare const MIN_HEIGHT = 5777842;
|
|
4
|
+
export declare const MIN_HEIGHT_HEADER_HASH = "b29a4daac2434fd17a36e15ba1aac5d65012d4a66f99bed0bf2b5342e92e562c";
|
|
5
|
+
export declare const DIG_FOLDER_PATH: string;
|
|
6
|
+
export declare const STORE_PATH: string;
|
|
7
|
+
export declare const USER_DIR_PATH: string;
|
|
8
|
+
export declare const CONFIG_FILE_PATH: string;
|
|
9
|
+
export declare const getManifestFilePath: (storeId: string) => string;
|
|
10
|
+
export declare const getHeightFilePath: (storeId: string) => string;
|
|
11
|
+
export declare const createInitialConfig: () => void;
|
|
12
|
+
export declare const setRemote: (remote: string) => void;
|
|
13
|
+
export declare const setActiveStore: (storeId: string) => void;
|
|
14
|
+
export declare const getCoinState: (storeId: string) => {
|
|
15
|
+
metadata: {
|
|
16
|
+
rootHash: string;
|
|
17
|
+
bytes: string;
|
|
18
|
+
label: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves a list of valid store folders (64-character hexadecimal names) in the DIG folder.
|
|
24
|
+
*
|
|
25
|
+
* @returns {string[]} An array of valid folder names.
|
|
26
|
+
*/
|
|
27
|
+
export declare const getStoresList: () => string[];
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the active_store value from the dig.config.json file within the .dig directory.
|
|
30
|
+
* If not set, checks the subfolders and prompts the user to choose the active one if necessary.
|
|
31
|
+
*
|
|
32
|
+
* @returns {Promise<Buffer | null>} The active_store value as a Buffer if found, otherwise null.
|
|
33
|
+
*/
|
|
34
|
+
export declare const getActiveStoreId: () => Promise<Buffer | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Loads the dig.config.json file from the base directory.
|
|
37
|
+
*
|
|
38
|
+
* @param baseDir - The base directory where the config file is located.
|
|
39
|
+
* @returns {DigConfig} - The parsed configuration object.
|
|
40
|
+
* @throws Will throw an error if the config file does not exist or cannot be parsed.
|
|
41
|
+
*/
|
|
42
|
+
export declare const loadDigConfig: (baseDir: string) => DigConfig;
|
|
43
|
+
/**
|
|
44
|
+
* Ensures that the dig.config.json file exists in the base directory.
|
|
45
|
+
* If the file doesn't exist, it creates it with the deploy_dir set to "./dist".
|
|
46
|
+
*
|
|
47
|
+
* @param baseDir - The base directory where the config file should be located.
|
|
48
|
+
* @returns {DigConfig} - The configuration object.
|
|
49
|
+
*/
|
|
50
|
+
export declare const ensureDigConfig: (baseDir: string) => DigConfig;
|
|
51
|
+
/**
|
|
52
|
+
* Sets a key-value pair in the dig.config.json file.
|
|
53
|
+
* If the file or key doesn't exist, it will create them.
|
|
54
|
+
*
|
|
55
|
+
* @param baseDir - The base directory where the config file is located.
|
|
56
|
+
* @param key - The configuration key to set.
|
|
57
|
+
* @param value - The value to set for the given key.
|
|
58
|
+
*/
|
|
59
|
+
export declare const setDigConfigKey: (baseDir: string, key: string, value: any) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Deletes a key from the dig.config.json file.
|
|
62
|
+
*
|
|
63
|
+
* @param baseDir - The base directory where the config file is located.
|
|
64
|
+
* @param key - The configuration key to delete.
|
|
65
|
+
*/
|
|
66
|
+
export declare const deleteDigConfigKey: (baseDir: string, key: string) => void;
|
|
67
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAKrC,eAAO,MAAM,oBAAoB,qEACmC,CAAC;AAErE,eAAO,MAAM,UAAU,UAAU,CAAC;AAClC,eAAO,MAAM,sBAAsB,qEACiC,CAAC;AAErE,eAAO,MAAM,eAAe,QACqC,CAAC;AAElE,eAAO,MAAM,UAAU,QAAuC,CAAC;AAE/D,eAAO,MAAM,aAAa,QAAkC,CAAC;AAC7D,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,MACN,CAAC;AAEjD,eAAO,MAAM,iBAAiB,YAAa,MAAM,KAAG,MACL,CAAC;AAEhD,eAAO,MAAM,mBAAmB,QAAO,IAItC,CAAC;AAEF,eAAO,MAAM,SAAS,WAAY,MAAM,KAAG,IAU1C,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,MAAM,KAAG,IAUhD,CAAC;AAqBF,eAAO,MAAM,YAAY,YACd,MAAM,KACd;IACD,QAAQ,EAAE;QACR,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CAYH,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,QAAO,MAAM,EAOtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAa,OAAO,CAAC,MAAM,GAAG,IAAI,CAkC9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,SAY/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,YAAa,MAAM,KAAG,SAmBjD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,YACjB,MAAM,OACV,MAAM,SACJ,GAAG,KACT,IAMF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,YAAa,MAAM,OAAO,MAAM,KAAG,IAcjE,CAAC"}
|
|
@@ -0,0 +1,223 @@
|
|
|
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.getManifestFilePath = exports.CONFIG_FILE_PATH = exports.USER_DIR_PATH = exports.STORE_PATH = exports.DIG_FOLDER_PATH = exports.MIN_HEIGHT_HEADER_HASH = exports.MIN_HEIGHT = 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
|
+
exports.NETWORK_AGG_SIG_DATA = "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb";
|
|
35
|
+
exports.MIN_HEIGHT = 5777842;
|
|
36
|
+
exports.MIN_HEIGHT_HEADER_HASH = "b29a4daac2434fd17a36e15ba1aac5d65012d4a66f99bed0bf2b5342e92e562c";
|
|
37
|
+
exports.DIG_FOLDER_PATH = process.env.DIG_FOLDER_PATH || path.join(process.cwd(), ".dig");
|
|
38
|
+
exports.STORE_PATH = path.join(exports.DIG_FOLDER_PATH, "stores");
|
|
39
|
+
exports.USER_DIR_PATH = path.join(os_1.default.homedir(), ".dig");
|
|
40
|
+
exports.CONFIG_FILE_PATH = path.join(exports.DIG_FOLDER_PATH, "dig.config.json");
|
|
41
|
+
const getManifestFilePath = (storeId) => path.join(exports.STORE_PATH, storeId, "manifest.dat");
|
|
42
|
+
exports.getManifestFilePath = getManifestFilePath;
|
|
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
|
+
if (!fs.existsSync(exports.CONFIG_FILE_PATH)) {
|
|
53
|
+
throw new Error("Config file not found.");
|
|
54
|
+
}
|
|
55
|
+
const config = JSON.parse(fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8"));
|
|
56
|
+
config.remote = remote;
|
|
57
|
+
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4));
|
|
58
|
+
console.log(`Remote set to ${remote}`);
|
|
59
|
+
};
|
|
60
|
+
exports.setRemote = setRemote;
|
|
61
|
+
const setActiveStore = (storeId) => {
|
|
62
|
+
if (!fs.existsSync(exports.CONFIG_FILE_PATH)) {
|
|
63
|
+
throw new Error("Config file not found.");
|
|
64
|
+
}
|
|
65
|
+
const config = JSON.parse(fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8"));
|
|
66
|
+
config.active_store = storeId;
|
|
67
|
+
fs.writeFileSync(exports.CONFIG_FILE_PATH, JSON.stringify(config, null, 4));
|
|
68
|
+
console.log(`Active Store set to ${storeId}`);
|
|
69
|
+
};
|
|
70
|
+
exports.setActiveStore = setActiveStore;
|
|
71
|
+
/**
|
|
72
|
+
* Prompts the user to select an active store from a list of folders.
|
|
73
|
+
* @param {string[]} options - The list of folder options to choose from.
|
|
74
|
+
* @returns {Promise<string>} The selected folder name.
|
|
75
|
+
*/
|
|
76
|
+
const promptUserForSelection = async (options) => {
|
|
77
|
+
const questions = [
|
|
78
|
+
{
|
|
79
|
+
type: "list",
|
|
80
|
+
name: "selectedStore",
|
|
81
|
+
message: "Select the active store:",
|
|
82
|
+
choices: options.map((option) => ({ name: option, value: option })),
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
const answer = await inquirer_1.default.prompt(questions);
|
|
86
|
+
return answer.selectedStore;
|
|
87
|
+
};
|
|
88
|
+
const getCoinState = (storeId) => {
|
|
89
|
+
const stateFile = path.join(exports.STORE_PATH, `${storeId}.json`);
|
|
90
|
+
if (!fs.existsSync(stateFile)) {
|
|
91
|
+
return {
|
|
92
|
+
metadata: { rootHash: "", bytes: "", label: "", description: "" },
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const stateContent = fs.readFileSync(stateFile, "utf-8");
|
|
96
|
+
const { latestStore } = JSON.parse(stateContent);
|
|
97
|
+
return latestStore;
|
|
98
|
+
};
|
|
99
|
+
exports.getCoinState = getCoinState;
|
|
100
|
+
/**
|
|
101
|
+
* Retrieves a list of valid store folders (64-character hexadecimal names) in the DIG folder.
|
|
102
|
+
*
|
|
103
|
+
* @returns {string[]} An array of valid folder names.
|
|
104
|
+
*/
|
|
105
|
+
const getStoresList = () => {
|
|
106
|
+
const folders = fs.readdirSync(exports.STORE_PATH);
|
|
107
|
+
return folders.filter((folder) => /^[a-f0-9]{64}$/.test(folder) &&
|
|
108
|
+
fs.lstatSync(path.join(exports.STORE_PATH, folder)).isDirectory());
|
|
109
|
+
};
|
|
110
|
+
exports.getStoresList = getStoresList;
|
|
111
|
+
/**
|
|
112
|
+
* Retrieves the active_store value from the dig.config.json file within the .dig directory.
|
|
113
|
+
* If not set, checks the subfolders and prompts the user to choose the active one if necessary.
|
|
114
|
+
*
|
|
115
|
+
* @returns {Promise<Buffer | null>} The active_store value as a Buffer if found, otherwise null.
|
|
116
|
+
*/
|
|
117
|
+
const getActiveStoreId = async () => {
|
|
118
|
+
const configFilePath = path.join(exports.DIG_FOLDER_PATH, "dig.config.json");
|
|
119
|
+
if (!fs.existsSync(configFilePath)) {
|
|
120
|
+
(0, exports.createInitialConfig)();
|
|
121
|
+
}
|
|
122
|
+
const configContent = fs.readFileSync(configFilePath, "utf-8");
|
|
123
|
+
const config = JSON.parse(configContent);
|
|
124
|
+
if (config &&
|
|
125
|
+
config.active_store &&
|
|
126
|
+
/^[a-f0-9]{64}$/.test(config.active_store)) {
|
|
127
|
+
return Buffer.from(config.active_store, "hex");
|
|
128
|
+
}
|
|
129
|
+
const validFolders = (0, exports.getStoresList)();
|
|
130
|
+
if (validFolders.length === 1 || process.env.REMOTE_NODE === "1") {
|
|
131
|
+
// If only one valid folder exists, set it as the active_store and return it
|
|
132
|
+
config.active_store = validFolders[0];
|
|
133
|
+
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 4));
|
|
134
|
+
return Buffer.from(validFolders[0], "hex");
|
|
135
|
+
}
|
|
136
|
+
else if (validFolders.length > 1) {
|
|
137
|
+
// Prompt the user to select the active store
|
|
138
|
+
const selectedStore = await promptUserForSelection(validFolders);
|
|
139
|
+
config.active_store = selectedStore;
|
|
140
|
+
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 4));
|
|
141
|
+
return Buffer.from(selectedStore, "hex");
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
};
|
|
145
|
+
exports.getActiveStoreId = getActiveStoreId;
|
|
146
|
+
/**
|
|
147
|
+
* Loads the dig.config.json file from the base directory.
|
|
148
|
+
*
|
|
149
|
+
* @param baseDir - The base directory where the config file is located.
|
|
150
|
+
* @returns {DigConfig} - The parsed configuration object.
|
|
151
|
+
* @throws Will throw an error if the config file does not exist or cannot be parsed.
|
|
152
|
+
*/
|
|
153
|
+
const loadDigConfig = (baseDir) => {
|
|
154
|
+
if (!fs.existsSync(exports.CONFIG_FILE_PATH)) {
|
|
155
|
+
throw new Error(`Configuration file not found at ${exports.CONFIG_FILE_PATH}`);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const configContent = fs.readFileSync(exports.CONFIG_FILE_PATH, "utf-8");
|
|
159
|
+
const config = JSON.parse(configContent);
|
|
160
|
+
return config;
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
throw new Error(`Failed to load configuration: ${error.message}`);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
exports.loadDigConfig = loadDigConfig;
|
|
167
|
+
/**
|
|
168
|
+
* Ensures that the dig.config.json file exists in the base directory.
|
|
169
|
+
* If the file doesn't exist, it creates it with the deploy_dir set to "./dist".
|
|
170
|
+
*
|
|
171
|
+
* @param baseDir - The base directory where the config file should be located.
|
|
172
|
+
* @returns {DigConfig} - The configuration object.
|
|
173
|
+
*/
|
|
174
|
+
const ensureDigConfig = (baseDir) => {
|
|
175
|
+
if (!fs.existsSync(exports.CONFIG_FILE_PATH)) {
|
|
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deltaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deltaUtils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,YACf,MAAM,mBACE,MAAM,6BACR,MAAM,KACpB,OAAO,CAAC,MAAM,EAAE,CAwElB,CAAC"}
|