@dignetwork/dig-sdk 0.0.1-alpha.99 → 0.2.0

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.
Files changed (162) hide show
  1. package/LICENSE +21 -7
  2. package/README.md +412 -0
  3. package/dist/adapters.cjs +356 -0
  4. package/dist/adapters.cjs.map +1 -0
  5. package/dist/adapters.d.cts +20 -0
  6. package/dist/adapters.d.ts +20 -0
  7. package/dist/adapters.js +347 -0
  8. package/dist/adapters.js.map +1 -0
  9. package/dist/dev-shim-DfKRA1ok.d.cts +128 -0
  10. package/dist/dev-shim-DfKRA1ok.d.ts +128 -0
  11. package/dist/dig-client-entry-ChYxUvBn.d.cts +372 -0
  12. package/dist/dig-client-entry-ChYxUvBn.d.ts +372 -0
  13. package/dist/dig-client.cjs +443 -0
  14. package/dist/dig-client.cjs.map +1 -0
  15. package/dist/dig-client.d.cts +1 -0
  16. package/dist/dig-client.d.ts +1 -0
  17. package/dist/dig-client.js +432 -0
  18. package/dist/dig-client.js.map +1 -0
  19. package/dist/index.cjs +1186 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.cts +502 -0
  22. package/dist/index.d.ts +502 -5
  23. package/dist/index.js +1156 -19
  24. package/dist/index.js.map +1 -0
  25. package/dist/next.cjs +369 -0
  26. package/dist/next.cjs.map +1 -0
  27. package/dist/next.d.cts +23 -0
  28. package/dist/next.d.ts +23 -0
  29. package/dist/next.js +362 -0
  30. package/dist/next.js.map +1 -0
  31. package/dist/spend.cjs +14 -0
  32. package/dist/spend.cjs.map +1 -0
  33. package/dist/spend.d.cts +1 -0
  34. package/dist/spend.d.ts +1 -0
  35. package/dist/spend.js +3 -0
  36. package/dist/spend.js.map +1 -0
  37. package/dist/vite.cjs +381 -0
  38. package/dist/vite.cjs.map +1 -0
  39. package/dist/vite.d.cts +35 -0
  40. package/dist/vite.d.ts +35 -0
  41. package/dist/vite.js +375 -0
  42. package/dist/vite.js.map +1 -0
  43. package/package.json +87 -59
  44. package/vendor/PROVENANCE.md +102 -0
  45. package/vendor/dig_client.d.ts +150 -0
  46. package/vendor/dig_client.mjs +805 -0
  47. package/vendor/dig_client_bg.wasm +0 -0
  48. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +0 -163
  49. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +0 -1
  50. package/dist/DataIntegrityTree/DataIntegrityTree.js +0 -707
  51. package/dist/DataIntegrityTree/DataLayerError.d.ts +0 -6
  52. package/dist/DataIntegrityTree/DataLayerError.d.ts.map +0 -1
  53. package/dist/DataIntegrityTree/DataLayerError.js +0 -17
  54. package/dist/DataIntegrityTree/index.d.ts +0 -2
  55. package/dist/DataIntegrityTree/index.d.ts.map +0 -1
  56. package/dist/DataIntegrityTree/index.js +0 -17
  57. package/dist/DigNetwork/ContentServer.d.ts +0 -31
  58. package/dist/DigNetwork/ContentServer.d.ts.map +0 -1
  59. package/dist/DigNetwork/ContentServer.js +0 -176
  60. package/dist/DigNetwork/DigChallenge.d.ts +0 -82
  61. package/dist/DigNetwork/DigChallenge.d.ts.map +0 -1
  62. package/dist/DigNetwork/DigChallenge.js +0 -144
  63. package/dist/DigNetwork/DigNetwork.d.ts +0 -14
  64. package/dist/DigNetwork/DigNetwork.d.ts.map +0 -1
  65. package/dist/DigNetwork/DigNetwork.js +0 -169
  66. package/dist/DigNetwork/DigPeer.d.ts +0 -24
  67. package/dist/DigNetwork/DigPeer.d.ts.map +0 -1
  68. package/dist/DigNetwork/DigPeer.js +0 -118
  69. package/dist/DigNetwork/IncentiveServer.d.ts +0 -13
  70. package/dist/DigNetwork/IncentiveServer.d.ts.map +0 -1
  71. package/dist/DigNetwork/IncentiveServer.js +0 -76
  72. package/dist/DigNetwork/PropagationServer.d.ts +0 -81
  73. package/dist/DigNetwork/PropagationServer.d.ts.map +0 -1
  74. package/dist/DigNetwork/PropagationServer.js +0 -563
  75. package/dist/DigNetwork/index.d.ts +0 -4
  76. package/dist/DigNetwork/index.d.ts.map +0 -1
  77. package/dist/DigNetwork/index.js +0 -19
  78. package/dist/blockchain/DataStore.d.ts +0 -67
  79. package/dist/blockchain/DataStore.d.ts.map +0 -1
  80. package/dist/blockchain/DataStore.js +0 -413
  81. package/dist/blockchain/DataStoreSerializer.d.ts +0 -52
  82. package/dist/blockchain/DataStoreSerializer.d.ts.map +0 -1
  83. package/dist/blockchain/DataStoreSerializer.js +0 -109
  84. package/dist/blockchain/FullNodePeer.d.ts +0 -31
  85. package/dist/blockchain/FullNodePeer.d.ts.map +0 -1
  86. package/dist/blockchain/FullNodePeer.js +0 -295
  87. package/dist/blockchain/ServerCoin.d.ts +0 -29
  88. package/dist/blockchain/ServerCoin.d.ts.map +0 -1
  89. package/dist/blockchain/ServerCoin.js +0 -324
  90. package/dist/blockchain/Wallet.d.ts +0 -28
  91. package/dist/blockchain/Wallet.d.ts.map +0 -1
  92. package/dist/blockchain/Wallet.js +0 -253
  93. package/dist/blockchain/coins.d.ts +0 -6
  94. package/dist/blockchain/coins.d.ts.map +0 -1
  95. package/dist/blockchain/coins.js +0 -102
  96. package/dist/blockchain/index.d.ts +0 -8
  97. package/dist/blockchain/index.d.ts.map +0 -1
  98. package/dist/blockchain/index.js +0 -36
  99. package/dist/index.d.ts.map +0 -1
  100. package/dist/prompts.d.ts +0 -21
  101. package/dist/prompts.d.ts.map +0 -1
  102. package/dist/prompts.js +0 -149
  103. package/dist/types.d.ts +0 -64
  104. package/dist/types.d.ts.map +0 -1
  105. package/dist/types.js +0 -2
  106. package/dist/utils/ContentScanner.d.ts +0 -63
  107. package/dist/utils/ContentScanner.d.ts.map +0 -1
  108. package/dist/utils/ContentScanner.js +0 -175
  109. package/dist/utils/Environment.d.ts +0 -18
  110. package/dist/utils/Environment.d.ts.map +0 -1
  111. package/dist/utils/Environment.js +0 -85
  112. package/dist/utils/FileCache.d.ts +0 -11
  113. package/dist/utils/FileCache.d.ts.map +0 -1
  114. package/dist/utils/FileCache.js +0 -58
  115. package/dist/utils/FileTransfer.d.ts +0 -47
  116. package/dist/utils/FileTransfer.d.ts.map +0 -1
  117. package/dist/utils/FileTransfer.js +0 -209
  118. package/dist/utils/NconfManager.d.ts +0 -11
  119. package/dist/utils/NconfManager.d.ts.map +0 -1
  120. package/dist/utils/NconfManager.js +0 -56
  121. package/dist/utils/StoreArchiveManager.d.ts +0 -45
  122. package/dist/utils/StoreArchiveManager.d.ts.map +0 -1
  123. package/dist/utils/StoreArchiveManager.js +0 -153
  124. package/dist/utils/asyncPool.d.ts +0 -9
  125. package/dist/utils/asyncPool.d.ts.map +0 -1
  126. package/dist/utils/asyncPool.js +0 -23
  127. package/dist/utils/config.d.ts +0 -68
  128. package/dist/utils/config.d.ts.map +0 -1
  129. package/dist/utils/config.js +0 -223
  130. package/dist/utils/connectionUtils.d.ts +0 -10
  131. package/dist/utils/connectionUtils.d.ts.map +0 -1
  132. package/dist/utils/connectionUtils.js +0 -18
  133. package/dist/utils/credentialsUtils.d.ts +0 -8
  134. package/dist/utils/credentialsUtils.d.ts.map +0 -1
  135. package/dist/utils/credentialsUtils.js +0 -122
  136. package/dist/utils/directoryUtils.d.ts +0 -9
  137. package/dist/utils/directoryUtils.d.ts.map +0 -1
  138. package/dist/utils/directoryUtils.js +0 -110
  139. package/dist/utils/encryption.d.ts +0 -8
  140. package/dist/utils/encryption.d.ts.map +0 -1
  141. package/dist/utils/encryption.js +0 -55
  142. package/dist/utils/hashUtils.d.ts +0 -8
  143. package/dist/utils/hashUtils.d.ts.map +0 -1
  144. package/dist/utils/hashUtils.js +0 -44
  145. package/dist/utils/index.d.ts +0 -14
  146. package/dist/utils/index.d.ts.map +0 -1
  147. package/dist/utils/index.js +0 -29
  148. package/dist/utils/merkle.d.ts +0 -2
  149. package/dist/utils/merkle.d.ts.map +0 -1
  150. package/dist/utils/merkle.js +0 -28
  151. package/dist/utils/network.d.ts +0 -2
  152. package/dist/utils/network.d.ts.map +0 -1
  153. package/dist/utils/network.js +0 -54
  154. package/dist/utils/spinnerUtils.d.ts +0 -2
  155. package/dist/utils/spinnerUtils.d.ts.map +0 -1
  156. package/dist/utils/spinnerUtils.js +0 -47
  157. package/dist/utils/ssl.d.ts +0 -5
  158. package/dist/utils/ssl.d.ts.map +0 -1
  159. package/dist/utils/ssl.js +0 -50
  160. package/dist/utils/validationUtils.d.ts +0 -9
  161. package/dist/utils/validationUtils.d.ts.map +0 -1
  162. package/dist/utils/validationUtils.js +0 -55
