@dignetwork/dig-sdk 0.0.1-alpha.23 → 0.0.1-alpha.25

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.
@@ -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;IAgHN,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;WA2B3B,qBAAqB,CACjC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EAAE,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC;WAwBI,gBAAgB,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,GAChD,OAAO,CAAC,IAAI,CAAC;IAkCH,WAAW,CAAC,UAAU,EAAE,MAAM,E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class DigPeer {
153
153
  return DigPeer.sendBulkPayments(walletName, outputs);
154
154
  }
155
155
  static async sendBulkPayments(walletName, outputs) {
156
- const fee = BigInt(1000);
156
+ const feePerCondition = BigInt(1000);
157
+ const totalFee = feePerCondition * BigInt(outputs.length);
157
158
  const wallet = await blockchain_3.Wallet.load(walletName);
158
159
  const publicSyntheticKey = await wallet.getPublicSyntheticKey();
159
160
  const peer = await blockchain_2.FullNodePeer.connect();
160
161
  const totalAmount = outputs.reduce((acc, output) => acc + output.amount, BigInt(0));
161
- const coins = await (0, coins_1.selectUnspentCoins)(peer, totalAmount, fee, [], walletName);
162
- const coinSpends = await (0, datalayer_driver_1.sendXch)(publicSyntheticKey, coins, outputs, fee);
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);
163
164
  const sig = (0, datalayer_driver_1.signCoinSpends)(coinSpends, [await wallet.getPrivateSyntheticKey()], false);
164
165
  const err = await peer.broadcastSpend(coinSpends, [sig]);
165
166
  if (err) {
@@ -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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A2B;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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AA0B,GACjC,OAAO,CAAC,SAAS,CAAC;mBAyCA,IAAI;IA4FzB;;;OAGG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAK5C;;;OAGG;WACiB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIxD;;;;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
  }
@@ -12,12 +12,18 @@ export declare class ServerCoin {
12
12
  getActiveEpochPeers(blacklist?: string[]): Promise<string[]>;
13
13
  sampleCurrentEpoch(sampleSize?: number, blacklist?: string[]): Promise<string[]>;
14
14
  sampleServerCoinsByEpoch(epoch: number, sampleSize?: number, blacklist?: string[]): Promise<string[]>;
15
- static getCurrentEpoch(): number;
15
+ static getCurrentEpoch(): {
16
+ epoch: number;
17
+ round: number;
18
+ };
16
19
  ensureServerCoinExists(peerIp: string): Promise<void>;
17
20
  meltOutdatedEpochs(peerIp: string): Promise<void>;
18
21
  static meltUntrackedStoreCoins(): Promise<void>;
19
22
  private getServerCoinsForStore;
20
23
  hasEpochCoinBeenCreated(currentEpoch: number, peerIp: string): Promise<boolean>;
21
- static calculateEpoch(currentTimestampUTC: Date): number;
24
+ static calculateEpochAndRound(currentTimestampUTC: Date): {
25
+ epoch: number;
26
+ round: number;
27
+ };
22
28
  }
23
29
  //# sourceMappingURL=ServerCoin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ServerCoin.d.ts","sourceRoot":"","sources":["../../src/blockchain/ServerCoin.ts"],"names":[],"mappings":"AACA,OAAO,EAML,UAAU,IAAI,gBAAgB,EAE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AAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WA+B1C,uBAAuB;YAkE7B,sBAAsB;IAWvB,uBAAuB,CAClC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;WAuBL,sBAAsB,CAAC,mBAAmB,EAAE,IAAI,GAAG;QAC/D,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf;CA2BF"}
