@dignetwork/dig-sdk 0.0.1-alpha.2
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.
- package/LICENSE +7 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +160 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.js +648 -0
- package/dist/DataIntegrityTree/DataLayerError.d.ts +6 -0
- package/dist/DataIntegrityTree/DataLayerError.d.ts.map +1 -0
- package/dist/DataIntegrityTree/DataLayerError.js +17 -0
- package/dist/DataIntegrityTree/index.d.ts +2 -0
- package/dist/DataIntegrityTree/index.d.ts.map +1 -0
- package/dist/DataIntegrityTree/index.js +17 -0
- package/dist/DigNetwork/ContentServer.d.ts +28 -0
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -0
- package/dist/DigNetwork/ContentServer.js +243 -0
- package/dist/DigNetwork/DigChallenge.d.ts +82 -0
- package/dist/DigNetwork/DigChallenge.d.ts.map +1 -0
- package/dist/DigNetwork/DigChallenge.js +144 -0
- package/dist/DigNetwork/DigNetwork.d.ts +19 -0
- package/dist/DigNetwork/DigNetwork.d.ts.map +1 -0
- package/dist/DigNetwork/DigNetwork.js +222 -0
- package/dist/DigNetwork/DigPeer.d.ts +19 -0
- package/dist/DigNetwork/DigPeer.d.ts.map +1 -0
- package/dist/DigNetwork/DigPeer.js +164 -0
- package/dist/DigNetwork/IncentiveServer.d.ts +13 -0
- package/dist/DigNetwork/IncentiveServer.d.ts.map +1 -0
- package/dist/DigNetwork/IncentiveServer.js +76 -0
- package/dist/DigNetwork/PropagationServer.d.ts +41 -0
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -0
- package/dist/DigNetwork/PropagationServer.js +415 -0
- package/dist/DigNetwork/index.d.ts +4 -0
- package/dist/DigNetwork/index.d.ts.map +1 -0
- package/dist/DigNetwork/index.js +19 -0
- package/dist/blockchain/DataStore.d.ts +54 -0
- package/dist/blockchain/DataStore.d.ts.map +1 -0
- package/dist/blockchain/DataStore.js +410 -0
- package/dist/blockchain/DataStoreSerializer.d.ts +52 -0
- package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -0
- package/dist/blockchain/DataStoreSerializer.js +109 -0
- package/dist/blockchain/FullNodePeer.d.ts +17 -0
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -0
- package/dist/blockchain/FullNodePeer.js +215 -0
- package/dist/blockchain/ServerCoin.d.ts +21 -0
- package/dist/blockchain/ServerCoin.d.ts.map +1 -0
- package/dist/blockchain/ServerCoin.js +261 -0
- package/dist/blockchain/Wallet.d.ts +28 -0
- package/dist/blockchain/Wallet.d.ts.map +1 -0
- package/dist/blockchain/Wallet.js +220 -0
- package/dist/blockchain/coins.d.ts +6 -0
- package/dist/blockchain/coins.d.ts.map +1 -0
- package/dist/blockchain/coins.js +101 -0
- package/dist/blockchain/index.d.ts +8 -0
- package/dist/blockchain/index.d.ts.map +1 -0
- package/dist/blockchain/index.js +36 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/prompts.d.ts +21 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +149 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/utils/FileCache.d.ts +11 -0
- package/dist/utils/FileCache.d.ts.map +1 -0
- package/dist/utils/FileCache.js +58 -0
- package/dist/utils/NconfManager.d.ts +11 -0
- package/dist/utils/NconfManager.d.ts.map +1 -0
- package/dist/utils/NconfManager.js +55 -0
- package/dist/utils/config.d.ts +67 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +223 -0
- package/dist/utils/connectionUtils.d.ts +10 -0
- package/dist/utils/connectionUtils.d.ts.map +1 -0
- package/dist/utils/connectionUtils.js +18 -0
- package/dist/utils/credentialsUtils.d.ts +8 -0
- package/dist/utils/credentialsUtils.d.ts.map +1 -0
- package/dist/utils/credentialsUtils.js +122 -0
- package/dist/utils/deltaUtils.d.ts +2 -0
- package/dist/utils/deltaUtils.d.ts.map +1 -0
- package/dist/utils/deltaUtils.js +83 -0
- package/dist/utils/directoryUtils.d.ts +15 -0
- package/dist/utils/directoryUtils.d.ts.map +1 -0
- package/dist/utils/directoryUtils.js +91 -0
- package/dist/utils/encryption.d.ts +8 -0
- package/dist/utils/encryption.d.ts.map +1 -0
- package/dist/utils/encryption.js +55 -0
- package/dist/utils/hashUtils.d.ts +8 -0
- package/dist/utils/hashUtils.d.ts.map +1 -0
- package/dist/utils/hashUtils.js +44 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +29 -0
- package/dist/utils/network.d.ts +2 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +38 -0
- package/dist/utils/spinnerUtils.d.ts +2 -0
- package/dist/utils/spinnerUtils.d.ts.map +1 -0
- package/dist/utils/spinnerUtils.js +47 -0
- package/dist/utils/ssl.d.ts +5 -0
- package/dist/utils/ssl.d.ts.map +1 -0
- package/dist/utils/ssl.js +50 -0
- package/dist/utils/validationUtils.d.ts +9 -0
- package/dist/utils/validationUtils.d.ts.map +1 -0
- package/dist/utils/validationUtils.js +55 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 Michael Taylor
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -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): 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=DataInteg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