@@ -1,29 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./config"), exports);
18
- __exportStar(require("./connectionUtils"), exports);
19
- __exportStar(require("./credentialsUtils"), exports);
20
- __exportStar(require("./directoryUtils"), exports);
21
- __exportStar(require("./encryption"), exports);
22
- __exportStar(require("./FileCache"), exports);
23
- __exportStar(require("./hashUtils"), exports);
24
- __exportStar(require("./NconfManager"), exports);
25
- __exportStar(require("./network"), exports);
26
- __exportStar(require("./spinnerUtils"), exports);
27
- __exportStar(require("./ssl"), exports);
28
- __exportStar(require("./validationUtils"), exports);
29
- __exportStar(require("./Environment"), exports);
@@ -1,2 +0,0 @@
1
- export declare function merkleIntegrityCheck(treePath: string, tmpDir: string, dataPath: string, roothash: string): Promise<boolean>;
2
- //# sourceMappingURL=merkle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../../src/utils/merkle.ts"],"names":[],"mappings":"AAIA,wBAAsB,oBAAoB,CACtC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CA6BlB"}
@@ -1,28 +0,0 @@
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.merkleIntegrityCheck = merkleIntegrityCheck;
7
- const DataIntegrityTree_1 = require("../DataIntegrityTree");
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- async function merkleIntegrityCheck(treePath, tmpDir, dataPath, roothash) {
11
- const rootHashContent = fs_1.default.readFileSync(treePath, "utf-8");
12
- const tree = JSON.parse(rootHashContent);
13
- // Extract expected sha256 from dataPath
14
- const expectedSha256 = dataPath.replace("data", "").replace(/\//g, "");
15
- console.log("expectedSha256", expectedSha256);
16
- // Find the hexKey in the tree based on matching sha256
17
- const hexKey = Object.keys(tree.files).find((key) => {
18
- const fileData = tree.files[key]; // Inline type definition
19
- return fileData.sha256 === expectedSha256;
20
- });
21
- if (!hexKey) {
22
- throw new Error(`No matching file found with sha256: ${expectedSha256}`);
23
- }
24
- // Validate the integrity with the foreign tree
25
- const integrity = await DataIntegrityTree_1.DataIntegrityTree.validateKeyIntegrityWithForeignTree(hexKey, expectedSha256, tree, roothash, path_1.default.join(tmpDir, "data"));
26
- console.log("Integrity check result:", integrity);
27
- return integrity;
28
- }
@@ -1,2 +0,0 @@
1
- export declare const getPublicIpAddress: () => Promise<string | undefined>;
2
- //# sourceMappingURL=network.d.ts.map
@@ -1 +0,0 @@
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,54 +0,0 @@
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.getPublicIpAddress = void 0;
7
- /*
8
- * Stopgap until better solution for finding public IPS found
9
- */
10
- const superagent_1 = __importDefault(require("superagent"));
11
- const Environment_1 = require("./Environment");
12
- const MAX_RETRIES = 5;
13
- const RETRY_DELAY = 2000; // in milliseconds
14
- // Regular expression for validating both IPv4 and IPv6 addresses
15
- const ipv4Regex = /^(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]?)$/;
16
- const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:)|(([0-9a-fA-F]{1,4}:){1,7}|:):(([0-9a-fA-F]{1,4}:){1,6}|:):([0-9a-fA-F]{1,4}|:):([0-9a-fA-F]{1,4}|:)|::)$/;
17
- // Helper function to validate the IP address
18
- const isValidIp = (ip) => {
19
- return ipv4Regex.test(ip) || ipv6Regex.test(ip);
20
- };
21
- const getPublicIpAddress = async () => {
22
- const publicIp = Environment_1.Environment.PUBLIC_IP;
23
- if (publicIp) {
24
- console.log("Public IP address from env:", publicIp);
25
- if (isValidIp(publicIp)) {
26
- return publicIp;
27
- }
28
- console.error("Invalid public IP address in environment variable");
29
- return undefined;
30
- }
31
- let attempt = 0;
32
- while (attempt < MAX_RETRIES) {
33
- try {
34
- const response = await superagent_1.default.get("https://api.datalayer.storage/user/v1/get_user_ip");
35
- if (response.body && response.body.success) {
36
- const ipAddress = response.body.ip_address;
37
- if (isValidIp(ipAddress)) {
38
- return ipAddress;
39
- }
40
- throw new Error("Invalid IP address format received");
41
- }
42
- throw new Error("Failed to retrieve public IP address");
43
- }
44
- catch (error) {
45
- attempt++;
46
- console.error(`Error fetching public IP address (Attempt ${attempt}):`, error.message);
47
- if (attempt >= MAX_RETRIES) {
48
- throw new Error("Could not retrieve public IP address after several attempts");
49
- }
50
- await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
51
- }
52
- }
53
- };
54
- exports.getPublicIpAddress = getPublicIpAddress;
@@ -1,2 +0,0 @@
1
- export declare const waitForPromise: <T>(promiseFn: () => Promise<T>, spinnerText?: string, successText?: string, errorText?: string) => Promise<T>;
2
- //# sourceMappingURL=spinnerUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spinnerUtils.d.ts","sourceRoot":"","sources":["../../src/utils/spinnerUtils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,GAAU,CAAC,aACzB,MAAM,OAAO,CAAC,CAAC,CAAC,gBACd,MAAM,gBACN,MAAM,cACR,MAAM,KAChB,OAAO,CAAC,CAAC,CA8CX,CAAC"}
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.waitForPromise = void 0;
4
- const nanospinner_1 = require("nanospinner");
5
- const waitForPromise = async (promiseFn, spinnerText = "Processing...", successText = "OK!", errorText = "Error.") => {
6
- const spinner = (0, nanospinner_1.createSpinner)(spinnerText).start();
7
- // Store original console.log and console.error, and collect log messages
8
- const originalConsoleLog = console.log;
9
- const originalConsoleError = console.error;
10
- let logMessages = [];
11
- let errorMessages = [];
12
- console.log = (...args) => {
13
- logMessages.push(args.map(arg => (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' '));
14
- };
15
- console.error = (...args) => {
16
- errorMessages.push(args.map(arg => (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' '));
17
- };
18
- try {
19
- const result = await promiseFn();
20
- if (result) {
21
- spinner.success({ text: successText });
22
- }
23
- else {
24
- throw new Error(errorText);
25
- }
26
- return result;
27
- }
28
- catch (error) {
29
- spinner.error({ text: errorText });
30
- // Print collected log messages and error messages on error
31
- if (logMessages.length > 0) {
32
- originalConsoleLog("\nCollected logs:");
33
- logMessages.forEach((message) => originalConsoleLog(message));
34
- }
35
- if (errorMessages.length > 0) {
36
- originalConsoleError("\nCollected errors:");
37
- errorMessages.forEach((message) => originalConsoleError(message));
38
- }
39
- throw error;
40
- }
41
- finally {
42
- // Restore the original console.log and console.error functions
43
- console.log = originalConsoleLog;
44
- console.error = originalConsoleError;
45
- }
46
- };
47
- exports.waitForPromise = waitForPromise;
@@ -1,5 +0,0 @@
1
- export declare const getOrCreateSSLCerts: () => {
2
- certPath: string;
3
- keyPath: string;
4
- };
5
- //# sourceMappingURL=ssl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ssl.d.ts","sourceRoot":"","sources":["../../src/utils/ssl.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mBAAmB;;;CAqB/B,CAAC"}
package/dist/utils/ssl.js DELETED
@@ -1,50 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getOrCreateSSLCerts = void 0;
27
- const fs = __importStar(require("fs"));
28
- const path = __importStar(require("path"));
29
- const chia_server_coin_1 = require("chia-server-coin");
30
- const config_1 = require("./config");
31
- const getOrCreateSSLCerts = () => {
32
- const sslDir = path.join(config_1.USER_DIR_PATH, "ssl");
33
- const certPath = path.join(sslDir, "client.cert");
34
- const keyPath = path.join(sslDir, "client.key");
35
- // Ensure the SSL directory exists
36
- if (!fs.existsSync(sslDir)) {
37
- fs.mkdirSync(sslDir, { recursive: true });
38
- }
39
- // Check if the certificate and key exist, if not, generate them
40
- if (!fs.existsSync(certPath) || !fs.existsSync(keyPath)) {
41
- new chia_server_coin_1.Tls(certPath, keyPath);
42
- console.log("Client certificate and key generated successfully.");
43
- }
44
- // Return the paths to the cert and key files
45
- return {
46
- certPath,
47
- keyPath,
48
- };
49
- };
50
- exports.getOrCreateSSLCerts = getOrCreateSSLCerts;
@@ -1,9 +0,0 @@
1
- /**
2
- * Validates if the SHA256 hash of the decompressed file matches the provided hash.
3
- *
4
- * @param sha256 - The expected SHA256 hash of the decompressed file.
5
- * @param dataDir - The root folder where the data files are stored.
6
- * @returns A boolean indicating whether the decompressed file's hash matches the provided hash.
7
- */
8
- export declare const validateFileSha256: (sha256: string, dataDir: string) => boolean;
9
- //# sourceMappingURL=validationUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../../src/utils/validationUtils.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,WACrB,MAAM,WACL,MAAM,KACd,OAoBF,CAAC"}
@@ -1,55 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.validateFileSha256 = void 0;
27
- const fs = __importStar(require("fs"));
28
- const zlib = __importStar(require("zlib"));
29
- const crypto = __importStar(require("crypto"));
30
- const hashUtils_1 = require("./hashUtils");
31
- /**
32
- * Validates if the SHA256 hash of the decompressed file matches the provided hash.
33
- *
34
- * @param sha256 - The expected SHA256 hash of the decompressed file.
35
- * @param dataDir - The root folder where the data files are stored.
36
- * @returns A boolean indicating whether the decompressed file's hash matches the provided hash.
37
- */
38
- const validateFileSha256 = (sha256, dataDir) => {
39
- // Derive the file path from the SHA256 hash
40
- const filePath = (0, hashUtils_1.getFilePathFromSha256)(sha256, dataDir);
41
- if (!fs.existsSync(filePath)) {
42
- return false;
43
- }
44
- // Read and decompress the file
45
- const fileBuffer = fs.readFileSync(filePath);
46
- const decompressedBuffer = zlib.gunzipSync(fileBuffer);
47
- // Calculate the SHA256 hash of the decompressed content
48
- const hash = crypto
49
- .createHash("sha256")
50
- .update(decompressedBuffer)
51
- .digest("hex");
52
- // Compare the calculated hash with the provided hash
53
- return hash === sha256;
54
- };
55
- exports.validateFileSha256 = validateFileSha256;