@dignetwork/dig-sdk 0.0.1-alpha.99 → 0.2.0
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 +21 -7
- package/README.md +412 -0
- package/dist/adapters.cjs +356 -0
- package/dist/adapters.cjs.map +1 -0
- package/dist/adapters.d.cts +20 -0
- package/dist/adapters.d.ts +20 -0
- package/dist/adapters.js +347 -0
- package/dist/adapters.js.map +1 -0
- package/dist/dev-shim-DfKRA1ok.d.cts +128 -0
- package/dist/dev-shim-DfKRA1ok.d.ts +128 -0
- package/dist/dig-client-entry-ChYxUvBn.d.cts +372 -0
- package/dist/dig-client-entry-ChYxUvBn.d.ts +372 -0
- package/dist/dig-client.cjs +443 -0
- package/dist/dig-client.cjs.map +1 -0
- package/dist/dig-client.d.cts +1 -0
- package/dist/dig-client.d.ts +1 -0
- package/dist/dig-client.js +432 -0
- package/dist/dig-client.js.map +1 -0
- package/dist/index.cjs +1186 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +502 -0
- package/dist/index.d.ts +502 -5
- package/dist/index.js +1156 -19
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +369 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +23 -0
- package/dist/next.d.ts +23 -0
- package/dist/next.js +362 -0
- package/dist/next.js.map +1 -0
- package/dist/spend.cjs +14 -0
- package/dist/spend.cjs.map +1 -0
- package/dist/spend.d.cts +1 -0
- package/dist/spend.d.ts +1 -0
- package/dist/spend.js +3 -0
- package/dist/spend.js.map +1 -0
- package/dist/vite.cjs +381 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +35 -0
- package/dist/vite.d.ts +35 -0
- package/dist/vite.js +375 -0
- package/dist/vite.js.map +1 -0
- package/package.json +87 -59
- package/vendor/PROVENANCE.md +102 -0
- package/vendor/dig_client.d.ts +150 -0
- package/vendor/dig_client.mjs +805 -0
- package/vendor/dig_client_bg.wasm +0 -0
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts +0 -163
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +0 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.js +0 -707
- package/dist/DataIntegrityTree/DataLayerError.d.ts +0 -6
- package/dist/DataIntegrityTree/DataLayerError.d.ts.map +0 -1
- package/dist/DataIntegrityTree/DataLayerError.js +0 -17
- package/dist/DataIntegrityTree/index.d.ts +0 -2
- package/dist/DataIntegrityTree/index.d.ts.map +0 -1
- package/dist/DataIntegrityTree/index.js +0 -17
- package/dist/DigNetwork/ContentServer.d.ts +0 -31
- package/dist/DigNetwork/ContentServer.d.ts.map +0 -1
- package/dist/DigNetwork/ContentServer.js +0 -176
- package/dist/DigNetwork/DigChallenge.d.ts +0 -82
- package/dist/DigNetwork/DigChallenge.d.ts.map +0 -1
- package/dist/DigNetwork/DigChallenge.js +0 -144
- package/dist/DigNetwork/DigNetwork.d.ts +0 -14
- package/dist/DigNetwork/DigNetwork.d.ts.map +0 -1
- package/dist/DigNetwork/DigNetwork.js +0 -169
- package/dist/DigNetwork/DigPeer.d.ts +0 -24
- package/dist/DigNetwork/DigPeer.d.ts.map +0 -1
- package/dist/DigNetwork/DigPeer.js +0 -118
- package/dist/DigNetwork/IncentiveServer.d.ts +0 -13
- package/dist/DigNetwork/IncentiveServer.d.ts.map +0 -1
- package/dist/DigNetwork/IncentiveServer.js +0 -76
- package/dist/DigNetwork/PropagationServer.d.ts +0 -81
- package/dist/DigNetwork/PropagationServer.d.ts.map +0 -1
- package/dist/DigNetwork/PropagationServer.js +0 -563
- package/dist/DigNetwork/index.d.ts +0 -4
- package/dist/DigNetwork/index.d.ts.map +0 -1
- package/dist/DigNetwork/index.js +0 -19
- package/dist/blockchain/DataStore.d.ts +0 -67
- package/dist/blockchain/DataStore.d.ts.map +0 -1
- package/dist/blockchain/DataStore.js +0 -413
- package/dist/blockchain/DataStoreSerializer.d.ts +0 -52
- package/dist/blockchain/DataStoreSerializer.d.ts.map +0 -1
- package/dist/blockchain/DataStoreSerializer.js +0 -109
- package/dist/blockchain/FullNodePeer.d.ts +0 -31
- package/dist/blockchain/FullNodePeer.d.ts.map +0 -1
- package/dist/blockchain/FullNodePeer.js +0 -295
- package/dist/blockchain/ServerCoin.d.ts +0 -29
- package/dist/blockchain/ServerCoin.d.ts.map +0 -1
- package/dist/blockchain/ServerCoin.js +0 -324
- package/dist/blockchain/Wallet.d.ts +0 -28
- package/dist/blockchain/Wallet.d.ts.map +0 -1
- package/dist/blockchain/Wallet.js +0 -253
- package/dist/blockchain/coins.d.ts +0 -6
- package/dist/blockchain/coins.d.ts.map +0 -1
- package/dist/blockchain/coins.js +0 -102
- package/dist/blockchain/index.d.ts +0 -8
- package/dist/blockchain/index.d.ts.map +0 -1
- package/dist/blockchain/index.js +0 -36
- package/dist/index.d.ts.map +0 -1
- package/dist/prompts.d.ts +0 -21
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -149
- package/dist/types.d.ts +0 -64
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/utils/ContentScanner.d.ts +0 -63
- package/dist/utils/ContentScanner.d.ts.map +0 -1
- package/dist/utils/ContentScanner.js +0 -175
- package/dist/utils/Environment.d.ts +0 -18
- package/dist/utils/Environment.d.ts.map +0 -1
- package/dist/utils/Environment.js +0 -85
- package/dist/utils/FileCache.d.ts +0 -11
- package/dist/utils/FileCache.d.ts.map +0 -1
- package/dist/utils/FileCache.js +0 -58
- package/dist/utils/FileTransfer.d.ts +0 -47
- package/dist/utils/FileTransfer.d.ts.map +0 -1
- package/dist/utils/FileTransfer.js +0 -209
- package/dist/utils/NconfManager.d.ts +0 -11
- package/dist/utils/NconfManager.d.ts.map +0 -1
- package/dist/utils/NconfManager.js +0 -56
- package/dist/utils/StoreArchiveManager.d.ts +0 -45
- package/dist/utils/StoreArchiveManager.d.ts.map +0 -1
- package/dist/utils/StoreArchiveManager.js +0 -153
- package/dist/utils/asyncPool.d.ts +0 -9
- package/dist/utils/asyncPool.d.ts.map +0 -1
- package/dist/utils/asyncPool.js +0 -23
- package/dist/utils/config.d.ts +0 -68
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -223
- package/dist/utils/connectionUtils.d.ts +0 -10
- package/dist/utils/connectionUtils.d.ts.map +0 -1
- package/dist/utils/connectionUtils.js +0 -18
- package/dist/utils/credentialsUtils.d.ts +0 -8
- package/dist/utils/credentialsUtils.d.ts.map +0 -1
- package/dist/utils/credentialsUtils.js +0 -122
- package/dist/utils/directoryUtils.d.ts +0 -9
- package/dist/utils/directoryUtils.d.ts.map +0 -1
- package/dist/utils/directoryUtils.js +0 -110
- package/dist/utils/encryption.d.ts +0 -8
- package/dist/utils/encryption.d.ts.map +0 -1
- package/dist/utils/encryption.js +0 -55
- package/dist/utils/hashUtils.d.ts +0 -8
- package/dist/utils/hashUtils.d.ts.map +0 -1
- package/dist/utils/hashUtils.js +0 -44
- package/dist/utils/index.d.ts +0 -14
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -29
- package/dist/utils/merkle.d.ts +0 -2
- package/dist/utils/merkle.d.ts.map +0 -1
- package/dist/utils/merkle.js +0 -28
- package/dist/utils/network.d.ts +0 -2
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js +0 -54
- package/dist/utils/spinnerUtils.d.ts +0 -2
- package/dist/utils/spinnerUtils.d.ts.map +0 -1
- package/dist/utils/spinnerUtils.js +0 -47
- package/dist/utils/ssl.d.ts +0 -5
- package/dist/utils/ssl.d.ts.map +0 -1
- package/dist/utils/ssl.js +0 -50
- package/dist/utils/validationUtils.d.ts +0 -9
- package/dist/utils/validationUtils.d.ts.map +0 -1
- package/dist/utils/validationUtils.js +0 -55
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.DigNetwork = void 0;
|
|
27
|
-
const fs = __importStar(require("fs"));
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const DigPeer_1 = require("./DigPeer");
|
|
30
|
-
const blockchain_1 = require("../blockchain");
|
|
31
|
-
const config_1 = require("../utils/config");
|
|
32
|
-
const util_1 = require("util");
|
|
33
|
-
const rename = (0, util_1.promisify)(fs.rename);
|
|
34
|
-
const unlink = (0, util_1.promisify)(fs.unlink);
|
|
35
|
-
class DigNetwork {
|
|
36
|
-
constructor(storeId) {
|
|
37
|
-
this.dataStore = blockchain_1.DataStore.from(storeId);
|
|
38
|
-
this.serverCoin = new blockchain_1.ServerCoin(storeId);
|
|
39
|
-
this.storeDir = path.resolve(config_1.DIG_FOLDER_PATH, "stores", storeId);
|
|
40
|
-
this.peerBlacklist = new Map(); // Initialize empty map for blacklists
|
|
41
|
-
}
|
|
42
|
-
static async subscribeToStore(storeId) {
|
|
43
|
-
fs.mkdirSync(path.join(config_1.DIG_FOLDER_PATH, "stores", storeId), {
|
|
44
|
-
recursive: true,
|
|
45
|
-
});
|
|
46
|
-
const digNetwork = new DigNetwork(storeId);
|
|
47
|
-
await digNetwork.syncStoreFromPeers();
|
|
48
|
-
}
|
|
49
|
-
static async findPeerWithStoreKey(storeId, rootHash, key, intialBlackList = []) {
|
|
50
|
-
const peerBlackList = intialBlackList;
|
|
51
|
-
const serverCoin = new blockchain_1.ServerCoin(storeId);
|
|
52
|
-
let peerIp = null;
|
|
53
|
-
// Keep sampling peers until an empty array is returned
|
|
54
|
-
while (true) {
|
|
55
|
-
try {
|
|
56
|
-
// Sample a peer from the current epoch
|
|
57
|
-
const digPeers = await serverCoin.sampleCurrentEpoch(1, peerBlackList);
|
|
58
|
-
// If no peers are returned, break out of the loop
|
|
59
|
-
if (digPeers.length === 0) {
|
|
60
|
-
console.log("No more peers found.");
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
peerIp = digPeers[0];
|
|
64
|
-
const digPeer = new DigPeer_1.DigPeer(peerIp, storeId);
|
|
65
|
-
// Try to fetch the head store information
|
|
66
|
-
const { storeExists, rootHashExists } = await digPeer.propagationServer.checkStoreExists(rootHash);
|
|
67
|
-
// If the peer has the correct root hash, check if key is required
|
|
68
|
-
if (storeExists && rootHashExists) {
|
|
69
|
-
console.log(`Found Peer at ${peerIp} for storeId: ${storeId}, root hash ${rootHash}`);
|
|
70
|
-
// If no key is provided, return the peer
|
|
71
|
-
if (!key) {
|
|
72
|
-
return digPeer;
|
|
73
|
-
}
|
|
74
|
-
// If key is provided, check if the peer has it
|
|
75
|
-
const keyResponse = await digPeer.contentServer.headKey(key, rootHash);
|
|
76
|
-
if (keyResponse.headers?.["x-key-exists"] === "true") {
|
|
77
|
-
return digPeer;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Add peer to blacklist if it doesn't meet criteria
|
|
81
|
-
peerBlackList.push(peerIp);
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
console.error(`Error connecting to DIG Peer ${peerIp}. Resampling...`);
|
|
85
|
-
if (peerIp) {
|
|
86
|
-
peerBlackList.push(peerIp); // Add to blacklist if error occurs
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Return null if no valid peer was found
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
static unsubscribeFromStore(storeId) {
|
|
94
|
-
fs.rmdirSync(path.join(config_1.DIG_FOLDER_PATH, "stores", storeId), {
|
|
95
|
-
recursive: true,
|
|
96
|
-
});
|
|
97
|
-
fs.unlinkSync(path.join(config_1.DIG_FOLDER_PATH, "stores", storeId + ".json"));
|
|
98
|
-
}
|
|
99
|
-
async syncStoreFromPeers(maxRootsToProcess) {
|
|
100
|
-
console.log("Starting file download process...");
|
|
101
|
-
let peerBlackList = [];
|
|
102
|
-
try {
|
|
103
|
-
const rootHistory = await this.dataStore.getRootHistory();
|
|
104
|
-
if (!rootHistory.length) {
|
|
105
|
-
throw new Error("No roots found in rootHistory. Cannot proceed with file download.");
|
|
106
|
-
}
|
|
107
|
-
// Filter out rootInfo entries where the .dat file already exists
|
|
108
|
-
const rootHistoryFiltered = rootHistory
|
|
109
|
-
.filter((item) => item.timestamp !== undefined)
|
|
110
|
-
.filter((item) => !fs.existsSync(`${this.storeDir}/${item.root_hash}.dat`))
|
|
111
|
-
.reverse(); // Reverse to download the latest first
|
|
112
|
-
if (!rootHistoryFiltered.length) {
|
|
113
|
-
console.log("All root hashes already exist locally. No need for download.");
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
// If maxRootsToProcess is specified, limit the number of roots processed
|
|
117
|
-
const rootsToProcess = maxRootsToProcess
|
|
118
|
-
? rootHistoryFiltered.slice(0, maxRootsToProcess)
|
|
119
|
-
: rootHistoryFiltered;
|
|
120
|
-
// Process the root hashes sequentially
|
|
121
|
-
for (const rootInfo of rootsToProcess) {
|
|
122
|
-
let selectedPeer = null;
|
|
123
|
-
while (true) {
|
|
124
|
-
try {
|
|
125
|
-
// Find a peer with the store and root hash
|
|
126
|
-
selectedPeer = await DigNetwork.findPeerWithStoreKey(this.dataStore.StoreId, rootInfo.root_hash, undefined, peerBlackList);
|
|
127
|
-
if (!selectedPeer) {
|
|
128
|
-
console.error(`No peer found with root hash ${rootInfo.root_hash}. Moving to next root.`);
|
|
129
|
-
break; // Exit the while loop to proceed to the next rootInfo
|
|
130
|
-
}
|
|
131
|
-
// Check if the selected peer has the store and root hash
|
|
132
|
-
const { storeExists, rootHashExists } = await selectedPeer.propagationServer.checkStoreExists(rootInfo.root_hash);
|
|
133
|
-
if (!storeExists || !rootHashExists) {
|
|
134
|
-
console.warn(`Peer ${selectedPeer.IpAddress} does not have the required store or root hash. Trying another peer...`);
|
|
135
|
-
peerBlackList.push(selectedPeer.IpAddress); // Blacklist and retry
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
// Download the store root and associated data
|
|
139
|
-
await selectedPeer.downloadStoreRoot(rootInfo.root_hash);
|
|
140
|
-
// Clear the blacklist upon successful download
|
|
141
|
-
peerBlackList = [];
|
|
142
|
-
// Break after successful download to proceed to next root hash
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
if (error.message)
|
|
147
|
-
console.error(`Error downloading from peer ${selectedPeer?.IpAddress}. Retrying with another peer.`, error);
|
|
148
|
-
if (selectedPeer) {
|
|
149
|
-
peerBlackList.push(selectedPeer.IpAddress); // Blacklist and retry
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
console.log("Syncing store complete.");
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
console.error("Error during syncing store from peers:", error);
|
|
158
|
-
throw error;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
// Fetches available peers for the store
|
|
162
|
-
async fetchAvailablePeers() {
|
|
163
|
-
//const publicIp: string | null | undefined =
|
|
164
|
-
// await nconfManager.getConfigValue("publicIp");
|
|
165
|
-
const peers = await this.serverCoin.sampleCurrentEpoch(10, Array.from(this.peerBlacklist.keys()));
|
|
166
|
-
return peers.map((ip) => new DigPeer_1.DigPeer(ip, this.dataStore.StoreId));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.DigNetwork = DigNetwork;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ContentServer } from "./ContentServer";
|
|
2
|
-
import { PropagationServer } from "./PropagationServer";
|
|
3
|
-
import { IncentiveServer } from "./IncentiveServer";
|
|
4
|
-
import { Output } from "@dignetwork/datalayer-driver";
|
|
5
|
-
export declare class DigPeer {
|
|
6
|
-
private ipAddress;
|
|
7
|
-
private storeId;
|
|
8
|
-
private _contentServer;
|
|
9
|
-
private _propagationServer;
|
|
10
|
-
private _incentiveServer;
|
|
11
|
-
constructor(ipAddress: string, storeId: string);
|
|
12
|
-
get contentServer(): ContentServer;
|
|
13
|
-
get propagationServer(): PropagationServer;
|
|
14
|
-
get incentiveServer(): IncentiveServer;
|
|
15
|
-
get IpAddress(): string;
|
|
16
|
-
static sendEqualBulkPayments(walletName: string, addresses: string[], totalAmount: bigint, memos: Buffer[]): Promise<void>;
|
|
17
|
-
static sendBulkPayments(walletName: string, outputs: Output[]): Promise<void>;
|
|
18
|
-
sendPayment(walletName: string, amount: bigint, memos?: Buffer[]): Promise<void>;
|
|
19
|
-
static createPaymentHint(storeId: Buffer): Buffer;
|
|
20
|
-
syncStore(): Promise<void>;
|
|
21
|
-
pushStoreRoot(storeId: string, rootHash: string): Promise<void>;
|
|
22
|
-
downloadStoreRoot(rootHash: string): Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=DigPeer.d.ts.map
|
|
@@ -1 +0,0 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AC;IAI/D,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOhE"}
|
|
@@ -1,118 +0,0 @@
|
|
|
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.DigPeer = void 0;
|
|
7
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
const ContentServer_1 = require("./ContentServer");
|
|
9
|
-
const PropagationServer_1 = require("./PropagationServer");
|
|
10
|
-
const IncentiveServer_1 = require("./IncentiveServer");
|
|
11
|
-
const blockchain_1 = require("../blockchain");
|
|
12
|
-
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
13
|
-
const blockchain_2 = require("../blockchain");
|
|
14
|
-
const blockchain_3 = require("../blockchain");
|
|
15
|
-
const coins_1 = require("../blockchain/coins");
|
|
16
|
-
class DigPeer {
|
|
17
|
-
constructor(ipAddress, storeId) {
|
|
18
|
-
this.ipAddress = ipAddress;
|
|
19
|
-
this.storeId = storeId;
|
|
20
|
-
this._contentServer = new ContentServer_1.ContentServer(ipAddress, storeId);
|
|
21
|
-
this._propagationServer = new PropagationServer_1.PropagationServer(ipAddress, storeId);
|
|
22
|
-
this._incentiveServer = new IncentiveServer_1.IncentiveServer(ipAddress);
|
|
23
|
-
}
|
|
24
|
-
// Getter for ContentServer
|
|
25
|
-
get contentServer() {
|
|
26
|
-
return this._contentServer;
|
|
27
|
-
}
|
|
28
|
-
// Getter for PropagationServer
|
|
29
|
-
get propagationServer() {
|
|
30
|
-
return this._propagationServer;
|
|
31
|
-
}
|
|
32
|
-
// Getter for IncentiveServer
|
|
33
|
-
get incentiveServer() {
|
|
34
|
-
return this._incentiveServer;
|
|
35
|
-
}
|
|
36
|
-
get IpAddress() {
|
|
37
|
-
return this.ipAddress;
|
|
38
|
-
}
|
|
39
|
-
static sendEqualBulkPayments(walletName, addresses, totalAmount, memos) {
|
|
40
|
-
// Use a Set to ensure unique addresses
|
|
41
|
-
const uniqueAddresses = Array.from(new Set(addresses));
|
|
42
|
-
// Convert unique addresses to puzzle hashes
|
|
43
|
-
const puzzleHashes = uniqueAddresses.map((address) => (0, datalayer_driver_1.addressToPuzzleHash)(address));
|
|
44
|
-
// Calculate amount per puzzle hash
|
|
45
|
-
const amountPerPuzzleHash = totalAmount / BigInt(puzzleHashes.length);
|
|
46
|
-
// Create outputs array
|
|
47
|
-
const outputs = puzzleHashes.map((puzzleHash) => ({
|
|
48
|
-
puzzleHash,
|
|
49
|
-
amount: amountPerPuzzleHash,
|
|
50
|
-
memos,
|
|
51
|
-
}));
|
|
52
|
-
// Call the sendBulkPayments function with the generated outputs
|
|
53
|
-
return DigPeer.sendBulkPayments(walletName, outputs);
|
|
54
|
-
}
|
|
55
|
-
static async sendBulkPayments(walletName, outputs) {
|
|
56
|
-
const feePerCondition = BigInt(1000);
|
|
57
|
-
const totalFee = feePerCondition * BigInt(outputs.length);
|
|
58
|
-
const wallet = await blockchain_3.Wallet.load(walletName);
|
|
59
|
-
const publicSyntheticKey = await wallet.getPublicSyntheticKey();
|
|
60
|
-
const peer = await blockchain_2.FullNodePeer.connect();
|
|
61
|
-
const totalAmount = outputs.reduce((acc, output) => acc + output.amount, BigInt(0));
|
|
62
|
-
const coins = await (0, coins_1.selectUnspentCoins)(peer, totalAmount, totalFee, [], walletName);
|
|
63
|
-
const coinSpends = await (0, datalayer_driver_1.sendXch)(publicSyntheticKey, coins, outputs, totalFee);
|
|
64
|
-
const sig = (0, datalayer_driver_1.signCoinSpends)(coinSpends, [await wallet.getPrivateSyntheticKey()], false);
|
|
65
|
-
const err = await peer.broadcastSpend(coinSpends, [sig]);
|
|
66
|
-
if (err) {
|
|
67
|
-
throw new Error(err);
|
|
68
|
-
}
|
|
69
|
-
await blockchain_2.FullNodePeer.waitForConfirmation((0, datalayer_driver_1.getCoinId)(coins[0]));
|
|
70
|
-
}
|
|
71
|
-
async sendPayment(walletName, amount, memos = []) {
|
|
72
|
-
const paymentAddress = await this.contentServer.getPaymentAddress();
|
|
73
|
-
if (!paymentAddress) {
|
|
74
|
-
throw new Error("Payment address not found.");
|
|
75
|
-
}
|
|
76
|
-
const paymentAddressPuzzleHash = (0, datalayer_driver_1.addressToPuzzleHash)(paymentAddress);
|
|
77
|
-
const output = {
|
|
78
|
-
puzzleHash: paymentAddressPuzzleHash,
|
|
79
|
-
amount,
|
|
80
|
-
memos,
|
|
81
|
-
};
|
|
82
|
-
return DigPeer.sendBulkPayments(walletName, [output]);
|
|
83
|
-
}
|
|
84
|
-
static createPaymentHint(storeId) {
|
|
85
|
-
// Ensure the input is a 32-byte buffer
|
|
86
|
-
if (!Buffer.isBuffer(storeId) || storeId.length !== 32) {
|
|
87
|
-
throw new Error("Invalid input. Must be a 32-byte buffer.");
|
|
88
|
-
}
|
|
89
|
-
// Define the seed
|
|
90
|
-
const seed = "digpayment";
|
|
91
|
-
// Combine the seed and the original buffer
|
|
92
|
-
const combinedBuffer = Buffer.concat([Buffer.from(seed), storeId]);
|
|
93
|
-
// Apply SHA-256 hash to the combined buffer
|
|
94
|
-
const hash = crypto_1.default.createHash("sha256");
|
|
95
|
-
hash.update(combinedBuffer);
|
|
96
|
-
const transformedBuffer = hash.digest();
|
|
97
|
-
// Return the 32-byte hash as a hex string
|
|
98
|
-
return transformedBuffer;
|
|
99
|
-
}
|
|
100
|
-
async syncStore() {
|
|
101
|
-
const dataStore = blockchain_1.DataStore.from(this.storeId);
|
|
102
|
-
const rootHistory = await dataStore.getRootHistory();
|
|
103
|
-
const localRootHistory = rootHistory
|
|
104
|
-
.filter((root) => Boolean(root.synced))
|
|
105
|
-
.reverse();
|
|
106
|
-
console.log(`Syncing store ${this.storeId} with ${this.IpAddress}`);
|
|
107
|
-
for (const item of localRootHistory) {
|
|
108
|
-
await this.pushStoreRoot(this.storeId, item.root_hash);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async pushStoreRoot(storeId, rootHash) {
|
|
112
|
-
await PropagationServer_1.PropagationServer.uploadStore(storeId, rootHash, this.IpAddress);
|
|
113
|
-
}
|
|
114
|
-
async downloadStoreRoot(rootHash) {
|
|
115
|
-
await PropagationServer_1.PropagationServer.downloadStore(this.storeId, rootHash, this.IpAddress);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
exports.DigPeer = DigPeer;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IncentiveProgramData } from "../types";
|
|
2
|
-
export declare class IncentiveServer {
|
|
3
|
-
private ipAddress;
|
|
4
|
-
private port;
|
|
5
|
-
constructor(ipAddress: string);
|
|
6
|
-
createIncentiveProgram(data: IncentiveProgramData): Promise<void>;
|
|
7
|
-
updateIncentiveProgram(data: IncentiveProgramData): Promise<void>;
|
|
8
|
-
deleteIncentiveProgram(storeId: string): Promise<void>;
|
|
9
|
-
getAllIncentivePrograms(): Promise<IncentiveProgramData[]>;
|
|
10
|
-
getIncentiveProgram(storeId: string): Promise<IncentiveProgramData>;
|
|
11
|
-
private makeRequest;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=IncentiveServer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IncentiveServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/IncentiveServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD,qBAAa,eAAe;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,IAAI,CAAgB;gBAEhB,SAAS,EAAE,MAAM;IAKhB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtD,uBAAuB,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAO1D,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAOlE,WAAW;CA6C1B"}
|
|
@@ -1,76 +0,0 @@
|
|
|
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.IncentiveServer = void 0;
|
|
7
|
-
const https_1 = __importDefault(require("https"));
|
|
8
|
-
const url_1 = require("url");
|
|
9
|
-
class IncentiveServer {
|
|
10
|
-
constructor(ipAddress) {
|
|
11
|
-
this.port = 4160;
|
|
12
|
-
this.ipAddress = ipAddress;
|
|
13
|
-
}
|
|
14
|
-
// Method to create a new incentive program
|
|
15
|
-
async createIncentiveProgram(data) {
|
|
16
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
17
|
-
await this.makeRequest(url, "POST", data);
|
|
18
|
-
}
|
|
19
|
-
// Method to update an existing incentive program
|
|
20
|
-
async updateIncentiveProgram(data) {
|
|
21
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
22
|
-
await this.makeRequest(url, "PUT", data);
|
|
23
|
-
}
|
|
24
|
-
// Method to delete an incentive program by storeId
|
|
25
|
-
async deleteIncentiveProgram(storeId) {
|
|
26
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
27
|
-
await this.makeRequest(url, "DELETE", { storeId });
|
|
28
|
-
}
|
|
29
|
-
// Method to get all incentive programs
|
|
30
|
-
async getAllIncentivePrograms() {
|
|
31
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
32
|
-
return this.makeRequest(url, "GET");
|
|
33
|
-
}
|
|
34
|
-
// Method to get a specific incentive program by storeId
|
|
35
|
-
async getIncentiveProgram(storeId) {
|
|
36
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive/${storeId}`;
|
|
37
|
-
return this.makeRequest(url, "GET");
|
|
38
|
-
}
|
|
39
|
-
// Helper method to handle the HTTPS request
|
|
40
|
-
async makeRequest(url, method, data) {
|
|
41
|
-
return new Promise((resolve, reject) => {
|
|
42
|
-
const urlObj = new url_1.URL(url);
|
|
43
|
-
const options = {
|
|
44
|
-
hostname: urlObj.hostname,
|
|
45
|
-
port: urlObj.port,
|
|
46
|
-
path: urlObj.pathname + urlObj.search,
|
|
47
|
-
method: method,
|
|
48
|
-
headers: {
|
|
49
|
-
"Content-Type": "application/json",
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
const req = https_1.default.request(options, (res) => {
|
|
53
|
-
let responseData = "";
|
|
54
|
-
res.on("data", (chunk) => {
|
|
55
|
-
responseData += chunk;
|
|
56
|
-
});
|
|
57
|
-
res.on("end", () => {
|
|
58
|
-
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
59
|
-
resolve(responseData ? JSON.parse(responseData) : undefined);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
reject(new Error(`Request failed with status ${res.statusCode}: ${res.statusMessage}`));
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
req.on("error", (err) => {
|
|
67
|
-
reject(err);
|
|
68
|
-
});
|
|
69
|
-
if (data) {
|
|
70
|
-
req.write(JSON.stringify(data));
|
|
71
|
-
}
|
|
72
|
-
req.end();
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.IncentiveServer = IncentiveServer;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import https from "https";
|
|
2
|
-
import { PassThrough } from "stream";
|
|
3
|
-
export declare class PropagationServer {
|
|
4
|
-
storeId: string;
|
|
5
|
-
sessionId: string;
|
|
6
|
-
publicKey: string;
|
|
7
|
-
wallet: any;
|
|
8
|
-
ipAddress: string;
|
|
9
|
-
certPath: string;
|
|
10
|
-
keyPath: string;
|
|
11
|
-
username: string | undefined;
|
|
12
|
-
password: string | undefined;
|
|
13
|
-
private static readonly port;
|
|
14
|
-
private static readonly inactivityTimeout;
|
|
15
|
-
constructor(ipAddress: string, storeId: string);
|
|
16
|
-
/**
|
|
17
|
-
* Initialize the Wallet instance.
|
|
18
|
-
*/
|
|
19
|
-
initializeWallet(): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Create an Axios HTTPS Agent with self-signed certificate allowance.
|
|
22
|
-
*/
|
|
23
|
-
createHttpsAgent(): https.Agent;
|
|
24
|
-
/**
|
|
25
|
-
* Adds a custom inactivity timeout for large file transfers.
|
|
26
|
-
*/
|
|
27
|
-
addInactivityTimeout(stream: PassThrough, timeoutMs: number): PassThrough;
|
|
28
|
-
/**
|
|
29
|
-
* Check if the store and optional root hash exist by making a HEAD request.
|
|
30
|
-
*/
|
|
31
|
-
checkStoreExists(rootHash?: string): Promise<{
|
|
32
|
-
storeExists: boolean;
|
|
33
|
-
rootHashExists: boolean;
|
|
34
|
-
}>;
|
|
35
|
-
/**
|
|
36
|
-
* Start an upload session by sending a POST request with the rootHash.dat file.
|
|
37
|
-
*/
|
|
38
|
-
startUploadSession(rootHash: string): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Request a nonce for a file by sending a HEAD request to the server.
|
|
41
|
-
*/
|
|
42
|
-
getFileNonce(filename: string): Promise<{
|
|
43
|
-
nonce: string;
|
|
44
|
-
fileExists: boolean;
|
|
45
|
-
}>;
|
|
46
|
-
/**
|
|
47
|
-
* Upload a file to the server by sending a PUT request.
|
|
48
|
-
* Logs progress using a local cli-progress bar.
|
|
49
|
-
*/
|
|
50
|
-
uploadFile(label: string, dataPath: string): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Commit the upload session by sending a POST request to the server.
|
|
53
|
-
*/
|
|
54
|
-
commitUploadSession(): Promise<any>;
|
|
55
|
-
/**
|
|
56
|
-
* Static function to handle the entire upload process for multiple files based on rootHash.
|
|
57
|
-
*/
|
|
58
|
-
static uploadStore(storeId: string, rootHash: string, ipAddress: string): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Fetch a file from the server by sending a GET request and return its content in memory.
|
|
61
|
-
* Logs progress using a local cli-progress bar.
|
|
62
|
-
*/
|
|
63
|
-
fetchFile(dataPath: string): Promise<Buffer>;
|
|
64
|
-
/**
|
|
65
|
-
* Get details of a file, including whether it exists and its size.
|
|
66
|
-
*/
|
|
67
|
-
getFileDetails(dataPath: string, rootHash: string): Promise<{
|
|
68
|
-
exists: boolean;
|
|
69
|
-
size: number;
|
|
70
|
-
}>;
|
|
71
|
-
/**
|
|
72
|
-
* Download a file from the server by sending a GET request.
|
|
73
|
-
* Logs progress using a local cli-progress bar.
|
|
74
|
-
*/
|
|
75
|
-
downloadFile(label: string, dataPath: string, rootHash: string, baseDir: string): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Static function to handle downloading multiple files from a DataStore based on file paths.
|
|
78
|
-
*/
|
|
79
|
-
static downloadStore(storeId: string, rootHash: string, ipAddress: string): Promise<void>;
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=PropagationServer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAiBrC,qBAAa,iBAAiB;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAA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