@dignetwork/dig-sdk 0.0.1-alpha.22 → 0.0.1-alpha.24

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.
@@ -14,6 +14,11 @@ export declare class DigPeer {
14
14
  get IpAddress(): string;
15
15
  validateStore(rootHash: string, keys: string[]): Promise<boolean>;
16
16
  isSynced(): Promise<boolean>;
17
+ static sendEqualBulkPayments(walletName: string, addresses: string[], totalAmount: bigint): Promise<void>;
18
+ static sendBulkPayments(walletName: string, outputs: {
19
+ puzzleHash: Buffer;
20
+ amount: bigint;
21
+ }[]): Promise<void>;
17
22
  sendPayment(walletName: string, amount: bigint): Promise<void>;
18
23
  }
19
24
  //# sourceMappingURL=DigPeer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DigPeer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/DigPeer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAcpD,qBAAa,OAAO;IAClB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,gBAAgB,CAAkB;gBAE9B,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAS9C,IAAW,aAAa,IAAI,aAAa,CAExC;IAGD,IAAW,iBAAiB,IAAI,iBAAiB,CAEhD;IAGD,IAAW,eAAe,IAAI,eAAe,CAE5C;IAED,IAAW,SAAS,IAAI,MAAM,CAE7B;IAEY,aAAa,CACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,OAAO,CAAC;IA8GN,QAAQ,IAAI,OAAO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,GAAG,OAAO,CAAC,IAAI,CAAC;CAO5E"}
@@ -137,22 +137,30 @@ class DigPeer {
137
137
  return false;
138
138
  }
139
139
  }
