@dignetwork/dig-sdk 0.0.1-alpha.101 → 0.0.1-alpha.103
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.map +1 -1
- package/dist/DigNetwork/ContentServer.js +9 -8
- package/dist/DigNetwork/IncentiveServer.d.ts.map +1 -1
- package/dist/DigNetwork/IncentiveServer.js +6 -5
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
- package/dist/DigNetwork/PropagationServer.js +9 -8
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.js +7 -5
- package/dist/utils/network.d.ts +1 -0
- package/dist/utils/network.d.ts.map +1 -1
- package/dist/utils/network.js +12 -1
- package/dist/utils/ssl.js +2 -2
- package/package.json +2 -3
|
@@ -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;
|
|
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;AAIlC,qBAAa,aAAa;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;gBAExB,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAYjC,MAAM,CACjB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC;IAaL,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAe3C,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC;IAM5B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,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"}
|
|
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const http_1 = __importDefault(require("http"));
|
|
9
9
|
const url_1 = require("url");
|
|
10
10
|
const ssl_1 = require("../utils/ssl");
|
|
11
|
+
const network_1 = require("../utils/network");
|
|
11
12
|
class ContentServer {
|
|
12
13
|
constructor(ipAddress, storeId) {
|
|
13
14
|
this.ipAddress = ipAddress;
|
|
@@ -21,7 +22,7 @@ class ContentServer {
|
|
|
21
22
|
// Method to get the content of a specified key from the peer, with optional challenge query
|
|
22
23
|
async getKey(key, rootHash, challengeHex) {
|
|
23
24
|
// Construct the base URL
|
|
24
|
-
let url = `https://${this.ipAddress}:${ContentServer.port}/chia.${this.storeId}.${rootHash}/${key}`;
|
|
25
|
+
let url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/chia.${this.storeId}.${rootHash}/${key}`;
|
|
25
26
|
// If a challenge is provided, append it as a query parameter
|
|
26
27
|
if (challengeHex) {
|
|
27
28
|
url += `?challenge=${challengeHex}`;
|
|
@@ -42,17 +43,17 @@ class ContentServer {
|
|
|
42
43
|
}
|
|
43
44
|
// Method to get the .well-known information
|
|
44
45
|
async getWellKnown() {
|
|
45
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/.well-known`;
|
|
46
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/.well-known`;
|
|
46
47
|
return this.fetchJson(url);
|
|
47
48
|
}
|
|
48
49
|
// Method to get the list of known stores
|
|
49
50
|
async getKnownStores() {
|
|
50
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/.well-known/stores`;
|
|
51
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/.well-known/stores`;
|
|
51
52
|
return this.fetchJson(url);
|
|
52
53
|
}
|
|
53
54
|
// Method to get the index of all stores
|
|
54
55
|
async getStoresIndex() {
|
|
55
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/`;
|
|
56
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/`;
|
|
56
57
|
return this.fetchJson(url);
|
|
57
58
|
}
|
|
58
59
|
// Method to get the index of keys in a store
|
|
@@ -61,7 +62,7 @@ class ContentServer {
|
|
|
61
62
|
if (rootHash) {
|
|
62
63
|
udi += `.${rootHash}`;
|
|
63
64
|
}
|
|
64
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/${udi}`;
|
|
65
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}`;
|
|
65
66
|
return this.fetchJson(url);
|
|
66
67
|
}
|
|
67
68
|
// Method to check if a specific key exists (HEAD request)
|
|
@@ -70,12 +71,12 @@ class ContentServer {
|
|
|
70
71
|
if (rootHash) {
|
|
71
72
|
udi += `.${rootHash}`;
|
|
72
73
|
}
|
|
73
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/${udi}/${key}`;
|
|
74
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}/${key}`;
|
|
74
75
|
return this.head(url);
|
|
75
76
|
}
|
|
76
77
|
// Method to check if a specific store exists (HEAD request)
|
|
77
78
|
async headStore(options) {
|
|
78
|
-
let url = `https://${this.ipAddress}:${ContentServer.port}/chia.${this.storeId}`;
|
|
79
|
+
let url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/chia.${this.storeId}`;
|
|
79
80
|
if (options?.hasRootHash) {
|
|
80
81
|
url += `?hasRootHash=${options.hasRootHash}`;
|
|
81
82
|
}
|
|
@@ -96,7 +97,7 @@ class ContentServer {
|
|
|
96
97
|
udi += `.${rootHash}`;
|
|
97
98
|
}
|
|
98
99
|
return new Promise((resolve, reject) => {
|
|
99
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/${udi}/${key}`;
|
|
100
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}/${key}`;
|
|
100
101
|
const urlObj = new url_1.URL(url);
|
|
101
102
|
const requestOptions = {
|
|
102
103
|
hostname: urlObj.hostname,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncentiveServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/IncentiveServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"IncentiveServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/IncentiveServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGhD,qBAAa,eAAe;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,IAAI,CAAgB;gBAEhB,SAAS,EAAE,MAAM;IAKhB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtD,uBAAuB,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAO1D,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAOlE,WAAW;CA6C1B"}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.IncentiveServer = void 0;
|
|
7
7
|
const https_1 = __importDefault(require("https"));
|
|
8
8
|
const url_1 = require("url");
|
|
9
|
+
const network_1 = require("../utils/network");
|
|
9
10
|
class IncentiveServer {
|
|
10
11
|
constructor(ipAddress) {
|
|
11
12
|
this.port = 4160;
|
|
@@ -13,27 +14,27 @@ class IncentiveServer {
|
|
|
13
14
|
}
|
|
14
15
|
// Method to create a new incentive program
|
|
15
16
|
async createIncentiveProgram(data) {
|
|
16
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
17
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive`;
|
|
17
18
|
await this.makeRequest(url, "POST", data);
|
|
18
19
|
}
|
|
19
20
|
// Method to update an existing incentive program
|
|
20
21
|
async updateIncentiveProgram(data) {
|
|
21
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
22
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive`;
|
|
22
23
|
await this.makeRequest(url, "PUT", data);
|
|
23
24
|
}
|
|
24
25
|
// Method to delete an incentive program by storeId
|
|
25
26
|
async deleteIncentiveProgram(storeId) {
|
|
26
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
27
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive`;
|
|
27
28
|
await this.makeRequest(url, "DELETE", { storeId });
|
|
28
29
|
}
|
|
29
30
|
// Method to get all incentive programs
|
|
30
31
|
async getAllIncentivePrograms() {
|
|
31
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
32
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive`;
|
|
32
33
|
return this.makeRequest(url, "GET");
|
|
33
34
|
}
|
|
34
35
|
// Method to get a specific incentive program by storeId
|
|
35
36
|
async getIncentiveProgram(storeId) {
|
|
36
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive/${storeId}`;
|
|
37
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive/${storeId}`;
|
|
37
38
|
return this.makeRequest(url, "GET");
|
|
38
39
|
}
|
|
39
40
|
// Helper method to handle the HTTPS request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAkBrC,qBAAa,iBAAiB;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;gBAErC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAY9C;;OAEG;IACG,gBAAgB;IAOtB;;OAEG;IACH,gBAAgB;IAQhB;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM;IAyB3D;;OAEG;IACG,gBAAgB,CACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IA0C7D;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAuDzC;;OAEG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IAyBlD;;;OAGG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAuGhD;;OAEG;IACG,mBAAmB;IAgCzB;;OAEG;WACU,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IA2DnB;;;OAGG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgFlD;;OAEG;IACG,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA0B7C;;;OAGG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM;IAwGjB;;OAEG;WACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CA2FpB"}
|
|
@@ -23,6 +23,7 @@ const stream_1 = require("stream");
|
|
|
23
23
|
const credentialsUtils_1 = require("../utils/credentialsUtils");
|
|
24
24
|
const config_1 = require("../utils/config");
|
|
25
25
|
const blockchain_1 = require("../blockchain");
|
|
26
|
+
const network_1 = require("../utils/network");
|
|
26
27
|
// Helper function to trim long filenames with ellipsis and ensure consistent padding
|
|
27
28
|
function formatFilename(filename, maxLength = 30) {
|
|
28
29
|
if (!filename) {
|
|
@@ -90,7 +91,7 @@ class PropagationServer {
|
|
|
90
91
|
const config = {
|
|
91
92
|
httpsAgent: this.createHttpsAgent(),
|
|
92
93
|
};
|
|
93
|
-
let url = `https://${this.ipAddress}:${PropagationServer.port}/${this.storeId}`;
|
|
94
|
+
let url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/${this.storeId}`;
|
|
94
95
|
if (rootHash) {
|
|
95
96
|
url += `?hasRootHash=${rootHash}`;
|
|
96
97
|
}
|
|
@@ -144,7 +145,7 @@ class PropagationServer {
|
|
|
144
145
|
password: this.password,
|
|
145
146
|
};
|
|
146
147
|
}
|
|
147
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}?roothash=${rootHash}`;
|
|
148
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/upload/${this.storeId}?roothash=${rootHash}`;
|
|
148
149
|
const response = await axios_1.default.post(url, formData, config);
|
|
149
150
|
this.sessionId = response.data.sessionId;
|
|
150
151
|
spinner.success({
|
|
@@ -165,7 +166,7 @@ class PropagationServer {
|
|
|
165
166
|
const config = {
|
|
166
167
|
httpsAgent: this.createHttpsAgent(),
|
|
167
168
|
};
|
|
168
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
|
|
169
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
|
|
169
170
|
const response = await axios_1.default.head(url, config);
|
|
170
171
|
// Check for 'x-file-exists' header
|
|
171
172
|
const fileExists = response.headers["x-file-exists"] === "true";
|
|
@@ -239,7 +240,7 @@ class PropagationServer {
|
|
|
239
240
|
maxContentLength: Infinity,
|
|
240
241
|
maxBodyLength: Infinity,
|
|
241
242
|
};
|
|
242
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${dataPath}`;
|
|
243
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${dataPath}`;
|
|
243
244
|
// Create a promise that resolves when the progress stream ends
|
|
244
245
|
const progressPromise = new Promise((resolve, reject) => {
|
|
245
246
|
progressStream.on("end", resolve);
|
|
@@ -274,7 +275,7 @@ class PropagationServer {
|
|
|
274
275
|
}
|
|
275
276
|
: undefined,
|
|
276
277
|
};
|
|
277
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/commit/${this.storeId}/${this.sessionId}`;
|
|
278
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/commit/${this.storeId}/${this.sessionId}`;
|
|
278
279
|
const response = await axios_1.default.post(url, {}, config);
|
|
279
280
|
spinner.success({
|
|
280
281
|
text: (0, colorette_1.green)(`Upload session ${this.sessionId} successfully committed.`),
|
|
@@ -330,7 +331,7 @@ class PropagationServer {
|
|
|
330
331
|
* Logs progress using a local cli-progress bar.
|
|
331
332
|
*/
|
|
332
333
|
async fetchFile(dataPath) {
|
|
333
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
|
|
334
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
|
|
334
335
|
const config = {
|
|
335
336
|
responseType: "stream",
|
|
336
337
|
httpsAgent: this.createHttpsAgent(),
|
|
@@ -397,7 +398,7 @@ class PropagationServer {
|
|
|
397
398
|
const config = {
|
|
398
399
|
httpsAgent: this.createHttpsAgent(),
|
|
399
400
|
};
|
|
400
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/store/${this.storeId}/${rootHash}/${dataPath}`;
|
|
401
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/store/${this.storeId}/${rootHash}/${dataPath}`;
|
|
401
402
|
const response = await axios_1.default.head(url, config);
|
|
402
403
|
// Check the headers for file existence and size
|
|
403
404
|
const fileExists = response.headers["x-file-exists"] === "true";
|
|
@@ -417,7 +418,7 @@ class PropagationServer {
|
|
|
417
418
|
* Logs progress using a local cli-progress bar.
|
|
418
419
|
*/
|
|
419
420
|
async downloadFile(label, dataPath, rootHash, baseDir) {
|
|
420
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
|
|
421
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
|
|
421
422
|
let downloadPath = path_1.default.join(baseDir, dataPath);
|
|
422
423
|
// Ensure that the directory for the file exists
|
|
423
424
|
fs_1.default.mkdirSync(path_1.default.dirname(downloadPath), { recursive: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAO,MAAM,8BAA8B,CAAC;AAoBzD,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;IAQzD,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;mBA6Df,UAAU;IA2B/B,OAAO,CAAC,MAAM,CAAC,eAAe;mBAyDT,WAAW;IAsGzB,OAAO,IAAI,IAAI;WAIF,mBAAmB,CACrC,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC;CAwBpB"}
|
|
@@ -8,7 +8,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
11
|
-
const chia_server_coin_1 = require("chia-server-coin");
|
|
12
11
|
const promises_1 = require("dns/promises");
|
|
13
12
|
const net_1 = __importDefault(require("net"));
|
|
14
13
|
const lodash_1 = require("lodash");
|
|
@@ -158,7 +157,8 @@ class FullNodePeer {
|
|
|
158
157
|
}
|
|
159
158
|
catch (error) {
|
|
160
159
|
// If the error is WebSocket-related or timeout, reset the peer
|
|
161
|
-
if (error.message.includes("WebSocket") ||
|
|
160
|
+
if (error.message.includes("WebSocket") ||
|
|
161
|
+
error.message.includes("Operation timed out")) {
|
|
162
162
|
FullNodePeer.cachedPeer = null;
|
|
163
163
|
// @ts-ignore
|
|
164
164
|
FullNodePeer.memoizedFetchNewPeerIPs.cache.clear();
|
|
@@ -187,7 +187,7 @@ class FullNodePeer {
|
|
|
187
187
|
if (!fs_1.default.existsSync(sslFolder)) {
|
|
188
188
|
fs_1.default.mkdirSync(sslFolder, { recursive: true });
|
|
189
189
|
}
|
|
190
|
-
new
|
|
190
|
+
const tls = new datalayer_driver_1.Tls(certFile, keyFile);
|
|
191
191
|
const peerIPs = await FullNodePeer.getPeerIPs();
|
|
192
192
|
const trustedNodeIp = Environment_1.Environment.TRUSTED_FULLNODE || null;
|
|
193
193
|
const peers = await Promise.all(peerIPs.map(async (ip) => {
|
|
@@ -201,7 +201,7 @@ class FullNodePeer {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
try {
|
|
204
|
-
const peer = await datalayer_driver_1.Peer.new(`${ip}:${port}`, false,
|
|
204
|
+
const peer = await datalayer_driver_1.Peer.new(`${ip}:${port}`, false, tls);
|
|
205
205
|
return FullNodePeer.createPeerProxy(peer);
|
|
206
206
|
}
|
|
207
207
|
catch (error) {
|
|
@@ -230,7 +230,9 @@ class FullNodePeer {
|
|
|
230
230
|
// Prioritize LOCALHOST, TRUSTED_NODE_IP, and CHIA_NODES_HOST if they have the highest peak height
|
|
231
231
|
let bestPeerIndex = validHeights.findIndex((height, index) => height === highestPeak &&
|
|
232
232
|
!FullNodePeer.deprioritizedIps.has(peerIPs[index]) && // Exclude deprioritized IPs
|
|
233
|
-
(peerIPs[index] === LOCALHOST ||
|
|
233
|
+
(peerIPs[index] === LOCALHOST ||
|
|
234
|
+
peerIPs[index] === trustedNodeIp ||
|
|
235
|
+
peerIPs[index] === CHIA_NODES_HOST));
|
|
234
236
|
// If LOCALHOST, TRUSTED_NODE_IP, or CHIA_NODES_HOST don't have the highest peak, select any peer with the highest peak
|
|
235
237
|
if (bestPeerIndex === -1) {
|
|
236
238
|
bestPeerIndex = validHeights.findIndex((height) => height === highestPeak);
|
package/dist/utils/network.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
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"}
|
|
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;AAGF,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,MAUzC,CAAC"}
|
package/dist/utils/network.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPublicIpAddress = void 0;
|
|
6
|
+
exports.formatHost = exports.getPublicIpAddress = void 0;
|
|
7
7
|
/*
|
|
8
8
|
* Stopgap until better solution for finding public IPS found
|
|
9
9
|
*/
|
|
@@ -52,3 +52,14 @@ const getPublicIpAddress = async () => {
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
exports.getPublicIpAddress = getPublicIpAddress;
|
|
55
|
+
// Helper function to wrap IPv6 addresses in brackets
|
|
56
|
+
const formatHost = (host) => {
|
|
57
|
+
const ipv6Pattern = /^[a-fA-F0-9:]+$/; // Simple regex to match raw IPv6 addresses (without brackets)
|
|
58
|
+
const hasBrackets = /^\[.*\]$/; // Regex to check if the address already has brackets
|
|
59
|
+
// If it's an IPv6 address without brackets, add them
|
|
60
|
+
if (ipv6Pattern.test(host) && !hasBrackets.test(host)) {
|
|
61
|
+
return `[${host}]`;
|
|
62
|
+
}
|
|
63
|
+
return host; // Return the host as is (IPv4, hostname, or already bracketed IPv6)
|
|
64
|
+
};
|
|
65
|
+
exports.formatHost = formatHost;
|
package/dist/utils/ssl.js
CHANGED
|
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.getOrCreateSSLCerts = void 0;
|
|
27
27
|
const fs = __importStar(require("fs"));
|
|
28
28
|
const path = __importStar(require("path"));
|
|
29
|
-
const
|
|
29
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
30
30
|
const config_1 = require("./config");
|
|
31
31
|
const getOrCreateSSLCerts = () => {
|
|
32
32
|
const sslDir = path.join(config_1.USER_DIR_PATH, "ssl");
|
|
@@ -38,7 +38,7 @@ const getOrCreateSSLCerts = () => {
|
|
|
38
38
|
}
|
|
39
39
|
// Check if the certificate and key exist, if not, generate them
|
|
40
40
|
if (!fs.existsSync(certPath) || !fs.existsSync(keyPath)) {
|
|
41
|
-
new
|
|
41
|
+
new datalayer_driver_1.Tls(certPath, keyPath);
|
|
42
42
|
console.log("Client certificate and key generated successfully.");
|
|
43
43
|
}
|
|
44
44
|
// Return the paths to the cert and key files
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dignetwork/dig-sdk",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.103",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,14 +25,13 @@
|
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@dignetwork/datalayer-driver": "^0.1.
|
|
28
|
+
"@dignetwork/datalayer-driver": "^0.1.28",
|
|
29
29
|
"archiver": "^7.0.1",
|
|
30
30
|
"axios": "^1.7.7",
|
|
31
31
|
"bip39": "^3.1.0",
|
|
32
32
|
"chia-bls": "^1.0.2",
|
|
33
33
|
"chia-config-loader": "^1.0.1",
|
|
34
34
|
"chia-root-resolver": "^1.0.0",
|
|
35
|
-
"chia-server-coin": "^0.0.5",
|
|
36
35
|
"chia-wallet": "^1.0.18",
|
|
37
36
|
"cli-progress": "^3.12.0",
|
|
38
37
|
"colorette": "^2.0.20",
|