@dignetwork/dig-sdk 0.0.1-alpha.17 → 0.0.1-alpha.170

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 (84) hide show
  1. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +10 -1
  2. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -1
  3. package/dist/DataIntegrityTree/DataIntegrityTree.js +77 -10
  4. package/dist/DigNetwork/ContentServer.d.ts +24 -5
  5. package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
  6. package/dist/DigNetwork/ContentServer.js +239 -27
  7. package/dist/DigNetwork/DigNetwork.d.ts +15 -9
  8. package/dist/DigNetwork/DigNetwork.d.ts.map +1 -1
  9. package/dist/DigNetwork/DigNetwork.js +129 -189
  10. package/dist/DigNetwork/DigPeer.d.ts +8 -3
  11. package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
  12. package/dist/DigNetwork/DigPeer.js +72 -115
  13. package/dist/DigNetwork/IncentiveServer.d.ts.map +1 -1
  14. package/dist/DigNetwork/IncentiveServer.js +6 -5
  15. package/dist/DigNetwork/PropagationServer.d.ts +88 -33
  16. package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
  17. package/dist/DigNetwork/PropagationServer.js +636 -357
  18. package/dist/blockchain/DataStore.d.ts +25 -7
  19. package/dist/blockchain/DataStore.d.ts.map +1 -1
  20. package/dist/blockchain/DataStore.js +115 -159
  21. package/dist/blockchain/DataStoreSerializer.d.ts +1 -1
  22. package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -1
  23. package/dist/blockchain/FullNodePeer.d.ts +95 -10
  24. package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
  25. package/dist/blockchain/FullNodePeer.js +324 -115
  26. package/dist/blockchain/ServerCoin.d.ts +13 -5
  27. package/dist/blockchain/ServerCoin.d.ts.map +1 -1
  28. package/dist/blockchain/ServerCoin.js +90 -28
  29. package/dist/blockchain/StoreMonitorRegistry.d.ts +85 -0
  30. package/dist/blockchain/StoreMonitorRegistry.d.ts.map +1 -0
  31. package/dist/blockchain/StoreMonitorRegistry.js +238 -0
  32. package/dist/blockchain/Wallet.d.ts +2 -2
  33. package/dist/blockchain/Wallet.d.ts.map +1 -1
  34. package/dist/blockchain/Wallet.js +50 -18
  35. package/dist/blockchain/coins.d.ts +1 -2
  36. package/dist/blockchain/coins.d.ts.map +1 -1
  37. package/dist/blockchain/coins.js +1 -55
  38. package/dist/blockchain/index.d.ts +1 -0
  39. package/dist/blockchain/index.d.ts.map +1 -1
  40. package/dist/blockchain/index.js +1 -0
  41. package/dist/types.d.ts +2 -0
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/utils/ContentScanner.d.ts +63 -0
  44. package/dist/utils/ContentScanner.d.ts.map +1 -0
  45. package/dist/utils/ContentScanner.js +175 -0
  46. package/dist/utils/Environment.d.ts +21 -0
  47. package/dist/utils/Environment.d.ts.map +1 -0
  48. package/dist/utils/Environment.js +93 -0
  49. package/dist/utils/FileCache.d.ts +1 -1
  50. package/dist/utils/FileCache.d.ts.map +1 -1
  51. package/dist/utils/FileCache.js +2 -2
  52. package/dist/utils/FileTransfer.d.ts +47 -0
  53. package/dist/utils/FileTransfer.d.ts.map +1 -0
  54. package/dist/utils/FileTransfer.js +209 -0
  55. package/dist/utils/NconfManager.js +2 -1
  56. package/dist/utils/PeerRanker.d.ts +55 -0
  57. package/dist/utils/PeerRanker.d.ts.map +1 -0
  58. package/dist/utils/PeerRanker.js +186 -0
  59. package/dist/utils/StoreArchiveManager.d.ts +45 -0
  60. package/dist/utils/StoreArchiveManager.d.ts.map +1 -0
  61. package/dist/utils/StoreArchiveManager.js +153 -0
  62. package/dist/utils/config.d.ts +4 -3
  63. package/dist/utils/config.d.ts.map +1 -1
  64. package/dist/utils/config.js +13 -8
  65. package/dist/utils/directoryUtils.d.ts +16 -0
  66. package/dist/utils/directoryUtils.d.ts.map +1 -1
  67. package/dist/utils/directoryUtils.js +66 -0
  68. package/dist/utils/index.d.ts +3 -1
  69. package/dist/utils/index.d.ts.map +1 -1
  70. package/dist/utils/index.js +3 -1
  71. package/dist/utils/merkle.d.ts +2 -0
  72. package/dist/utils/merkle.d.ts.map +1 -0
  73. package/dist/utils/merkle.js +28 -0
  74. package/dist/utils/network.d.ts +2 -1
  75. package/dist/utils/network.d.ts.map +1 -1
  76. package/dist/utils/network.js +40 -15
  77. package/dist/utils/promiseUtils.d.ts +19 -0
  78. package/dist/utils/promiseUtils.d.ts.map +1 -0
  79. package/dist/utils/promiseUtils.js +43 -0
  80. package/dist/utils/ssl.js +2 -2
  81. package/package.json +18 -5
  82. package/dist/utils/deltaUtils.d.ts +0 -2
  83. package/dist/utils/deltaUtils.d.ts.map +0 -1
  84. package/dist/utils/deltaUtils.js +0 -83