140
- async sendPayment(walletName, amount) {
141
- const paymentAddress = await this.contentServer.getPaymentAddress();
142
- console.log(`Sending ${amount} Mojos to ${paymentAddress}...`);
143
- const fee = BigInt(1000);
140
+ static sendEqualBulkPayments(walletName, addresses, totalAmount) {
141
+ // Use a Set to ensure unique addresses
142
+ const uniqueAddresses = Array.from(new Set(addresses));
143
+ // Convert unique addresses to puzzle hashes
144
+ const puzzleHashes = uniqueAddresses.map((address) => (0, datalayer_driver_1.addressToPuzzleHash)(address));
145
+ // Calculate amount per puzzle hash
146
+ const amountPerPuzzleHash = totalAmount / BigInt(puzzleHashes.length);
147
+ // Create outputs array
148
+ const outputs = puzzleHashes.map((puzzleHash) => ({
149
+ puzzleHash,
150
+ amount: amountPerPuzzleHash,
151
+ }));
152
+ // Call the sendBulkPayments function with the generated outputs
153
+ return DigPeer.sendBulkPayments(walletName, outputs);
154
+ }
155
+ static async sendBulkPayments(walletName, outputs) {
156
+ const feePerCondition = BigInt(1000);
157
+ const totalFee = feePerCondition * BigInt(outputs.length);
144
158
  const wallet = await blockchain_3.Wallet.load(walletName);
145
159
  const publicSyntheticKey = await wallet.getPublicSyntheticKey();
146
160
  const peer = await blockchain_2.FullNodePeer.connect();
147
- const coins = await (0, coins_1.selectUnspentCoins)(peer, amount, fee, [], walletName);
148
- const paymentAddressPuzzleHash = (0, datalayer_driver_1.addressToPuzzleHash)(paymentAddress);
149
- const outputs = [
150
- {
151
- puzzleHash: paymentAddressPuzzleHash,
152
- amount: amount,
153
- },
154
- ];
155
- const coinSpends = await (0, datalayer_driver_1.sendXch)(publicSyntheticKey, coins, outputs, fee);
161
+ const totalAmount = outputs.reduce((acc, output) => acc + output.amount, BigInt(0));
162
+ const coins = await (0, coins_1.selectUnspentCoins)(peer, totalAmount, totalFee, [], walletName);
163
+ const coinSpends = await (0, datalayer_driver_1.sendXch)(publicSyntheticKey, coins, outputs, totalFee);
156
164
  const sig = (0, datalayer_driver_1.signCoinSpends)(coinSpends, [await wallet.getPrivateSyntheticKey()], false);
157
165
  const err = await peer.broadcastSpend(coinSpends, [sig]);
158
166
  if (err) {
@@ -160,5 +168,12 @@ class DigPeer {
160
168
  }
161
169
  await blockchain_2.FullNodePeer.waitForConfirmation((0, datalayer_driver_1.getCoinId)(coins[0]));
162
170
  }
171
+ async sendPayment(walletName, amount) {
172
+ const paymentAddress = await this.contentServer.getPaymentAddress();
173
+ const paymentAddressPuzzleHash = (0, datalayer_driver_1.addressToPuzzleHash)(paymentAddress);
174
+ return DigPeer.sendBulkPayments(walletName, [
175
+ { puzzleHash: paymentAddressPuzzleHash, amount },
176
+ ]);
177
+ }
163
178
  }
164
179
  exports.DigPeer = DigPeer;
@@ -1 +1 @@
1
- {"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAK;IACvC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAQ;IAC5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAS;IACzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAO;gBAElC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAYjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,G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C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAQ;IAC5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAS;IACzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAO;gBAElC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAYjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB/D,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAQjC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAK9B,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMpD,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK/C,SAAS,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;IAOzC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAM7B,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAMjC,gBAAgB,IAAI,OAAO,CAAC;QACvC,KAAK,EAAE,MAAM,CAAC;QACd,gBAAgB,EAAE,MAAM,CAAC;QACzB,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;YAmBY,WAAW;YAyCX,kBAAkB;YAoElB,gBAAgB;YAgEhB,cAAc;YAiCd,KAAK;YAmDL,IAAI;YAgCJ,SAAS;YAuCT,2BAA2B;YAiC3B,gBAAgB;CAyC/B"}
@@ -9,7 +9,6 @@ const https_1 = __importDefault(require("https"));
9
9
  const url_1 = require("url");
10
10
  const ssl_1 = require("../utils/ssl");
11
11
  const credentialsUtils_1 = require("../utils/credentialsUtils");
12
- const spinnerUtils_1 = require("../utils/spinnerUtils");
13
12
  const blockchain_1 = require("../blockchain");
14
13
  class PropagationServer {
15
14
  constructor(ipAddress, storeId) {
@@ -122,51 +121,49 @@ class PropagationServer {
122
121
  // Method to fetch upload details from the server
123
122
  async fetchUploadDetails(username, password) {
124
123
  const remote = `https://${this.ipAddress}:${PropagationServer.port}/${this.storeId}`;
125
- return (0, spinnerUtils_1.waitForPromise)(() => {
126
- return new Promise((resolve, reject) => {
127
- const url = new url_1.URL(remote);
128
- const options = {
129
- hostname: url.hostname,
130
- port: url.port,
131
- path: url.pathname,
132
- method: "HEAD",
133
- headers: {
134
- Authorization: `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`,
135
- },
136
- key: fs_1.default.readFileSync(PropagationServer.keyPath),
137
- cert: fs_1.default.readFileSync(PropagationServer.certPath),
138
- rejectUnauthorized: false, // Allow self-signed certificates
139
- };
140
- const req = https_1.default.request(options, (res) => {
141
- if (res.statusCode === 200) {
142
- // Check if the headers are present and valid
143
- const nonce = res.headers["x-nonce"];
144
- const lastUploadedHash = res.headers?.["x-last-uploaded-hash"] ||
145
- "0000000000000000000000000000000000000000000000000000000000000000";
146
- const generationIndex = res.headers?.["x-generation-index"] || 0;
147
- console.log({ nonce, lastUploadedHash, generationIndex });
148
- if (nonce) {
149
- resolve({
150
- nonce: nonce,
151
- lastUploadedHash: lastUploadedHash,
152
- generationIndex: Number(generationIndex),
153
- });
154
- }
155
- else {
156
- reject(new Error("Missing required headers in the response."));
157
- }
124
+ return new Promise((resolve, reject) => {
125
+ const url = new url_1.URL(remote);
126
+ const options = {
127
+ hostname: url.hostname,
128
+ port: url.port,
129
+ path: url.pathname,
130
+ method: "HEAD",
131
+ headers: {
132
+ Authorization: `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`,
133
+ },
134
+ key: fs_1.default.readFileSync(PropagationServer.keyPath),
135
+ cert: fs_1.default.readFileSync(PropagationServer.certPath),
136
+ rejectUnauthorized: false, // Allow self-signed certificates
137
+ };
138
+ const req = https_1.default.request(options, (res) => {
139
+ if (res.statusCode === 200) {
140
+ // Check if the headers are present and valid
141
+ const nonce = res.headers["x-nonce"];
142
+ const lastUploadedHash = res.headers?.["x-last-uploaded-hash"] ||
143
+ "0000000000000000000000000000000000000000000000000000000000000000";
144
+ const generationIndex = res.headers?.["x-generation-index"] || 0;
145
+ console.log({ nonce, lastUploadedHash, generationIndex });
146
+ if (nonce) {
147
+ resolve({
148
+ nonce: nonce,
149
+ lastUploadedHash: lastUploadedHash,
150
+ generationIndex: Number(generationIndex),
151
+ });
158
152
  }
159
153
  else {
160
- reject(new Error(`Failed to perform preflight check: ${res.statusCode} ${res.statusMessage}`));
154
+ reject(new Error("Missing required headers in the response."));
161
155
  }
162
- });
163
- req.on("error", (err) => {
164
- console.error(err.message);
165
- resolve(false); // Resolve to false if there is an error
166
- });
167
- req.end();
156
+ }
157
+ else {
158
+ reject(new Error(`Failed to perform preflight check: ${res.statusCode} ${res.statusMessage}`));
159
+ }
160
+ });
161
+ req.on("error", (err) => {
162
+ console.error(err.message);
163
+ resolve(false); // Resolve to false if there is an error
168
164
  });
169
- }, "Performing remote preflight", "Preflight succeeded.", "Error on preflight.");
165
+ req.end();
166
+ });
170
167
  }
171
168
  // Core method to upload a file directly to the server using a stream
172
169
  async uploadFileDirect(filePath, uploadUrl, username, password, keyOwnershipSig, publicKey, nonce) {
@@ -1 +1 @@
1
- {"version":3,"file":"DataStore.d.ts","sourceRoot":"","sources":["../../src/blockchain/DataStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,SAAS,IAAI,eAAe,EAE5B,iBAAiB,EAIlB,MAAM,kBAAkB,CAAC;AAY1B,OAAO,EAAE,eAAe,EAAW,MAAM,UAAU,CAAC;AAGpD,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAQjD,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,C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;OAIG;mBACkB,mBAAmB;WAqB1B,YAAY,IAAI,SAAS,EAAE;IAW5B,aAAa,IAAI,OAAO,CAAC;QACpC,WAAW,EAAE,eAAe,CAAC;QAC7B,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAyGW,iBAAiB,IAAI,OAAO,CAAC;QACxC,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;YA0BY,iBAAiB;IAYlB,cAAc,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAsB5C,mBAAmB,IAAI,OAAO,CAAC,eAAe,EAAE,GAAG,SAAS,CAAC;IAiB7D,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAoF5B,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAKzC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAgB5B,uBAAuB,CAClC,kBAAkB,CAAC,EAAE,MAAM,GAC1B,OAAO,CAAC,OAAO,CAAC;IAkBN,cAAc,CACzB,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,eAAe,CAAC;IA+Cd,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAiChE,iBAAiB,IAAI,MAAM,EAAE;CAUrC"}
@@ -336,6 +336,7 @@ class DataStore {
336
336
  }
337
337
  }
338
338
  let filesIntegrityIntact = true;
339
+ // At this point we have verified that the root history and manifest file match
339
340
  for (const rootHash of manifestHashes) {
340
341
  const datFilePath = path_1.default.join(config_1.STORE_PATH, this.storeId, `${rootHash}.dat`);
341
342
  if (!fs_1.default.existsSync(datFilePath)) {
@@ -348,8 +349,11 @@ class DataStore {
348
349
  return false;
349
350
  }
350
351
  for (const [fileKey, fileData] of Object.entries(datFileContent.files)) {
351
- const integrityCheck = (0, utils_1.validateFileSha256)(fileData.sha256, path_1.default.join(config_1.STORE_PATH, this.storeId, "data"));
352
- if (!integrityCheck) {
352
+ // We are going to check if the sha256 belongs to the tree, and then we are going to make sure
353
+ // that the file is in the data folder and that the sha256 of the file matches the one in the dat file
354
+ const belongsInTree = await this.Tree.verifyKeyIntegrity(fileData.sha256, rootHash);
355
+ const fileIntegrityCheck = (0, utils_1.validateFileSha256)(fileData.sha256, path_1.default.join(config_1.STORE_PATH, this.storeId, "data"));
356
+ if (!fileIntegrityCheck || !belongsInTree) {
353
357
  filesIntegrityIntact = false;
354
358
  }
355
359
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.22",
3
+ "version": "0.0.1-alpha.24",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",