@dignetwork/dig-sdk 0.0.1-alpha.90 → 0.0.1-alpha.94
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/dist/DigNetwork/ContentServer.d.ts +1 -1
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +34 -5
- package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
- package/dist/DigNetwork/DigPeer.js +3 -0
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.js +12 -3
- package/dist/blockchain/ServerCoin.d.ts.map +1 -1
- package/dist/blockchain/ServerCoin.js +3 -2
- package/dist/blockchain/coins.d.ts.map +1 -1
- package/dist/blockchain/coins.js +4 -3
- package/dist/utils/Environment.d.ts +18 -0
- package/dist/utils/Environment.d.ts.map +1 -0
- package/dist/utils/Environment.js +85 -0
- package/dist/utils/NconfManager.js +2 -1
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +3 -2
- package/dist/utils/network.d.ts.map +1 -1
- package/dist/utils/network.js +2 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ export declare class ContentServer {
|
|
|
8
8
|
private static readonly port;
|
|
9
9
|
constructor(ipAddress: string, storeId: string);
|
|
10
10
|
getKey(key: string, rootHash: string, challengeHex?: string): Promise<string>;
|
|
11
|
-
getPaymentAddress(): Promise<string>;
|
|
11
|
+
getPaymentAddress(): Promise<string | null>;
|
|
12
12
|
getWellKnown(): Promise<any>;
|
|
13
13
|
getKnownStores(): Promise<any>;
|
|
14
14
|
getStoresIndex(): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/ContentServer.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,q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AAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAY7C,OAAO,CAClB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAA;KAAE,CAAC;IAYvD,SAAS,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QACjE,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;KACpC,CAAC;IAUW,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUrD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;YAgDrD,IAAI;YA0EJ,SAAS;YAMT,gBAAgB;YAiChB,KAAK;CA6GpB"}
|
|
@@ -37,7 +37,7 @@ class ContentServer {
|
|
|
37
37
|
}
|
|
38
38
|
catch (error) {
|
|
39
39
|
console.error(`Failed to fetch payment address from ${this.ipAddress}: ${error.message}`);
|
|
40
|
-
|
|
40
|
+
return null;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
// Method to get the .well-known information
|
|
@@ -201,7 +201,7 @@ class ContentServer {
|
|
|
201
201
|
// Helper method to fetch content with retries and redirection handling
|
|
202
202
|
async fetchWithRetries(url) {
|
|
203
203
|
let attempt = 0;
|
|
204
|
-
const maxRetries =
|
|
204
|
+
const maxRetries = 1;
|
|
205
205
|
const initialDelay = 2000; // 2 seconds
|
|
206
206
|
const maxDelay = 10000; // 10 seconds
|
|
207
207
|
const delayMultiplier = 1.5;
|
|
@@ -225,10 +225,12 @@ class ContentServer {
|
|
|
225
225
|
}
|
|
226
226
|
throw new Error(`Failed to retrieve data from ${url} after ${maxRetries} attempts.`);
|
|
227
227
|
}
|
|
228
|
-
// Core method to fetch content from a URL
|
|
228
|
+
// Core method to fetch content from a URL with a 5-second inactivity timeout
|
|
229
229
|
async fetch(url, maxRedirects = 5) {
|
|
230
230
|
return new Promise((resolve, reject) => {
|
|
231
231
|
const urlObj = new url_1.URL(url);
|
|
232
|
+
const timeoutDuration = 5000; // 5 seconds
|
|
233
|
+
let timeout = null; // Initialize timeout
|
|
232
234
|
const requestOptions = {
|
|
233
235
|
hostname: urlObj.hostname,
|
|
234
236
|
port: urlObj.port || ContentServer.port,
|
|
@@ -240,11 +242,31 @@ class ContentServer {
|
|
|
240
242
|
};
|
|
241
243
|
const request = http_1.default.request(requestOptions, (response) => {
|
|
242
244
|
let data = "";
|
|
245
|
+
// Set timeout for inactivity
|
|
246
|
+
timeout = setTimeout(() => {
|
|
247
|
+
console.error(`Request timeout: No data received for ${timeoutDuration / 1000} seconds.`);
|
|
248
|
+
request.destroy(); // Use destroy instead of abort
|
|
249
|
+
reject(new Error(`Request timed out after ${timeoutDuration / 1000} seconds of inactivity`));
|
|
250
|
+
}, timeoutDuration);
|
|
251
|
+
const resetTimeout = () => {
|
|
252
|
+
if (timeout) {
|
|
253
|
+
clearTimeout(timeout);
|
|
254
|
+
}
|
|
255
|
+
timeout = setTimeout(() => {
|
|
256
|
+
console.error(`Request timeout: No data received for ${timeoutDuration / 1000} seconds.`);
|
|
257
|
+
request.destroy(); // Use destroy instead of abort
|
|
258
|
+
reject(new Error(`Request timed out after ${timeoutDuration / 1000} seconds of inactivity`));
|
|
259
|
+
}, timeoutDuration);
|
|
260
|
+
};
|
|
243
261
|
if (response.statusCode === 200) {
|
|
244
262
|
response.on("data", (chunk) => {
|
|
245
263
|
data += chunk;
|
|
264
|
+
resetTimeout(); // Reset the timeout every time data is received
|
|
246
265
|
});
|
|
247
266
|
response.on("end", () => {
|
|
267
|
+
if (timeout) {
|
|
268
|
+
clearTimeout(timeout);
|
|
269
|
+
}
|
|
248
270
|
resolve(data);
|
|
249
271
|
});
|
|
250
272
|
}
|
|
@@ -253,8 +275,9 @@ class ContentServer {
|
|
|
253
275
|
// Handle redirects
|
|
254
276
|
if (maxRedirects > 0) {
|
|
255
277
|
const redirectUrl = new url_1.URL(response.headers.location, url); // Resolve relative URLs based on the original URL
|
|
256
|
-
|
|
257
|
-
|
|
278
|
+
if (timeout) {
|
|
279
|
+
clearTimeout(timeout);
|
|
280
|
+
}
|
|
258
281
|
this.fetch(redirectUrl.toString(), maxRedirects - 1)
|
|
259
282
|
.then(resolve)
|
|
260
283
|
.catch(reject);
|
|
@@ -264,10 +287,16 @@ class ContentServer {
|
|
|
264
287
|
}
|
|
265
288
|
}
|
|
266
289
|
else {
|
|
290
|
+
if (timeout) {
|
|
291
|
+
clearTimeout(timeout);
|
|
292
|
+
}
|
|
267
293
|
reject(new Error(`Failed to retrieve data from ${url}. Status code: ${response.statusCode}`));
|
|
268
294
|
}
|
|
269
295
|
});
|
|
270
296
|
request.on("error", (error) => {
|
|
297
|
+
if (timeout) {
|
|
298
|
+
clearTimeout(timeout);
|
|
299
|
+
}
|
|
271
300
|
console.error(`GET ${url}:`, error.message);
|
|
272
301
|
reject(error);
|
|
273
302
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DigPeer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigPeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAKpD,OAAO,EAKL,MAAM,EACP,MAAM,8BAA8B,CAAC;AAKtC,qBAAa,OAAO;IAClB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,gBAAgB,CAAkB;gBAE9B,S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I,MAAM,CAE7B;WAEa,qBAAqB,CACjC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EAAE,EACnB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,IAAI,CAAC;WAuBI,gBAAgB,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,IAAI,CAAC;IAwCH,WAAW,CACtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAAM,EAAO,GACnB,OAAO,CAAC,IAAI,CAAC;WAiBF,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAqBlC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAc1B,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOhE"}
|
|
@@ -70,6 +70,9 @@ class DigPeer {
|
|
|
70
70
|
}
|
|
71
71
|
async sendPayment(walletName, amount, memos = []) {
|
|
72
72
|
const paymentAddress = await this.contentServer.getPaymentAddress();
|
|
73
|
+
if (!paymentAddress) {
|
|
74
|
+
throw new Error("Payment address not found.");
|
|
75
|
+
}
|
|
73
76
|
const paymentAddressPuzzleHash = (0, datalayer_driver_1.addressToPuzzleHash)(paymentAddress);
|
|
74
77
|
const output = {
|
|
75
78
|
puzzleHash: paymentAddressPuzzleHash,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAqBpD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAkD;IAC3E,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAA0B;IAChE,OAAO,CAAC,IAAI,CAAO;IACnB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA0B;IAMzD,OAAO;WAIa,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5C,OAAO,CAAC,MAAM,CAAC,eAAe;IAiB9B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAM/B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;mBASZ,eAAe;mBA2Df,UAAU;IA2B/B,OAAO,CAAC,MAAM,CAAC,eAAe;mBAkDT,WAAW;IAuGzB,OAAO,IAAI,IAAI;WAIF,mBAAmB,CACrC,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC;CAwBpB"}
|
|
@@ -14,6 +14,7 @@ const net_1 = __importDefault(require("net"));
|
|
|
14
14
|
const lodash_1 = require("lodash");
|
|
15
15
|
const nanospinner_1 = require("nanospinner");
|
|
16
16
|
const config_1 = require("../utils/config");
|
|
17
|
+
const Environment_1 = require("../utils/Environment");
|
|
17
18
|
const FULLNODE_PORT = 8444;
|
|
18
19
|
const LOCALHOST = "127.0.0.1";
|
|
19
20
|
const CHIA_NODES_HOST = "chia-nodes";
|
|
@@ -56,7 +57,7 @@ class FullNodePeer {
|
|
|
56
57
|
* @returns {string | null} The valid IP address or null if invalid
|
|
57
58
|
*/
|
|
58
59
|
static getTrustedFullNode() {
|
|
59
|
-
const trustedNodeIp =
|
|
60
|
+
const trustedNodeIp = Environment_1.Environment.TRUSTED_FULLNODE || null;
|
|
60
61
|
if (trustedNodeIp && FullNodePeer.isValidIpAddress(trustedNodeIp)) {
|
|
61
62
|
return trustedNodeIp;
|
|
62
63
|
}
|
|
@@ -188,11 +189,19 @@ class FullNodePeer {
|
|
|
188
189
|
}
|
|
189
190
|
new chia_server_coin_1.Tls(certFile, keyFile);
|
|
190
191
|
const peerIPs = await FullNodePeer.getPeerIPs();
|
|
191
|
-
const trustedNodeIp =
|
|
192
|
+
const trustedNodeIp = Environment_1.Environment.TRUSTED_FULLNODE || null;
|
|
192
193
|
const peers = await Promise.all(peerIPs.map(async (ip) => {
|
|
193
194
|
if (ip) {
|
|
195
|
+
// Allow override of the trusted fullnode port if the override exists
|
|
196
|
+
let port = FULLNODE_PORT;
|
|
197
|
+
if (trustedNodeIp && ip === trustedNodeIp) {
|
|
198
|
+
const trustedFullNodePort = Environment_1.Environment.TRUSTED_FULLNODE_PORT;
|
|
199
|
+
if (trustedFullNodePort) {
|
|
200
|
+
port = trustedFullNodePort;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
194
203
|
try {
|
|
195
|
-
const peer = await datalayer_driver_1.Peer.new(`${ip}:${
|
|
204
|
+
const peer = await datalayer_driver_1.Peer.new(`${ip}:${port}`, false, certFile, keyFile);
|
|
196
205
|
return FullNodePeer.createPeerProxy(peer);
|
|
197
206
|
}
|
|
198
207
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerCoin.d.ts","sourceRoot":"","sources":["../../src/blockchain/ServerCoin.ts"],"names":[],"mappings":"AACA,OAAO,EAML,UAAU,IAAI,gBAAgB,EAE/B,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"ServerCoin.d.ts","sourceRoot":"","sources":["../../src/blockchain/ServerCoin.ts"],"names":[],"mappings":"AACA,OAAO,EAML,UAAU,IAAI,gBAAgB,EAE/B,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAYrD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,gBAAuB,iBAAiB,eAEtC;gBAEU,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 @@ const NconfManager_1 = require("../utils/NconfManager");
|
|
|
13
13
|
const DataStore_1 = require("./DataStore");
|
|
14
14
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
15
15
|
const network_1 = require("../utils/network");
|
|
16
|
+
const Environment_1 = require("../utils/Environment");
|
|
16
17
|
const serverCoinCollateral = 300000000;
|
|
17
18
|
// Initialize the cache with a TTL of 300 seconds (5 minutes)
|
|
18
19
|
const serverCoinPeersCache = new node_cache_1.default({ stdTTL: 300 });
|
|
@@ -119,7 +120,7 @@ class ServerCoin {
|
|
|
119
120
|
serverCoinPeers.add(peerUrl);
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
|
-
if (
|
|
123
|
+
if (Environment_1.Environment.DEBUG) {
|
|
123
124
|
console.log("Server Coin Peers: ", serverCoinPeers);
|
|
124
125
|
}
|
|
125
126
|
const peerList = Array.from(serverCoinPeers);
|
|
@@ -144,7 +145,7 @@ class ServerCoin {
|
|
|
144
145
|
blacklist.push(myIp);
|
|
145
146
|
}
|
|
146
147
|
const serverCoinPeers = await this.getAllEpochPeers(epoch, blacklist);
|
|
147
|
-
if (
|
|
148
|
+
if (Environment_1.Environment.DEBUG) {
|
|
148
149
|
console.log("Server Coin Peers: ", serverCoinPeers);
|
|
149
150
|
}
|
|
150
151
|
return lodash_1.default.sampleSize(serverCoinPeers, sampleSize);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coins.d.ts","sourceRoot":"","sources":["../../src/blockchain/coins.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"coins.d.ts","sourceRoot":"","sources":["../../src/blockchain/coins.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,8BAA8B,CAAC;AAMtC,eAAO,MAAM,qBAAqB,WAAa,CAAC;AAWhD,eAAO,MAAM,yBAAyB,SAC9B,IAAI,cACE,SAAS,EAAE,GAAG,IAAI,KAC7B,OAAO,CAAC,MAAM,CA4BhB,CAAC;AAEF,eAAO,MAAM,kBAAkB,SACvB,IAAI,cACE,MAAM,aACP,MAAM,cACN,IAAI,EAAE,eACL,MAAM,KACjB,OAAO,CAAC,IAAI,EAAE,CAoEhB,CAAC;AAGF,eAAO,MAAM,eAAe,SACpB,IAAI,UACF,MAAM,KACb,OAAO,CAAC,OAAO,CAWjB,CAAC"}
|
package/dist/blockchain/coins.js
CHANGED
|
@@ -5,6 +5,7 @@ const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
|
5
5
|
const Wallet_1 = require("./Wallet");
|
|
6
6
|
const config_1 = require("../utils/config");
|
|
7
7
|
const FileCache_1 = require("../utils/FileCache");
|
|
8
|
+
const Environment_1 = require("../utils/Environment");
|
|
8
9
|
exports.DEFAULT_FEE_COIN_COST = 64000000;
|
|
9
10
|
// Set cache expiration time (5 minutes)
|
|
10
11
|
const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes in milliseconds
|
|
@@ -63,18 +64,18 @@ const selectUnspentCoins = async (peer, coinAmount, feeBigInt, omitCoins = [], w
|
|
|
63
64
|
const wallet = await Wallet_1.Wallet.load(walletName);
|
|
64
65
|
const ownerPuzzleHash = await wallet.getOwnerPuzzleHash();
|
|
65
66
|
const coinsResp = await peer.getAllUnspentCoins(ownerPuzzleHash, config_1.MIN_HEIGHT, Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
|
|
66
|
-
if (
|
|
67
|
+
if (Environment_1.Environment.DEBUG) {
|
|
67
68
|
console.log("Unspent Coins:", coinsResp); // Debugging
|
|
68
69
|
}
|
|
69
70
|
const unspentCoins = coinsResp.coins;
|
|
70
71
|
// Filter out the omitted coins
|
|
71
72
|
const filteredUnspentCoins = unspentCoins.filter((coin) => !omitCoinIds.includes((0, datalayer_driver_1.getCoinId)(coin).toString("hex")));
|
|
72
|
-
if (
|
|
73
|
+
if (Environment_1.Environment.DEBUG) {
|
|
73
74
|
console.log("Unspent Coins after filtering:", filteredUnspentCoins); // Debugging
|
|
74
75
|
}
|
|
75
76
|
// Select coins needed for the transaction
|
|
76
77
|
const selectedCoins = (0, datalayer_driver_1.selectCoins)(filteredUnspentCoins, feeBigInt + coinAmount);
|
|
77
|
-
if (
|
|
78
|
+
if (Environment_1.Environment.DEBUG) {
|
|
78
79
|
console.log("Selected Coins:", selectedCoins); // Debugging
|
|
79
80
|
}
|
|
80
81
|
// If no coins are selected, throw an error
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class Environment {
|
|
2
|
+
private static isValidIp;
|
|
3
|
+
private static isValidHostnameOrIp;
|
|
4
|
+
private static isValidPort;
|
|
5
|
+
private static isValidFilePath;
|
|
6
|
+
private static getNumberEnvVar;
|
|
7
|
+
static get DIG_USERNAME(): string | undefined;
|
|
8
|
+
static get DIG_PASSWORD(): string | undefined;
|
|
9
|
+
static get TRUSTED_FULLNODE(): string | undefined;
|
|
10
|
+
static get TRUSTED_FULLNODE_PORT(): number | undefined;
|
|
11
|
+
static get PUBLIC_IP(): string | undefined;
|
|
12
|
+
static get DISK_SPACE_LIMIT_BYTES(): number | undefined;
|
|
13
|
+
static get MERCENARY_MODE(): boolean | undefined;
|
|
14
|
+
static get DEBUG(): boolean | undefined;
|
|
15
|
+
static get DIG_FOLDER_PATH(): string | undefined;
|
|
16
|
+
static get REMOTE_NODE(): boolean | undefined;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=Environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Environment.d.ts","sourceRoot":"","sources":["../../src/utils/Environment.ts"],"names":[],"mappings":"AAGA,qBAAa,WAAW;IAEtB,OAAO,CAAC,MAAM,CAAC,SAAS;IAOxB,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAQlC,OAAO,CAAC,MAAM,CAAC,WAAW;IAK1B,OAAO,CAAC,MAAM,CAAC,eAAe;IAK9B,OAAO,CAAC,MAAM,CAAC,eAAe;IAO9B,MAAM,KAAK,YAAY,IAAI,MAAM,GAAG,SAAS,CAG5C;IAGD,MAAM,KAAK,YAAY,IAAI,MAAM,GAAG,SAAS,CAG5C;IAGD,MAAM,KAAK,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAGhD;IAGD,MAAM,KAAK,qBAAqB,IAAI,MAAM,GAAG,SAAS,CAGrD;IAGD,MAAM,KAAK,SAAS,IAAI,MAAM,GAAG,SAAS,CAGzC;IAGD,MAAM,KAAK,sBAAsB,IAAI,MAAM,GAAG,SAAS,CAEtD;IAGD,MAAM,KAAK,cAAc,IAAI,OAAO,GAAG,SAAS,CAG/C;IAGD,MAAM,KAAK,KAAK,IAAI,OAAO,GAAG,SAAS,CAGtC;IAGD,MAAM,KAAK,eAAe,IAAI,MAAM,GAAG,SAAS,CAG/C;IAGD,MAAM,KAAK,WAAW,IAAI,OAAO,GAAG,SAAS,CAG5C;CACF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
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.Environment = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
class Environment {
|
|
10
|
+
// Helper to validate if a string is a valid IP address (IPv4)
|
|
11
|
+
static isValidIp(ip) {
|
|
12
|
+
const ipPattern = /^(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]?)$/;
|
|
13
|
+
return ipPattern.test(ip);
|
|
14
|
+
}
|
|
15
|
+
// Helper to validate if a string is a valid hostname or IP address
|
|
16
|
+
static isValidHostnameOrIp(hostname) {
|
|
17
|
+
// Hostname regex (simple, allows subdomains but not special characters)
|
|
18
|
+
const hostnamePattern = /^(([a-zA-Z0-9](-*[a-zA-Z0-9])*)\.)*([a-zA-Z0-9](-*[a-zA-Z0-9])*)\.?$/;
|
|
19
|
+
return this.isValidIp(hostname) || hostnamePattern.test(hostname);
|
|
20
|
+
}
|
|
21
|
+
// Helper to validate if a number is a valid port (between 1 and 65535)
|
|
22
|
+
static isValidPort(port) {
|
|
23
|
+
return port > 0 && port <= 65535;
|
|
24
|
+
}
|
|
25
|
+
// Helper to validate if a string is a valid file path
|
|
26
|
+
static isValidFilePath(filePath) {
|
|
27
|
+
return fs_1.default.existsSync(filePath) && path_1.default.isAbsolute(filePath);
|
|
28
|
+
}
|
|
29
|
+
// Helper to get and validate number env variables
|
|
30
|
+
static getNumberEnvVar(envVar) {
|
|
31
|
+
const value = process.env[envVar];
|
|
32
|
+
const parsedValue = Number(value);
|
|
33
|
+
return !isNaN(parsedValue) ? parsedValue : undefined;
|
|
34
|
+
}
|
|
35
|
+
// Static getter for DIG_USERNAME (string, non-empty)
|
|
36
|
+
static get DIG_USERNAME() {
|
|
37
|
+
const value = process.env["DIG_USERNAME"];
|
|
38
|
+
return value && value.trim().length > 0 ? value : undefined;
|
|
39
|
+
}
|
|
40
|
+
// Static getter for DIG_PASSWORD (string, non-empty)
|
|
41
|
+
static get DIG_PASSWORD() {
|
|
42
|
+
const value = process.env["DIG_PASSWORD"];
|
|
43
|
+
return value && value.trim().length > 0 ? value : undefined;
|
|
44
|
+
}
|
|
45
|
+
// Static getter for TRUSTED_FULLNODE (valid IP or hostname)
|
|
46
|
+
static get TRUSTED_FULLNODE() {
|
|
47
|
+
const value = process.env["TRUSTED_FULLNODE"];
|
|
48
|
+
return value && this.isValidHostnameOrIp(value) ? value : undefined;
|
|
49
|
+
}
|
|
50
|
+
// Static getter for TRUSTED_FULLNODE_PORT (valid port)
|
|
51
|
+
static get TRUSTED_FULLNODE_PORT() {
|
|
52
|
+
const port = this.getNumberEnvVar("TRUSTED_FULLNODE_PORT");
|
|
53
|
+
return port && this.isValidPort(port) ? port : undefined;
|
|
54
|
+
}
|
|
55
|
+
// Static getter for PUBLIC_IP (valid IP)
|
|
56
|
+
static get PUBLIC_IP() {
|
|
57
|
+
const value = process.env["PUBLIC_IP"];
|
|
58
|
+
return value && this.isValidIp(value) ? value : undefined;
|
|
59
|
+
}
|
|
60
|
+
// Static getter for DISK_SPACE_LIMIT_BYTES (number, optional)
|
|
61
|
+
static get DISK_SPACE_LIMIT_BYTES() {
|
|
62
|
+
return this.getNumberEnvVar("DISK_SPACE_LIMIT_BYTES");
|
|
63
|
+
}
|
|
64
|
+
// Static getter for MERCENARY_MODE (boolean: "true" or "false")
|
|
65
|
+
static get MERCENARY_MODE() {
|
|
66
|
+
const value = process.env["MERCENARY_MODE"];
|
|
67
|
+
return value === "true" ? true : value === "false" ? false : undefined;
|
|
68
|
+
}
|
|
69
|
+
// Static getter for MERCENARY_MODE (boolean: "true" or "false")
|
|
70
|
+
static get DEBUG() {
|
|
71
|
+
const value = process.env["DIG_DEBUG"];
|
|
72
|
+
return value === "true" ? true : value === "false" ? false : undefined;
|
|
73
|
+
}
|
|
74
|
+
// Static getter for DIG_FOLDER_PATH (valid file path)
|
|
75
|
+
static get DIG_FOLDER_PATH() {
|
|
76
|
+
const value = process.env["DIG_FOLDER_PATH"];
|
|
77
|
+
return value && this.isValidFilePath(value) ? value : undefined;
|
|
78
|
+
}
|
|
79
|
+
// Static getter for REMOTE_NODE (boolean: "1" or "0", mapped to true/false)
|
|
80
|
+
static get REMOTE_NODE() {
|
|
81
|
+
const value = process.env["REMOTE_NODE"];
|
|
82
|
+
return value === "1" ? true : value === "0" ? false : undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.Environment = Environment;
|
|
@@ -8,7 +8,8 @@ const nconf_1 = __importDefault(require("nconf"));
|
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const config_1 = require("./config");
|
|
11
|
-
const
|
|
11
|
+
const Environment_1 = require("./Environment");
|
|
12
|
+
const CONF_FOLDER_PATH = Environment_1.Environment.DIG_FOLDER_PATH || config_1.USER_DIR_PATH;
|
|
12
13
|
class NconfManager {
|
|
13
14
|
constructor(relativePath) {
|
|
14
15
|
this.configFilePath = path_1.default.join(CONF_FOLDER_PATH, relativePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAMrC,eAAO,MAAM,oBAAoB,qEACmC,CAAC;AAErE,eAAO,MAAM,0BAA0B,qEAAuB,CAAC;AAE/D,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,iBAAiB,YAAa,MAAM,KAAG,MACL,CAAC;AAEhD,eAAO,MAAM,mBAAmB,QAAO,IAItC,CAAC;AAEF,eAAO,MAAM,SAAS,WAAY,MAAM,KAAG,IAQ1C,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,MAAM,KAAG,IAQhD,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;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAAO,MAAM,EAYtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAa,OAAO,CAAC,MAAM,GAAG,IAAI,CAkC9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,SAS/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,YAAa,MAAM,KAAG,SAoBjD,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"}
|
package/dist/utils/config.js
CHANGED
|
@@ -31,11 +31,12 @@ const fs = __importStar(require("fs"));
|
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
32
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
33
33
|
const os_1 = __importDefault(require("os"));
|
|
34
|
+
const Environment_1 = require("./Environment");
|
|
34
35
|
exports.NETWORK_AGG_SIG_DATA = "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb";
|
|
35
36
|
exports.MAIN_NET_GENISES_CHALLENGE = exports.NETWORK_AGG_SIG_DATA;
|
|
36
37
|
exports.MIN_HEIGHT = 5777842;
|
|
37
38
|
exports.MIN_HEIGHT_HEADER_HASH = "b29a4daac2434fd17a36e15ba1aac5d65012d4a66f99bed0bf2b5342e92e562c";
|
|
38
|
-
exports.DIG_FOLDER_PATH =
|
|
39
|
+
exports.DIG_FOLDER_PATH = Environment_1.Environment.DIG_FOLDER_PATH || path.join(process.cwd(), ".dig");
|
|
39
40
|
exports.STORE_PATH = path.join(exports.DIG_FOLDER_PATH, "stores");
|
|
40
41
|
exports.USER_DIR_PATH = path.join(os_1.default.homedir(), ".dig");
|
|
41
42
|
exports.CONFIG_FILE_PATH = path.join(exports.DIG_FOLDER_PATH, "dig.config.json");
|
|
@@ -127,7 +128,7 @@ const getActiveStoreId = async () => {
|
|
|
127
128
|
return Buffer.from(config.active_store, "hex");
|
|
128
129
|
}
|
|
129
130
|
const validFolders = (0, exports.getStoresList)();
|
|
130
|
-
if (validFolders.length === 1 ||
|
|
131
|
+
if (validFolders.length === 1 || Environment_1.Environment.REMOTE_NODE) {
|
|
131
132
|
// If only one valid folder exists, set it as the active_store and return it
|
|
132
133
|
config.active_store = validFolders[0];
|
|
133
134
|
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 4));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA6CrE,CAAC"}
|
package/dist/utils/network.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.getPublicIpAddress = void 0;
|
|
|
8
8
|
* Stopgap until better solution for finding public IPS found
|
|
9
9
|
*/
|
|
10
10
|
const superagent_1 = __importDefault(require("superagent"));
|
|
11
|
+
const Environment_1 = require("./Environment");
|
|
11
12
|
const MAX_RETRIES = 5;
|
|
12
13
|
const RETRY_DELAY = 2000; // in milliseconds
|
|
13
14
|
// Regular expression for validating both IPv4 and IPv6 addresses
|
|
@@ -18,7 +19,7 @@ const isValidIp = (ip) => {
|
|
|
18
19
|
return ipv4Regex.test(ip) || ipv6Regex.test(ip);
|
|
19
20
|
};
|
|
20
21
|
const getPublicIpAddress = async () => {
|
|
21
|
-
const publicIp =
|
|
22
|
+
const publicIp = Environment_1.Environment.PUBLIC_IP;
|
|
22
23
|
if (publicIp) {
|
|
23
24
|
console.log("Public IP address from env:", publicIp);
|
|
24
25
|
if (isValidIp(publicIp)) {
|