@@ -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;AAEhD,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"}
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,41 +1,96 @@
1
- import { Readable } from "stream";
1
+ import https from "https";
2
+ import { PassThrough } from "stream";
2
3
  export declare class PropagationServer {
3
- private ipAddress;
4
- private storeId;
5
- private static certPath;
6
- private static keyPath;
4
+ storeId: string;
5
+ sessionId: string;
6
+ publicKey: string;
7
+ wallet: any;
8
+ ipAddress: string;
9
+ certPath: string;
10
+ keyPath: string;
11
+ username: string | undefined;
12
+ password: string | undefined;
7
13
  private static readonly port;
8
- private static readonly maxRetries;
9
- private static readonly initialDelay;
10
- private static readonly maxDelay;
11
- private static readonly delayMultiplier;
14
+ private static readonly inactivityTimeout;
12
15
  constructor(ipAddress: string, storeId: string);
13
- pushFile(filePath: string, relativePath: string): Promise<void>;
14
- subscribeToStore(): Promise<void>;
15
- unsubscribeFromStore(): Promise<void>;
16
- getStoreStatus(): Promise<any>;
17
- streamStoreData(dataPath: string): Promise<Readable>;
18
- getStoreData(dataPath: string): Promise<string>;
19
- getStatus(): Promise<{
20
- synced: boolean;
16
+ /**
17
+ * Initialize the Wallet instance.
18
+ */
19
+ initializeWallet(): Promise<void>;
20
+ /**
21
+ * Create an Axios HTTPS Agent with self-signed certificate allowance.
22
+ */
23
+ createHttpsAgent(): https.Agent;
24
+ /**
25
+ * Ping the current peer about an update to the store, passing rootHash.
26
+ * @param rootHash - The root hash for the store update.
27
+ */
28
+ getMyPublicIp(rootHash: string): Promise<void>;
29
+ /**
30
+ * Ping the current peer about an update to the store, passing rootHash.
31
+ * If the combination of ipAddress-storeId-rootHash is cached as "successfully synced", skip the request.
32
+ * @param rootHash - The root hash for the store update.
33
+ */
34
+ pingUpdate(rootHash: string): Promise<void>;
35
+ /**
36
+ * Adds a custom inactivity timeout for large file transfers.
37
+ */
38
+ addInactivityTimeout(stream: PassThrough, timeoutMs: number): PassThrough;
39
+ /**
40
+ * Checks if the store exists and optionally if a specific rootHash exists.
41
+ * Utilizes caching to improve performance.
42
+ *
43
+ * @param rootHash - (Optional) The root hash to check.
44
+ * @returns A promise that resolves to an object containing store existence and root hash existence.
45
+ */
46
+ checkStoreExists(rootHash?: string): Promise<{
47
+ storeExists: boolean;
48
+ rootHashExists: boolean;
21
49
  }>;
22
- headStore(): Promise<boolean>;
23
- isStoreSynced(): Promise<boolean>;
24
- getUploadDetails(): Promise<{
50
+ /**
51
+ * Start an upload session by sending a POST request with the rootHash.dat file.
52
+ */
53
+ startUploadSession(rootHash: string): Promise<void>;
54
+ /**
55
+ * Request a nonce for a file by sending a HEAD request to the server.
56
+ */
57
+ getFileNonce(filename: string): Promise<{
25
58
  nonce: string;
26
- lastUploadedHash: string;
27
- generationIndex: number;
28
- username: string;
29
- password: string;
59
+ fileExists: boolean;
30
60
  }>;
31
- private postRequest;
32
- private fetchUploadDetails;
33
- private uploadFileDirect;
34
- private retryOperation;
35
- private fetch;
36
- private head;
37
- private fetchJson;
38
- private createReadStreamWithRetries;
39
- private createReadStream;
61
+ /**
62
+ * Upload a file to the server by sending a PUT request.
63
+ * Logs progress using a local cli-progress bar.
64
+ */
65
+ uploadFile(label: string, dataPath: string, uncompress?: boolean): Promise<void>;
66
+ /**
67
+ * Commit the upload session by sending a POST request to the server.
68
+ */
69
+ commitUploadSession(): Promise<any>;
70
+ /**
71
+ * Static function to handle the entire upload process for multiple files based on rootHash.
72
+ */
73
+ static uploadStore(storeId: string, rootHash: string, ipAddress: string): Promise<void>;
74
+ /**
75
+ * Fetch a file from the server by sending a GET request and return its content in memory.
76
+ * Logs progress using a local cli-progress bar.
77
+ */
78
+ fetchFile(dataPath: string): Promise<Buffer>;
79
+ /**
80
+ * Get details of a file, including whether it exists and its size.
81
+ */
82
+ getFileDetails(dataPath: string, rootHash: string): Promise<{
83
+ exists: boolean;
84
+ size: number;
85
+ }>;
86
+ /**
87
+ * Download a file from the server by sending a GET request.
88
+ * Logs progress using a local cli-progress bar.
89
+ */
90
+ downloadFile(label: string, dataPath: string, rootHash: string, baseDir: string): Promise<void>;
91
+ /**
92
+ * Static function to handle downloading multiple files from a DataStore based on file paths.
93
+ */
94
+ static downloadStore(storeId: string, rootHash: string, ipAddress: string): Promise<void>;
40
95
  }
41
96
  //# sourceMappingURL=PropagationServer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,qBAAa,iBAAiB;IAC5B,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;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAK;IACvC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAQ;IAC5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAS;IACzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAO;gBAElC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAYjC,QAAQ,CAAC,QAAQ,E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