@dignetwork/dig-sdk 0.0.1-alpha.194 → 0.0.1-alpha.195
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.
|
@@ -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;AAQlC,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;IAiBL,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAW3D,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAcxD;;;;OAIG;IACU,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC;IA6B5B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAQ9B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAiB7C,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;IAiBvD,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;IAoBF;;;;;;OAMG;IACU,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BrD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;YA+CrD,IAAI;YA0EJ,SAAS;YAMT,gBAAgB;YAiChB,KAAK;YA+GL,eAAe;CA4G9B"}
|
|
@@ -9,6 +9,7 @@ const http_1 = __importDefault(require("http"));
|
|
|
9
9
|
const url_1 = require("url");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
11
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
12
|
+
const utils_2 = require("../utils");
|
|
12
13
|
const hasRootHashCache = new node_cache_1.default({ stdTTL: 86400 });
|
|
13
14
|
const wellKnownCache = new node_cache_1.default({ stdTTL: 86400 });
|
|
14
15
|
class ContentServer {
|
|
@@ -23,8 +24,9 @@ class ContentServer {
|
|
|
23
24
|
}
|
|
24
25
|
// Method to get the content of a specified key from the peer, with optional challenge query
|
|
25
26
|
async getKey(key, rootHash, challengeHex) {
|
|
27
|
+
const udi = new utils_2.Udi("chia", this.storeId, rootHash, key);
|
|
26
28
|
// Construct the base URL
|
|
27
|
-
let url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}
|
|
29
|
+
let url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi.toString()}`;
|
|
28
30
|
// If a challenge is provided, append it as a query parameter
|
|
29
31
|
if (challengeHex) {
|
|
30
32
|
url += `?challenge=${challengeHex}`;
|
|
@@ -33,8 +35,9 @@ class ContentServer {
|
|
|
33
35
|
}
|
|
34
36
|
// New method to get only the first chunk of the content
|
|
35
37
|
async getKeyChunk(key, rootHash) {
|
|
38
|
+
const udi = new utils_2.Udi("chia", this.storeId, rootHash, key);
|
|
36
39
|
// Construct the base URL
|
|
37
|
-
let url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}
|
|
40
|
+
let url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi.toString()}`;
|
|
38
41
|
return this.fetchFirstChunk(url);
|
|
39
42
|
}
|
|
40
43
|
// Method to get the payment address from the peer
|
|
@@ -87,11 +90,8 @@ class ContentServer {
|
|
|
87
90
|
// Method to get the index of keys in a store
|
|
88
91
|
async getKeysIndex(rootHash) {
|
|
89
92
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
udi += `.${rootHash}`;
|
|
93
|
-
}
|
|
94
|
-
const url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}`;
|
|
93
|
+
const udi = new utils_2.Udi("chia", this.storeId, rootHash);
|
|
94
|
+
const url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi.toString()}`;
|
|
95
95
|
return this.fetchJson(url);
|
|
96
96
|
}
|
|
97
97
|
catch (error) {
|
|
@@ -104,11 +104,8 @@ class ContentServer {
|
|
|
104
104
|
// Method to check if a specific key exists (HEAD request)
|
|
105
105
|
async headKey(key, rootHash) {
|
|
106
106
|
try {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
udi += `.${rootHash}`;
|
|
110
|
-
}
|
|
111
|
-
const url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}/${key}`;
|
|
107
|
+
const udi = new utils_2.Udi("chia", this.storeId, rootHash, key);
|
|
108
|
+
const url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi.toString()}`;
|
|
112
109
|
return this.head(url);
|
|
113
110
|
}
|
|
114
111
|
catch (error) {
|
|
@@ -120,8 +117,9 @@ class ContentServer {
|
|
|
120
117
|
}
|
|
121
118
|
// Method to check if a specific store exists (HEAD request)
|
|
122
119
|
async headStore(options) {
|
|
120
|
+
const udi = new utils_2.Udi("chia", this.storeId);
|
|
123
121
|
try {
|
|
124
|
-
let url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}
|
|
122
|
+
let url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi.toString()}`;
|
|
125
123
|
if (options?.hasRootHash) {
|
|
126
124
|
url += `?hasRootHash=${options.hasRootHash}`;
|
|
127
125
|
}
|
|
@@ -162,12 +160,9 @@ class ContentServer {
|
|
|
162
160
|
return hasHash;
|
|
163
161
|
}
|
|
164
162
|
streamKey(key, rootHash) {
|
|
165
|
-
|
|
166
|
-
if (rootHash) {
|
|
167
|
-
udi += `.${rootHash}`;
|
|
168
|
-
}
|
|
163
|
+
const udi = new utils_2.Udi("chia", this.storeId, rootHash, key);
|
|
169
164
|
return new Promise((resolve, reject) => {
|
|
170
|
-
const url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}
|
|
165
|
+
const url = `https://${(0, utils_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi.toString()}`;
|
|
171
166
|
const urlObj = new url_1.URL(url);
|
|
172
167
|
const requestOptions = {
|
|
173
168
|
hostname: urlObj.hostname,
|