@dignetwork/dig-sdk 0.0.1-alpha.9 → 0.0.1-alpha.92

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 (64) hide show
  1. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +5 -2
  2. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -1
  3. package/dist/DataIntegrityTree/DataIntegrityTree.js +93 -34
  4. package/dist/DigNetwork/ContentServer.d.ts +10 -5
  5. package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
  6. package/dist/DigNetwork/ContentServer.js +89 -24
  7. package/dist/DigNetwork/DigNetwork.d.ts +3 -9
  8. package/dist/DigNetwork/DigNetwork.d.ts.map +1 -1
  9. package/dist/DigNetwork/DigNetwork.js +98 -189
  10. package/dist/DigNetwork/DigPeer.d.ts +8 -3
  11. package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
  12. package/dist/DigNetwork/DigPeer.js +68 -114
  13. package/dist/DigNetwork/PropagationServer.d.ts +67 -33
  14. package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
  15. package/dist/DigNetwork/PropagationServer.js +484 -363
  16. package/dist/blockchain/DataStore.d.ts +18 -7
  17. package/dist/blockchain/DataStore.d.ts.map +1 -1
  18. package/dist/blockchain/DataStore.js +78 -98
  19. package/dist/blockchain/DataStoreSerializer.d.ts +1 -1
  20. package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -1
  21. package/dist/blockchain/FullNodePeer.d.ts +9 -1
  22. package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
  23. package/dist/blockchain/FullNodePeer.js +45 -11
  24. package/dist/blockchain/ServerCoin.d.ts +11 -3
  25. package/dist/blockchain/ServerCoin.d.ts.map +1 -1
  26. package/dist/blockchain/ServerCoin.js +51 -17
  27. package/dist/blockchain/Wallet.d.ts +2 -2
  28. package/dist/blockchain/Wallet.d.ts.map +1 -1
  29. package/dist/blockchain/Wallet.js +51 -18
  30. package/dist/blockchain/coins.d.ts +1 -1
  31. package/dist/blockchain/coins.d.ts.map +1 -1
  32. package/dist/blockchain/coins.js +1 -1
  33. package/dist/types.d.ts +1 -0
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/utils/ContentScanner.d.ts +63 -0
  36. package/dist/utils/ContentScanner.d.ts.map +1 -0
  37. package/dist/utils/ContentScanner.js +175 -0
  38. package/dist/utils/FileTransfer.d.ts +47 -0
  39. package/dist/utils/FileTransfer.d.ts.map +1 -0
  40. package/dist/utils/FileTransfer.js +209 -0
  41. package/dist/utils/StoreArchiveManager.d.ts +45 -0
  42. package/dist/utils/StoreArchiveManager.d.ts.map +1 -0
  43. package/dist/utils/StoreArchiveManager.js +153 -0
  44. package/dist/utils/asyncPool.d.ts +9 -0
  45. package/dist/utils/asyncPool.d.ts.map +1 -0
  46. package/dist/utils/asyncPool.js +23 -0
  47. package/dist/utils/config.d.ts +4 -3
  48. package/dist/utils/config.d.ts.map +1 -1
  49. package/dist/utils/config.js +9 -5
  50. package/dist/utils/directoryUtils.d.ts +0 -6
  51. package/dist/utils/directoryUtils.d.ts.map +1 -1
  52. package/dist/utils/directoryUtils.js +30 -11
  53. package/dist/utils/index.d.ts +0 -1
  54. package/dist/utils/index.d.ts.map +1 -1
  55. package/dist/utils/index.js +0 -1
  56. package/dist/utils/merkle.d.ts +2 -0
  57. package/dist/utils/merkle.d.ts.map +1 -0
  58. package/dist/utils/merkle.js +28 -0
  59. package/dist/utils/network.d.ts.map +1 -1
  60. package/dist/utils/network.js +24 -9
  61. package/package.json +13 -3
  62. package/dist/utils/deltaUtils.d.ts +0 -2
  63. package/dist/utils/deltaUtils.d.ts.map +0 -1
  64. package/dist/utils/deltaUtils.js +0 -83
