@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,209 +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.FileTransfer = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const https_1 = __importDefault(require("https"));
9
- const url_1 = require("url");
10
- const ssl_1 = require("../utils/ssl");
11
- class FileTransfer {
12
- constructor() {
13
- if (!FileTransfer.certPath || !FileTransfer.keyPath) {
14
- const { certPath, keyPath } = (0, ssl_1.getOrCreateSSLCerts)();
15
- FileTransfer.certPath = certPath;
16
- FileTransfer.keyPath = keyPath;
17
- }
18
- }
19
- /** ------------------------ UPLOAD FUNCTIONALITY ------------------------ **/
20
- /**
21
- * Upload a file to the server using a stream.
22
- * @param filePath - Local path of the file.
23
- * @param uploadUrl - Server URL to upload the file.
24
- * @param headers - Additional headers for the request.
25
- * @returns Promise<void>
26
- */
27
- async uploadFile(filePath, uploadUrl, headers) {
28
- const fileStream = fs_1.default.createReadStream(filePath);
29
- const fileSize = fs_1.default.statSync(filePath).size;
30
- return new Promise((resolve, reject) => {
31
- const url = new url_1.URL(uploadUrl);
32
- const options = {
33
- hostname: url.hostname,
34
- port: url.port || 443,
35
- path: url.pathname,
36
- method: "PUT",
37
- headers: {
38
- ...headers,
39
- "Content-Type": "application/octet-stream",
40
- "Content-Length": fileSize,
41
- },
42
- key: fs_1.default.readFileSync(FileTransfer.keyPath),
43
- cert: fs_1.default.readFileSync(FileTransfer.certPath),
44
- rejectUnauthorized: false,
45
- };
46
- const req = https_1.default.request(options, (res) => {
47
- if (res.statusCode === 200) {
48
- resolve();
49
- }
50
- else {
51
- reject(new Error(`Upload failed with status ${res.statusCode}: ${res.statusMessage}`));
52
- }
53
- });
54
- req.on("error", (err) => reject(err));
55
- fileStream.pipe(req);
56
- fileStream.on("error", (err) => reject(err));
57
- });
58
- }
59
- /**
60
- * Perform a POST request.
61
- * @param url - The URL to POST to.
62
- * @param data - Data to send.
63
- * @param headers - Headers for the POST request.
64
- * @returns Promise<void>
65
- */
66
- async postRequest(url, data, headers) {
67
- return new Promise((resolve, reject) => {
68
- const urlObj = new url_1.URL(url);
69
- const options = {
70
- hostname: urlObj.hostname,
71
- port: urlObj.port || 443,
72
- path: urlObj.pathname,
73
- method: "POST",
74
- headers: {
75
- ...headers,
76
- "Content-Type": "application/json",
77
- "Content-Length": Buffer.byteLength(data),
78
- },
79
- key: fs_1.default.readFileSync(FileTransfer.keyPath),
80
- cert: fs_1.default.readFileSync(FileTransfer.certPath),
81
- rejectUnauthorized: false,
82
- };
83
- const req = https_1.default.request(options, (res) => {
84
- if (res.statusCode === 200) {
85
- resolve();
86
- }
87
- else {
88
- reject(new Error(`POST request failed with status ${res.statusCode}: ${res.statusMessage}`));
89
- }
90
- });
91
- req.on("error", (err) => reject(err));
92
- req.write(data);
93
- req.end();
94
- });
95
- }
96
- /** ------------------------ DOWNLOAD FUNCTIONALITY ------------------------ **/
97
- /**
98
- * Download data from a URL.
99
- * @param url - The URL to download data from.
100
- * @returns Promise<string>
101
- */
102
- async downloadData(url) {
103
- return new Promise((resolve, reject) => {
104
- const urlObj = new url_1.URL(url);
105
- const options = {
106
- hostname: urlObj.hostname,
107
- port: urlObj.port || 443,
108
- path: urlObj.pathname + urlObj.search,
109
- method: "GET",
110
- key: fs_1.default.readFileSync(FileTransfer.keyPath),
111
- cert: fs_1.default.readFileSync(FileTransfer.certPath),
112
- rejectUnauthorized: false,
113
- };
114
- const req = https_1.default.request(options, (res) => {
115
- let data = "";
116
- if (res.statusCode === 200) {
117
- res.on("data", (chunk) => (data += chunk));
118
- res.on("end", () => resolve(data));
119
- }
120
- else if (res.statusCode === 301 || res.statusCode === 302) {
121
- const redirectUrl = res.headers.location;
122
- if (redirectUrl) {
123
- this.downloadData(redirectUrl).then(resolve).catch(reject);
124
- }
125
- else {
126
- reject(new Error("Redirected without a location header"));
127
- }
128
- }
129
- else {
130
- reject(new Error(`Failed to retrieve data from ${url}. Status code: ${res.statusCode}`));
131
- }
132
- });
133
- req.on("error", (error) => reject(error));
134
- req.end();
135
- });
136
- }
137
- /**
138
- * Stream data from a URL.
139
- * @param url - The URL to stream data from.
140
- * @returns Promise<Readable>
141
- */
142
- async streamData(url) {
143
- return new Promise((resolve, reject) => {
144
- const urlObj = new url_1.URL(url);
145
- const options = {
146
- hostname: urlObj.hostname,
147
- port: urlObj.port || 443,
148
- path: urlObj.pathname + urlObj.search,
149
- method: "GET",
150
- key: fs_1.default.readFileSync(FileTransfer.keyPath),
151
- cert: fs_1.default.readFileSync(FileTransfer.certPath),
152
- rejectUnauthorized: false,
153
- };
154
- const req = https_1.default.request(options, (res) => {
155
- if (res.statusCode === 200) {
156
- resolve(res); // Return the readable stream
157
- }
158
- else if (res.statusCode === 301 || res.statusCode === 302) {
159
- const redirectUrl = res.headers.location;
160
- if (redirectUrl) {
161
- this.streamData(redirectUrl).then(resolve).catch(reject);
162
- }
163
- else {
164
- reject(new Error("Redirected without a location header"));
165
- }
166
- }
167
- else {
168
- reject(new Error(`Failed to retrieve stream from ${url}. Status code: ${res.statusCode}`));
169
- }
170
- });
171
- req.on("error", (error) => reject(error));
172
- req.end();
173
- });
174
- }
175
- /** ------------------------ HEAD REQUEST FUNCTIONALITY ------------------------ **/
176
- /**
177
- * Perform a HEAD request to check if a resource exists on the server.
178
- * @param url - The URL to check.
179
- * @returns Promise<{ success: boolean; headers?: Record<string, string> }>
180
- */
181
- async headRequest(url) {
182
- return new Promise((resolve, reject) => {
183
- const urlObj = new url_1.URL(url);
184
- const options = {
185
- hostname: urlObj.hostname,
186
- port: urlObj.port || 443,
187
- path: urlObj.pathname,
188
- method: "HEAD",
189
- key: fs_1.default.readFileSync(FileTransfer.keyPath),
190
- cert: fs_1.default.readFileSync(FileTransfer.certPath),
191
- rejectUnauthorized: false,
192
- };
193
- const req = https_1.default.request(options, (res) => {
194
- if (res.statusCode === 200) {
195
- resolve({
196
- success: true,
197
- headers: res.headers,
198
- });
199
- }
200
- else {
201
- resolve({ success: false });
202
- }
203
- });
204
- req.on("error", (err) => reject(err));
205
- req.end();
206
- });
207
- }
208
- }
209
- exports.FileTransfer = FileTransfer;
@@ -1,11 +0,0 @@
1
- export declare class NconfManager {
2
- private configFilePath;
3
- constructor(relativePath: string);
4
- private initializeConfig;
5
- getConfigValue<T>(key: string): Promise<T | null>;
6
- setConfigValue(key: string, value: any): Promise<void>;
7
- deleteConfigValue(key: string): Promise<void>;
8
- configExists(): Promise<boolean>;
9
- getFullConfig(): Promise<Record<string, any>>;
10
- }
11
- //# sourceMappingURL=NconfManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NconfManager.d.ts","sourceRoot":"","sources":["../../src/utils/NconfManager.ts"],"names":[],"mappings":"AAQA,qBAAa,YAAY;IACvB,OAAO,CAAC,cAAc,CAAS;gBAEnB,YAAY,EAAE,MAAM;YAKlB,gBAAgB;IAejB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAMjD,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAStD,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAKhC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAI3D"}
@@ -1,56 +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.NconfManager = void 0;
7
- const nconf_1 = __importDefault(require("nconf"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const path_1 = __importDefault(require("path"));
10
- const config_1 = require("./config");
11
- const Environment_1 = require("./Environment");
12
- const CONF_FOLDER_PATH = Environment_1.Environment.DIG_FOLDER_PATH || config_1.USER_DIR_PATH;
13
- class NconfManager {
14
- constructor(relativePath) {
15
- this.configFilePath = path_1.default.join(CONF_FOLDER_PATH, relativePath);
16
- this.initializeConfig();
17
- }
18
- async initializeConfig() {
19
- const directory = path_1.default.dirname(this.configFilePath);
20
- if (!(await fs_extra_1.default.pathExists(directory))) {
21
- await fs_extra_1.default.mkdirp(directory);
22
- console.log("Directory created:", directory);
23
- }
24
- if (!(await fs_extra_1.default.pathExists(this.configFilePath))) {
25
- await fs_extra_1.default.writeFile(this.configFilePath, "{}");
26
- console.log("Configuration file created:", this.configFilePath);
27
- }
28
- nconf_1.default.file({ file: this.configFilePath });
29
- }
30
- async getConfigValue(key) {
31
- await this.initializeConfig();
32
- const value = nconf_1.default.get(key);
33
- return value !== undefined ? value : null;
34
- }
35
- async setConfigValue(key, value) {
36
- await this.initializeConfig();
37
- nconf_1.default.set(key, value);
38
- await new Promise((resolve, reject) => nconf_1.default.save((err) => (err ? reject(err) : resolve(undefined))));
39
- console.log(`${key} saved to config file.`);
40
- }
41
- async deleteConfigValue(key) {
42
- await this.initializeConfig();
43
- nconf_1.default.clear(key);
44
- await new Promise((resolve, reject) => nconf_1.default.save((err) => (err ? reject(err) : resolve(undefined))));
45
- console.log(`${key} deleted from config file.`);
46
- }
47
- async configExists() {
48
- return await fs_extra_1.default.pathExists(this.configFilePath);
49
- }
50
- // Method to get the full configuration as a key-value object
51
- async getFullConfig() {
52
- await this.initializeConfig();
53
- return nconf_1.default.get() || {};
54
- }
55
- }
56
- exports.NconfManager = NconfManager;
@@ -1,45 +0,0 @@
1
- /**
2
- * Class for managing file archiving, extraction, and working with the 'data' folder.
3
- */
4
- declare class StoreArchiveManager {
5
- private archivePath;
6
- private outputStream;
7
- /**
8
- * Constructor that initializes the FileArchiveManager with a given path.
9
- * @param archivePath - The path where the archive will be created.
10
- */
11
- constructor(archivePath: string);
12
- /**
13
- * Creates the archive at the specified path.
14
- * @returns Promise<void>
15
- */
16
- createArchive(): Promise<void>;
17
- /**
18
- * Streams a file into the archive.
19
- * @param filePath - The file to add to the archive.
20
- * @param fileNameInArchive - The name the file should have inside the archive.
21
- * @returns Promise<void>
22
- */
23
- addFileToArchive(filePath: string, fileNameInArchive: string): Promise<void>;
24
- /**
25
- * Extracts a file from the archive to a specified directory.
26
- * @param extractToPath - The path where the file should be extracted.
27
- * @returns Promise<void>
28
- */
29
- extractArchive(extractToPath: string): Promise<void>;
30
- /**
31
- * Merges another archive into the current one.
32
- * Extracts files from the given archive and adds them into the current archive.
33
- * @param archiveToMergePath - The path of the archive to be merged.
34
- * @returns Promise<void>
35
- */
36
- mergeArchive(archiveToMergePath: string): Promise<void>;
37
- /**
38
- * Adds extracted files to the current archive.
39
- * @param extractedFolderPath - The path of the folder containing extracted files.
40
- * @returns Promise<void>
41
- */
42
- private addExtractedFilesToArchive;
43
- }
44
- export default StoreArchiveManager;
45
- //# sourceMappingURL=StoreArchiveManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StoreArchiveManager.d.ts","sourceRoot":"","sources":["../../src/utils/StoreArchiveManager.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,cAAM,mBAAmB;IACrB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAwB;IAE5C;;;OAGG;gBACS,WAAW,EAAE,MAAM;IAK/B;;;OAGG;IACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB3C;;;;;OAKG;IACU,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBzF;;;;OAIG;IACU,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASjE;;;;;OAKG;IACU,YAAY,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiCpE;;;;OAIG;YACW,0BAA0B;CAkB3C;AAED,eAAe,mBAAmB,CAAC"}
@@ -1,153 +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
- const fs = __importStar(require("fs"));
27
- const path = __importStar(require("path"));
28
- const archiver = __importStar(require("archiver"));
29
- const unzipper = __importStar(require("unzipper"));
30
- /**
31
- * Class for managing file archiving, extraction, and working with the 'data' folder.
32
- */
33
- class StoreArchiveManager {
34
- /**
35
- * Constructor that initializes the FileArchiveManager with a given path.
36
- * @param archivePath - The path where the archive will be created.
37
- */
38
- constructor(archivePath) {
39
- this.archivePath = archivePath;
40
- this.outputStream = null;
41
- }
42
- /**
43
- * Creates the archive at the specified path.
44
- * @returns Promise<void>
45
- */
46
- async createArchive() {
47
- return new Promise((resolve, reject) => {
48
- this.outputStream = fs.createWriteStream(this.archivePath);
49
- // @ts-ignore
50
- const archive = archiver('zip', {
51
- zlib: { level: 9 }
52
- });
53
- this.outputStream.on('close', () => {
54
- console.log(`${archive.pointer()} total bytes`);
55
- console.log('Archive has been finalized and output file descriptor has closed.');
56
- resolve();
57
- });
58
- archive.on('error', (err) => {
59
- reject(err);
60
- });
61
- archive.pipe(this.outputStream);
62
- });
63
- }
64
- /**
65
- * Streams a file into the archive.
66
- * @param filePath - The file to add to the archive.
67
- * @param fileNameInArchive - The name the file should have inside the archive.
68
- * @returns Promise<void>
69
- */
70
- async addFileToArchive(filePath, fileNameInArchive) {
71
- if (!this.outputStream) {
72
- throw new Error('Archive not yet created.');
73
- }
74
- return new Promise((resolve, reject) => {
75
- // @ts-ignore
76
- const archive = archiver('zip', { zlib: { level: 9 } });
77
- const fileStream = fs.createReadStream(filePath);
78
- archive.append(fileStream, { name: fileNameInArchive });
79
- archive.finalize();
80
- archive.on('finish', resolve);
81
- archive.on('error', reject);
82
- });
83
- }
84
- /**
85
- * Extracts a file from the archive to a specified directory.
86
- * @param extractToPath - The path where the file should be extracted.
87
- * @returns Promise<void>
88
- */
89
- async extractArchive(extractToPath) {
90
- return new Promise((resolve, reject) => {
91
- fs.createReadStream(this.archivePath)
92
- .pipe(unzipper.Extract({ path: extractToPath }))
93
- .on('close', resolve)
94
- .on('error', reject);
95
- });
96
- }
97
- /**
98
- * Merges another archive into the current one.
99
- * Extracts files from the given archive and adds them into the current archive.
100
- * @param archiveToMergePath - The path of the archive to be merged.
101
- * @returns Promise<void>
102
- */
103
- async mergeArchive(archiveToMergePath) {
104
- if (!this.outputStream) {
105
- throw new Error('Archive not yet created.');
106
- }
107
- return new Promise((resolve, reject) => {
108
- const tempExtractPath = path.join(__dirname, 'tempExtract');
109
- // Ensure the temp directory exists
110
- if (!fs.existsSync(tempExtractPath)) {
111
- fs.mkdirSync(tempExtractPath);
112
- }
113
- // Step 1: Extract the contents of the archive to be merged
114
- fs.createReadStream(archiveToMergePath)
115
- .pipe(unzipper.Extract({ path: tempExtractPath }))
116
- .on('close', async () => {
117
- try {
118
- // Step 2: Read the extracted files and add them to the current archive
119
- await this.addExtractedFilesToArchive(tempExtractPath);
120
- // Clean up: Delete the temporary directory
121
- fs.rmSync(tempExtractPath, { recursive: true, force: true });
122
- resolve();
123
- }
124
- catch (error) {
125
- reject(error);
126
- }
127
- })
128
- .on('error', reject);
129
- });
130
- }
131
- /**
132
- * Adds extracted files to the current archive.
133
- * @param extractedFolderPath - The path of the folder containing extracted files.
134
- * @returns Promise<void>
135
- */
136
- async addExtractedFilesToArchive(extractedFolderPath) {
137
- const files = fs.readdirSync(extractedFolderPath);
138
- for (const file of files) {
139
- const fullFilePath = path.join(extractedFolderPath, file);
140
- const stat = fs.statSync(fullFilePath);
141
- if (stat.isFile()) {
142
- const relativePath = path.relative(extractedFolderPath, fullFilePath);
143
- // Add the file into the current archive
144
- await this.addFileToArchive(fullFilePath, relativePath);
145
- }
146
- else if (stat.isDirectory()) {
147
- // Recursively add files from nested directories
148
- await this.addExtractedFilesToArchive(fullFilePath);
149
- }
150
- }
151
- }
152
- }
153
- exports.default = StoreArchiveManager;
@@ -1,9 +0,0 @@
1
- /**
2
- * Processes items in sequential batches with a concurrency limit.
3
- * @param {number} limit - The maximum number of concurrent executions per batch.
4
- * @param {Array<T>} items - The array of items to process.
5
- * @param {(item: T) => Promise<R>} iteratorFn - The async function to apply to each item.
6
- * @returns {Promise<Array<R>>} - A promise that resolves when all items have been processed.
7
- */
8
- export declare function asyncPool<T, R>(limit: number, items: T[], iteratorFn: (item: T) => Promise<R>): Promise<R[]>;
9
- //# sourceMappingURL=asyncPool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"asyncPool.d.ts","sourceRoot":"","sources":["../../src/utils/asyncPool.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC,EAChC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,CAAC,EAAE,EACV,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAClC,OAAO,CAAC,CAAC,EAAE,CAAC,CAgBd"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asyncPool = asyncPool;
4
- /**
5
- * Processes items in sequential batches with a concurrency limit.
6
- * @param {number} limit - The maximum number of concurrent executions per batch.
7
- * @param {Array<T>} items - The array of items to process.
8
- * @param {(item: T) => Promise<R>} iteratorFn - The async function to apply to each item.
9
- * @returns {Promise<Array<R>>} - A promise that resolves when all items have been processed.
10
- */
11
- async function asyncPool(limit, items, iteratorFn) {
12
- const ret = [];
13
- for (let i = 0; i < items.length; i += limit) {
14
- const batchItems = items.slice(i, i + limit);
15
- const batchPromises = batchItems.map((item) => iteratorFn(item));
16
- // Wait for the current batch to complete before starting the next one
17
- const batchResults = await Promise.all(batchPromises);
18
- ret.push(...batchResults);
19
- // Optional: add a cooldown between batches
20
- // await new Promise((resolve) => setTimeout(resolve, 500));
21
- }
22
- return ret;
23
- }
@@ -1,68 +0,0 @@
1
- import { DigConfig } from "../types";
2
- export declare const NETWORK_AGG_SIG_DATA = "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb";
3
- export declare const MAIN_NET_GENISES_CHALLENGE = "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb";
4
- export declare const MIN_HEIGHT = 5777842;
5
- export declare const MIN_HEIGHT_HEADER_HASH = "b29a4daac2434fd17a36e15ba1aac5d65012d4a66f99bed0bf2b5342e92e562c";
6
- export declare const DIG_FOLDER_PATH: string;
7
- export declare const STORE_PATH: string;
8
- export declare const USER_DIR_PATH: string;
9
- export declare const CONFIG_FILE_PATH: string;
10
- export declare const getHeightFilePath: (storeId: string) => string;
11
- export declare const createInitialConfig: () => void;
12
- export declare const setRemote: (remote: string) => void;
13
- export declare const setActiveStore: (storeId: string) => void;
14
- export declare const getCoinState: (storeId: string) => {
15
- metadata: {
16
- rootHash: string;
17
- bytes: string;
18
- label: string;
19
- description: string;
20
- };
21
- };
22
- /**
23
- * Retrieves the list of valid store folders.
24
- * If the STORE_PATH directory does not exist, it is created.
25
- *
26
- * @returns {string[]} An array of valid store folder names.
27
- */
28
- export declare const getStoresList: () => string[];
29
- /**
30
- * Retrieves the active_store value from the dig.config.json file within the .dig directory.
31
- * If not set, checks the subfolders and prompts the user to choose the active one if necessary.
32
- *
33
- * @returns {Promise<Buffer | null>} The active_store value as a Buffer if found, otherwise null.
34
- */
35
- export declare const getActiveStoreId: () => Promise<Buffer | null>;
36
- /**
37
- * Loads the dig.config.json file from the base directory.
38
- *
39
- * @param baseDir - The base directory where the config file is located.
40
- * @returns {DigConfig} - The parsed configuration object.
41
- * @throws Will throw an error if the config file does not exist or cannot be parsed.
42
- */
43
- export declare const loadDigConfig: (baseDir: string) => DigConfig;
44
- /**
45
- * Ensures that the dig.config.json file exists in the base directory.
46
- * If the file doesn't exist, it creates it with the deploy_dir set to "./dist".
47
- *
48
- * @param baseDir - The base directory where the config file should be located.
49
- * @returns {DigConfig} - The configuration object.
50
- */
51
- export declare const ensureDigConfig: (baseDir: string) => DigConfig;
52
- /**
53
- * Sets a key-value pair in the dig.config.json file.
54
- * If the file or key doesn't exist, it will create them.
55
- *
56
- * @param baseDir - The base directory where the config file is located.
57
- * @param key - The configuration key to set.
58
- * @param value - The value to set for the given key.
59
- */
60
- export declare const setDigConfigKey: (baseDir: string, key: string, value: any) => void;
61
- /**
62
- * Deletes a key from the dig.config.json file.
63
- *
64
- * @param baseDir - The base directory where the config file is located.
65
- * @param key - The configuration key to delete.
66
- */
67
- export declare const deleteDigConfigKey: (baseDir: string, key: string) => void;
68
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAMrC,eAAO,MAAM,oBAAoB,qEACmC,CAAC;AAErE,eAAO,MAAM,0BAA0B,qEAAuB,CAAC;AAE/D,eAAO,MAAM,UAAU,UAAU,CAAC;AAClC,eAAO,MAAM,sBAAsB,qEACiC,CAAC;AAErE,eAAO,MAAM,eAAe,QACqC,CAAC;AAElE,eAAO,MAAM,UAAU,QAAuC,CAAC;AAE/D,eAAO,MAAM,aAAa,QAAkC,CAAC;AAC7D,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E,eAAO,MAAM,iBAAiB,YAAa,MAAM,KAAG,MACL,CAAC;AAEhD,eAAO,MAAM,mBAAmB,QAAO,IAItC,CAAC;AAEF,eAAO,MAAM,SAAS,WAAY,MAAM,KAAG,IAQ1C,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,MAAM,KAAG,IAQhD,CAAC;AAqBF,eAAO,MAAM,YAAY,YACd,MAAM,KACd;IACD,QAAQ,EAAE;QACR,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CAYH,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAAO,MAAM,EAYtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAa,OAAO,CAAC,MAAM,GAAG,IAAI,CAkC9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,SAS/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,YAAa,MAAM,KAAG,SAoBjD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,YACjB,MAAM,OACV,MAAM,SACJ,GAAG,KACT,IAMF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,YAAa,MAAM,OAAO,MAAM,KAAG,IAcjE,CAAC"}