@dignetwork/dig-sdk 0.0.1-alpha.49 → 0.0.1-alpha.51

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.
@@ -23,6 +23,7 @@ export declare class ContentServer {
23
23
  success: boolean;
24
24
  headers?: http.IncomingHttpHeaders;
25
25
  }>;
26
+ hasRootHash(rootHash: string): Promise<boolean>;
26
27
  streamKey(key: string): Promise<Readable>;
27
28
  private head;
28
29
  private fetchJson;
@@ -1 +1 @@
1
- {"version":3,"file":"ContentServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/ContentServer.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,qBAAa,aAAa;IACxB,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;gBAExB,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAYjC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAa7E,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAepC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC;IAM5B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC;IAM5B,OAAO,CAClB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB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I,CAAC,mBAAmB,CAAA;KAAE,CAAC;IAMvD,SAAS,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QACjE,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;KACpC,CAAC;IAUW,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUrD,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;YA0ClC,IAAI;YA0EJ,SAAS;YAMT,gBAAgB;YAiChB,KAAK;CA0DpB"}
@@ -73,6 +73,15 @@ class ContentServer {
73
73
  }
74
74
  return this.head(url);
75
75
  }
76
+ async hasRootHash(rootHash) {
77
+ const { success, headers } = await this.headStore({
78
+ hasRootHash: rootHash,
79
+ });
80
+ if (success) {
81
+ return headers?.["x-has-root-hash"] === "true";
82
+ }
83
+ return false;
84
+ }
76
85
  streamKey(key) {
77
86
  return new Promise((resolve, reject) => {
78
87
  const url = `https://${this.ipAddress}:${ContentServer.port}/${this.storeId}/${key}`;
@@ -5,16 +5,12 @@ export declare class DigNetwork {
5
5
  private storeDir;
6
6
  private peerBlacklist;
7
7
  constructor(storeId: string);
8
- private uploadPreflight;
9
- uploadStoreHead(digPeer: DigPeer): Promise<void>;
10
- uploadStore(digPeer: DigPeer): Promise<void>;
11
8
  static subscribeToStore(storeId: string): Promise<void>;
12
9
  static findPeerWithStoreKey(storeId: string, rootHash: string, key?: string, intialBlackList?: string[]): Promise<DigPeer | null>;
13
10
  static unsubscribeFromStore(storeId: string): void;
14
- downloadFiles(forceDownload?: boolean, renderProgressBar?: boolean, skipData?: boolean): Promise<void>;
11
+ downloadFiles(skipData?: boolean): Promise<void>;
15
12
  private fetchAvailablePeers;
16
13
  private downloadHeightFile;
17
- private downloadManifestFile;
18
14
  private downloadFileFromPeers;
19
15
  private runProgressBar;
20
16
  }
@@ -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;AAYpC,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;YAOb,eAAe;IA8ChB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAsDhD,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;WA6BrC,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;IAQ5C,aAAa,CACxB,aAAa,GAAE,OAAe,EAC9B,iBAAiB,GAAE,OAAc,EACjC,QAAQ,GAAE,OAAe,GACxB,OAAO,CAAC,IAAI,CAAC;YAkJF,mBAAmB;YAWnB,kBAAkB;YASlB,oBAAoB;YASpB,qBAAqB;YAsFrB,cAAc;CAoB7B"}
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,aAAa,CACxB,QAAQ,GAAE,OAAe,GACxB,OAAO,CAAC,IAAI,CAAC;YAgJF,mBAAmB;YAWnB,kBAAkB;YASlB,qBAAqB;YAoCrB,cAAc;CAoB7B"}
@@ -28,7 +28,6 @@ const fs = __importStar(require("fs"));
28
28
  const path = __importStar(require("path"));
29
29
  const cli_progress_1 = require("cli-progress");
30
30
  const DigPeer_1 = require("./DigPeer");
31
- const deltaUtils_1 = require("../utils/deltaUtils");
32
31
  const hashUtils_1 = require("../utils/hashUtils");
33
32
  const blockchain_1 = require("../blockchain");
34
33
  const config_1 = require("../utils/config");
@@ -43,82 +42,6 @@ class DigNetwork {
43
42
  this.storeDir = path.resolve(config_1.DIG_FOLDER_PATH, "stores", storeId);
44
43
  this.peerBlacklist = new Map(); // Initialize empty map for blacklists
45
44
  }
46
- async uploadPreflight(digPeer) {
47
- // Preflight check is handled internally by PropagationServer if needed
48
- const { lastUploadedHash, generationIndex } = await digPeer.propagationServer.getUploadDetails();
49
- const rootHistory = await this.dataStore.getLocalRootHistory();
50
- if (!rootHistory || rootHistory.length === 0) {
51
- throw new Error("No root hashes found. Please commit your changes first.");
52
- }
53
- const lastLocalRootHash = rootHistory[rootHistory.length - 1].root_hash;
54
- const localGenerationIndex = rootHistory.length - 1;
55
- // Handle conditions based on the upload details
56
- if (lastUploadedHash !== lastLocalRootHash &&
57
- generationIndex === localGenerationIndex) {
58
- throw new Error("The repository seems to be corrupted. Please pull the latest changes before pushing.");
59
- }
60
- if (lastUploadedHash === lastLocalRootHash &&
61
- generationIndex === localGenerationIndex) {
62
- throw new Error("No changes detected. Skipping push.");
63
- }
64
- if (lastUploadedHash !== lastLocalRootHash &&
65
- generationIndex > localGenerationIndex) {
66
- throw new Error("Remote repository is ahead of the local repository. Please pull the latest changes before pushing.");
67
- }
68
- return { generationIndex, lastLocalRootHash };
69
- }
70
- async uploadStoreHead(digPeer) {
71
- // First make sure that the remote store is up to date.
72
- const rootHistory = await this.dataStore.getRootHistory();
73
- const localManifestHashes = await this.dataStore.getManifestHashes();
74
- const remoteManifestFile = await digPeer.propagationServer.getStoreData("manifest.dat");
75
- const remoteManifestHashes = remoteManifestFile.split("\n").filter(Boolean);
76
- const onChainRootHashes = rootHistory.map((root) => root.root_hash);
77
- // Check that remote manifest is one behind on-chain root hashes
78
- if (remoteManifestHashes.length !== onChainRootHashes.length - 1) {
79
- throw new Error("Remote manifest should be one behind the on-chain root. Cannot push head.");
80
- }
81
- // Compare each remote manifest hash with the corresponding on-chain root hash
82
- for (let i = 0; i < remoteManifestHashes.length; i++) {
83
- if (remoteManifestHashes[i] !== onChainRootHashes[i]) {
84
- throw new Error(`Remote manifest does not match on-chain root at index ${i}. Cannot push head.`);
85
- }
86
- }
87
- // Get the files for the latest local manifest hash
88
- const filesToUpload = await this.dataStore.getFileSetForRootHash(localManifestHashes[localManifestHashes.length - 1]);
89
- if (!filesToUpload.length) {
90
- console.log("No files to upload.");
91
- return;
92
- }
93
- // Upload files to the remote peer with a progress bar
94
- await this.runProgressBar(filesToUpload.length, "Store Data", async (progress) => {
95
- for (const filePath of filesToUpload) {
96
- const relativePath = path
97
- .relative(this.storeDir, filePath)
98
- .replace(/\\/g, "/");
99
- await digPeer.propagationServer.pushFile(filePath, relativePath);
100
- progress.increment();
101
- }
102
- });
103
- }
104
- // Uploads the store to a specific peer
105
- async uploadStore(digPeer) {
106
- const { generationIndex } = await this.uploadPreflight(digPeer);
107
- const filesToUpload = await (0, deltaUtils_1.getDeltaFiles)(this.dataStore.StoreId, generationIndex, path.resolve(config_1.DIG_FOLDER_PATH, "stores"));
108
- if (!filesToUpload.length) {
109
- console.log("No files to upload.");
110
- return;
111
- }
112
- await this.runProgressBar(filesToUpload.length, "Store Data", async (progress) => {
113
- for (const filePath of filesToUpload) {
114
- const relativePath = path
115
- .relative(this.storeDir, filePath)
116
- .replace(/\\/g, "/");
117
- await digPeer.propagationServer.pushFile(filePath, relativePath);
118
- progress.increment();
119
- }
120
- });
121
- }
122
45
  static async subscribeToStore(storeId) {
123
46
  fs.mkdirSync(path.join(config_1.DIG_FOLDER_PATH, "stores", storeId), {
124
47
  recursive: true,
@@ -178,8 +101,7 @@ class DigNetwork {
178
101
  });
179
102
  fs.unlinkSync(path.join(config_1.DIG_FOLDER_PATH, "stores", storeId + ".json"));
180
103
  }
181
- // Downloads files from the network based on the manifest
182
- async downloadFiles(forceDownload = false, renderProgressBar = true, skipData = false) {
104
+ async downloadFiles(skipData = false) {
183
105
  console.log("Starting file download process...");
184
106
  let peerBlackList = [];
185
107
  let selectedPeer = null;
@@ -243,7 +165,6 @@ class DigNetwork {
243
165
  // Then it will backfill historical roothashes
244
166
  break;
245
167
  }
246
- await this.downloadManifestFile(true);
247
168
  console.log("Syncing store complete.");
248
169
  }
249
170
  catch (error) {
@@ -265,10 +186,6 @@ class DigNetwork {
265
186
  const heightFilePath = path.join(this.storeDir, "height.json");
266
187
  await this.downloadFileFromPeers("height.json", heightFilePath, forceDownload);
267
188
  }
268
- async downloadManifestFile(forceDownload) {
269
- const heightFilePath = path.join(this.storeDir, "manifest.dat");
270
- await this.downloadFileFromPeers("manifest.dat", heightFilePath, forceDownload);
271
- }
272
189
  async downloadFileFromPeers(dataPath, filePath, overwrite) {
273
190
  let digPeers = await this.fetchAvailablePeers();
274
191
  const tempFilePath = `${filePath}.tmp`;
@@ -280,31 +197,7 @@ class DigNetwork {
280
197
  try {
281
198
  if (blacklist.has(digPeer.IpAddress))
282
199
  continue;
283
- const response = await digPeer.propagationServer.headStore();
284
- if (!response.success) {
285
- continue;
286
- }
287
- // Create directory if it doesn't exist
288
- const directory = path.dirname(tempFilePath);
289
- if (!fs.existsSync(directory)) {
290
- fs.mkdirSync(directory, { recursive: true });
291
- }
292
- // Stream the file data to a temporary file
293
- const fileStream = fs.createWriteStream(tempFilePath);
294
- // Start streaming the data from the peer
295
- const peerStream = await digPeer.propagationServer.streamStoreData(dataPath);
296
- // Pipe the peer stream to the temp file
297
- await new Promise((resolve, reject) => {
298
- peerStream.pipe(fileStream);
299
- peerStream.on("end", resolve);
300
- peerStream.on("error", reject);
301
- fileStream.on("error", reject);
302
- });
303
- // Rename the temp file to the final file path after successful download
304
- await rename(tempFilePath, filePath);
305
- if (process.env.DIG_DEBUG === "1") {
306
- console.log(`Downloaded ${dataPath} from ${digPeer.IpAddress}`);
307
- }
200
+ await digPeer.downloadData(this.dataStore.StoreId, dataPath);
308
201
  return; // Exit the method if download succeeds
309
202
  }
310
203
  catch (error) {
@@ -316,16 +209,6 @@ class DigNetwork {
316
209
  }
317
210
  }
318
211
  }
319
- this.peerBlacklist.set(dataPath, blacklist);
320
- if (blacklist.size >= digPeers.length) {
321
- if (process.env.DIG_DEBUG === "1") {
322
- console.warn(`All peers blacklisted for ${dataPath}. Refreshing peers...`);
323
- }
324
- digPeers = await this.fetchAvailablePeers();
325
- if (!digPeers.length) {
326
- throw new Error(`Failed to download ${dataPath}: no peers available.`);
327
- }
328
- }
329
212
  }
330
213
  }
331
214
  async runProgressBar(total, name, task) {
@@ -13,12 +13,12 @@ export declare class DigPeer {
13
13
  get propagationServer(): PropagationServer;
14
14
  get incentiveServer(): IncentiveServer;
15
15
  get IpAddress(): string;
16
- validateStore(rootHash: string, keys: string[]): Promise<boolean>;
17
- isSynced(): Promise<boolean>;
18
16
  static sendEqualBulkPayments(walletName: string, addresses: string[], totalAmount: bigint, memos: Buffer[]): Promise<void>;
19
17
  static sendBulkPayments(walletName: string, outputs: Output[]): Promise<void>;
20
18
  sendPayment(walletName: string, amount: bigint, memos?: Buffer[]): Promise<void>;
21
19
  static createPaymentHint(storeId: Buffer): Buffer;
20
+ syncStore(): Promise<void>;
21
+ pushStoreRoot(storeId: string, rootHash: string): Promise<void>;
22
22
  downloadData(storeId: string, dataPath: string): Promise<void>;
23
23
  }
24
24
  //# sourceMappingURL=DigPeer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DigPeer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigPeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAKpD,OAAO,EAKL,MAAM,EACP,MAAM,8BAA8B,CAAC;AAUtC,qBAAa,OAAO;IAClB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,gBAAgB,CAAkB;gBAE9B,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAS9C,IAAW,aAAa,IAAI,aAAa,CAExC;IAGD,IAAW,iBAAiB,IAAI,iBAAiB,CAEhD;IAGD,IAAW,eAAe,IAAI,eAAe,CAE5C;IAED,IAAW,SAAS,IAAI,MAAM,CAE7B;IAEY,aAAa,CACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,OAAO,CAAC;IAiHN,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;WA2B3B,qBAAqB,CACjC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EAAE,EACnB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,IAAI,CAAC;WAuBI,gBAAgB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MAAM,EAAE,GAChB,OAAO,CAAC,IAAI,CAAC;IAwCH,WAAW,CACtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAAM,EAAO,GACnB,OAAO,CAAC,IAAI,CAAC;WAYF,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAqBlC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAU1B,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB/D,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA4C5E"}
@@ -10,14 +10,12 @@ const ContentServer_1 = require("./ContentServer");
10
10
  const PropagationServer_1 = require("./PropagationServer");
11
11
  const IncentiveServer_1 = require("./IncentiveServer");
12
12
  const blockchain_1 = require("../blockchain");
13
- const DataIntegrityTree_1 = require("../DataIntegrityTree");
14
- const config_1 = require("../utils/config");
15
13
  const fs_1 = __importDefault(require("fs"));
16
14
  const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
17
15
  const blockchain_2 = require("../blockchain");
18
16
  const blockchain_3 = require("../blockchain");
19
17
  const coins_1 = require("../blockchain/coins");
20
- const config_2 = require("../utils/config");
18
+ const config_1 = require("../utils/config");
21
19
  const util_1 = require("util");
22
20
  const rename = (0, util_1.promisify)(fs_1.default.rename);
23
21
  const unlink = (0, util_1.promisify)(fs_1.default.unlink);
@@ -44,106 +42,6 @@ class DigPeer {
44
42
  get IpAddress() {
45
43
  return this.ipAddress;
46
44
  }
47
- async validateStore(rootHash, keys) {
48
- console.log(`Validating store ${this.storeId} on peer ${this.ipAddress}...`);
49
- try {
50
- const dataStore = blockchain_1.DataStore.from(this.storeId);
51
- // Fetch the root history from the propagation server
52
- const rootHistory = await dataStore.getRootHistory();
53
- if (rootHistory.length === 0) {
54
- console.error("No root history found for the store.");
55
- return false;
56
- }
57
- // Fetch the manifest.dat file content from the propagation server
58
- const manifestContent = await this.propagationServer.getStoreData("manifest.dat");
59
- const manifestHashes = manifestContent
60
- .split("\n")
61
- .filter(Boolean);
62
- // Ensure all hashes in root history are present in the manifest in the same order
63
- for (let i = 0; i < rootHistory.length; i++) {
64
- if (rootHistory[i].root_hash !== manifestHashes[i]) {
65
- console.error(`Hash mismatch at index ${i}: manifest hash ${manifestHashes[i]} does not match root history hash ${rootHistory[i].root_hash}`);
66
- return false;
67
- }
68
- }
69
- console.log("Manifest file validated.");
70
- // Fetch the .dat file content for the specified root hash from the content server
71
- const datFileContent = JSON.parse(await this.propagationServer.getStoreData(`${rootHash}.dat`));
72
- if (datFileContent.root !== rootHash) {
73
- console.error(`Root hash in .dat file does not match: ${datFileContent.root} !== ${rootHash}`);
74
- return false;
75
- }
76
- let filesIntegrityIntact = true;
77
- // Validate SHA256 hashes of the specified keys using streamStoreKey
78
- for (const key of keys) {
79
- const fileData = datFileContent.files[key];
80
- if (!fileData) {
81
- console.error(`File key ${key} not found in .dat file.`);
82
- filesIntegrityIntact = false;
83
- continue;
84
- }
85
- // Stream the file from the propagation server and calculate the SHA256 hash on the fly
86
- const hash = crypto_1.default.createHash("sha256");
87
- const fileStream = await this.contentServer.streamKey(Buffer.from(key, "hex").toString("utf-8"));
88
- await new Promise((resolve, reject) => {
89
- fileStream.on("data", (chunk) => {
90
- hash.update(chunk); // Update the hash with each chunk of data
91
- });
92
- fileStream.on("end", () => {
93
- const calculatedHash = hash.digest("hex");
94
- // Compare the calculated hash with the expected hash
95
- if (calculatedHash !== fileData.sha256) {
96
- console.error(`File ${key} failed SHA256 validation.`);
97
- filesIntegrityIntact = false;
98
- }
99
- resolve();
100
- });
101
- fileStream.on("error", (err) => {
102
- console.error(`Failed to stream file ${key}: ${err.message}`);
103
- reject(err);
104
- });
105
- });
106
- // Perform tree integrity validation using the datFileContent and the root hash
107
- const treeCheck = DataIntegrityTree_1.DataIntegrityTree.validateKeyIntegrityWithForeignTree(key, fileData.sha256, datFileContent, rootHash, path_1.default.resolve(config_1.DIG_FOLDER_PATH, "stores", this.storeId, 'data'));
108
- if (!treeCheck) {
109
- console.error(`Tree validation failed for file ${key}.`);
110
- filesIntegrityIntact = false;
111
- }
112
- }
113
- if (!filesIntegrityIntact) {
114
- console.error("Store Corrupted: Data failed SHA256 validation.");
115
- return false;
116
- }
117
- console.log("Store validation successful.");
118
- return true;
119
- }
120
- catch (error) {
121
- console.error(`Failed to validate store: ${error.message}`);
122
- return false;
123
- }
124
- }
125
- async isSynced() {
126
- try {
127
- // Fetch the root history from the propagation server
128
- const dataStore = blockchain_1.DataStore.from(this.storeId);
129
- const rootHistory = await dataStore.getRootHistory();
130
- if (rootHistory.length === 0) {
131
- console.error("No root history found for the store.");
132
- return false;
133
- }
134
- // Fetch the manifest.dat file content from the content server
135
- const manifestContent = await this.propagationServer.getStoreData("manifest.dat");
136
- const manifestHashes = manifestContent
137
- .split("\n")
138
- .filter(Boolean);
139
- // Compare lengths of root history and manifest
140
- return rootHistory.length === manifestHashes.length;
141
- }
142
- catch (error) {
143
- console.error(`Failed to check sync status: ${error.message}`);
144
- return false;
145
- }
146
- }
147
45
  static sendEqualBulkPayments(walletName, addresses, totalAmount, memos) {
148
46
  // Use a Set to ensure unique addresses
149
47
  const uniqueAddresses = Array.from(new Set(addresses));
@@ -202,8 +100,34 @@ class DigPeer {
202
100
  // Return the 32-byte hash as a hex string
203
101
  return transformedBuffer;
204
102
  }
103
+ async syncStore() {
104
+ const dataStore = blockchain_1.DataStore.from(this.storeId);
105
+ const rootHistory = await dataStore.getRootHistory();
106
+ rootHistory
107
+ .filter((root) => root.synced)
108
+ .forEach((item) => {
109
+ this.pushStoreRoot(this.storeId, item.root_hash);
110
+ });
111
+ }
112
+ async pushStoreRoot(storeId, rootHash) {
113
+ const dataStore = blockchain_1.DataStore.from(storeId);
114
+ const alreadySynced = await this.contentServer.hasRootHash(rootHash);
115
+ if (alreadySynced) {
116
+ console.log(`Root hash ${rootHash} already synced.`);
117
+ return;
118
+ }
119
+ const tree = await dataStore.Tree.serialize(rootHash);
120
+ // @ts-ignore
121
+ tree.files.forEach(async (file) => {
122
+ await dataStore.Tree.verifyKeyIntegrity(file.sha256, rootHash);
123
+ console.log(`Pushing file ${file.key} to ${this.IpAddress}`);
124
+ const dataPath = path_1.default.join("data", file.sha256.match(/.{1,2}/g).join("/"));
125
+ const fileLocation = path_1.default.join(config_1.STORE_PATH, storeId, dataPath);
126
+ await this.propagationServer.pushFile(fileLocation, dataPath);
127
+ });
128
+ }
205
129
  async downloadData(storeId, dataPath) {
206
- const filePath = path_1.default.join(config_2.STORE_PATH, storeId, dataPath);
130
+ const filePath = path_1.default.join(config_1.STORE_PATH, storeId, dataPath);
207
131
  const tempFilePath = `${filePath}.tmp`;
208
132
  try {
209
133
  const headStoreResponse = await this.propagationServer.headStore();
@@ -11,7 +11,7 @@ export declare class PropagationServer {
11
11
  private static readonly maxDelay;
12
12
  private static readonly delayMultiplier;
13
13
  constructor(ipAddress: string, storeId: string);
14
- pushFile(filePath: string, relativePath: string): Promise<void>;
14
+ pushFile(fileLocation: string, dataPath: string): Promise<void>;
15
15
  subscribeToStore(): Promise<void>;
16
16
  unsubscribeFromStore(): Promise<void>;
17
17
  getStoreStatus(): Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AAKxB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,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,M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OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAA;KAAE,CAAC;IAW/G,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAMjC,gBAAgB,IAAI,OAAO,CAAC;QACvC,KAAK,EAAE,MAAM,CAAC;QACd,gBAAgB,EAAE,MAAM,CAAC;QACzB,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;YAmBY,WAAW;YAyCX,kBAAkB;YAoElB,gBAAgB;YAgEhB,cAAc;YAiCd,KAAK;YAmDL,IAAI;YAmEJ,SAAS;YAuCT,2BAA2B;YAiC3B,gBAAgB;CAyC/B"}
@@ -21,13 +21,13 @@ class PropagationServer {
21
21
  }
22
22
  }
23
23
  // Method to upload a file to the propagation server
24
- async pushFile(filePath, relativePath) {
24
+ async pushFile(fileLocation, dataPath) {
25
25
  const { nonce, username, password } = await this.getUploadDetails();
26
26
  const wallet = await blockchain_1.Wallet.load("default");
27
27
  const keyOwnershipSig = await wallet.createKeyOwnershipSignature(nonce);
28
28
  const publicKey = await wallet.getPublicSyntheticKey();
29
- const uploadUrl = `https://${this.ipAddress}:${PropagationServer.port}/${this.storeId}/${relativePath}`;
30
- await this.retryOperation(() => this.uploadFileDirect(filePath, uploadUrl, username, password, keyOwnershipSig, publicKey.toString("hex"), nonce), `Upload failed for ${relativePath}`);
29
+ const uploadUrl = `https://${this.ipAddress}:${PropagationServer.port}/${this.storeId}/${dataPath}`;
30
+ await this.retryOperation(() => this.uploadFileDirect(fileLocation, uploadUrl, username, password, keyOwnershipSig, publicKey.toString("hex"), nonce), `Upload failed for ${dataPath}`);
31
31
  }
32
32
  // Method to subscribe to a store on the propagation server
33
33
  async subscribeToStore() {
@@ -44,13 +44,10 @@ export declare class DataStore {
44
44
  }>;
45
45
  private setCreationHeight;
46
46
  getRootHistory(): Promise<RootHistoryItem[]>;
47
- getLocalRootHistory(): Promise<RootHistoryItem[] | undefined>;
48
- validate(): Promise<boolean>;
49
47
  getMetaData(): Promise<DataStoreMetadata>;
50
48
  isSynced(): Promise<boolean>;
51
49
  hasMetaWritePermissions(publicSyntheticKey?: Buffer): Promise<boolean>;
52
50
  updateMetadata(metadata: DataStoreMetadata): Promise<DataStoreDriver>;
53
51
  getFileSetForRootHash(rootHash: string): Promise<string[]>;
54
- getManifestHashes(): string[];
55
52
  }
56
53
  //# sourceMappingURL=DataStore.d.ts.map
@@ -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;AAYtC,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;AAQjD,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,IAAI,CAAoB;gBAEpB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB;IAiB/D,IAAW,OAAO,IAAI,MAAM,CAE3B;IAED,IAAW,IAAI,IAAI,iBAAiB,CAEnC;IAEM,QAAQ,IAAI,MAAM;IAIlB,QAAQ,IAAI,MAAM;IAIlB,SAAS,IAAI,MAAM;WAMN,cAAc,IAAI,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;WAOtD,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS;WAK1C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;WAYnC,MAAM,CACxB,MAAM,GAAE,qBAA0B,GACjC,OAAO,CAAC,SAAS,CAAC;mBAyCA,IAAI;IA4FzB;;;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AO,CAAC,OAAO,CAAC;IAkBN,cAAc,CACzB,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,eAAe,CAAC;IA+Cd,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAgCxE"}
@@ -12,7 +12,6 @@ const FullNodePeer_1 = require("./FullNodePeer");
12
12
  const Wallet_1 = require("./Wallet");
13
13
  const config_1 = require("../utils/config");
14
14
  const coins_1 = require("./coins");
15
- const utils_1 = require("../utils");
16
15
  const hashUtils_1 = require("../utils/hashUtils");
17
16
  const DataIntegrityTree_1 = require("../DataIntegrityTree");
18
17
  const prompts_1 = require("../prompts");
@@ -293,92 +292,17 @@ class DataStore {
293
292
  return rootHashes.map((rootHash, index) => ({
294
293
  root_hash: rootHash.toString("hex"),
295
294
  timestamp: Number(rootHashesTimestamps?.[index].toString()),
295
+ synced: fs_1.default.existsSync(`${config_1.STORE_PATH}/${this.storeId}/${rootHash}.dat`),
296
296
  }));
297
297
  }
298
- async getLocalRootHistory() {
299
- const manifestFilePath = (0, config_1.getManifestFilePath)(this.storeId);
300
- if (!fs_1.default.existsSync(manifestFilePath)) {
301
- console.error("Manifest file not found", manifestFilePath);
302
- return undefined;
303
- }
304
- const manifestHashes = fs_1.default
305
- .readFileSync(manifestFilePath, "utf-8")
306
- .split("\n")
307
- .filter(Boolean);
308
- return manifestHashes.map((rootHash) => ({
309
- root_hash: rootHash,
310
- timestamp: 0, // Timestamps are not yet included in the manifest
311
- }));
312
- }
313
- async validate() {
314
- const rootHistory = await this.getRootHistory();
315
- const manifestFilePath = (0, config_1.getManifestFilePath)(this.storeId);
316
- if (!fs_1.default.existsSync(manifestFilePath)) {
317
- console.error("Manifest file not found", manifestFilePath);
318
- return false;
319
- }
320
- const manifestHashes = fs_1.default
321
- .readFileSync(manifestFilePath, "utf-8")
322
- .split("\n")
323
- .filter(Boolean);
324
- if (manifestHashes.length > rootHistory.length) {
325
- console.error("The store is corrupted: Manifest file has more hashes than the root history.");
326
- return false;
327
- }
328
- if (rootHistory.length > manifestHashes.length) {
329
- console.error("The store is not synced: Root history has more hashes than the manifest file.");
330
- return false;
331
- }
332
- for (let i = 0; i < manifestHashes.length; i++) {
333
- if (manifestHashes[i] !== rootHistory[i]?.root_hash) {
334
- console.error(`Root hash mismatch at position ${i}: expected ${manifestHashes[i]} but found ${rootHistory[i]?.root_hash}`);
335
- return false;
336
- }
337
- }
338
- let filesIntegrityIntact = true;
339
- // At this point we have verified that the root history and manifest file match
340
- for (const rootHash of manifestHashes) {
341
- const datFilePath = path_1.default.join(config_1.STORE_PATH, this.storeId, `${rootHash}.dat`);
342
- if (!fs_1.default.existsSync(datFilePath)) {
343
- console.error(`Data file for root hash ${rootHash} not found`);
344
- return false;
345
- }
346
- const datFileContent = JSON.parse(fs_1.default.readFileSync(datFilePath, "utf-8"));
347
- if (datFileContent.root !== rootHash) {
348
- console.error(`Root hash in data file does not match: ${datFileContent.root} !== ${rootHash}`);
349
- return false;
350
- }
351
- for (const [fileKey, fileData] of Object.entries(datFileContent.files)) {
352
- // We are going to check if the sha256 belongs to the tree, and then we are going to make sure
353
- // that the file is in the data folder and that the sha256 of the file matches the one in the dat file
354
- const belongsInTree = await this.Tree.verifyKeyIntegrity(fileData.sha256, rootHash);
355
- const fileIntegrityCheck = (0, utils_1.validateFileSha256)(fileData.sha256, path_1.default.join(config_1.STORE_PATH, this.storeId, "data"));
356
- if (!fileIntegrityCheck || !belongsInTree) {
357
- filesIntegrityIntact = false;
358
- }
359
- }
360
- }
361
- if (!filesIntegrityIntact) {
362
- console.error("Store Corrupted: Data failed SHA256 validation.");
363
- return false;
364
- }
365
- return true;
366
- }
367
298
  async getMetaData() {
368
299
  const { latestStore } = await this.fetchCoinInfo();
369
300
  return latestStore.metadata;
370
301
  }
371
302
  async isSynced() {
372
- const rootHistory = await this.getRootHistory();
373
- const manifestFilePath = (0, config_1.getManifestFilePath)(this.storeId);
374
- if (!fs_1.default.existsSync(manifestFilePath)) {
375
- return false;
376
- }
377
- const manifestHashes = fs_1.default
378
- .readFileSync(manifestFilePath, "utf-8")
379
- .split("\n")
380
- .filter(Boolean);
381
- return rootHistory.length === manifestHashes.length;
303
+ const dataStore = await DataStore.from(this.storeId);
304
+ const rootHistory = await dataStore.getRootHistory();
305
+ return !rootHistory.some((root) => !root.synced);
382
306
  }
383
307
  async hasMetaWritePermissions(publicSyntheticKey) {
384
308
  const wallet = await Wallet_1.Wallet.load("default");
@@ -427,11 +351,5 @@ class DataStore {
427
351
  }
428
352
  return filesInvolved;
429
353
  }
430
- getManifestHashes() {
431
- const manifestFilePath = path_1.default.join(config_1.STORE_PATH, this.storeId, "manifest.dat");
432
- return fs_1.default.existsSync(manifestFilePath)
433
- ? fs_1.default.readFileSync(manifestFilePath, "utf-8").split("\n").filter(Boolean)
434
- : [];
435
- }
436
354
  }
437
355
  exports.DataStore = DataStore;
package/dist/types.d.ts CHANGED
@@ -23,6 +23,7 @@ export interface DigConfig {
23
23
  export interface RootHistoryItem {
24
24
  root_hash: string;
25
25
  timestamp: Number | undefined;
26
+ synced: boolean;
26
27
  }
27
28
  export interface DatFile {
28
29
  root: string;
@@ -1 +1 @@
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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AI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;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"}
@@ -0,0 +1,45 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,153 @@
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;
@@ -6,7 +6,6 @@ export declare const DIG_FOLDER_PATH: string;
6
6
  export declare const STORE_PATH: string;
7
7
  export declare const USER_DIR_PATH: string;
8
8
  export declare const CONFIG_FILE_PATH: string;
9
- export declare const getManifestFilePath: (storeId: string) => string;
10
9
  export declare const getHeightFilePath: (storeId: string) => string;
11
10
  export declare const createInitialConfig: () => void;
12
11
  export declare const setRemote: (remote: string) => void;
@@ -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;AAE9E,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,MACN,CAAC;AAEjD,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,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;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,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,7 +26,7 @@ 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.getManifestFilePath = 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.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"));
@@ -38,8 +38,6 @@ exports.DIG_FOLDER_PATH = process.env.DIG_FOLDER_PATH || path.join(process.cwd()
38
38
  exports.STORE_PATH = path.join(exports.DIG_FOLDER_PATH, "stores");
39
39
  exports.USER_DIR_PATH = path.join(os_1.default.homedir(), ".dig");
40
40
  exports.CONFIG_FILE_PATH = path.join(exports.DIG_FOLDER_PATH, "dig.config.json");
41
- const getManifestFilePath = (storeId) => path.join(exports.STORE_PATH, storeId, "manifest.dat");
42
- exports.getManifestFilePath = getManifestFilePath;
43
41
  const getHeightFilePath = (storeId) => path.join(exports.STORE_PATH, storeId, "height.json");
44
42
  exports.getHeightFilePath = getHeightFilePath;
45
43
  const createInitialConfig = () => {
@@ -1,7 +1,6 @@
1
1
  export * from './config';
2
2
  export * from './connectionUtils';
3
3
  export * from './credentialsUtils';
4
- export * from './deltaUtils';
5
4
  export * from './directoryUtils';
6
5
  export * from './encryption';
7
6
  export * from './FileCache';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,OAAO,CAAC;AACtB,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,OAAO,CAAC;AACtB,cAAc,mBAAmB,CAAC"}
@@ -17,7 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./config"), exports);
18
18
  __exportStar(require("./connectionUtils"), exports);
19
19
  __exportStar(require("./credentialsUtils"), exports);
20
- __exportStar(require("./deltaUtils"), exports);
21
20
  __exportStar(require("./directoryUtils"), exports);
22
21
  __exportStar(require("./encryption"), exports);
23
22
  __exportStar(require("./FileCache"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.49",
3
+ "version": "0.0.1-alpha.51",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",
@@ -26,6 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@dignetwork/datalayer-driver": "^0.1.24",
29
+ "archiver": "^7.0.1",
29
30
  "bip39": "^3.1.0",
30
31
  "chia-bls": "^1.0.2",
31
32
  "chia-config-loader": "^1.0.1",
@@ -43,9 +44,11 @@
43
44
  "nconf": "^0.12.1",
44
45
  "node-cache": "^5.1.2",
45
46
  "p-limit": "^6.1.0",
46
- "superagent": "^10.0.0"
47
+ "superagent": "^10.0.0",
48
+ "unzipper": "^0.12.3"
47
49
  },
48
50
  "devDependencies": {
51
+ "@types/archiver": "^6.0.2",
49
52
  "@types/chai": "^4.3.17",
50
53
  "@types/cli-progress": "^3.11.6",
51
54
  "@types/crypto-js": "^4.2.2",
@@ -56,6 +59,7 @@
56
59
  "@types/nconf": "^0.10.7",
57
60
  "@types/node": "^22.1.0",
58
61
  "@types/superagent": "^8.1.8",
62
+ "@types/unzipper": "^0.10.10",
59
63
  "chai": "^5.1.1",
60
64
  "copyfiles": "^2.4.1",
61
65
  "mocha": "^10.7.0",
@@ -1,2 +0,0 @@
1
- export declare const getDeltaFiles: (storeId: string, generationIndex: number | undefined, directoryPath: string) => Promise<string[]>;
2
- //# sourceMappingURL=deltaUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deltaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deltaUtils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,YACf,MAAM,mBACE,MAAM,6BACR,MAAM,KACpB,OAAO,CAAC,MAAM,EAAE,CAwElB,CAAC"}
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getDeltaFiles = void 0;
27
- const fs = __importStar(require("fs"));
28
- const path = __importStar(require("path"));
29
- const hashUtils_1 = require("./hashUtils");
30
- const getDeltaFiles = async (storeId, generationIndex = 0, directoryPath) => {
31
- if (isNaN(generationIndex)) {
32
- generationIndex = 0;
33
- }
34
- // Load manifest file
35
- const manifestFilePath = path.join(directoryPath, storeId, "manifest.dat");
36
- if (!fs.existsSync(manifestFilePath)) {
37
- console.error("Manifest file not found", manifestFilePath);
38
- return [];
39
- }
40
- const manifestHashes = fs
41
- .readFileSync(manifestFilePath, "utf-8")
42
- .split("\n")
43
- .filter(Boolean);
44
- console.log("");
45
- console.log(`Uploading delta from generation ${generationIndex}`);
46
- const filesInvolved = [];
47
- // Include the height.dat file at the top of the directory
48
- const heightDatFilePath = path.join(directoryPath, storeId, "height.json");
49
- if (fs.existsSync(heightDatFilePath)) {
50
- filesInvolved.push(heightDatFilePath);
51
- }
52
- // Collect files starting from generationIndex + 1
53
- for (let i = generationIndex; i < manifestHashes.length; i++) {
54
- const rootHash = manifestHashes[i];
55
- const datFilePath = path.join(directoryPath, storeId, `${rootHash}.dat`);
56
- if (!fs.existsSync(datFilePath)) {
57
- console.error(`Data file for root hash ${rootHash} not found`);
58
- return [];
59
- }
60
- const datFileContent = JSON.parse(fs.readFileSync(datFilePath, "utf-8"));
61
- if (datFileContent.root !== rootHash) {
62
- console.error(`Root hash in data file does not match: ${datFileContent.root} !== ${rootHash}`);
63
- return [];
64
- }
65
- // Add the .dat file itself to the list of files involved
66
- filesInvolved.push(datFilePath);
67
- // Collect all files involved, ensuring correct paths
68
- for (const file of Object.keys(datFileContent.files)) {
69
- const filePath = (0, hashUtils_1.getFilePathFromSha256)(datFileContent.files[file].sha256, path.join(directoryPath, storeId, "data"));
70
- filesInvolved.push(filePath);
71
- }
72
- }
73
- if (process.env.DIG_DEBUG === "1") {
74
- console.log("Files involved in the delta:");
75
- console.table(filesInvolved);
76
- }
77
- // list the manifest file last, this actually
78
- // helps with upload because by overriding the manifest file last,
79
- // the store can still be considered valid even when the upload is interrupted
80
- filesInvolved.push(manifestFilePath);
81
- return filesInvolved;
82
- };
83
- exports.getDeltaFiles = getDeltaFiles;