@dignetwork/dig-sdk 0.0.1-alpha.65 → 0.0.1-alpha.68
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/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.js +4 -1
- package/dist/DigNetwork/ContentServer.d.ts +3 -3
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +19 -7
- package/dist/DigNetwork/DigNetwork.js +3 -5
- package/dist/DigNetwork/PropagationServer.d.ts +12 -0
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
- package/dist/DigNetwork/PropagationServer.js +31 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataIntegrityTree.d.ts","sourceRoot":"","sources":["../../src/DataIntegrityTree/DataIntegrityTree.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAuClC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,cAAM,iBAAiB;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACjB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAa;gBAEb,OAAO,EAAE,MAAM,EAAE,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MAAM,GAAG,OAAO;IA4B5D;;;;;OAKG;IACH,WAAW,CACT,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB;QAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE;IA+B/D;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAyD5E;;;;;;;;;OASG;WACU,mCAAmC,CAC9C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC;CAwFpB;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -135,7 +135,10 @@ class DataIntegrityTree {
|
|
|
135
135
|
const manifest = this._loadManifest();
|
|
136
136
|
if (manifest.length > 0) {
|
|
137
137
|
const latestRootHash = manifest[manifest.length - 1];
|
|
138
|
-
|
|
138
|
+
if (latestRootHash && isHexString(latestRootHash)) {
|
|
139
|
+
return this.deserializeTree(latestRootHash);
|
|
140
|
+
}
|
|
141
|
+
return new merkletreejs_1.MerkleTree([], crypto_js_1.SHA256, { sortPairs: true });
|
|
139
142
|
}
|
|
140
143
|
else {
|
|
141
144
|
return new merkletreejs_1.MerkleTree([], crypto_js_1.SHA256, { sortPairs: true });
|
|
@@ -12,8 +12,8 @@ export declare class ContentServer {
|
|
|
12
12
|
getWellKnown(): Promise<any>;
|
|
13
13
|
getKnownStores(): Promise<any>;
|
|
14
14
|
getStoresIndex(): Promise<any>;
|
|
15
|
-
getKeysIndex(): Promise<any>;
|
|
16
|
-
headKey(key: string): Promise<{
|
|
15
|
+
getKeysIndex(rootHash?: string): Promise<any>;
|
|
16
|
+
headKey(key: string, rootHash?: string): Promise<{
|
|
17
17
|
success: boolean;
|
|
18
18
|
headers?: http.IncomingHttpHeaders;
|
|
19
19
|
}>;
|
|
@@ -24,7 +24,7 @@ export declare class ContentServer {
|
|
|
24
24
|
headers?: http.IncomingHttpHeaders;
|
|
25
25
|
}>;
|
|
26
26
|
hasRootHash(rootHash: string): Promise<boolean>;
|
|
27
|
-
streamKey(key: string): Promise<Readable>;
|
|
27
|
+
streamKey(key: string, rootHash?: string): Promise<Readable>;
|
|
28
28
|
private head;
|
|
29
29
|
private fetchJson;
|
|
30
30
|
private fetchWithRetries;
|
|
@@ -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,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,CAAC;IAepC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC;IAM5B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,YAAY,
|
|
1
|
+
{"version":3,"file":"ContentServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/ContentServer.ts"],"names":[],"mappings":"A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OAAO,CAAC,QAAQ,CAAC;YAgDrD,IAAI;YA0EJ,SAAS;YAMT,gBAAgB;YAiChB,KAAK;CA0DpB"}
|
|
@@ -56,18 +56,26 @@ class ContentServer {
|
|
|
56
56
|
return this.fetchJson(url);
|
|
57
57
|
}
|
|
58
58
|
// Method to get the index of keys in a store
|
|
59
|
-
async getKeysIndex() {
|
|
60
|
-
|
|
59
|
+
async getKeysIndex(rootHash) {
|
|
60
|
+
let udi = `chia.${this.storeId}`;
|
|
61
|
+
if (rootHash) {
|
|
62
|
+
udi += `.${rootHash}`;
|
|
63
|
+
}
|
|
64
|
+
const url = `https://${this.ipAddress}:${ContentServer.port}/${udi}`;
|
|
61
65
|
return this.fetchJson(url);
|
|
62
66
|
}
|
|
63
67
|
// Method to check if a specific key exists (HEAD request)
|
|
64
|
-
async headKey(key) {
|
|
65
|
-
|
|
68
|
+
async headKey(key, rootHash) {
|
|
69
|
+
let udi = `chia.${this.storeId}`;
|
|
70
|
+
if (rootHash) {
|
|
71
|
+
udi += `.${rootHash}`;
|
|
72
|
+
}
|
|
73
|
+
const url = `https://${this.ipAddress}:${ContentServer.port}/${udi}/${key}`;
|
|
66
74
|
return this.head(url);
|
|
67
75
|
}
|
|
68
76
|
// Method to check if a specific store exists (HEAD request)
|
|
69
77
|
async headStore(options) {
|
|
70
|
-
let url = `https://${this.ipAddress}:${ContentServer.port}
|
|
78
|
+
let url = `https://${this.ipAddress}:${ContentServer.port}/chia.${this.storeId}`;
|
|
71
79
|
if (options?.hasRootHash) {
|
|
72
80
|
url += `?hasRootHash=${options.hasRootHash}`;
|
|
73
81
|
}
|
|
@@ -82,9 +90,13 @@ class ContentServer {
|
|
|
82
90
|
}
|
|
83
91
|
return false;
|
|
84
92
|
}
|
|
85
|
-
streamKey(key) {
|
|
93
|
+
streamKey(key, rootHash) {
|
|
94
|
+
let udi = `chia.${this.storeId}`;
|
|
95
|
+
if (rootHash) {
|
|
96
|
+
udi += `.${rootHash}`;
|
|
97
|
+
}
|
|
86
98
|
return new Promise((resolve, reject) => {
|
|
87
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/${
|
|
99
|
+
const url = `https://${this.ipAddress}:${ContentServer.port}/${udi}/${key}`;
|
|
88
100
|
const urlObj = new url_1.URL(url);
|
|
89
101
|
const requestOptions = {
|
|
90
102
|
hostname: urlObj.hostname,
|
|
@@ -63,18 +63,16 @@ class DigNetwork {
|
|
|
63
63
|
peerIp = digPeers[0];
|
|
64
64
|
const digPeer = new DigPeer_1.DigPeer(peerIp, storeId);
|
|
65
65
|
// Try to fetch the head store information
|
|
66
|
-
const
|
|
67
|
-
hasRootHash: rootHash,
|
|
68
|
-
});
|
|
66
|
+
const { storeExists, rootHashExists } = await digPeer.propagationServer.checkStoreExists(rootHash);
|
|
69
67
|
// If the peer has the correct root hash, check if key is required
|
|
70
|
-
if (
|
|
68
|
+
if (storeExists && rootHashExists) {
|
|
71
69
|
console.log(`Found Peer at ${peerIp} for storeId: ${storeId}, root hash ${rootHash}`);
|
|
72
70
|
// If no key is provided, return the peer
|
|
73
71
|
if (!key) {
|
|
74
72
|
return digPeer;
|
|
75
73
|
}
|
|
76
74
|
// If key is provided, check if the peer has it
|
|
77
|
-
const keyResponse = await digPeer.contentServer.headKey(key);
|
|
75
|
+
const keyResponse = await digPeer.contentServer.headKey(key, rootHash);
|
|
78
76
|
if (keyResponse.headers?.["x-key-exists"] === "true") {
|
|
79
77
|
return digPeer;
|
|
80
78
|
}
|
|
@@ -70,6 +70,18 @@ export declare class PropagationServer {
|
|
|
70
70
|
* @returns {Promise<Buffer>} - The file content in memory as a Buffer.
|
|
71
71
|
*/
|
|
72
72
|
fetchFile(dataPath: string): Promise<Buffer>;
|
|
73
|
+
/**
|
|
74
|
+
* Get details of a file, including whether it exists and its size.
|
|
75
|
+
* Makes a HEAD request to the server and checks the response headers.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} dataPath - The path of the file within the DataStore.
|
|
78
|
+
* @param {string} rootHash - The root hash associated with the DataStore.
|
|
79
|
+
* @returns {Promise<{ exists: boolean; size: number }>} - An object containing file existence and size information.
|
|
80
|
+
*/
|
|
81
|
+
getFileDetails(dataPath: string, rootHash: string): Promise<{
|
|
82
|
+
exists: boolean;
|
|
83
|
+
size: number;
|
|
84
|
+
}>;
|
|
73
85
|
/**
|
|
74
86
|
* Download a file from the server by sending a GET request.
|
|
75
87
|
* Logs progress using cli-progress.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAC;AAiB1B,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;IAIpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAqCrB;gBAEU,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAY9C;;OAEG;IACG,gBAAgB;IAKtB;;OAEG;IACH,gBAAgB;IAQhB;;;;;OAKG;IACG,gBAAgB,CACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IAwC7D;;;;;OAKG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAqDzC;;;OAGG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,KAAK,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CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IAwC7D;;;;;OAKG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAqDzC;;;OAGG;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;IA+DhD;;;OAGG;IACG,mBAAmB;IAgCzB;;;;;;OAMG;WACU,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IAiDnB;;;;;OAKG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4ClD;;;;;;;OAOG;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;IA2B7C;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM;IAgEnC;;;;;OAKG;WACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CA+BpB"}
|
|
@@ -317,6 +317,35 @@ class PropagationServer {
|
|
|
317
317
|
throw error;
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Get details of a file, including whether it exists and its size.
|
|
322
|
+
* Makes a HEAD request to the server and checks the response headers.
|
|
323
|
+
*
|
|
324
|
+
* @param {string} dataPath - The path of the file within the DataStore.
|
|
325
|
+
* @param {string} rootHash - The root hash associated with the DataStore.
|
|
326
|
+
* @returns {Promise<{ exists: boolean; size: number }>} - An object containing file existence and size information.
|
|
327
|
+
*/
|
|
328
|
+
async getFileDetails(dataPath, rootHash) {
|
|
329
|
+
try {
|
|
330
|
+
const config = {
|
|
331
|
+
httpsAgent: this.createHttpsAgent(),
|
|
332
|
+
};
|
|
333
|
+
// Construct the URL for the HEAD request to check file details
|
|
334
|
+
const url = `https://${this.ipAddress}:${PropagationServer.port}/store/${this.storeId}/${rootHash}/${dataPath}`;
|
|
335
|
+
const response = await axios_1.default.head(url, config);
|
|
336
|
+
// Check the headers for file existence and size
|
|
337
|
+
const fileExists = response.headers["x-file-exists"] === "true";
|
|
338
|
+
const fileSize = parseInt(response.headers["x-file-size"], 10);
|
|
339
|
+
return {
|
|
340
|
+
exists: fileExists,
|
|
341
|
+
size: fileExists ? fileSize : 0, // Return 0 size if file doesn't exist
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
console.error((0, colorette_1.red)(`✖ Error checking file details for ${dataPath}:`), error.message);
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
320
349
|
/**
|
|
321
350
|
* Download a file from the server by sending a GET request.
|
|
322
351
|
* Logs progress using cli-progress.
|
|
@@ -382,8 +411,8 @@ class PropagationServer {
|
|
|
382
411
|
// Initialize wallet
|
|
383
412
|
await propagationServer.initializeWallet();
|
|
384
413
|
// Check if the store exists
|
|
385
|
-
const storeExists = await propagationServer.checkStoreExists();
|
|
386
|
-
if (!storeExists) {
|
|
414
|
+
const { storeExists, rootHashExists } = await propagationServer.checkStoreExists(rootHash);
|
|
415
|
+
if (!storeExists || !rootHashExists) {
|
|
387
416
|
throw new Error(`Store ${storeId} does not exist.`);
|
|
388
417
|
}
|
|
389
418
|
await propagationServer.downloadFile("height.json");
|