@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
package/dist/types.d.ts DELETED
@@ -1,64 +0,0 @@
1
- export interface FileDetails {
2
- filename: string;
3
- sha256: string;
4
- relativePath: string;
5
- }
6
- export interface Config {
7
- deploy_dir: string;
8
- remote?: string;
9
- active_store?: string;
10
- }
11
- export interface CreateStoreUserInputs {
12
- label?: string;
13
- description?: string;
14
- authorizedWriter?: string;
15
- oracleFee?: number;
16
- }
17
- export interface DigConfig {
18
- remote?: string;
19
- deploy_dir: string;
20
- active_store?: string;
21
- [key: string]: any;
22
- }
23
- export interface RootHistoryItem {
24
- root_hash: string;
25
- timestamp: Number | undefined;
26
- synced: boolean;
27
- }
28
- export interface DatFile {
29
- root: string;
30
- leaves: string[];
31
- files: {
32
- [key: string]: {
33
- hash: string;
34
- sha256: string;
35
- };
36
- };
37
- }
38
- export interface Credentials {
39
- username: string;
40
- password: string;
41
- }
42
- export interface CoinData {
43
- amount: string;
44
- puzzleHash: string;
45
- parentCoinInfo: string;
46
- }
47
- export interface ServerCoinData {
48
- coin: CoinData;
49
- createdAt: string;
50
- epoch: number;
51
- rootHash: string;
52
- }
53
- export interface IncentiveProgramData {
54
- storeId: string;
55
- xchRewardPerEpoch: number;
56
- totalRoundsPerEpoch: number;
57
- totalRoundsCompleted?: number;
58
- paymentTotalToDate?: bigint;
59
- active: boolean;
60
- lastEpochPaid?: number;
61
- walletName: string;
62
- currentCoin?: ServerCoinData;
63
- }
64
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,MAAM;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG;YACb,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B"}
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,63 +0,0 @@
1
- /**
2
- * @class IllegalContentScanner
3
- * Scans files for illegal content using ClamAV running in a Docker container and deletes files if flagged.
4
- */
5
- export declare class IllegalContentScanner {
6
- private clamAVContainerName;
7
- private virusTotalApiKey?;
8
- private openAiApiKey?;
9
- /**
10
- * @constructor
11
- * @param clamAVContainerName The name of the Docker container running ClamAV (default: 'clamav').
12
- */
13
- constructor(clamAVContainerName?: string);
14
- /**
15
- * Scans a file for illegal content using ClamAV, VirusTotal, and OpenAI Moderation API.
16
- * If a service is missing its API key, the scan for that service is skipped.
17
- * @param filePath The path of the file to scan.
18
- * @returns {Promise<void>} A promise that resolves after the scan and potential deletion.
19
- */
20
- scanFile(filePath: string): Promise<void>;
21
- /**
22
- * Scans a file using ClamAV running in Docker.
23
- * @param filePath The path of the file to scan.
24
- * @returns {Promise<string>} The result of the ClamAV scan.
25
- */
26
- private scanWithClamAV;
27
- /**
28
- * Submits a file to VirusTotal for scanning.
29
- * @param filePath The path of the file to scan.
30
- * @returns {Promise<any>} The result from VirusTotal.
31
- */
32
- private scanWithVirusTotal;
33
- /**
34
- * Scans file content (text) using OpenAI's Moderation API.
35
- * @param content The text content to scan.
36
- * @returns {Promise<any>} The result from OpenAI's Moderation API.
37
- */
38
- private scanWithOpenAI;
39
- /**
40
- * Checks if the ClamAV scan result indicates a malicious file.
41
- * @param result The ClamAV scan output.
42
- * @returns {boolean} True if the file is flagged, false otherwise.
43
- */
44
- private isClamAVResultMalicious;
45
- /**
46
- * Checks if the VirusTotal result indicates a malicious file.
47
- * @param result The VirusTotal scan result.
48
- * @returns {boolean} True if the file is flagged, false otherwise.
49
- */
50
- private isVirusTotalResultMalicious;
51
- /**
52
- * Checks if the OpenAI Moderation result indicates harmful content.
53
- * @param result The OpenAI Moderation result.
54
- * @returns {boolean} True if harmful content is detected, false otherwise.
55
- */
56
- private isOpenAiResultMalicious;
57
- /**
58
- * Deletes a file from the filesystem.
59
- * @param filePath The file to delete.
60
- */
61
- private deleteFile;
62
- }
63
- //# sourceMappingURL=ContentScanner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContentScanner.d.ts","sourceRoot":"","sources":["../../src/utils/ContentScanner.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,qBAAa,qBAAqB;IAC9B,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,gBAAgB,CAAC,CAAS;IAClC,OAAO,CAAC,YAAY,CAAC,CAAS;IAE9B;;;OAGG;gBACS,mBAAmB,GAAE,MAAiB;IAMlD;;;;;OAKG;IACU,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqDtD;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAYtB;;;;OAIG;YACW,kBAAkB;IAgBhC;;;;OAIG;YACW,cAAc;IAa5B;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAI/B;;;;OAIG;IACH,OAAO,CAAC,2BAA2B;IAKnC;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAI/B;;;OAGG;IACH,OAAO,CAAC,UAAU;CASrB"}
@@ -1,175 +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.IllegalContentScanner = void 0;
7
- const child_process_1 = require("child_process");
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const axios_1 = __importDefault(require("axios"));
11
- /**
12
- * @class IllegalContentScanner
13
- * Scans files for illegal content using ClamAV running in a Docker container and deletes files if flagged.
14
- */
15
- class IllegalContentScanner {
16
- /**
17
- * @constructor
18
- * @param clamAVContainerName The name of the Docker container running ClamAV (default: 'clamav').
19
- */
20
- constructor(clamAVContainerName = "clamav") {
21
- this.clamAVContainerName = clamAVContainerName;
22
- this.virusTotalApiKey = process.env.VIRUSTOTAL_API_KEY || undefined;
23
- this.openAiApiKey = process.env.OPENAI_API_KEY || undefined;
24
- }
25
- /**
26
- * Scans a file for illegal content using ClamAV, VirusTotal, and OpenAI Moderation API.
27
- * If a service is missing its API key, the scan for that service is skipped.
28
- * @param filePath The path of the file to scan.
29
- * @returns {Promise<void>} A promise that resolves after the scan and potential deletion.
30
- */
31
- async scanFile(filePath) {
32
- try {
33
- // 1. ClamAV Scan
34
- console.log(`Starting ClamAV scan for file: ${filePath}`);
35
- const clamAvResult = await this.scanWithClamAV(filePath);
36
- if (this.isClamAVResultMalicious(clamAvResult)) {
37
- console.log(`ClamAV flagged file: ${filePath}. Deleting...`);
38
- this.deleteFile(filePath);
39
- return;
40
- }
41
- else {
42
- console.log(`ClamAV did not flag the file: ${filePath}.`);
43
- }
44
- // 2. VirusTotal Scan (if API key is provided)
45
- if (this.virusTotalApiKey) {
46
- console.log(`Submitting file to VirusTotal for scanning: ${filePath}`);
47
- const virusTotalResult = await this.scanWithVirusTotal(filePath);
48
- if (this.isVirusTotalResultMalicious(virusTotalResult)) {
49
- console.log(`VirusTotal flagged file: ${filePath}. Deleting...`);
50
- this.deleteFile(filePath);
51
- return;
52
- }
53
- else {
54
- console.log(`VirusTotal did not flag the file: ${filePath}.`);
55
- }
56
- }
57
- else {
58
- console.log(`VirusTotal API key not provided. Skipping VirusTotal scan.`);
59
- }
60
- // 3. OpenAI Moderation API (if API key is provided and file is text-based)
61
- const fileExtension = path_1.default.extname(filePath).toLowerCase();
62
- if (this.openAiApiKey && (fileExtension === ".txt" || fileExtension === ".json")) {
63
- console.log(`Scanning file content with OpenAI Moderation API: ${filePath}`);
64
- const fileContent = await fs_1.default.promises.readFile(filePath, "utf-8");
65
- const openAiResult = await this.scanWithOpenAI(fileContent);
66
- if (this.isOpenAiResultMalicious(openAiResult)) {
67
- console.log(`OpenAI flagged file: ${filePath}. Deleting...`);
68
- this.deleteFile(filePath);
69
- return;
70
- }
71
- }
72
- else {
73
- if (!this.openAiApiKey) {
74
- console.log(`OpenAI API key not provided. Skipping OpenAI scan.`);
75
- }
76
- else {
77
- console.log(`OpenAI scan skipped: File type not supported (${fileExtension}).`);
78
- }
79
- }
80
- console.log(`File ${filePath} passed all multilayer scans.`);
81
- }
82
- catch (error) {
83
- console.error(`Error scanning file: ${filePath}`, error);
84
- }
85
- }
86
- /**
87
- * Scans a file using ClamAV running in Docker.
88
- * @param filePath The path of the file to scan.
89
- * @returns {Promise<string>} The result of the ClamAV scan.
90
- */
91
- scanWithClamAV(filePath) {
92
- return new Promise((resolve, reject) => {
93
- (0, child_process_1.exec)(`docker exec ${this.clamAVContainerName} clamdscan ${filePath}`, (error, stdout, stderr) => {
94
- if (error) {
95
- reject(`ClamAV scan error: ${stderr}`);
96
- }
97
- else {
98
- resolve(stdout);
99
- }
100
- });
101
- });
102
- }
103
- /**
104
- * Submits a file to VirusTotal for scanning.
105
- * @param filePath The path of the file to scan.
106
- * @returns {Promise<any>} The result from VirusTotal.
107
- */
108
- async scanWithVirusTotal(filePath) {
109
- const fileContent = await fs_1.default.promises.readFile(filePath);
110
- const formData = new FormData();
111
- // @ts-ignore
112
- formData.append("file", fileContent);
113
- const response = await axios_1.default.post("https://www.virustotal.com/vtapi/v2/file/scan", formData, {
114
- headers: {
115
- "x-apikey": this.virusTotalApiKey,
116
- // @ts-ignore
117
- ...formData.getHeaders(),
118
- },
119
- });
120
- return response.data;
121
- }
122
- /**
123
- * Scans file content (text) using OpenAI's Moderation API.
124
- * @param content The text content to scan.
125
- * @returns {Promise<any>} The result from OpenAI's Moderation API.
126
- */
127
- async scanWithOpenAI(content) {
128
- const response = await axios_1.default.post("https://api.openai.com/v1/moderations", { input: content }, {
129
- headers: {
130
- Authorization: `Bearer ${this.openAiApiKey}`,
131
- },
132
- });
133
- return response.data;
134
- }
135
- /**
136
- * Checks if the ClamAV scan result indicates a malicious file.
137
- * @param result The ClamAV scan output.
138
- * @returns {boolean} True if the file is flagged, false otherwise.
139
- */
140
- isClamAVResultMalicious(result) {
141
- return result.includes("FOUND");
142
- }
143
- /**
144
- * Checks if the VirusTotal result indicates a malicious file.
145
- * @param result The VirusTotal scan result.
146
- * @returns {boolean} True if the file is flagged, false otherwise.
147
- */
148
- isVirusTotalResultMalicious(result) {
149
- // Check if VirusTotal flagged the file based on its multiple antivirus results
150
- return result.positives > 0;
151
- }
152
- /**
153
- * Checks if the OpenAI Moderation result indicates harmful content.
154
- * @param result The OpenAI Moderation result.
155
- * @returns {boolean} True if harmful content is detected, false otherwise.
156
- */
157
- isOpenAiResultMalicious(result) {
158
- return result.flagged === true;
159
- }
160
- /**
161
- * Deletes a file from the filesystem.
162
- * @param filePath The file to delete.
163
- */
164
- deleteFile(filePath) {
165
- fs_1.default.unlink(filePath, (err) => {
166
- if (err) {
167
- console.error(`Error deleting file: ${filePath}`, err);
168
- }
169
- else {
170
- console.log(`File ${filePath} was deleted successfully.`);
171
- }
172
- });
173
- }
174
- }
175
- exports.IllegalContentScanner = IllegalContentScanner;
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,85 +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.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;
@@ -1,11 +0,0 @@
1
- export declare class FileCache<T> {
2
- private cacheDir;
3
- constructor(relativeFilePath: string);
4
- private ensureDirectoryExists;
5
- private getCacheFilePath;
6
- get(key: string): T | null;
7
- set(key: string, data: T): void;
8
- delete(key: string): void;
9
- getCachedKeys(): string[];
10
- }
11
- //# sourceMappingURL=FileCache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FileCache.d.ts","sourceRoot":"","sources":["../../src/utils/FileCache.ts"],"names":[],"mappings":"AAIA,qBAAa,SAAS,CAAC,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAS;gBAEb,gBAAgB,EAAE,MAAM;IAMpC,OAAO,CAAC,qBAAqB;IAO7B,OAAO,CAAC,gBAAgB;IAKjB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAY1B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;IAO/B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IASzB,aAAa,IAAI,MAAM,EAAE;CAUjC"}
@@ -1,58 +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.FileCache = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const config_1 = require("./config");
10
- class FileCache {
11
- constructor(relativeFilePath) {
12
- this.cacheDir = path_1.default.join(config_1.DIG_FOLDER_PATH, relativeFilePath);
13
- this.ensureDirectoryExists();
14
- }
15
- // Ensure the directory exists or create it
16
- ensureDirectoryExists() {
17
- if (!fs_1.default.existsSync(this.cacheDir)) {
18
- fs_1.default.mkdirSync(this.cacheDir, { recursive: true });
19
- }
20
- }
21
- // Get the cache file path for the given key
22
- getCacheFilePath(key) {
23
- return path_1.default.join(this.cacheDir, `${key}.json`);
24
- }
25
- // Retrieve cached data by key
26
- get(key) {
27
- const cacheFilePath = this.getCacheFilePath(key);
28
- if (!fs_1.default.existsSync(cacheFilePath)) {
29
- return null;
30
- }
31
- const rawData = fs_1.default.readFileSync(cacheFilePath, "utf-8");
32
- return JSON.parse(rawData);
33
- }
34
- // Save data to the cache
35
- set(key, data) {
36
- const cacheFilePath = this.getCacheFilePath(key);
37
- const serializedData = JSON.stringify(data);
38
- fs_1.default.writeFileSync(cacheFilePath, serializedData);
39
- }
40
- // Delete cache data by key
41
- delete(key) {
42
- const cacheFilePath = this.getCacheFilePath(key);
43
- if (fs_1.default.existsSync(cacheFilePath)) {
44
- fs_1.default.unlinkSync(cacheFilePath);
45
- }
46
- }
47
- // Retrieve all cached keys in the directory
48
- getCachedKeys() {
49
- if (!fs_1.default.existsSync(this.cacheDir)) {
50
- return [];
51
- }
52
- return fs_1.default
53
- .readdirSync(this.cacheDir)
54
- .filter((file) => file.endsWith(".json"))
55
- .map((file) => file.replace(".json", ""));
56
- }
57
- }
58
- exports.FileCache = FileCache;
@@ -1,47 +0,0 @@
1
- import { Readable } from "stream";
2
- export declare class FileTransfer {
3
- private static certPath;
4
- private static keyPath;
5
- constructor();
6
- /** ------------------------ UPLOAD FUNCTIONALITY ------------------------ **/
7
- /**
8
- * Upload a file to the server using a stream.
9
- * @param filePath - Local path of the file.
10
- * @param uploadUrl - Server URL to upload the file.
11
- * @param headers - Additional headers for the request.
12
- * @returns Promise<void>
13
- */
14
- uploadFile(filePath: string, uploadUrl: string, headers: Record<string, string>): Promise<void>;
15
- /**
16
- * Perform a POST request.
17
- * @param url - The URL to POST to.
18
- * @param data - Data to send.
19
- * @param headers - Headers for the POST request.
20
- * @returns Promise<void>
21
- */
22
- postRequest(url: string, data: string, headers: Record<string, string>): Promise<void>;
23
- /** ------------------------ DOWNLOAD FUNCTIONALITY ------------------------ **/
24
- /**
25
- * Download data from a URL.
26
- * @param url - The URL to download data from.
27
- * @returns Promise<string>
28
- */
29
- downloadData(url: string): Promise<string>;
30
- /**
31
- * Stream data from a URL.
32
- * @param url - The URL to stream data from.
33
- * @returns Promise<Readable>
34
- */
35
- streamData(url: string): Promise<Readable>;
36
- /** ------------------------ HEAD REQUEST FUNCTIONALITY ------------------------ **/
37
- /**
38
- * Perform a HEAD request to check if a resource exists on the server.
39
- * @param url - The URL to check.
40
- * @returns Promise<{ success: boolean; headers?: Record<string, string> }>
41
- */
42
- headRequest(url: string): Promise<{
43
- success: boolean;
44
- headers?: Record<string, string>;
45
- }>;
46
- }
47
- //# sourceMappingURL=FileTransfer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FileTransfer.d.ts","sourceRoot":"","sources":["../../src/utils/FileTransfer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;;IAU/B,8EAA8E;IAE9E;;;;;;OAMG;IACU,UAAU,CACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;IA0ChB;;;;;;OAMG;IACU,WAAW,CACtB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;IAsChB,gFAAgF;IAEhF;;;;OAIG;IACU,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA0CvD;;;;OAIG;IACU,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAuCvD,oFAAoF;IAEpF;;;;OAIG;IACU,WAAW,CACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CA8BnE"}