@dignetwork/dig-sdk 0.0.1-alpha.18 → 0.0.1-alpha.181
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/dist/DataIntegrityTree/DataIntegrityTree.d.ts +10 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.js +77 -10
- package/dist/DigNetwork/ContentServer.d.ts +22 -5
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +226 -28
- package/dist/DigNetwork/DigNetwork.d.ts +15 -9
- package/dist/DigNetwork/DigNetwork.d.ts.map +1 -1
- package/dist/DigNetwork/DigNetwork.js +129 -189
- package/dist/DigNetwork/DigPeer.d.ts +8 -3
- package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
- package/dist/DigNetwork/DigPeer.js +72 -115
- package/dist/DigNetwork/IncentiveServer.d.ts.map +1 -1
- package/dist/DigNetwork/IncentiveServer.js +6 -5
- package/dist/DigNetwork/PropagationServer.d.ts +89 -33
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
- package/dist/DigNetwork/PropagationServer.js +625 -358
- package/dist/blockchain/DataStore.d.ts +25 -7
- package/dist/blockchain/DataStore.d.ts.map +1 -1
- package/dist/blockchain/DataStore.js +117 -159
- package/dist/blockchain/DataStoreSerializer.d.ts +1 -1
- package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.d.ts +95 -10
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.js +325 -115
- package/dist/blockchain/ServerCoin.d.ts +13 -5
- package/dist/blockchain/ServerCoin.d.ts.map +1 -1
- package/dist/blockchain/ServerCoin.js +89 -28
- package/dist/blockchain/StoreMonitorRegistry.d.ts +85 -0
- package/dist/blockchain/StoreMonitorRegistry.d.ts.map +1 -0
- package/dist/blockchain/StoreMonitorRegistry.js +238 -0
- package/dist/blockchain/Wallet.d.ts +2 -2
- package/dist/blockchain/Wallet.d.ts.map +1 -1
- package/dist/blockchain/Wallet.js +50 -18
- package/dist/blockchain/coins.d.ts +1 -2
- package/dist/blockchain/coins.d.ts.map +1 -1
- package/dist/blockchain/coins.js +1 -55
- package/dist/blockchain/index.d.ts +1 -0
- package/dist/blockchain/index.d.ts.map +1 -1
- package/dist/blockchain/index.js +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/ContentScanner.d.ts +63 -0
- package/dist/utils/ContentScanner.d.ts.map +1 -0
- package/dist/utils/ContentScanner.js +175 -0
- package/dist/utils/DigCache.d.ts +38 -0
- package/dist/utils/DigCache.d.ts.map +1 -0
- package/dist/utils/DigCache.js +236 -0
- package/dist/utils/Environment.d.ts +21 -0
- package/dist/utils/Environment.d.ts.map +1 -0
- package/dist/utils/Environment.js +93 -0
- package/dist/utils/FileCache.d.ts +1 -1
- package/dist/utils/FileCache.d.ts.map +1 -1
- package/dist/utils/FileCache.js +2 -2
- package/dist/utils/FileTransfer.d.ts +47 -0
- package/dist/utils/FileTransfer.d.ts.map +1 -0
- package/dist/utils/FileTransfer.js +209 -0
- package/dist/utils/NconfManager.d.ts.map +1 -1
- package/dist/utils/NconfManager.js +16 -7
- package/dist/utils/PeerRanker.d.ts +55 -0
- package/dist/utils/PeerRanker.d.ts.map +1 -0
- package/dist/utils/PeerRanker.js +186 -0
- package/dist/utils/StoreArchiveManager.d.ts +45 -0
- package/dist/utils/StoreArchiveManager.d.ts.map +1 -0
- package/dist/utils/StoreArchiveManager.js +153 -0
- package/dist/utils/Udi.d.ts +28 -0
- package/dist/utils/Udi.d.ts.map +1 -0
- package/dist/utils/Udi.js +145 -0
- package/dist/utils/config.d.ts +4 -3
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +13 -8
- package/dist/utils/directoryUtils.d.ts +16 -0
- package/dist/utils/directoryUtils.d.ts.map +1 -1
- package/dist/utils/directoryUtils.js +66 -0
- package/dist/utils/index.d.ts +5 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +5 -1
- package/dist/utils/merkle.d.ts +2 -0
- package/dist/utils/merkle.d.ts.map +1 -0
- package/dist/utils/merkle.js +28 -0
- package/dist/utils/network.d.ts +2 -1
- package/dist/utils/network.d.ts.map +1 -1
- package/dist/utils/network.js +40 -15
- package/dist/utils/promiseUtils.d.ts +27 -0
- package/dist/utils/promiseUtils.d.ts.map +1 -0
- package/dist/utils/promiseUtils.js +69 -0
- package/dist/utils/ssl.js +2 -2
- package/package.json +31 -13
- package/dist/utils/deltaUtils.d.ts +0 -2
- package/dist/utils/deltaUtils.d.ts.map +0 -1
- package/dist/utils/deltaUtils.js +0 -83
|
@@ -6,23 +6,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.NconfManager = void 0;
|
|
7
7
|
const nconf_1 = __importDefault(require("nconf"));
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const async_mutex_1 = require("async-mutex");
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
11
|
const config_1 = require("./config");
|
|
11
|
-
const
|
|
12
|
+
const Environment_1 = require("./Environment");
|
|
13
|
+
const CONF_FOLDER_PATH = Environment_1.Environment.DIG_FOLDER_PATH || config_1.USER_DIR_PATH;
|
|
14
|
+
const fileMutex = new async_mutex_1.Mutex();
|
|
12
15
|
class NconfManager {
|
|
13
16
|
constructor(relativePath) {
|
|
14
17
|
this.configFilePath = path_1.default.join(CONF_FOLDER_PATH, relativePath);
|
|
15
18
|
this.initializeConfig();
|
|
16
19
|
}
|
|
17
20
|
async initializeConfig() {
|
|
21
|
+
const release = await fileMutex.acquire();
|
|
18
22
|
const directory = path_1.default.dirname(this.configFilePath);
|
|
19
|
-
|
|
20
|
-
await fs_extra_1.default.
|
|
21
|
-
|
|
23
|
+
try {
|
|
24
|
+
if (!(await fs_extra_1.default.pathExists(directory))) {
|
|
25
|
+
await fs_extra_1.default.mkdirp(directory);
|
|
26
|
+
console.log("Directory created:", directory);
|
|
27
|
+
}
|
|
28
|
+
if (!(await fs_extra_1.default.pathExists(this.configFilePath))) {
|
|
29
|
+
await fs_extra_1.default.writeFile(this.configFilePath, "{}");
|
|
30
|
+
console.log("Configuration file created:", this.configFilePath);
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
console.log("Configuration file created:", this.configFilePath);
|
|
33
|
+
finally {
|
|
34
|
+
release();
|
|
26
35
|
}
|
|
27
36
|
nconf_1.default.file({ file: this.configFilePath });
|
|
28
37
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface PeerMetrics {
|
|
2
|
+
ip: string;
|
|
3
|
+
latency: number;
|
|
4
|
+
bandwidth: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Utility class to rank peers based on latency and upload bandwidth using HTTPS with mTLS.
|
|
8
|
+
*/
|
|
9
|
+
export declare class PeerRanker {
|
|
10
|
+
private ipAddresses;
|
|
11
|
+
private static certPath;
|
|
12
|
+
private static keyPath;
|
|
13
|
+
private timeout;
|
|
14
|
+
private uploadTestSize;
|
|
15
|
+
private sortedPeers;
|
|
16
|
+
private currentIndex;
|
|
17
|
+
/**
|
|
18
|
+
* Constructs a PeerRanker instance.
|
|
19
|
+
* @param ipAddresses - Array of IP addresses to rank.
|
|
20
|
+
*/
|
|
21
|
+
constructor(ipAddresses: string[], timeout?: number, uploadTestSize?: number);
|
|
22
|
+
/**
|
|
23
|
+
* Measures the latency of a given IP address using an HTTPS request.
|
|
24
|
+
* Tries HEAD first, then falls back to GET if HEAD is not supported.
|
|
25
|
+
* If the latency is cached, returns the cached value.
|
|
26
|
+
* @param ip - The IP address of the peer.
|
|
27
|
+
* @returns Promise resolving to the latency in milliseconds or rejecting if the peer fails.
|
|
28
|
+
*/
|
|
29
|
+
private measureLatency;
|
|
30
|
+
/**
|
|
31
|
+
* Measures the upload bandwidth of a given IP address by sending random data.
|
|
32
|
+
* If the bandwidth is cached, returns the cached value.
|
|
33
|
+
* @param ip - The IP address of the peer.
|
|
34
|
+
* @returns Promise resolving to the upload bandwidth in bytes per second or rejecting if the peer fails.
|
|
35
|
+
*/
|
|
36
|
+
private measureBandwidth;
|
|
37
|
+
/**
|
|
38
|
+
* Ranks the peers based on measured latency and upload bandwidth.
|
|
39
|
+
* Unresponsive peers are excluded from the final ranking.
|
|
40
|
+
* @param cooldown - Cooldown time in milliseconds between batches.
|
|
41
|
+
* @returns Promise resolving to an array of PeerMetrics sorted by latency and bandwidth.
|
|
42
|
+
*/
|
|
43
|
+
rankPeers(cooldown?: number): Promise<PeerMetrics[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the next best peer based on the ranking.
|
|
46
|
+
* Cycles through the list, resetting to the beginning once the end is reached.
|
|
47
|
+
* @returns The next PeerMetrics object or null if no peers are available.
|
|
48
|
+
*/
|
|
49
|
+
GetNextBestPeer(): PeerMetrics | null;
|
|
50
|
+
/**
|
|
51
|
+
* Resets the internal iterator to start from the beginning of the sorted list.
|
|
52
|
+
*/
|
|
53
|
+
resetIterator(): void;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=PeerRanker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PeerRanker.d.ts","sourceRoot":"","sources":["../../src/utils/PeerRanker.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,WAAW,CAAW;IAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAC/B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAS;IAG/B,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,YAAY,CAAa;IAEjC;;;OAGG;gBACS,WAAW,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,MAAa,EAAE,cAAc,GAAE,MAAoB;IAW/F;;;;;;OAMG;YACW,cAAc;IAkD5B;;;;;OAKG;YACW,gBAAgB;IA2C9B;;;;;OAKG;IACU,SAAS,CAAC,QAAQ,GAAE,MAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAmCtE;;;;OAIG;IACI,eAAe,IAAI,WAAW,GAAG,IAAI;IAW5C;;OAEG;IACI,aAAa,IAAI,IAAI;CAG7B"}
|
|
@@ -0,0 +1,186 @@
|
|
|
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.PeerRanker = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const https_1 = __importDefault(require("https"));
|
|
10
|
+
const ssl_1 = require("./ssl");
|
|
11
|
+
const promiseUtils_1 = require("./promiseUtils");
|
|
12
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
13
|
+
// Cache with TTL of 1 day (86400 seconds)
|
|
14
|
+
const peerCache = new node_cache_1.default({ stdTTL: 86400 });
|
|
15
|
+
/**
|
|
16
|
+
* Utility class to rank peers based on latency and upload bandwidth using HTTPS with mTLS.
|
|
17
|
+
*/
|
|
18
|
+
class PeerRanker {
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a PeerRanker instance.
|
|
21
|
+
* @param ipAddresses - Array of IP addresses to rank.
|
|
22
|
+
*/
|
|
23
|
+
constructor(ipAddresses, timeout = 5000, uploadTestSize = 1024 * 1024) {
|
|
24
|
+
// Internal properties for iteration
|
|
25
|
+
this.sortedPeers = [];
|
|
26
|
+
this.currentIndex = 0;
|
|
27
|
+
this.ipAddresses = ipAddresses;
|
|
28
|
+
this.timeout = timeout; // Allow customizable timeout
|
|
29
|
+
this.uploadTestSize = uploadTestSize; // Default upload size: 1MB
|
|
30
|
+
// Fetch the SSL certificates used for mTLS.
|
|
31
|
+
const { certPath, keyPath } = (0, ssl_1.getOrCreateSSLCerts)();
|
|
32
|
+
PeerRanker.certPath = certPath;
|
|
33
|
+
PeerRanker.keyPath = keyPath;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Measures the latency of a given IP address using an HTTPS request.
|
|
37
|
+
* Tries HEAD first, then falls back to GET if HEAD is not supported.
|
|
38
|
+
* If the latency is cached, returns the cached value.
|
|
39
|
+
* @param ip - The IP address of the peer.
|
|
40
|
+
* @returns Promise resolving to the latency in milliseconds or rejecting if the peer fails.
|
|
41
|
+
*/
|
|
42
|
+
async measureLatency(ip) {
|
|
43
|
+
const cachedMetrics = await peerCache.get(ip);
|
|
44
|
+
if (cachedMetrics && cachedMetrics.latency) {
|
|
45
|
+
return cachedMetrics.latency;
|
|
46
|
+
}
|
|
47
|
+
const url = `https://${ip}:4159/diagnostics/ping`;
|
|
48
|
+
const configHead = {
|
|
49
|
+
url: url,
|
|
50
|
+
method: 'HEAD',
|
|
51
|
+
httpsAgent: new https_1.default.Agent({
|
|
52
|
+
cert: fs_1.default.readFileSync(PeerRanker.certPath),
|
|
53
|
+
key: fs_1.default.readFileSync(PeerRanker.keyPath),
|
|
54
|
+
rejectUnauthorized: false,
|
|
55
|
+
}),
|
|
56
|
+
timeout: this.timeout,
|
|
57
|
+
validateStatus: (status) => status < 500,
|
|
58
|
+
};
|
|
59
|
+
const startTime = Date.now();
|
|
60
|
+
try {
|
|
61
|
+
const response = await (0, axios_1.default)(configHead);
|
|
62
|
+
if (response.status === 405) {
|
|
63
|
+
const configGet = {
|
|
64
|
+
url: url,
|
|
65
|
+
method: 'GET',
|
|
66
|
+
httpsAgent: new https_1.default.Agent({
|
|
67
|
+
cert: fs_1.default.readFileSync(PeerRanker.certPath),
|
|
68
|
+
key: fs_1.default.readFileSync(PeerRanker.keyPath),
|
|
69
|
+
rejectUnauthorized: false,
|
|
70
|
+
}),
|
|
71
|
+
timeout: this.timeout,
|
|
72
|
+
headers: {
|
|
73
|
+
'Range': 'bytes=0-0',
|
|
74
|
+
},
|
|
75
|
+
validateStatus: (status) => status < 500,
|
|
76
|
+
};
|
|
77
|
+
await (0, axios_1.default)(configGet);
|
|
78
|
+
}
|
|
79
|
+
const latency = Date.now() - startTime;
|
|
80
|
+
// Cache the latency for the IP
|
|
81
|
+
peerCache.set(ip, { ...cachedMetrics, latency });
|
|
82
|
+
return latency;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw new Error(`Latency measurement failed for IP ${ip}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Measures the upload bandwidth of a given IP address by sending random data.
|
|
90
|
+
* If the bandwidth is cached, returns the cached value.
|
|
91
|
+
* @param ip - The IP address of the peer.
|
|
92
|
+
* @returns Promise resolving to the upload bandwidth in bytes per second or rejecting if the peer fails.
|
|
93
|
+
*/
|
|
94
|
+
async measureBandwidth(ip) {
|
|
95
|
+
const cachedMetrics = await peerCache.get(ip);
|
|
96
|
+
if (cachedMetrics && cachedMetrics.bandwidth) {
|
|
97
|
+
return cachedMetrics.bandwidth;
|
|
98
|
+
}
|
|
99
|
+
const url = `https://${ip}:4159/diagnostics/bandwidth`;
|
|
100
|
+
const randomData = Buffer.alloc(this.uploadTestSize, 'a');
|
|
101
|
+
const config = {
|
|
102
|
+
url: url,
|
|
103
|
+
method: 'POST',
|
|
104
|
+
data: randomData,
|
|
105
|
+
headers: {
|
|
106
|
+
'Content-Type': 'application/octet-stream',
|
|
107
|
+
'Content-Length': this.uploadTestSize,
|
|
108
|
+
},
|
|
109
|
+
httpsAgent: new https_1.default.Agent({
|
|
110
|
+
cert: fs_1.default.readFileSync(PeerRanker.certPath),
|
|
111
|
+
key: fs_1.default.readFileSync(PeerRanker.keyPath),
|
|
112
|
+
rejectUnauthorized: false,
|
|
113
|
+
}),
|
|
114
|
+
timeout: this.timeout,
|
|
115
|
+
maxContentLength: Infinity,
|
|
116
|
+
maxBodyLength: Infinity,
|
|
117
|
+
};
|
|
118
|
+
const startTime = Date.now();
|
|
119
|
+
try {
|
|
120
|
+
await (0, axios_1.default)(config);
|
|
121
|
+
const timeElapsed = (Date.now() - startTime) / 1000;
|
|
122
|
+
const bandwidth = this.uploadTestSize / timeElapsed;
|
|
123
|
+
// Cache the bandwidth for the IP
|
|
124
|
+
peerCache.set(ip, { ...cachedMetrics, bandwidth });
|
|
125
|
+
return bandwidth;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw new Error(`Bandwidth measurement failed for IP ${ip}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Ranks the peers based on measured latency and upload bandwidth.
|
|
133
|
+
* Unresponsive peers are excluded from the final ranking.
|
|
134
|
+
* @param cooldown - Cooldown time in milliseconds between batches.
|
|
135
|
+
* @returns Promise resolving to an array of PeerMetrics sorted by latency and bandwidth.
|
|
136
|
+
*/
|
|
137
|
+
async rankPeers(cooldown = 500) {
|
|
138
|
+
const limit = 5; // Limit to 5 parallel requests at a time
|
|
139
|
+
const iteratorFn = async (ip) => {
|
|
140
|
+
try {
|
|
141
|
+
const [latency, bandwidth] = await Promise.all([
|
|
142
|
+
this.measureLatency(ip),
|
|
143
|
+
this.measureBandwidth(ip),
|
|
144
|
+
]);
|
|
145
|
+
return { ip, latency, bandwidth };
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
// Peer failed, skip it by returning null
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
// Process all peers with a concurrency limit and cooldown between batches
|
|
153
|
+
const peerMetrics = (await (0, promiseUtils_1.asyncPool)(limit, this.ipAddresses, iteratorFn, cooldown)).filter((metrics) => metrics !== null); // Use a type guard
|
|
154
|
+
// Sort by lowest latency first, then by highest bandwidth
|
|
155
|
+
peerMetrics.sort((a, b) => {
|
|
156
|
+
if (a.latency === b.latency) {
|
|
157
|
+
return b.bandwidth - a.bandwidth; // Higher bandwidth is better
|
|
158
|
+
}
|
|
159
|
+
return a.latency - b.latency; // Lower latency is better
|
|
160
|
+
});
|
|
161
|
+
this.sortedPeers = peerMetrics;
|
|
162
|
+
this.currentIndex = 0;
|
|
163
|
+
return peerMetrics;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns the next best peer based on the ranking.
|
|
167
|
+
* Cycles through the list, resetting to the beginning once the end is reached.
|
|
168
|
+
* @returns The next PeerMetrics object or null if no peers are available.
|
|
169
|
+
*/
|
|
170
|
+
GetNextBestPeer() {
|
|
171
|
+
if (this.sortedPeers.length === 0) {
|
|
172
|
+
console.warn('Peer list is empty. Please run rankPeers() first.');
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const peer = this.sortedPeers[this.currentIndex];
|
|
176
|
+
this.currentIndex = (this.currentIndex + 1) % this.sortedPeers.length;
|
|
177
|
+
return peer;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Resets the internal iterator to start from the beginning of the sorted list.
|
|
181
|
+
*/
|
|
182
|
+
resetIterator() {
|
|
183
|
+
this.currentIndex = 0;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.PeerRanker = PeerRanker;
|
|
@@ -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;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare class Udi {
|
|
2
|
+
readonly chainName: string;
|
|
3
|
+
private readonly _storeId;
|
|
4
|
+
private readonly _rootHash;
|
|
5
|
+
readonly resourceKey: string | null;
|
|
6
|
+
static readonly nid: string;
|
|
7
|
+
static readonly namespace: string;
|
|
8
|
+
constructor(chainName: string, storeId: string | Buffer, rootHash?: string | Buffer | null, resourceKey?: string | null);
|
|
9
|
+
static convertToBuffer(input: string | Buffer): Buffer;
|
|
10
|
+
static isHex(input: string): boolean;
|
|
11
|
+
static isBase32(input: string): boolean;
|
|
12
|
+
static addBase32Padding(input: string): string;
|
|
13
|
+
withRootHash(rootHash: string | Buffer | null): Udi;
|
|
14
|
+
withResourceKey(resourceKey: string | null): Udi;
|
|
15
|
+
static fromUrn(urn: string): Udi;
|
|
16
|
+
toUrn(encoding?: "hex" | "base32"): string;
|
|
17
|
+
bufferToString(buffer: Buffer, encoding: "hex" | "base32"): string;
|
|
18
|
+
equals(other: Udi): boolean;
|
|
19
|
+
toString(): string;
|
|
20
|
+
clone(): Udi;
|
|
21
|
+
hashCode(): string;
|
|
22
|
+
get storeId(): string;
|
|
23
|
+
get rootHash(): string | null;
|
|
24
|
+
get storeIdBase32(): string;
|
|
25
|
+
get rootHashBase32(): string | null;
|
|
26
|
+
}
|
|
27
|
+
export { Udi };
|
|
28
|
+
//# sourceMappingURL=Udi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Udi.d.ts","sourceRoot":"","sources":["../../src/utils/Udi.ts"],"names":[],"mappings":"AAIA,cAAM,GAAG;IACP,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAS;IACpC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAoB;gBAGnD,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,QAAQ,GAAE,MAAM,GAAG,MAAM,GAAG,IAAW,EACvC,WAAW,GAAE,MAAM,GAAG,IAAW;IAWnC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAmBtD,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIpC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIvC,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAM9C,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG;IAInD,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,GAAG;IAIhD,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;IA4BhC,KAAK,CAAC,QAAQ,GAAE,KAAK,GAAG,QAAgB,GAAG,MAAM;IAgBjD,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM;IAMlE,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAW3B,QAAQ,IAAI,MAAM;IAIlB,KAAK,IAAI,GAAG;IASZ,QAAQ,IAAI,MAAM;IAMlB,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,QAAQ,IAAI,MAAM,GAAG,IAAI,CAE5B;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,cAAc,IAAI,MAAM,GAAG,IAAI,CAIlC;CACF;AAED,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
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.Udi = void 0;
|
|
27
|
+
const urns = __importStar(require("urns"));
|
|
28
|
+
const crypto_1 = require("crypto");
|
|
29
|
+
const hi_base32_1 = require("hi-base32");
|
|
30
|
+
class Udi {
|
|
31
|
+
constructor(chainName, storeId, rootHash = null, resourceKey = null) {
|
|
32
|
+
if (!storeId) {
|
|
33
|
+
throw new Error("storeId cannot be empty");
|
|
34
|
+
}
|
|
35
|
+
this.chainName = chainName || "chia";
|
|
36
|
+
this._storeId = Udi.convertToBuffer(storeId);
|
|
37
|
+
this._rootHash = rootHash ? Udi.convertToBuffer(rootHash) : null;
|
|
38
|
+
this.resourceKey = resourceKey;
|
|
39
|
+
}
|
|
40
|
+
static convertToBuffer(input) {
|
|
41
|
+
if (Buffer.isBuffer(input)) {
|
|
42
|
+
return input;
|
|
43
|
+
}
|
|
44
|
+
if (Udi.isHex(input)) {
|
|
45
|
+
return Buffer.from(input, "hex");
|
|
46
|
+
}
|
|
47
|
+
if (Udi.isBase32(input)) {
|
|
48
|
+
const paddedInput = Udi.addBase32Padding(input.toUpperCase());
|
|
49
|
+
return Buffer.from((0, hi_base32_1.decode)(paddedInput, false)); // Decode as UTF-8
|
|
50
|
+
}
|
|
51
|
+
throw new Error("Invalid input encoding. Must be 32-byte hex or Base32 string.");
|
|
52
|
+
}
|
|
53
|
+
static isHex(input) {
|
|
54
|
+
return /^[a-fA-F0-9]{64}$/.test(input);
|
|
55
|
+
}
|
|
56
|
+
static isBase32(input) {
|
|
57
|
+
return /^[a-z2-7]{52}$/.test(input.toLowerCase());
|
|
58
|
+
}
|
|
59
|
+
static addBase32Padding(input) {
|
|
60
|
+
// Calculate required padding
|
|
61
|
+
const paddingNeeded = (8 - (input.length % 8)) % 8;
|
|
62
|
+
return input + "=".repeat(paddingNeeded);
|
|
63
|
+
}
|
|
64
|
+
withRootHash(rootHash) {
|
|
65
|
+
return new Udi(this.chainName, this._storeId, rootHash, this.resourceKey);
|
|
66
|
+
}
|
|
67
|
+
withResourceKey(resourceKey) {
|
|
68
|
+
return new Udi(this.chainName, this._storeId, this._rootHash, resourceKey);
|
|
69
|
+
}
|
|
70
|
+
static fromUrn(urn) {
|
|
71
|
+
const parsedUrn = urns.parseURN(urn);
|
|
72
|
+
if (parsedUrn.nid.toLowerCase() !== Udi.nid) {
|
|
73
|
+
throw new Error(`Invalid nid: ${parsedUrn.nid}`);
|
|
74
|
+
}
|
|
75
|
+
const parts = parsedUrn.nss.split(":");
|
|
76
|
+
if (parts.length < 2) {
|
|
77
|
+
throw new Error(`Invalid UDI format: ${parsedUrn.nss}`);
|
|
78
|
+
}
|
|
79
|
+
const chainName = parts[0];
|
|
80
|
+
const storeId = parts[1].split("/")[0];
|
|
81
|
+
let rootHash = null;
|
|
82
|
+
if (parts.length > 2) {
|
|
83
|
+
rootHash = parts[2].split("/")[0];
|
|
84
|
+
}
|
|
85
|
+
const pathParts = parsedUrn.nss.split("/");
|
|
86
|
+
let resourceKey = null;
|
|
87
|
+
if (pathParts.length > 1) {
|
|
88
|
+
resourceKey = pathParts.slice(1).join("/");
|
|
89
|
+
}
|
|
90
|
+
return new Udi(chainName, storeId, rootHash, resourceKey);
|
|
91
|
+
}
|
|
92
|
+
toUrn(encoding = "hex") {
|
|
93
|
+
const storeIdStr = this.bufferToString(this._storeId, encoding);
|
|
94
|
+
let urn = `${Udi.namespace}:${this.chainName}:${storeIdStr}`;
|
|
95
|
+
if (this._rootHash) {
|
|
96
|
+
const rootHashStr = this.bufferToString(this._rootHash, encoding);
|
|
97
|
+
urn += `:${rootHashStr}`;
|
|
98
|
+
}
|
|
99
|
+
if (this.resourceKey) {
|
|
100
|
+
urn += `/${this.resourceKey}`;
|
|
101
|
+
}
|
|
102
|
+
return urn;
|
|
103
|
+
}
|
|
104
|
+
bufferToString(buffer, encoding) {
|
|
105
|
+
return encoding === "hex"
|
|
106
|
+
? buffer.toString("hex")
|
|
107
|
+
: (0, hi_base32_1.encode)(buffer).toLowerCase().replace(/=+$/, "");
|
|
108
|
+
}
|
|
109
|
+
equals(other) {
|
|
110
|
+
return (this._storeId.equals(other._storeId) &&
|
|
111
|
+
this.chainName === other.chainName &&
|
|
112
|
+
(this._rootHash && other._rootHash
|
|
113
|
+
? this._rootHash.equals(other._rootHash)
|
|
114
|
+
: this._rootHash === other._rootHash) &&
|
|
115
|
+
this.resourceKey === other.resourceKey);
|
|
116
|
+
}
|
|
117
|
+
toString() {
|
|
118
|
+
return this.toUrn();
|
|
119
|
+
}
|
|
120
|
+
clone() {
|
|
121
|
+
return new Udi(this.chainName, this._storeId, this._rootHash, this.resourceKey);
|
|
122
|
+
}
|
|
123
|
+
hashCode() {
|
|
124
|
+
const hash = (0, crypto_1.createHash)("sha256");
|
|
125
|
+
hash.update(this.toUrn());
|
|
126
|
+
return hash.digest("hex");
|
|
127
|
+
}
|
|
128
|
+
get storeId() {
|
|
129
|
+
return this._storeId.toString("hex");
|
|
130
|
+
}
|
|
131
|
+
get rootHash() {
|
|
132
|
+
return this._rootHash ? this._rootHash.toString("hex") : null;
|
|
133
|
+
}
|
|
134
|
+
get storeIdBase32() {
|
|
135
|
+
return this.bufferToString(this._storeId, "base32");
|
|
136
|
+
}
|
|
137
|
+
get rootHashBase32() {
|
|
138
|
+
return this._rootHash
|
|
139
|
+
? this.bufferToString(this._rootHash, "base32")
|
|
140
|
+
: null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.Udi = Udi;
|
|
144
|
+
Udi.nid = "dig";
|
|
145
|
+
Udi.namespace = `urn:${Udi.nid}`;
|