@@ -23,7 +23,7 @@ class ServerCoin {
23
23
  const wallet = await Wallet_1.Wallet.load("default");
24
24
  const publicSyntheticKey = await wallet.getPublicSyntheticKey();
25
25
  const serverCoinCreationCoins = await (0, coins_1.selectUnspentCoins)(peer, BigInt(serverCoinCollateral), BigInt(1000000));
26
- const currentEpoch = ServerCoin.getCurrentEpoch();
26
+ const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
27
27
  const epochBasedHint = (0, datalayer_driver_1.morphLauncherId)(Buffer.from(this.storeId, "hex"), BigInt(currentEpoch));
28
28
  const newServerCoin = (0, datalayer_driver_1.createServerCoin)(publicSyntheticKey, serverCoinCreationCoins, epochBasedHint, [peerIp], BigInt(serverCoinCollateral), BigInt(1000000));
29
29
  const combinedCoinSpends = [...newServerCoin.coinSpends];
@@ -115,12 +115,12 @@ class ServerCoin {
115
115
  return Array.from(serverCoinPeers);
116
116
  }
117
117
  async getActiveEpochPeers(blacklist = []) {
118
- const epoch = ServerCoin.getCurrentEpoch();
118
+ const { epoch } = ServerCoin.getCurrentEpoch();
119
119
  return this.getAllEpochPeers(epoch, blacklist);
120
120
  }
121
121
  // Sample server coins for the current epoch
122
122
  async sampleCurrentEpoch(sampleSize = 5, blacklist = []) {
123
- const epoch = ServerCoin.getCurrentEpoch();
123
+ const { epoch } = ServerCoin.getCurrentEpoch();
124
124
  return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist);
125
125
  }
126
126
  // Sample server coins by epoch
@@ -130,13 +130,13 @@ class ServerCoin {
130
130
  }
131
131
  // Get the current epoch based on the current timestamp
132
132
  static getCurrentEpoch() {
133
- return ServerCoin.calculateEpoch(new Date());
133
+ return ServerCoin.calculateEpochAndRound(new Date());
134
134
  }
135
135
  // Ensure server coin exists for the current epoch
136
136
  async ensureServerCoinExists(peerIp) {
137
137
  try {
138
138
  console.log(`Ensuring server coin exists for store ${this.storeId}...`);
139
- const currentEpoch = ServerCoin.getCurrentEpoch();
139
+ const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
140
140
  const serverCoins = await this.getServerCoinsForStore(peerIp);
141
141
  // Check if a server coin already exists for the current epoch
142
142
  const existingCoin = serverCoins.find((coin) => coin.epoch === currentEpoch);
@@ -167,7 +167,7 @@ class ServerCoin {
167
167
  // Melt outdated server coins
168
168
  async meltOutdatedEpochs(peerIp) {
169
169
  try {
170
- const currentEpoch = ServerCoin.getCurrentEpoch();
170
+ const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
171
171
  let serverCoins = await this.getServerCoinsForStore(peerIp);
172
172
  // Filter out coins that are not in the current epoch
173
173
  const outdatedCoins = serverCoins.filter((coin) => coin.epoch < currentEpoch);
@@ -251,17 +251,23 @@ class ServerCoin {
251
251
  }
252
252
  }
253
253
  // Static method to calculate the current epoch
254
- static calculateEpoch(currentTimestampUTC) {
254
+ static calculateEpochAndRound(currentTimestampUTC) {
255
255
  const firstEpochStart = new Date(Date.UTC(2024, 8, 3, 0, 0)); // Sept 3, 2024, 00:00 UTC
256
256
  // Convert the current timestamp to milliseconds
257
257
  const currentTimestampMillis = currentTimestampUTC.getTime();
258
258
  // Calculate the number of milliseconds in one epoch (7 days)
259
- const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000;
259
+ const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds
260
260
  // Calculate the difference in milliseconds between the current timestamp and the first epoch start
261
261
  const differenceMillis = currentTimestampMillis - firstEpochStart.getTime();
262
262
  // Calculate the current epoch number
263
263
  const epochNumber = Math.floor(differenceMillis / millisecondsInEpoch) + 1;
264
- return epochNumber;
264
+ // Calculate the milliseconds elapsed since the start of the current epoch
265
+ const elapsedMillisInCurrentEpoch = differenceMillis % millisecondsInEpoch;
266
+ // Calculate the number of milliseconds in a round (10 minutes)
267
+ const millisecondsInRound = 10 * 60 * 1000; // 10 minutes in milliseconds
268
+ // Calculate the current round number
269
+ const roundNumber = Math.floor(elapsedMillisInCurrentEpoch / millisecondsInRound) + 1;
270
+ return { epoch: epochNumber, round: roundNumber };
265
271
  }
266
272
  }
267
273
  exports.ServerCoin = ServerCoin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.23",
3
+ "version": "0.0.1-alpha.25",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",