@dignetwork/dig-sdk 0.0.1-alpha.4 → 0.0.1-alpha.42

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 (47) hide show
  1. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +160 -0
  2. package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -0
  3. package/dist/DataIntegrityTree/DataIntegrityTree.js +672 -0
  4. package/dist/DataIntegrityTree/DataLayerError.d.ts +6 -0
  5. package/dist/DataIntegrityTree/DataLayerError.d.ts.map +1 -0
  6. package/dist/DataIntegrityTree/DataLayerError.js +17 -0
  7. package/dist/DataIntegrityTree/index.d.ts +2 -0
  8. package/dist/DataIntegrityTree/index.d.ts.map +1 -0
  9. package/dist/DataIntegrityTree/index.js +17 -0
  10. package/dist/DigNetwork/ContentServer.d.ts +5 -1
  11. package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
  12. package/dist/DigNetwork/ContentServer.js +28 -13
  13. package/dist/DigNetwork/DigNetwork.d.ts +1 -0
  14. package/dist/DigNetwork/DigNetwork.d.ts.map +1 -1
  15. package/dist/DigNetwork/DigNetwork.js +79 -50
  16. package/dist/DigNetwork/DigPeer.d.ts +5 -1
  17. package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
  18. package/dist/DigNetwork/DigPeer.js +51 -16
  19. package/dist/DigNetwork/PropagationServer.d.ts +7 -1
  20. package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
  21. package/dist/DigNetwork/PropagationServer.js +100 -68
  22. package/dist/blockchain/DataStore.d.ts +2 -2
  23. package/dist/blockchain/DataStore.d.ts.map +1 -1
  24. package/dist/blockchain/DataStore.js +9 -5
  25. package/dist/blockchain/DataStoreSerializer.d.ts +1 -1
  26. package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -1
  27. package/dist/blockchain/FullNodePeer.d.ts +8 -1
  28. package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
  29. package/dist/blockchain/FullNodePeer.js +39 -7
  30. package/dist/blockchain/ServerCoin.d.ts +11 -3
  31. package/dist/blockchain/ServerCoin.d.ts.map +1 -1
  32. package/dist/blockchain/ServerCoin.js +30 -17
  33. package/dist/blockchain/Wallet.d.ts +1 -1
  34. package/dist/blockchain/Wallet.d.ts.map +1 -1
  35. package/dist/blockchain/Wallet.js +1 -1
  36. package/dist/blockchain/coins.d.ts +1 -1
  37. package/dist/blockchain/coins.d.ts.map +1 -1
  38. package/dist/blockchain/coins.js +1 -1
  39. package/dist/index.d.ts +1 -1
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +1 -1
  42. package/dist/utils/config.d.ts.map +1 -1
  43. package/dist/utils/config.js +4 -9
  44. package/dist/utils/directoryUtils.d.ts +1 -7
  45. package/dist/utils/directoryUtils.d.ts.map +1 -1
  46. package/dist/utils/directoryUtils.js +30 -11
  47. package/package.json +3 -3
