@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.
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +5 -2
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.js +93 -34
- package/dist/DigNetwork/ContentServer.d.ts +10 -5
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +89 -24
- package/dist/DigNetwork/DigNetwork.d.ts +3 -9
- package/dist/DigNetwork/DigNetwork.d.ts.map +1 -1
- package/dist/DigNetwork/DigNetwork.js +98 -189
- package/dist/DigNetwork/DigPeer.d.ts +8 -3
- package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
- package/dist/DigNetwork/DigPeer.js +68 -114
- package/dist/DigNetwork/PropagationServer.d.ts +67 -33
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
- package/dist/DigNetwork/PropagationServer.js +484 -363
- package/dist/blockchain/DataStore.d.ts +18 -7
- package/dist/blockchain/DataStore.d.ts.map +1 -1
- package/dist/blockchain/DataStore.js +78 -98
- package/dist/blockchain/DataStoreSerializer.d.ts +1 -1
- package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.d.ts +9 -1
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.js +45 -11
- package/dist/blockchain/ServerCoin.d.ts +11 -3
- package/dist/blockchain/ServerCoin.d.ts.map +1 -1
- package/dist/blockchain/ServerCoin.js +51 -17
- package/dist/blockchain/Wallet.d.ts +2 -2
- package/dist/blockchain/Wallet.d.ts.map +1 -1
- package/dist/blockchain/Wallet.js +51 -18
- package/dist/blockchain/coins.d.ts +1 -1
- package/dist/blockchain/coins.d.ts.map +1 -1
- package/dist/blockchain/coins.js +1 -1
- package/dist/types.d.ts +1 -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/FileTransfer.d.ts +47 -0
- package/dist/utils/FileTransfer.d.ts.map +1 -0
- package/dist/utils/FileTransfer.js +209 -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/asyncPool.d.ts +9 -0
- package/dist/utils/asyncPool.d.ts.map +1 -0
- package/dist/utils/asyncPool.js +23 -0
- package/dist/utils/config.d.ts +4 -3
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +9 -5
- package/dist/utils/directoryUtils.d.ts +0 -6
- package/dist/utils/directoryUtils.d.ts.map +1 -1
- package/dist/utils/directoryUtils.js +30 -11
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -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.map +1 -1
- package/dist/utils/network.js +24 -9
- package/package.json +13 -3
- package/dist/utils/deltaUtils.d.ts +0 -2
- package/dist/utils/deltaUtils.d.ts.map +0 -1
- package/dist/utils/deltaUtils.js +0 -83
|
@@ -5,13 +5,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ServerCoin = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const datalayer_driver_1 = require("datalayer-driver");
|
|
8
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
9
9
|
const FullNodePeer_1 = require("./FullNodePeer");
|
|
10
10
|
const coins_1 = require("./coins");
|
|
11
11
|
const Wallet_1 = require("./Wallet");
|
|
12
12
|
const NconfManager_1 = require("../utils/NconfManager");
|
|
13
13
|
const DataStore_1 = require("./DataStore");
|
|
14
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
15
|
+
const network_1 = require("../utils/network");
|
|
14
16
|
const serverCoinCollateral = 300000000;
|
|
17
|
+
// Initialize the cache with a TTL of 300 seconds (5 minutes)
|
|
18
|
+
const serverCoinPeersCache = new node_cache_1.default({ stdTTL: 300 });
|
|
15
19
|
class ServerCoin {
|
|
16
20
|
constructor(storeId) {
|
|
17
21
|
this.storeId = storeId;
|
|
@@ -23,7 +27,7 @@ class ServerCoin {
|
|
|
23
27
|
const wallet = await Wallet_1.Wallet.load("default");
|
|
24
28
|
const publicSyntheticKey = await wallet.getPublicSyntheticKey();
|
|
25
29
|
const serverCoinCreationCoins = await (0, coins_1.selectUnspentCoins)(peer, BigInt(serverCoinCollateral), BigInt(1000000));
|
|
26
|
-
const currentEpoch = ServerCoin.getCurrentEpoch();
|
|
30
|
+
const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
|
|
27
31
|
const epochBasedHint = (0, datalayer_driver_1.morphLauncherId)(Buffer.from(this.storeId, "hex"), BigInt(currentEpoch));
|
|
28
32
|
const newServerCoin = (0, datalayer_driver_1.createServerCoin)(publicSyntheticKey, serverCoinCreationCoins, epochBasedHint, [peerIp], BigInt(serverCoinCollateral), BigInt(1000000));
|
|
29
33
|
const combinedCoinSpends = [...newServerCoin.coinSpends];
|
|
@@ -94,13 +98,13 @@ class ServerCoin {
|
|
|
94
98
|
serverCoins = serverCoins.filter((coin) => coin.coin.parentCoinInfo !== serverCoin.parentCoinInfo);
|
|
95
99
|
await ServerCoin.serverCoinManager.setConfigValue(`${this.storeId}:${peerIp}`, serverCoins);
|
|
96
100
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
async getAllEpochPeers(epoch, blacklist = []) {
|
|
102
|
+
const cacheKey = `serverCoinPeers-${this.storeId}-${epoch}`;
|
|
103
|
+
// Check if the result is already cached
|
|
104
|
+
const cachedPeers = serverCoinPeersCache.get(cacheKey);
|
|
105
|
+
if (cachedPeers) {
|
|
106
|
+
return cachedPeers;
|
|
107
|
+
}
|
|
104
108
|
const epochBasedHint = (0, datalayer_driver_1.morphLauncherId)(Buffer.from(this.storeId, "hex"), BigInt(epoch));
|
|
105
109
|
const peer = await FullNodePeer_1.FullNodePeer.connect();
|
|
106
110
|
const maxClvmCost = BigInt(11000000000);
|
|
@@ -118,18 +122,42 @@ class ServerCoin {
|
|
|
118
122
|
if (process.env.DIG_DEBUG === "1") {
|
|
119
123
|
console.log("Server Coin Peers: ", serverCoinPeers);
|
|
120
124
|
}
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
const peerList = Array.from(serverCoinPeers);
|
|
126
|
+
// Cache the result
|
|
127
|
+
serverCoinPeersCache.set(cacheKey, peerList);
|
|
128
|
+
return peerList;
|
|
129
|
+
}
|
|
130
|
+
async getActiveEpochPeers(blacklist = []) {
|
|
131
|
+
const { epoch } = ServerCoin.getCurrentEpoch();
|
|
132
|
+
return this.getAllEpochPeers(epoch, blacklist);
|
|
133
|
+
}
|
|
134
|
+
// Sample server coins for the current epoch
|
|
135
|
+
async sampleCurrentEpoch(sampleSize = 5, blacklist = []) {
|
|
136
|
+
const { epoch } = ServerCoin.getCurrentEpoch();
|
|
137
|
+
return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist);
|
|
138
|
+
}
|
|
139
|
+
// Sample server coins by epoch
|
|
140
|
+
async sampleServerCoinsByEpoch(epoch, sampleSize = 5, blacklist = []) {
|
|
141
|
+
// We dont want our own IP to be included
|
|
142
|
+
const myIp = await (0, network_1.getPublicIpAddress)();
|
|
143
|
+
if (myIp) {
|
|
144
|
+
blacklist.push(myIp);
|
|
145
|
+
}
|
|
146
|
+
const serverCoinPeers = await this.getAllEpochPeers(epoch, blacklist);
|
|
147
|
+
if (process.env.DIG_DEBUG === "1") {
|
|
148
|
+
console.log("Server Coin Peers: ", serverCoinPeers);
|
|
149
|
+
}
|
|
150
|
+
return lodash_1.default.sampleSize(serverCoinPeers, sampleSize);
|
|
123
151
|
}
|
|
124
152
|
// Get the current epoch based on the current timestamp
|
|
125
153
|
static getCurrentEpoch() {
|
|
126
|
-
return ServerCoin.
|
|
154
|
+
return ServerCoin.calculateEpochAndRound(new Date());
|
|
127
155
|
}
|
|
128
156
|
// Ensure server coin exists for the current epoch
|
|
129
157
|
async ensureServerCoinExists(peerIp) {
|
|
130
158
|
try {
|
|
131
159
|
console.log(`Ensuring server coin exists for store ${this.storeId}...`);
|
|
132
|
-
const currentEpoch = ServerCoin.getCurrentEpoch();
|
|
160
|
+
const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
|
|
133
161
|
const serverCoins = await this.getServerCoinsForStore(peerIp);
|
|
134
162
|
// Check if a server coin already exists for the current epoch
|
|
135
163
|
const existingCoin = serverCoins.find((coin) => coin.epoch === currentEpoch);
|
|
@@ -160,7 +188,7 @@ class ServerCoin {
|
|
|
160
188
|
// Melt outdated server coins
|
|
161
189
|
async meltOutdatedEpochs(peerIp) {
|
|
162
190
|
try {
|
|
163
|
-
const currentEpoch = ServerCoin.getCurrentEpoch();
|
|
191
|
+
const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
|
|
164
192
|
let serverCoins = await this.getServerCoinsForStore(peerIp);
|
|
165
193
|
// Filter out coins that are not in the current epoch
|
|
166
194
|
const outdatedCoins = serverCoins.filter((coin) => coin.epoch < currentEpoch);
|
|
@@ -244,17 +272,23 @@ class ServerCoin {
|
|
|
244
272
|
}
|
|
245
273
|
}
|
|
246
274
|
// Static method to calculate the current epoch
|
|
247
|
-
static
|
|
275
|
+
static calculateEpochAndRound(currentTimestampUTC) {
|
|
248
276
|
const firstEpochStart = new Date(Date.UTC(2024, 8, 3, 0, 0)); // Sept 3, 2024, 00:00 UTC
|
|
249
277
|
// Convert the current timestamp to milliseconds
|
|
250
278
|
const currentTimestampMillis = currentTimestampUTC.getTime();
|
|
251
279
|
// Calculate the number of milliseconds in one epoch (7 days)
|
|
252
|
-
const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000;
|
|
280
|
+
const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds
|
|
253
281
|
// Calculate the difference in milliseconds between the current timestamp and the first epoch start
|
|
254
282
|
const differenceMillis = currentTimestampMillis - firstEpochStart.getTime();
|
|
255
283
|
// Calculate the current epoch number
|
|
256
284
|
const epochNumber = Math.floor(differenceMillis / millisecondsInEpoch) + 1;
|
|
257
|
-
|
|
285
|
+
// Calculate the milliseconds elapsed since the start of the current epoch
|
|
286
|
+
const elapsedMillisInCurrentEpoch = differenceMillis % millisecondsInEpoch;
|
|
287
|
+
// Calculate the number of milliseconds in a round (10 minutes)
|
|
288
|
+
const millisecondsInRound = 10 * 60 * 1000; // 10 minutes in milliseconds
|
|
289
|
+
// Calculate the current round number
|
|
290
|
+
const roundNumber = Math.floor(elapsedMillisInCurrentEpoch / millisecondsInRound) + 1;
|
|
291
|
+
return { epoch: epochNumber, round: roundNumber };
|
|
258
292
|
}
|
|
259
293
|
}
|
|
260
294
|
exports.ServerCoin = ServerCoin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import { Peer, Coin, CoinSpend } from "datalayer-driver";
|
|
2
|
+
import { Peer, Coin, CoinSpend } from "@dignetwork/datalayer-driver";
|
|
3
3
|
export declare const DEFAULT_FEE_COIN_COST = 64000000;
|
|
4
4
|
export declare class Wallet {
|
|
5
5
|
private mnemonic;
|
|
@@ -20,7 +20,7 @@ export declare class Wallet {
|
|
|
20
20
|
private static getWalletFromKeyring;
|
|
21
21
|
private static saveWalletToKeyring;
|
|
22
22
|
createKeyOwnershipSignature(nonce: string): Promise<string>;
|
|
23
|
-
verifyKeyOwnershipSignature(nonce: string, signature: string, publicKey: string): Promise<boolean>;
|
|
23
|
+
static verifyKeyOwnershipSignature(nonce: string, signature: string, publicKey: string): Promise<boolean>;
|
|
24
24
|
selectUnspentCoins(peer: Peer, coinAmount: bigint, feeBigInt: bigint, omitCoins?: Coin[]): Promise<Coin[]>;
|
|
25
25
|
static calculateFeeForCoinSpends(peer: Peer, coinSpends: CoinSpend[] | null): Promise<bigint>;
|
|
26
26
|
static isCoinSpendable(peer: Peer, coinId: Buffer): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wallet.d.ts","sourceRoot":"","sources":["../../src/blockchain/Wallet.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EASL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,
|
|
1
|
+
{"version":3,"file":"Wallet.d.ts","sourceRoot":"","sources":["../../src/blockchain/Wallet.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EASL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,8BAA8B,CAAC;AAQtC,eAAO,MAAM,qBAAqB,WAAa,CAAC;AAOhD,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO;WAKa,IAAI,CACtB,UAAU,GAAE,MAAkB,EAC9B,iBAAiB,GAAE,OAAc,GAChC,OAAO,CAAC,MAAM,CAAC;IAsBX,WAAW,IAAI,MAAM;WAOR,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;WAMpD,YAAY,CAC9B,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC;WASE,oBAAoB,CACtC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC;IA6BL,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKrC,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC;IAMxC,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKzC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAMrC,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;WAK7B,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;WASlD,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;mBAU/B,oBAAoB;mBAcpB,mBAAmB;IAS3B,2BAA2B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;WAUpD,2BAA2B,CAC7C,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IASN,kBAAkB,CAC7B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,GAAE,IAAI,EAAO,GACrB,OAAO,CAAC,IAAI,EAAE,CAAC;WA+EE,yBAAyB,CAC3C,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,GAC7B,OAAO,CAAC,MAAM,CAAC;WAIE,eAAe,CACjC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;CAWpB"}
|
|
@@ -38,9 +38,11 @@ const chia_root_resolver_1 = require("chia-root-resolver");
|
|
|
38
38
|
const chia_config_loader_1 = require("chia-config-loader");
|
|
39
39
|
const encryption_1 = require("../utils/encryption");
|
|
40
40
|
const buffer_1 = require("buffer");
|
|
41
|
-
const datalayer_driver_1 = require("datalayer-driver");
|
|
41
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
42
42
|
const config_1 = require("../utils/config");
|
|
43
43
|
const FileCache_1 = require("../utils/FileCache");
|
|
44
|
+
const config_2 = require("../utils/config");
|
|
45
|
+
const path_1 = __importDefault(require("path"));
|
|
44
46
|
const KEYRING_FILE = "keyring.json";
|
|
45
47
|
const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
|
|
46
48
|
exports.DEFAULT_FEE_COIN_COST = 64000000;
|
|
@@ -174,31 +176,62 @@ class Wallet {
|
|
|
174
176
|
const signature = (0, datalayer_driver_1.signMessage)(buffer_1.Buffer.from(message, "utf-8"), privateSyntheticKey);
|
|
175
177
|
return signature.toString("hex");
|
|
176
178
|
}
|
|
177
|
-
async verifyKeyOwnershipSignature(nonce, signature, publicKey) {
|
|
179
|
+
static async verifyKeyOwnershipSignature(nonce, signature, publicKey) {
|
|
178
180
|
const message = `Signing this message to prove ownership of key.\n\nNonce: ${nonce}`;
|
|
179
181
|
return (0, datalayer_driver_1.verifySignedMessage)(buffer_1.Buffer.from(signature, "hex"), buffer_1.Buffer.from(publicKey, "hex"), buffer_1.Buffer.from(message, "utf-8"));
|
|
180
182
|
}
|
|
181
183
|
async selectUnspentCoins(peer, coinAmount, feeBigInt, omitCoins = []) {
|
|
182
|
-
const cache = new FileCache_1.FileCache("reserved_coins");
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
const cache = new FileCache_1.FileCache(path_1.default.join(config_2.USER_DIR_PATH, "reserved_coins"));
|
|
185
|
+
const ownerPuzzleHash = await this.getOwnerPuzzleHash();
|
|
186
|
+
// Define a function to attempt selecting unspent coins
|
|
187
|
+
const trySelectCoins = async () => {
|
|
188
|
+
const now = Date.now();
|
|
189
|
+
const omitCoinIds = omitCoins.map((coin) => (0, datalayer_driver_1.getCoinId)(coin).toString("hex"));
|
|
190
|
+
// Update omitCoinIds with currently valid reserved coins
|
|
191
|
+
const cachedReservedCoins = cache.getCachedKeys();
|
|
192
|
+
cachedReservedCoins.forEach((coinId) => {
|
|
193
|
+
const reservation = cache.get(coinId);
|
|
194
|
+
if (reservation && reservation.expiry > now) {
|
|
195
|
+
if (!omitCoinIds.includes(coinId)) {
|
|
196
|
+
omitCoinIds.push(coinId);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
cache.delete(coinId);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
const coinsResp = await peer.getAllUnspentCoins(ownerPuzzleHash, config_1.MIN_HEIGHT, buffer_1.Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
|
|
204
|
+
const unspentCoins = coinsResp.coins.filter((coin) => !omitCoinIds.includes((0, datalayer_driver_1.getCoinId)(coin).toString("hex")));
|
|
205
|
+
const selectedCoins = (0, datalayer_driver_1.selectCoins)(unspentCoins, feeBigInt + coinAmount);
|
|
206
|
+
return selectedCoins;
|
|
207
|
+
};
|
|
208
|
+
let selectedCoins = [];
|
|
209
|
+
let retry = true;
|
|
210
|
+
while (retry) {
|
|
211
|
+
selectedCoins = await trySelectCoins();
|
|
212
|
+
if (selectedCoins.length > 0) {
|
|
213
|
+
// Coins have been successfully selected
|
|
214
|
+
retry = false;
|
|
190
215
|
}
|
|
191
216
|
else {
|
|
192
|
-
|
|
217
|
+
const now = Date.now();
|
|
218
|
+
// Check if there are any valid cached reserved coins left
|
|
219
|
+
const cachedReservedCoins = cache.getCachedKeys().filter((coinId) => {
|
|
220
|
+
const reservation = cache.get(coinId);
|
|
221
|
+
return reservation && reservation.expiry > now;
|
|
222
|
+
});
|
|
223
|
+
if (cachedReservedCoins.length > 0) {
|
|
224
|
+
// Wait 10 seconds and try again
|
|
225
|
+
console.log("No unspent coins available. Waiting 10 seconds...");
|
|
226
|
+
await new Promise((resolve) => setTimeout(resolve, 10000));
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
// No unspent coins and no reserved coins
|
|
230
|
+
throw new Error("No unspent coins available.");
|
|
231
|
+
}
|
|
193
232
|
}
|
|
194
|
-
});
|
|
195
|
-
const ownerPuzzleHash = await this.getOwnerPuzzleHash();
|
|
196
|
-
const coinsResp = await peer.getAllUnspentCoins(ownerPuzzleHash, config_1.MIN_HEIGHT, buffer_1.Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
|
|
197
|
-
const unspentCoins = coinsResp.coins.filter((coin) => !omitCoinIds.includes((0, datalayer_driver_1.getCoinId)(coin).toString("hex")));
|
|
198
|
-
const selectedCoins = (0, datalayer_driver_1.selectCoins)(unspentCoins, feeBigInt + coinAmount);
|
|
199
|
-
if (selectedCoins.length === 0) {
|
|
200
|
-
throw new Error("No unspent coins available.");
|
|
201
233
|
}
|
|
234
|
+
// Reserve the selected coins
|
|
202
235
|
selectedCoins.forEach((coin) => {
|
|
203
236
|
const coinId = (0, datalayer_driver_1.getCoinId)(coin).toString("hex");
|
|
204
237
|
cache.set(coinId, { coinId, expiry: Date.now() + CACHE_DURATION });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Peer, Coin, CoinSpend } from "datalayer-driver";
|
|
1
|
+
import { Peer, Coin, CoinSpend } from "@dignetwork/datalayer-driver";
|
|
2
2
|
export declare const DEFAULT_FEE_COIN_COST = 64000000;
|
|
3
3
|
export declare const calculateFeeForCoinSpends: (peer: Peer, coinSpends: CoinSpend[] | null) => Promise<bigint>;
|
|
4
4
|
export declare const selectUnspentCoins: (peer: Peer, coinAmount: bigint, feeBigInt: bigint, omitCoins?: Coin[], walletName?: string) => Promise<Coin[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coins.d.ts","sourceRoot":"","sources":["../../src/blockchain/coins.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,
|
|
1
|
+
{"version":3,"file":"coins.d.ts","sourceRoot":"","sources":["../../src/blockchain/coins.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,EACJ,IAAI,EAEJ,SAAS,EAEV,MAAM,8BAA8B,CAAC;AAKtC,eAAO,MAAM,qBAAqB,WAAa,CAAC;AAWhD,eAAO,MAAM,yBAAyB,SAC9B,IAAI,cACE,SAAS,EAAE,GAAG,IAAI,KAC7B,OAAO,CAAC,MAAM,CA4BhB,CAAC;AAEF,eAAO,MAAM,kBAAkB,SACvB,IAAI,cACE,MAAM,aACP,MAAM,cACN,IAAI,EAAE,eACL,MAAM,KACjB,OAAO,CAAC,IAAI,EAAE,CAoEhB,CAAC;AAGF,eAAO,MAAM,eAAe,SACpB,IAAI,UACF,MAAM,KACb,OAAO,CAAC,OAAO,CAWjB,CAAC"}
|
package/dist/blockchain/coins.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isCoinSpendable = exports.selectUnspentCoins = exports.calculateFeeForCoinSpends = exports.DEFAULT_FEE_COIN_COST = void 0;
|
|
4
|
-
const datalayer_driver_1 = require("datalayer-driver");
|
|
4
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
5
5
|
const Wallet_1 = require("./Wallet");
|
|
6
6
|
const config_1 = require("../utils/config");
|
|
7
7
|
const FileCache_1 = require("../utils/FileCache");
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -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;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;
|
|
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;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG;YACb,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,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,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class IllegalContentScanner
|
|
3
|
+
* Scans files for illegal content using ClamAV running in a Docker container and deletes files if flagged.
|
|
4
|
+
*/
|
|
5
|
+
export declare class IllegalContentScanner {
|
|
6
|
+
private clamAVContainerName;
|
|
7
|
+
private virusTotalApiKey?;
|
|
8
|
+
private openAiApiKey?;
|
|
9
|
+
/**
|
|
10
|
+
* @constructor
|
|
11
|
+
* @param clamAVContainerName The name of the Docker container running ClamAV (default: 'clamav').
|
|
12
|
+
*/
|
|
13
|
+
constructor(clamAVContainerName?: string);
|
|
14
|
+
/**
|
|
15
|
+
* Scans a file for illegal content using ClamAV, VirusTotal, and OpenAI Moderation API.
|
|
16
|
+
* If a service is missing its API key, the scan for that service is skipped.
|
|
17
|
+
* @param filePath The path of the file to scan.
|
|
18
|
+
* @returns {Promise<void>} A promise that resolves after the scan and potential deletion.
|
|
19
|
+
*/
|
|
20
|
+
scanFile(filePath: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Scans a file using ClamAV running in Docker.
|
|
23
|
+
* @param filePath The path of the file to scan.
|
|
24
|
+
* @returns {Promise<string>} The result of the ClamAV scan.
|
|
25
|
+
*/
|
|
26
|
+
private scanWithClamAV;
|
|
27
|
+
/**
|
|
28
|
+
* Submits a file to VirusTotal for scanning.
|
|
29
|
+
* @param filePath The path of the file to scan.
|
|
30
|
+
* @returns {Promise<any>} The result from VirusTotal.
|
|
31
|
+
*/
|
|
32
|
+
private scanWithVirusTotal;
|
|
33
|
+
/**
|
|
34
|
+
* Scans file content (text) using OpenAI's Moderation API.
|
|
35
|
+
* @param content The text content to scan.
|
|
36
|
+
* @returns {Promise<any>} The result from OpenAI's Moderation API.
|
|
37
|
+
*/
|
|
38
|
+
private scanWithOpenAI;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the ClamAV scan result indicates a malicious file.
|
|
41
|
+
* @param result The ClamAV scan output.
|
|
42
|
+
* @returns {boolean} True if the file is flagged, false otherwise.
|
|
43
|
+
*/
|
|
44
|
+
private isClamAVResultMalicious;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if the VirusTotal result indicates a malicious file.
|
|
47
|
+
* @param result The VirusTotal scan result.
|
|
48
|
+
* @returns {boolean} True if the file is flagged, false otherwise.
|
|
49
|
+
*/
|
|
50
|
+
private isVirusTotalResultMalicious;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if the OpenAI Moderation result indicates harmful content.
|
|
53
|
+
* @param result The OpenAI Moderation result.
|
|
54
|
+
* @returns {boolean} True if harmful content is detected, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
private isOpenAiResultMalicious;
|
|
57
|
+
/**
|
|
58
|
+
* Deletes a file from the filesystem.
|
|
59
|
+
* @param filePath The file to delete.
|
|
60
|
+
*/
|
|
61
|
+
private deleteFile;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=ContentScanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentScanner.d.ts","sourceRoot":"","sources":["../../src/utils/ContentScanner.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,qBAAa,qBAAqB;IAC9B,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,gBAAgB,CAAC,CAAS;IAClC,OAAO,CAAC,YAAY,CAAC,CAAS;IAE9B;;;OAGG;gBACS,mBAAmB,GAAE,MAAiB;IAMlD;;;;;OAKG;IACU,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqDtD;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAYtB;;;;OAIG;YACW,kBAAkB;IAgBhC;;;;OAIG;YACW,cAAc;IAa5B;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAI/B;;;;OAIG;IACH,OAAO,CAAC,2BAA2B;IAKnC;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAI/B;;;OAGG;IACH,OAAO,CAAC,UAAU;CASrB"}
|
|
@@ -0,0 +1,175 @@
|
|
|
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.IllegalContentScanner = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
/**
|
|
12
|
+
* @class IllegalContentScanner
|
|
13
|
+
* Scans files for illegal content using ClamAV running in a Docker container and deletes files if flagged.
|
|
14
|
+
*/
|
|
15
|
+
class IllegalContentScanner {
|
|
16
|
+
/**
|
|
17
|
+
* @constructor
|
|
18
|
+
* @param clamAVContainerName The name of the Docker container running ClamAV (default: 'clamav').
|
|
19
|
+
*/
|
|
20
|
+
constructor(clamAVContainerName = "clamav") {
|
|
21
|
+
this.clamAVContainerName = clamAVContainerName;
|
|
22
|
+
this.virusTotalApiKey = process.env.VIRUSTOTAL_API_KEY || undefined;
|
|
23
|
+
this.openAiApiKey = process.env.OPENAI_API_KEY || undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Scans a file for illegal content using ClamAV, VirusTotal, and OpenAI Moderation API.
|
|
27
|
+
* If a service is missing its API key, the scan for that service is skipped.
|
|
28
|
+
* @param filePath The path of the file to scan.
|
|
29
|
+
* @returns {Promise<void>} A promise that resolves after the scan and potential deletion.
|
|
30
|
+
*/
|
|
31
|
+
async scanFile(filePath) {
|
|
32
|
+
try {
|
|
33
|
+
// 1. ClamAV Scan
|
|
34
|
+
console.log(`Starting ClamAV scan for file: ${filePath}`);
|
|
35
|
+
const clamAvResult = await this.scanWithClamAV(filePath);
|
|
36
|
+
if (this.isClamAVResultMalicious(clamAvResult)) {
|
|
37
|
+
console.log(`ClamAV flagged file: ${filePath}. Deleting...`);
|
|
38
|
+
this.deleteFile(filePath);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(`ClamAV did not flag the file: ${filePath}.`);
|
|
43
|
+
}
|
|
44
|
+
// 2. VirusTotal Scan (if API key is provided)
|
|
45
|
+
if (this.virusTotalApiKey) {
|
|
46
|
+
console.log(`Submitting file to VirusTotal for scanning: ${filePath}`);
|
|
47
|
+
const virusTotalResult = await this.scanWithVirusTotal(filePath);
|
|
48
|
+
if (this.isVirusTotalResultMalicious(virusTotalResult)) {
|
|
49
|
+
console.log(`VirusTotal flagged file: ${filePath}. Deleting...`);
|
|
50
|
+
this.deleteFile(filePath);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.log(`VirusTotal did not flag the file: ${filePath}.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console.log(`VirusTotal API key not provided. Skipping VirusTotal scan.`);
|
|
59
|
+
}
|
|
60
|
+
// 3. OpenAI Moderation API (if API key is provided and file is text-based)
|
|
61
|
+
const fileExtension = path_1.default.extname(filePath).toLowerCase();
|
|
62
|
+
if (this.openAiApiKey && (fileExtension === ".txt" || fileExtension === ".json")) {
|
|
63
|
+
console.log(`Scanning file content with OpenAI Moderation API: ${filePath}`);
|
|
64
|
+
const fileContent = await fs_1.default.promises.readFile(filePath, "utf-8");
|
|
65
|
+
const openAiResult = await this.scanWithOpenAI(fileContent);
|
|
66
|
+
if (this.isOpenAiResultMalicious(openAiResult)) {
|
|
67
|
+
console.log(`OpenAI flagged file: ${filePath}. Deleting...`);
|
|
68
|
+
this.deleteFile(filePath);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
if (!this.openAiApiKey) {
|
|
74
|
+
console.log(`OpenAI API key not provided. Skipping OpenAI scan.`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.log(`OpenAI scan skipped: File type not supported (${fileExtension}).`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
console.log(`File ${filePath} passed all multilayer scans.`);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error(`Error scanning file: ${filePath}`, error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Scans a file using ClamAV running in Docker.
|
|
88
|
+
* @param filePath The path of the file to scan.
|
|
89
|
+
* @returns {Promise<string>} The result of the ClamAV scan.
|
|
90
|
+
*/
|
|
91
|
+
scanWithClamAV(filePath) {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
(0, child_process_1.exec)(`docker exec ${this.clamAVContainerName} clamdscan ${filePath}`, (error, stdout, stderr) => {
|
|
94
|
+
if (error) {
|
|
95
|
+
reject(`ClamAV scan error: ${stderr}`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
resolve(stdout);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Submits a file to VirusTotal for scanning.
|
|
105
|
+
* @param filePath The path of the file to scan.
|
|
106
|
+
* @returns {Promise<any>} The result from VirusTotal.
|
|
107
|
+
*/
|
|
108
|
+
async scanWithVirusTotal(filePath) {
|
|
109
|
+
const fileContent = await fs_1.default.promises.readFile(filePath);
|
|
110
|
+
const formData = new FormData();
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
formData.append("file", fileContent);
|
|
113
|
+
const response = await axios_1.default.post("https://www.virustotal.com/vtapi/v2/file/scan", formData, {
|
|
114
|
+
headers: {
|
|
115
|
+
"x-apikey": this.virusTotalApiKey,
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
...formData.getHeaders(),
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
return response.data;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Scans file content (text) using OpenAI's Moderation API.
|
|
124
|
+
* @param content The text content to scan.
|
|
125
|
+
* @returns {Promise<any>} The result from OpenAI's Moderation API.
|
|
126
|
+
*/
|
|
127
|
+
async scanWithOpenAI(content) {
|
|
128
|
+
const response = await axios_1.default.post("https://api.openai.com/v1/moderations", { input: content }, {
|
|
129
|
+
headers: {
|
|
130
|
+
Authorization: `Bearer ${this.openAiApiKey}`,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
return response.data;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Checks if the ClamAV scan result indicates a malicious file.
|
|
137
|
+
* @param result The ClamAV scan output.
|
|
138
|
+
* @returns {boolean} True if the file is flagged, false otherwise.
|
|
139
|
+
*/
|
|
140
|
+
isClamAVResultMalicious(result) {
|
|
141
|
+
return result.includes("FOUND");
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Checks if the VirusTotal result indicates a malicious file.
|
|
145
|
+
* @param result The VirusTotal scan result.
|
|
146
|
+
* @returns {boolean} True if the file is flagged, false otherwise.
|
|
147
|
+
*/
|
|
148
|
+
isVirusTotalResultMalicious(result) {
|
|
149
|
+
// Check if VirusTotal flagged the file based on its multiple antivirus results
|
|
150
|
+
return result.positives > 0;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Checks if the OpenAI Moderation result indicates harmful content.
|
|
154
|
+
* @param result The OpenAI Moderation result.
|
|
155
|
+
* @returns {boolean} True if harmful content is detected, false otherwise.
|
|
156
|
+
*/
|
|
157
|
+
isOpenAiResultMalicious(result) {
|
|
158
|
+
return result.flagged === true;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Deletes a file from the filesystem.
|
|
162
|
+
* @param filePath The file to delete.
|
|
163
|
+
*/
|
|
164
|
+
deleteFile(filePath) {
|
|
165
|
+
fs_1.default.unlink(filePath, (err) => {
|
|
166
|
+
if (err) {
|
|
167
|
+
console.error(`Error deleting file: ${filePath}`, err);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
console.log(`File ${filePath} was deleted successfully.`);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.IllegalContentScanner = IllegalContentScanner;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Readable } from "stream";
|
|
2
|
+
export declare class FileTransfer {
|
|
3
|
+
private static certPath;
|
|
4
|
+
private static keyPath;
|
|
5
|
+
constructor();
|
|
6
|
+
/** ------------------------ UPLOAD FUNCTIONALITY ------------------------ **/
|
|
7
|
+
/**
|
|
8
|
+
* Upload a file to the server using a stream.
|
|
9
|
+
* @param filePath - Local path of the file.
|
|
10
|
+
* @param uploadUrl - Server URL to upload the file.
|
|
11
|
+
* @param headers - Additional headers for the request.
|
|
12
|
+
* @returns Promise<void>
|
|
13
|
+
*/
|
|
14
|
+
uploadFile(filePath: string, uploadUrl: string, headers: Record<string, string>): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Perform a POST request.
|
|
17
|
+
* @param url - The URL to POST to.
|
|
18
|
+
* @param data - Data to send.
|
|
19
|
+
* @param headers - Headers for the POST request.
|
|
20
|
+
* @returns Promise<void>
|
|
21
|
+
*/
|
|
22
|
+
postRequest(url: string, data: string, headers: Record<string, string>): Promise<void>;
|
|
23
|
+
/** ------------------------ DOWNLOAD FUNCTIONALITY ------------------------ **/
|
|
24
|
+
/**
|
|
25
|
+
* Download data from a URL.
|
|
26
|
+
* @param url - The URL to download data from.
|
|
27
|
+
* @returns Promise<string>
|
|
28
|
+
*/
|
|
29
|
+
downloadData(url: string): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Stream data from a URL.
|
|
32
|
+
* @param url - The URL to stream data from.
|
|
33
|
+
* @returns Promise<Readable>
|
|
34
|
+
*/
|
|
35
|
+
streamData(url: string): Promise<Readable>;
|
|
36
|
+
/** ------------------------ HEAD REQUEST FUNCTIONALITY ------------------------ **/
|
|
37
|
+
/**
|
|
38
|
+
* Perform a HEAD request to check if a resource exists on the server.
|
|
39
|
+
* @param url - The URL to check.
|
|
40
|
+
* @returns Promise<{ success: boolean; headers?: Record<string, string> }>
|
|
41
|
+
*/
|
|
42
|
+
headRequest(url: string): Promise<{
|
|
43
|
+
success: boolean;
|
|
44
|
+
headers?: Record<string, string>;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=FileTransfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileTransfer.d.ts","sourceRoot":"","sources":["../../src/utils/FileTransfer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;;IAU/B,8EAA8E;IAE9E;;;;;;OAMG;IACU,UAAU,CACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;IA0ChB;;;;;;OAMG;IACU,WAAW,CACtB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;IAsChB,gFAAgF;IAEhF;;;;OAIG;IACU,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA0CvD;;;;OAIG;IACU,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAuCvD,oFAAoF;IAEpF;;;;OAIG;IACU,WAAW,CACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CA8BnE"}
|