@@ -0,0 +1,28 @@
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.merkleIntegrityCheck = merkleIntegrityCheck;
7
+ const DataIntegrityTree_1 = require("../DataIntegrityTree");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ async function merkleIntegrityCheck(treePath, tmpDir, dataPath, roothash) {
11
+ const rootHashContent = fs_1.default.readFileSync(treePath, "utf-8");
12
+ const tree = JSON.parse(rootHashContent);
13
+ // Extract expected sha256 from dataPath
14
+ const expectedSha256 = dataPath.replace("data", "").replace(/\//g, "");
15
+ console.log("expectedSha256", expectedSha256);
16
+ // Find the hexKey in the tree based on matching sha256
17
+ const hexKey = Object.keys(tree.files).find((key) => {
18
+ const fileData = tree.files[key]; // Inline type definition
19
+ return fileData.sha256 === expectedSha256;
20
+ });
21
+ if (!hexKey) {
22
+ throw new Error(`No matching file found with sha256: ${expectedSha256}`);
23
+ }
24
+ // Validate the integrity with the foreign tree
25
+ const integrity = await DataIntegrityTree_1.DataIntegrityTree.validateKeyIntegrityWithForeignTree(hexKey, expectedSha256, tree, roothash, path_1.default.join(tmpDir, "data"));
26
+ console.log("Integrity check result:", integrity);
27
+ return integrity;
28
+ }
@@ -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":"AAmBA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA6CrE,CAAC"}
@@ -4,32 +4,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getPublicIpAddress = void 0;
7
+ /*
8
+ * Stopgap until better solution for finding public IPS found
9
+ */
7
10
  const superagent_1 = __importDefault(require("superagent"));
8
11
  const MAX_RETRIES = 5;
9
12
  const RETRY_DELAY = 2000; // in milliseconds
13
+ // Regular expression for validating both IPv4 and IPv6 addresses
14
+ const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
15
+ const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:)|(([0-9a-fA-F]{1,4}:){1,7}|:):(([0-9a-fA-F]{1,4}:){1,6}|:):([0-9a-fA-F]{1,4}|:):([0-9a-fA-F]{1,4}|:)|::)$/;
16
+ // Helper function to validate the IP address
17
+ const isValidIp = (ip) => {
18
+ return ipv4Regex.test(ip) || ipv6Regex.test(ip);
19
+ };
10
20
  const getPublicIpAddress = async () => {
11
21
  const publicIp = process.env.PUBLIC_IP;
12
22
  if (publicIp) {
13
- console.log('Public IP address from env:', publicIp);
14
- return publicIp;
23
+ console.log("Public IP address from env:", publicIp);
24
+ if (isValidIp(publicIp)) {
25
+ return publicIp;
26
+ }
27
+ console.error("Invalid public IP address in environment variable");
28
+ return undefined;
15
29
  }
16
30
  let attempt = 0;
17
31
  while (attempt < MAX_RETRIES) {
18
32
  try {
19
- const response = await superagent_1.default.get('https://api.datalayer.storage/user/v1/get_user_ip');
33
+ const response = await superagent_1.default.get("https://api.datalayer.storage/user/v1/get_user_ip");
20
34
  if (response.body && response.body.success) {
21
- console.log('Public IP address:', response.body);
22
- return response.body.ip_address;
23
- }
24
- else {
25
- throw new Error('Failed to retrieve public IP address');
35
+ const ipAddress = response.body.ip_address;
36
+ if (isValidIp(ipAddress)) {
37
+ return ipAddress;
38
+ }
39
+ throw new Error("Invalid IP address format received");
26
40
  }
41
+ throw new Error("Failed to retrieve public IP address");
27
42
  }
28
43
  catch (error) {
29
44
  attempt++;
30
45
  console.error(`Error fetching public IP address (Attempt ${attempt}):`, error.message);
31
46
  if (attempt >= MAX_RETRIES) {
32
- throw new Error('Could not retrieve public IP address after several attempts');
47
+ throw new Error("Could not retrieve public IP address after several attempts");
33
48
  }
34
49
  await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
35
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.9",
3
+ "version": "0.0.1-alpha.92",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",
@@ -25,6 +25,9 @@
25
25
  "LICENSE"
26
26
  ],
27
27
  "dependencies": {
28
+ "@dignetwork/datalayer-driver": "^0.1.25",
29
+ "archiver": "^7.0.1",
30
+ "axios": "^1.7.7",
28
31
  "bip39": "^3.1.0",
29
32
  "chia-bls": "^1.0.2",
30
33
  "chia-config-loader": "^1.0.1",
@@ -32,8 +35,9 @@
32
35
  "chia-server-coin": "^0.0.5",
33
36
  "chia-wallet": "^1.0.18",
34
37
  "cli-progress": "^3.12.0",
38
+ "colorette": "^2.0.20",
35
39
  "crypto-js": "^4.2.0",
36
- "datalayer-driver": "^0.1.21",
40
+ "figures": "^6.1.0",
37
41
  "fs-extra": "^11.2.0",
38
42
  "ignore": "^5.3.2",
39
43
  "inquirer": "^10.1.8",
@@ -41,9 +45,13 @@
41
45
  "merkletreejs": "^0.4.0",
42
46
  "nanospinner": "^1.1.0",
43
47
  "nconf": "^0.12.1",
44
- "superagent": "^10.0.0"
48
+ "node-cache": "^5.1.2",
49
+ "progress-stream": "^2.0.0",
50
+ "superagent": "^10.0.0",
51
+ "unzipper": "^0.12.3"
45
52
  },
46
53
  "devDependencies": {
54
+ "@types/archiver": "^6.0.2",
47
55
  "@types/chai": "^4.3.17",
48
56
  "@types/cli-progress": "^3.11.6",
49
57
  "@types/crypto-js": "^4.2.2",
@@ -53,7 +61,9 @@
53
61
  "@types/mocha": "^10.0.7",
54
62
  "@types/nconf": "^0.10.7",
55
63
  "@types/node": "^22.1.0",
64
+ "@types/progress-stream": "^2.0.5",
56
65
  "@types/superagent": "^8.1.8",
66
+ "@types/unzipper": "^0.10.10",
57
67
  "chai": "^5.1.1",
58
68
  "copyfiles": "^2.4.1",
59
69
  "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;