@@ -0,0 +1,160 @@
1
+ import { MerkleTree } from "merkletreejs";
2
+ import { Readable } from "stream";
3
+ export interface DataIntegrityTreeOptions {
4
+ storeDir?: string;
5
+ storageMode?: "local" | "unified";
6
+ rootHash?: string;
7
+ disableInitialize?: boolean;
8
+ }
9
+ /**
10
+ * DataStoreManager class to manage Merkle tree operations.
11
+ */
12
+ declare class DataIntegrityTree {
13
+ private storeId;
14
+ private storeBaseDir;
15
+ private storeDir;
16
+ private dataDir;
17
+ files: Map<string, {
18
+ hash: string;
19
+ sha256: string;
20
+ }>;
21
+ private tree;
22
+ constructor(storeId: string, options?: DataIntegrityTreeOptions);
23
+ static from(storeId: string, options: DataIntegrityTreeOptions): DataIntegrityTree;
24
+ /**
25
+ * Load the manifest file.
26
+ * @private
27
+ */
28
+ private _loadManifest;
29
+ /**
30
+ * Load the latest tree from the manifest file.
31
+ * @private
32
+ */
33
+ private _loadLatestTree;
34
+ /**
35
+ * Save a binary stream to the store's data directory.
36
+ * @param sha256 - The SHA-256 hash of the buffer.
37
+ * @returns The write stream for the file.
38
+ */
39
+ private _createWriteStream;
40
+ /**
41
+ * Stream file from one path to another.
42
+ * @param src - The source file path.
43
+ * @param dest - The destination file path.
44
+ */
45
+ private _streamFile;
46
+ /**
47
+ * Upsert a key with a binary stream to the Merkle tree.
48
+ * Compresses the file, calculates the SHA-256 of the uncompressed file, and stores it.
49
+ * @param readStream - The binary data stream.
50
+ * @param key - The hexadecimal key for the binary data.
51
+ */
52
+ upsertKey(readStream: Readable, key: string): Promise<void>;
53
+ /**
54
+ * Delete a key from the Merkle tree.
55
+ * @param key - The hexadecimal key to delete.
56
+ */
57
+ deleteKey(key: string): void;
58
+ /**
59
+ * List all keys in the Merkle tree.
60
+ * @param rootHash - The root hash of the tree. Defaults to the latest root hash.
61
+ * @returns The list of keys.
62
+ */
63
+ listKeys(rootHash?: string | null): string[];
64
+ /**
65
+ * Rebuild the Merkle tree from the current files.
66
+ * @private
67
+ */
68
+ private _rebuildTree;
69
+ /**
70
+ * Get the root of the Merkle tree.
71
+ * @param rootHash - The root hash of the tree. Defaults to the latest root hash.
72
+ * @returns The Merkle root.
73
+ */
74
+ getRoot(): string;
75
+ /**
76
+ * Serialize the Merkle tree to a JSON object.
77
+ * @param rootHash - The root hash of the tree. Defaults to the latest root hash.
78
+ * @returns The serialized Merkle tree.
79
+ */
80
+ serialize(rootHash?: string | null): object;
81
+ /**
82
+ * Deserialize a JSON object to a Merkle tree.
83
+ * @param rootHash - The root hash of the tree.
84
+ * @returns The deserialized Merkle tree.
85
+ */
86
+ deserializeTree(rootHash: string): MerkleTree;
87
+ private appendRootHashToManifest;
88
+ /**
89
+ * Commit the current state of the Merkle tree.
90
+ */
91
+ commit(): string | undefined;
92
+ /**
93
+ * Clear pending changes and revert to the latest committed state.
94
+ */
95
+ clearPendingRoot(): void;
96
+ /**
97
+ * Check if a file exists for a given key.
98
+ * @param hexKey - The hexadecimal key of the file.
99
+ * @param rootHash - The root hash of the tree. Defaults to the latest root hash.
100
+ * @returns A boolean indicating if the file exists.
101
+ */
102
+ hasKey(hexKey: string, rootHash?: string | null): boolean;
103
+ /**
104
+ * Get a readable stream for a file based on its key, with decompression.
105
+ * @param hexKey - The hexadecimal key of the file.
106
+ * @param rootHash - The root hash of the tree. Defaults to the latest root hash.
107
+ * @returns The readable stream for the file.
108
+ */
109
+ getValueStream(hexKey: string, rootHash?: string | null, byteOffset?: number | null, length?: number | null): Readable;
110
+ /**
111
+ * Delete all leaves from the Merkle tree.
112
+ */
113
+ deleteAllLeaves(): void;
114
+ getSHA256(hexKey: string, rootHash?: string): string | undefined;
115
+ /**
116
+ * Get a proof for a file based on its key and SHA-256 hash.
117
+ * @param hexKey - The hexadecimal key of the file.
118
+ * @param sha256 - The SHA-256 hash of the file.
119
+ * @param rootHash - The root hash of the tree. Defaults to the latest root hash.
120
+ * @returns The proof for the file as a hex string.
121
+ */
122
+ getProof(hexKey: string, sha256: string, rootHash?: string | null): string;
123
+ /**
124
+ * Verify a proof for a file against the Merkle tree.
125
+ * @param proofObjectHex - The proof object as a hex string.
126
+ * @param sha256 - The SHA-256 hash of the file.
127
+ * @returns True if the proof is valid, false otherwise.
128
+ */
129
+ verifyProof(proofObjectHex: string, sha256: string): boolean;
130
+ /**
131
+ * Get the difference between two Merkle tree roots.
132
+ * @param rootHash1 - The first root hash.
133
+ * @param rootHash2 - The second root hash.
134
+ * @returns An object containing the added and deleted keys and their SHA-256 hashes.
135
+ */
136
+ getRootDiff(rootHash1: string, rootHash2: string): {
137
+ added: Map<string, string>;
138
+ deleted: Map<string, string>;
139
+ };
140
+ /**
141
+ * Verify the integrity of a file based on its SHA-256 hash and check if it is in the specified Merkle root.
142
+ * @param sha256 - The SHA-256 hash of the file.
143
+ * @param root - The root hash to check against.
144
+ * @returns True if the file integrity is verified and it is in the Merkle root, false otherwise.
145
+ */
146
+ verifyKeyIntegrity(sha256: string, rootHash: string): Promise<boolean>;
147
+ /**
148
+ * Static method to validate key integrity using a foreign Merkle tree.
149
+ * Verifies if a given SHA-256 hash for a key exists within the foreign tree and checks if the root hash matches.
150
+ *
151
+ * @param key - The hexadecimal key of the file.
152
+ * @param sha256 - The SHA-256 hash of the file.
153
+ * @param serializedTree - The foreign serialized Merkle tree.
154
+ * @param expectedRootHash - The expected root hash of the Merkle tree.
155
+ * @returns A boolean indicating if the SHA-256 is present in the foreign tree and the root hash matches.
156
+ */
157
+ static validateKeyIntegrityWithForeignTree(key: string, sha256: string, serializedTree: object, expectedRootHash: string): boolean;
158
+ }
159
+ export { DataIntegrityTree };
160
+ //# sourceMappingURL=DataIntegrityTree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataIntegrityTree.d.ts","sourceRoot":"","sources":["../../src/DataIntegrityTree/DataIntegrityTree.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAuClC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,cAAM,iBAAiB;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACjB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAa;gBAEb,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B;WAiDrD,IAAI,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,wBAAwB,GAChC,iBAAiB;IAOpB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAQrB;;;OAGG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