@dignetwork/dig-sdk 0.0.1-alpha.73 → 0.0.1-alpha.76

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.
@@ -1 +1 @@
1
- {"version":3,"file":"DigNetwork.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigNetwork.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,aAAa,CAA2B;gBAEpC,OAAO,EAAE,MAAM;WAOP,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAQhD,oBAAoB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,GAAG,CAAC,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAC7B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;WAyDZ,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5C,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;YAyGlC,mBAAmB;IAWpB,qBAAqB,CAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,IAAI,CAAC;CA2CjB"}
1
+ {"version":3,"file":"DigNetwork.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigNetwork.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,aAAa,CAA2B;gBAEpC,OAAO,EAAE,MAAM;WAOP,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAQhD,oBAAoB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,GAAG,CAAC,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAC7B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;WAyDZ,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5C,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;YA0GlC,mBAAmB;IAWpB,qBAAqB,CAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,IAAI,CAAC;CA2CjB"}
@@ -121,8 +121,8 @@ class DigNetwork {
121
121
  // Find a peer with the store and root hash
122
122
  selectedPeer = await DigNetwork.findPeerWithStoreKey(this.dataStore.StoreId, rootInfo.root_hash, undefined, peerBlackList);
123
123
  if (!selectedPeer) {
124
- console.error(`No peer found with root hash ${rootInfo.root_hash}. Skipping download.`);
125
- break; // Exit loop if no more peers are found
124
+ console.error(`No peer found with root hash ${rootInfo.root_hash}. Abort download.`);
125
+ throw new Error("No peer found with root hash.");
126
126
  }
127
127
  // Ensure the selected peer has the store by checking with a HEAD request
128
128
  const { storeExists, rootHashExists } = await selectedPeer.propagationServer.checkStoreExists(rootInfo.root_hash);
@@ -1 +1 @@
1
- {"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,OAAO,CAAC;AAoB1B,qBAAa,iBAAiB;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,C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Q,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA0ElD;;OAEG;IACG,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA0B7C;;;OAGG;IACG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IA+ElD;;OAEG;WACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CAkDpB"}
@@ -42,6 +42,7 @@ const config_1 = require("../utils/config");
42
42
  const hashUtils_1 = require("../utils/hashUtils");
43
43
  const nanospinner_1 = require("nanospinner");
44
44
  const progress_stream_1 = __importDefault(require("progress-stream"));
45
+ const stream_1 = require("stream");
45
46
  // Helper function to trim long filenames with ellipsis and ensure consistent padding
46
47
  function formatFilename(filename, maxLength = 30) {
47
48
  if (!filename) {
@@ -99,12 +100,12 @@ class PropagationServer {
99
100
  const rootHashExists = response.headers["x-has-root-hash"] === "true";
100
101
  if (storeExists) {
101
102
  spinner.success({
102
- text: (0, colorette_1.green)(`Store ${this.storeId} exists on peer!`),
103
+ text: (0, colorette_1.green)(`Store ${this.storeId} exists on peer: ${this.ipAddress}`),
103
104
  });
104
105
  }
105
106
  else {
106
107
  spinner.error({
107
- text: (0, colorette_1.red)(`Store ${this.storeId} does not exist. Credentials will be required to push.`),
108
+ text: (0, colorette_1.yellow)(`Store ${this.storeId} does not exist on ${this.ipAddress}. Credentials will be required to push.`),
108
109
  });
109
110
  }
110
111
  return { storeExists, rootHashExists };
@@ -147,7 +148,7 @@ class PropagationServer {
147
148
  const response = await axios_1.default.post(url, formData, config);
148
149
  this.sessionId = response.data.sessionId;
149
150
  spinner.success({
150
- text: (0, colorette_1.green)(`Upload session started for DataStore ${this.storeId} with session ID ${this.sessionId}`),
151
+ text: (0, colorette_1.green)(`Upload session started for Root Hash: ${(0, colorette_1.cyan)(rootHash)} with session ID ${this.sessionId}`),
151
152
  });
152
153
  }
153
154
  catch (error) {
@@ -197,7 +198,7 @@ class PropagationServer {
197
198
  try {
198
199
  // Create a new progress bar for the file
199
200
  progressBar = new cli_progress_1.default.SingleBar({
200
- format: `${(0, colorette_1.blue)('[{bar}]')} | ${(0, colorette_1.yellow)('{filename}')} | {percentage}% | {value}/{total} bytes`,
201
+ format: `${(0, colorette_1.blue)("[{bar}]")} | ${(0, colorette_1.yellow)("{filename}")} | {percentage}% | {value}/{total} bytes`,
201
202
  hideCursor: true,
202
203
  barsize: 30,
203
204
  align: "left",
@@ -207,8 +208,10 @@ class PropagationServer {
207
208
  clearOnComplete: false,
208
209
  }, cli_progress_1.default.Presets.legacy);
209
210
  progressBar.start(fileSize, 0, {
210
- filename: formatFilename(path_1.default.basename(label)),
211
+ filename: formatFilename(label),
211
212
  });
213
+ // Create the read stream
214
+ const fileReadStream = fs_1.default.createReadStream(filePath);
212
215
  // Create a progress stream
213
216
  const progressStream = (0, progress_stream_1.default)({
214
217
  length: fileSize,
@@ -217,13 +220,13 @@ class PropagationServer {
217
220
  progressStream.on("progress", (progress) => {
218
221
  progressBar.update(progress.transferred);
219
222
  });
220
- // Create a read stream and pipe it through the progress stream
221
- const fileReadStream = fs_1.default
222
- .createReadStream(filePath)
223
- .pipe(progressStream);
223
+ // Create a PassThrough stream
224
+ const passThroughStream = new stream_1.PassThrough();
225
+ // Pipe the read stream through the progress stream into the PassThrough stream
226
+ fileReadStream.pipe(progressStream).pipe(passThroughStream);
224
227
  // Use form-data to construct the request body
225
228
  const formData = new form_data_1.default();
226
- formData.append("file", fileReadStream);
229
+ formData.append("file", passThroughStream);
227
230
  const headers = {
228
231
  ...formData.getHeaders(),
229
232
  "x-nonce": nonce,
@@ -237,12 +240,15 @@ class PropagationServer {
237
240
  maxBodyLength: Infinity,
238
241
  };
239
242
  const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${dataPath}`;
240
- const response = await axios_1.default.put(url, formData, config);
241
- // Wait for the progress stream to finish
242
- await new Promise((resolve, reject) => {
243
+ // Create a promise that resolves when the progress stream ends
244
+ const progressPromise = new Promise((resolve, reject) => {
243
245
  progressStream.on("end", resolve);
244
246
  progressStream.on("error", reject);
245
247
  });
248
+ // Start the upload request
249
+ const uploadPromise = axios_1.default.put(url, formData, config);
250
+ // Wait for both the upload and the progress stream to finish
251
+ await Promise.all([uploadPromise, progressPromise]);
246
252
  }
247
253
  catch (error) {
248
254
  throw error;
@@ -311,7 +317,7 @@ class PropagationServer {
311
317
  dataPath: file.path,
312
318
  }));
313
319
  // Limit the number of concurrent uploads
314
- const concurrencyLimit = 3; // Adjust this number as needed
320
+ const concurrencyLimit = 10; // Adjust this number as needed
315
321
  // Import asyncPool from your utilities
316
322
  const { asyncPool } = await Promise.resolve().then(() => __importStar(require("../utils/asyncPool")));
317
323
  await asyncPool(concurrencyLimit, uploadTasks, async (task) => {
@@ -319,7 +325,7 @@ class PropagationServer {
319
325
  });
320
326
  // Commit the session after all files have been uploaded
321
327
  await propagationServer.commitUploadSession();
322
- console.log((0, colorette_1.green)(`✔ All files have been uploaded to DataStore ${storeId}.`));
328
+ console.log((0, colorette_1.green)(`✔ All files have been uploaded to for Root Hash: ${(0, colorette_1.cyan)(rootHash)}.`));
323
329
  }
324
330
  /**
325
331
  * Fetch a file from the server by sending a GET request and return its content in memory.
@@ -343,7 +349,7 @@ class PropagationServer {
343
349
  }
344
350
  // Create a new progress bar for the file
345
351
  progressBar = new cli_progress_1.default.SingleBar({
346
- format: `${(0, colorette_1.blue)('[{bar}]')} | ${(0, colorette_1.yellow)('{filename}')} | {percentage}% | {value}/{total} bytes`,
352
+ format: `${(0, colorette_1.blue)("[{bar}]")} | ${(0, colorette_1.yellow)("{filename}")} | {percentage}% | {value}/{total} bytes`,
347
353
  hideCursor: true,
348
354
  barsize: 30,
349
355
  align: "left",
@@ -431,7 +437,7 @@ class PropagationServer {
431
437
  }
432
438
  // Create a new progress bar for the file
433
439
  progressBar = new cli_progress_1.default.SingleBar({
434
- format: `${(0, colorette_1.blue)('[{bar}]')} | ${(0, colorette_1.yellow)('{filename}')} | {percentage}% | {value}/{total} bytes`,
440
+ format: `${(0, colorette_1.blue)("[{bar}]")} | ${(0, colorette_1.yellow)("{filename}")} | {percentage}% | {value}/{total} bytes`,
435
441
  hideCursor: true,
436
442
  barsize: 30,
437
443
  align: "left",
@@ -496,7 +502,7 @@ class PropagationServer {
496
502
  downloadTasks.push({ label, dataPath });
497
503
  }
498
504
  // Limit the number of concurrent downloads
499
- const concurrencyLimit = 5; // Adjust this number as needed
505
+ const concurrencyLimit = 10; // Adjust this number as needed
500
506
  // Import asyncPool from your utilities
501
507
  const { asyncPool } = await Promise.resolve().then(() => __importStar(require("../utils/asyncPool")));
502
508
  await asyncPool(concurrencyLimit, downloadTasks, async (task) => {
@@ -38,6 +38,10 @@ export declare class DataStore {
38
38
  latestHeight: number;
39
39
  latestHash: Buffer;
40
40
  }>;
41
+ cacheStoreCreationHeight(): Promise<{
42
+ createdAtHeight: number;
43
+ createdAtHash: Buffer;
44
+ }>;
41
45
  getCreationHeight(): Promise<{
42
46
  createdAtHeight: number;
43
47
  createdAtHash: Buffer;
@@ -1 +1 @@
1
- {"version":3,"file":"DataStore.d.ts","sourceRoot":"","sources":["../../src/blockchain/DataStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,SAAS,IAAI,eAAe,EAE5B,iBAAiB,EAIlB,MAAM,8BAA8B,CAAC;AAWtC,OAAO,EAAE,eAAe,EAAW,MAAM,UAAU,CAAC;AAGpD,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAYjD,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAoB;gBAEpB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AC,MAAM,CAAC;IAIxD;;;;OAIG;mBACkB,mBAAmB;WAqB1B,YAAY,IAAI,SAAS,EAAE;IAW5B,aAAa,IAAI,OAAO,CAAC;QACpC,WAAW,EAAE,eAAe,CAAC;QAC7B,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAyGW,wBAAwB,IAAI,OAAO,CAAC;QAC/C,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IAcW,iBAAiB,IAAI,OAAO,CAAC;QACxC,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;YA0BY,iBAAiB;IAYlB,cAAc,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAwC5C,oBAAoB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAexD,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAKzC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAM5B,uBAAuB,CAClC,kBAAkB,CAAC,EAAE,MAAM,GAC1B,OAAO,CAAC,OAAO,CAAC;IAkBN,cAAc,CACzB,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,eAAe,CAAC;IA+C3B;;;;;OAKG;IACU,qBAAqB,CAChC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAyC7C"}
@@ -19,6 +19,7 @@ const prompts_1 = require("../prompts");
19
19
  const FileCache_1 = require("../utils/FileCache");
20
20
  const DataStoreSerializer_1 = require("./DataStoreSerializer");
21
21
  const node_cache_1 = __importDefault(require("node-cache"));
22
+ const config_2 = require("../utils/config");
22
23
  // Initialize the cache with a TTL of 180 seconds (3 minutes)
23
24
  const rootHistoryCache = new node_cache_1.default({ stdTTL: 180 });
24
25
  const stat = (0, util_1.promisify)(fs_1.default.stat);
@@ -263,22 +264,29 @@ class DataStore {
263
264
  throw error;
264
265
  }
265
266
  }
267
+ async cacheStoreCreationHeight() {
268
+ const peer = await FullNodePeer_1.FullNodePeer.connect();
269
+ const createdAtHeight = await peer.getStoreCreationHeight(Buffer.from(this.storeId, "hex"), null, Buffer.from(config_2.MAIN_NET_GENISES_CHALLENGE, "hex"));
270
+ const createdAtHash = await peer.getHeaderHash(Number(createdAtHeight));
271
+ await this.setCreationHeight(Number(createdAtHeight), createdAtHash);
272
+ return { createdAtHeight: Number(createdAtHeight), createdAtHash };
273
+ }
266
274
  async getCreationHeight() {
267
- const defaultHeight = config_1.MIN_HEIGHT;
268
- const defaultHash = Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex");
269
275
  // Initialize the FileCache for the height file
270
276
  const fileCache = new FileCache_1.FileCache(`stores/${this.storeId}`);
271
277
  // Try to retrieve the cached height information
272
278
  const cachedHeightInfo = fileCache.get("height");
273
279
  if (!cachedHeightInfo) {
274
- // If no cache, return the default values
275
- return { createdAtHeight: defaultHeight, createdAtHash: defaultHash };
280
+ // If no cache, regenerate the cache
281
+ return this.cacheStoreCreationHeight();
276
282
  }
277
283
  // Parse the cached height and hash values
278
284
  const { height, hash } = cachedHeightInfo;
285
+ const defaultHeight = config_1.MIN_HEIGHT;
286
+ const defaultHash = Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex");
279
287
  return {
280
288
  createdAtHeight: height || defaultHeight,
281
- createdAtHash: Buffer.from(hash || config_1.MIN_HEIGHT_HEADER_HASH, "hex"),
289
+ createdAtHash: hash ? Buffer.from(hash, "hex") : defaultHash,
282
290
  };
283
291
  }
284
292
  async setCreationHeight(height, hash) {
@@ -382,7 +390,6 @@ class DataStore {
382
390
  // Perform the integrity check
383
391
  const integrityCheck = await DataIntegrityTree_1.DataIntegrityTree.validateKeyIntegrityWithForeignTree(fileKey, datFileContent.files[fileKey].sha256, datFileContent, rootHash, path_1.default.join(config_1.STORE_PATH, this.storeId, "data"));
384
392
  if (integrityCheck) {
385
- console.log((0, colorette_1.green)(`✔ File ${fileKey} has passed the integrity check.`));
386
393
  // Add the file to the Set
387
394
  filesInvolved.add({
388
395
  name: Buffer.from(fileKey, "hex").toString("utf-8"),
@@ -1 +1 @@
1
- {"version":3,"file":"ServerCoin.d.ts","sourceRoot":"","sources":["../../src/blockchain/ServerCoin.ts"],"names":[],"mappings":"AACA,OAAO,EAML,UAAU,IAAI,gBAAgB,EAE/B,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAWrD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,gBAAuB,iBAAiB,eAEtC;gBAEU,OAAO,EAAE,MAAM;IAKd,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2DzD,kBAAkB,CAC7B,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;IAqBH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAoDjD,oBAAoB;IAerB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA2C5E,mBAAmB,CAC9B,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;IAMP,kBAAkB,CAC7B,UAAU,GAAE,MAAU,EACtB,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;IAMP,wBAAwB,CACnC,KAAK,EAAE,MAAM,EACb,UAAU,GAAE,MAAU,EACtB,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;WAeN,eAAe,IAA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MAAM,EAAE,CAAC;IAMP,kBAAkB,CAC7B,UAAU,GAAE,MAAU,EACtB,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;IAMP,wBAAwB,CACnC,KAAK,EAAE,MAAM,EACb,UAAU,GAAE,MAAU,EACtB,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,MAAM,EAAE,CAAC;WAeN,eAAe,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAKpD,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDrD,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WA+B1C,uBAAuB;YAkE7B,sBAAsB;IAWvB,uBAAuB,CAClC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;WAuBL,sBAAsB,CAAC,mBAAmB,EAAE,IAAI,GAAG;QAC/D,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf;CA2BF"}
@@ -103,6 +103,7 @@ class ServerCoin {
103
103
  // Check if the result is already cached
104
104
  const cachedPeers = serverCoinPeersCache.get(cacheKey);
105
105
  if (cachedPeers) {
106
+ console.log('!');
106
107
  return cachedPeers;
107
108
  }
108
109
  const epochBasedHint = (0, datalayer_driver_1.morphLauncherId)(Buffer.from(this.storeId, "hex"), BigInt(epoch));
@@ -125,6 +126,7 @@ class ServerCoin {
125
126
  const peerList = Array.from(serverCoinPeers);
126
127
  // Cache the result
127
128
  serverCoinPeersCache.set(cacheKey, peerList);
129
+ console.log(peerList);
128
130
  return peerList;
129
131
  }
130
132
  async getActiveEpochPeers(blacklist = []) {
@@ -1,5 +1,6 @@
1
1
  import { DigConfig } from "../types";
2
2
  export declare const NETWORK_AGG_SIG_DATA = "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb";
3
+ export declare const MAIN_NET_GENISES_CHALLENGE = "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb";
3
4
  export declare const MIN_HEIGHT = 5777842;
4
5
  export declare const MIN_HEIGHT_HEADER_HASH = "b29a4daac2434fd17a36e15ba1aac5d65012d4a66f99bed0bf2b5342e92e562c";
5
6
  export declare const DIG_FOLDER_PATH: string;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAKrC,eAAO,MAAM,oBAAoB,qEACmC,CAAC;AAErE,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;AAI9E,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;;;;GAIG;AACH,eAAO,MAAM,aAAa,QAAO,MAAM,EAOtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAa,OAAO,CAAC,MAAM,GAAG,IAAI,CAkC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EAOtC,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"}
@@ -26,12 +26,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.deleteDigConfigKey = exports.setDigConfigKey = exports.ensureDigConfig = exports.loadDigConfig = exports.getActiveStoreId = exports.getStoresList = exports.getCoinState = exports.setActiveStore = exports.setRemote = exports.createInitialConfig = exports.getHeightFilePath = exports.CONFIG_FILE_PATH = exports.USER_DIR_PATH = exports.STORE_PATH = exports.DIG_FOLDER_PATH = exports.MIN_HEIGHT_HEADER_HASH = exports.MIN_HEIGHT = exports.NETWORK_AGG_SIG_DATA = void 0;
29
+ exports.deleteDigConfigKey = exports.setDigConfigKey = exports.ensureDigConfig = exports.loadDigConfig = exports.getActiveStoreId = exports.getStoresList = exports.getCoinState = exports.setActiveStore = exports.setRemote = exports.createInitialConfig = exports.getHeightFilePath = exports.CONFIG_FILE_PATH = exports.USER_DIR_PATH = exports.STORE_PATH = exports.DIG_FOLDER_PATH = exports.MIN_HEIGHT_HEADER_HASH = exports.MIN_HEIGHT = exports.MAIN_NET_GENISES_CHALLENGE = exports.NETWORK_AGG_SIG_DATA = void 0;
30
30
  const fs = __importStar(require("fs"));
31
31
  const path = __importStar(require("path"));
32
32
  const inquirer_1 = __importDefault(require("inquirer"));
33
33
  const os_1 = __importDefault(require("os"));
34
34
  exports.NETWORK_AGG_SIG_DATA = "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb";
35
+ exports.MAIN_NET_GENISES_CHALLENGE = exports.NETWORK_AGG_SIG_DATA;
35
36
  exports.MIN_HEIGHT = 5777842;
36
37
  exports.MIN_HEIGHT_HEADER_HASH = "b29a4daac2434fd17a36e15ba1aac5d65012d4a66f99bed0bf2b5342e92e562c";
37
38
  exports.DIG_FOLDER_PATH = process.env.DIG_FOLDER_PATH || path.join(process.cwd(), ".dig");
@@ -1 +1 @@
1
- {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA8BrE,CAAC"}
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA6BrE,CAAC"}
@@ -18,7 +18,6 @@ const getPublicIpAddress = async () => {
18
18
  try {
19
19
  const response = await superagent_1.default.get('https://api.datalayer.storage/user/v1/get_user_ip');
20
20
  if (response.body && response.body.success) {
21
- console.log('Public IP address:', response.body);
22
21
  return response.body.ip_address;
23
22
  }
24
23
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.73",
3
+ "version": "0.0.1-alpha.76",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",
@@ -25,7 +25,7 @@
25
25
  "LICENSE"
26
26
  ],
27
27
  "dependencies": {
28
- "@dignetwork/datalayer-driver": "^0.1.24",
28
+ "@dignetwork/datalayer-driver": "^0.1.25",
29
29
  "archiver": "^7.0.1",
30
30
  "axios": "^1.7.7",
31
31
  "bip39": "^3.1.0",